CharlesCNorton commited on
Commit ·
01a8320
1
Parent(s): cc0c0b3
Replace optimality_proof.v with mux.v - exact enumeration
Browse files- optimality_proof.v → mux.v +59 -64
- solution1.safetensors +0 -0
- solution2.safetensors +0 -0
- solution3.safetensors +0 -0
- solution4.safetensors +0 -0
optimality_proof.v → mux.v
RENAMED
|
@@ -1,12 +1,3 @@
|
|
| 1 |
-
(*
|
| 2 |
-
MUX Magnitude Discovery
|
| 3 |
-
|
| 4 |
-
We search for the minimum magnitude that can compute 2:1 MUX.
|
| 5 |
-
MUX(a, b, s) = a if s=0, b if s=1
|
| 6 |
-
|
| 7 |
-
The result is discovered through exhaustive computation.
|
| 8 |
-
*)
|
| 9 |
-
|
| 10 |
Require Import ZArith.
|
| 11 |
Require Import Bool.
|
| 12 |
Require Import List.
|
|
@@ -14,45 +5,34 @@ Import ListNotations.
|
|
| 14 |
|
| 15 |
Open Scope Z_scope.
|
| 16 |
|
| 17 |
-
(* Threshold gate with 3 inputs *)
|
| 18 |
Definition threshold3 (w1 w2 w3 b : Z) (x1 x2 x3 : bool) : bool :=
|
| 19 |
Z.geb (w1 * (if x1 then 1 else 0) +
|
| 20 |
w2 * (if x2 then 1 else 0) +
|
| 21 |
w3 * (if x3 then 1 else 0) + b) 0.
|
| 22 |
|
| 23 |
-
(* Threshold gate with 2 inputs *)
|
| 24 |
Definition threshold2 (w1 w2 b : Z) (x1 x2 : bool) : bool :=
|
| 25 |
Z.geb (w1 * (if x1 then 1 else 0) +
|
| 26 |
w2 * (if x2 then 1 else 0) + b) 0.
|
| 27 |
|
| 28 |
-
(* 3-neuron circuit: 2 hidden + 1 output *)
|
| 29 |
Definition circuit (w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo : Z)
|
| 30 |
(a b s : bool) : bool :=
|
| 31 |
let h1 := threshold3 w1a w1b w1s b1 a b s in
|
| 32 |
let h2 := threshold3 w2a w2b w2s b2 a b s in
|
| 33 |
threshold2 wo1 wo2 bo h1 h2.
|
| 34 |
|
| 35 |
-
(
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
negb (circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo false
|
| 41 |
-
(circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
(* Magnitude *)
|
| 50 |
-
Definition magnitude (w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo : Z) : Z :=
|
| 51 |
-
Z.abs w1a + Z.abs w1b + Z.abs w1s + Z.abs b1 +
|
| 52 |
-
Z.abs w2a + Z.abs w2b + Z.abs w2s + Z.abs b2 +
|
| 53 |
-
Z.abs wo1 + Z.abs wo2 + Z.abs bo.
|
| 54 |
-
|
| 55 |
-
(* Generate signed variants *)
|
| 56 |
Fixpoint all_signs (abs_vals : list Z) : list (list Z) :=
|
| 57 |
match abs_vals with
|
| 58 |
| [] => [[]]
|
|
@@ -64,7 +44,6 @@ Fixpoint all_signs (abs_vals : list Z) : list (list Z) :=
|
|
| 64 |
map (cons a) signed_rest ++ map (cons (-a)) signed_rest
|
| 65 |
end.
|
| 66 |
|
| 67 |
-
(* Partition magnitude across positions *)
|
| 68 |
Fixpoint partitions (remaining : Z) (positions : nat) (max_val : Z) : list (list Z) :=
|
| 69 |
match positions with
|
| 70 |
| O => if Z.eqb remaining 0 then [[]] else []
|
|
@@ -74,50 +53,66 @@ Fixpoint partitions (remaining : Z) (positions : nat) (max_val : Z) : list (list
|
|
| 74 |
) (map Z.of_nat (seq 0 (Z.to_nat (Z.min remaining max_val) + 1)))
|
| 75 |
end.
|
| 76 |
|
| 77 |
-
(* All signed configs at magnitude M *)
|
| 78 |
Definition configs_at_mag (m : Z) : list (list Z) :=
|
| 79 |
flat_map all_signs (partitions m 11 m).
|
| 80 |
|
| 81 |
-
(
|
| 82 |
-
|
| 83 |
-
existsb (fun c =>
|
| 84 |
match c with
|
| 85 |
| [w1a; w1b; w1s; b1; w2a; w2b; w2s; b2; wo1; wo2; bo] =>
|
| 86 |
-
|
| 87 |
| _ => false
|
| 88 |
end
|
| 89 |
) configs.
|
| 90 |
|
| 91 |
-
(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
Proof. native_compute. reflexivity. Qed.
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
Proof. native_compute. reflexivity. Qed.
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
Proof. native_compute. reflexivity. Qed.
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
Proof. native_compute. reflexivity. Qed.
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
Proof. native_compute. reflexivity. Qed.
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
Proof. native_compute. reflexivity. Qed.
|
| 120 |
|
| 121 |
-
(
|
| 122 |
-
|
| 123 |
-
Proof. native_compute. reflexivity. Qed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
Require Import ZArith.
|
| 2 |
Require Import Bool.
|
| 3 |
Require Import List.
|
|
|
|
| 5 |
|
| 6 |
Open Scope Z_scope.
|
| 7 |
|
|
|
|
| 8 |
Definition threshold3 (w1 w2 w3 b : Z) (x1 x2 x3 : bool) : bool :=
|
| 9 |
Z.geb (w1 * (if x1 then 1 else 0) +
|
| 10 |
w2 * (if x2 then 1 else 0) +
|
| 11 |
w3 * (if x3 then 1 else 0) + b) 0.
|
| 12 |
|
|
|
|
| 13 |
Definition threshold2 (w1 w2 b : Z) (x1 x2 : bool) : bool :=
|
| 14 |
Z.geb (w1 * (if x1 then 1 else 0) +
|
| 15 |
w2 * (if x2 then 1 else 0) + b) 0.
|
| 16 |
|
|
|
|
| 17 |
Definition circuit (w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo : Z)
|
| 18 |
(a b s : bool) : bool :=
|
| 19 |
let h1 := threshold3 w1a w1b w1s b1 a b s in
|
| 20 |
let h2 := threshold3 w2a w2b w2s b2 a b s in
|
| 21 |
threshold2 wo1 wo2 bo h1 h2.
|
| 22 |
|
| 23 |
+
Definition is_mux (w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo : Z) : bool :=
|
| 24 |
+
negb (circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo false false false) &&
|
| 25 |
+
negb (circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo false true false) &&
|
| 26 |
+
(circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo true false false) &&
|
| 27 |
+
(circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo true true false) &&
|
| 28 |
+
negb (circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo false false true) &&
|
| 29 |
+
(circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo false true true) &&
|
| 30 |
+
negb (circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo true false true) &&
|
| 31 |
+
(circuit w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo true true true).
|
| 32 |
+
|
| 33 |
+
Definition mag (c : list Z) : Z :=
|
| 34 |
+
fold_left (fun acc x => acc + Z.abs x) c 0.
|
| 35 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
Fixpoint all_signs (abs_vals : list Z) : list (list Z) :=
|
| 37 |
match abs_vals with
|
| 38 |
| [] => [[]]
|
|
|
|
| 44 |
map (cons a) signed_rest ++ map (cons (-a)) signed_rest
|
| 45 |
end.
|
| 46 |
|
|
|
|
| 47 |
Fixpoint partitions (remaining : Z) (positions : nat) (max_val : Z) : list (list Z) :=
|
| 48 |
match positions with
|
| 49 |
| O => if Z.eqb remaining 0 then [[]] else []
|
|
|
|
| 53 |
) (map Z.of_nat (seq 0 (Z.to_nat (Z.min remaining max_val) + 1)))
|
| 54 |
end.
|
| 55 |
|
|
|
|
| 56 |
Definition configs_at_mag (m : Z) : list (list Z) :=
|
| 57 |
flat_map all_signs (partitions m 11 m).
|
| 58 |
|
| 59 |
+
Definition filter_mux (configs : list (list Z)) : list (list Z) :=
|
| 60 |
+
filter (fun c =>
|
|
|
|
| 61 |
match c with
|
| 62 |
| [w1a; w1b; w1s; b1; w2a; w2b; w2s; b2; wo1; wo2; bo] =>
|
| 63 |
+
is_mux w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo
|
| 64 |
| _ => false
|
| 65 |
end
|
| 66 |
) configs.
|
| 67 |
|
| 68 |
+
Definition solutions_at_mag (m : Z) : list (list Z) :=
|
| 69 |
+
filter_mux (configs_at_mag m).
|
| 70 |
+
|
| 71 |
+
Definition count (m : Z) : nat :=
|
| 72 |
+
length (solutions_at_mag m).
|
| 73 |
|
| 74 |
+
Theorem count_0 : count 0 = 0%nat.
|
| 75 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 76 |
|
| 77 |
+
Theorem count_1 : count 1 = 0%nat.
|
| 78 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 79 |
|
| 80 |
+
Theorem count_2 : count 2 = 0%nat.
|
| 81 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 82 |
|
| 83 |
+
Theorem count_3 : count 3 = 0%nat.
|
| 84 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 85 |
|
| 86 |
+
Theorem count_4 : count 4 = 0%nat.
|
| 87 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 88 |
|
| 89 |
+
Theorem count_5 : count 5 = 0%nat.
|
| 90 |
+
Proof. vm_compute. reflexivity. Qed.
|
| 91 |
+
|
| 92 |
+
Theorem count_6 : count 6 = 0%nat.
|
| 93 |
+
Proof. vm_compute. reflexivity. Qed.
|
| 94 |
+
|
| 95 |
+
Theorem count_7 : count 7 = 4%nat.
|
| 96 |
+
Proof. vm_compute. reflexivity. Qed.
|
| 97 |
+
|
| 98 |
+
Definition solutions : list (list Z) :=
|
| 99 |
+
[[0; 1; -1; 0; -1; 0; -1; 0; 1; -1; -1];
|
| 100 |
+
[0; -1; 1; -1; -1; 0; -1; 0; -1; -1; 0];
|
| 101 |
+
[-1; 0; -1; 0; 0; 1; -1; 0; -1; 1; -1];
|
| 102 |
+
[-1; 0; -1; 0; 0; -1; 1; -1; -1; -1; 0]].
|
| 103 |
+
|
| 104 |
+
Theorem solutions_eq : solutions_at_mag 7 = solutions.
|
| 105 |
+
Proof. vm_compute. reflexivity. Qed.
|
| 106 |
+
|
| 107 |
+
Definition check (c : list Z) : bool :=
|
| 108 |
+
match c with
|
| 109 |
+
| [w1a; w1b; w1s; b1; w2a; w2b; w2s; b2; wo1; wo2; bo] =>
|
| 110 |
+
is_mux w1a w1b w1s b1 w2a w2b w2s b2 wo1 wo2 bo
|
| 111 |
+
| _ => false
|
| 112 |
+
end.
|
| 113 |
|
| 114 |
+
Theorem solutions_valid : forallb check solutions = true.
|
| 115 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
|
| 116 |
|
| 117 |
+
Theorem solutions_mag : forallb (fun c => Z.eqb (mag c) 7) solutions = true.
|
| 118 |
+
Proof. vm_compute. reflexivity. Qed.
|
|
|
solution1.safetensors
CHANGED
|
Binary files a/solution1.safetensors and b/solution1.safetensors differ
|
|
|
solution2.safetensors
CHANGED
|
Binary files a/solution2.safetensors and b/solution2.safetensors differ
|
|
|
solution3.safetensors
CHANGED
|
Binary files a/solution3.safetensors and b/solution3.safetensors differ
|
|
|
solution4.safetensors
CHANGED
|
Binary files a/solution4.safetensors and b/solution4.safetensors differ
|
|
|