Skip to main content

LaTeX-first differential geometry renderer for Jupyter/Colab.

Project description

Geometrix

LLM-assisted LaTeX-first differential geometry renderer for Jupyter/Colab. Ask for symbolic solutions (with full derivations), then graph them immediately.

Flagship: LLM → Graph

LLM assist example (examples/14_llm_assist2.py) From examples/14_llm_assist2.py.

import sympy as sp
from google.colab import userdata
from geometrix import llm_solve, latex, show
from geometrix.api import SceneBundle
from geometrix.sample.domains import Domain
from geometrix.sample.surface import sample_surface_grid
from geometrix.scene.build import build_surface_scene
from geometrix.symbolic.compile import compile_vector
from geometrix.symbolic.llm import LLMConfig

config = LLMConfig(
    provider="gemini",
    model="gemini-3-flash-preview",
    api_key=userdata.get("GEMINI_API_KEY"),
)
live = llm_solve(
    "x^2 + y^2 + z^2 = 1",
    config=config,
    response_type="full",
    wants_graph=True,
    graph_dim=3,
)

graph_latex = live.data.graph  # e.g., "z = \\sqrt{1-x^2-y^2}"
_, rhs = graph_latex.split("=", 1)
x, y = sp.symbols("x y")
z_expr = latex(rhs.strip())

domains = [Domain("x", -1.0, 1.0), Domain("y", -1.0, 1.0)]
compiled = compile_vector([x, y, z_expr], [x, y])
surface = sample_surface_grid(compiled, domains, [80, 80])
scene = build_surface_scene(surface.positions, surface.grid_shape)
show(SceneBundle(scene=scene, arrays={"positions": surface.positions}))

LaTeX-first differential geometry renderer for Jupyter/Colab. Write math in LaTeX, sample it numerically, and render with an interactive Three.js viewer.

Install

pip install geometrix

Quickstart (Notebook)

from geometrix import geom

scene = geom("""
coords: u v
X(u,v) = (u, v, 0)
render: surface X domain u:[0,1] v:[0,1] res 30 30
""")
scene.show()

LaTeX-First Workflow

import sympy as sp
from geometrix import latex, show
from geometrix.api import SceneBundle
from geometrix.sample.domains import Domain
from geometrix.sample.surface import sample_surface_grid
from geometrix.scene.build import build_surface_scene
from geometrix.symbolic.compile import compile_vector

u, v = sp.symbols("u v")
x = latex("u", show_latex_expr=True)
y = latex("v", show_latex_expr=True)
z = latex("\\sin(u)\\cos(v)", show_latex_expr=True)

compiled = compile_vector([x, y, z], [u, v])
surface = sample_surface_grid(
    compiled,
    [Domain("u", -sp.pi.evalf(), sp.pi.evalf()), Domain("v", -sp.pi.evalf(), sp.pi.evalf())],
    [60, 60],
)
scene = build_surface_scene(surface.positions, surface.grid_shape)
show(SceneBundle(scene=scene, arrays={"positions": surface.positions}))

Viewer Controls

  • Toggle axes, grid, gizmo, legend, and light mode.
  • Drag gizmo arrow tips to move the locator; coordinates update in the panel.
  • Grid planes and tick labels adapt to the data range.

Input Types

  • LaTeX expressions via latex() (math-first workflow).
  • DSL blocks via geom(...) for quick parametric surfaces.
  • Python arrays for points/lines/meshes (via points(), line(), mesh()).

Symbolic Utilities

import sympy as sp
from geometrix import canonicalize, simplify, solve

x = sp.symbols("x")
expr = (x**2 - 1) / (x - 1)
print(canonicalize(expr))
print(simplify(expr, mode="factor"))
print(solve([x**2 - 1], [x], dict=True))

Coordinate Helpers

import numpy as np
from geometrix import cylindrical_to_cartesian, spherical_to_cartesian, lorentz_metric

r, theta, z = np.array([1.0]), np.array([0.5]), np.array([0.0])
xyz = cylindrical_to_cartesian(r, theta, z)
metric = lorentz_metric()

Notes

  • LaTeX parsing uses a safe allowlist of commands; unknown commands are rejected.
  • Indices use the symbols i, j, k, l, m, n, a, b, c, d by default.
  • The HTML renderer loads Three.js from a CDN (no widget install needed).

Examples

See examples/ for points, lines, surfaces, DSL, and LaTeX demos.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geometrix-0.1.16.tar.gz (227.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geometrix-0.1.16-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file geometrix-0.1.16.tar.gz.

File metadata

  • Download URL: geometrix-0.1.16.tar.gz
  • Upload date:
  • Size: 227.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for geometrix-0.1.16.tar.gz
Algorithm Hash digest
SHA256 c019d5c5b83bb857f5abc8276d4a685ceaaed169b8c6a60a0d3435ae9c973b37
MD5 95e3e12918448f81fd4830520bb90f88
BLAKE2b-256 4c6cfe3a36bc7786146b854f3be9eccc991cfc2a8b59931c81e69aadcaa9dcd3

See more details on using hashes here.

File details

Details for the file geometrix-0.1.16-py3-none-any.whl.

File metadata

  • Download URL: geometrix-0.1.16-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for geometrix-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 caf7a741156680284581d6fc198a022b9d79df5574c44001b28bb936479d978e
MD5 119b3750a6fea81ae82a6c8de4d9dcde
BLAKE2b-256 e39c8361b9974c6171b875223c8529250480c4b00269972b71c427444f412e11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page