Skip to content

Commit

Permalink
Merge pull request #1564 from mathics/quickpatterntest
Browse files Browse the repository at this point in the history
adding some quick pattern tests for PatternTest
  • Loading branch information
rocky authored Aug 25, 2021
2 parents 7cfa65d + 7716c43 commit 8a90e51
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ def init(self, expr):
def quick_pattern_test(self, candidate, test, evaluation):
if test == "System`NumberQ":
return isinstance(candidate, Number)
elif test == "System`RealNumberQ":
if isinstance(candidate, (Integer, Rational, 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`Negative":
if isinstance(candidate, (Integer, Rational, Real)):
return candidate.value < 0
Expand Down

0 comments on commit 8a90e51

Please sign in to comment.