12
$\begingroup$
p1 := y /. {First[Solve[x^2 + y^2 + x == 1, y, Reals]]}
{ConditionalExpression[-Sqrt[1 - x - x^2], 
   1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]}

I want to get the -Sqrt[1 - x - x^2] out of the conditional expression and assign it to a variable. I don't care about the conditions, I'm aware of them and need the expression for use out of the ConditionalExpression. How do I do that?

I tried list commands combinations (Flatten, First, etc.) but they don't work with this. Am I just supposed to copy-paste?

$\endgroup$
  • 2
    $\begingroup$ Have you tried Part? Like in %[[1,1]]. (By the way, with := you should not get any output, perhaps you meant p1=...). $\endgroup$ – Peltio Dec 10 '13 at 5:33
22
$\begingroup$

You can use Normal, ConditionalExpression is not explicitly mentioned there but documentation says it deals with special forms.

p1 = y /. {First[Solve[x^2 + y^2 + x == 1, y, Reals]]} // First
 ConditionalExpression[-Sqrt[1 - x - x^2], 1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]
Normal @ p1
-Sqrt[1 - x - x^2]
$\endgroup$
  • $\begingroup$ Ah didn't know Normal can handle this! +1! $\endgroup$ – Silvia Dec 10 '13 at 8:11
7
$\begingroup$

You can forcely specify the condition to be True:

Solve[x^2 + y^2 + x == 1, y, Reals] /.
 ConditionalExpression[e_, _] :> ConditionalExpression[e, True]
{{y -> -Sqrt[1 - x - x^2]}, {y -> Sqrt[1 - x - x^2]}}

But you should always keep it in mind that this is not an identical transformation.

$\endgroup$
1
$\begingroup$
Simplify[ConditionalExpression[-Sqrt[1 - x - x^2], 
  1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])],
 1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]

 (*    -Sqrt[1 - x - x^2]       *)
$\endgroup$
0
$\begingroup$

another way is to use Simplify or Fullsimplify

Simplify @@ 
 ConditionalExpression[-Sqrt[1 - x - x^2], 
  1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]

returns

-Sqrt[1 - x - x^2]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.