Skip to main content

A lazy-evaluation symbolic calculator, geometric primitive engine, and constraint solver built on SymPy.

Project description

lazysym

A lazy-evaluation symbolic calculator, geometric primitive engine, and constraint solver built on SymPy.

lazysym overloads standard Python operators on wrapped symbols, vectors, matrices, physical quantities, and geometric entities to defer evaluation, enabling fluent definition of complex math systems that are solved dynamically.

Installation

pip install lazysym

Quick Start

1. Symbolic Calculations & Equation Solving

Define symbolic variables in a context, register constraints (using native Python operators), and solve for target variables.

from lazysym import Context

ctx = Context()
x = ctx.Symbol('x')
y = ctx.Symbol('y')

# Register equations
ctx.given(
    2 * x + y == 10,
    x - y == 2
)

# Solve dynamically
print("x =", ctx.find(x))  # x = 4
print("y =", ctx.find(y))  # y = 2

2. Physical Quantities with Units

Perform arithmetic across different units with automatic base conversion.

from lazysym import Quantity

# Quantities auto-convert to a base representation during operations
distance1 = Quantity(5, 'km')
distance2 = Quantity(500, 'm')

total = distance1 + distance2
print(total)                # 5.5 km
print(total.convert_to('m')) # 5500.0

3. Constraint Satisfaction (Digit/Alphametic Solvers)

Solve discrete constraint-satisfaction problems or cryptarithms using digit domains and numerical constraints.

from lazysym import Context

ctx = Context()

# Define digits with ranges
A = ctx.Digit('A', domain=(1, 9))
B = ctx.Digit('B', domain=(0, 9))

# Add constraints (e.g. A + B must equal 10, and A must be a prime number)
ctx.given(
    A + B == 10,
    A.isPrime()
)

# Find all valid combinations
solutions = ctx.findAll(A, B)
print(solutions)  # [(2, 8), (3, 7), (5, 5), (7, 3)]

4. Geometry and Selection Transformations (2D & 3D)

Construct points, lines, circles, spheres, and other geometric primitives in a canvas environment. Group entities into a selection to perform bulk spatial transformations (translation, rotation, scaling, dilation, reflection).

from lazysym import Context, Plot

ctx = Context()
plot = Plot(ctx, dim=2)

p1 = plot.Point('p1', 0, 0)
p2 = plot.Point('p2', 3, 4)

# Calculate dynamic distances
distance = p1.distance(p2)
print("Distance:", distance)  # Distance: 5 m

# Create a circle at p1
circle = plot.Circle('c1', center=p1, radius=5)

# Selection-based bulk transformation
selection = plot.selection(p1, circle)
selection.translate(dx=10, dy=5)

# Original points are modified in-place
print(p1.x, p1.y)          # 10, 5
print(circle.center.coords()) # (10, 5)

5. Custom Matrix & Vector Wrappers

Construct vectors and matrices with custom support for dot products, cross products, and matrix multiplication under symbolic contexts.

from lazysym import Context

ctx = Context()

# Access namespace matrices and vectors
v1 = ctx.Vector.Vector([1, 2, 3])
v2 = ctx.Vector.Vector([4, 5, 6])

print("Dot product:", v1.dot(v2))    # 32
print("Cross product:", v1.cross(v2))  # Vector([-3, 6, -3])

Features

  • Deferred Symbolic Operations: Overloaded magic methods map arithmetic and comparison operators directly into SymPy expressions.
  • Physical Quantities System: Pre-configured factors for metric units (m, cm, mm, km), imperial units (inch, ft, yd, mi), and angles (radians, degrees, gradians, turns).
  • Geometric Primitives: 2D/3D support for points, lines, rays, segments, circles, spheres, triangles, ellipses, parabolas, cylinders, cones, and planes.
  • Dynamic Solver Contexts: Behind the scenes, the context uses SymPy solver utilities to resolve systems of equations, with automatic coordinate gauge-fixing for under-constrained geometric layouts.
  • Sequence Patterns: Built-in support for evaluating arithmetic or custom recurrence relations based on pattern configuration.

License

MIT

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

lazysym-1.0.2.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

lazysym-1.0.2-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file lazysym-1.0.2.tar.gz.

File metadata

  • Download URL: lazysym-1.0.2.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lazysym-1.0.2.tar.gz
Algorithm Hash digest
SHA256 996472d2be5ab484ae3dd21b963c9b21c8e9ce545161be3e792641c7680567a8
MD5 3aead3ebe236e1d906436c670cc5109f
BLAKE2b-256 53d004c40131f8b89fdc9fa34b9758be21369520d805643dfd2299ffadbc6cb0

See more details on using hashes here.

File details

Details for the file lazysym-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: lazysym-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lazysym-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12d4c85d11523a15366f074a4c4bb9d75cb6d6c8c309c3b5fe99bf5ed6820edb
MD5 f1adb3b8f6743006f11fcb2a0c8807ed
BLAKE2b-256 37ef368b766921c21918582103ce030dc0e145211f298270210fc53f9afe2a15

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