threshold-ripplecarry2bit

Adds two 2-bit numbers with carry-in. The classic ripple-carry architecture using cascaded full adders.

Circuit

       a0  b0  cin          a1  b1
        β”‚   β”‚   β”‚            β”‚   β”‚
        β””β”€β”€β”€β”Όβ”€β”€β”€β”˜            β””β”€β”€β”€β”Όβ”€β”€β”€β”˜
            β–Ό                    β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚   FA0   │──────────│   FA1   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   c0     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚                    β”‚    β”‚
            β–Ό                    β–Ό    β–Ό
           s0                   s1   cout


    Input:  (a1 a0) + (b1 b0) + cin
    Output: (cout s1 s0)

The carry ripples from FA0 to FA1, hence "ripple-carry."

Example

  11 (a1=1, a0=1)
+ 11 (b1=1, b0=1)
+ 0  (cin=0)
────
 110 (cout=1, s1=1, s0=0)

3 + 3 + 0 = 6 = 0b110

Architecture

Component Neurons
FA0 9
FA1 9

Total: 18 neurons, 42 parameters, 8 layers

Inputs/Outputs

Type Bits Meaning
a a1, a0 First 2-bit number
b b1, b0 Second 2-bit number
cin 1 bit Carry in
s s1, s0 2-bit sum
cout 1 bit Carry out

Usage

from safetensors.torch import load_file

w = load_file('model.safetensors')

def ripple_carry_2bit(a0, a1, b0, b1, cin):
    # FA0: a0 + b0 + cin -> s0, c0
    # FA1: a1 + b1 + c0 -> s1, cout
    # See model.py for full implementation
    pass

Scaling

This 2-bit adder demonstrates the pattern. For n bits:

  • n full adders in cascade
  • Depth grows linearly (slow for large n)
  • Carry-lookahead or prefix adders would be faster but more complex

Files

threshold-ripplecarry2bit/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ model.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

Downloads last month
9
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-ripplecarry2bit