Buckets:
| import Mathlib | |
| import OAI.Computability.QuantumFactoring.BitStackLists | |
| namespace OAI | |
| section | |
| namespace ExactQuantumFactoring.BitStackProgram | |
| /-- Prefix-free quoting for one Boolean word. Both constructor tags and payload | |
| bits are literal stack symbols. It is used only by the classical generator. -/ | |
| def quoteBits (xs : List Bool) : List Bool := | |
| xs.flatMap (fun b=>[true,b]) ++ [false] | |
| @[simp] lemma quoteBits_nil : quoteBits []=[false] := rfl | |
| @[simp] lemma quoteBits_cons (b : Bool) (xs : List Bool) : | |
| quoteBits (b::xs)=true::b::quoteBits xs := rfl | |
| lemma quoteBits_length (xs : List Bool) : (quoteBits xs).length=2*xs.length+1 := by | |
| induction xs with | |
| | nil => rfl | |
| | cons b xs ih => simp only [quoteBits_cons,List.length_cons,ih]; omega | |
| def pairBits (xs ys : List Bool) : List Bool := quoteBits xs++ys | |
| lemma pairBits_length (xs ys : List Bool) : | |
| (pairBits xs ys).length=2*xs.length+ys.length+1 := by | |
| simp only [pairBits,List.length_append,quoteBits_length]; omega | |
| variable {K : Type} [DecidableEq K] | |
| def quoteLoop (a t : K) : Program K := | |
| .loop a (.seq (.push t true) (.push t false)) (.seq (.push t true) (.push t true)) | |
| def quoteMove (a b t : K) : Program K := | |
| .seq (quoteLoop a t) (.seq (.push t false) (reverseMove t b)) | |
| lemma quoteLoop_runs (a t : K) (hat : a≠t) (s : Store K) : | |
| Runs (quoteLoop a t) s | |
| (Function.update (Function.update s a []) t | |
| (((s a).flatMap (fun b=>[true,b])).reverse++s t)) (3*(s a).length+1) := by | |
| generalize hs : s a=xs at * | |
| induction xs generalizing s with | |
| | nil => | |
| have h : Function.update (Function.update s a []) t | |
| (([].flatMap (fun b=>[true,b])).reverse++s t)=s := by | |
| simp only [List.flatMap_nil,List.reverse_nil,List.nil_append] | |
| rw [←hs,Function.update_eq_self,Function.update_eq_self] | |
| rw [h] | |
| exact Runs.loop_nil hs | |
| | cons x xs ih => | |
| let u := Function.update s a xs | |
| let v := Function.update u t (x::true::u t) | |
| have hva : v a=xs := by simp [v,u,hat] | |
| have hb : Runs (.seq (.push t true) (.push t x)) u v 2 := by | |
| have hh := Runs.seq (Runs.push u t true) | |
| (Runs.push (Function.update u t (true::u t)) t x) | |
| simpa only [Function.update_self,Function.update_idem] using hh | |
| have hh : Runs (quoteLoop a t) s | |
| (Function.update (Function.update v a []) t | |
| ((xs.flatMap (fun b=>[true,b])).reverse++v t)) (3*xs.length+1+2+1) := by | |
| cases x | |
| · exact Runs.loop_false (a:=2) (b:=3*xs.length+1) hs hb (ih v hva) | |
| · exact Runs.loop_true (a:=2) (b:=3*xs.length+1) hs hb (ih v hva) | |
| convert hh using 1 | |
| · funext k | |
| by_cases ha : k=a <;> by_cases ht : k=t <;> | |
| simp_all [v,u,Function.update,List.reverse_cons,List.append_assoc] | |
| lemma quoteMove_runs (a b t : K) (hab : a≠b) (hat : a≠t) (hbt : b≠t) | |
| (s : Store K) (ht : s t=[]) : | |
| Runs (quoteMove a b t) s | |
| (Function.update (Function.update s a []) b (quoteBits (s a)++s b)) | |
| (7*(s a).length+5) := by | |
| let u := Function.update (Function.update s a []) t | |
| (((s a).flatMap (fun b=>[true,b])).reverse++s t) | |
| let v := Function.update u t (false::u t) | |
| have hh := Runs.seq (quoteLoop_runs a t hat s) | |
| (Runs.seq (Runs.push u t false) (reverseMove_runs t b hbt.symm v)) | |
| change Runs (.seq _ _) _ _ _ | |
| convert hh using 1 | |
| · funext k | |
| by_cases ha : k=a <;> by_cases hb : k=b <;> by_cases ht' : k=t <;> | |
| simp_all [u,v,Function.update,quoteBits,Ne.symm hat,Ne.symm hab,Ne.symm hbt] | |
| · simp only [v,Function.update_self,u,Function.update_self,ht,List.append_nil, | |
| List.length_cons,List.length_reverse] | |
| have hl : ((s a).flatMap (fun b=>[true,b])).length=2*(s a).length := by | |
| have h:=quoteBits_length (s a) | |
| simp only [quoteBits,List.length_append,List.length_cons,List.length_nil] at h | |
| omega | |
| rw [hl]; omega | |
| def unquoteBody (a t c : K) : Program K := | |
| .cases a .skip .skip | |
| (.cases a .skip (.seq (.push t false) (.push c true)) | |
| (.seq (.push t true) (.push c true))) | |
| def unquoteLoop (a t c : K) : Program K := | |
| .loop c (unquoteBody a t c) (unquoteBody a t c) | |
| def unquoteMove (a b t c : K) : Program K := | |
| .seq (.push c true) (.seq (unquoteLoop a t c) (reverseMove t b)) | |
| lemma unquoteLoop_runs (a t c : K) (hat : a≠t) (hac : a≠c) (htc : t≠c) | |
| (xs ys : List Bool) (s : Store K) (ha : s a=quoteBits xs++ys) (hc : s c=[true]) : | |
| Runs (unquoteLoop a t c) s | |
| (Function.update (Function.update (Function.update s a ys) c []) t (xs.reverse++s t)) | |
| (5*xs.length+4) := by | |
| induction xs generalizing s with | |
| | nil => | |
| let u := Function.update s c [] | |
| let v := Function.update u a ys | |
| have hua : u a=false::ys := by simp [u,hac,ha] | |
| have hvc : v c=[] := by simp [v,u,hac.symm] | |
| have hb : Runs (unquoteBody a t c) u v 2 := Runs.cases_false hua (Runs.skip v) | |
| have hh := Runs.loop_true (p:=unquoteBody a t c) hc hb (Runs.loop_nil hvc) | |
| change Runs (.loop _ _ _) _ _ _ | |
| convert hh using 1 | |
| · funext k | |
| by_cases ha' : k=a <;> by_cases hc' : k=c <;> by_cases ht' : k=t <;> | |
| simp_all [v,u,Function.update,Ne.symm hat,Ne.symm hac,Ne.symm htc] | |
| | cons x xs ih => | |
| let u := Function.update s c [] | |
| let v := Function.update u a (x::quoteBits xs++ys) | |
| let w := Function.update v a (quoteBits xs++ys) | |
| let z := Function.update (Function.update w t (x::w t)) c [true] | |
| have hua : u a=true::x::quoteBits xs++ys := by simp [u,hac,ha] | |
| have hva : v a=x::quoteBits xs++ys := by simp [v] | |
| have hzc : z c=[true] := by simp [z] | |
| have hza : z a=quoteBits xs++ys := by simp [z,w,v,hat,hac] | |
| have hb : Runs (unquoteBody a t c) u z 4 := by | |
| apply Runs.cases_true hua | |
| have hh := Runs.seq (Runs.push w t x) | |
| (Runs.push (Function.update w t (x::w t)) c true) | |
| have hc0 : Function.update w t (x::w t) c=[] := by simp [w,v,u,htc.symm,hac.symm] | |
| rw [hc0] at hh | |
| cases x | |
| · exact Runs.cases_false hva hh | |
| · exact Runs.cases_true hva hh | |
| have hh := Runs.loop_true hc hb (ih z hza hzc) | |
| change Runs (.loop _ _ _) _ _ _ | |
| convert hh using 1 | |
| · funext k | |
| by_cases ha' : k=a <;> by_cases hc' : k=c <;> by_cases ht' : k=t <;> | |
| simp_all [z,w,v,u,Function.update,Ne.symm hat,Ne.symm hac,Ne.symm htc, | |
| List.reverse_cons,List.append_assoc] | |
| lemma unquoteMove_runs (a b t c : K) (hab : a≠b) (hat : a≠t) (hac : a≠c) | |
| (hbt : b≠t) (hbc : b≠c) (htc : t≠c) | |
| (xs ys : List Bool) (s : Store K) (ha : s a=quoteBits xs++ys) | |
| (ht : s t=[]) (hc : s c=[]) : | |
| Runs (unquoteMove a b t c) s | |
| (Function.update (Function.update s a ys) b (xs++s b)) (7*xs.length+6) := by | |
| let u := Function.update s c [true] | |
| let v := Function.update (Function.update (Function.update u a ys) c []) t (xs.reverse++u t) | |
| have hua : u a=quoteBits xs++ys := by simp [u,hac,ha] | |
| have huc : u c=[true] := by simp [u] | |
| have hp : Runs (.push c true) s u 1 := by simpa only [hc] using Runs.push s c true | |
| have hh := Runs.seq hp (Runs.seq (unquoteLoop_runs a t c hat hac htc xs ys u hua huc) | |
| (reverseMove_runs t b hbt.symm v)) | |
| change Runs (.seq _ _) _ _ _ | |
| convert hh using 1 | |
| · funext k | |
| by_cases ha' : k=a <;> by_cases hb' : k=b <;> by_cases ht' : k=t <;> by_cases hc' : k=c <;> | |
| simp_all [v,u,Function.update,Ne.symm hab,Ne.symm hat,Ne.symm hac,Ne.symm hbt, | |
| Ne.symm hbc,Ne.symm htc] | |
| · simp only [v,Function.update_self,u,Function.update_of_ne htc,ht,List.append_nil, | |
| List.length_reverse]; omega | |
| end ExactQuantumFactoring.BitStackProgram | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 7.52 kB
- Xet hash:
- 81c117f7a21f265d8940e1f20da7fb96427273727b511a66f4ac30f61c04a996
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.