Re: odd behaviour of `if`



In article <f0m82h$qcl$02$1@xxxxxxxxxxxxxxxxx>, kilian heckrodt
<kilianheckrodt@xxxxxxxxx> wrote:

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/
.



Relevant Pages

  • odd behaviour of `if`
    ... and in sum and product statement the `if` behaves like with the ... substitution. ...
    (sci.math.symbolic)
  • Re: Problem using solve... keeps busy
    ... However, if you then simplify() the result, you get a *large* ... Then at the end of the sum, there are a few lines of other terms ... and you simplifyafter substitution (applying the ... a=x into the original equation ...
    (comp.soft-sys.matlab)
  • Re: maple sucks!!!
    ... I am trying to compute the higher order derivatives the above but as usual ... I've tried various combinations of map, unapply, diff and also converted it ... Knowledge of Maple syntax shows this should be: ... All I want it to do is compute diff before substitution instead of after. ...
    (sci.math)
  • maple sucks!!!
    ... maple is being a complete bitch about it. ... I've tried various combinations of map, unapply, diff and also converted it ... Nothing works and maple always tries and substitutes the numeric value for x ... All I want it to do is compute diff before substitution instead of after. ...
    (sci.math)
  • Re: This integral blows my PC (Maple 9.5) Help !
    ... And memory usage increasing and increasing until the whole ... When I try, Maple can get the antiderivative, which is a sum of polylogs, ... In this case you can make a substitution in the integral with the ... The imaginary "I" is cancelled by the imaginary components of the ...
    (sci.math.symbolic)