Symbolic Demonstrations

Executable pure-symbolic Python demonstrations (Model(…, auto_intersect=False)) verifying every geometric construction and algebraic identity in Almagest Book I and Planisphaerium with zero floating-point coordinates.

1. Golden Pentagon–Decagon & Radical Chord Table

Constructs Ptolemy’s single-circle regular decagon ($s_{10} = R/\phi$) and regular pentagon ($s_5 = \sqrt{R^2 + s_{10}^2}$) over $\mathbb{Q}(\phi)$ (Almagest I.10a, Heiberg I, pp. 32–35), evaluates the closed-form SymPy radical tower for Ptolemy’s chord cascade ($120^\circ \to \dots \to \frac{3}{4}^\circ$), and verifies Ptolemy’s Inequality Lemma bounding $\operatorname{crd}(1^\circ) \approx 1;2,50$ and $\pi \approx 3;8,30 = \frac{377}{120}$.

 1r"""Demonstration 1: Ptolemy's Golden Pentagon-Decagon Construction & Radical Chord Table.
         2
         3Showcases *Almagest* Book I, Chs. 10-11 (Heiberg 1898, Vol. I.1, pp. 32-46):
         4
         51. Constructs Ptolemy's single-circle regular decagon ($DZ = R / \phi$) and regular
         6   pentagon ($BZ = \sqrt{R^2 + DZ^2}$) in ``geometor.model`` with ``auto_intersect=False``
         7   and zero floating-point coordinates.
         82. Computes the exact closed-form SymPy radical expressions and base-60 sexagesimal
         9   approximations for Ptolemy's chord cascade ($120^\circ \to 90^\circ \to 72^\circ \to
        10   60^\circ \to 36^\circ \to 12^\circ \to 6^\circ \to 3^\circ \to 1\frac{1}{2}^\circ
        11   \to \frac{3}{4}^\circ$), comparing each against Heiberg's Greek text.
        123. Verifies Ptolemy's Inequality Lemma bounds for $\operatorname{crd}(1^\circ) \approx 1;2,50$
        13   and the resulting sexagesimal ratio $\pi \approx 3;8,30 = \frac{377}{120}$.
        14"""
        15
        16from __future__ import annotations
        17
        18import sys
        19from pathlib import Path
        20
        21_SRC_DIR = Path(__file__).resolve().parents[1] / "src"
        22if str(_SRC_DIR) not in sys.path:
        23    sys.path.insert(0, str(_SRC_DIR))
        24
        25import sympy as sp  # noqa: E402
        26from rich.console import Console  # noqa: E402
        27from rich.table import Table  # noqa: E402
        28
        29from geometor.ptolemy import (  # noqa: E402
        30    PHI,
        31    PHI_INV,
        32    build_radical_chord_table,
        33    construct_pentagon_decagon,
        34    verify_ptolemy_pi,
        35)
        36
        37
        38def run_demo() -> None:
        39    """Execute the Golden Pentagon-Decagon and Sexagesimal Chord demonstration."""
        40    console = Console()
        41
        42    res = construct_pentagon_decagon(radius=60)
        43    prop_table = Table(title="Almagest I.10a — Golden Pentagon-Decagon Construction (R = 60)")
        44    prop_table.add_column("Geometric Invariant", style="cyan bold")
        45    prop_table.add_column("Exact Symbolic Expression", style="green")
        46    prop_table.add_row("Golden Ratio φ", f"{PHI}")
        47    prop_table.add_row("Constructed Point E (bisect DC)", f"({res.E.x}, {res.E.y})")
        48    prop_table.add_row("Constructed Point Z (arc EB ∩ AD)", f"({res.Z.x}, {res.Z.y})")
        49    prop_table.add_row("Decagon Side s_10 = DZ", f"{res.decagon_length}")
        50    prop_table.add_row(
        51        "Ratio DZ / R == φ⁻¹",
        52        f"{res.decagon_over_radius} (exact match: {sp.simplify(res.decagon_over_radius - PHI_INV) == 0})",
        53    )
        54    prop_table.add_row("Pentagon Side s_5 = BZ", f"{res.pentagon_length}")
        55    prop_table.add_row(
        56        "Euclid XIII.10 (DZ² + DB² == BZ²)",
        57        f"{sp.simplify(res.decagon_length**2 + res.radius**2)} == {sp.simplify(res.pentagon_length**2)}",
        58    )
        59    prop_table.add_row("Proof Ledger Steps Recorded", str(len(res.model.steps)))
        60    console.print(prop_table)
        61
        62    chord_table = Table(title="Almagest I.10-11 — Exact Radical & Sexagesimal Chord Cascade (2R = 120)")
        63    chord_table.add_column("Arc θ (°)", style="bold yellow")
        64    chord_table.add_column("Exact SymPy Radical", style="cyan")
        65    chord_table.add_column("Computed Base-60", style="green")
        66    chord_table.add_column("Heiberg (1898)", style="magenta")
        67
        68    for entry in build_radical_chord_table(radius=60):
        69        h_str = entry.heiberg_sexagesimal.format_greek_style() if entry.heiberg_sexagesimal else "-"
        70        chord_table.add_row(
        71            str(entry.arc_deg),
        72            str(entry.exact_expr),
        73            entry.sexagesimal.format_greek_style(),
        74            h_str,
        75        )
        76    console.print(chord_table)
        77
        78    pi_ver = verify_ptolemy_pi()
        79    pi_table = Table(title="Almagest I.10 & VI.7 — Ptolemy's Inequality Lemma & Sexagesimal π")
        80    pi_table.add_column("Quantity", style="cyan bold")
        81    pi_table.add_column("Value", style="green")
        82    pi_table.add_row("Lower Bound (2/3)·crd(1½°)", f"{float(pi_ver.exact_lower_bound.evalf()):.10f}")
        83    pi_table.add_row("Upper Bound (4/3)·crd(¾°)", f"{float(pi_ver.exact_upper_bound.evalf()):.10f}")
        84    pi_table.add_row("Strict Inequality Holds?", str(pi_ver.strict_inequality_holds))
        85    pi_table.add_row("Sexagesimal crd(1°)", f"{pi_ver.ptolemy_crd_1_deg.format_greek_style()} = {pi_ver.ptolemy_crd_1_deg.rational}")
        86    pi_table.add_row(
        87        "Implied Sexagesimal π = 3·crd(1°)",
        88        f"{pi_ver.ptolemy_pi.format_greek_style()} = {pi_ver.pi_rational} ≈ {float(pi_ver.pi_rational):.8f}",
        89    )
        90    console.print(pi_table)
        91
        92
        93if __name__ == "__main__":
        94    run_demo()
        

