axiom-developer
[Top][All Lists]

## Re: [Axiom-developer] Re: How can I get every term of an expression ?

 From: Martin Rubey Subject: Re: [Axiom-developer] Re: How can I get every term of an expression ? Date: Tue, 20 Sep 2005 14:19:42 +0200

```Francois Maltey writes:
>
> > How can I persuade Axiom to write out
> >
> > (1) -> (2*log(x)+3*exp(y))*(4*sin(z)+2*log(x))
> >
> > as a "sum of products"? E.g.
> >
> > (2) -> 8*log(x)*sin(z)+4*log(x)^2+12*exp(y)*sin(z)+6*exp(y)*log(x)
> >
> > In Axiom, both of these expressions are rendered as
> >
> >     (8log(x) + 12exp(y))sin(z) + 4log(x)  + 6exp(y)log(x)
> >                 Type: Expression Integer

For example:

(16) -> ex:=(2*log(x)+3*exp(y))*(4*sin(z)+2*log(x))

y                 2      y
(16)  (8log(x) + 12%e )sin(z) + 4log(x)  + 6%e log(x)
Type: Expression Integer
(17) -> subst(ex, kernels ex, [x1,x2,x3])::DMP([x1,x2,x3], INT)

2
(17)  8x1 x2 + 12x1 x3 + 4x2  + 6x2 x3
Type: DistributedMultivariatePolynomial([x1,x2,x3],Integer)

> I use kernels to get the elementary functions.

taken by two other things ... ;-)

> Can I substitute theses elementary functions to new variables, make
> transforms over polynoms,

yes...

> and substitute the variables back ?

Well, as soon as you go back, you'll loose the transformations you did...

The "deeper" reason why there is no domain DistributedExpression is probably
that DMP defined in gdpoly.spad asks for a List Symbol as variables. It
probably could be in fact any finite OrderedSet, but it would need some work to
get it done.

A simple workaround is

out(p, kl, vl) ==
if reductum p = 0
else (eval(leadingMonomial(p)::EXPR INT, vl, kl))::OUTFORM _
+ out(reductum p, kl, vl)

output ex ==
kl := kernels ex
vl := [subscript('x, [i::OutputForm]) for i in 1..#kl]
out(subst(ex, kl, vl)::DMP(vl, INT), kl, vl)

Note that this returns an element of OUTFORM. This can be circumvented: highly
undebugged, undocumented and all the bad things :-)

)abb domain DEXPR DistributedExpression
DistributedExpression(R: Join(Ring, OrderedSet)): Exports == Implementation
where

EXPRR ==> Expression R

Exports == FunctionSpace R

Rep := EXPRR

out: (Polynomial R, List %, List %) -> OutputForm
out(p, kl, vl) ==
if reductum p = 0
then coerce(eval(ex, vl, kl))\$Rep
else coerce(eval(ex, vl, kl))\$Rep _
+ out(reductum p, kl, vl)

coerce(ex:%):OutputForm ==
kl := kernels ex
vl: List % := [subscript('x, [i::OutputForm])::Symbol::% for i in
1..#kl]
ex1: % := subst(ex, kl, vl)\$%
kl1 := map(coerce(#1)\$%, kl)\$ListFunctions2(Kernel %, %)
out(retract(ex1)@Polynomial(R), kl1, vl)

```