Grace/Cumulus/Nat/RootLemmas.g17

Open in Workbench Download source

Imports

Root

Declarations

Source

1-- Integer roots of products and of roots, and cancelling powers2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: András Salamon67module Grace.Cumulus.Nat.RootLemmas8import Root910-- Section: Cancelling powers11-- Equal exponents cancel: a ^ s ≤ b ^ s gives a ≤ b.12theorem pow.base_cancel (a b s : Nat)13  requires positive : 1 ≤ s14  requires below : a ^ s ≤ b ^ s15  shows a ≤ b16proof17  have pa := pow.closed at a, s18  have pb := pow.closed at b, s19  have grows := rootNat.monotone at s, a ^ s, b ^ s with positive, below20  have ra := rootNat.pow at s, a with positive21  have rb := rootNat.pow at s, b with positive22  rw [ra, rb] at grows23  exact grows2425-- A base above 1 cancels: b ^ m ≤ b ^ n gives m ≤ n.26theorem pow.exponent_cancel (b m n : Nat)27  requires above : 1 < b28  requires below : b ^ m ≤ b ^ n29  shows m ≤ n30proof31  have split := Less.or_LessEqual at n, m32  cases split with larger | atMost33  . have grows := pow.exponent_strict at b, n, m with above, larger34    have pm := pow.closed at b, m35    have pn := pow.closed at b, n36    have notBelow := LessEqual.not_Less at b ^ m, b ^ n with below37    exfalso38    exact notBelow with grows39  . exact atMost4041-- Section: Bounds by the root42-- 1 ≤ ⌊n^(1/q)⌋ for 1 ≤ n.43theorem rootNat.ge_one (q n : Nat)44  requires positive : 1 ≤ q45  requires one : 1 ≤ n46  shows 1 ≤ rootNat(q, n)47proof48  have unit := pow.one_left at q49  have adjunction := rootNat.le_iff at q, n, 1 with positive50  rw unit at adjunction51  exact adjunction.backward with one5253-- The floor costs at most a factor 2 ^ q:54-- n ≤ 2 ^ q · ⌊n^(1/q)⌋ ^ q for 1 ≤ n.55theorem rootNat.pow_lower (q n : Nat)56  requires positive : 1 ≤ q57  requires one : 1 ≤ n58  shows n ≤ 2 ^ q * rootNat(q, n) ^ q59proof60  have rNat := rootNat.natural at q, n with positive61  have rOne := rootNat.ge_one at q, n with positive, one62  have above := rootNat.lt_succ_pow at q, n with positive63  have step := LessEqual.add_monotone_left at64    1, rootNat(q, n), rootNat(q, n) with rOne65  have twice : rootNat(q, n) + rootNat(q, n) = 2 * rootNat(q, n) by ring66  rw twice at step67  have grows := pow.base_monotone at68    rootNat(q, n) + 1, 2 * rootNat(q, n), q with step69  have split := pow.mul_base at 2, rootNat(q, n), q70  rw split at grows71  have succPow := pow.closed at rootNat(q, n) + 1, q72  have twoPow := pow.closed at 2, q73  have rootPow := pow.closed at rootNat(q, n), q74  have strict := Less.transitive_LessEqual at n, (rootNat(q, n) + 1) ^ q,75    2 ^ q * rootNat(q, n) ^ q with above, grows76  have succ := Less.add_one_le_of_lt at n, 2 ^ q * rootNat(q, n) ^ q with strict77  have self := LessEqual.add_one at n78  exact LessEqual.transitive at n, n + 1, 2 ^ q * rootNat(q, n) ^ q with79    self, succ8081-- Section: Roots of products82-- ⌊X^(1/q)⌋ · ⌊Y^(1/q)⌋ ≤ ⌊(X · Y)^(1/q)⌋.83theorem rootNat.mul_lower (q X Y : Nat)84  requires positive : 1 ≤ q85  shows rootNat(q, X) * rootNat(q, Y) ≤ rootNat(q, X * Y)86proof87  have xNat := rootNat.natural at q, X with positive88  have yNat := rootNat.natural at q, Y with positive89  have xBelow := rootNat.pow_le at q, X with positive90  have yBelow := rootNat.pow_le at q, Y with positive91  have xPow := pow.closed at rootNat(q, X), q92  have yPow := pow.closed at rootNat(q, Y), q93  have both := LessEqual.mul at rootNat(q, X) ^ q, X, rootNat(q, Y) ^ q, Y with94    xBelow, yBelow95  have split := pow.mul_base at rootNat(q, X), rootNat(q, Y), q96  rw ← split at both97  have adjunction := rootNat.le_iff at98    q, X * Y, rootNat(q, X) * rootNat(q, Y) with positive99  exact adjunction.backward with both100101-- ⌊(X · Y)^(1/q)⌋ < (⌊X^(1/q)⌋ + 1) · (⌊Y^(1/q)⌋ + 1).102theorem rootNat.mul_upper (q X Y : Nat)103  requires positive : 1 ≤ q104  shows rootNat(q, X * Y) < (rootNat(q, X) + 1) * (rootNat(q, Y) + 1)105proof106  have xNat := rootNat.natural at q, X with positive107  have yNat := rootNat.natural at q, Y with positive108  have xAbove := rootNat.lt_succ_pow at q, X with positive109  have yAbove := rootNat.lt_succ_pow at q, Y with positive110  have xPow := pow.closed at rootNat(q, X) + 1, q111  have yPow := pow.closed at rootNat(q, Y) + 1, q112  have both := Less.mul at X, (rootNat(q, X) + 1) ^ q, Y, (rootNat(q,113    Y) + 1) ^ q with xAbove, yAbove114  have split := pow.mul_base at rootNat(q, X) + 1, rootNat(q, Y) + 1, q115  rw ← split at both116  have adjunction := rootNat.lt_iff at q, X * Y, (rootNat(q,117    X) + 1) * (rootNat(q, Y) + 1) with positive118  exact adjunction.backward with both119120-- A q-th power factors out from below:121-- ⌊X^(1/q)⌋ · Y ≤ ⌊(X · Y ^ q)^(1/q)⌋.122theorem rootNat.mul_pow_lower (q X Y : Nat)123  requires positive : 1 ≤ q124  shows rootNat(q, X) * Y ≤ rootNat(q, X * Y ^ q)125proof126  have rNat := rootNat.natural at q, X with positive127  have rPow := pow.closed at rootNat(q, X), q128  have yPow := pow.closed at Y, q129  have below := rootNat.pow_le at q, X with positive130  have scaled := LessEqual.mul_right at rootNat(q, X) ^ q, X, Y ^ q with below131  have split := pow.mul_base at rootNat(q, X), Y, q132  rw ← split at scaled133  have adjunction := rootNat.le_iff at q, X * Y ^ q, rootNat(q, X) * Y with134    positive135  exact adjunction.backward with scaled136137-- And from above, for 1 ≤ Y:138-- ⌊(X · Y ^ q)^(1/q)⌋ < (⌊X^(1/q)⌋ + 1) · Y.139theorem rootNat.mul_pow_upper (q X Y : Nat)140  requires positive : 1 ≤ q141  requires one : 1 ≤ Y142  shows rootNat(q, X * Y ^ q) < (rootNat(q, X) + 1) * Y143proof144  have rNat := rootNat.natural at q, X with positive145  have rPow := pow.closed at rootNat(q, X) + 1, q146  have yPow := pow.closed at Y, q147  have above := rootNat.lt_succ_pow at q, X with positive148  have yPositive := (LessEqual.one_iff_positive at Y).forward with one149  have powPositive := pow.positive at Y, q with yPositive150  have nonzero := Less.ne_zero_of_positive at Y ^ q with powPositive151  have scaled := Less.mul_right at X, (rootNat(q, X) + 1) ^ q, Y ^ q with152    nonzero, above153  have split := pow.mul_base at rootNat(q, X) + 1, Y, q154  rw ← split at scaled155  have adjunction := rootNat.lt_iff at156    q, X * Y ^ q, (rootNat(q, X) + 1) * Y with positive157  exact adjunction.backward with scaled158159-- Section: Roots of roots160-- ⌊y^(1/(s·d))⌋ ^ d ≤ ⌊y^(1/s)⌋.161theorem rootNat.mul_index_lower (s d y : Nat)162  requires positive : 1 ≤ s163  requires positiveD : 1 ≤ d164  shows rootNat(s * d, y) ^ d ≤ rootNat(s, y)165proof166  have product := LessEqual.one_le_mul at s, d with positive, positiveD167  have rootNatural := rootNat.natural at s * d, y with product168  have power := pow.closed at rootNat(s * d, y), d169  have below := rootNat.pow_le at s * d, y with product170  have regroup := pow.mul_exponent at rootNat(s * d, y), d, s171  have swap : d * s = s * d by ring172  rw swap at regroup173  rw ← regroup at below174  have adjunction := rootNat.le_iff at s, y, rootNat(s * d, y) ^ d with positive175  exact adjunction.backward with below176177-- ⌊y^(1/s)⌋ < (⌊y^(1/(s·d))⌋ + 1) ^ d.178theorem rootNat.mul_index_upper (s d y : Nat)179  requires positive : 1 ≤ s180  requires positiveD : 1 ≤ d181  shows rootNat(s, y) < (rootNat(s * d, y) + 1) ^ d182proof183  have product := LessEqual.one_le_mul at s, d with positive, positiveD184  have rootNatural := rootNat.natural at s * d, y with product185  have power := pow.closed at rootNat(s * d, y) + 1, d186  have above := rootNat.lt_succ_pow at s * d, y with product187  have regroup := pow.mul_exponent at rootNat(s * d, y) + 1, d, s188  have swap : d * s = s * d by ring189  rw swap at regroup190  rw ← regroup at above191  have adjunction := rootNat.lt_iff at s, y, (rootNat(s * d, y) + 1) ^ d with192    positive193  exact adjunction.backward with above194