Skip to content

feat(mv): add __rtruediv__ to support scalar/Mv expressions#543

Merged
utensil merged 2 commits intopygae:masterfrom
utiberious:fix/issue-512-mv-rtruediv
Mar 30, 2026
Merged

feat(mv): add __rtruediv__ to support scalar/Mv expressions#543
utensil merged 2 commits intopygae:masterfrom
utiberious:fix/issue-512-mv-rtruediv

Conversation

@utiberious
Copy link
Copy Markdown
Contributor

Summary

Adds __rtruediv__ to the Mv class so that expressions like 1/mv and scalar/mv work as expected, computing scalar * mv.inv().

Previously, 1/mv would raise a TypeError because Python's int.__truediv__ doesn't know how to handle Mv objects and Mv didn't implement __rtruediv__.

Fixes #512

Changes

  • galgebra/mv.py: Add __rtruediv__ method that wraps the scalar as an Mv and multiplies by self.inv()
  • test/test_mv.py: Add tests for 1/I, 2/v, and S(3)/I

Test plan

  • pytest test/ -v passes
  • Full CI with nbval notebooks passes

Expressions like 1/I where I is a pseudoscalar previously raised an
exception because Python's int/float types cannot handle division by
an Mv object. This adds __rtruediv__ so that scalar/Mv is computed
as Mv(scalar) * Mv.inv().

Fixes #1
@utensil
Copy link
Copy Markdown
Member

utensil commented Mar 30, 2026

Tests look good. Checked against kingdon's approach — they use the same convention (A / mv = A * mv⁻¹) and their own test for this is actually just assert x.inv() == 1/x in 2D Euclidean, so this PR is already more thorough than the reference impl.

Two minor gaps worth noting: no test with a symbolic numerator (e.g. symbols('a') / v), and no non-Euclidean metric. Neither is blocking: kingdon doesn't cover them either.

@utiberious utiberious changed the title Add __rtruediv__ to Mv to support 1/Mv expressions Add __rtruediv__ to Mv to support scalar/Mv expressions Mar 30, 2026
@utiberious
Copy link
Copy Markdown
Contributor Author

Thanks for the review! Added both suggested test cases:

  • Symbolic numerator: symbols('a') / I
  • Non-Euclidean metric: Minkowski-like g=[1, -1] with an invertible vector

Pushed in 5c1f0ac.

@utiberious utiberious changed the title Add __rtruediv__ to Mv to support scalar/Mv expressions feat(mv): add __rtruediv__ to support scalar/Mv expressions Mar 30, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.95%. Comparing base (8f661e3) to head (5c1f0ac).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #543      +/-   ##
==========================================
- Coverage   78.93%   72.95%   -5.98%     
==========================================
  Files          19       19              
  Lines        4452     4452              
==========================================
- Hits         3514     3248     -266     
- Misses        938     1204     +266     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@utensil
Copy link
Copy Markdown
Member

utensil commented Mar 30, 2026

Tests look good, thanks!

The coverage drop is likely a codecov artifact. Codecov itself says all modified lines are covered.

@utensil utensil merged commit ab557e8 into pygae:master Mar 30, 2026
7 of 8 checks passed
@utensil utensil added enhancement component: core Ga, Mv, Metric, etc state: needs changelog Needs a changelog entry before the next release. Remove this label when the changelog is done. labels Mar 30, 2026
@utensil utensil added this to the 0.6.0 milestone Mar 31, 2026
utiberious added a commit to utiberious/galgebra that referenced this pull request Apr 1, 2026
Groups new entries by: features, bug fixes, examples/docs, tests/maintenance.

Features: Cl() kingdon interface (pygae#550, closes pygae#524), Mv.__rtruediv__
(pygae#543, closes pygae#512), shirokov_inverse/hitzer_inverse (pygae#530).

Bugs: interop dual mode contamination (pygae#556, closes pygae#555), norm() Abs
wrapping (pygae#554, closes pygae#522), is_versor() improvement (pygae#536, closes pygae#533).

Examples/docs: sundial + cheatsheet tests (pygae#549+pygae#557, closes pygae#506),
coords tutorial (pygae#551), README ops (pygae#548, closes pygae#523).

Tests/maintenance: lt.matrix() regression tests (pygae#558, closes pygae#461),
extra-cdot regression test (pygae#545), er_blade + ReciprocalFrame refactors
(pygae#552+pygae#553), CI fix (pygae#535).
utensil pushed a commit that referenced this pull request Apr 1, 2026
* docs: add 0.6.0 changelog entries

Groups new entries by: features, bug fixes, examples/docs, tests/maintenance.

Features: Cl() kingdon interface (#550, closes #524), Mv.__rtruediv__
(#543, closes #512), shirokov_inverse/hitzer_inverse (#530).

Bugs: interop dual mode contamination (#556, closes #555), norm() Abs
wrapping (#554, closes #522), is_versor() improvement (#536, closes #533).

Examples/docs: sundial + cheatsheet tests (#549+#557, closes #506),
coords tutorial (#551), README ops (#548, closes #523).

Tests/maintenance: lt.matrix() regression tests (#558, closes #461),
extra-cdot regression test (#545), er_blade + ReciprocalFrame refactors
(#552+#553), CI fix (#535).

* docs: add missing issue link for #551 entry

* docs: add changelog entry for #560 (Lt callable zero fix)

* docs: move Lt zero fix into bug group, use issue #540 as reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: core Ga, Mv, Metric, etc enhancement state: needs changelog Needs a changelog entry before the next release. Remove this label when the changelog is done.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expression like 1/<Mv> raise exception

2 participants