Constuct a function that plus equations

I want to construct a function that plus equations. For example:

SomaEqns[eq1,eq2,...] == eq1 + eq2 + ...


It's possible do that with recursive way? Using less then possible the functions of Mathematica.

I know Mathematica already can do that. It's just for exercise.

• perhaps you'll find Fold helpful for a functional approach that circumvents possible problems with recursion limits Sep 18 '18 at 17:22
• By "It's possible do that with recursive way? Using less then possible the functions of Mathematica.", I assume you are looking for a solution that uses recursion and does not use Thread, Fold, etc. One way to do this f[{eqn_}] := eqn f[eqn_List] := First[eqn] + f[Rest[eqn]] f[{eq1, eq2, eq3, eq4}] gives eq1 + eq2 + eq3 + eq4 Sep 18 '18 at 17:42
• SomaEqns = Plus? Sep 18 '18 at 17:45
• Something like that @RohitNamjoshi. But in this case I don't want to write my equations as a List Sep 18 '18 at 19:29

1 Answer

Here's a recursive way (like Rohit's comment but without the list):

f[first_, rest__] := first + f[rest]
f[last_] := last

f[1, x, x^2, x^3]


1 + x + x^2 + x^3

But note that Plus is exactly what you describe (as pointed out what AccidentalFourierTransform):

f[eqns__] := Plus[eqns]
f[1, x, x^2, x^3]


1 + x + x^2 + x^3