On 20.07.23 15:29, '68th' via FriCAS - computer algebra system wrote:
(323) -> eq := c^2 = a^2 + b^2 -(2ab)*cos(gamma)
The reason why I enclosed 2ab in brackets is to visually separate it
from cosine. Otherwise one could think there are six variables: a, b,
c, o, s, and γ. That's not what I want FriCAS to distribute.
Sure. In FriCAS, can achieve that
a b
(with a space inbetween) means a*b, but I do not explain that to a
beginner. If you write ab, it always denotes an identifier or variable
that consists of the two letters a and b (and is *one* thing. So cos is
one thing, namely, a function. In fact, I understood your notation as
mathematica (and I was probably right). Actually, mathematical notation
is not always unambiguous. But and input for a CAS must be clear,
otherwise if you enter nonsense, you get nonsense back.
(324) -> map(x +-> subst(x,[a=(l+k)/2, b=(l-k)/2]), eq)
I don't think that I fully understand this command
(13) -> -- Let's take a look at what the above command does.
(13) -> -- `eq` is an equation that consists of a left- and righthand side.
(13) -> lhs(eq)
2
(13) c
Type: Expression(Integer)
(14) -> rhs eq
2 2
(14) - 2 a b cos(gamma) + b + a
Type: Expression(Integer)
(15) -> -- NB: If a function has only one argument and this argument
(15) -> -- consists just of one part, then you can leave out the
parentheses.
(15) -> -- There is a function `map: (S -> S, %) -> %` in
(15) -> -- [Equation](https://fricas.github.io/api/Equation.html)(S) where
(15) -> -- the $S$ in our case is
(15) -> --
[Expression](https://fricas.github.io/api/Expression)([Integer](https://fricas.github.io/api/Integer)).
(15) -> -- The first argument of `map` is a function from $S$ to $S$ and
this
(15) -> -- is exactly what
(15) -> x +-> subst(x,[a=(l+k)/2,b=(l-k)/2])
l + k l - k
(15) x +-> subst(x,[a = -----, b = -----])
2 2
Type: AnonymousFunction
(16) -> -- is, a mapping from x to what is on the right of `+->` (which
should
(16) -> -- somewhat resemble the mathematical $\mapsto$ notation).
(16) -> --
(16) -> -- The second argument to `map` is the equation `eq` itself.
(16) -> -- According to its specification, `map` applies the function
(16) -> -- to the righthand and the lefthand side of the equation.
(16) -> -- In our case, it will do nothing on the lefthand side,
(16) -> -- but on the righthand side it substitutes $\frac{l+k}{2}$ for $a$,
(16) -> -- and similarly $\frac{l-k}{2}$ for $b$.
Hope that explains it.
That's just a preliminary step. Now we get to the point. How to
distribute cos(γ) over (k²-l²) and then factor out k² and l² to
derive k²(1+cos(γ))+l²(1-cos(γ))?
Try the following.
(17) -> eq := c^2 = a^2 + b^2 -(2*a*b)*cos(gamma)
2 2 2
(17) c = - 2 a b cos(gamma) + b + a
Type:
Equation(Expression(Integer))
(18) -> ex := subst(rhs eq,[a=(l+k)/2,b=(l-k)/2])
2 2 2 2
(- l + k )cos(gamma) + l + k
(18) -------------------------------
2
Type:
Expression(Integer)
(19) -> ex :: DistributedMultivariatePolynomial([k,l],Expression Integer)
cos(gamma) + 1 2 - cos(gamma) + 1 2
(19) -------------- k + ---------------- l
2 2
Type:
DistributedMultivariatePolynomial([k,l],Expression(Integer))
Note that now the resulting type has a coefficient ring
Expression(Integer) (not just Integer).
Admittedly, that's a bit dangerous, because how can FriCAS decide
that your input k is the variable of
DistributedMultivariatePolynomial([k,l],Expression Integer) and
does not belong to the coefficient domain Expression(Integer)?
It cannot unless the user help. Anyway, here is a big problem.
You can also achieve the following with exposed lokal variable in other
CAS. So be careful.
First, just a macro to make things shorter...
(20) -> Dkl ==> DistributedMultivariatePolynomial([k,l],Expression Integer)
Type: Void
The variable k.
(21) -> k1 := k::Dkl
(21) k
Type:
DistributedMultivariatePolynomial([k,l],Expression(Integer))
(22) -> k2 := k::Expression(Integer) * 1$Dkl
An expression k that lives in the coefficient domain of the polynomial ring.
(22) k
Type:
DistributedMultivariatePolynomial([k,l],Expression(Integer))
(23) -> [degree(k1,k), degree(k2,k)]
(23) [1, 0]
Type:
List(NonNegativeInteger)
(24) -> k1-k2
(24) k - k
Type:
DistributedMultivariatePolynomial([k,l],Expression(Integer))
That is, of course, not 0. And FriCAS is right. The input is what is
dangerous.
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/971bda71-4654-4fe1-3f98-20380ebf69cd%40hemmecke.org.