All about simplification

Jan 29 2024

In this post, we list out all the steps the Mathlify library does to "simplify" expressions.

Fraction

  • "Hoist" negative denominators to the numerator if necessary so that denominators are always positive. For example, 52 will be simplified to 52.
  • Extract gcd such that the numerator and denominator are coprime. For example 156 becomes 52 and 06 becomes 01.

Sum

  • Combines like terms into a Product of a numerical coefficient and the term
  • _combine_like_terms() also combines Numerals such that there are at most one Numeral in a Sum.
  • Nested sums are flattened.
  • Numerals of 0s are removed.

Product

  • Combines Numerals to become a coeff at the start of the product
  • Nested products are flattened
  • (New feature introduced 24/6/17) Product containing a quotient will be changed into a quotient with the products in the numerator

Expression

The Expression class allow us to modify the underlying type

  • Any Bracket class are changed to the underlying type.
  • An empty Sum will be changed to a Numeral of 0.
  • A singleton Sum will be changed to the underlying type.
  • An empty Product will be changed to a Numeral of its coeff
  • A product with a single factor and coeff of 1 will be changed to the underlying type
  • A product with a coeff of 0 will be changed to a Numeral 0.
  • A Quotient with a numerator of Numeral 0 will be changed 0
  • A Quotient with a denominator of Numeral 1 will be changed to the underlying numerator type
  • A Quotient with Numerals on both numerator and denominator will be changed to a Numeral class
  • A Quotient with a negative Numeral or a negative Product will be changed to a product with a coeff of -1
  • An Exponent with positive integral Numeral power and a Product base will be cased of a Product of Exponents