Skip to content

Commit

Permalink
improving quick_pattern_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Aug 25, 2021
1 parent 7f47483 commit e389341
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Real,
SymbolFalse,
SymbolList,
SymbolN,
SymbolTrue,
)
from mathics.core.rules import Rule
Expand Down Expand Up @@ -476,21 +477,38 @@ def init(self, expr):
def quick_pattern_test(self, candidate, test, evaluation):
if test == "System`NumberQ":
return isinstance(candidate, Number)
if test == "System`NumericQ":
if isinstance(candidate, Number):
return True
# Otherwise, follow the standard evaluation
elif test == "System`RealNumberQ":
if isinstance(candidate, (Integer, Rational, Real)):
return True
candidate = Expression(SymbolN, candidate).evaluate(evaluation)
if isinstance(candidate, Real):
return True
return False
# pass
elif test == "System`Positive":
if isinstance(candidate, (Integer, Rational, Real)):
return candidate.value > 0
return False
# pass
elif test == "System`NonPositive":
if isinstance(candidate, (Integer, Rational, Real)):
return candidate.value <= 0
return False
# pass
elif test == "System`Negative":
if isinstance(candidate, (Integer, Rational, Real)):
return candidate.value < 0
return False
# pass
elif test == "System`NonNegative":
if isinstance(candidate, (Integer, Rational, Real)):
return candidate.value >= 0
return False
# pass
elif test == "System`NegativePowerQ":
return (
candidate.has_form("Power", 2)
Expand Down

0 comments on commit e389341

Please sign in to comment.