1
$\begingroup$

I want to be able to check if a function f is even, odd, or neither using Maple's symbolic math. Unfortunately I don't get a boolean return of 'true' on a function I know is even.

g:=abs(x)/x^2
evalb(g(x)=g(-x))
                                          false

Since my function is even, that is a problem. It turns out that my expression is multiplying g by x or -x instead of inputing/composing them.

How can I get Maple to check the parity of my function?

  • 1
    Define $g$ as a function. $g:=x->abs(x)/x^2$2017-01-10
  • 0
    @BernardMassé Your solution is better than mine. Post it as an answer please.2017-01-10
  • 0
    Agree with comment of @BernardMassé , but I like more the following way of defining function. g(x) := abs(x)/x^2 which is basically the same but simpler notation. Replace first line of the two in your question by this definition and the second line will work just like a charm.2018-07-30

3 Answers 3

2

All the right ideas are already in other answers/comments, but I'll post this as an answer to hopefully provide some more detail.

The way people normally use 'function' in a programming context is a construct which takes some number of parameters and executes one or more statements making use of these parameters.

In that sense, your definition of g isn't a function, it's an expression. The instances of 'x' inside aren't function parameters, but unassigned symbols. (I should say however, at the risk of confusing you further, that Maple's documentation and type system frequently uses the word 'function' to refer to expressions, e.g. in the definition of the Maple type function. But don't worry about that right now.)

The easiest way to do what you want using your expression g is what you already found:

g:=abs(x)/x^2;
evalb( g = eval(g, x=-x) );

Going back to the question about a 'function', the thing in Maple which corresponds most naturally to that idea is a 'procedure'. Here are two ways to define a procedure corresponding to g and perform the test you've already done. I'll call this function 'h':

Method #1:

h := x -> abs(x)/x^2;
evalb( h(x) = h(-x) );

Method #2:

h := unapply( abs(x)/x^2, x );
evalb( h(x) = h(-x ) );

Hope that helps.

  • 0
    Somebody made a suggested edit to this post with a Method #3: `h(x) := abs(x)/x^2; evalb( h(x) = h(-x) );` An editor accepted this but I've since rejected it, and I think it's worth clarifying why. That syntax might look like it works, but it is not doing what you think. Instead of creating a function returns the absolute value of its input divided by the square of its input, this syntax is assigning a value into a lookup table for the function h. Afterwards, h(x) will return abs(x)/x^2, but this will only work for the symbol x, and not anything else (e.g. h(1) or h(y) are unknown).2018-08-14
  • 0
    Not agree, `h(1)` or `h(y)` or any other valid use cases are correctly defined as well, and `h(x)` style of defining function name in `h(x) := abs(x)/x^2;` gives additional clue that `h` is function rather than variable, and it is more human readable option. It was valid method, and instead of posting as a separate answer, I added this method in this answer in order to maintain cleaner conversation on this page for community, but I can also post it as a separate answer if you insist, as it is a valid answer given the question asked.2018-08-30
  • 0
    I posted the here removed Method #3 as a separate answer, due to the wrong rejection by @saforrest (e.g. h(1) or h(y) and other valid use cases are well defined rather than unknown for the h(x) function, in contrast of the opinion that was stated in the reason of rejection).2018-08-30
  • 0
    @T.V.: No, sorry, you're wrong. This syntax simply doesn't work. If you post an example where you think it is working, I will explain why it doesn't do what you think it does. I should mention however that Maple's GUI editor has a special mode that intercepts use of this syntax and offers you a choice of interpretations, one of which essentially maps to Method #1. But that is a UI-level addition outside the Maple programming language.2018-09-10
0

I think I figured out what I was looking for. I needed a function that would evaluate g at a value, which I found in the documentation.

evalb(eval(g, x = x) = eval(g, x = -x))
0

More human readable method (especially in the part of declaring a function):

h(x) := abs(x)/x^2;
evalb( h(x) = h(-x) );