--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic - arithmetic --- # threshold-subtractor4bit 4-bit subtractor. Computes A - B (modulo 16) with borrow output. ## Function subtractor4bit(A, B) = (A - B) mod 16, borrow_out ## Truth Table (selected rows) | A | B | Diff | Borrow | |---|---|------|--------| | 7 | 3 | 4 | 0 | | 5 | 5 | 0 | 0 | | 3 | 7 | 12 | 1 | | 0 | 1 | 15 | 1 | ## Architecture Ripple-borrow subtractor using full subtractor units. For each bit i: - diff_i = a_i XOR b_i XOR borrow_{i-1} - borrow_i = majority(NOT(a_i), b_i, borrow_{i-1}) The borrow signal indicates A < B (unsigned comparison). ## Parameters | | | |---|---| | Inputs | 8 (a3-a0, b3-b0) | | Outputs | 5 (d3-d0, bout) | | Neurons | 25 | | Layers | 8 | | Parameters | 86 | | Magnitude | 88 | ## Usage ```python from safetensors.torch import load_file # See model.py for full implementation # 7 - 3 = 4 # subtractor4(0,1,1,1, 0,0,1,1) = [0,1,0,0, 0] # 3 - 7 = 12 (wraps), borrow=1 # subtractor4(0,0,1,1, 0,1,1,1) = [1,1,0,0, 1] ``` ## License MIT