# Another using Solve output for further calculations

I probably missed a question already posted as this topic seems common, but I looked at several, e.g. Using result of Solve in further calculations and am a little stuck. I didn't understand the use of Prefix in this one (which only had 1 solution anyway): Using Solve outputs for further calculations

Even this one: Using the result of Solve in subsequent calculations which looked promising, doesn't seem to have a way of automatically selecting solutions (this one only had 1 again). Maybe I am overlooking how to use these methods but I cannot make the connection...

If I have something like,

eq1 = x^2 - 3*y^2 + 3
sol = Reduce[eq1 == 0, y, Complexes]
sol[[1]][[2]]
eq2[i_] = 100 + (y /. y -> sol[[i]][[2]])

Part::pkspec1: The expression i cannot be used as a part specification.


I made sure not to use SetDelayed, and I know I can do things like,

100 + (y /. y -> sol[[1]][[2]])


where 100 + y is a new function, but the 1 is chosen by the script itself automatically and can't be 'hard-coded'.

What kind of methodology can one use when there are functions calling functions calling.... etc, that ultimately depend on an automatic choice of a solution set?

PS.

I also tried name a set of rules, but I cannot hold the left side unevaluated (like a ' in Lisp), how do I control the output of Reduce function?

solSet = Table[Unevaluated[y] -> y /. y -> sol[[i]][[2]], {i, 1, 2}]


I guess this is more likely to be (though still fails)

solSet = {ToRules[sol]}
eq3[i_] = 100 + y/.solSet[[i]]


What I would want is (in pseudo-code):

eq1 = x^2 -3*y^2 + 3
sol = Reduce[eq1==0,y,Complexes]
eq2[i_] = 100 + sol[[i]][[2]]
eq2[1] = 100 + solution_one
eq2[2] = 100 + solution_two
eq3[i_,j_] = A*eq2[i] + B*eq2[j];
etc
etc

• What do you want to get as a result? Commented Feb 25, 2019 at 1:06
• well i guess i want a function that uses an index to select which solution value to use, e.g. eq2[1] ----> 100 + sol[[1]][[2]] or eq2[2] -----> 100 + sol[[2]][[2]]...and in even more nested functions
– nate
Commented Feb 25, 2019 at 1:11
• But the solution sol is y == -(Sqrt[3 + x^2]/Sqrt[3]) || y == Sqrt[3 + x^2]/Sqrt[3]. You can use a replacement eq2[i_] := sol[[i]] /. {y -> 100 + z} Commented Feb 25, 2019 at 1:21
• well I get then: 100 + z == -(Sqrt[3 + x^2]/Sqrt[3]) which isn't really a result (unless I'm doing something wrong). But also, if the enveloping function isn't simple (like 100 + last_choice_of_solution) then it would be difficult to type.
– nate
Commented Feb 25, 2019 at 1:31
• The question remains, what do you want to get? Commented Feb 25, 2019 at 4:32

Much more in the spirit of the question, J.M. had a better answer:

In[1]:= sol =
y /. {ToRules[
Reduce[x^2 - 3 y^2 + 3 == 0, y, Complexes,
Backsubstitution -> True]]}

Out[1]= {-(Sqrt[3 + x^2]/Sqrt[3]), Sqrt[3 + x^2]/Sqrt[3]}

In[2]:= eq2[i_] := 100 + Indexed[sol, i]

In[4]:= eq2[1]
eq2[2]

Out[4]= 100 - Sqrt[3 + x^2]/Sqrt[3]

Out[5]= 100 + Sqrt[3 + x^2]/Sqrt[3]


Noting that the original problem was complaints of using [[i]] (I think effectively Part[]) to reference the solutions, I add the interesting (to me) observation that the function oop uses Part but does not suffer from the same error, and allows the further building of functions.

In[6]:= oop[i_, ch_] := h /. Part[Solve[eq2[i] + h^2 == 0, h], ch, 1]

In[8]:= oop[1, 1]
oop[1, 2]
oop[2, 1]
oop[2, 2]

Out[8]= -Sqrt[-100 + Sqrt[3 + x^2]/Sqrt[3]]

Out[9]= Sqrt[-100 + Sqrt[3 + x^2]/Sqrt[3]]

Out[10]= -(Sqrt[-300 - Sqrt[3] Sqrt[3 + x^2]]/Sqrt[3])

Out[11]= Sqrt[-300 - Sqrt[3] Sqrt[3 + x^2]]/Sqrt[3]


In[1]:= eq1 = x^2 - 3*y^2 + 3

Out[1]= 3 + x^2 - 3 y^2

In[2]:= sol = Reduce[eq1 == 0, y, Complexes, Backsubstitution -> True]

Out[2]= y == -(Sqrt[3 + x^2]/Sqrt[3]) || y == Sqrt[3 + x^2]/Sqrt[3]

In[3]:= sol[[1]][[2]]

Out[3]= -(Sqrt[3 + x^2]/Sqrt[3])

In[4]:= eq2[i_] := 100 + sol[[i]][[2]]

In[5]:= eq2[1]

Out[5]= 100 - Sqrt[3 + x^2]/Sqrt[3]

In[6]:= eq2[2]

Out[6]= 100 + Sqrt[3 + x^2]/Sqrt[3]

• You could also do sol = y /. {ToRules[Reduce[x^2 - 3 y^2 + 3 == 0, y, Complexes, Backsubstitution -> True]]} and then eq2[i_] := 100 + Indexed[sol, i]. Commented Feb 25, 2019 at 1:57
• I like a lot better! If it was an answer I'd accept it.
– nate
Commented Feb 25, 2019 at 2:18
• I was not able to test that code because I'm only using a smartphone. If it worked, I'm fine with you editing your answer to include it, and I can then upvote your answer. :) Commented Feb 25, 2019 at 2:20