Skip to content

Commit

Permalink
Merge pull request #26554 from haru-44/default_sort_key
Browse files Browse the repository at this point in the history
Fix min/max using `default_sort_key`
  • Loading branch information
oscarbenjamin committed Apr 30, 2024
2 parents 37bb755 + fc89b52 commit e8ffa81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sympy/functions/special/tensor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def eval(cls, i, j, delta_range=None):
# to make KroneckerDelta canonical
# following lines will check if inputs are in order
# if not, will return KroneckerDelta with correct order
if i != min(i, j, key=default_sort_key):
if default_sort_key(j) < default_sort_key(i):
if delta_range:
return cls(j, i, delta_range)
else:
Expand Down
11 changes: 5 additions & 6 deletions sympy/simplify/sqrtdenest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def is_sqrt(expr):
return expr.is_Pow and expr.exp.is_Rational and abs(expr.exp) is S.Half


def sqrt_depth(p):
def sqrt_depth(p) -> int:
"""Return the maximum depth of any square root argument of p.
>>> from sympy.functions.elementary.miscellaneous import sqrt
Expand All @@ -34,12 +34,11 @@ def sqrt_depth(p):
return 1
if p.is_Atom:
return 0
elif p.is_Add or p.is_Mul:
return max([sqrt_depth(x) for x in p.args], key=default_sort_key)
elif is_sqrt(p):
if p.is_Add or p.is_Mul:
return max(sqrt_depth(x) for x in p.args)
if is_sqrt(p):
return sqrt_depth(p.base) + 1
else:
return 0
return 0


def is_algebraic(p):
Expand Down

0 comments on commit e8ffa81

Please sign in to comment.