File size: 869 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
import Mathlib
import OAI.Computability.QuantumFactoring.BitEncoding

namespace OAI

section
open scoped BigOperators


namespace ExactQuantumFactoring
open scoped BigOperators

lemma bitsValue_toNat {b : ℕ} (x : Fin b → Bool) :
    (bitsValue x).toNat = ∑ i : Fin b, 2^i.val*(x i).toNat := by
  induction b with
  | zero => simp [bitsValue]
  | succ b ih =>
    rw [bitsValue, BitVec.toNat_cons', Nat.shiftLeft_eq, ih, Fin.sum_univ_castSucc]
    simp only [Fin.val_last, Fin.val_castSucc]
    ring

lemma bitsValue_ofFn {b : ℕ} (v : Fin (2^b)) :
    (bitsValue (fun i : Fin b => v.val.testBit i.val)).toNat = v.val := by
  have he : (fun i : Fin b => v.val.testBit i.val) =
      (fun i : Fin b => (BitVec.ofNat b v.val).getLsbD i.val) := by simp
  rw [he, bitsValue_bits, BitVec.toNat_ofNat, Nat.mod_eq_of_lt v.isLt]

end ExactQuantumFactoring


end

end OAI