Skip to content

Commit

Permalink
feat: use sympy norm for better latex
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumJHays committed Jul 2, 2023
1 parent 1ed6c76 commit 58945d5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mathpad/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@ def norm(self) -> Val:
Raises:
ValueError: if the vector does not have uniform dimensionality (each base_unit in the vector space must be equivalent)
"""
from mathpad.functions import sqrt
assert len(set(self.space.base_units)) == 1, "Cannot take the norm of a vector with non-uniform units"

try:
norm_squared = sum(val ** 2 for val in self)
except SumDimensionsMismatchError:
raise ValueError("Cannot take the norm of a vector with non-uniform units")

return sqrt(norm_squared) # type: ignore
return Val(
self.expr.norm(), # type: ignore
self.space.base_units[0] ** 2
)

def __mul__(self, other: Q[Val]):
return Vector(
Expand Down

0 comments on commit 58945d5

Please sign in to comment.