ApplePiesFromScratch commited on
Commit
70e8ba6
·
verified ·
1 Parent(s): add3dcd

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +21 -0
  2. receipt_calc.py +60 -0
README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - process-calc
5
+ - receipt
6
+ - exact-arithmetic
7
+ ---
8
+
9
+ # rate-receipt
10
+
11
+ Same kernel as `process-calc`, but every call returns a **receipt**:
12
+ seed, value, channel, rate, gauge yes/no.
13
+
14
+ ```python
15
+ from receipt_calc import mix, receipt
16
+ print(receipt(lambda x: mix(x, x), 3))
17
+ ```
18
+
19
+ Empty seeds and seed 0 are θ. Float is θ.
20
+
21
+ Not an LLM. Sister of `process-calc`.
receipt_calc.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Every rate write is a receipt. Stdlib only."""
3
+ from __future__ import annotations
4
+
5
+ from fractions import Fraction as F
6
+
7
+
8
+ def as_exact(x):
9
+ if isinstance(x, bool):
10
+ raise TypeError("theta bool")
11
+ if isinstance(x, int):
12
+ return F(x)
13
+ if isinstance(x, F):
14
+ return F(x)
15
+ raise TypeError("theta not Q: %s" % type(x).__name__)
16
+
17
+
18
+ def isolate(v, seed):
19
+ v, seed = as_exact(v), as_exact(seed)
20
+ if seed == 0:
21
+ raise ValueError("theta seed 0")
22
+ return (v, seed)
23
+
24
+
25
+ def mix(a, b):
26
+ (v, r), (w, s) = a, b
27
+ return (v * w, r * w + v * s)
28
+
29
+
30
+ def rate(top, bot):
31
+ if bot[1] == 0:
32
+ raise ValueError("theta dead isolator")
33
+ return top[1] / bot[1]
34
+
35
+
36
+ def receipt(fn, v, seeds=(1, 2, F(1, 2), -1)):
37
+ """One row per seed, plus gauge (all rates equal or split)."""
38
+ if not seeds:
39
+ raise ValueError("theta empty seeds")
40
+ rows = []
41
+ for s in seeds:
42
+ x = isolate(v, s)
43
+ y = fn(x)
44
+ r = rate(y, x)
45
+ rows.append({"seed": s, "value": y[0], "channel": y[1], "rate": r})
46
+ rates = [row["rate"] for row in rows]
47
+ gauge = all(r == rates[0] for r in rates)
48
+ return {"at": as_exact(v), "gauge": gauge, "rate": rates[0] if gauge else None, "rows": rows, "theta": not gauge}
49
+
50
+
51
+ if __name__ == "__main__":
52
+ sq = lambda x: mix(x, x)
53
+ rec = receipt(sq, 3)
54
+ print("gauge", rec["gauge"], "rate", rec["rate"])
55
+ for row in rec["rows"]:
56
+ print(row)
57
+ try:
58
+ receipt(sq, 3, seeds=())
59
+ except ValueError as e:
60
+ print(e)