File size: 2,533 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
import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.SqrtLog.BucketProgramProducedRankMatrix
import OAI.Algorithms.SubexponentialSAT.SqrtLog.LayoutOwnerFiberProgramBounds
import OAI.Algorithms.SubexponentialSAT.SqrtLog.LayoutFiberSumProgramInterface

namespace OAI.Algorithms

/-! Literal equality between the runtime owner-fiber sum and an integer
matrix column. Both use the original incidence order and original owner IDs. -/
namespace SubexponentialSAT.SqrtLog.BucketProgram.ProducedRank
open scoped BigOperators

/-- The executable fiber scanner selects exactly the matching indices.
No nodup or arbitrary re-enumeration premise is needed. -/
theorem fiber_sum_ofFn {D : β„•} (ps : Fin D β†’ β„• Γ— β„•) (value : β„• β†’ β„€)
    (query start : β„•) :
    ((LayoutOwnerFiberProgram.fiberIndices query start (List.ofFn ps)).map value).sum=
      βˆ‘ i : Fin D,if (ps i).1=query then value (start+i.val) else 0 := by
  induction D generalizing start with
  | zero => simp [LayoutOwnerFiberProgram.fiberIndices]
  | succ D ih =>
      rw [List.ofFn_succ,LayoutOwnerFiberProgram.fiberIndices,Fin.sum_univ_succ]
      by_cases h : (ps 0).1=query
      Β· simp only [h,ite_true,List.map_cons,List.sum_cons]
        rw [ih]
        congr 1
        apply Finset.sum_congr rfl
        intro i _
        simp [Nat.add_left_comm,Nat.add_comm]
      Β· simp only [h,ite_false,zero_add]
        rw [ih]
        apply Finset.sum_congr rfl
        intro i _
        simp [Nat.add_left_comm,Nat.add_comm]

/-- A physical owner-fiber result computes this exact literal matrix, even
when incidence factors and variable labels are not consecutive. -/
def fiberMatrix {D n : β„•} (owner : Fin D β†’ Fin n)
    (entry : Fin D β†’ Fin D β†’ β„€) : Fin D β†’ Fin n β†’ β„€ :=
  fun j v=>βˆ‘ i,if owner i=v then entry j i else 0

theorem fiber_sum_eq_matrix {D n : β„•} (owner : Fin D β†’ Fin n)
    (ps : Fin D β†’ β„• Γ— β„•) (hp : βˆ€ i,(ps i).1=(owner i).val)
    (entry : Fin D β†’ Fin D β†’ β„€) (value : β„• β†’ β„• β†’ β„€)
    (hv : βˆ€ j i,value j.val i.val=entry j i) (j : Fin D) (v : Fin n) :
    ((LayoutOwnerFiberProgram.fiberIndices v.val 0 (List.ofFn ps)).map (value j.val)).sum=
      fiberMatrix owner entry j v := by
  rw [fiber_sum_ofFn]
  unfold fiberMatrix
  apply Finset.sum_congr rfl
  intro i _
  simp only [Nat.zero_add,hp,hv]
  have he : (owner i).val=v.val ↔ owner i=v := Fin.ext_iff.symm
  simp only [he]

end SubexponentialSAT.SqrtLog.BucketProgram.ProducedRank

end OAI.Algorithms