On 18.07.23 19:03, '68th' via FriCAS - computer algebra system wrote:
How to make FriCAS distribute over addition?
For example, (a+b)*c into a*c+b*c.
Thank you for this question. I am currently trying to put a collections
of such simple things into a notebook. And I'll probably also take that
example.
So please do not hesitate to ask such seemingly stupid questions. FriCAS
is known to have a steep learning curve. I would like to cure it by
providing many more examples that FriCAS beginners struggle with.
Let me try to "solve" your problem.
Would you call the following behaviour of FriCAS a bit weird?
(204) -> (a+b)*c
(204) (b + a)c
Type: Polynomial(Integer)
(205) -> (c+b)*a
(205) a c + a b
Type: Polynomial(Integer)
No, it is not. And for that to understand you always have to keep in
mind that in contrast to most other computer algebra systems, every
object in FriCAS has a type, above you see Polynomial(Integer).
Type information can be switched on or off via
)type on
)type off
When you type something into a FriCAS session like (a+b)*c, then the
interpreter tries to make sense out of this information. In particular,
it tries to find an appropriate type for your input. In your case,
Polynomial(Integer).
What is Polynomial(Integer). Mathematically, that is the ring Z[X] where
X is the set of any variable (symbol) you can think of, i.e. a ring in
infinitely many variables. All those variable are are sorted and this
sorting agrees with the order in the type Symbol. We have
(207) -> a < b
(207) true
(208) -> b < c
(208) true
So c is the biggest variable. In fact your polynomial lives in
Z[a][b][c]. Yes, it is a polynomial in c with coefficients in Z[a][b].
So (a+b)*c is a polynomial in c (of degree 1 with coefficient (a+b)
being a polynomial (of degree 1) in b with leading coefficient 1 and the
"constant" being the polynomial a from Z[a].
Now how would you print a polynomial in c? Right, as a sum of terms of
the form coefficient*c^n. The coefficient is (a+b) and n is 1 in your
case. So printing (a+b)*c is perfectly fine. That explains (204) from above.
What about (205)? Well, also (c+b)*a is a polynomial of degree 1 in c
having the coefficient a. That explains the a*c part. The "constant"
term of this polynomial is the polynomial a*b (degree 1 in b and
coefficient a).
Good. That explains what FriCAS does, but does not solve your problem.
In fact, I do not know the solution myself. FriCAS certainly knows about
the distributive law, but the answer to your question depends on what
you actually want to achieve. Let me give you one solution. That simply
converts your input into a type that always prints its elements in a
distibuted form.
(209) -> ((a+b)*c)::DistributedMultivariatePolynomial([a,b,c],Integer)
(209) a c + b c
Type: DistributedMultivariatePolynomial([a,b,c],Integer)
However, now the type is something else.
Please pose more questions if something is or becomes unclear.
Ralf
--
You received this message because you are subscribed to the Google Groups "FriCAS -
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/907d79f7-a520-748e-a65b-88f65d04b705%40hemmecke.org.