axiom-math
[Top][All Lists]
Advanced

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

RE: [Axiom-math] lot of questions about functions.


From: Page, Bill
Subject: RE: [Axiom-math] lot of questions about functions.
Date: Tue, 28 Jun 2005 15:51:15 -0400

Francois,

On Tuesday, June 28, 2005 10:00 AM you wrote:

> I want to play with generic functions of type
> expression -> expression.

I think you have the right idea but perhaps you do not realize
just how rigorous Axiom is when it comes to defining and
operating on functions. What Axiom does is quite simple but
not simply explained. You may have to read several sections of
the Axiom Book carefully several times - sometimes between the
lines.

E.g. 

6.3 Introduction to Functions
6.4 Declaring the Type of Functions
6.6 Declared vs. Undeclared Functions
6.7 Functions vs. Operations
6.9 How Axiom Determines What Function to Use
9.3 BasicOperator
9.50 MakeFunction
9.51 MappingPackage1
10.10 Automatic Newton Iteration Formulas

And here is some discussion of this on MathAction:

http://page.axiom-developer.org/zope/mathaction/FunctionalMapping
http://page.axiom-developer.org/zope/mathaction/114MapOnFunctionsCrash

Sometimes even reading the library code helps. (See mappkg.spad.pamphlet)

--------

There are two important things to remember that might seem
quite odd to someone who has used Mupad, Mathematica or Maple:

1) The name cos is just a name, it is *not* a function.
2) Functions in Axiom are objects of type "mapping", i.e. A -> B
   (also called signature).

In Axiom the same name can be used in more than one way (overloading).
The Axiom interpreter has elaborate sometimes heuristic rules for
trying to decide on what mapping to associate with a given name.
Sometimes you have to give it a little help.

> I use (cos@@100)(1.0) with mupad when I want u100, with u0=1 and
> u(n+1)=cos u(n)

This works in Axiom but you have to provide some additional
information

(1) -> cos:Expression Float -> Expression Float := x +-> cos(x)

   (1)  theMap(Closure)
                       Type: (Expression Float -> Expression Float)
(2) -> (cos**100)(1.0)

   (2)  0.7390851332 1516064351
                       Type: Expression Float

Another way is to specify explicitly the package to use for the
function composition. E.g.

(3) -> FuncExpr:=MappingPackage3(Expression Integer, _
                                 Expression Integer, _
                                 Expression Integer);
                        Type: Domain

(4) -> ((sin*exp)$FuncExpr)(x)

               x
   (4)  sin(%e )
                        Type: Expression Integer

(5) -> )show MappingPackage1

(5) -> )show MappingPackage3

>...
> Is there a the difference between f := t -> 2*t + 1 and
> f(x)==2*x+1 ?

You mean

(5) -> f := t +-> 2*t + 1

   (5)  t +-> 2t + 1
                        Type: AnonymousFunction

(6) -> f(2)

   (6)  5
                        Type: PositiveInteger

This defines an "anonymous" function. On page of The Book
it says:

"Every function in Axiom is identified by a name and type.
(An exception is an "anonymous function" discussed in 6.17 on
page 268.) The type of a function is always a mapping of the
form Source -> Target where Source and Target are types. To enter
a type from the keyboard, enter the arrow by using a hyphen "-"
followed by a greater-than sign ">", e.g. Integer -> Integer."

You must declare the type of the function before you can
use it in functional composition:

(7) -> (f::(Expression Integer->Expression Integer)**3)(3)

   (7)  31
                                                     Type: Expression
Integer
(8) -> f := (t:INT):INT +-> 2*t + 1

   (8)  theMap(Closure)
                                                   Type: (Integer ->
Integer)
(9) -> (f**3)(3)

   (9)  31
                                                        Type:
PositiveInteger

The different between an anonymous function and the following
is subtle and as far as I can see only be significant if the
function definition depended on free (global) variables.

(10) -> f(x)==2*x+1
                        Type: Void

In this case f(x) is not (yet) a function. We only know it's
functional form, not it's type. More over, the expression on
the right hand side has not be evaluated (i.e. compiled).

(11) -> f(2)
   Compiling function f with type PositiveInteger -> PositiveInteger

   (11)  5
                        Type: PositiveInteger


> How can I do f o f o f o ...o f = x -> f(f(f(f...f(x)))) ?
>    (I iterate 10 or 100 times)

See examples above.

> f := x +-> 3*x
> g := x +-> 2*x+3
> It seems impossible to add 2 anonymous functions. I can
> compute f(x)+g(x) but I can't use (f+g)(x)

You mean that you would like to treat + as a functional operator?

This one is harder. Trying to do this in the interpret seems
to cause several different kinds of problems in the Axiom
interpreter (such as recently reported by here Ralf Hemmecke).

The proper way to do this is to compiled a new package for the
Axiom library. I wrote a very simple example here:

http://page.axiom-developer.org/zope/mathaction/SanboxFunctionalAddition

It's only about 10 lines of SPAD code. Let me know if you have
any questions about how it works.

>> Can I do (f o g) or can I only compute f(g(x)) = f g x.

Function composition works using symbol * show above.

> With mupad (sqrt@@2)(16) and (address@hidden@sin)(PI) compute $2$ and $0$.

This works in Axiom.

(1) -> MEI:=MappingPackage1(EXPR INT)

   (1)  MappingPackage1 Expression Integer
                               Type: Domain
(2) -> ((sqrt**2)$MEI)(16)

   (2)  2
                               Type: Expression Integer

(3) -> MEI3:=MappingPackage3(EXPR INT,EXPR INT,EXPR INT)

   (3)
   MappingPackage3(Expression Integer,Expression Integer,Expression Integer)
                               Type: Domain
(4) -> ((log*cos*sin)$MEI3)(%pi)

   (4)  0
                               Type: Expression Integer

----------

Thanks for asking these questions!

Regards,
Bill Page.




reply via email to

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