Message Boards Message Boards

How to combine variables automatically?

Posted 10 years ago

Here is my problem: I have several variables that I know are unknown and have arbitrary values. Let's call them C[1], C[2], and C[3]. After doing some magic with Solve[ ... ] and Reduce[ ... ] and Simplify[ ... ], I get the expression:

C[1]+C[2]+C[3]

Now, I know two things about these variables: they have arbitrary values, but each variable is an integer. So C[1] spans Z, C[2] spans Z, etc. Therefore, their sum spans Z. This is quite obvious. Mathematica gives me a conditional expression like

ConditionalExpression[C[1]+C[2]+C[3],C[1] is in Integers && C[2] is in Integers && C[3] is in Integers]

Which is swell, but I know their sum is also an arbitrary integer. How would I tell Mathematica to replace C[1]+C[2]+C[3] with C[4], C[4] is in integers? Or to do this for arbitrary sums of unknowns, where the properties of the result are obvious but somewhat hard to read in their full form.

Thanks!

POSTED BY: Aaron Clair
Posted 10 years ago

I'm not certain this will do everything you are hoping for, but perhaps it will help

In[1]:= 2 + x^2 - 4 y + C[1] + C[2] + C[3] /. C[1] + C[2] + C[3] -> C[4]

Out[1]= 2 + x^2 - 4 y + C[4]

In[2]:= 2 + x^2 - 4 y + C[1] + C[2] + C[3] + C[5] + C[8] /. Plus[C[__]] -> C[i]

Out[2]= 2 + x^2 - 4 y + 5 C[i]

where the 5 or the i in 5 C[ i ] has perhaps no great significance.

Be careful to check each time you do something like this. I was actually surprised when it worked on the first try.

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract