[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] How to expand a fraction (like Maple does with 'expand'
From: |
Martin Rubey |
Subject: |
Re: [Axiom-mail] How to expand a fraction (like Maple does with 'expand')? |
Date: |
26 Jan 2007 12:20:08 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Dear Thomas,
although for the end-user it probably doesn't matter, I'm afraid that the
impression the mails by Bill Page and Francois Maltey give is not quite
"complete".
* in Axiom, it is very important to distinguish between internal representation
and output.
* "expand" as provided by Maple, Mathematica, etc., is mainly about output, the
internal representation doesn't matter too much there. It can be interpreted
as: display the thing with everything multiplied out.
* in Axiom, if you want to have a different output, it is best to write a
wrapper domain.
* it is very easy to write such a domain in Axiom. In Aldor, it would be even
easier, but unfortunately, currently the necessary functionality ("extend")
is not provided by the Axiom-Aldor interface.
Here goes the domain. Put it into a file, for example myexpr.spad, type
)co myexpr.spad
on the axiom command prompt
and
(((-r1*r2*uoff)+((r2+r1)*r3+r1*r2)*ue)/(r2*r3))::DEXPR INT
should return
r1 ue r1 uoff r1 ue
----- - ------- + ----- + ue
r3 r3 r2
---myexpr.spad ----------------------------------------------------------------
)abb domain DEXPR DistributedExpression
DistributedExpression(R: Join(Ring, OrderedSet)): Exports == Implementation
where
AN ==> AlgebraicNumber
SUP ==> SparseUnivariatePolynomial
EXPRR ==> Expression R
Exports == FunctionSpace R with
if R has IntegralDomain then
AlgebraicallyClosedFunctionSpace R
TranscendentalFunctionCategory
CombinatorialOpsCategory
LiouvillianFunctionCategory
SpecialFunctionCategory
reduce: % -> %
++ reduce(f) simplifies all the unreduced algebraic quantities
++ present in f by applying their defining relations.
number?: % -> Boolean
++ number?(f) tests if f is rational
simplifyPower: (%,Integer) -> %
++ simplifyPower?(f,n) \undocumented{}
if R has GcdDomain then
factorPolynomial : SUP % -> Factored SUP %
++ factorPolynomial(p) \undocumented{}
squareFreePolynomial : SUP % -> Factored SUP %
++ squareFreePolynomial(p) \undocumented{}
if R has RetractableTo Integer then RetractableTo AN
Implementation == EXPRR add
Rep := EXPRR
out: (Polynomial R, %, List %, List %) -> OutputForm
-- coerces the polynomial to OutputForm completely expanded and replaces the
-- variables in vl with the kernels in kl
out(p, q, kl, vl) ==
ex: Fraction Rep := (eval(leadingMonomial(p)::%, vl, kl)::Rep)/(q::Rep)
if reductum p = 0
then coerce(ex)$Fraction(Rep)
else coerce(ex)$Fraction(Rep) _
+ out(reductum p, q, 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 %, %)
if R has IntegralDomain then
out(retract(numerator ex1)@Polynomial(R),
denominator eval(ex1, vl, kl1), kl1, vl)
else
out(retract(ex1)@Polynomial(R), 1, kl1, vl)
---myexpr.spad ----------------------------------------------------------------
A note for Thomas: the only bit of code that required some work was "out" and
"coerce". Everything else (i.e., everything before and including "Rep:=EXPRR")
is copy and paste. If the Aldor interface would work properly, it wouldn't be
there.
I'm sure that "out" and "coerce" could be simplified and improved, too. I just
didn't bother.
A note for axiom developers:
In my opinion, this is not the right approach. The right approach would be to
generalize DMP and to allow arbitrary variables, just as SMP does.
Martin