File size: 9,037 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 | import OAI.Computability.BinPacking.Machines.GraphPackingPreparationFinish
namespace OAI
noncomputable section
namespace BinPackingGap.GraphPackingJobs
open FiniteTapeProgram PackingMachineBlocks GraphPackingRegisters
open GraphPackingPreparation PackingItemExpression
open GraphPackingProgram (PhaseRuns)
open PackingMachineLayout (tapes)
variable (fixed : InventoryData) (K : Nat)
def cleanupPhases : List (GraphPackingProgram.Program fixed K) :=
[GraphPackingProgram.incrementEdge fixed K,
GraphPackingProgram.setWork fixed K .leftEndpoint 0,
GraphPackingProgram.setWork fixed K .rightEndpoint 0,
GraphPackingProgram.setWork fixed K .leftPower 0,
GraphPackingProgram.setWork fixed K .rightPower 0,
GraphPackingProgram.setItem fixed K .labelPower 0,
GraphPackingProgram.setItem fixed K .repetitionOne 0]
private def cleanupWidthTimePolynomial : Polynomial Nat :=
64 * (2 * Polynomial.X + 1) ^ 2 +
PackingLayoutCommands.setOtherTime (Numerator fixed) denominator
(Other := Other fixed K) (.inr .leftEndpoint) 0 +
PackingLayoutCommands.setOtherTime (Numerator fixed) denominator
(Other := Other fixed K) (.inr .rightEndpoint) 0 +
PackingLayoutCommands.setOtherTime (Numerator fixed) denominator
(Other := Other fixed K) (.inr .leftPower) 0 +
PackingLayoutCommands.setOtherTime (Numerator fixed) denominator
(Other := Other fixed K) (.inr .rightPower) 0 +
PackingLayoutCommands.setInputTime (Numerator fixed) denominator
(Other := Other fixed K) .labelPower 0 +
PackingLayoutCommands.setInputTime (Numerator fixed) denominator
(Other := Other fixed K) .repetitionOne 0
def cleanupTimePolynomial : Polynomial Nat :=
(cleanupWidthTimePolynomial fixed K).comp (GraphPackingWidths.polynomial fixed K)
theorem cleanup_exec (x : GraphReductionInput) (e : x.graph.Edge)
(base : Tape fixed K β List Bool) (state : State) :
β steps β€ (cleanupTimePolynomial fixed K).eval (graphBits x).length,
PhaseRuns (cleanupPhases fixed K)
β¨state, tapes (Numerator fixed) denominator base
(completedInputs fixed K x e.val (x.graph.right e).val)
(loadedOther fixed K x (x.graph.left e).val (x.graph.right e).val)β© steps
β¨.arithmetic (BinaryAddMachine.clean ()),
tapes (Numerator fixed) denominator base (inputs fixed K x (e.val + 1))
(preparedOther fixed K x)β© := by
let width := GraphPackingWidths.width fixed K x
let initialInput := completedInputs fixed K x e.val (x.graph.right e).val
let initialOther := loadedOther fixed K x (x.graph.left e).val (x.graph.right e).val
let nextPower := (GraphPackingPreparation.repetitions fixed K x + 1) ^ (e.val + 1)
let advancedInput := Function.update initialInput .edgePower nextPower
let otherβ := Function.update initialOther (.inr Work.leftEndpoint) 0
let otherβ := Function.update otherβ (.inr Work.rightEndpoint) 0
let otherβ := Function.update otherβ (.inr Work.leftPower) 0
let otherβ := Function.update otherβ (.inr Work.rightPower) 0
let inputβ := Function.update advancedInput .labelPower 0
let inputβ := Function.update inputβ .repetitionOne 0
let clean : State := .arithmetic (BinaryAddMachine.clean ())
have initialInputWidth : β a, (initialInput a).size β€ width :=
completedInputs_width fixed K x e.val (x.graph.right e).val
(Nat.le_of_lt e.isLt) (x.graph.right e).isLt
have initialOtherWidth : β r, (initialOther r).size β€ width :=
loadedOther_width fixed K x (x.graph.left e).val (x.graph.right e).val
(x.graph.left e).isLt (x.graph.right e).isLt
have zeroWidth : (0 : Nat).size β€ width := by simp
have advancedInputWidth : β a, (advancedInput a).size β€ width :=
GraphPackingWidths.update_width fixed K x initialInput initialInputWidth .edgePower
nextPower (GraphPackingWidths.edge_power_width fixed K x (e.val + 1)
(Nat.succ_le_of_lt e.isLt))
have otherβWidth : β r, (otherβ r).size β€ width :=
GraphPackingWidths.update_width fixed K x initialOther initialOtherWidth _ 0 zeroWidth
have otherβWidth : β r, (otherβ r).size β€ width :=
GraphPackingWidths.update_width fixed K x otherβ otherβWidth _ 0 zeroWidth
have otherβWidth : β r, (otherβ r).size β€ width :=
GraphPackingWidths.update_width fixed K x otherβ otherβWidth _ 0 zeroWidth
have otherβWidth : β r, (otherβ r).size β€ width :=
GraphPackingWidths.update_width fixed K x otherβ otherβWidth _ 0 zeroWidth
have inputβWidth : β a, (inputβ a).size β€ width :=
GraphPackingWidths.update_width fixed K x advancedInput advancedInputWidth _ 0 zeroWidth
have temporaryZero : initialOther (.inr Work.temporary) = 0 :=
loaded_helper_zero fixed K x (x.graph.left e).val (x.graph.right e).val
.temporary (Or.inr (Or.inr (Or.inl rfl)))
have baseValue : initialOther (GraphPackingProgram.otherSetup fixed K .base) =
GraphPackingPreparation.repetitions fixed K x + 1 := by
change loadedOther fixed K x (x.graph.left e).val (x.graph.right e).val
(.inl (PackingSetupMachine.output (parameters fixed K) .base)) = _
rw [loaded_setup]
rfl
have edgeValue : initialInput .edgePower =
(GraphPackingPreparation.repetitions fixed K x + 1) ^ e.val := by
simp [initialInput, completedInputs, inputs]
have productValue : PackingRegisterUpdate.operation .multiply
(initialOther (GraphPackingProgram.otherSetup fixed K .base))
(initialInput .edgePower) = nextPower := by
simp only [PackingRegisterUpdate.operation, baseValue, edgeValue]
exact (Nat.mul_comm _ _).trans (Nat.pow_succ _ _).symm
obtain β¨nβ, bβ, rββ© := PackingVertexUpdate.general_exec
(Numerator fixed) denominator .edgePower
(GraphPackingProgram.otherSetup fixed K .base) (.inr Work.temporary)
(by simp [GraphPackingProgram.otherSetup]) .multiply
base initialInput initialOther temporaryZero state
rw [productValue] at rβ
change Exec (GraphPackingProgram.incrementEdge fixed K)
β¨state, tapes (Numerator fixed) denominator base initialInput initialOtherβ© nβ
β¨clean, tapes (Numerator fixed) denominator base advancedInput initialOtherβ© at rβ
have multiplicationBound : nβ β€ 64 * (2 * width + 1) ^ 2 := by
apply bβ.trans
apply Nat.mul_le_mul_left 64
apply Nat.pow_le_pow_left
have hb := initialOtherWidth (GraphPackingProgram.otherSetup fixed K .base)
have he := initialInputWidth .edgePower
omega
obtain β¨nβ, bβ, rββ© := PackingLayoutCommands.setOther_exec
(Numerator fixed) denominator (.inr Work.leftEndpoint) 0
base advancedInput initialOther clean width advancedInputWidth initialOtherWidth
obtain β¨nβ, bβ, rββ© := PackingLayoutCommands.setOther_exec
(Numerator fixed) denominator (.inr Work.rightEndpoint) 0
base advancedInput otherβ clean width advancedInputWidth otherβWidth
obtain β¨nβ, bβ, rββ© := PackingLayoutCommands.setOther_exec
(Numerator fixed) denominator (.inr Work.leftPower) 0
base advancedInput otherβ clean width advancedInputWidth otherβWidth
obtain β¨nβ, bβ, rββ© := PackingLayoutCommands.setOther_exec
(Numerator fixed) denominator (.inr Work.rightPower) 0
base advancedInput otherβ clean width advancedInputWidth otherβWidth
obtain β¨nβ
, bβ
, rβ
β© := PackingLayoutCommands.setInput_exec
(Numerator fixed) denominator .labelPower 0
base advancedInput otherβ clean width advancedInputWidth otherβWidth
obtain β¨nβ, bβ, rββ© := PackingLayoutCommands.setInput_exec
(Numerator fixed) denominator .repetitionOne 0
base inputβ otherβ clean width inputβWidth otherβWidth
have finalOther : otherβ = preparedOther fixed K x :=
clearedOther_eq fixed K x (x.graph.left e).val (x.graph.right e).val
have finalInput : inputβ = inputs fixed K x (e.val + 1) :=
clearedInputs_eq fixed K x e.val (x.graph.right e).val
have runs := PhaseRuns.cons rβ (PhaseRuns.cons rβ (PhaseRuns.cons rβ
(PhaseRuns.cons rβ (PhaseRuns.cons rβ (PhaseRuns.cons rβ
(PhaseRuns.single rβ))))))
refine β¨nβ + (nβ + (nβ + (nβ + (nβ + (nβ
+ nβ))))), ?_, ?_β©
Β· rw [cleanupTimePolynomial, Polynomial.eval_comp]
change _ β€ (cleanupWidthTimePolynomial fixed K).eval width
simp only [cleanupWidthTimePolynomial, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_pow, Polynomial.eval_ofNat, Polynomial.eval_X, Polynomial.eval_one]
omega
Β· change PhaseRuns (cleanupPhases fixed K)
β¨state, tapes (Numerator fixed) denominator base initialInput initialOtherβ© _
β¨clean, tapes (Numerator fixed) denominator base
(inputs fixed K x (e.val + 1)) (preparedOther fixed K x)β©
rw [β finalOther, β finalInput]
simpa only [cleanupPhases, GraphPackingProgram.setWork, GraphPackingProgram.setItem]
using runs
end BinPackingGap.GraphPackingJobs
end
end OAI
|