threshold-thermometertobinary

Converts 7-bit thermometer code to 3-bit binary. The inverse of BinaryToThermometer.

Circuit

  tβ‚€  t₁  tβ‚‚  t₃  tβ‚„  tβ‚…  t₆
   β”‚   β”‚   β”‚   β”‚   β”‚   β”‚   β”‚
   β”‚   β”‚   β”‚   β”‚   β”‚   β”‚   β”‚
   β”œβ”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜
   β”‚   β”‚       β”‚       β”‚
   β”‚   β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί bβ‚‚ (direct from t₃)
   β”‚   β”‚       β”‚       β”‚
   β”‚   β”‚   β”Œβ”€β”€β”€β”΄β”€β”€β”€β”   β”‚
   β”‚   β”‚   β”‚tβ‚βˆ§Β¬t₃ β”‚   β”‚
   β”‚   β”‚   β””β”€β”€β”€β”¬β”€β”€β”€β”˜   β”‚
   β”‚   β”‚       β”‚       β”‚
   β”‚   β”‚       β”œβ”€β”€β”€OR──┴──────────► b₁
   β”‚   β”‚       β”‚   β”‚
   β”‚   β”‚       β”‚   tβ‚…
   β”‚   β”‚       β”‚
   β”œβ”€β”€β”€β”΄β”€β”€β”€β” β”Œβ”€β”΄β”€β” β”Œβ”€β”€β”€β”
   β”‚tβ‚€βˆ§Β¬t₁│ β”‚...β”‚ β”‚t₆ β”‚
   β””β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”¬β”€β”˜ β””β”€β”¬β”€β”˜
       β”‚       β”‚     β”‚
       └───────┴─OR──┴────────────► bβ‚€

Conversion Table

Thermometer Value Binary
0000000 0 000
1000000 1 001
1100000 2 010
1110000 3 011
1111000 4 100
1111100 5 101
1111110 6 110
1111111 7 111

Mechanism

For valid thermometer (monotonic ones then zeros), tα΅’ = 1 iff value > i.

bβ‚‚ (bit 2): Directly equals t₃.

  • t₃ = 1 iff value β‰₯ 4, which is exactly when bβ‚‚ = 1

b₁ (bit 1): Fires for values {2, 3, 6, 7}.

b₁ = (t₁ AND NOT(t₃)) OR tβ‚…
  • t₁ AND NOT(t₃) catches values 2, 3 (β‰₯2 but <4)
  • tβ‚… catches values 6, 7 (β‰₯6)

bβ‚€ (bit 0): Fires for odd values {1, 3, 5, 7}.

bβ‚€ = (tβ‚€ AND NOT(t₁)) OR (tβ‚‚ AND NOT(t₃)) OR (tβ‚„ AND NOT(tβ‚…)) OR t₆

Each AND-NOT term detects a transition from 1 to 0 at an odd position.

The Transition Detection Insight

In valid thermometer code, the value equals the position of the last 1. The formula detects "where does the thermometer stop?"

Value Last 1 at Detected by
1 tβ‚€ tβ‚€ AND NOT(t₁)
3 tβ‚‚ tβ‚‚ AND NOT(t₃)
5 tβ‚„ tβ‚„ AND NOT(tβ‚…)
7 t₆ t₆ (no t₇ to check)

Architecture

Output Neurons Parameters
bβ‚‚ 1 8
b₁ 2 11
bβ‚€ 4 29
Total 7 48

Layers: 2

Asymmetry Note

BinaryToThermometer is single-layer (7 parallel thresholds). ThermometerToBinary requires 2 layers because extracting individual bits from a sum needs non-trivial logic.

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def therm_to_binary(therm):
    """therm: 7-element list"""
    # See model.py for full implementation
    pass

# Thermometer for 5 -> binary 101
therm = [1, 1, 1, 1, 1, 0, 0]
b2, b1, b0 = therm_to_binary(therm)
print(b2, b1, b0)  # 1, 0, 1

Files

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

License

MIT

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

Collection including phanerozoic/threshold-thermometertobinary