Mathematica Asked by Antimony51 on April 15, 2021
Consider the following list
list={0 < x < 1/12, 0 < x < 1/4}
I wish to find the intersection of the two ranges of x
and check if the result is an element of the above list, i.e.
In:=Simplify[And @@ list]
out:=0<x<1/12
Now I want to check if the above range of x
belongs to the list
.
in:=MemberQ[list, Simplify[And @@ list]]
out:= False
But It is clear that such a range is an element of list
. This is not giving the expected result because the Heads are not matching.
in:=FullForm[Simplify[And @@ list]]
out:=Inequality[0,Less,x,Less,Rational[1,12]]
Whereas,
in:=FullForm[0 < x < 1/12]
out:=Less[0,x,Rational[1,12]]
How to resolve this?
Your intent is interval arithmetics. Mathematica offers specialized built-ins to deal with intervals.
IntervalUnion[Interval[{0, 1/12}], Interval[{0, 1/4}]]
Interval[{0, 1/4}]
IntervalIntersection[Interval[{0, 1/12}], Interval[{0, 1/4}]]
Interval[{0, 1/12}]
FullForm@IntervalIntersection[Interval[{0, 1/12}], Interval[{0, 1/4}]]
Interval[List,[0,Rational[1,12]]]
This is some a tautology and the check corresponding Your MemberQ input is redundant.
On the other hand there is the built-in IntervalMemberQ
:
IntervalMemberQ[Interval[{0, 1/12}], Interval[{0, 1/15}]]
True
To more directly:
Equal[Inequality[0, Less, x, Less, Rational[1, 12]],
Less[0, x, Rational[1, 12]]]
(0 < x < 1/12) == (0 < x < 1/12)
The output is not True and
Expand[%]
does not alter any.
But
Equivalent@Equal[Inequality[0, Less, x, Less, Rational[1, 12]], Less[0, x, Rational[1, 12]]]
True
Equivalent
represents the logical equivalence of both representation.
Equivalent[%741] // TautologyQ
True
TautologyQ@Equal[Inequality[0, Less, x, Less, Rational[1, 12]],
Less[0, x, Rational[1, 12]]]
False
It is in the terms of Mathematica not a direct tautology, but is set with Equal.
NumberLinePlot[{Interval[{0, 1/4}], Interval[{0, 1/12}]}]
This does not work with the Inequality.
NumberLinePlot[Simplify[And @@ list], {x, 0, .1}]
This brings up the real differences between both representation and how there are meant to be made equal in Mathematica.
And it visualizes the main drawback. The interval in Mathematica is closed, the inequalities are strict and therefore open.
The very most suitable answer is use Reduce:
Reduce[list, x]
0 < x < 1/12
Reduce[Inequality[0, Less, x, Less, Rational[1, 12]], x]
0 < x < 1/12
FullForm of both is the very same.
FullForm@Reduce[Inequality[0, Less, x, Less, Rational[1, 12]], x]
Inequality[0,Less,x,Less,Rational[1,12]]
FullForm@Reduce[list, x] Inequality[0,Less,x,Less,Rational[1,12]]
FullForm@Reduce[Inequality[0, Less, x, Less, Rational[1, 12]], x]==FullForm@Reduce[list, x]
True
Answered by Steffen Jaeschke on April 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP