Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any software where this kind of symbolic calculation is possible?

s = 0
for i = 1 to m
   j = 2 i + a - t
   if (j > 0) s = s + a

I want s as a function of m,a,t, where m,a,t are integers. This is a toy example. In my calculation a lot of if/else, minimum of two values, etc., are involved.

share|improve this question
    
Mathematica can certainly handle this, but I don't see this a symbolic calculation if all the actual arguments are going to be integer values. I suggest you elaborate on how you intend to use unbound symbols in your work. –  m_goldberg Dec 15 '12 at 1:40
    
@m_goldberg perhaps he means to evaluate his statement symbolically into closed form. OP, could you please clarify? –  VF1 Dec 15 '12 at 1:54
    
Otherwise, OP, I recommend taking a look at this. What you wrote in psuedocode can easily be transcribed into MMA. –  VF1 Dec 15 '12 at 1:59
    
Yes, I want closed form of s. Will you kindly explain how to write this code? –  user46185 Dec 15 '12 at 2:23
add comment

1 Answer

up vote 3 down vote accepted

If I understand you, then:

Sum[Boole[2 i + a - t > 0] a, {i, 1, m}]

Mathematica graphics

share|improve this answer
1  
I gotta learn how to use Boole better! –  Mark McClure Dec 15 '12 at 3:28
    
Thank you very much. –  user46185 Dec 15 '12 at 4:31
    
@user46185 I see that you Accepted this answer. Were you able to adapt this to your larger problem? You mentioned "a lot of if/else" -- generally you want to use Boole and Piecewise which are mathematical constructs rather than If/Which etc. flow control functions, when using Sum, Product etc. to compute a symbolic equivalent. –  Mr.Wizard Dec 15 '12 at 5:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.