# Extract unique root instances. Re-insert after solving

• How can I programmatically extract all Root instances within a solution?
• How can I then replace each Root instance after solving for it?

I have identified with python that all Root objects are of the same 5th order polynomial so ToRadicals cannot handle it.

I can solve each Root object individually but due to the size of the equation I need a programmatic method of replacing the Root objects with their respective solutions that I can solve separately.

### Futher Detail (example)

For completeness, the equation to simplify is ghmc[t_, φ_, ϑ_, ρ_, r_] in this package:

• Calculation time 30s on a MacBook Pro
• Target function ghmc at lines 129-130
• Dependencies ghmcLt[β_, φ_, ϑ_, ρ_, r_] at lines 75-85
• DeleteDuplicates@Cases[expr, _Root, Infinity]...but replace them with what? Commented Aug 6, 2016 at 11:05
• sorry I must have removed that part when ironically making my question clearer! I want to solve the Root objects individually and then replace their respective solutions back into the main equation. I know how to solve but not how to replace them back again Commented Aug 6, 2016 at 11:14
• The Root object is an exact symbolic representation of a solution and generally the best symbolic representation you can expect if it cannot be represented by radicals. You can get a machine-precision approximation with N[rootobj] or an approximation to however many digits, say 50, with N[rootobj, 50]. Is an approximation what you mean by "solve" it? Commented Aug 6, 2016 at 11:34
• "Is an approximation what you mean by "solve" it?" yes, although that's not what I am asking about. DeleteDuplicates@Cases[expr, _Root, Infinity] is a great solution for extracting them but how can I re-insert the N[...] objects? Commented Aug 6, 2016 at 13:08
• If you just need approximations, then consider using NSolve[]. Commented Aug 6, 2016 at 13:12

This should work:

solutions /. (Thread[# -> N[#]] &@ DeleteDuplicates@Cases[solutions, _Root, Infinity])


But N[solutions] might be easier.