File size: 2,505 Bytes
2f887db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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