axiom-developer
[Top][All Lists]
Advanced

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

RE: [Axiom-developer] Expression problems


From: Bill Page
Subject: RE: [Axiom-developer] Expression problems
Date: Sun, 6 Nov 2005 20:42:52 -0500

On November 6, 2005 4:20 PM Hans Peter Würmli wrote:
> 
> I am struggling with dealing with Expressions. For most sake 
> and purposes I can find a fix and solve my small problems,
> but I never feel very assured. 
> 
> Maybe you can give me some pointers. The question that I 
> originally would have liked to ask was: is there a
> "parse tree" object available for elements of type, say,
> Expression(Integer).

I am not entirely sure what you expect when you say "parse tree",
but maybe InputForm is similar to what you want. Try for example:

(1) -> cos(3*x)::InputForm

   (1)  (cos (* 3 x))
                                        Type: InputForm

The "parse tree" is in the form of a lisp-like S-expression. There
is some information about this at:

http://wiki.axiom-developer.org/ManipulatingExpressions

and

http://wiki.axiom-developer.org/InputForm

> 
> As there doesn't seem to exist a parse tree object, I should 
> ask a different question: how are you analysing an Expression?

I think the most direct answer to that question is the same as
above: as in InputForm object. But of course the internal details
are a little more complex.

> 
> While browsing through the documentation I found many 
> functions that could be usable for parsing, but I wasn't
> very lucky in using them. 
> 
> For example, there is a function
> 
> isMult(p) 
> 
> which is supposed to return [n,x] if p=n*x if n<>0.
> 
> For a Symbol x and an Integer n 
> 
> isMult(n*x) returns [n,x], 
> 
> but for another Symbol y
> 
> isMult(y*x) returns "failed".

That is exactly what it is supposed to do. In the context of
Expression Integer, the parameter n must be an Integer. The
Symbol y is not an Integer.

> 
> Not exactly analogously
> 
> isPower(x**y) returns [x**y,1], whereas
> 
> isPower(x**10) returns [x,10].
>

It is similar:

  isPower(p) returns [x, n] if p = x**n

for some Integer n. In the first case the Integer is 1.
 
> isExpt behaves like isPower, where isTimes differs from 
> isMult and returns all factors of a product, i.e.
> 
> isTimes(x*y*z)=[x,y,z].
>

The definition of isTimes is:

  isTimes(p) returns [a_1,...,a_n] if p = a_1*...*a_n and n > 1.

where a_1, ..., a_n are sub-expressions.

> Whereas 
> 
> isPlus((x+y+z*y) returns [y z,y,x]
> 
> isTimes((x+y)*z) returns "failed" instead of the exp.

That is because the expression is internally treated as a
multivariate polynomial like this:

(1) -> ((x+y)*z)::MPOLY([x,y,z],INT)

   (1)  z x + z y
              Type: MultivariatePolynomial([x,y,z],Integer)

If you say:

(2) -> isPlus((x+y)*z)

   (2)  [y z,x z]
                     Type: Union(List Polynomial Integer,...)

perhaps the result makes sense?

> 
> Somehow I don't understand the inner logic of these
> operations.
> 
> Any hints for how to proceed are greatly welcome.
> 

I hope this helps. For some of the details of these operations
I consulted the actual algebra code at:

http://wiki.axiom-developer.org/axiom--test--1/src/algebra/FspaceSpad

Click on 'pdf' or 'dvi' to see the documentation.

You can also enter expressions like 'isTimes' in the search box
on the upper right and see all the places in the algebra where
this operation is defined and used.

I haven't checked the Axiom book yet, but if some of the
definitions there are incomplete or misleading, then perhaps
we can update it.

Regards,
Bill Page.






reply via email to

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