math / data /lean /OAI /Computability /QuantumFactoring /BitArithmeticDivision.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.51 kB
import Mathlib
import OAI.Computability.QuantumFactoring.BitArithmetic
import OAI.Computability.QuantumFactoring.AIGDivisionBounds
namespace OAI
section
open scoped BigOperators
namespace ExactQuantumFactoring.BitArithmetic
open Std.Sat Std.Tactic.BVDecide.BVExpr.bitblast
open AIGCompiler BooleanNetwork
def sub (w : β„•) : BooleanNetwork (w+w) w :=
let res := blastSub (inputs (w+w)).1 (binaryInputs w)
compileVec res.aig res.vec
lemma sub_correct (w : β„•) (x : Fin (w+w) β†’ Bool) (i : Fin w) :
(sub w).eval x i = (leftWord x - rightWord x).getLsbD i.val := by
rw [sub, compileVec_correct]
exact denote_blastSub _ _ _ _ _ (binaryInputs_left w x) (binaryInputs_right w x) _ _
lemma sub_count (w : β„•) : (sub w).net.count ≀ 158*w+6 := by
have h := compileVec_count (blastSub (inputs (w+w)).1 (binaryInputs w)).aig
(blastSub (inputs (w+w)).1 (binaryInputs w)).vec
have hs := AIGBounds.sub_size (inputs (w+w)).1 (binaryInputs w)
rw [inputs_size] at hs
dsimp only [sub]
nlinarith
def div (w : β„•) : BooleanNetwork (w+w) w :=
let res := blastUdiv (inputs (w+w)).1 (binaryInputs w)
compileVec res.aig res.vec
lemma div_correct (w : β„•) (x : Fin (w+w) β†’ Bool) (i : Fin w) :
(div w).eval x i = (leftWord x / rightWord x).getLsbD i.val := by
rw [div, compileVec_correct]
exact denote_blastUdiv _ _ _ _ _ (binaryInputs_left w x) (binaryInputs_right w x) _ _
lemma div_count (w : β„•) : (div w).net.count ≀ 216*w*w+56*w+6 := by
have h := compileVec_count (blastUdiv (inputs (w+w)).1 (binaryInputs w)).aig
(blastUdiv (inputs (w+w)).1 (binaryInputs w)).vec
have hs := AIGBounds.div_size (inputs (w+w)).1 (binaryInputs w)
rw [inputs_size] at hs
dsimp only [div]
nlinarith
def mod (w : β„•) : BooleanNetwork (w+w) w :=
let res := blastUmod (inputs (w+w)).1 (binaryInputs w)
compileVec res.aig res.vec
lemma mod_correct (w : β„•) (x : Fin (w+w) β†’ Bool) (i : Fin w) :
(mod w).eval x i = (leftWord x % rightWord x).getLsbD i.val := by
rw [mod, compileVec_correct]
exact denote_blastUmod _ _ _ _ _ (binaryInputs_left w x) (binaryInputs_right w x) _ _
lemma mod_count (w : β„•) : (mod w).net.count ≀ 216*w*w+56*w+6 := by
have h := compileVec_count (blastUmod (inputs (w+w)).1 (binaryInputs w)).aig
(blastUmod (inputs (w+w)).1 (binaryInputs w)).vec
have hs := AIGBounds.mod_size (inputs (w+w)).1 (binaryInputs w)
rw [inputs_size] at hs
dsimp only [mod]
nlinarith
end ExactQuantumFactoring.BitArithmetic
end
end OAI