

last edited 3 days ago by test1 
1 2  
Editor: test1
Time: 2018/02/15 15:57:08 GMT+0 

Note: 
changed: One of the most frustrating things as a novice axiom user is to try to figure out how to get One of the most frustrating things as a novice FriCAS user is to try to figure out how to get
One of the most frustrating things as a novice FriCAS user is to try to figure out how to get FriCAS output to appear in the desired form. For instance:
(a + b)/2
(1) 
but if one wanted it formatted as a single fraction
(a + b)/2 :: FRAC POLY INT
(2) 
However, this doesn't always work:
1/2  exp(t)
(3) 
but if one wanted the output to appear as:
(4) 
1/2  exp(t) :: POLY FRAC Integer
Cannot convert the value from type Expression(Integer) to Polynomial (Fraction(Integer)) .
this doesn't work. So how does one deal with output formatting for Expression Integers?
In this particular case you have to say
1/2  exp(t) :: EXPR FRAC INT
(5) 
since you have an expression here, not a polynomial.
In general, to modify the way FriCAS 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 FriCAS to output expressions in distributed form.
Here are some more detailed explanations:
Whenever FriCAS 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:
x^2y^2
(6) 
(x^2y^2)::Factored Polynomial Integer
(7) 
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 DistributedExpression.
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:
z*a+a
(8) 
z*a+z
(9) 
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 (but you can see difference only in some large, tricky cases).
As follows from the above, this currently cannot be done within the domain EXPR INT
.
However, one can avoid combining subexpression with surrounding terms using
box
operator:
x+box(1/(y+1))
(10) 
Similarly, one can use paren
operator to present expressions in factored form:
paren(exp(x)  x)*paren(exp(x) + x)
(11) 
Note that box
and paren
inhibit normal simplification, so
paren(x)  x
(12) 
will not simplify to 0. One needs to use distribute
to cancel
effect of box
or 'paren':
distribute(paren(x)  x)
(13) 
I think that there are several possibilities, which I will explain on an old example, the problem of displaying expressions in "fully expanded" form:
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.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.