Skip to content

Add user-defined constraint system (Perp, Para) #2

@vkotaru

Description

@vkotaru

Summary

Implement a general constraint system where users can declare geometric relationships between vectors, and have them applied during simplification. Based on the original Scala implementation in symbolic_lhdynamics.ast.ConstraintRules.

Desired API

from geomech import Perp, Para, UserConstraints

q = S2('q')
omega = q.get_tangent_vector()
xi = q.get_variation_vector()

# Declare constraints
UserConstraints.append([
    Perp(omega, q),   # Dot(ω, q) → 0
    Perp(xi, q),      # Dot(ξ, q) → 0
    # Para(a, b),     # Cross(a, b) → 0
])

# Constraints applied during simplification
result = simplify(expr)  # or UserConstraints.apply(expr)

Constraint types

  • Perp(a, b) — substitutes Dot(a, b) → 0 (and Dot(b, a) → 0 by commutativity)
  • Para(a, b) — substitutes Cross(a, b) → 0

Reference

Original Scala implementation: /home/prasanth/Workspace/git/vkotaru/symbolic_lhdynamics in symbolic_lhdynamics/ast/ConstraintRules.scala

Key design from old package:

  • UserConstraints is a global mutable list of active constraints
  • ConstraintRules.apply(expr, rule) uses expr.subs(Dot(u,v), Number(0)) for Perp
  • Constraints are applied as a post-processing step

Notes

  • This is more general than hardcoding S2/SO3 orthogonality rules in vector_rules.py
  • Should support reset() to clear constraints between different systems
  • Consider whether to integrate into simplify() pipeline or keep as a separate apply step
  • The commented-out code in the Scala version shows plans for vector/matrix substitution rules (applyConstraintsV, applyConstraintsM) — consider this for future extension

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions