import Mathlib import OAI.Computability.MinUncut.Estimates.CodeComputability namespace OAI section namespace MinUncut.Costed open Turing.ToPartrec def addCode : Code := .prec .head (.comp .succ .tail) def subCode : Code := .prec .head (.comp .pred .tail) lemma run_add (n a : ℕ) (v : List ℕ) : Runs addCode (n::a::v) [a+n] (100000*(magnitude (n::a::v)+2)^2) := by let M := magnitude (n::a::v) have hn : n≤M := by dsimp [M]; omega have ha : a≤M := by dsimp [M]; omega have hv : magnitude (a::v)≤M := by dsimp [M]; omega have hr : ∀i≤n,a+i≤M := by intro i hi; dsimp [M]; omega have hg : ∀ia+i) (a::v) M (300*(M+1)) (200*(M+1)) hn hr hv ((run_head (a::v)).mono (by gcongr)) hg apply hh.mono dsimp [M] at * nlinarith lemma run_sub (n a : ℕ) (v : List ℕ) : Runs subCode (n::a::v) [a-n] (100000*(magnitude (n::a::v)+2)^2) := by let M := magnitude (n::a::v) have hn : n≤M := by dsimp [M]; omega have ha : a≤M := by dsimp [M]; omega have hv : magnitude (a::v)≤M := by dsimp [M]; omega have hr : ∀i≤n,a-i≤M := by intro i _; omega have hg : ∀ia-i) (a::v) M (300*(M+1)) (1000*(M+1)) hn hr hv ((run_head (a::v)).mono (by gcongr)) hg apply hh.mono dsimp [M] at * nlinarith def mulCode : Code := .prec .zero (.comp addCode .tail) lemma run_mul (n a : ℕ) (v : List ℕ) : Runs mulCode (n::a::v) [a*n] (10000000*(magnitude (n::a::v)+2)^6) := by let S := magnitude (n::a::v) let M := (S+2)^2 have hnS : n≤S := by dsimp [S]; omega have haS : a≤S := by dsimp [S]; omega have hvS : magnitude (a::v)≤S := by dsimp [S]; omega have hSM : S≤M := by dsimp [M]; nlinarith have hr : ∀i≤n,a*i≤M := by intro i hi have hh : a*i≤S*S := Nat.mul_le_mul haS (hi.trans hnS) dsimp [M]; nlinarith have hg : ∀ia*i) (a::v) M (210*(M+1)) (1000000*(M+2)^2) (hnS.trans hSM) hr (hvS.trans hSM) ((run_const_zero (a::v)).mono (by gcongr; exact hvS.trans hSM)) hg apply hh.mono change 210*(M+1)+(n+2)*(1000000*(M+2)^2+50000*(M+1))≤10000000*(S+2)^6 calc _ ≤ 210*(M+1)+(S+2)*(1000000*(M+2)^2+50000*(M+1)) := by gcongr _ ≤ _ := by dsimp [M]; ring_nf; omega end MinUncut.Costed end end OAI