login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for AxiomOutputFormatting revision 1 of 1

1
Editor:
Time: 2008/05/28 20:38:20 GMT-7
Note:

changed:
-
One of the most frustrating things as a novice axiom user is to try to figure out how to get axiom output to appear in the desired form.  For instance:

\begin{axiom}
(a + b)/2
\end{axiom}
but if one wanted it formatted as a single fraction
\begin{axiom}
(a + b)/2 :: FRAC POLY INT
\end{axiom}

However, this doesn't always work:
\begin{axiom}
1/2 - exp(-t)
\end{axiom}

but if one wanted the output to appear as:
\begin{equation}
\frac{1}{2} + e^{(-t)}
\end{equation}
 
\begin{axiom}
1/2 - exp(-t) :: POLY FRAC Integer
\end{axiom}

this doesn't work.  So how does one deal with output formatting for Expression Integers?

In this particular case you have to say
\begin{axiom}
1/2 - exp(-t) :: EXPR FRAC INT
\end{axiom}

since you have an expression here, not a polynomial.

In general, to modify the way Axiom outputs your expressions, you have to write a wrapper domain that replaces 'coerce: % -> OutputForm' with your own code. This is not difficult, I have done this to convince Axiom to "output expressions in distributed form":SandBoxDistributedExpression.

Here are some more detailed explanations:

How can I affect the way Axiom displays its results?

    Whenever Axiom needs to write an element of a domain, i.e., an expression from
'Expression Integer', a number from 'PrimeField 5', a factored polynomial from
'Factored Polynomial Fraction Integer', etc., to the screen, it calls the
operation with the signature 'coerce: % -> OutputForm' from that domain.

For example, to output a polynomial in factored form, the "real" way to do it
is to coerce it into the domain Factored Polynomial Integer:

\begin{axiom}
x^2-y^2
(x^2-y^2)::Factored Polynomial Integer
\end{axiom}

Thus, philosophically, the way things are output depends only on the domain,
and if we want to implement a different way, we need to implement a new
domain. This is very easy, see SandBoxDistributedExpression.

How does this work in 'Polynomial Integer', 'Expression Integer'?

    The domain 'EXPR INT' contains expressions in the form p/q where p and q are
polynomials -- with the variables being the "kernels" -- and the polynomials
are displayed in the same form as in 'POLY INT', which is unfortunately slightly
confusing. Roughly: "larger" variables are factored out:

\begin{axiom}
z*a+a
z*a+z
\end{axiom}

since "z" is "larger" than "a". Of course, "larger" is simply a rather
arbitrary, but fortunately fixed internal order of the variables. For
Expressions, this order is not even fixed, I think, but I might be wrong here.
In fact, this ordering is the thing about axiom that I hate most, I don't
really want it to say:

\begin{axiom}
tan x > sin x
tan x > sin y
\end{axiom}

although I got used to it...

Can I make Axiom display $(xy+x+1)/(y+1)$ as $x+1/(y+1)$?

    As follows from the above, this currently cannot be done within the domain 'EXPR INT'. I think that there are several possibilities, which I will explain on an
old example, the problem of displaying expressions in "fully expanded" form:

* one can write a domain which only overrides the output functionality, and
  applies the simplifications every time the element is written on the
  screen. That's what I have done for DistributedExpression. This is the quick
  and dirty way.

* one writes a new domain with a new representation. For
  'DistributedExpression' I failed to do so, since the proper representation
  would be 'DMP', but this only accepts a 'List Symbol' as variables, for
  expressions I need to allow an arbitrary 'OrderedSet' however.

* one abstracts the form and writes a new functor, as for example
  'Factored'. I'm not quite sure, but it may be that a functor 'Distributed'
  would be the best solution. I would have to look why the original developers
  chose to implement 'DistributedMultivariatePolynomials' instead.

So, the conclusion is that you might want to write a function first that takes
- for example - an expression and returns a list of expressions. It would be
easy to make this into a new domain "MyExpression". I vaguely recall that
Maxima has such a function.

