File size: 5,162 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 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 | import OAI.Combinatorics.EditApproximation.Binary.FractionAllocation
import OAI.Combinatorics.EditApproximation.Binary.BinaryFixedDenominator
import OAI.Combinatorics.EditApproximation.Binary.BinaryCeilingWork
import OAI.Combinatorics.EditApproximation.Coarse.CoarseDenominatorArithmetic
import OAI.Combinatorics.EditApproximation.Probability.FiniteEnumerationWork
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
theorem bitPowerAllocation_le_work (base : List Bool) (n : ℕ) :
bitPowerAllocation base n ≤ (bitPowerWithWork base n).2 := by
induction n with
| zero => rfl
| succ n ih =>
have hm := bitMulAllocation_le_work (bitPowerWithWork base n).1 base
have ht := trimBitWordAllocation_le_work
(bitMulWithWork (bitPowerWithWork base n).1 base).1
simp only [bitPowerAllocation, bitPowerWithWork]
omega
def coarseDenominatorAllocation (allowanceDen q L branching : List Bool) (D : ℕ) : ℕ :=
let first := bitMulWithWork L branching
let base := bitMulWithWork first.1 q
let trimmed := trimBitWordWithWork base.1
let power := bitPowerWithWork trimmed.1 D
let initial := bitMulWithWork allowanceDen q
let product := bitMulWithWork initial.1 power.1
bitMulAllocation L branching + bitMulAllocation first.1 q + trimBitWordAllocation base.1 +
bitPowerAllocation trimmed.1 D + bitMulAllocation allowanceDen q +
bitMulAllocation initial.1 power.1 + trimBitWordAllocation product.1
theorem coarseDenominatorAllocation_le_work (allowanceDen q L branching : List Bool) (D : ℕ) :
coarseDenominatorAllocation allowanceDen q L branching D ≤
(coarseDenominatorWithWork allowanceDen q L branching D).2 := by
have h1 := bitMulAllocation_le_work L branching
have h2 := bitMulAllocation_le_work (bitMulWithWork L branching).1 q
have h3 := trimBitWordAllocation_le_work (bitMulWithWork (bitMulWithWork L branching).1 q).1
have h4 := bitPowerAllocation_le_work
(trimBitWordWithWork (bitMulWithWork (bitMulWithWork L branching).1 q).1).1 D
have h5 := bitMulAllocation_le_work allowanceDen q
have h6 := bitMulAllocation_le_work (bitMulWithWork allowanceDen q).1
(bitPowerWithWork (trimBitWordWithWork (bitMulWithWork (bitMulWithWork L branching).1 q).1).1 D).1
have h7 := trimBitWordAllocation_le_work
(bitMulWithWork (bitMulWithWork allowanceDen q).1
(bitPowerWithWork (trimBitWordWithWork (bitMulWithWork (bitMulWithWork L branching).1 q).1).1 D).1).1
unfold coarseDenominatorAllocation coarseDenominatorWithWork
dsimp only
omega
theorem bitCeilDivAllocation_le_work (divisor bits : List Bool) :
bitCeilDivAllocation divisor bits ≤ (bitCeilDivWithWork divisor bits).2 := by
have hd := bitDivModAllocation_le_work divisor bits
have ha := bitAddAllocation_le_work (bitDivModWithWork divisor bits).1 [true] false
unfold bitCeilDivAllocation bitCeilDivWithWork
dsimp only
split_ifs <;> dsimp only <;> omega
/-- Map allocation includes one result spine cell for every callback. -/
theorem arithmeticMapAllocation_le_work {α β : Type*} (f : α → β × ℕ)
(allocation : α → ℕ) (values : List α)
(h : ∀ a ∈ values, allocation a ≤ (f a).2) :
arithmeticMapAllocation allocation values ≤ (arithmeticMapWithWork f values).2 := by
induction values with
| nil => rfl
| cons a rest ih =>
have hh := h a List.mem_cons_self
have ht := ih (fun b hb => h b (List.mem_cons_of_mem _ hb))
simp only [arithmeticMapAllocation, arithmeticMapWithWork]
omega
namespace BinaryFraction
theorem invAllocation_le_work (a : BinaryFraction) :
invAllocation a ≤ a.invWithWork.2 := by
unfold invAllocation invWithWork
dsimp only
split_ifs <;> dsimp only
· exact Nat.succ_le_succ (Nat.zero_le _)
· exact Nat.zero_le _
theorem divAllocation_le_work (a b : BinaryFraction) :
divAllocation a b ≤ (divWithWork a b).2 := by
have hi := invAllocation_le_work b
have hm := canonicalMulAllocation_le_work a b.invWithWork.1
unfold divAllocation divWithWork
dsimp only
omega
theorem fixedDenominatorAllocation_le_work (a : BinaryFraction) (denominator : List Bool)
(hden : 0 < bitWordValue denominator) :
fixedDenominatorAllocation a denominator hden ≤ (fixedDenominatorWithWork a denominator hden).2 := by
have hm := bitMulAllocation_le_work a.numerator.bits denominator
have hd := bitDivModAllocation_le_work a.denominator
(bitMulWithWork a.numerator.bits denominator).1
have hc := canonicalizeAllocation_le_work
(⟨⟨a.numerator.negative,
(bitDivModWithWork a.denominator (bitMulWithWork a.numerator.bits denominator).1).1⟩,
denominator, hden⟩ : BinaryFraction)
unfold fixedDenominatorAllocation fixedDenominatorWithWork
dsimp only
omega
theorem naturalCeilingAllocation_le_work (a : BinaryFraction) :
naturalCeilingAllocation a ≤ a.naturalCeilingWithWork.2 := by
have h := bitCeilDivAllocation_le_work a.denominator a.numerator.bits
unfold naturalCeilingAllocation naturalCeilingWithWork
split_ifs <;> dsimp only <;> omega
end BinaryFraction
end EditApproximation
end OAI
|