Main Page | Report this Page
 
   
Science Forum Index  »  Math - Symbolic Forum  »  odd behaviour of `if`
Page 1 of 1    
Author Message
kilian heckrodt
Posted: Tue Apr 24, 2007 7:40 pm
Guest
Hi !

I'm getting bugged by somewhat odd (and for me unexpected) behaviour of
maple:

subs(i=5,`if`(i mod 5 = 0,1,i)) = 5, but `if`(5 mod 5 = 0,1,5) = 1

and in sum and product statement the `if` behaves like with the
substitution.
What's the reason for this behaviour and is there a workaround?
In other words how can if use the `if` in formulas/products/sums ?
G. A. Edgar
Posted: Wed Apr 25, 2007 7:15 am
Guest
In article <f0m82h$qcl$02$1@news.t-online.com>, kilian heckrodt
<kilianheckrodt@yahoo.com> wrote:

Quote:
Hi !

I'm getting bugged by somewhat odd (and for me unexpected) behaviour of
maple:

subs(i=5,`if`(i mod 5 = 0,1,i)) = 5, but `if`(5 mod 5 = 0,1,5) = 1

and in sum and product statement the `if` behaves like with the
substitution.
What's the reason for this behaviour and is there a workaround?
In other words how can if use the `if` in formulas/products/sums ?

You want to evaluate `if`(i mod 5 = 0,1,i) before or after you
substitute i=5? It makes a difference. Use quotes ' ' to
delay evaluation. You can use "eval" instead of "subs" . I
prefer to use "piecewise" instead of "`if`" , but here
I guess it doesn't matter.



eval('`if`(i mod 5 = 0,1,i)',i=5);
1


eval(`if`(i mod 5 = 0,1,i),i=5);
5


eval(piecewise(i mod 5 = 0,1,i),i=5);
5

eval('piecewise(i mod 5 = 0,1,i)',i=5);
1

--
G. A. Edgar http://www.math.ohio-state.edu/~edgar/
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Mon Dec 01, 2008 8:36 pm