Skip to content

feat(mv): add components() method for extracting multivector coordinates#547

Closed
utiberious wants to merge 1 commit intopygae:masterfrom
utiberious:fix/issue-483-mv-coords
Closed

feat(mv): add components() method for extracting multivector coordinates#547
utiberious wants to merge 1 commit intopygae:masterfrom
utiberious:fix/issue-483-mv-coords

Conversation

@utiberious
Copy link
Copy Markdown
Contributor

Summary

Adds Mv.components() that returns a dict mapping basis blades to their scalar coefficients, making it easy to extract coordinates from a multivector.

Fixes #483

Changes

  • galgebra/mv.py: Add components() method that iterates over blade expansion and returns {blade_symbol: coefficient} dict
  • test/test_mv.py: Add tests for scalar, vector, and general multivector decomposition

Example

ga, ex, ey, ez = Ga.build('e*x|y|z')
v = 2*ex + 3*ey - ez
v.components()
# {e_x: 2, e_y: 3, e_z: -1}

Test plan

  • Unit tests pass
  • Full CI with nbval notebooks passes

Adds Mv.components() which returns a dictionary mapping each basis
blade to its scalar coefficient. This provides a convenient way to
extract individual coordinates for further processing, e.g.
v.components()[e_1] returns the e_1 coefficient.

Fixes #4
@utensil
Copy link
Copy Markdown
Member

utensil commented Mar 30, 2026

Thanks for this. CI fails on two flake8 errors worth fixing first:

  • F821: Dict not imported in mv.py (only List, Any, Tuple, Union, TYPE_CHECKING are)
  • F811: there's already a components() at mv.py:984 returning List[Mv] sorted by blade order — this PR shadows it with a different return type (Dict[Mv, Expr]). Either replace the existing one intentionally or pick a different name.

Also the mixed-grade test only checks len(comps) == 3, not the actual values.

Kingdon cross-check: MultiVector.items() (multivector.py:147) returns zip(keys, values) with integer blade indices. The dict-with-Mv-keys API here is more ergonomic for a symbolic library, so the idea is sound.

@utensil
Copy link
Copy Markdown
Member

utensil commented Mar 30, 2026

Also worth re-reading #483: the ask was extracting coords as a list for numeric use (math.sin(v1[1])). Greg pointed out blade_coefs() already does this, and the existing components() at mv.py:984 returns sorted List[Mv]. The last commenter's suggestion was to add a tutorial example, not a new method. So if this PR keeps components() as a dict API, it should clarify the value-add over what's already there.

@utensil
Copy link
Copy Markdown
Member

utensil commented Mar 30, 2026

Closing the PR. Please open a new PR for adding the example. Should keep the original components() signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting coords of multivector

2 participants