Run locally:

/home/phi/PROJECTS/geometor/.venv/bin/python demos/pentagon_chords.py
        

2. Ptolemy’s Theorem on Cyclic Quadrilaterals & Menelaus Calculus

Constructs rational cyclic quadrilaterals (pythagorean_65 with integer sides $25, 39, 60, 52$ and integer diagonals $56, 63$ where $56 \times 63 = 3528 = 25 \times 60 + 39 \times 52$, plus brahmagupta with perpendicular diagonals) alongside Ptolemy’s Planar & 3D Spherical Menelaus lemmas and I.14 solar declinations.

 1r"""Demonstration 2: Ptolemy's Theorem on Cyclic Quadrilaterals & Menelaus Sector Lemma.
         2
         3Showcases *Almagest* Book I, Ch. 10b (Heiberg 1898, Vol. I.1, pp. 36-37) and Ch. 13-14
         4(pp. 68-78):
         5
         61. Constructs the Pythagorean cyclic quadrilateral on diameter $65$ with exact integer
         7   sides $(AB, BC, CD, DA) = (25, 39, 60, 52)$ and diagonals $(AC, BD) = (56, 63)$,
         8   verifying $56 \times 63 = 3528 = 25 \times 60 + 39 \times 52 = 1500 + 2028$ and
         9   locating Ptolemy's exact Euclidean similarity point $E \in AC$ ($AE = \frac{500}{21}$,
        10   $EC = \frac{676}{21}$).
        112. Constructs the pure-integer Brahmagupta cyclic quadrilateral on $x^2 + y^2 = 65^2$.
        123. Proves Ptolemy's Theorem universally over $\mathbb{Z}[t_1, t_2, t_3, t_4]$ and runs
        13   Ptolemy's Planar & 3D Spherical Menelaus verifications (*Almagest* I.13-I.14).
        14"""
        15
        16from __future__ import annotations
        17
        18import sys
        19from pathlib import Path
        20
        21_SRC_DIR = Path(__file__).resolve().parents[1] / "src"
        22if str(_SRC_DIR) not in sys.path:
        23    sys.path.insert(0, str(_SRC_DIR))
        24
        25from rich.console import Console  # noqa: E402
        26from rich.table import Table  # noqa: E402
        27
        28from geometor.ptolemy import (  # noqa: E402
        29    compute_solar_declination,
        30    construct_planar_menelaus,
        31    construct_ptolemy_quadrilateral,
        32    prove_ptolemy_theorem_universally,
        33    verify_spherical_menelaus,
        34)
        35
        36
        37def run_demo() -> None:
        38    """Execute the Ptolemy's Theorem and Menelaus Trigonometry demonstration."""
        39    console = Console()
        40
        41    for preset_name in ("pythagorean_65", "brahmagupta"):
        42        res = construct_ptolemy_quadrilateral(preset=preset_name)
        43        ab, bc, cd, da = res.sides
        44        ac, bd = res.diagonals
        45        q_table = Table(title=f"Almagest I.10b — Ptolemy's Theorem ({preset_name})")
        46        q_table.add_column("Element / Relation", style="cyan bold")
        47        q_table.add_column("Exact Symbolic Value", style="green")
        48        q_table.add_row("Sides (AB, BC, CD, DA)", f"({ab}, {bc}, {cd}, {da})")
        49        q_table.add_row("Diagonals (AC, BD)", f"({ac}, {bd})")
        50        q_table.add_row("Ptolemy Point E on AC", f"({res.E.x}, {res.E.y}) -> AE = {res.ae_segment_length}, EC = {res.ec_segment_length}")
        51        q_table.add_row("LHS = AC · BD", str(res.lhs_product))
        52        q_table.add_row("RHS = AB·CD + BC·DA", f"{ab * cd} + {bc * da} = {res.rhs_sum}")
        53        console.print(q_table)
        54
        55    poly_res = prove_ptolemy_theorem_universally()
        56    men_p = construct_planar_menelaus()
        57    men_s = verify_spherical_menelaus()
        58
        59    m_table = Table(title="Almagest I.13-14 — Universal Proof & Menelaus Spherical Trigonometry")
        60    m_table.add_column("Verification", style="bold yellow")
        61    m_table.add_column("Exact Result", style="cyan")
        62    m_table.add_row("Universal 4-Variable Circle Residual", str(poly_res))
        63    m_table.add_row(
        64        "Planar Menelaus (kata synthesin)",
        65        f"CA/AE = {men_p.ratio_ca_ae} == (CD/DZ)·(ZB/BE) = {men_p.compound_synthesin}",
        66    )
        67    m_table.add_row(
        68        "Planar Menelaus (kata diairesin)",
        69        f"CE/EA = {men_p.ratio_ce_ea} == (CZ/ZD)·(DB/BA) = {men_p.compound_diairesin}",
        70    )
        71    m_table.add_row(
        72        "3D Spherical Menelaus Plane Meet (Θ, K, Λ)",
        73        f"Collinear = {men_s.are_theta_k_lambda_collinear}; crd²(2CE)/crd²(2EA) = {men_s.lhs_chord_ratio_sq}",
        74    )
        75    for lon in (30, 60, 90):
        76        decl = compute_solar_declination(lon)
        77        m_table.add_row(
        78            f"I.14 Solar Declination δ(λ={lon}°)",
        79            f"Computed {decl.declination_deg_sexagesimal.format_greek_style()}° vs Heiberg {decl.heiberg_declination.format_greek_style()}°",
        80        )
        81    console.print(m_table)
        82
        83
        84if __name__ == "__main__":
        85    run_demo()
        

