phanerozoic commited on
Commit
60f4258
·
verified ·
1 Parent(s): 636cc38

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +106 -0
README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - formal-verification
5
+ - coq
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - arithmetic
9
+ - adder
10
+ ---
11
+
12
+ # tiny-RippleCarry2Bit-verified
13
+
14
+ Formally verified 2-bit ripple carry adder. Chains two full adders to add two 2-bit numbers with 100% accuracy.
15
+
16
+ ## Architecture
17
+
18
+ | Component | Value |
19
+ |-----------|-------|
20
+ | Inputs | 4 (a1, a0, b1, b0) |
21
+ | Outputs | 3 (cout, s1, s0) |
22
+ | Neurons | 8 (2 full adders × 4 neurons each) |
23
+ | Parameters | 24 (2 full adders × 12 params each) |
24
+ | Layers | 2 (chained full adders) |
25
+ | Activation | Heaviside step |
26
+
27
+ ## Key Properties
28
+
29
+ - 100% accuracy (16/16 input combinations correct)
30
+ - Coq-proven correctness
31
+ - Compositional construction from verified full adders
32
+ - Produces 3-bit output (sum can be 0-6, requiring 3 bits)
33
+ - Compatible with neuromorphic hardware
34
+
35
+ ## Circuit Structure
36
+
37
+ ```
38
+ a1 a0 b1 b0
39
+ | | | |
40
+ | +--+--+ |
41
+ | | |
42
+ | FA0 (cin=0)
43
+ | | |
44
+ | s0 c0
45
+ | | |
46
+ +--+--+-----+
47
+ |
48
+ FA1
49
+ |
50
+ s1 c1
51
+ ```
52
+
53
+ First full adder adds least significant bits (a0 + b0 + 0), producing sum bit s0 and carry c0. Second full adder adds most significant bits with the carry (a1 + b1 + c0), producing s1 and final carry cout.
54
+
55
+ ## Usage
56
+
57
+ ```python
58
+ import torch
59
+ from safetensors.torch import load_file
60
+
61
+ weights = load_file('ripplecarry2bit.safetensors')
62
+
63
+ def full_adder_sim(a, b, cin):
64
+ sum_out = a ^ b ^ cin
65
+ carry_out = (a & b) | (cin & (a ^ b))
66
+ return sum_out, carry_out
67
+
68
+ def ripple_carry_2bit(a1, a0, b1, b0):
69
+ s0, c0 = full_adder_sim(a0, b0, 0)
70
+ s1, cout = full_adder_sim(a1, b1, c0)
71
+ return cout, s1, s0
72
+
73
+ # Test
74
+ print(ripple_carry_2bit(1, 1, 1, 0)) # 3 + 2 = 5 -> (1, 0, 1)
75
+ print(ripple_carry_2bit(1, 0, 1, 0)) # 2 + 2 = 4 -> (1, 0, 0)
76
+ print(ripple_carry_2bit(0, 1, 0, 1)) # 1 + 1 = 2 -> (0, 1, 0)
77
+ ```
78
+
79
+ ## Verification
80
+
81
+ **Coq Theorem**:
82
+ ```coq
83
+ Theorem ripple_carry_2bit_correct : forall a1 a0 b1 b0,
84
+ ripple_carry_2bit a1 a0 b1 b0 = ripple_carry_2bit_spec a1 a0 b1 b0.
85
+ ```
86
+
87
+ Proven axiom-free via exhaustive case analysis on all 16 input combinations.
88
+
89
+ Full proof: [coq-circuits/Arithmetic/RippleCarry2Bit.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Arithmetic/RippleCarry2Bit.v)
90
+
91
+ ## Properties
92
+
93
+ - **Commutative**: Adding A + B equals B + A
94
+ - **Identity**: Adding 0 preserves the value
95
+ - **Compositional**: Built from two verified FullAdder circuits
96
+
97
+ ## Citation
98
+
99
+ ```bibtex
100
+ @software{tiny_ripplecarry2bit_verified_2025,
101
+ title={tiny-RippleCarry2Bit-verified: Formally Verified 2-Bit Ripple Carry Adder},
102
+ author={Norton, Charles},
103
+ url={https://huggingface.co/phanerozoic/tiny-RippleCarry2Bit-verified},
104
+ year={2025}
105
+ }
106
+ ```