File size: 2,816 Bytes
e63eb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.EditApproximation.Binary.BitQueryKeys
import OAI.Combinatorics.EditApproximation.Geometry.SourceRankedRestriction
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalDependencyRank
import OAI.Combinatorics.EditApproximation.Queries.QueryPhysicalScalarGuards
import OAI.Combinatorics.EditApproximation.Binary.BinaryArithmeticWork
import OAI.Combinatorics.EditApproximation.Definitions


namespace OAI

/-! Finite-domain guards execute binary comparisons on table coordinates.
Random-source coordinates pass through the guard unchanged. -/

namespace EditApproximation

@[simp] theorem queryNaturalLEWithWork_value (a b : ℕ) :
    (wordLEWithWork a.bits b.bits).1 = true ↔ a ≤ b := by
  simp only [wordLEWithWork_value, bitWordValue_bits]



@[simp] theorem queryPhysicalBoundedWithWork_value {M J n : ℕ}
    (passes copies T S : ℕ) (request : PhysicalTableRequest M J n) :
    (queryPhysicalBoundedWithWork passes copies T S request).1 = true ↔
      request.Bounded passes copies T S := by
  simp only [queryPhysicalBoundedWithWork, Bool.and_eq_true, decide_eq_true_eq,
    binaryNaturalCompareWithWork_lt, wordLEWithWork_value, bitWordValue_bits,
    binaryNaturalAddWithWork_value, PhysicalTableRequest.Bounded]
  tauto

section Body
variable {σ : Type*} {M J n : ℕ} (passes copies T S : ℕ)
  (parent : {r : PhysicalTableRequest M J n // r.Bounded passes copies T S})





@[simp] theorem querySupportedChildWithWork_value
    (key : QueryPhysicalChild (σ := σ) passes copies T S parent) :
    (querySupportedChildWithWork passes copies T S parent key).1 = true ↔
      SourceRanked.supportedChild (PhysicalTableRequest.combinedRank T S)
        (PhysicalTableRequest.Bounded passes copies T S) parent.val key := by
  cases key with
  | inl source => exact iff_of_true rfl trivial
  | inr child => exact queryPhysicalBoundedWithWork_value passes copies T S child.val



theorem queryRestrictPhysicalBody_refines
    (program : BitQuery (QueryPhysicalChild (σ := σ) passes copies T S parent) BinaryFraction)
    (expected : (request : PhysicalTableRequest M J n) →
      FiniteQuery (Sum σ {child : PhysicalTableRequest M J n //
        child.combinedRank T S < request.combinedRank T S}))
    (h : BitQuery.Refines (fun word value => word.value = value) program (expected parent.val)) :
    BitQuery.Refines (fun word value => word.value = value)
      (queryRestrictPhysicalBody passes copies T S parent program)
      (SourceRanked.restrictBody (PhysicalTableRequest.combinedRank T S)
        (PhysicalTableRequest.Bounded passes copies T S) expected parent) := by
  classical
  exact (h.restrictWithWork _ _ (querySupportedChildWithWork_value passes copies T S parent)).mapKeysWithWork
    _ _ (fun _ => rfl)

end Body
end EditApproximation

end OAI