Buckets:
| import Mathlib | |
| import OAI.Computability.QuantumFactoring.AIGCompiler | |
| import OAI.Computability.QuantumFactoring.NetworkEmissionVector | |
| import OAI.Computability.QuantumFactoring.NetworkEmissionRewire | |
| namespace OAI | |
| section | |
| namespace ExactQuantumFactoring.AIGNetworkEmission | |
| open Std.Sat BooleanNetwork | |
| open NetworkEmission | |
| def faninPack (n gs : ℕ) (f : NativeAIG.Ref) : Pack:= | |
| let v:=if f.1<gs then bitPack (n+gs) (n+f.1) else constantPack (n+gs) false | |
| if f.2 then bnotPack v else v | |
| lemma faninPack_value {n : ℕ} (g : AIG (Fin n)) (f : AIG.Fanin) : | |
| (faninPack n g.decls.size (f.gate,f.invert)).val.value=erase (AIGCompiler.faninNet g f):=by | |
| unfold faninPack AIGCompiler.faninNet | |
| by_cases h : f.gate<g.decls.size | |
| · simp only [h,↓reduceIte,↓reduceDIte] | |
| have hv:=bitPack_value (AIGCompiler.graphWire g ⟨f.gate,h⟩) | |
| change (bitPack (n+g.decls.size) (n+f.gate)).val.value=_ at hv | |
| cases f.invert | |
| · exact hv | |
| · exact bnotPack_value _ _ hv | |
| · simp only [h,↓reduceIte,↓reduceDIte] | |
| cases f.invert | |
| · exact constantPack_value _ _ | |
| · exact bnotPack_value _ _ (constantPack_value _ _) | |
| def nodePack (n gs : ℕ) : NativeAIG.Decl→Pack | |
| | .zero=>constantPack (n+gs) false | |
| | .atom v=>bitPack (n+gs) v | |
| | .gate a b=>bandPack (faninPack n gs a) (faninPack n gs b) | |
| lemma nodePack_value {n : ℕ} (g : AIG (Fin n)) (i : Fin g.decls.size) : | |
| (nodePack n g.decls.size (NativeAIG.eraseDecl g.decls[i.val])).val.value= | |
| erase (AIGCompiler.nodeNet g i):=by | |
| unfold AIGCompiler.nodeNet | |
| cases h : g.decls[i.val] with | |
| | false=>exact constantPack_value _ _ | |
| | atom v=>exact bitPack_value (v.castAdd g.decls.size) | |
| | gate a b=>exact bandPack_value _ _ _ _ (faninPack_value g a) (faninPack_value g b) | |
| def partialPack (n : ℕ) (ds : List NativeAIG.Decl) (k : ℕ) : Pack:= | |
| ((List.range k).map (fun i=>assignPack (n+ds.length) (n+i) | |
| (nodePack n ds.length ((ds.drop i).headD .zero)))).foldl compPack (identityPack (n+ds.length)) | |
| lemma partialPack_value {n : ℕ} {r : NativeAIG.Graph} {g : AIG (Fin n)} | |
| (hr : NativeAIG.Rel r g) (k : ℕ) (hk : k≤g.decls.size) : | |
| (partialPack n r.decls k).val.value=erase (AIGCompiler.partialGraph g k hk):=by | |
| have hl : r.decls.length=g.decls.size:=by rw [hr.1,List.length_map,Array.length_toList] | |
| induction k with | |
| | zero=>simpa only [partialPack,List.range_zero,List.map_nil,List.foldl_nil,hl,AIGCompiler.partialGraph] | |
| using identityPack_value (n+g.decls.size) | |
| | succ k ih=> | |
| have hips:=ih (by omega) | |
| have hd : (r.decls.drop k).headD .zero=NativeAIG.eraseDecl g.decls[k]:=by | |
| rw [List.headD_eq_head?_getD,List.head?_drop,hr.1,List.getElem?_map,Array.getElem?_toList, | |
| Array.getElem?_eq_getElem (by omega),Option.map_some,Option.getD_some] | |
| have hn:=assignPack_value (AIGCompiler.graphWire g ⟨k,by omega⟩) _ _ (nodePack_value g ⟨k,by omega⟩) | |
| simp only [AIGCompiler.graphWire,Fin.val_natAdd] at hn | |
| unfold partialPack | |
| rw [List.range_succ,List.map_append,List.map_cons,List.map_nil,List.foldl_append,List.foldl_cons,List.foldl_nil] | |
| change (compPack (partialPack n r.decls k) (assignPack (n+r.decls.length) (n+k) | |
| (nodePack n r.decls.length ((r.decls.drop k).headD .zero)))).val.value=_ | |
| rw [compPack_value] | |
| · rw [hips,hl,hd,hn] | |
| exact (erase_comp _ _).symm | |
| · rw [hips,hl,hd,hn] | |
| simp [erase] | |
| def padPack (n gs : ℕ) : Pack:=vectorPack n ((List.range (n+gs)).map | |
| (fun i=>if i<n then bitPack n i else constantPack n false)) | |
| lemma padPack_value (n gs : ℕ) : (padPack n gs).val.value=erase (BooleanNetwork.padRight n gs):=by | |
| unfold padPack BooleanNetwork.padRight | |
| rw [←ofFn_val_range,List.map_ofFn] | |
| apply vectorPack_value | |
| intro i | |
| dsimp only [Function.comp_apply] | |
| by_cases h : i.val<n | |
| · simp only [h,↓reduceIte,↓reduceDIte] | |
| exact bitPack_value ⟨i.val,h⟩ | |
| · simp only [h,↓reduceIte,↓reduceDIte] | |
| exact constantPack_value _ _ | |
| def compilePack (n : ℕ) (ds : List NativeAIG.Decl) (refs : List NativeAIG.Ref) : Pack:= | |
| compPack (compPack (padPack n ds.length) (partialPack n ds ds.length)) | |
| (vectorPack (n+ds.length) (refs.map (faninPack n ds.length))) | |
| lemma compilePack_value {n m : ℕ} {r : NativeAIG.Graph} {g : AIG (Fin n)} | |
| (hr : NativeAIG.Rel r g) (refs : Fin m→AIG.Ref g) : | |
| (compilePack n r.decls (List.ofFn (fun i=>((refs i).gate,(refs i).invert)))).val.value= | |
| erase (AIGCompiler.compile g refs):=by | |
| have hl : r.decls.length=g.decls.size:=by rw [hr.1,List.length_map,Array.length_toList] | |
| have hp:=partialPack_value hr g.decls.size le_rfl | |
| have hs : (compPack (padPack n r.decls.length) (partialPack n r.decls r.decls.length)).val.value= | |
| erase ((BooleanNetwork.padRight n g.decls.size).comp (AIGCompiler.partialGraph g g.decls.size le_rfl)):=by | |
| rw [compPack_value] | |
| · rw [hl,padPack_value,hp,erase_comp] | |
| · rw [hl,padPack_value,hp];simp [erase] | |
| have hv : (vectorPack (n+r.decls.length) ((List.ofFn (fun i=>((refs i).gate,(refs i).invert))).map | |
| (faninPack n r.decls.length))).val.value= | |
| erase (BooleanNetwork.vector (fun i=>AIGCompiler.faninNet g (.mk (refs i).gate (refs i).invert))):=by | |
| rw [hl,List.map_ofFn] | |
| apply vectorPack_value | |
| intro i | |
| dsimp only [Function.comp_apply] | |
| simpa only [AIG.Fanin.gate_mk,AIG.Fanin.invert_mk] using | |
| faninPack_value g (.mk (refs i).gate (refs i).invert) | |
| unfold compilePack | |
| rw [compPack_value] | |
| · rw [hs,hv];exact (erase_comp _ _).symm | |
| · rw [hs,hv];simp [erase] | |
| end ExactQuantumFactoring.AIGNetworkEmission | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 5.58 kB
- Xet hash:
- 6ac7e1b843bae5e9276f63cff29c6379cb3f74d5da8a7347902d6e8067d43abf
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.