math / data /lean /OAI /Computability /Scheduling /RankCosts.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
9.43 kB
import OAI.Computability.Scheduling.ScheduleBounds
namespace OAI
universe u1 u2
section
namespace ThreeMachine.StackCompiler.Costs
variable {J : Type u1} (n : J β†’ β„•) (x : βˆ€ j, Uniform.RankCellInput (n j))
theorem rankCellLT (h : Poly n (fun j => volume (x j).2.1) 2) :
Poly n (fun j => Uniform.rankCellLT.time (n j) (x j)) 4 := by poly_auto
theorem rankCellEQ (h : Poly n (fun j => volume (x j).2.1) 2) :
Poly n (fun j => Uniform.rankCellEQ.time (n j) (x j)) 4 := by poly_auto
theorem rankCellFinLT (h : Poly n (fun j => volume (x j).2.1) 2) :
Poly n (fun j => Uniform.rankCellFinLT.time (n j) (x j)) 4 := by
simp only [Uniform.rankCellFinLT, Uniform.time_comp, Uniform.time_pair, Uniform.time_fst, Uniform.time_snd, Uniform.time_finVal, Function.comp_apply]
poly_auto
theorem rankCell (h : Poly n (fun j => volume (x j).2.1) 2) :
Poly n (fun j => Uniform.rankCell.time (n j) (x j)) 4 := by
have h1 := rankCellLT n x h
have h2 := rankCellEQ n x h
have h3 := rankCellFinLT n x h
poly_auto
end ThreeMachine.StackCompiler.Costs
end
section
namespace ThreeMachine.StackCompiler.Costs
variable {J : Type u2} (n : J β†’ β„•)
theorem rankFromCounts (U : βˆ€ j, Universe (n j)) (r : βˆ€ j, Fin (n j) β†’ β„•)
(v : βˆ€ j, Fin (n j)) (h : Poly n (fun j => volume (r j)) 2) :
Poly n (fun j => Uniform.rankFromCounts.time (n j) (U j,(r j,v j))) 5 := by
have hc := rankCell (fun p : Poly.ListPool (fun j => (Finset.univ : Finset (Fin (n j))).sort (Β· ≀ Β·)) => n p.1)
(fun p => (p.2.1,(r p.1,v p.1))) (h.precomp Sigma.fst)
poly_auto
theorem rank : Poly (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1)
(fun x => Uniform.rank.time x.1 x.2) 6 := by
let n : (Ξ£ n, Universe n Γ— Matrix n) β†’ β„• := Sigma.fst
have hv := Poly.volumePredecessors (fun x : Ξ£ n, Universe n Γ— Matrix n => x.2.2) (Poly.size n)
have hC := rankFromCounts (fun p : Poly.ListPool (fun x : Ξ£ n, Universe n Γ— Matrix n => List.finRange x.1) => p.1.1)
(fun p => p.1.2.1) (fun p => Structure.predecessorCount (matrixRel p.1.2.2))
(fun p => p.2.1) (hv.precomp Sigma.fst)
poly_auto
theorem reverseRank (U : βˆ€ j, Universe (n j)) (r : βˆ€ j, Fin (n j) β†’ β„•)
(h : Poly n (fun j => volume (r j)) 2) :
Poly n (fun j => Uniform.reverseRank.time (n j) (U j,r j)) 5 := by poly_auto
theorem ranks (frame : Bool) : Poly (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1)
(fun x => (Uniform.ranks frame).time x.1 x.2) 6 := by
cases frame
Β· poly_auto
Β· have hv := Poly.volumeRank (fun x : Ξ£ n, Universe n Γ— Matrix n => x.2.2)
(Poly.size (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1))
have hr := reverseRank (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1) (fun x => x.2.1)
(fun x => Structure.jobRank (matrixRel x.2.2)) hv
poly_auto
end ThreeMachine.StackCompiler.Costs
end
section
namespace ThreeMachine.StackCompiler.Uniform
abbrev ThresholdInput (n : β„•) := Fin n Γ— (β„• Γ— (Fin n β†’ β„•))
def thresholdA : Uniform (fun n (x : ThresholdInput n) => x.2.2 x.1) :=
((snd.comp snd).pair fst).comp functionGet
def thresholdB : Uniform (fun n (x : ThresholdInput n) => x.2.1) := snd.comp fst
def thresholdP (upper : Bool) : Uniform (fun n (x : ThresholdInput n) =>
decide (if upper then x.2.2 x.1 ≀ x.2.1 else x.2.1 ≀ x.2.2 x.1)) := by
cases upper
Β· exact (thresholdB.pair thresholdA).comp (Realizer.le.uniform β„•)
Β· exact (thresholdA.pair thresholdB).comp (Realizer.le.uniform β„•)
def thresholdF (upper : Bool) : Uniform (fun n (x : β„• Γ— (Universe n Γ— (Fin n β†’ β„•))) =>
Finset.univ.filter (fun v => decide (if upper then x.2.2 v ≀ x.1 else x.1 ≀ x.2.2 v) = true)) :=
(((snd.comp fst).comp universeSet).pair (fst.pair (snd.comp snd))).comp (thresholdP upper).setFilter
def thresholdN : Uniform (fun n (_ : Universe n Γ— (Fin n β†’ β„•)) => List.range (n+2)) :=
(((fst.comp universeNumber).pair (constant 2)).comp (Realizer.add.uniform β„•)).comp (Realizer.range.uniform β„•)
theorem time_thresholdSets (upper : Bool) (n : β„•) (x : Universe n Γ— (Fin n β†’ β„•)) :
(thresholdSets upper).time n x = ((thresholdN.pair id).comp (thresholdF upper).map).time n x := by
cases upper <;> rfl
end ThreeMachine.StackCompiler.Uniform
namespace ThreeMachine.StackCompiler.Costs
variable {J : Type} (n : J β†’ β„•)
theorem thresholdP (upper : Bool) (x : βˆ€ j, Uniform.ThresholdInput (n j))
(hk : Poly n (fun j => (x j).2.1) 1) (hr : Poly n (fun j => volume (x j).2.2) 2) :
Poly n (fun j => (Uniform.thresholdP upper).time (n j) (x j)) 4 := by
cases upper <;> poly_auto
theorem thresholdF (upper : Bool) (U : βˆ€ j, Universe (n j))
(r : βˆ€ j, Fin (n j) β†’ β„•) (k : J β†’ β„•)
(hk : Poly n k 1) (hr : Poly n (fun j => volume (r j)) 2) :
Poly n (fun j => (Uniform.thresholdF upper).time (n j) (k j,(U j,r j))) 5 := by
have hp := thresholdP (fun p : Poly.ListPool (fun j => (Finset.univ : Finset (Fin (n j))).sort (Β· ≀ Β·)) => n p.1)
upper (fun p => (p.2.1,(k p.1,r p.1))) (hk.precomp Sigma.fst) (hr.precomp Sigma.fst)
poly_auto
theorem thresholdSets (upper : Bool) (U : βˆ€ j, Universe (n j))
(r : βˆ€ j, Fin (n j) β†’ β„•) (hr : Poly n (fun j => volume (r j)) 2) :
Poly n (fun j => (Uniform.thresholdSets upper).time (n j) (U j,r j)) 6 := by
have hk : Poly (fun p : Poly.ListPool (fun j => List.range (n j+2)) => n p.1)
(fun p => p.2.1) 1 := by
apply Poly.of_le (fun p => (Nat.le_of_lt (List.mem_range.mp p.2.2)))
exact (Poly.base n).precomp Sigma.fst
have hF := thresholdF (fun p : Poly.ListPool (fun j => List.range (n j+2)) => n p.1)
upper (fun p => U p.1) (fun p => r p.1) (fun p => p.2.1) hk (hr.precomp Sigma.fst)
poly_auto
end ThreeMachine.StackCompiler.Costs
end
section
namespace ThreeMachine.StackCompiler.Uniform
def triplesE := (universeList.pair (universeList.pair universeList |>.comp product)).comp product
def triplesA := (triplesE.pair id).comp (swap.comp tripleSet).map
def triplesP : Uniform (fun n (x : Finset (Fin n) Γ— Unit) => decide (x.1.card = 3)) :=
(((fst.comp setCard).pair (constant 3)).comp (Realizer.eqNat.uniform β„•))
theorem time_triples (n : β„•) (x : Universe n) :
triples.time n x = ((triplesA.pair unit).comp triplesP.filter).time n x := rfl
def conesF (frame : Bool) (k : Fin 5) :=
((((snd.comp fst).pair ((snd.comp snd).pair fst))).comp (cone frame k))
def conesOne (frame : Bool) (k : Fin 5) :=
(((fst.comp triples).pair id).comp (conesF frame k).map)
theorem time_cones_cons (frame : Bool) (k : Fin 5) (ks : List (Fin 5))
(n : β„•) (x : Universe n Γ— Matrix n) :
(cones frame (k::ks)).time n x = ((conesOne frame k).pair (cones frame ks) |>.comp append).time n x := rfl
end ThreeMachine.StackCompiler.Uniform
namespace ThreeMachine.StackCompiler.Costs
open ThreeMachine.Structure
theorem matrixGetFrame (frame : Bool) :
Poly (fun x : Ξ£ n, Matrix n Γ— (Fin n Γ— Fin n) => x.1)
(fun x => (Uniform.matrixGetFrame frame).time x.1 x.2) 3 := by
cases frame <;> poly_auto
theorem conePred (frame : Bool) :
Poly (fun x : Ξ£ n, Universe n Γ— (Matrix n Γ— Finset (Fin n)) => x.1)
(fun x => (Uniform.conePred frame).time x.1 x.2) 20 := by
cases frame <;> poly_auto
theorem cone (frame : Bool) (kind : Fin 5) :
Poly (fun x : Ξ£ n, Universe n Γ— (Matrix n Γ— Finset (Fin n)) => x.1)
(fun x => (Uniform.cone frame kind).time x.1 x.2) 20 := by
have hf := conePred frame
have hr := conePred (!frame)
fin_cases kind <;> poly_auto
theorem triplesE : Poly (fun x : Ξ£ n, Universe n => x.1)
(fun x => Uniform.triplesE.time x.1 x.2) 20 := by poly_auto
theorem triplesA : Poly (fun x : Ξ£ n, Universe n => x.1)
(fun x => Uniform.triplesA.time x.1 x.2) 20 := by poly_auto
theorem triplesP : Poly (fun x : Ξ£ n, Finset (Fin n) Γ— Unit => x.1)
(fun x => Uniform.triplesP.time x.1 x.2) 3 := by poly_auto
theorem triples : Poly (fun x : Ξ£ n, Universe n => x.1)
(fun x => Uniform.triples.time x.1 x.2) 20 := by poly_auto
theorem conesF (frame : Bool) (k : Fin 5) :
Poly (fun x : Ξ£ n, Finset (Fin n) Γ— (Universe n Γ— Matrix n) => x.1)
(fun x => (Uniform.conesF frame k).time x.1 x.2) 20 := by poly_auto
theorem conesOne (frame : Bool) (k : Fin 5) :
Poly (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1)
(fun x => (Uniform.conesOne frame k).time x.1 x.2) 100 := by
have ht := Poly.lengthTriples (Poly.size (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1))
poly_auto
theorem cones (frame : Bool) (ks : List (Fin 5)) :
Poly (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1)
(fun x => (Uniform.cones frame ks).time x.1 x.2) 100 := by
induction ks with
| nil => poly_auto
| cons k ks ih =>
have hCone := cone frame k
have htr := Poly.lengthTriples (Poly.size (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1))
have hlen : Poly (fun x : Ξ£ n, Universe n Γ— Matrix n => x.1)
(fun x => (ks.flatMap (fun k =>
((Structure.tripleList (List.finRange x.1)).map Subtype.val).map (coneSet x.2.2 frame k))).length) 3 := by
have he (x : Ξ£ n, Universe n Γ— Matrix n) :
(ks.flatMap (fun k => ((Structure.tripleList (List.finRange x.1)).map Subtype.val).map (coneSet x.2.2 frame k))).length =
ks.length*(Structure.tripleList (List.finRange x.1)).length := by simp [List.length_flatMap]
apply Poly.of_le (fun x => (he x).le)
poly_bound
poly_auto
end ThreeMachine.StackCompiler.Costs
end
end OAI