One of the most frustrating things as a novice axiom user is to try to figure out how to get axiom output to appear in the desired form. For instance:

axiom
(a + b)/2
LatexWiki Image(1)
Type: Polynomial Fraction Integer

but if one wanted it formatted as a single fraction

axiom
(a + b)/2 :: FRAC POLY INT
LatexWiki Image(2)
Type: Fraction Polynomial Integer

However, this doesn't always work:

axiom
1/2 - exp(-t)
LatexWiki Image(3)
Type: Expression Integer

but if one wanted the output to appear as:

LatexWiki Image(4)

axiom
1/2 - exp(-t) :: POLY FRAC Integer
Cannot convert from type Expression Integer to Polynomial Fraction Integer for value - t %e

this doesn't work. So how does one deal with output formatting for Expression Integers?

In this particular case you have to say

axiom
1/2 - exp(-t) :: EXPR FRAC INT
LatexWiki Image(5)
Type: Expression Fraction Integer

since you have an expression here, not a polynomial.

In general, to modify the way Axiom outputs your expressions, you have to write a wrapper domain that replaces coerce: % -> OutputForm with your own code. This is not difficult, I have done this to convince Axiom to output expressions in distributed form.

Here are some more detailed explanations:

How can I affect the way Axiom displays its results?

Whenever Axiom needs to write an element of a domain, i.e., an expression from Expression Integer, a number from PrimeField 5, a factored polynomial from Factored Polynomial Fraction Integer, etc., to the screen, it calls the operation with the signature coerce: % -> OutputForm from that domain.

For example, to output a polynomial in factored form, the "real" way to do it is to coerce it into the domain Factored Polynomial Integer:

axiom
x^2-y^2
LatexWiki Image(6)
Type: Polynomial Integer
axiom
(x^2-y^2)::Factored Polynomial Integer
LatexWiki Image(7)
Type: Factored Polynomial Integer

Thus, philosophically, the way things are output depends only on the domain, and if we want to implement a different way, we need to implement a new domain. This is very easy, see SandBoxDistributedExpression.

How does this work in Polynomial Integer, Expression Integer?

The domain EXPR INT contains expressions in the form p/q where p and q are polynomials -- with the variables being the "kernels" -- and the polynomials are displayed in the same form as in POLY INT, which is unfortunately slightly confusing. Roughly: "larger" variables are factored out:

axiom
z*a+a
LatexWiki Image(8)
Type: Polynomial Integer
axiom
z*a+z
LatexWiki Image(9)
Type: Polynomial Integer

since "z" is "larger" than "a". Of course, "larger" is simply a rather arbitrary, but fortunately fixed internal order of the variables. For Expressions, this order is not even fixed, I think, but I might be wrong here. In fact, this ordering is the thing about axiom that I hate most, I don't really want it to say:

axiom
tan x > sin x
LatexWiki Image(10)
Type: Boolean
axiom
tan x > sin y
LatexWiki Image(11)
Type: Boolean

although I got used to it...

Can I make Axiom display LatexWiki Image as LatexWiki Image?

As follows from the above, this currently cannot be done within the domain EXPR INT. I think that there are several possibilities, which I will explain on an old example, the problem of displaying expressions in "fully expanded" form:

  • one can write a domain which only overrides the output functionality, and applies the simplifications every time the element is written on the screen. That's what I have done for DistributedExpression?. This is the quick and dirty way.
  • one writes a new domain with a new representation. For DistributedExpression I failed to do so, since the proper representation would be DMP, but this only accepts a List Symbol as variables, for expressions I need to allow an arbitrary OrderedSet however.
  • one abstracts the form and writes a new functor, as for example Factored. I'm not quite sure, but it may be that a functor Distributed would be the best solution. I would have to look why the original developers chose to implement DistributedMultivariatePolynomials instead.

So, the conclusion is that you might want to write a function first that takes - for example - an expression and returns a list of expressions. It would be easy to make this into a new domain "MyExpression?". I vaguely recall that Maxima has such a function.