Download data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Encoding.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.69 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Encoding.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Encoding.lean
-
curl -L -o Encoding.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/NavierStokes/Material/Encoding.lean
7.69 kB
| import OAI.MathematicalPhysics.NavierStokes.Material.Model | |
| namespace OAI | |
| namespace Alternating.Memory | |
| open scoped BigOperators | |
| noncomputable def fraction (b : β) : List β β β | |
| | [] => 0 | |
| | d :: ds => ((d : β) + fraction b ds) / b | |
| def AllowedDigits (b : β) (ds : List β) : Prop := | |
| β d β ds, Even d β§ d + 2 β€ b | |
| noncomputable def tailBound (b : β) : β := ((b : β) - 2) / ((b : β) - 1) | |
| @[simp] theorem fraction_nil (b : β) : fraction b [] = 0 := rfl | |
| @[simp] theorem fraction_cons (b d : β) (ds : List β) : | |
| fraction b (d :: ds) = ((d : β) + fraction b ds) / b := rfl | |
| theorem fraction_nonneg (b : β) (ds : List β) : 0 β€ fraction b ds := by | |
| induction ds with | |
| | nil => simp | |
| | cons d ds ih => simp only [fraction_cons]; positivity | |
| theorem tailBound_nonneg {b : β} (hb : 2 β€ b) : 0 β€ tailBound b := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| unfold tailBound | |
| exact div_nonneg (by linarith) (by linarith) | |
| theorem tailBound_lt_one {b : β} (hb : 2 β€ b) : tailBound b < 1 := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| unfold tailBound | |
| exact (div_lt_one (by linarith)).2 (by linarith) | |
| theorem fraction_le_tailBound {b : β} (hb : 2 β€ b) {ds : List β} | |
| (hds : AllowedDigits b ds) : fraction b ds β€ tailBound b := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| have hpos : (0 : β) < b := by linarith | |
| have hkey : ((b : β) - 1) * tailBound b = (b : β) - 2 := by | |
| unfold tailBound | |
| field_simp [(by linarith : (b : β) - 1 β 0)] | |
| induction ds with | |
| | nil => simpa using tailBound_nonneg hb | |
| | cons d ds ih => | |
| have hd : (d : β) + 2 β€ b := by | |
| exact_mod_cast (hds d (by simp)).2 | |
| have hrest : AllowedDigits b ds := fun a ha => hds a (by simp [ha]) | |
| rw [fraction_cons] | |
| apply (div_le_iffβ hpos).2 | |
| have := ih hrest | |
| nlinarith | |
| theorem fraction_lt_one {b : β} (hb : 2 β€ b) {ds : List β} | |
| (hds : AllowedDigits b ds) : fraction b ds < 1 := | |
| (fraction_le_tailBound hb hds).trans_lt (tailBound_lt_one hb) | |
| theorem fraction_mem_digit_interval {b d : β} (hb : 2 β€ b) {ds : List β} | |
| (hds : AllowedDigits b ds) : | |
| fraction b (d :: ds) β Set.Ico ((d : β) / b) (((d : β) + 1) / b) := by | |
| have hpos : (0 : β) < b := by exact_mod_cast (by omega : 0 < b) | |
| rw [fraction_cons] | |
| exact β¨div_le_div_of_nonneg_right (le_add_of_nonneg_right (fraction_nonneg b ds)) hpos.le, | |
| (div_lt_div_iff_of_pos_right hpos).2 (by have := fraction_lt_one hb hds; linarith)β© | |
| theorem fraction_append {b : β} (_hb : 0 < b) (ds es : List β) : | |
| fraction b (ds ++ es) = fraction b ds + (b : β)β»ΒΉ ^ ds.length * fraction b es := by | |
| induction ds with | |
| | nil => simp | |
| | cons d ds ih => | |
| simp only [List.cons_append, fraction_cons, List.length_cons, pow_succ, ih] | |
| ring | |
| @[simp] theorem fraction_replicate_zero (b n : β) : | |
| fraction b (List.replicate n 0) = 0 := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => simp [List.replicate_succ, ih] | |
| def pad (K : β) (ds : List β) : List β := | |
| ds ++ List.replicate (K - ds.length) 0 | |
| theorem pad_length {ds : List β} {K : β} (h : ds.length β€ K) : | |
| (pad K ds).length = K := by simp [pad, Nat.add_sub_of_le h] | |
| theorem fraction_pad {b : β} (hb : 0 < b) (K : β) (ds : List β) : | |
| fraction b (pad K ds) = fraction b ds := by simp [pad, fraction_append hb] | |
| theorem allowedDigits_pad {b : β} (hb : 2 β€ b) {ds : List β} | |
| (hds : AllowedDigits b ds) (K : β) : AllowedDigits b (pad K ds) := by | |
| intro d hd | |
| simp only [pad, List.mem_append, List.mem_replicate] at hd | |
| rcases hd with hd | β¨_, rflβ© | |
| Β· exact hds d hd | |
| Β· exact β¨by simp, by simpa using hbβ© | |
| theorem fraction_denominator {b : β} (hb : 0 < b) (ds : List β) : | |
| β k : β€, (b : β) ^ ds.length * fraction b ds = k := by | |
| have hb0 : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| induction ds with | |
| | nil => exact β¨0, by simpβ© | |
| | cons d ds ih => | |
| rcases ih with β¨k, hkβ© | |
| refine β¨(b : β€) ^ ds.length * (d : β€) + k, ?_β© | |
| simp only [List.length_cons, fraction_cons, pow_succ, Int.cast_add, Int.cast_mul, | |
| Int.cast_pow, Int.cast_natCast] | |
| rw [β hk] | |
| field_simp | |
| theorem fraction_padded_denominator {b K : β} (hb : 0 < b) (ds : List β) | |
| (hK : ds.length β€ K) : β k : β€, (b : β) ^ K * fraction b ds = k := by | |
| simpa [pad_length hK, fraction_pad hb] using fraction_denominator hb (pad K ds) | |
| structure Block (b K : β) where | |
| stateDigit : β | |
| left : List β | |
| right : List β | |
| state_allowed : Even stateDigit β§ stateDigit + 2 β€ b | |
| left_allowed : AllowedDigits b left | |
| right_allowed : AllowedDigits b right | |
| left_length : left.length β€ K | |
| right_length : right.length β€ K | |
| def Block.digits {b K : β} (c : Block b K) : List β := | |
| c.stateDigit :: (pad K c.left ++ pad K c.right) | |
| noncomputable def Block.code {b K : β} (c : Block b K) : β := fraction b c.digits | |
| noncomputable def Block.leftCode {b K : β} (c : Block b K) : β := fraction b c.left | |
| noncomputable def Block.rightCode {b K : β} (c : Block b K) : β := fraction b c.right | |
| theorem Block.digits_length {b K : β} (c : Block b K) : c.digits.length = 1 + 2 * K := by | |
| simp [Block.digits, pad_length c.left_length, pad_length c.right_length] | |
| omega | |
| theorem Block.digits_allowed {b K : β} (hb : 2 β€ b) (c : Block b K) : | |
| AllowedDigits b c.digits := by | |
| intro d hd | |
| simp only [Block.digits, List.mem_cons, List.mem_append] at hd | |
| rcases hd with rfl | h | h | |
| Β· exact c.state_allowed | |
| Β· exact allowedDigits_pad hb c.left_allowed K d h | |
| Β· exact allowedDigits_pad hb c.right_allowed K d h | |
| theorem Block.code_formula {b K : β} (hb : 0 < b) (c : Block b K) : | |
| c.code = ((c.stateDigit : β) + c.leftCode + (b : β)β»ΒΉ ^ K * c.rightCode) / b := by | |
| simp [Block.code, Block.digits, fraction_append hb, pad_length c.left_length, | |
| fraction_pad hb, Block.leftCode, Block.rightCode, add_assoc] | |
| theorem Block.code_nonneg {b K : β} (c : Block b K) : 0 β€ c.code := | |
| fraction_nonneg _ _ | |
| theorem Block.code_le {b K : β} (hb : 2 β€ b) (c : Block b K) : c.code β€ tailBound b := | |
| fraction_le_tailBound hb (c.digits_allowed hb) | |
| theorem Block.code_denominator {b K : β} (hb : 0 < b) (c : Block b K) : | |
| β k : β€, (b : β) ^ (1 + 2 * K) * c.code = k := by | |
| simpa [c.digits_length, Block.code] using fraction_denominator hb c.digits | |
| theorem Block.left_denominator {b K : β} (hb : 0 < b) (c : Block b K) : | |
| β k : β€, (b : β) ^ K * c.leftCode = k := | |
| fraction_padded_denominator hb c.left c.left_length | |
| theorem Block.right_denominator {b K : β} (hb : 0 < b) (c : Block b K) : | |
| β k : β€, (b : β) ^ K * c.rightCode = k := | |
| fraction_padded_denominator hb c.right c.right_length | |
| theorem Block.tail_mem {b K : β} (hb : 2 β€ b) (c : Block b K) : | |
| c.leftCode + (b : β)β»ΒΉ ^ K * c.rightCode β Set.Icc 0 (tailBound b) := by | |
| have hbpos : 0 < b := by omega | |
| have hcode : fraction b (pad K c.left ++ pad K c.right) = | |
| c.leftCode + (b : β)β»ΒΉ ^ K * c.rightCode := by | |
| simp [fraction_append hbpos, fraction_pad hbpos, pad_length c.left_length, | |
| Block.leftCode, Block.rightCode] | |
| rw [β hcode] | |
| refine β¨fraction_nonneg _ _, fraction_le_tailBound hb ?_β© | |
| intro d hd | |
| rcases List.mem_append.1 hd with h | h | |
| Β· exact allowedDigits_pad hb c.left_allowed K d h | |
| Β· exact allowedDigits_pad hb c.right_allowed K d h | |
| theorem Block.right_mem {b K : β} (hb : 2 β€ b) (c : Block b K) : | |
| c.rightCode β Set.Icc 0 (tailBound b) := | |
| β¨fraction_nonneg _ _, fraction_le_tailBound hb c.right_allowedβ© | |
| end Alternating.Memory | |
| end OAI | |