Skip to content

Commit

Permalink
Check equality of Cross arguments after simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ratnania committed Mar 2, 2024
1 parent 7f83e33 commit 74e7475
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions sympde/calculus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ def __new__(cls, arg1, arg2, **options):
a,b = b,a
c = -c

# after simplifications, the expression can be reduced to 0 in some cases
# here's an example;
# if b is a Vector and u and v are scalar functions,
# we should have the following
# cross(b*u,b*v) = u*v*cross(b,b) = 0
if a == b:
return S.Zero

obj = Basic.__new__(cls, a, b)

return c*obj
Expand Down
18 changes: 12 additions & 6 deletions sympde/expr/tests/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,12 @@ def test_matrices_vectors():
assert not A1 == A
# ...

# ... some tests on cross operator & vectors
assert cross(b,b) == 0
assert cross(b*u,b*u) == 0
assert cross(b*u,b*v) == 0
# ...

########################################################################
# SCALAR-FUNCTION CASE
########################################################################
Expand Down Expand Up @@ -2021,12 +2027,12 @@ def test_matrices_vectors():
assert is_linear_expression(f(u,v), (v,))
# ...

# # ...
# f = lambda u,v: cross(b*u, b*v)
#
# assert is_linear_expression(f(u,v), (u,))
# assert is_linear_expression(f(u,v), (v,))
# # ...
# ...
f = lambda u,v: cross(b*u, b*v)

assert is_linear_expression(f(u,v), (u,))
assert is_linear_expression(f(u,v), (v,))
# ...

# ...
f = lambda u,v: cross(b*u, grad(v))
Expand Down

0 comments on commit 74e7475

Please sign in to comment.