# How to pick elements from a set and use them in a sum (or product)

I would like to obtain the sum (or some other reduction) from a set which is the result of a previous operation:

NSolve[z^5 == 1, z, Complexes]

{{z -> -0.809017 - 0.587785 I}, {z -> -0.809017 + 0.587785 I}, {z ->
0.309017 - 0.951057 I}, {z -> 0.309017 + 0.951057 I}, {z -> 1.}}


How do I address these elements individually and how can I form a sum (or product)?

• sol = NSolve[z^5 == 1, z, Complexes]; {Plus @@ (z /. sol), Times @@ (z /. sol)} Apr 11 at 7:28
• Also Plus@@soln[[All,1,2]] and Times@@soln[[All,1,2]] Apr 11 at 7:54

solVals = Last /@ Flatten[NSolve[z^5 == 1, z, Complexes]]

solVals1 = NSolveValues[z^5 == 1, z, Complexes]

solVals == solVals1
(* True *)

Plus @@ sol
(* 0.+0.I)

Times @@ sol
(1. + 0.I *)


For exact sum much better approach is

RootSum[#^5 - 1 &, # &]


(* 0 *)

• For the product: Exp@RootSum[#^5 - 1 &, Log] gives $1$. Apr 11 at 9:08
• @Acus: Mathematica 12 does not recognize NSolveValues; is it a new feature? Apr 11 at 17:56
• @Vectorizer Documentation says it was introduced in 2021, in version 12.3
– Acus
Apr 12 at 6:23
• @Acus: Thanks. I am using 12.0 Apr 12 at 7:06