|
|
|
last edited 8 years ago by test1 |
| 1 2 | ||
|
Editor:
Time: 2011/02/12 21:45:13 GMT-8 |
||
| Note: | ||
changed: - Francois Maltey (FM) and Bill Page (BP) wrote:: How can I persuade Axiom to write out \begin{axiom} ex1:=(2*log(x)+3*exp(y))*(4*sin(z)+2*log(x)) \end{axiom} as a "sum of products"? E.g. \begin{axiom} ex2:=8*log(x)*sin(z)+4*log(x)^2+12*exp(y)*sin(z)+6*exp(y)*log(x) \end{axiom} In Axiom, both of these expressions are rendered the same! <hr /> On Tuesday, September 20, 2005 8:20 AM Martin Rubey wrote: For example: \begin{axiom} subst(ex1, kernels ex1, [x1,x2,x3])::DMP([x1,x2,x3], INT) \end{axiom} FM:: Can I substitute theses elementary functions ![kernels] to new variables, make transforms over polynoms, yes... FM:: 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: \begin{axiom} List Kernel Expression Integer has OrderedSet \end{axiom} A simple workaround is: \begin{axiom} out(p, kl, vl) == if reductum p = 0 then (eval(leadingMonomial(p)::EXPR INT, vl, kl))::OUTFORM 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) \end{axiom} \begin{axiom} output(ex1) \end{axiom} Note that this returns an element of 'OUTFORM'. This can be circumvented: highly undebugged, undocumented and all the bad things :-) \begin{spad} )abb domain DEXPR DistributedExpression DistributedExpression(R: Join(Ring, OrderedSet)): Exports == Implementation where EXPRR ==> Expression R AN ==> AlgebraicNumber SUP ==> SparseUnivariatePolynomial 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 coerce: EXPRR -> % 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, kl, vl) == ex := leadingMonomial(p)::% 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 %, %) if R has IntegralDomain then if denominator ex1 = 1 then out(retract(numerator ex1)@Polynomial(R), kl1, vl) else out(retract(numerator ex1)@Polynomial(R), kl1, vl) / out(retract(denominator ex1)@Polynomial(R), kl1, vl) else out(retract(ex1)@Polynomial(R), kl1, vl) coerce(p:EXPRR):% == p \end{spad} Unfortunately, it seems that it is not possible to tell Axiom to take all the exported functions of a given domain and export them. So we have to include the whole 'Exports' section of 'EXPR'... \begin{axiom} ex1::DistributedExpression(Integer) ((1+2*a+3*b)*(4*c+5*d))::DEXPR INT %::POLY INT \end{axiom} From BillPage Tue Sep 20 11:45:30 -0500 2005 From: Bill Page Date: Tue, 20 Sep 2005 11:45:30 -0500 Subject: duplicate exported functions Message-ID: <20050920114530-0500@wiki.axiom-developer.org> > Unfortunately, it seems that it is not possible to tell Axiom to > take all the exported functions of a given domain and export them. Isn't this a case where one should define a category relevant to both Expression and DistributedExpression in order to avoid duplication of the list of exports? From kratt6 Mon Sep 26 08:14:17 -0500 2005 From: kratt6 Date: Mon, 26 Sep 2005 08:14:17 -0500 Subject: Message-ID: <20050926081417-0500@page.axiom-developer.org> Yes, but since Spad doesn't support Aldor's keyword 'extend', this cannot be done post factum...
Francois Maltey (FM) and Bill Page (BP) wrote:
How can I persuade Axiom to write out
ex1:=(2*log(x)+3*exp(y))*(4*sin(z)+2*log(x))
| (1) |
as a "sum of products"? E.g.
ex2:=8*log(x)*sin(z)+4*log(x)^2+12*exp(y)*sin(z)+6*exp(y)*log(x)
| (2) |
In Axiom, both of these expressions are rendered the same!
For example:
subst(ex1,kernels ex1, [x1, x2, x3])::DMP([x1, x2, x3], INT)
| (3) |
FM:
Can I substitute theses elementary functions [kernels] to new variables, make transforms over polynoms,
yes...
FM:
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:
List Kernel Expression Integer has OrderedSet
| (4) |
A simple workaround is:
out(p,kl, vl) == if reductum p = 0 then (eval(leadingMonomial(p)::EXPR INT, vl, kl))::OUTFORM 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)
output(ex1)
Cannot compile conversion for types involving local variables. In particular,could not compile the expression involving :: DMP(vl, INT) FriCAS will attempt to step through and interpret the code.
Compiling function out with type (DistributedMultivariatePolynomial(
[*01x1, *01x2, *01x3], Integer), List(Kernel(Expression(Integer))),
List(Symbol)) -> OutputForm| (5) |
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 AN ==> AlgebraicNumber SUP ==> SparseUnivariatePolynomial
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
coerce: EXPRR -> %
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, kl, vl) == ex := leadingMonomial(p)::% 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 %, %) if R has IntegralDomain then if denominator ex1 = 1 then out(retract(numerator ex1)@Polynomial(R), kl1, vl) else out(retract(numerator ex1)@Polynomial(R), kl1, vl) / out(retract(denominator ex1)@Polynomial(R), kl1, vl) else out(retract(ex1)@Polynomial(R), kl1, vl)
coerce(p:EXPRR):% == p
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/4397718924680446687-25px007.spad
using old system compiler.
DEXPR abbreviates domain DistributedExpression
------------------------------------------------------------------------
initializing NRLIB DEXPR for DistributedExpression
compiling into NRLIB DEXPR
****** Domain: R already in scope
compiling local out : (Polynomial R, List $, List $) -> OutputForm
Time: 0.07 SEC.
compiling exported coerce : $ -> OutputForm
****** Domain: R already in scope
augmenting R: (IntegralDomain)
****** Domain: $ already in scope
augmenting $: (AlgebraicallyClosedFunctionSpace R)
****** Domain: $ already in scope
augmenting $: (TranscendentalFunctionCategory)
****** Domain: $ already in scope
augmenting $: (CombinatorialOpsCategory)
****** Domain: $ already in scope
augmenting $: (LiouvillianFunctionCategory)
****** Domain: $ already in scope
augmenting $: (SpecialFunctionCategory)
augmenting $: (SIGNATURE $ reduce ($ $))
augmenting $: (SIGNATURE $ number? ((Boolean) $))
augmenting $: (SIGNATURE $ simplifyPower ($ $ (Integer)))
Time: 0.09 SEC.
compiling exported coerce : Expression R -> $
DEXPR;coerce;E$;3 is replaced by p
Time: 0 SEC.
****** Domain: $ already in scope
augmenting $: (RetractableTo (Integer))
****** Domain: R already in scope
augmenting R: (IntegralDomain)
****** Domain: $ already in scope
augmenting $: (AlgebraicallyClosedFunctionSpace R)
****** Domain: $ already in scope
augmenting $: (TranscendentalFunctionCategory)
****** Domain: $ already in scope
augmenting $: (CombinatorialOpsCategory)
****** Domain: $ already in scope
augmenting $: (LiouvillianFunctionCategory)
****** Domain: $ already in scope
augmenting $: (SpecialFunctionCategory)
augmenting $: (SIGNATURE $ reduce ($ $))
augmenting $: (SIGNATURE $ number? ((Boolean) $))
augmenting $: (SIGNATURE $ simplifyPower ($ $ (Integer)))
****** Domain: R already in scope
augmenting R: (GcdDomain)
****** Domain: R already in scope
augmenting R: (IntegralDomain)
****** Domain: $ already in scope
augmenting $: (AlgebraicallyClosedFunctionSpace R)
****** Domain: $ already in scope
augmenting $: (TranscendentalFunctionCategory)
****** Domain: $ already in scope
augmenting $: (CombinatorialOpsCategory)
****** Domain: $ already in scope
augmenting $: (LiouvillianFunctionCategory)
****** Domain: $ already in scope
augmenting $: (SpecialFunctionCategory)
augmenting $: (SIGNATURE $ reduce ($ $))
augmenting $: (SIGNATURE $ number? ((Boolean) $))
augmenting $: (SIGNATURE $ simplifyPower ($ $ (Integer)))
****** Domain: R already in scope
augmenting R: (RetractableTo (Integer))
****** Domain: R already in scope
augmenting R: (LinearlyExplicitRingOver (Integer))
****** Domain: $ already in scope
augmenting $: (RetractableTo (Integer))
****** Domain: R already in scope
augmenting R: (CharacteristicNonZero)
****** Domain: R already in scope
augmenting R: (CommutativeRing)
****** Domain: R already in scope
augmenting R: (ConvertibleTo (InputForm))
****** Domain: R already in scope
augmenting R: (ConvertibleTo (Pattern (Float)))
****** Domain: R already in scope
augmenting R: (ConvertibleTo (Pattern (Integer)))
****** Domain: R already in scope
augmenting R: (Group)
****** Domain: R already in scope
augmenting R: (IntegralDomain)
****** Domain: $ already in scope
augmenting $: (AlgebraicallyClosedFunctionSpace R)
****** Domain: $ already in scope
augmenting $: (TranscendentalFunctionCategory)
****** Domain: $ already in scope
augmenting $: (CombinatorialOpsCategory)
****** Domain: $ already in scope
augmenting $: (LiouvillianFunctionCategory)
****** Domain: $ already in scope
augmenting $: (SpecialFunctionCategory)
augmenting $: (SIGNATURE $ reduce ($ $))
augmenting $: (SIGNATURE $ number? ((Boolean) $))
augmenting $: (SIGNATURE $ simplifyPower ($ $ (Integer)))
****** Domain: R already in scope
augmenting R: (PatternMatchable (Float))
****** Domain: R already in scope
augmenting R: (PatternMatchable (Integer))
****** Domain: R already in scope
augmenting R: (RetractableTo (Integer))
(time taken in buildFunctor: 190)
;;; *** |DistributedExpression| REDEFINED
;;; *** |DistributedExpression| REDEFINED
Time: 0.51 SEC.
Warnings:
[1] coerce: $$ has no value
[2] not known that (IntegralDomain) is of mode (CATEGORY domain (SIGNATURE simplifyPower ($ $ (Integer))))
[3] not known that (Comparable) is of mode (CATEGORY domain (SIGNATURE simplifyPower ($ $ (Integer))))
[4] not known that (Ring) is of mode (CATEGORY domain (SIGNATURE simplifyPower ($ $ (Integer))))
Cumulative Statistics for Constructor DistributedExpression
Time: 0.67 seconds
--------------non extending category----------------------
.. DistributedExpression(#1) of cat
(|Join| (|FunctionSpace| |#1|)
(CATEGORY |domain|
(IF (|has| |#1| (|IntegralDomain|))
(PROGN
(ATTRIBUTE (|AlgebraicallyClosedFunctionSpace| |#1|))
(ATTRIBUTE (|TranscendentalFunctionCategory|))
(ATTRIBUTE (|CombinatorialOpsCategory|))
(ATTRIBUTE (|LiouvillianFunctionCategory|))
(ATTRIBUTE (|SpecialFunctionCategory|))
(SIGNATURE |reduce| ($ $))
(SIGNATURE |number?| ((|Boolean|) $))
(SIGNATURE |simplifyPower| ($ $ (|Integer|)))
(IF (|has| |#1| (|GcdDomain|))
(PROGN
(SIGNATURE |factorPolynomial|
((|Factored| (|SparseUnivariatePolynomial| $))
(|SparseUnivariatePolynomial| $)))
(SIGNATURE |squareFreePolynomial|
((|Factored| (|SparseUnivariatePolynomial| $))
(|SparseUnivariatePolynomial| $))))
|noBranch|)
(IF (|has| |#1| (|RetractableTo| (|Integer|)))
(ATTRIBUTE (|RetractableTo| (|AlgebraicNumber|)))
|noBranch|))
|noBranch|)
(SIGNATURE |coerce| ($ (|Expression| |#1|))))) has no
(IF (|has| |#1| (|IntegralDomain|))
(PROGN
(ATTRIBUTE (|AlgebraicallyClosedFunctionSpace| |#1|))
(ATTRIBUTE (|TranscendentalFunctionCategory|))
(ATTRIBUTE (|CombinatorialOpsCategory|))
(ATTRIBUTE (|LiouvillianFunctionCategory|))
(ATTRIBUTE (|SpecialFunctionCategory|))
(SIGNATURE |reduce| ($ $))
(SIGNATURE |number?| ((|Boolean|) $))
(SIGNATURE |simplifyPower| ($ $ (|Integer|)))
(IF (|has| |#1| (|GcdDomain|))
(PROGN
(SIGNATURE |factorPolynomial|
((|Factored| (|SparseUnivariatePolynomial| $))
(|SparseUnivariatePolynomial| $)))
(SIGNATURE |squareFreePolynomial|
((|Factored| (|SparseUnivariatePolynomial| $))
(|SparseUnivariatePolynomial| $))))
|noBranch|)
(IF (|has| |#1| (|RetractableTo| (|Integer|)))
(ATTRIBUTE (|RetractableTo| (|AlgebraicNumber|)))
|noBranch|)
(SIGNATURE |setSimplifyDenomsFlag| ((|Boolean|) (|Boolean|)))
(SIGNATURE |getSimplifyDenomsFlag| ((|Boolean|))))
|noBranch|) finalizing NRLIB DEXPR
Processing DistributedExpression for Browser database:
--->-->DistributedExpression(constructor): Not documented!!!!
--------(reduce (% %))---------
--------(number? ((Boolean) %))---------
--------(simplifyPower (% % (Integer)))---------
--->-->DistributedExpression((simplifyPower (% % (Integer)))): Improper first word in comments: simplifyPower?
"simplifyPower?(\\spad{f}, {}\\spad{n}) \\undocumented{}"
--------(factorPolynomial ((Factored (SparseUnivariatePolynomial %)) (SparseUnivariatePolynomial %)))---------
--------(squareFreePolynomial ((Factored (SparseUnivariatePolynomial %)) (SparseUnivariatePolynomial %)))---------
--->-->DistributedExpression((coerce (% (Expression R)))): Not documented!!!!
--->-->DistributedExpression(): Missing Description
; compiling file "/var/aw/var/LatexWiki/DEXPR.NRLIB/DEXPR.lsp" (written 19 SEP 2014 09:22:21 PM):
; /var/aw/var/LatexWiki/DEXPR.NRLIB/DEXPR.fasl written
; compilation finished in 0:00:00.040
------------------------------------------------------------------------
DistributedExpression is now explicitly exposed in frame initial
DistributedExpression will be automatically loaded when needed from
/var/aw/var/LatexWiki/DEXPR.NRLIB/DEXPRUnfortunately, it seems that it is not possible to tell Axiom to take all the exported functions of a given domain and export them. So we have to include the whole Exports section of EXPR...
ex1::DistributedExpression(Integer)
| (6) |
((1+2*a+3*b)*(4*c+5*d))::DEXPR INT
| (7) |
%::POLY INT
| (8) |
Unfortunately, it seems that it is not possible to tell Axiom to take all the exported functions of a given domain and export them.
Isn't this a case where one should define a category relevant to both Expression and DistributedExpression? in order to avoid duplication of the list of exports?
Yes, but since Spad doesn't support Aldor's keywordextend, this cannot be done post factum...