Wikipedia:Reference desk/Archives/Mathematics/2007 March 12

= March 12 =

mathematica
In[13]:= Simplify[x^2==9,x>0]

Out[13]= x^2 == 9

In mathematica 5.2, why does mathematica not output the answer " x == 3  "

211.28.238.164 05:01, 12 March 2007 (UTC)


 * You misstate the request. What you want is
 * Reduce[x^2 == 9 && x > 0]
 * This does produce
 * x == 3
 * as you wish. --KSmrqT 05:36, 12 March 2007 (UTC)


 * As to why, this is because Simplify simplifies sets of equations, not inequations. Reduce simplifies sets of inequations and equations.


 * That's not really . Simplify works with inequalities just fine (try Simplify[2x>2]) but only uses a very limited set of tools. Also, it doesn't actually simplify a set of equations - it simplifies a single expression (which could be an equation) under a set of assumptions. FullSimplify is slower but gives better results - for example, FullSimplify[x^2==9, x>0] works. -- Meni Rosenfeld (talk) 20:02, 12 March 2007 (UTC)


 * Mathematica is a large complicated beast, with many ways to approach the same problem. Simplification is known to be a tough problem for several reasons. One is that we have no universal definition of "simpler"; another is computational complexity. Both Simplify and FullSimplify use sets of heuristics — guesses at potentially helpful transformations — hoping to get somewhere. By contrast, Reduce uses the idea of cylindrical algebraic decomposition, which can be horrendously slow but effectively thorough. For example,
 * Reduce[x^2 == 9]
 * produces
 * x == -3 || x == 3
 * which not even FullSimplify will do. Another tool is <tt>Solve</tt>, and indeed
 * <tt>Solve[x^2 == 9]</tt>
 * produces
 * <tt>{{x -> -3}, {x -> 3}}</tt>
 * much like <tt>Reduce</tt>; however, we have no way to insist on the positive solution. Can we conclude that <tt>Reduce</tt> is the best tool? No; for consider that
 * <tt>Reduce[z == Cos[x]^2 + Sin[x]^2]</tt>
 * does nothing, producing
 * <tt>z == Cos[x]^2 + Sin[x]^2</tt>
 * in contrast to
 * <tt>Simplify[z == Cos[x]^2 + Sin[x]^2]</tt>
 * which produces
 * <tt>z == 1</tt>
 * as we would hope. Also, we may sometimes settle for <tt>FindInstance</tt>. Note: Obviously we are exploring trivial examples, as practice for the real challenges. --KSmrqT 23:40, 12 March 2007 (UTC)
 * Is there a way to say
 * <tt>Solve[x^2 == 9] // SelectPositive </tt>
 * produces
 * <tt></tt>
 * 202.168.50.40 01:36, 13 March 2007 (UTC)


 * Use Select with a suitable anonymous function, then apply it to the solution list. —The preceding unsigned comment was added by 129.78.64.102 (talk) 02:39, 13 March 2007 (UTC).


 * Create a function called SelectPositive and then use it to filter the result of Solve
 * <tt>In[1]:= SelectPositive[soln_]:= Select[ soln, Part[FullForm[#], 1, 1, 2] ≥ 0 &  ]</tt>
 * <tt>In[2]:= Solve[x^2 == 9, x] // SelectPositive</tt>
 * <tt>Out[2]:= </tt>
 * 211.28.123.23 06:19, 13 March 2007 (UTC)
 * This one is slightly better because it can handle complex numbers
 * <tt>In[3]:= SelectPositive2[soln_] := Select[ soln,  Function[X, Module[{val}, val = Part[FullForm[X], 1, 1, 2]; Abs[val] == val ]]] </tt>
 * <tt>In[4]:= Solve[x^2 == 16, x] // SelectPositive2</tt>
 * <tt>Out[4]:= </tt>
 * 211.28.123.23 07:25, 13 March 2007 (UTC)


 * You can't consistently assign an ordering to the complexes.
 * You dont need to assign an ordering, merely get a True / False response
 * <tt>In[1]:= Abs[ 3+4I ] == ( 3+4I )     (* Abs[ 3 + 4i ] == 3 + 4i *)</tt>
 * <tt>Out[1]= False</tt>
 * <tt>In[2]:= Abs[-5] == -5</tt>
 * <tt>Out[2]= False</tt>
 * <tt>In[3]:= Abs[3] == 3</tt>
 * <tt>Out[3]= True</tt>
 * <tt>In[4]:= Abs[0] == 0</tt>
 * <tt>Out[4]= True</tt>
 * Call me old-fashioned, but I'm uncomfortable with zero being considered positive. Now might be the time to break out <tt>Element[x,Reals]</tt>. Also, this <tt>Select</tt> approach may force us to work finding many roots that we then discard; for some problems, not such a good idea. --KSmrqT 23:38, 13 March 2007 (UTC)
 * If you prefer you can always change it to
 * <tt>Abs[val] == val && Abs[val] > 0</tt>
 * and filter out zero as well.
 * 211.28.123.23 00:15, 14 March 2007 (UTC)
 * If you prefer you can always change it to
 * <tt>Abs[val] == val && Abs[val] > 0</tt>
 * and filter out zero as well.
 * 211.28.123.23 00:15, 14 March 2007 (UTC)


 * Still, you need to have defined some sense of how a complex number is "positive" or not, and there are a few ways of doing this.