# 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[][]
eq2[i_] = 100 + (y /. y -> sol[[i]][])

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[][])


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]][], {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]][]
eq2 = 100 + solution_one
eq2 = 100 + solution_two
eq3[i_,j_] = A*eq2[i] + B*eq2[j];
etc
etc

• What do you want to get as a result? Feb 25 '19 at 1:06
• well i guess i want a function that uses an index to select which solution value to use, e.g. eq2 ----> 100 + sol[][] or eq2 -----> 100 + sol[][]...and in even more nested functions
– nate
Feb 25 '19 at 1:11
• But the solution sol is y == -(Sqrt[3 + x^2]/Sqrt) || y == Sqrt[3 + x^2]/Sqrt. You can use a replacement eq2[i_] := sol[[i]] /. {y -> 100 + z} Feb 25 '19 at 1:21
• well I get then: 100 + z == -(Sqrt[3 + x^2]/Sqrt) 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
Feb 25 '19 at 1:31
• The question remains, what do you want to get? Feb 25 '19 at 4:32

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

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

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

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

In:= eq2
eq2

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

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


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:= oop[i_, ch_] := h /. Part[Solve[eq2[i] + h^2 == 0, h], ch, 1]

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

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

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

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

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


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

Out= 3 + x^2 - 3 y^2

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

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

In:= sol[][]

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

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

In:= eq2

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

In:= eq2

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

• 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]. Feb 25 '19 at 1:57
• I like a lot better! If it was an answer I'd accept it.
– nate
Feb 25 '19 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. :) Feb 25 '19 at 2:20