#!/usr/bin/env node /** * Build Euclid's Elements Book XII discourse JSON and Mermaid charts. * 18 propositions. Measurement: circles, pyramids, cones, cylinders, spheres. * Depends on Books I, V, VI, XI. Source: David E. Joyce. * * Charts: 2. Props 1-9, 10-18. */ const fs = require('fs'); const path = require('path'); const PROPS = [ { n: 1, short: "Similar polygons: as squares on diameters", full: "Similar polygons in circles: to one another as squares on diameters" }, { n: 2, short: "Circles: as squares on diameters", full: "Circles are to one another as the squares on their diameters" }, { n: 3, short: "Pyramid divided", full: "Pyramid with triangular base: divided into two pyramids, two prisms; prisms greater than half" }, { n: 4, short: "Pyramids: base as prisms", full: "Two pyramids same height, triangular bases, divided: base to base as all prisms" }, { n: 5, short: "Pyramids: as bases", full: "Pyramids same height, triangular bases: to one another as bases" }, { n: 6, short: "Pyramids polygonal: as bases", full: "Pyramids same height, polygonal bases: to one another as bases" }, { n: 7, short: "Prism into three pyramids", full: "Prism with triangular base: divided into three equal pyramids" }, { n: 8, short: "Similar pyramids: triplicate ratio", full: "Similar pyramids triangular bases: in triplicate ratio of corresponding sides" }, { n: 9, short: "Equal pyramids: bases reciprocally proportional", full: "Equal pyramids triangular bases: bases reciprocally proportional to heights" }, { n: 10, short: "Cone third of cylinder", full: "Any cone is third part of cylinder same base and equal height" }, { n: 11, short: "Cones, cylinders: as bases", full: "Cones and cylinders same height: to one another as bases" }, { n: 12, short: "Similar cones, cylinders: triplicate", full: "Similar cones and cylinders: in triplicate ratio of diameters of bases" }, { n: 13, short: "Cylinder cut: as axes", full: "Cylinder cut by plane parallel to opposite: cylinder to cylinder as axis to axis" }, { n: 14, short: "Cones, cylinders equal bases: as heights", full: "Cones and cylinders on equal bases: to one another as heights" }, { n: 15, short: "Equal cones, cylinders: reciprocally proportional", full: "Equal cones and cylinders: bases reciprocally proportional to heights" }, { n: 16, short: "Inscribe polygon in greater circle", full: "Given two circles same center: inscribe in greater equilateral polygon even sides not touching lesser" }, { n: 17, short: "Inscribe polyhedron in greater sphere", full: "Given two spheres same center: inscribe in greater polyhedral solid not touching lesser" }, { n: 18, short: "Spheres: triplicate ratio", full: "Spheres are to one another in triplicate ratio of their diameters" } ]; const FOUNDATIONS = ["BookI", "BookV", "BookVI", "BookXI"]; const DEPS = {}; for (let i = 1; i <= 18; i++) DEPS[i] = FOUNDATIONS; const discourse = { schemaVersion: "1.0", discourse: { id: "euclid-elements-book-xii", name: "Euclid's Elements, Book XII", subject: "measurement", variant: "classical", description: "Measurement of figures: circles, pyramids, cones, cylinders, spheres. 18 propositions. Depends on Books I, V, VI, XI. Source: David E. Joyce.", structure: { books: 12, propositions: 18, foundationTypes: ["foundation"] } }, metadata: { created: "2026-03-18", lastUpdated: "2026-03-18", version: "1.0.0", license: "CC BY 4.0", authors: ["Welz, G."], methodology: "Programming Framework", citation: "Welz, G. (2026). Euclid's Elements Book XII Dependency Graph. Programming Framework.", keywords: ["Euclid", "Elements", "Book XII", "measurement", "pyramid", "cone", "cylinder", "sphere"] }, sources: [ { id: "joyce", type: "digital", authors: "Joyce, David E.", title: "Euclid's Elements, Book XII", year: "1996", url: "https://mathcs.clarku.edu/~djoyce/java/elements/bookXII/bookXII.html", notes: "Clark University" } ], nodes: [], edges: [], colorScheme: { foundation: { fill: "#95a5a6", stroke: "#7f8c8d" }, proposition: { fill: "#1abc9c", stroke: "#16a085" } } }; discourse.nodes.push( { id: "BookI", type: "foundation", label: "Book I — Plane geometry", shortLabel: "Book I", short: "Foundation", book: 1, colorClass: "foundation" }, { id: "BookV", type: "foundation", label: "Book V — Proportions", shortLabel: "Book V", short: "Foundation", book: 5, colorClass: "foundation" }, { id: "BookVI", type: "foundation", label: "Book VI — Similar figures", shortLabel: "Book VI", short: "Foundation", book: 6, colorClass: "foundation" }, { id: "BookXI", type: "foundation", label: "Book XI — Solid geometry", shortLabel: "Book XI", short: "Foundation", book: 11, colorClass: "foundation" } ); for (const prop of PROPS) { discourse.nodes.push({ id: `Prop${prop.n}`, type: "proposition", label: prop.full, shortLabel: `Prop. XII.${prop.n}`, short: prop.short, book: 12, number: prop.n, colorClass: "proposition" }); for (const dep of DEPS[prop.n]) { discourse.edges.push({ from: dep, to: `Prop${prop.n}` }); } } const dataDir = path.join(__dirname, "..", "data"); fs.mkdirSync(dataDir, { recursive: true }); fs.writeFileSync(path.join(dataDir, "euclid-elements-book-xii.json"), JSON.stringify(discourse, null, 2), "utf8"); console.log("Wrote euclid-elements-book-xii.json"); function toMermaid(filter) { const nodes = filter ? discourse.nodes.filter(filter) : discourse.nodes; const nodeIds = new Set(nodes.map(n => n.id)); const edges = discourse.edges.filter(e => nodeIds.has(e.from) && nodeIds.has(e.to)); const lines = ["graph TD"]; for (const n of nodes) { const desc = n.short || (n.label && n.label.length > 35 ? n.label.slice(0, 32) + "..." : n.label || n.id); const lbl = (n.shortLabel || n.id) + "\\n" + (desc || ""); lines.push(` ${n.id}["${String(lbl).replace(/"/g, '\\"')}"]`); } for (const e of edges) { lines.push(` ${e.from} --> ${e.to}`); } lines.push(" classDef foundation fill:#95a5a6,color:#fff,stroke:#7f8c8d"); lines.push(" classDef proposition fill:#1abc9c,color:#fff,stroke:#16a085"); const foundIds = nodes.filter(n => n.type === "foundation").map(n => n.id).join(","); const propIds = nodes.filter(n => n.type === "proposition").map(n => n.id).join(","); if (foundIds) lines.push(` class ${foundIds} foundation`); lines.push(` class ${propIds} proposition`); return lines.join("\n"); } function closure(propMax) { const needed = new Set(FOUNDATIONS); for (let i = 1; i <= propMax; i++) needed.add(`Prop${i}`); return n => needed.has(n.id); } const MATH_DB = process.env.MATH_DB || "/home/gdubs/copernicus-web-public/huggingface-space/mathematics-processes-database"; const GEOM_DIR = path.join(MATH_DB, "processes", "geometry_topology"); function htmlTemplate(title, subtitle, mermaid, nodes, edges) { const mermaidEscaped = mermaid.replace(//g, ">"); return ` ${title} - Mathematics Process

