Even and odd functions



Hi again:
 From a fresh session, after the first five commands, what I get is

(%i6) paridad(h)
(%o6) length: argument cannot be a symbol; found h
#0: paridad(f=h)
  -- an error. To debug this try: debugmode(true);

> the assumption assume(0<z and z<l)
> is made globally, not locally to paridad

I see this. Will local(z) suffice?

> But it's risky to rely on a user expressing the predicate > as (x>=0
> and x<%pi) instead of the logically equivalent (x<%pi and x>=0).

I agree. I will deal with that later (I think that it can be done by a
simple comparison procedure). By now, I just want a working example and
to understand why neither paridad(h(x)) or paridad(h) do the job.

Thanks for the comments!

J. A.

On 12/01/2011 05:56 AM, Barton Willis wrote:
> The function paridad expects a function, but paridad(h(x)) provides
> paridad with the formula for a function. Instead, try paridad(h).
> This will work as you expect it once, but not twice. The reason for
> the failure on the second attempt is that the assumption assume(0<z and z<l)
> is made globally, not locally to paridad. After paridad is executed once,
> h(z) simplifies to %pi-z.
>
> The Maxima logical operators are not commutative (I think), so your part
> statement works. But it's risky to rely on a user expressing the predicate
> as (x>=0 and x<%pi) instead of the logically equivalent (x<%pi and x>=0).
>
>
> --Barton
>
> -----maxima-bounces at math.utexas.edu wrote: -----
>
>
> Hi to all:
> Suppose that I have a piecewise-defined function on [-l,l] (in this
> example, l=%pi):
>
> (%i1) h(x):=if (x>=-%pi and x<0) then x+%pi elseif (x>=0 and x<%pi) then
> %pi-x$
>
> Suppose also that I want to know if it is even. I can do the following
> to extract the right extremum l (I think this should be always valid for
> any function defined piecewise "from left to right"):
>
> (%i2) l:part(h(x),length(h(x))-3,2,2);
> (%o2) %pi
>
> then:
>
> (%i3) assume(0<z and z<l);
> (%o3) [z>0,z<%pi]
>
> and finally
>
> (%i4) is(equal(h(-z),h(z)));
> (%o4) true
>
> which tells me that it is an even function. If I try to store these
> steps in a function like this:
>
> (%i5) paridad(f):=
>    block(
>           l:part(f,length(f)-3,2,2),
>           assume(0<z and z<l),
>           is(equal(f(-z),f(z)))
> )$
>
> then what I get is
>
> (%i6) paridad(h(x));
> (%o6) apply: found f evaluates to if x>=-%pi and x<0 then x+%pi elseif
> x>=0 and x<%pi then %pi-x  where a function was expected.
> #0: paridad(f=if x>= -%pi and x<  0 then x+%pi elseif x>= 0 and x<
> %pi then %pi-x)
>    -- an error. To debug this try: debugmode(true);
>
> This is strange to me: "found f evaluates to if x>=-%pi and x<0 then
> x+%pi elseif x>=0 and x<%pi then %pi-x", so f evaluates to a function of
> x, but then what does it mean "where a function was expected"?.
> Cheers,
>
> J. A.
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima

J. A.

-- 
__________________________________
Jos? A. Vallejo
Facultad de Ciencias UASLP
http://galia.fc.uaslp.mx/~jvallejo
__________________________________