Download lean/OAI/Computability/BinPacking/PCP/PreprocessingLazyWords.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 29.3 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/BinPacking/PCP/PreprocessingLazyWords.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/BinPacking/PCP/PreprocessingLazyWords.lean
-
curl -L -o PreprocessingLazyWords.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/BinPacking/PCP/PreprocessingLazyWords.lean
29.3 kB
| import Mathlib.Data.Fintype.BigOperators | |
| import Mathlib.Data.List.OfFn | |
| import Mathlib.Tactic.FieldSimp | |
| import OAI.Computability.BinPacking.Expanders.ExpanderTableEnumeration | |
| import OAI.Computability.BinPacking.PCP.PoweringMomentBound | |
| import OAI.Computability.BinPacking.PCP.RawInitialPredicate | |
| namespace OAI | |
| section | |
| open scoped BigOperators | |
| namespace BinPackingGames.Foundations.PCP.Overlay | |
| open PoweringWalks SpectralReturn | |
| variable {V D E A : Type*} | |
| def originalPortGraph (G : ConstraintGraph V (V × D) A) : PortGraph V D where | |
| rot := G.reverse | |
| rot_involutive := G.reverse_involutive | |
| def rotate (G : PortGraph V D) (H : PortGraph V E) : | |
| V × (D ⊕ E) → V × (D ⊕ E) | |
| | (v, Sum.inl d) => ((G.rot (v, d)).1, Sum.inl (G.rot (v, d)).2) | |
| | (v, Sum.inr e) => ((H.rot (v, e)).1, Sum.inr (H.rot (v, e)).2) | |
| theorem rotate_involutive (G : PortGraph V D) (H : PortGraph V E) : | |
| Function.Involutive (rotate G H) := by | |
| rintro ⟨v, p⟩ | |
| rcases p with d | e | |
| · exact congrArg (fun a : V × D => (a.1, (Sum.inl a.2 : D ⊕ E))) | |
| (G.rot_involutive (v, d)) | |
| · exact congrArg (fun a : V × E => (a.1, (Sum.inr a.2 : D ⊕ E))) | |
| (H.rot_involutive (v, e)) | |
| def portGraph (G : PortGraph V D) (H : PortGraph V E) : PortGraph V (D ⊕ E) where | |
| rot := | |
| { toFun := rotate G H | |
| invFun := rotate G H | |
| left_inv := rotate_involutive G H | |
| right_inv := rotate_involutive G H } | |
| rot_involutive := rotate_involutive G H | |
| @[simp] theorem portGraph_rot_inl (G : PortGraph V D) (H : PortGraph V E) | |
| (v : V) (d : D) : | |
| (portGraph G H).rot (v, Sum.inl d) = | |
| ((G.rot (v, d)).1, Sum.inl (G.rot (v, d)).2) := rfl | |
| @[simp] theorem portGraph_rot_inr (G : PortGraph V D) (H : PortGraph V E) | |
| (v : V) (e : E) : | |
| (portGraph G H).rot (v, Sum.inr e) = | |
| ((H.rot (v, e)).1, Sum.inr (H.rot (v, e)).2) := rfl | |
| def constraintGraph (G : ConstraintGraph V (V × D) A) (H : PortGraph V E) : | |
| ConstraintGraph V (V × (D ⊕ E)) A where | |
| reverse := (portGraph (originalPortGraph G) H).rot | |
| reverse_involutive := (portGraph (originalPortGraph G) H).rot_involutive | |
| tail := Prod.fst | |
| accepts p a b := match p.2 with | |
| | Sum.inl d => G.accepts (p.1, d) a b | |
| | Sum.inr _ => true | |
| reverse_accepts := by | |
| rintro ⟨v, p⟩ a b | |
| rcases p with d | e | |
| · exact G.reverse_accepts (v, d) a b | |
| · rfl | |
| @[simp] theorem constraintGraph_tail (G : ConstraintGraph V (V × D) A) | |
| (H : PortGraph V E) : (constraintGraph G H).tail = Prod.fst := rfl | |
| @[simp] theorem constraintGraph_portGraph (G : ConstraintGraph V (V × D) A) | |
| (H : PortGraph V E) : | |
| originalPortGraph (constraintGraph G H) = portGraph (originalPortGraph G) H := rfl | |
| @[simp] theorem edgeSatisfied_inl (G : ConstraintGraph V (V × D) A) | |
| (H : PortGraph V E) (htail : G.tail = Prod.fst) | |
| (labeling : V → A) (v : V) (d : D) : | |
| (constraintGraph G H).edgeSatisfied labeling (v, Sum.inl d) = | |
| G.edgeSatisfied labeling (v, d) := by | |
| change G.accepts (v, d) (labeling v) (labeling (G.reverse (v, d)).1) = | |
| G.accepts (v, d) (labeling (G.tail (v, d))) | |
| (labeling (G.tail (G.reverse (v, d)))) | |
| rw [htail] | |
| @[simp] theorem edgeSatisfied_inr (G : ConstraintGraph V (V × D) A) | |
| (H : PortGraph V E) (labeling : V → A) (v : V) (e : E) : | |
| (constraintGraph G H).edgeSatisfied labeling (v, Sum.inr e) = true := rfl | |
| theorem complete (G : ConstraintGraph V (V × D) A) (H : PortGraph V E) | |
| (htail : G.tail = Prod.fst) (labeling : V → A) | |
| (h : ∀ a, G.edgeSatisfied labeling a = true) : | |
| ∀ a, (constraintGraph G H).edgeSatisfied labeling a = true := by | |
| rintro ⟨v, p⟩ | |
| rcases p with d | e | |
| · rw [edgeSatisfied_inl G H htail] | |
| exact h (v, d) | |
| · rfl | |
| theorem satisfiable_iff (G : ConstraintGraph V (V × D) A) (H : PortGraph V E) | |
| (htail : G.tail = Prod.fst) : | |
| (constraintGraph G H).Satisfiable ↔ G.Satisfiable := by | |
| constructor | |
| · rintro ⟨labeling, h⟩ | |
| refine ⟨labeling, ?_⟩ | |
| rintro ⟨v, d⟩ | |
| rw [← edgeSatisfied_inl G H htail] | |
| exact h (v, Sum.inl d) | |
| · rintro ⟨labeling, h⟩ | |
| exact ⟨labeling, complete G H htail labeling h⟩ | |
| theorem rejectionCount_eq [Fintype V] [Fintype D] [Fintype E] | |
| (G : ConstraintGraph V (V × D) A) (H : PortGraph V E) | |
| (htail : G.tail = Prod.fst) (labeling : V → A) : | |
| (constraintGraph G H).rejectionCount labeling = G.rejectionCount labeling := by | |
| classical | |
| simp only [DegreeReplacement.rejectionCount_eq_sum, Fintype.sum_prod_type, | |
| Fintype.sum_sum_type] | |
| simp [edgeSatisfied_inl G H htail] | |
| theorem card_ports [Fintype D] [Fintype E] : | |
| Fintype.card (D ⊕ E) = Fintype.card D + Fintype.card E := Fintype.card_sum | |
| theorem card_darts [Fintype V] [Fintype D] [Fintype E] : | |
| Fintype.card (V × (D ⊕ E)) = | |
| Fintype.card (V × D) + Fintype.card (V × E) := by | |
| simp only [Fintype.card_prod, Fintype.card_sum, Nat.mul_add] | |
| variable [Fintype V] [Fintype D] [Fintype E] | |
| omit [Fintype V] in | |
| theorem operator_mix [Nonempty D] [Nonempty E] | |
| (G : PortGraph V D) (H : PortGraph V E) (f : V → ℝ) (v : V) : | |
| averagingOperator (portGraph G H) f v = | |
| (Fintype.card D : ℝ) / ((Fintype.card D : ℝ) + Fintype.card E) * | |
| averagingOperator G f v + | |
| (Fintype.card E : ℝ) / ((Fintype.card D : ℝ) + Fintype.card E) * | |
| averagingOperator H f v := by | |
| have hd : (0 : ℝ) < Fintype.card D := by | |
| exact_mod_cast (Fintype.card_pos : 0 < Fintype.card D) | |
| have he : (0 : ℝ) < Fintype.card E := by | |
| exact_mod_cast (Fintype.card_pos : 0 < Fintype.card E) | |
| change mean (fun p : D ⊕ E => f ((portGraph G H).rot (v, p)).1) = _ | |
| rw [mean_eq_sum_div_card] | |
| simp only [Fintype.sum_sum_type, Fintype.card_sum, Nat.cast_add, | |
| portGraph_rot_inl, portGraph_rot_inr] | |
| unfold averagingOperator | |
| rw [Fintype.expect_eq_sum_div_card, Fintype.expect_eq_sum_div_card] | |
| field_simp [hd.ne', he.ne', (add_pos hd he).ne'] | |
| theorem energy_convex_mix (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) | |
| (f g : V → ℝ) : | |
| energy (fun v => a * f v + b * g v) ≤ a * energy f + b * energy g := by | |
| calc | |
| energy (fun v => a * f v + b * g v) ≤ | |
| mean (fun v => a * (f v) ^ 2 + b * (g v) ^ 2) := by | |
| apply mean_mono | |
| intro v | |
| have hnormalize := congrArg (fun t : ℝ => t * (a * (f v) ^ 2 + b * (g v) ^ 2)) hab | |
| have hnonneg := mul_nonneg (mul_nonneg ha hb) (sq_nonneg (f v - g v)) | |
| nlinarith | |
| _ = a * energy f + b * energy g := by | |
| rw [mean_add, mean_mul_left, mean_mul_left] | |
| rfl | |
| theorem energy_bound [Nonempty V] [Nonempty D] [Nonempty E] | |
| (G : PortGraph V D) (H : PortGraph V E) (lambda : ℝ) | |
| (certificate : SpectralCertificate H lambda) (f : V → ℝ) (hf : mean f = 0) : | |
| energy (averagingOperator (portGraph G H) f) ≤ | |
| ((Fintype.card D : ℝ) + (Fintype.card E : ℝ) * lambda ^ 2) / | |
| ((Fintype.card D : ℝ) + Fintype.card E) * energy f := by | |
| let a : ℝ := (Fintype.card D : ℝ) / ((Fintype.card D : ℝ) + Fintype.card E) | |
| let b : ℝ := (Fintype.card E : ℝ) / ((Fintype.card D : ℝ) + Fintype.card E) | |
| have hd : (0 : ℝ) < Fintype.card D := by | |
| exact_mod_cast (Fintype.card_pos : 0 < Fintype.card D) | |
| have he : (0 : ℝ) < Fintype.card E := by | |
| exact_mod_cast (Fintype.card_pos : 0 < Fintype.card E) | |
| have hden : (0 : ℝ) < (Fintype.card D : ℝ) + Fintype.card E := add_pos hd he | |
| have ha : 0 ≤ a := div_nonneg hd.le hden.le | |
| have hb : 0 ≤ b := div_nonneg he.le hden.le | |
| have hab : a + b = 1 := by | |
| dsimp [a, b] | |
| rw [← add_div, div_self hden.ne'] | |
| have hop : averagingOperator (portGraph G H) f = | |
| fun v => a * averagingOperator G f v + b * averagingOperator H f v := by | |
| funext v | |
| exact operator_mix G H f v | |
| calc | |
| energy (averagingOperator (portGraph G H) f) ≤ | |
| a * energy (averagingOperator G f) + b * energy (averagingOperator H f) := by | |
| rw [hop] | |
| exact energy_convex_mix a b ha hb hab _ _ | |
| _ ≤ a * energy f + b * (lambda ^ 2 * energy f) := | |
| add_le_add | |
| (mul_le_mul_of_nonneg_left (ZigzagSpectral.averaging_energy_le G f) ha) | |
| (mul_le_mul_of_nonneg_left (certificate.contraction f hf) hb) | |
| _ = _ := by | |
| dsimp [a, b] | |
| ring | |
| theorem energy_bound_three_quarters [Nonempty V] | |
| (G : PortGraph V D) (H : PortGraph V E) | |
| (hdegree : Fintype.card D = Fintype.card E + 1) (hpositive : 1 ≤ Fintype.card E) | |
| (certificate : SpectralCertificate H (1 / 2 : ℝ)) | |
| (f : V → ℝ) (hf : mean f = 0) : | |
| energy (averagingOperator (portGraph G H) f) ≤ (3 / 4 : ℝ) * energy f := by | |
| let _ : Nonempty E := Fintype.card_pos_iff.mp (lt_of_lt_of_le Nat.zero_lt_one hpositive) | |
| let _ : Nonempty D := Fintype.card_pos_iff.mp (by omega) | |
| have he : (1 : ℝ) ≤ Fintype.card E := by exact_mod_cast hpositive | |
| have hd : (Fintype.card D : ℝ) = (Fintype.card E : ℝ) + 1 := by exact_mod_cast hdegree | |
| have hden : (0 : ℝ) < (Fintype.card D : ℝ) + Fintype.card E := by linarith | |
| have hcoefficient : | |
| ((Fintype.card D : ℝ) + (Fintype.card E : ℝ) * (1 / 2 : ℝ) ^ 2) / | |
| ((Fintype.card D : ℝ) + Fintype.card E) ≤ (3 / 4 : ℝ) := by | |
| apply (div_le_iff₀ hden).mpr | |
| nlinarith | |
| exact (energy_bound G H (1 / 2) certificate f hf).trans | |
| (mul_le_mul_of_nonneg_right hcoefficient (energy_nonnegative f)) | |
| theorem spectralCertificate_seven_eighths [Nonempty V] | |
| (G : PortGraph V D) (H : PortGraph V E) | |
| (hdegree : Fintype.card D = Fintype.card E + 1) (hpositive : 1 ≤ Fintype.card E) | |
| (certificate : SpectralCertificate H (1 / 2 : ℝ)) : | |
| SpectralCertificate (portGraph G H) (7 / 8 : ℝ) where | |
| nonnegative := by norm_num | |
| lt_one := by norm_num | |
| contraction := by | |
| intro f hf | |
| exact (energy_bound_three_quarters G H hdegree hpositive certificate f hf).trans | |
| (mul_le_mul_of_nonneg_right (by norm_num : (3 / 4 : ℝ) ≤ (7 / 8 : ℝ) ^ 2) | |
| (energy_nonnegative f)) | |
| theorem constraintGraph_spectralCertificate [Nonempty V] | |
| (G : ConstraintGraph V (V × D) A) (H : PortGraph V E) | |
| (hdegree : Fintype.card D = Fintype.card E + 1) (hpositive : 1 ≤ Fintype.card E) | |
| (certificate : SpectralCertificate H (1 / 2 : ℝ)) : | |
| SpectralCertificate (originalPortGraph (constraintGraph G H)) (7 / 8 : ℝ) := by | |
| rw [constraintGraph_portGraph] | |
| exact spectralCertificate_seven_eighths (originalPortGraph G) H | |
| hdegree hpositive certificate | |
| end BinPackingGames.Foundations.PCP.Overlay | |
| end | |
| namespace BinPackingGames.Foundations.PCP.LazyConstraint | |
| open scoped BigOperators | |
| open PoweringWalks | |
| variable {V D A : Type*} | |
| def constraintGraph (G : ConstraintGraph V (V × D) A) : | |
| ConstraintGraph V (V × (Bool × D)) A where | |
| reverse := (lazyGraph (Overlay.originalPortGraph G)).rot | |
| reverse_involutive := (lazyGraph (Overlay.originalPortGraph G)).rot_involutive | |
| tail := Prod.fst | |
| accepts e a b := if e.2.1 then G.accepts (e.1,e.2.2) a b else true | |
| reverse_accepts := by | |
| rintro ⟨v,b,d⟩ a c | |
| cases b with | |
| | false => rfl | |
| | true => exact G.reverse_accepts (v,d) a c | |
| @[simp] theorem constraintGraph_tail (G : ConstraintGraph V (V × D) A) : | |
| (constraintGraph G).tail = Prod.fst := rfl | |
| @[simp] theorem constraintGraph_reverse (G : ConstraintGraph V (V × D) A) : | |
| (constraintGraph G).reverse = (lazyGraph (Overlay.originalPortGraph G)).rot := rfl | |
| @[simp] theorem constraintGraph_portGraph (G : ConstraintGraph V (V × D) A) : | |
| Overlay.originalPortGraph (constraintGraph G) = | |
| lazyGraph (Overlay.originalPortGraph G) := rfl | |
| @[simp] theorem edgeSatisfied_false (G : ConstraintGraph V (V × D) A) | |
| (labeling : V → A) (v : V) (d : D) : | |
| (constraintGraph G).edgeSatisfied labeling (v,(false,d)) = true := rfl | |
| @[simp] theorem edgeSatisfied_true (G : ConstraintGraph V (V × D) A) | |
| (htail : G.tail = Prod.fst) (labeling : V → A) (v : V) (d : D) : | |
| (constraintGraph G).edgeSatisfied labeling (v,(true,d)) = | |
| G.edgeSatisfied labeling (v,d) := by | |
| change G.accepts (v,d) (labeling v) (labeling (G.reverse (v,d)).1) = | |
| G.accepts (v,d) (labeling (G.tail (v,d))) | |
| (labeling (G.tail (G.reverse (v,d)))) | |
| rw [htail] | |
| theorem complete (G : ConstraintGraph V (V × D) A) (htail : G.tail = Prod.fst) | |
| (labeling : V → A) (h : ∀ e, G.edgeSatisfied labeling e = true) : | |
| ∀ e, (constraintGraph G).edgeSatisfied labeling e = true := by | |
| rintro ⟨v,b,d⟩ | |
| cases b with | |
| | false => rfl | |
| | true => | |
| rw [edgeSatisfied_true G htail] | |
| exact h (v,d) | |
| theorem complete_iff (G : ConstraintGraph V (V × D) A) (htail : G.tail = Prod.fst) | |
| (labeling : V → A) : | |
| (∀ e, (constraintGraph G).edgeSatisfied labeling e = true) ↔ | |
| ∀ e, G.edgeSatisfied labeling e = true := by | |
| constructor | |
| · intro h | |
| rintro ⟨v,d⟩ | |
| rw [← edgeSatisfied_true G htail] | |
| exact h (v,(true,d)) | |
| · exact complete G htail labeling | |
| theorem satisfiable_iff (G : ConstraintGraph V (V × D) A) (htail : G.tail = Prod.fst) : | |
| (constraintGraph G).Satisfiable ↔ G.Satisfiable := by | |
| constructor | |
| · rintro ⟨labeling,h⟩ | |
| exact ⟨labeling, (complete_iff G htail labeling).mp h⟩ | |
| · rintro ⟨labeling,h⟩ | |
| exact ⟨labeling, complete G htail labeling h⟩ | |
| theorem rejectionCount_eq [Fintype V] [Fintype D] | |
| (G : ConstraintGraph V (V × D) A) (htail : G.tail = Prod.fst) | |
| (labeling : V → A) : | |
| (constraintGraph G).rejectionCount labeling = G.rejectionCount labeling := by | |
| classical | |
| simp only [DegreeReplacement.rejectionCount_eq_sum, Fintype.sum_prod_type, | |
| Fintype.sum_bool] | |
| simp [edgeSatisfied_true G htail] | |
| theorem card_ports [Fintype D] : | |
| Fintype.card (Bool × D) = 2 * Fintype.card D := by | |
| simp | |
| theorem card_darts [Fintype V] [Fintype D] : | |
| Fintype.card (V × (Bool × D)) = 2 * Fintype.card (V × D) := by | |
| simp [Fintype.card_prod, Nat.mul_left_comm] | |
| theorem rejection_density_eq_half [Fintype V] [Fintype D] | |
| (G : ConstraintGraph V (V × D) A) (htail : G.tail = Prod.fst) | |
| (labeling : V → A) : | |
| ((constraintGraph G).rejectionCount labeling : ℝ) / | |
| (Fintype.card (V × (Bool × D)) : ℝ) = | |
| ((G.rejectionCount labeling : ℝ) / (Fintype.card (V × D) : ℝ)) / 2 := by | |
| rw [rejectionCount_eq G htail, card_darts] | |
| simp only [Nat.cast_mul, Nat.cast_ofNat, div_eq_mul_inv, mul_inv_rev] | |
| ring | |
| end BinPackingGames.Foundations.PCP.LazyConstraint | |
| namespace BinPackingGames.Foundations.PCP.PreprocessingOverlayTables | |
| open PoweringWalks | |
| def overlayPorts (d e : Nat) : (Fin d ⊕ Fin e) ≃ Fin (d + e) := finSumFinEquiv | |
| @[simp] theorem overlayPorts_inl_val (d e : Nat) (i : Fin d) : | |
| (overlayPorts d e (Sum.inl i)).val = i.val := rfl | |
| @[simp] theorem overlayPorts_inr_val (d e : Nat) (i : Fin e) : | |
| (overlayPorts d e (Sum.inr i)).val = d + i.val := rfl | |
| def lazyPorts (d : Nat) : (Bool × Fin d) ≃ Fin (2 * d) := | |
| (Equiv.prodCongr finTwoEquiv.symm (Equiv.refl (Fin d))).trans finProdFinEquiv | |
| @[simp] theorem lazyPorts_false_val (d : Nat) (i : Fin d) : | |
| (lazyPorts d (false, i)).val = i.val := by | |
| simp [lazyPorts, finTwoEquiv, finProdFinEquiv] | |
| @[simp] theorem lazyPorts_true_val (d : Nat) (i : Fin d) : | |
| (lazyPorts d (true, i)).val = i.val + d := by | |
| simp [lazyPorts, finTwoEquiv, finProdFinEquiv] | |
| def materialize {n d : Nat} {D : Type*} | |
| (G : ConstraintGraph (Fin n) (Fin n × D) PortTables.Label) | |
| (ports : D ≃ Fin d) : PortTables.Table n d := | |
| PortTables.ofPortGraph | |
| (GraphTransport.reindex (Overlay.originalPortGraph G) (Equiv.refl _) ports) | |
| (fun x a b => G.accepts (x.1, ports.symm x.2) a b) | |
| (by | |
| intro x a b | |
| simp only [GraphTransport.reindex, Overlay.originalPortGraph, | |
| Equiv.trans_apply, Equiv.prodCongr_apply, Equiv.prodCongr_symm, | |
| Equiv.refl_apply, Equiv.symm_apply_apply, Prod.map] | |
| convert G.reverse_accepts (x.1, ports.symm x.2) a b using 1 | |
| rfl) | |
| theorem rotation_materialize {n d : Nat} {D : Type*} | |
| (G : ConstraintGraph (Fin n) (Fin n × D) PortTables.Label) | |
| (ports : D ≃ Fin d) (x : Fin n × Fin d) : | |
| PortTables.rotation (materialize G ports) x = | |
| ((G.reverse (x.1, ports.symm x.2)).1, | |
| ports (G.reverse (x.1, ports.symm x.2)).2) := by | |
| simp only [materialize, PortTables.rotation_ofPortGraph, GraphTransport.reindex, | |
| Overlay.originalPortGraph, Equiv.trans_apply, Equiv.prodCongr_apply, | |
| Equiv.prodCongr_symm, Equiv.refl_apply, Prod.map] | |
| rfl | |
| theorem rotation_materialize_image {n d : Nat} {D : Type*} | |
| (G : ConstraintGraph (Fin n) (Fin n × D) PortTables.Label) | |
| (ports : D ≃ Fin d) (v : Fin n) (i : D) : | |
| PortTables.rotation (materialize G ports) (v, ports i) = | |
| ((G.reverse (v, i)).1, ports (G.reverse (v, i)).2) := by | |
| rw [rotation_materialize, Equiv.symm_apply_apply] | |
| @[simp] theorem accepts_materialize {n d : Nat} {D : Type*} | |
| (G : ConstraintGraph (Fin n) (Fin n × D) PortTables.Label) | |
| (ports : D ≃ Fin d) (x : Fin n × Fin d) (a b : PortTables.Label) : | |
| PortTables.accepts (materialize G ports) x a b = | |
| G.accepts (x.1, ports.symm x.2) a b := by | |
| exact PortTables.accepts_ofPortGraph _ _ _ x a b | |
| private theorem constraintGraph_ext {V E A : Type*} {G H : ConstraintGraph V E A} | |
| (hreverse : ∀ e, G.reverse e = H.reverse e) | |
| (htail : ∀ e, G.tail e = H.tail e) | |
| (haccepts : ∀ e a b, G.accepts e a b = H.accepts e a b) : G = H := by | |
| rcases G with ⟨r, hi, t, p, hp⟩ | |
| rcases H with ⟨r', hi', t', p', hp'⟩ | |
| have hr : r = r' := Equiv.ext hreverse | |
| cases hr | |
| have ht : t = t' := funext htail | |
| cases ht | |
| have ha : p = p' := funext fun e => funext fun a => funext fun b => haccepts e a b | |
| cases ha | |
| rfl | |
| theorem baseGraph_materialize {n d : Nat} {D : Type*} | |
| (G : ConstraintGraph (Fin n) (Fin n × D) PortTables.Label) | |
| (ports : D ≃ Fin d) (htail : G.tail = Prod.fst) : | |
| PortTables.baseGraph (materialize G ports) = | |
| G.reindex (Equiv.refl _) (Equiv.prodCongr (Equiv.refl _) ports) (Equiv.refl _) := by | |
| apply constraintGraph_ext | |
| · intro x | |
| rw [PortTables.baseGraph_reverse, rotation_materialize] | |
| rfl | |
| · intro x | |
| change x.1 = G.tail (x.1, ports.symm x.2) | |
| rw [htail] | |
| · intro x a b | |
| rw [PortTables.baseGraph_accepts, accepts_materialize] | |
| rfl | |
| def overlay {n d e : Nat} (G : PortTables.Table n d) (H : ExpanderTables.Table n e) : | |
| PortTables.Table n (d + e) := | |
| materialize (Overlay.constraintGraph (PortTables.baseGraph G) (ExpanderTables.graph H)) | |
| (overlayPorts d e) | |
| theorem overlay_rotation_old {n d e : Nat} (G : PortTables.Table n d) | |
| (H : ExpanderTables.Table n e) (v : Fin n) (i : Fin d) : | |
| PortTables.rotation (overlay G H) (v, overlayPorts d e (Sum.inl i)) = | |
| ((PortTables.rotation G (v, i)).1, | |
| overlayPorts d e (Sum.inl (PortTables.rotation G (v, i)).2)) := by | |
| exact rotation_materialize_image _ _ v (Sum.inl i) | |
| theorem overlay_rotation_expander {n d e : Nat} (G : PortTables.Table n d) | |
| (H : ExpanderTables.Table n e) (v : Fin n) (i : Fin e) : | |
| PortTables.rotation (overlay G H) (v, overlayPorts d e (Sum.inr i)) = | |
| ((ExpanderTables.lookup H (v, i)).1, | |
| overlayPorts d e (Sum.inr (ExpanderTables.lookup H (v, i)).2)) := by | |
| exact rotation_materialize_image _ _ v (Sum.inr i) | |
| @[simp] theorem overlay_accepts_old {n d e : Nat} (G : PortTables.Table n d) | |
| (H : ExpanderTables.Table n e) (v : Fin n) (i : Fin d) (a b : PortTables.Label) : | |
| PortTables.accepts (overlay G H) (v, overlayPorts d e (Sum.inl i)) a b = | |
| PortTables.accepts G (v, i) a b := by | |
| simp only [overlay, accepts_materialize, Equiv.symm_apply_apply] | |
| rfl | |
| @[simp] theorem overlay_accepts_expander {n d e : Nat} (G : PortTables.Table n d) | |
| (H : ExpanderTables.Table n e) (v : Fin n) (i : Fin e) (a b : PortTables.Label) : | |
| PortTables.accepts (overlay G H) (v, overlayPorts d e (Sum.inr i)) a b = true := by | |
| simp only [overlay, accepts_materialize, Equiv.symm_apply_apply] | |
| rfl | |
| theorem overlay_semantics {n d e : Nat} (G : PortTables.Table n d) | |
| (H : ExpanderTables.Table n e) : | |
| PortTables.baseGraph (overlay G H) = | |
| (Overlay.constraintGraph (PortTables.baseGraph G) (ExpanderTables.graph H)).reindex | |
| (Equiv.refl _) (Equiv.prodCongr (Equiv.refl _) (overlayPorts d e)) | |
| (Equiv.refl _) := | |
| baseGraph_materialize _ _ rfl | |
| def lazy {n d : Nat} (G : PortTables.Table n d) : PortTables.Table n (2 * d) := | |
| materialize (LazyConstraint.constraintGraph (PortTables.baseGraph G)) (lazyPorts d) | |
| theorem lazy_rotation_false {n d : Nat} (G : PortTables.Table n d) | |
| (v : Fin n) (i : Fin d) : | |
| PortTables.rotation (lazy G) (v, lazyPorts d (false, i)) = | |
| (v, lazyPorts d (false, i)) := by | |
| exact rotation_materialize_image _ _ v (false, i) | |
| theorem lazy_rotation_true {n d : Nat} (G : PortTables.Table n d) | |
| (v : Fin n) (i : Fin d) : | |
| PortTables.rotation (lazy G) (v, lazyPorts d (true, i)) = | |
| ((PortTables.rotation G (v, i)).1, | |
| lazyPorts d (true, (PortTables.rotation G (v, i)).2)) := by | |
| exact rotation_materialize_image _ _ v (true, i) | |
| @[simp] theorem lazy_accepts_false {n d : Nat} (G : PortTables.Table n d) | |
| (v : Fin n) (i : Fin d) (a b : PortTables.Label) : | |
| PortTables.accepts (lazy G) (v, lazyPorts d (false, i)) a b = true := by | |
| simp only [lazy, accepts_materialize, Equiv.symm_apply_apply] | |
| rfl | |
| @[simp] theorem lazy_accepts_true {n d : Nat} (G : PortTables.Table n d) | |
| (v : Fin n) (i : Fin d) (a b : PortTables.Label) : | |
| PortTables.accepts (lazy G) (v, lazyPorts d (true, i)) a b = | |
| PortTables.accepts G (v, i) a b := by | |
| simp only [lazy, accepts_materialize, Equiv.symm_apply_apply] | |
| rfl | |
| theorem lazy_semantics {n d : Nat} (G : PortTables.Table n d) : | |
| PortTables.baseGraph (lazy G) = | |
| (LazyConstraint.constraintGraph (PortTables.baseGraph G)).reindex | |
| (Equiv.refl _) (Equiv.prodCongr (Equiv.refl _) (lazyPorts d)) (Equiv.refl _) := | |
| baseGraph_materialize _ _ rfl | |
| end BinPackingGames.Foundations.PCP.PreprocessingOverlayTables | |
| namespace BinPackingGames.Foundations.PCP.PreprocessingLazyWords | |
| open PortTables GraphTables PreprocessingOverlayTables | |
| open BinPackingGames.Foundations.Complexity | |
| variable {n d : Nat} | |
| def row (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| DartRow n (n * d) := | |
| ⟨v, table.reverseIndex[rowIndex n d (v, p)], table.relations[rowIndex n d (v, p)]⟩ | |
| def trueRelation : RelationTable := Vector.replicate 4096 true | |
| def stayRow (d : Nat) (v : Fin n) (p : Fin d) : DartRow n (n * (2 * d)) := | |
| ⟨v, rowIndex n (2 * d) (v, lazyPorts d (false, p)), trueRelation⟩ | |
| def moveRow (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| DartRow n (n * (2 * d)) := | |
| ⟨v, rowIndex n (2 * d) ((rotation table (v, p)).1, | |
| lazyPorts d (true, (rotation table (v, p)).2)), | |
| table.relations[rowIndex n d (v, p)]⟩ | |
| def reverseMap (d j : Nat) : Nat := 2 * d * (j / d) + d + j % d | |
| private theorem relation_ext {r s : RelationTable} | |
| (h : ∀ a b, relationAt r a b = relationAt s a b) : r = s := by | |
| apply Vector.ext | |
| intro i hi | |
| simpa only [relationAt, Prod.eta, Equiv.apply_symm_apply, Fin.getElem_fin] using | |
| h (relationIndex.symm ⟨i, hi⟩).1 (relationIndex.symm ⟨i, hi⟩).2 | |
| theorem row_lazy_stay (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| row (lazy table) v (lazyPorts d (false, p)) = stayRow d v p := by | |
| have hr : (lazy table).reverseIndex[rowIndex n (2 * d) (v, lazyPorts d (false, p))] = | |
| rowIndex n (2 * d) (v, lazyPorts d (false, p)) := by | |
| rw [← rowIndex_rotation, lazy_rotation_false] | |
| have hp : (lazy table).relations[rowIndex n (2 * d) (v, lazyPorts d (false, p))] = | |
| trueRelation := by | |
| apply relation_ext | |
| intro a b | |
| simpa only [PortTables.accepts, relationAt, trueRelation, Fin.getElem_fin, | |
| Vector.getElem_replicate] using lazy_accepts_false table v p a b | |
| exact congrArg₂ (DartRow.mk v) hr hp | |
| theorem row_lazy_move (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| row (lazy table) v (lazyPorts d (true, p)) = moveRow table v p := by | |
| have hr : (lazy table).reverseIndex[rowIndex n (2 * d) (v, lazyPorts d (true, p))] = | |
| rowIndex n (2 * d) ((rotation table (v, p)).1, | |
| lazyPorts d (true, (rotation table (v, p)).2)) := by | |
| rw [← rowIndex_rotation, lazy_rotation_true] | |
| have hp : (lazy table).relations[rowIndex n (2 * d) (v, lazyPorts d (true, p))] = | |
| table.relations[rowIndex n d (v, p)] := by | |
| apply relation_ext | |
| intro a b | |
| exact lazy_accepts_true table v p a b | |
| exact congrArg₂ (DartRow.mk v) hr hp | |
| theorem stayRow_reverse_val (v : Fin n) (p : Fin d) : | |
| (stayRow d v p).reverseIndex.val = 2 * d * v.val + p.val := by | |
| simp only [stayRow, rowIndex_val, lazyPorts_false_val] | |
| omega | |
| theorem moveRow_reverse_val (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| (moveRow table v p).reverseIndex.val = | |
| reverseMap d (row table v p).reverseIndex.val := by | |
| simp only [moveRow, rowIndex_val, lazyPorts_true_val, reverseMap, row] | |
| change (table.reverseIndex[rowIndex n d (v, p)]).val % d + d + | |
| (2 * d) * ((table.reverseIndex[rowIndex n d (v, p)]).val / d) = _ | |
| omega | |
| theorem relationWords_true : relationWords trueRelation = List.replicate 4096 1 := by | |
| simp only [relationWords, trueRelation, Vector.toList_replicate, | |
| List.map_replicate, bitWord, ite_true] | |
| theorem stayRow_words (v : Fin n) (p : Fin d) : | |
| rowWords (stayRow d v p) = | |
| [v.val, 2 * d * v.val + p.val] ++ List.replicate 4096 1 := by | |
| rw [rowWords, stayRow_reverse_val] | |
| exact congrArg (fun words => [v.val, 2 * d * v.val + p.val] ++ words) relationWords_true | |
| theorem moveRow_words (table : PortTables.Table n d) (v : Fin n) (p : Fin d) : | |
| rowWords (moveRow table v p) = | |
| [v.val, reverseMap d (row table v p).reverseIndex.val] ++ | |
| relationWords (row table v p).relation := by | |
| rw [rowWords, moveRow_reverse_val] | |
| rfl | |
| theorem ofFn_rowIndex {α : Type*} (f : Fin (n * d) → α) : | |
| List.ofFn f = (List.ofFn fun v : Fin n => | |
| List.ofFn fun p : Fin d => f (rowIndex n d (v, p))).flatten := by | |
| rw [List.ofFn_mul] | |
| apply congrArg List.flatten | |
| congr 1 | |
| funext v | |
| congr 1 | |
| funext p | |
| apply congrArg f | |
| apply Fin.ext | |
| simp only [rowIndex_val] | |
| ac_rfl | |
| theorem flatRows_list (table : PortTables.Table n d) : | |
| (flatRows table).toList = | |
| (List.ofFn fun v : Fin n => List.ofFn (row table v)).flatten := by | |
| rw [flatRows, Vector.toList_ofFn, ofFn_rowIndex] | |
| simp only [Equiv.symm_apply_apply] | |
| rfl | |
| theorem ofFn_lazyPorts {α : Type*} (f : Fin (2 * d) → α) : | |
| List.ofFn f = List.ofFn (fun p => f (lazyPorts d (false, p))) ++ | |
| List.ofFn (fun p => f (lazyPorts d (true, p))) := by | |
| have hf (p : Fin d) : rowIndex 2 d (0, p) = lazyPorts d (false, p) := by | |
| apply Fin.ext | |
| simp only [rowIndex_val, Fin.val_zero, Nat.mul_zero, Nat.add_zero, lazyPorts_false_val] | |
| have ht (p : Fin d) : rowIndex 2 d ((0 : Fin 1).succ, p) = lazyPorts d (true, p) := by | |
| apply Fin.ext | |
| simp only [rowIndex_val, Fin.val_succ, Fin.val_zero, Nat.zero_add, | |
| Nat.mul_one, lazyPorts_true_val] | |
| simpa only [List.ofFn_succ, List.ofFn_zero, List.flatten_cons, List.flatten_nil, | |
| List.append_nil, hf, ht] using (ofFn_rowIndex (n := 2) (d := d) f) | |
| def vertexRows (table : PortTables.Table n d) (v : Fin n) : | |
| List (DartRow n (n * (2 * d))) := | |
| List.ofFn (stayRow d v) ++ List.ofFn (moveRow table v) | |
| theorem vertexRows_length (table : PortTables.Table n d) (v : Fin n) : | |
| (vertexRows table v).length = 2 * d := by | |
| simp only [vertexRows, List.length_append, List.length_ofFn] | |
| omega | |
| theorem flatRows_lazy (table : PortTables.Table n d) : | |
| (flatRows (lazy table)).toList = (List.ofFn (vertexRows table)).flatten := by | |
| rw [flatRows_list] | |
| apply congrArg List.flatten | |
| congr 1 | |
| funext v | |
| rw [ofFn_lazyPorts] | |
| simp only [row_lazy_stay, row_lazy_move] | |
| rfl | |
| theorem vertexRows_words (table : PortTables.Table n d) (v : Fin n) : | |
| (vertexRows table v).flatMap rowWords = | |
| (List.ofFn fun p : Fin d => | |
| [v.val, 2 * d * v.val + p.val] ++ List.replicate 4096 1).flatten ++ | |
| (List.ofFn fun p : Fin d => | |
| [v.val, reverseMap d (row table v p).reverseIndex.val] ++ | |
| relationWords (row table v p).relation).flatten := by | |
| have hs : rowWords ∘ stayRow d v = fun p : Fin d => | |
| [v.val, 2 * d * v.val + p.val] ++ List.replicate 4096 1 := by | |
| funext p | |
| exact stayRow_words v p | |
| have hm : rowWords ∘ moveRow table v = fun p : Fin d => | |
| [v.val, reverseMap d (row table v p).reverseIndex.val] ++ | |
| relationWords (row table v p).relation := by | |
| funext p | |
| exact moveRow_words table v p | |
| simp only [vertexRows, List.flatMap_def, List.map_append, List.map_ofFn, | |
| List.flatten_append] | |
| rw [hs, hm] | |
| theorem tableWords_lazy (table : PortTables.Table n d) : | |
| PortTables.tableWords (lazy table) = | |
| [n, n * (2 * d)] ++ (List.ofFn (vertexRows table)).flatten.flatMap rowWords := by | |
| rw [PortTables.tableWords_eq, flatRows_lazy] | |
| theorem tableBits_lazy (table : PortTables.Table n d) : | |
| PortTables.tableBits (lazy table) = | |
| encodeWords ([n, n * (2 * d)] ++ | |
| (List.ofFn (vertexRows table)).flatten.flatMap rowWords) := by | |
| change encodeWords (PortTables.tableWords (lazy table)) = _ | |
| rw [tableWords_lazy] | |
| end BinPackingGames.Foundations.PCP.PreprocessingLazyWords | |
| end OAI | |