axiom-mail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-mail] Defining piece-wise functions and drawing, integrating


From: Sumant S.R. Oemrawsingh
Subject: Re: [Axiom-mail] Defining piece-wise functions and drawing, integrating, ...
Date: Sun, 3 Jun 2007 04:21:28 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

Hi Bill,

Thanks for your answer. It is now more clear to me what happens. As I am
completely new to Axiom, I probably don't understand the full philosophy
behind it yet, so I wish to ask a bit more on this, if you don't mind.

> You said you expected the 'f(x)' would represent some kind
> of expression defined in a piecewise manner, but Axiom does
> not currently have any expressions of this kind.

This is very strange, since in the Axiom book, there is a whole section on
piece-wise functions. Why have them, if they are not supported, so to say?
If it can be defined and yields correct answers when called with integers or
even expressions yielding specific values (say, sqrt(5) or cos(1/2)), why
can't it be integrated over a domain where the variable takes on specific
values for which all the definitions are required to be evaluated?

Thanks to your explanation, I understand why x < 0 (Variable, Polynomial
Integer, Symbol,...) *does not* return true, but I do not understand why it
*should* not return true (from a design point of view). But from a
mathematical point of view (imho), the expression x < 0 should not be false;
it should be true by default, unless it has been specified that x is an
element of some set, since if it is *not* defined, it can have *any* value,
also negative. Therefore, when one expects to test the domain of x, such as
in an expression like this, it should be true by default.

So, I wish to tell axiom that x is an element of, say, R. I understand that
I should declare the type, in my example Float -> Float, like so:

(1) -> f: (Float) -> Float
                                                                   Type: Void
(2) -> f(x|x<=0)==-x**2   
                                                                   Type: Void
(3) -> f(x|x>0)==x**2     
                                                                   Type: Void
(4) -> f(5)
   Compiling function f with type Float -> Float 

   (4)  - 25.0

(5) -> f(5**(1/3))
(5) -> 
   (5)  2.9240177382 128660655
                                                                  Type: Float

How do I get a symbolic answer now? I don't care what the answer up to n
digits is, I want to know the actual, exact answer. This is even worse:

(6) -> draw(f(x),x=-1..1)
   Conversion failed in the compiled user function f .
 
   Cannot convert from type Symbol to Float for value
   x

(6) -> integrate(f(x),x=-1..1)
   Conversion failed in the compiled user function f .
 
   Cannot convert from type Symbol to Float for value
   x

Granted, I really don't care that much about drawing the function. It is
more of a visual aid to see that I defined my function correctly. For the
example, this is not really necessary, but some of the functions I wish to
perform calculations with, have some wild definitions, with many pieces.
However, integration is very important, since that is what I really want to
do in the end. Even if it manages to give me an answer of the integral, I
still don't want to know the answer estimated to n digits, I would like the
exact answer.

So the real question I would like to ask is, how can I tell axiom that,
during function definition, my variable belongs to R (or C), while all
operations still remain symbolic? How can I get it to first evaluate the
value of x, figure out which function to use, and then return the value
symbolically again?

I have tried by using "numeric(x) > 0" in the conditions, but then
integration won't work since numeric won't work on symbols etc. Thanks to
your explanation, I already expected that before I even tried it. On a side
note, f(%pi) will work correctly then.

Which leads me to the following: why is %e fundamentally different from
%pi? Or, since Martin sort of answered that question already, I should ask:
why *should* %e be fundamentally different from %pi? 

(6) -> %e > 0                    
(6) -> 
   (6)  true
                                                                Type: Boolean

(7) -> %pi > 0
   There are 4 exposed and 1 unexposed library operations named < 
      having 2 argument(s) but none was determined to be applicable. 
      Use HyperDoc Browse, or issue
                                )display op <
      to learn more about the available operations. Perhaps 
      package-calling the operation or using coercions on the arguments
      will allow you to apply the operation.
 
   Cannot find a definition or applicable library operation named < 
      with argument type(s) 
                             NonNegativeInteger
                                     Pi
      
      Perhaps you should use "@" to indicate the required return type, 
      or "$" to specify which version of the function you need.


But I digress. The most imporant question is, how to define a function such
that it first evaluates the value of x, then chooses which case to use and
then perform the action?

In integrate(), I would expect it would look at the limits, perform an
indefinite integral of the relevant cases, and then fill in the limits for
each case correctly. For draw, I would expect something similar.

I've been doing some other stuff with axiom (no problems there!), and think
it is really amazing. That is also the reason that I find this particular
point so frustrating. So if you or any one could help, I would be very much
obliged.


Thanks,

Sumant

-- 
Sumant S. R. Oemrawsingh




reply via email to

[Prev in Thread] Current Thread [Next in Thread]