# Reducing solutions from Solve to positive solutions

Consider the following lines;

Clear[r, R, H, s]
rel1 = 2 r == 1/2 H;
rel2 = r/R == (H - r)/s;
rel3 = H^2 + R^2 == s^2;
solH = Solve[rel1, H][[1]]
sols = Solve[rel2 /. solH, s][[1]]
solR = Solve[rel3 /. solH /. sols, R, PositiveReals][[1]]

Quote = (\[Pi] R s + \[Pi] R^2)/(4 \[Pi] r^2) /. sols /. solR [[1]]

1. For the solR line I added PositiveReals to avoid two solutions where I manually had to use [[2]] to specify the correct solution. However, clearly, and logically, Mathematica does not know if $$r>0$$. How can I state/define that, perhaps as a ‘preface,’ after Clear, before calculations starts?

2. Is it necessary to use [[1]] for solH and sols (and for solR)? I got an error when removing them from solH and sols when solR is calculated. Is there a better way to write these two lines without using [[1]]?

Any other comments and recommendations to improve the code are most welcome.

TIA

• From the documentation, "Solve[expr, vars] attempts to solve the system expr of equations or inequalities for the variables vars." Constraints such as r > 0 can be included in the system expr. Commented Nov 5, 2020 at 19:57

You can simplify the solution and give r > 0 as an assumption:

solR = Simplify[Solve[rel3 /. solH /. sols, R, PositiveReals][[1]], Assumptions -> {r > 0}]


I doubt there is a better way to access the solution than [[1]] as Solve always returns a list, of which you are interested in the first element.

• Thank you. Is there a way to define, e.g. r>0, at the beginning of a note book and then let Mathematica remember that in future calculations without Assumptions?
– mf67
Commented Nov 5, 2020 at 19:47
• yes, you can set the assumptions as \$Assumptions = { r > 0 } - but you still need the Simplify around the Solve Commented Nov 5, 2020 at 19:51
• That is great. Many thanks!
– mf67
Commented Nov 5, 2020 at 21:55