Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/estimates/order_of_magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def __new__(cls, expr):
if isinstance(expr, OrderOfMagnitude):
return expr

if not expr.is_positive:
# Abs(x) is nonnegative but sympy often leaves .is_positive as None (zero possible).
# Still a valid order of magnitude when not identically zero.
if expr.is_positive:
pass
elif expr.is_nonnegative is True and expr.is_zero is not True:
pass
else:
print(f"Warning: a non-positive argument {expr!s} was passed to Theta.")
return Undefined()

Expand Down
9 changes: 9 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,12 @@ def test_subst_all_solution_reversed(self, capsys):
def test_sympy_simplify_solution(self, capsys):
sympy_simplify_solution()
self.proof_complete(capsys)

def test_theta_abs_nonnegative(self):
"""Theta(Abs(n)) must not become Undefined when positivity is unknown."""
from sympy import Abs, Symbol
from estimates.order_of_magnitude import Theta, Undefined
n = Symbol("n", integer=True)
t = Theta(Abs(n))
assert not isinstance(t, Undefined)
assert str(t).startswith("Theta")
Loading