factor((A-B)*(B-C)).list() ?

27 views
Skip to first unread message

Rolandb

unread,
Oct 23, 2023, 12:23:32 PM10/23/23
to sage-support
Hi,

I am surprised by  the output (9.8 and 10.1 Ubuntu):
var('A,B,C') factor((A-B)*(B-C)).list()
var('A,B,C') factor((A-B)*(B-C)).list()

    var('A,B,C')
    factor((A-B)*(B-C)).list()
    [-B^2 + B*C, B - C]

I expected [B - A, B - C]. Any explanation?

Kind regards,

Roland
Message has been deleted
Message has been deleted

Emmanuel Charpentier

unread,
Oct 23, 2023, 2:48:15 PM10/23/23
to sage-support
sage: var("a, b, c") (a, b, c) sage: foo=(a-b)*(b-c) ; foo (a - b)*(b - c)

Note that :

sage: foo.expand() a*b - b^2 - a*c + b*c

From foo.list? :

Docstring: Return the coefficients of this symbolic expression as a polynomial in x. INPUT: * "x" -- optional variable. OUTPUT: A list of expressions where the "n"-th element is the coefficient of "x^n" when self is seen as polynomial in "x".

Therefore :

sage: foo.list() [-b^2 + b*c, b - c]

Is indeed the list of foo’s coefficients of powers of a.

What you seek is :

sage: foo.operands() [a - b, b - c]

HTH,

BTW, a better forum or this kind of questions is probably ask.sagemath.org.

Reply all
Reply to author
Forward
0 new messages