Skip to content

Commit

Permalink
Between rule for several intervals (#1291)
Browse files Browse the repository at this point in the history
Add rule for `Between` list of ranges.
  • Loading branch information
mmatera authored Jan 15, 2025
1 parent c8788d7 commit 93b3284
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mathics/builtin/testing_expressions/equality_inequality.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ class Between(Builtin):
<dl>
<dt>'Between'[$x$, {$min$, $max$}]
<dd>equivalent to $min$ <= $x$ <= $max$.
## <dt>'Between[$x$, { {$min1$, $max1$}, {$min2$, $max2$}, ...]'
## <dd>equivalent to $min1$ <= $x$ <= $max1$' || $min2$ <= $x$ <= $max2$ ...
<dt>'Between[$x$, { {$min1$, $max1$}, {$min2$, $max2$}, ...]'
<dd>equivalent to $min1$ <= $x$ <= $max1$' || $min2$ <= $x$ <= $max2$ ...
<dt>'Between[$range$]'
<dd>operator form that yields 'Between'[$x$, $range$] when applied to expression $x$.
</dl>
Expand All @@ -365,13 +365,19 @@ class Between(Builtin):
'Between' works with irrational numbers:
>> Between[2, {E, Pi}]
= False
If more than an interval is given, 'Between' returns 'True' if $x$ belongs \\
to one of them:
>> {Between[3, {1, 2}, {4, 6}], Between[5, {1, 2}, {4, 6}]}
= {False, True}
"""

attributes = A_PROTECTED

rules = {
"Between[x_, {min_, max_}]": "min <= x <= max", # FIXME add error checking
# "Between[x_, {ranges__}]": "Apply[Or, Between[#][x]& /@List[ranges]]", # FIXME add error checking
"Between[x_, ranges__List]": "(Do[If[Between[x,range], Return[True]],{range, {ranges}}]===True)",
"Between[range_List][x_]": "Between[x, range]", # operator form
}

Expand Down

0 comments on commit 93b3284

Please sign in to comment.