File size: 1,933 Bytes
ea76aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Computability.MinUncut.Model

namespace OAI

section
namespace MinUncutGames.Integration.BinaryCoordinates

abbrev Coordinates (n : Nat) := Fin n → Bool

def pack : {n : Nat} → Coordinates n → BitVec n
  | 0, _ => 0
  | _ + 1, f => BitVec.concat (pack (fun i => f i.succ)) (f 0)

def unpack {n : Nat} (v : BitVec n) : Coordinates n :=
  fun i => v.getLsbD i.val

theorem pack_get {n : Nat} (f : Coordinates n) (i : Fin n) :
    (pack f).getLsbD i.val = f i := by
  induction n with
  | zero => exact Fin.elim0 i
  | succ n ih =>
    refine Fin.cases ?_ (fun j => ?_) i
    · exact BitVec.getLsbD_concat_zero
    · exact (BitVec.getLsbD_concat_succ).trans (ih (fun j => f j.succ) j)

theorem unpack_pack {n : Nat} (f : Coordinates n) : unpack (pack f) = f := by
  funext i
  exact pack_get f i

theorem pack_unpack {n : Nat} (v : BitVec n) : pack (unpack v) = v := by
  apply BitVec.eq_of_getLsbD_eq
  intro i hi
  exact pack_get (unpack v) ⟨i, hi⟩

theorem unpack_injective {n : Nat} : Function.Injective (@unpack n) := by
  intro u v h
  have h' := congrArg pack h
  simpa only [pack_unpack] using h'

theorem pack_injective {n : Nat} : Function.Injective (@pack n) := by
  intro u v h
  have h' := congrArg unpack h
  simpa only [unpack_pack] using h'

theorem unpack_xor {n : Nat} (u v : BitVec n) :
    unpack (u ^^^ v) = fun i => (unpack u i ^^ unpack v i) := by
  funext i
  exact BitVec.getLsbD_xor

theorem pack_xor {n : Nat} (u v : Coordinates n) :
    pack (fun i => (u i ^^ v i)) = pack u ^^^ pack v := by
  apply unpack_injective
  rw [unpack_pack, unpack_xor, unpack_pack, unpack_pack]

theorem unpack_zero {n : Nat} : unpack (0 : BitVec n) = fun _ => false := by
  funext i
  simp [unpack]

theorem pack_zero {n : Nat} : pack (fun _ : Fin n => false) = 0 := by
  apply unpack_injective
  rw [unpack_pack, unpack_zero]

end MinUncutGames.Integration.BinaryCoordinates

end

end OAI