text: # Using the output of Solve
  
  I had a math problem I solved like this:
  
  ``````In[1]:= Solve[2x(a-x)==0, x]
  Out[1]= {{x->0}, {x->a}}
  
  In[2]:= Integrate[2x(a-x), {x,0,a}]
  Out[2]= (a^3)/3
  
  In[3]:= Solve[(a^3)/3==a, a]
  Out[3]= {{a->0}, {a->-Sqrt[3]}, {a->Sqrt[3]}}
  ``````
  
  My question is if I could rewrite this to compute it in one step, rather than having to manually input the result from the previous line. I could easily replace the integral used in step three with the `Integrate` command from step two. But what I can't figure out is how I would use the result from step 1 as the limits of integration in the integral.
  
  -
  
  You could combine step 1 and 2 by doing something like
  
  ``````Integrate[2 x (a - x), {x, ##}] & @@ (x /. Solve[2 x (a - x) == 0, x]);
  ``````
  -
  `Integrate[2 x (a - x), {x, ##}] & @@ (x /. Solve[2 x (a - x) == 0, x])//Solve[#==a,a]&` gets all three steps together. –  kguler Dec 2 '11 at 11:09
  @kguler, post it as an answer, alongside an explanation of what it is doing. I'd vote for it. –  rcollyer Dec 2 '11 at 14:05
  @rcollyer, Thank you! I think Heike's answer adresses the specific question asked. What I added is just piping the expression produced by Heike's answer into the pure function `Solve[#==a,a]`. I think some would enjoy to play with the following pure function that combines all three steps: ```solveIntegrateSolve := (Integrate[#1, {#2, ## & @@ (#2 /. Solve[#1 == 0, #2])}] // (Solve[# == t, t] & /. t -> #3)) &```. Use it as `solveIntegrateSolve[2x(a-x),x,a]` or `solveIntegrateSolve@@{2x(a-x),x,a}`. –  kguler Dec 3 '11 at 0:22
  Nice, ReplaceAll elegantly gets the values out of the result `Solve` produces. Now why didn't I think of that? –  Mr Alpha Dec 3 '11 at 9:12
  
  If you agree to delegate the choice of the (positive oriented) domain to `Integrate`, by means of using `Clip` or `Boole`:
  
  ``````In[77]:= Solve[
  Integrate[
  Clip[2 x (a - x), {0, Infinity}], {x, -Infinity, Infinity}] == a, a]
  
  Out[77]= {{a -> 0}, {a -> Sqrt[3]}}
  ``````
  
  or
  
  ``````In[81]:= Solve[
  Integrate[
  2 x (a - x) Boole[2 x (a - x) > 0], {x, -Infinity, Infinity}] ==
  a, a]
  
  Out[81]= {{a -> 0}, {a -> Sqrt[3]}}
  ``````
  
  The reason only non-negative roots are found, is that `Integrate` will integrate from the smallest root to the largest root, i.e. from `{x,0,a}` for positive `a` and `{x,a,0}` for negative `a`.
  
  -
explanation: The document contains a math question related to using Mathematica to solve a problem in a more streamlined way. The user asks if it is possible to combine multiple steps into one, specifically how to use the result from solving an equation as the limits of integration in an integral. The document also includes answers and suggestions from other users on how to achieve this.
distilabel_metadata.content: Evaluate the user given text extract and determine if it contains a math question and optionally and answer to this question.
  
  Output rules:
  
  1. Briefly describe the document and mention if it contains a question or a question and answer.
  2. Finalize the output with: Label: no-question,question,question-and-answer,multiple-question,multiple-question-and-answer
distilabel_metadata.role: system
distilabel_metadata.content: # Using the output of Solve
  
  I had a math problem I solved like this:
  
  ``````In[1]:= Solve[2x(a-x)==0, x]
  Out[1]= {{x->0}, {x->a}}
  
  In[2]:= Integrate[2x(a-x), {x,0,a}]
  Out[2]= (a^3)/3
  
  In[3]:= Solve[(a^3)/3==a, a]
  Out[3]= {{a->0}, {a->-Sqrt[3]}, {a->Sqrt[3]}}
  ``````
  
  My question is if I could rewrite this to compute it in one step, rather than having to manually input the result from the previous line. I could easily replace the integral used in step three with the `Integrate` command from step two. But what I can't figure out is how I would use the result from step 1 as the limits of integration in the integral.
  
  -
  
  You could combine step 1 and 2 by doing something like
  
  ``````Integrate[2 x (a - x), {x, ##}] & @@ (x /. Solve[2 x (a - x) == 0, x]);
  ``````
  -
  `Integrate[2 x (a - x), {x, ##}] & @@ (x /. Solve[2 x (a - x) == 0, x])//Solve[#==a,a]&` gets all three steps together. –  kguler Dec 2 '11 at 11:09
  @kguler, post it as an answer, alongside an explanation of what it is doing. I'd vote for it. –  rcollyer Dec 2 '11 at 14:05
  @rcollyer, Thank you! I think Heike's answer adresses the specific question asked. What I added is just piping the expression produced by Heike's answer into the pure function `Solve[#==a,a]`. I think some would enjoy to play with the following pure function that combines all three steps: ```solveIntegrateSolve := (Integrate[#1, {#2, ## & @@ (#2 /. Solve[#1 == 0, #2])}] // (Solve[# == t, t] & /. t -> #3)) &```. Use it as `solveIntegrateSolve[2x(a-x),x,a]` or `solveIntegrateSolve@@{2x(a-x),x,a}`. –  kguler Dec 3 '11 at 0:22
  Nice, ReplaceAll elegantly gets the values out of the result `Solve` produces. Now why didn't I think of that? –  Mr Alpha Dec 3 '11 at 9:12
  
  If you agree to delegate the choice of the (positive oriented) domain to `Integrate`, by means of using `Clip` or `Boole`:
  
  ``````In[77]:= Solve[
  Integrate[
  Clip[2 x (a - x), {0, Infinity}], {x, -Infinity, Infinity}] == a, a]
  
  Out[77]= {{a -> 0}, {a -> Sqrt[3]}}
  ``````
  
  or
  
  ``````In[81]:= Solve[
  Integrate[
  2 x (a - x) Boole[2 x (a - x) > 0], {x, -Infinity, Infinity}] ==
  a, a]
  
  Out[81]= {{a -> 0}, {a -> Sqrt[3]}}
  ``````
  
  The reason only non-negative roots are found, is that `Integrate` will integrate from the smallest root to the largest root, i.e. from `{x,0,a}` for positive `a` and `{x,a,0}` for negative `a`.
  
  -
distilabel_metadata.role: user
distilabel_metadata.raw_output_q_a_detector_0: The document contains a math question related to using Mathematica to solve a problem in a more streamlined way. The user asks if it is possible to combine multiple steps into one, specifically how to use the result from solving an equation as the limits of integration in an integral. The document also includes answers and suggestions from other users on how to achieve this.
  
  Label: question-and-answer