Update of bug #10530 (project axiom):
Status: None => transferred
fricas
(1) -> gcd((x-2^a)::UP(x, EXPR INT), simplify((x-2^a)*(x+2^a))::UP(x, EXPR INT))
Gives 1, while the correct answer should be , as given by
fricas
gcd((x-2^a)::UP(x, EXPR INT),((x-2^a)*(x+2^a))::UP(x, EXPR INT))
In fact, to ensure that algebraic relations are respected inside expressions one has to normalize
all involved expressions:
fricas
uP := UP(x, EXPR INT)
Type: Type
fricas
p1 := (x-2^a)::uP
fricas
p2 := simplify((x-2^a)*(x+2^a))::uP
fricas
cl1 := coefficients(p1)
Type: List(Expression(Integer))
fricas
cl2 := coefficients(p2)
Type: List(Expression(Integer))
fricas
ncl := normalize(concat(cl1, cl2))
Type: List(Expression(Integer))
fricas
ncl1 := first(ncl, #cl1)
Type: List(Expression(Integer))
fricas
ncl2 := rest(ncl, #cl1)
Type: List(Expression(Integer))
fricas
np1 := reduce(_+, [monomial(c,degree(m))$uP for m in monomials(p1) for c in ncl1])
fricas
np2 := reduce(_+, [monomial(c,degree(m))$uP for m in monomials(p2) for c in ncl2])
fricas
gcd(np1, np2)
Not nice, but in general this is what is needed (below are simpler attempts which sometimes
work, but may fail).
Internal Cause
In EXPR INT, and are treated as two variables
without relations in EXPR INT. But
fricas
simplify((x-2^a)*(x+2^a))::UP(x, EXPR INT)
Therefore exquo in:
exquo(simplify((x-2^a)*(x+2^a))::UP(x,EXPR INT),(x-2^a)::UP(x,EXPR INT))
fails. In details, it calls exquo$UP(x,EXPR INT)
. This implements exact division of
polynomials p1 by p2 as usual. After each subtraction - done via
fmecg$UP
- the result is again stored in p1. exquo terminates
when p1 is the empty list - note that UPs? are stored as lists
of pairs (degree, coefficient) - or the degree of p2 is larger
than p1. In the latter case, exquo fails.
Thus, in our case, at one point p1 is , which is zero
mathematically, but FriCAS does not know it. In particular,
p1 is not the empty list, but rather a constant polynomial...
To get correct result we need to express coefficients of p1 and p2
in terms of independent kernels. In more general contexts (in
particular involving abs
) this is undecidable, but for
elementary functions normalize
works. More precisely,
currently normalize
ignores possible dependencies
between algebraic quantities like roots. And to simplification
of transcendental constants depends on Schanuel conjecture
(if Schanuel conjecture is false we may miss some dependencies).
Wed 09/29/2004 at 16:02, comment #1:
I should have added:
fricas
exquo(normalize(simplify(((A-2^a)*(A+2^a)))::EXPR INT),normalize((A-2^a)::EXPR INT))
Type: Union(Expression(Integer),...)
fricas
exquo(simplify((A-2^a)*(A+2^a))::UP(A,EXPR INT),(A-2^a)::UP(A,EXPR INT))
Type: Union("failed",...)
This shows that using normalize separately on polynomials does not help, we need
to normalize list of coefficients as a whole.
Few examples showing that without normalization FriCAS does not always treat
the same as :
fricas
dom:=UP('x,EXPR INT)
Type: Type
fricas
p:dom:=x-2^a
fricas
q:=(x-2^a)*(x+2^a)
Type: Expression(Integer)
fricas
qq:= simplify(q)
Type: Expression(Integer)
fricas
r:= q::dom
fricas
rr:= qq::dom
fricas
gcd(p,q)
fricas
exquo(q,p)
Type: Union(Expression(Integer),...)
fricas
gcd(p,r)
fricas
gcd(p,qq)
fricas
gcd(p,rr)
fricas
q - qq
Type: Expression(Integer)
fricas
simplify q - qq
Type: Expression(Integer)
fricas
simplify ((r - rr)::EXPR INT)
Type: Expression(Integer)
fricas
t:Boolean:=(r = rr)
Type: Boolean
Status: open => closed