Special Products in Sage

During engineering school no matter what math or physics I was in the work we were doing almost always came down to using one of these algebraic formulas. Every time they came up I always said, “I’ll go back one day and memorize those”, or would just manually redo them each time. I missed a lot of realizations and answers because they weren’t fresh on my mind, and they were also building blocks for other stuff. So here they are to remind us and how to see them expanded is Sage.

Initializing Variables:

sage: a,b,c,d,x = var('a,b,c,d,x')

Product of a Monomial and a Binomial

sage: eqn_mon_bin = a*(c+d)
sage: eqn_mon_bin.expand()
a*c + a*d

Product of the Sum and the Difference of Two Terms

sage: eqn_prod_sum_diff = (a+b)*(a-b)
sage: eqn_prod_sum_diff.expand()
a^2 - b^2

Square of a Binomial

sage: eqn_bin_sq = (a+b)^2
sage: eqn_bin_sq.expand()
a^2 + 2*a*b + b^2

sage: eqn_bin_sq_diff = (a-b)^2
sage: eqn_bin_sq_diff.expand()
a^2 - 2*a*b + b^2

Product of Two Binomials

sage: eqn_bin_prod = (x+a)*(x+b)
sage: eqn_bin_prod.expand()
a*b + a*x + b*x + x^2

Cube of Binomial

sage: eqn_bin_cube = (a+b)^3
sage: eqn_bin_cube.expand()
a^3 + 3*a^2*b + 3*a*b^2 + b^3

Square of a Trinomial

sage: eqn_tri_sq = (a+b+c)^2
sage: eqn_tri_sq.expand()
a^2 + 2*a*b + b^2 + 2*a*c + 2*b*c + c^2

 

Tools:
1. SageMathCloud

References:
1. Sage Docs – Symbolic Expressions
2. Schaum’s Outline of College Algebra