File size: 6,557 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | import OAI.Algorithms.SubexponentialSAT.LeanCompat
namespace OAI.Algorithms
/-!
# Computable coordinate splitting for an explicit packing
The inverse uses a finite sum of equality-tested coordinate copies, followed
by a residual-coordinate lookup. None of the definitions chooses a basis or
uses classical choice. Finite types, embeddings, and coordinate values are
inputs; this is not a Turing-machine cost theorem.
-/
namespace SubexponentialSAT.ComputablePackingSplit
open scoped BigOperators
section Scatter
variable {K U V : Type*} [Semiring K] [Fintype U] [DecidableEq V]
/-- Finite scatter along an explicit injection. -/
def scatter (e : U βͺ V) : (U β K) ββ[K] (V β K) where
toFun x v := β u, if e u = v then x u else 0
map_add' x y := by
funext v
change (β u, if e u = v then x u + y u else 0) =
(β u, if e u = v then x u else 0) + β u, if e u = v then y u else 0
rw [β Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro u _
split_ifs <;> simp
map_smul' c x := by
funext v
change (β u, if e u = v then c * x u else 0) =
c * β u, if e u = v then x u else 0
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro u _
split_ifs <;> simp
@[simp] theorem scatter_apply (e : U βͺ V) (x : U β K) (v : V) :
scatter e x v = β u, if e u = v then x u else 0 := rfl
@[simp] theorem scatter_on_image (e : U βͺ V) (x : U β K) (u : U) :
scatter e x (e u) = x u := by
classical
simp only [scatter_apply, e.injective.eq_iff, Finset.sum_ite_eq', Finset.mem_univ,
ite_true]
theorem scatter_outside (e : U βͺ V) (x : U β K) (v : V)
(hv : v β Set.range e) : scatter e x v = 0 := by
rw [scatter_apply]
apply Finset.sum_eq_zero
intro u _
have hu : e u β v := fun h => hv β¨u, hβ©
simp only [hu, ite_false]
/-- The coordinates absent from the supplied packing. -/
abbrev Leftover (e : U βͺ V) := {v : V // v β Set.range e}
/-- Copy a residual coordinate when it is absent from the embedding, and
return zero on every packed coordinate. Range membership is a finite search. -/
def leftoverExtend (e : U βͺ V) : (Leftover e β K) ββ[K] (V β K) where
toFun x v := if hv : v β Set.range e then 0 else x β¨v, hvβ©
map_add' x y := by
funext v
by_cases hv : β u, e u = v <;> simp [Set.mem_range, hv]
map_smul' c x := by
funext v
by_cases hv : β u, e u = v <;> simp [Set.mem_range, hv]
@[simp] theorem leftoverExtend_on_image (e : U βͺ V) (x : Leftover e β K) (u : U) :
leftoverExtend e x (e u) = 0 := by
simp [leftoverExtend ]
@[simp] theorem leftoverExtend_outside (e : U βͺ V) (x : Leftover e β K)
(v : V) (hv : v β Set.range e) : leftoverExtend e x v = x β¨v, hvβ© := by
simp only [Set.mem_range] at hv
simp [leftoverExtend, hv]
end Scatter
section Packing
variable {K I U V : Type*} [Semiring K] [Fintype I] [Fintype U] [DecidableEq V]
/-- Computable conversion between curried block coordinates and pair coordinates. -/
def uncurryLinear : (I β U β K) ββ[K] (I Γ U β K) where
toFun x z := x z.1 z.2
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- Assemble the packed blocks and the residual coordinates by finite copying. -/
def assemble (e : I Γ U βͺ V) :
((I β U β K) Γ (Leftover e β K)) ββ[K] (V β K) :=
(scatter e).comp (uncurryLinear.comp
(LinearMap.fst K (I β U β K) (Leftover e β K))) +
(leftoverExtend e).comp (LinearMap.snd K (I β U β K) (Leftover e β K))
theorem assemble_eq (e : I Γ U βͺ V)
(x : (I β U β K) Γ (Leftover e β K)) :
assemble e x = scatter e (fun z => x.1 z.1 z.2) + leftoverExtend e x.2 := rfl
@[simp] theorem assemble_on_block (e : I Γ U βͺ V)
(x : (I β U β K) Γ (Leftover e β K)) (i : I) (u : U) :
assemble e x (e (i, u)) = x.1 i u := by
rw [assemble_eq]
simp only [Pi.add_apply, scatter_on_image, leftoverExtend_on_image, add_zero]
@[simp] theorem assemble_outside (e : I Γ U βͺ V)
(x : (I β U β K) Γ (Leftover e β K)) (v : V) (hv : v β Set.range e) :
assemble e x v = x.2 β¨v, hvβ© := by
rw [assemble_eq]
simp only [Pi.add_apply, scatter_outside e _ v hv,
leftoverExtend_outside e _ v hv, zero_add]
/-- An executable coordinate split for a supplied block embedding.
The forward map restricts; the inverse uses `assemble`, with no chosen basis. -/
def split (e : I Γ U βͺ V) :
(V β K) ββ[K] ((I β U β K) Γ (Leftover e β K)) where
toFun x := (fun i u => x (e (i, u)), fun v => x v.val)
invFun := assemble e
left_inv x := by
funext v
by_cases hv : v β Set.range e
Β· obtain β¨β¨i, uβ©, rflβ© := hv
exact assemble_on_block e _ i u
Β· exact assemble_outside e _ v hv
right_inv x := by
apply Prod.ext
Β· funext i u
exact assemble_on_block e x i u
Β· funext v
exact assemble_outside e x v.val v.property
map_add' _ _ := rfl
map_smul' _ _ := rfl
@[simp] theorem split_apply_block (e : I Γ U βͺ V) (x : V β K) (i : I) (u : U) :
(split e x).1 i u = x (e (i, u)) := rfl
@[simp] theorem split_apply_leftover (e : I Γ U βͺ V) (x : V β K) (v : Leftover e) :
(split e x).2 v = x v.val := rfl
@[simp] theorem split_symm_apply (e : I Γ U βͺ V)
(x : (I β U β K) Γ (Leftover e β K)) :
(split e).symm x = assemble e x := rfl
/-- The executable inverse formula, down to the finite equality-tested sum. -/
theorem split_symm_apply_eq_sum (e : I Γ U βͺ V)
(x : (I β U β K) Γ (Leftover e β K)) (v : V) :
(split e).symm x v =
(β z : I Γ U, if e z = v then x.1 z.1 z.2 else 0) +
(if hv : v β Set.range e then 0 else x.2 β¨v, hvβ©) := rfl
end Packing
section Cardinalities
variable {I U V : Type*} [Fintype I] [Fintype U] [Fintype V] [DecidableEq V]
theorem card_leftover (e : I Γ U βͺ V) :
Fintype.card (Leftover e) = Fintype.card V - Fintype.card I * Fintype.card U := by
rw [Fintype.card_subtype_compl, Fintype.card_range e, Fintype.card_prod]
omit [DecidableEq V] in
theorem card_blocks_le (e : I Γ U βͺ V) :
Fintype.card I * Fintype.card U β€ Fintype.card V := by
simpa only [Fintype.card_prod] using Fintype.card_le_of_injective e e.injective
theorem card_blocks_add_leftover (e : I Γ U βͺ V) :
Fintype.card I * Fintype.card U + Fintype.card (Leftover e) = Fintype.card V := by
rw [card_leftover]
exact Nat.add_sub_of_le (card_blocks_le e)
end Cardinalities
end SubexponentialSAT.ComputablePackingSplit
end OAI.Algorithms
|