Grace/Cumulus/NumberTheory/ReducedFraction.g17
Imports
Grace.Cumulus.NumberTheory.IntegerDivisibility
Declarations
- Integer.reduced_fraction theorem derivation
- IntegerCoprime.divides_cube theorem derivation
Source
1-- Fractions in lowest terms over the integers: every quotient p/q with2-- q ≠ 0 is a coprime quotient, and a denominator coprime to p that divides3-- p³ is a unit.4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.NumberTheory.ReducedFraction10import Grace.Cumulus.NumberTheory.IntegerDivisibility1112-- Dividing by the greatest common divisor: g = integerGCD(p, q) is13-- positive since q ≠ 0, p = g p' and q = g q', and the Bézout identity14-- u p + v q = g cancels to u p' + v q' = 1.15theorem Integer.reduced_fraction (p q : Integer)16 requires nonzero : q ≠ 017 shows ∃ p2 ∈ ℤ, ∃ q2 ∈ ℤ,18 q2 ≠ 0 ∧ IntegerCoprime(p2, q2) ∧ p * q2 = p2 * q19proof20 obtain ⟨p2, p2Integer, pShape⟩ := integerGCD.divides_left at p, q21 obtain ⟨q2, q2Integer, qShape⟩ := integerGCD.divides_right at p, q22 obtain ⟨u, uInteger, v, vInteger, identity⟩ := integerGCD.bezout at p, q23 have gNonzero : integerOfNat(integerGCD(p, q)) ≠ 024 intro zero25 apply nonzero26 rw [← qShape, zero]27 ring28 have q2Nonzero : q2 ≠ 029 intro zero30 apply nonzero31 rw [← qShape, zero]32 ring33 have scaled : integerOfNat(integerGCD(p, q)) * (u * p2 + v * q2) =34 integerOfNat(integerGCD(p, q)) * integerOne35 linear_combination identity + u * pShape + v * qShape36 have bezout := integerMulValue.left_cancel at u * p2 + v * q2, integerOne,37 integerOfNat(integerGCD(p, q)) with gNonzero, scaled38 have coprime := IntegerCoprime.of_bezout at p2, q2, u, v with bezout39 have cross : p * q2 = p2 * q40 linear_combination p2 * qShape - q2 * pShape41 exact ⟨p2, p2Integer, q2, q2Integer, q2Nonzero, coprime, cross⟩4243-- A divisor of p³ coprime to p divides 1: three coprime cancellations and44-- IntegerDivides.unit_iff.45theorem IntegerCoprime.divides_cube (p q : Integer)46 requires coprime : IntegerCoprime(q, p)47 requires divides : IntegerDivides(q, p * p * p)48 shows q = 1 ∨ q = -149proof50 have shape : p * p * p = p * (p * p) by ring51 rw shape at divides52 have square := IntegerCoprime.cancel at q, p, p * p with coprime, divides53 have linear := IntegerCoprime.cancel at q, p, p with coprime, square54 have unit : IntegerDivides(q, p * integerOne)55 rw integerMulValue.one_right56 exact linear57 have one := IntegerCoprime.cancel at q, p, integerOne with coprime, unit58 exact IntegerDivides.unit_iff.forward with one59