Run locally:

/home/phi/PROJECTS/geometor/.venv/bin/python demos/cyclic_quadrilateral.py
        

3. Planisphaerium Stereographic Projection & Astrolabe Plate

Proves universal stereographic circle-preservation, the conformal metric pullback $ds^2 = \frac{4(dx^2 + dy^2)}{(1 + x^2 + y^2)^2}$, and §4 circular inversion ($r_+ \cdot r_- = R_{\text{eq}}^2$), and constructs the exact rational astrolabe plate ($R_{\text{eq}} = 60$, $r_{\text{Can}} = 40$, $r_{\text{Cap}} = 90$, oblique ecliptic center $(0, 25)$ and radius $65$).

  1r"""Demonstration 3: Stereographic Projection & Astrolabe Geometry (*Planisphaerium*).
          2
          3Showcases Ptolemy's *Planisphaerium* (ed. J. L. Heiberg, *Opera Astronomica Minora*,
          41907, §§1-4, pp. 227-234):
          5
          61. Verifies the universal algebraic Circle-Preservation Theorem over $\mathbb{Q}(a, b, c, d)$
          7   showing that every plane $aX + bY + cZ + d = 0$ ($d \neq c$) projects from the South
          8   Pole $S = (0, 0, -1)$ onto an exact Euclidean circle in the equatorial plane, while
          9   planes through $S$ ($d = c$, such as meridians) project to straight lines.
         102. Verifies the conformal metric tensor $J^T J = \frac{4}{(1 + x^2 + y^2)^2} I_2$ and
         11   *Planisphaerium* §4 circular inversion $r_+ \cdot r_- = R^2$ (`ez : ed = ed : ek`).
         123. Constructs Ptolemy's *Planisphaerium* §1 astrolabe plate (equator $ABGD$, Cancer $TL$,
         13   Capricorn $KM$, and oblique ecliptic $MBTD$) in ``geometor.model`` with zero ``sp.Float``
         14   coordinates, plus rational astrolabe horizon and almucantar circles.
         15"""
         16
         17from __future__ import annotations
         18
         19import sys
         20from pathlib import Path
         21
         22_SRC_DIR = Path(__file__).resolve().parents[1] / "src"
         23if str(_SRC_DIR) not in sys.path:
         24    sys.path.insert(0, str(_SRC_DIR))
         25
         26import sympy as sp  # noqa: E402
         27from rich.console import Console  # noqa: E402
         28from rich.table import Table  # noqa: E402
         29
         30from geometor.ptolemy import (  # noqa: E402
         31    construct_almucantar_circle,
         32    construct_astrolabe_planisphere,
         33    prove_circle_preservation_symbolically,
         34    prove_conformal_metric_symbolically,
         35    prove_parallel_inversion_symbolically,
         36)
         37
         38
         39def run_demo() -> None:
         40    """Execute the Stereographic Projection and Astrolabe demonstration."""
         41    console = Console()
         42
         43    circ_proof = prove_circle_preservation_symbolically()
         44    conf_factor = prove_conformal_metric_symbolically()
         45    inv_proof = prove_parallel_inversion_symbolically()
         46
         47    sym_table = Table(title="Planisphaerium — Universal Symbolic Stereographic Theorems")
         48    sym_table.add_column("Theorem", style="cyan bold")
         49    sym_table.add_column("Exact Algebraic Formula", style="green")
         50    sym_table.add_row(
         51        "Plane aX+bY+cZ+d=0 Projected Center",
         52        f"({circ_proof['center_x']}, {circ_proof['center_y']})",
         53    )
         54    sym_table.add_row("Projected Squared Radius r²", str(circ_proof["radius_sq"]))
         55    sym_table.add_row("Conformal Pullback Factor λ(x,y)", f"{conf_factor} · (dx² + dy²)")
         56    sym_table.add_row(
         57        "§4 Parallel Inversion r(+δ)·r(-δ)",
         58        f"({inv_proof['r_north']}) · ({inv_proof['r_south']}) = {inv_proof['product']}",
         59    )
         60    console.print(sym_table)
         61
         62    astro = construct_astrolabe_planisphere(equator_radius=60, half_obliquity_tan=sp.Rational(1, 5))
         63    horizon = construct_almucantar_circle(
         64        sp.Rational(3, 5),
         65        sp.Rational(4, 5),
         66        sp.Integer(0),
         67        equator_radius=60,
         68    )
         69    alm_30 = construct_almucantar_circle(
         70        sp.Rational(3, 5),
         71        sp.Rational(4, 5),
         72        sp.Rational(1, 2),
         73        equator_radius=60,
         74    )
         75
         76    ast_table = Table(title="Planisphaerium §§1-4 — Exact Astrolabe Construction (R_eq = 60)")
         77    ast_table.add_column("Astrolabe Locus", style="bold yellow")
         78    ast_table.add_column("Exact Rational Geometry", style="cyan")
         79    ast_table.add_row("Equator Circle cABGD", f"Center ({astro.E.x}, {astro.E.y}), Radius = {astro.equator_radius}")
         80    ast_table.add_row("Tropic of Cancer cTL", f"Center (0, 0), Radius EL = {astro.cancer_radius}")
         81    ast_table.add_row("Tropic of Capricorn cKM", f"Center (0, 0), Radius EK = {astro.capricorn_radius}")
         82    ast_table.add_row(
         83        "§4 Inversion Check EL · EK == ED²",
         84        f"{astro.cancer_radius} × {astro.capricorn_radius} = {astro.inversion_product} == {astro.equator_radius**2}",
         85    )
         86    ast_table.add_row(
         87        "Oblique Ecliptic Circle cMBTD",
         88        f"Center R = ({astro.R.x}, {astro.R.y}), Radius = {astro.ecliptic_radius} (passes through B={astro.B}, D={astro.D})",
         89    )
         90    ast_table.add_row(
         91        "Horizon Circle (sin φ = 3/5, h = 0°)",
         92        f"Center = {horizon.center}, Radius² = {horizon.radius_sq} (100² = 10000 -> Radius = 100)",
         93    )
         94    ast_table.add_row(
         95        "Almucantar Circle (sin φ = 3/5, sin h = 1/2)",
         96        f"Center = {alm_30.center}, Radius² = {alm_30.radius_sq}",
         97    )
         98    console.print(ast_table)
         99
        100
        101if __name__ == "__main__":
        102    run_demo()
        

Run locally:

/home/phi/PROJECTS/geometor/.venv/bin/python demos/stereographic.py