Mode of #cas

together

Writes a rational expression as one fraction in lowest terms, with the conditions under which they agree.

#cas [together] e
writes the rational expression e as one fraction in lowest terms and gives the conditions under which the fraction equals e.

together puts a sum of fractions over one denominator, the way you would by hand. The answer comes with a theorem, and the conditions of the theorem come from the divisors of the input.

On paper we rarely write those conditions down, but Lean needs them, because its division is total: 1/0=0. At x=0 the sum 1/x+1/y is 1/y in Lean, while (x+y)/(xy) is y/0=0. So the identity needs x≠0 and y≠0, and the theorem has them as hypotheses.

Details and Options

  • The theorem has the form ∀x1,…,xn,d1≠0→…→dk≠0→e=N/D about Mathlib’s real division, where d1,…,dk are the divisors of e as written. It is proved by field_simp and ring.
  • The input is built from real variables and rational numbers by +, -, *, / and natural powers, and every divisor is a polynomial.
  • The denominator D is a product of powers of pairwise coprime polynomials obtained from the divisors by gcds, so it stays factored as far as the input factors it. Each factor of D divides one of the di, which ring shows. The numerator N is expanded.
  • A divisor that is a number gives no condition.
  • numerator and denominator print N and D, with the same theorem. cancel cancels inside each summand without a common denominator, and apart goes the other way.
  • The tactic cas proves these identities, with the conditions as hypotheses.
  • There are no options.

Examples (13)#

Basic Examples (2)

Two reciprocals:

In[1]:=
#cas [together] (1/x + 1/y)
Out[1]=

common denominator

x+yxy
(x + y)/(x*y)
Input (rational function)
(1/x + 1/y)
Conditions
x≠0, y≠0

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → 1 / x + 1 / y = (x + y) / (x * y)
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → 1 / x + 1 / y = (x + y) / (x * y)

    Checked by Lean’s kernel


The denominator stays factored as the input factors it, and each divisor gives a condition:

In[2]:=
#cas [together] (1/(x^2-1) + 1/(x-1))
Out[2]=

common denominator

x+2(x−1)(x+1)
(x + 2)/((x - 1)*(x + 1))
Input (rational function)
(1/(x^2-1) + 1/(x-1))
Conditions
x2−1≠0, x−1≠0

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x : ℝ),
  x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x : ℝ),
      x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))

    Checked by Lean’s kernel

Scope (2)

Numbers as divisors need no condition:

In[3]:=
#cas [together] (x/2 + y/3)
Out[3]=

common denominator

3x+2y6
(3*x + 2*y)/6
Input (rational function)
(x/2 + y/3)

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ), x / 2 + y / 3 = (3 * x + 2 * y) / 6
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ), x / 2 + y / 3 = (3 * x + 2 * y) / 6

    Checked by Lean’s kernel


The fraction is in lowest terms. Here the common factor x−y cancels, and the condition is still the divisor of the input:

In[4]:=
#cas [together] ((x^3 - y^3)/(x^2 - y^2))
Out[4]=

common denominator

x2+xy+y2x+y
(x^2 + x*y + y^2)/(x + y)
Input (rational function)
((x^3 - y^3)/(x^2 - y^2))
Conditions
x2−y2≠0

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ),
  x ^ 2 - y ^ 2 ≠ 0 → (x ^ 3 - y ^ 3) / (x ^ 2 - y ^ 2) = (x ^ 2 + x * y + y ^ 2) / (x + y)
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ),
      x ^ 2 - y ^ 2 ≠ 0 → (x ^ 3 - y ^ 3) / (x ^ 2 - y ^ 2) = (x ^ 2 + x * y + y ^ 2) / (x + y)

    Checked by Lean’s kernel

Applications (2)

The first example as a theorem, with the conditions as hypotheses. Only the three standard axioms are used:

In[5]:=
theorem reciprocals_together (x y : ℝ) (hx : x ≠ 0) (hy : y ≠ 0) :
    1 / x + 1 / y = (x + y) / (x * y) := by
  cas

#print axioms reciprocals_together
Out[5]=

reciprocals_together depends on the axioms propext, Classical.choice, Quot.sound.


Without the conditions the identity is false in Lean. At x=0 and y=1 the left side is 1 and the right side is 1/0=0:

In[6]:=
example : ¬ ∀ x y : ℝ, 1 / x + 1 / y = (x + y) / (x * y) := by
  intro h
  have := h 0 1
  norm_num at this
Out[6]=

Lean accepts the proof.

Properties and Relations (4)

numerator gives the numerator x+y of the first example:

In[7]:=
#cas [numerator] (1/x + 1/y)
Out[7]=

numerator

x + y
Input (rational function)
(1/x + 1/y)
Conditions
x≠0, y≠0

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → 1 / x + 1 / y = (x + y) / (x * y)
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ), x ≠ 0 → y ≠ 0 → 1 / x + 1 / y = (x + y) / (x * y)

    Checked by Lean’s kernel


denominator gives the 6 of (3x+2y)/6:

In[8]:=
#cas [denominator] (x/2 + y/3)
Out[8]=

denominator

6
Input (rational function)
(x/2 + y/3)

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ), x / 2 + y / 3 = (3 * x + 2 * y) / 6
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ), x / 2 + y / 3 = (3 * x + 2 * y) / 6

    Checked by Lean’s kernel


cancel cancels inside each summand and keeps the sum:

In[9]:=
#cas [cancel] ((x^2-1)/(x-1) + 1/x)
Out[9]=

cancelled

x+1+1x
x + 1 + 1/x
Input (rational function)
((x^2-1)/(x-1) + 1/x)
Conditions
x−1≠0, x≠0

Checked by Lean’s kernel: Identity with the cancelled form

∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x
The certificate: 1 checked step
  1. Identity with the cancelled form

    ∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x

    Checked by Lean’s kernel


apart splits one fraction into partial fractions:

In[10]:=
#cas [apart] (1/((x - 1)*(x + 1)))
Out[10]=

partial fractions

12(x−1)−12(x+1)
1/(2*(x - 1)) - 1/(2*(x + 1))
Input (rational function)
(1/((x - 1)*(x + 1)))
Conditions
(x−1)(x+1)≠0

Checked by Lean’s kernel: Identity with the partial fraction decomposition

∀ (x : ℝ), (x - 1) * (x + 1) ≠ 0 → 1 / ((x - 1) * (x + 1)) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1))
The certificate: 1 checked step
  1. Identity with the partial fraction decomposition

    ∀ (x : ℝ), (x - 1) * (x + 1) ≠ 0 → 1 / ((x - 1) * (x + 1)) = 1 / (2 * (x - 1)) - 1 / (2 * (x + 1))

    Checked by Lean’s kernel

Possible Issues (3)

The conditions are the divisors as written. Here (xy+x−x)2 is x2y2, and the condition keeps the form of the input:

In[11]:=
#cas [together] (1/((x*y + x - x)^2) + 1)
Out[11]=

common denominator

x2y2+1x2y2
(x^2*y^2 + 1)/(x^2*y^2)
Input (rational function)
(1/((x*y + x - x)^2) + 1)
Conditions
(xy+x−x)2≠0

Checked by Lean’s kernel: Identity with the common-denominator form

∀ (x y : ℝ),
  (x * y + x - x) ^ 2 ≠ 0 → 1 / (x * y + x - x) ^ 2 + 1 = (x ^ 2 * y ^ 2 + 1) / (x ^ 2 * y ^ 2)
The certificate: 1 checked step
  1. Identity with the common-denominator form

    ∀ (x y : ℝ),
      (x * y + x - x) ^ 2 ≠ 0 → 1 / (x * y + x - x) ^ 2 + 1 = (x ^ 2 * y ^ 2 + 1) / (x ^ 2 * y ^ 2)

    Checked by Lean’s kernel


A divisor must be a polynomial. Multiply the inner fraction out first. For x≠0 the expression is x/(x+1):

In[12]:=
#cas [together] (1/(1 + 1/x))
Out[12]=

Error

together: a divisor is itself a quotient; write the expression with polynomial divisors

Functions other than the field operations are refused. simplify and fullSimplify accept them:

In[13]:=
#cas [together] (sin x / x)
Out[13]=

Error

together: the expression is not a rational function: it has a function other than the field operations and natural powers

See Also

cancel · numerator · denominator · apart · simplify