${title}

Mathematics Measurement Source: Euclid's Elements

Description

${subtitle}

Source: Euclid's Elements, Book XII (David E. Joyce, Clark University)

Dependency Flowchart

${mermaidEscaped}

Color Scheme

Gray
Book I, V, VI, XI (foundation)
Teal
Propositions

Statistics

  • Nodes: ${nodes}
  • Edges: ${edges}

Keywords

  • Euclid
  • Elements
  • Book XII
  • measurement
  • pyramid
  • cone
  • cylinder
  • sphere
`; } const CHARTS = [ [9, "1-9", "Circles, pyramids, prisms"], [18, "10-18", "Cones, cylinders, spheres"] ]; if (fs.existsSync(GEOM_DIR)) { CHARTS.forEach(([max, range, desc]) => { const filter = closure(max); const m = toMermaid(filter); const nodes = discourse.nodes.filter(filter); const edges = discourse.edges.filter(e => filter({ id: e.from }) && filter({ id: e.to })); const fname = `geometry_topology-euclid-elements-book-xii-props-${range.replace(/–/g, "-").replace(" ", "-")}.html`; fs.writeFileSync(path.join(GEOM_DIR, fname), htmlTemplate(`Euclid's Elements Book XII — Propositions ${range}`, desc, m, nodes.length, edges.length), "utf8"); console.log("Wrote", fname); }); } // Book XII index if (fs.existsSync(GEOM_DIR)) { const indexHtml = ` Euclid's Elements Book XII - Mathematics Process

Euclid's Elements Book XII

Measurement of figures: circles (XII.2), pyramids (XII.5–7), cones and cylinders (XII.10–15), spheres (XII.18). 18 propositions. Depends on Books I, V, VI, XI.

Propositions 1–9 Circles, pyramids, prisms Propositions 10–18 Cones, cylinders, spheres
`; fs.writeFileSync(path.join(GEOM_DIR, "geometry_topology-euclid-elements-book-xii.html"), indexHtml, "utf8"); console.log("Wrote geometry_topology-euclid-elements-book-xii.html"); } console.log("Done. Nodes:", discourse.nodes.length, "Edges:", discourse.edges.length);