# Assign condition to variable

I would like to integrate the output of a Solve. But Solve gives me an expression with some conditions. I would like to assign this condition to variables.

For example:

ysol = Solve[x^2 + y^2 + x == 1, y, Reals]

y1 = ysol[[1, 1, 2]]


Thus, y1=ConditionalExpression[-Sqrt[1 - x - x^2], 1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])].

I would like to automatically assign:

a = 1/2 (-1 - Sqrt[5])
b = 1/2 (-1 + Sqrt[5])

• a=y1[[-1, 1]]; b=y1[[-1, -1]]; Commented Jul 22 at 19:54

To be more general, you can directly use the condition from ConditionalExpression (by accessing Last[y1] or y1[[2]]) and feed it into ImplicitRegion:

Integrate[Normal[y1], {x} ∈ ImplicitRegion[Last[y1], x]]
(* -(5 π)/8 *)


To extract the minimum and maximum, you can use MinValue and MaxValue:

{a, b} = {MinValue[{x, Last[y1]}, x], MaxValue[{x, Last[y1]}, x]}
(* {1/2 (-1 - Sqrt[5]), 1/2 (-1 + Sqrt[5])} *)

• Thanks, you helped me even more than I needed! But to clarify, I would like to ask another question about this ImplicitRegion. Let's suppose, I consider the following function: y1=ConditionalExpression[x, 1 < x < 2 || 5 < x < 7]. Thus, the integration you mentioned over ImplictRegion is equivalent to this expression: Integrate[x, {x, 1,2}] + Integrate[x, {x, 5,7}]? Commented Jul 23 at 11:06
• @blahblah, yes. Commented Jul 23 at 12:38