We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Radix-1 contraction

From Esolang
Jump to navigation Jump to search

radix‑1 contraction is useful to evaluate the semantics of a language

example

Fuck you!

import math

S = lambda c: (lambda i: (i, i+1) if i < 27 else (27, 9999))(ord(c) - 65)

def d(s):
    lo, hi = 0.0, 19683.0
    for c in s:
        a, b = S(c)
        w = hi - lo
        lo = lo + w * (a / 9999)
        hi = lo + w * ((b - a) / 9999)
    return lo, hi

f = lambda x: int((x - math.floor(x)) * 1e13 + 0.5)

word = "!"
lo, hi = d(word)
print("lo:", lo)
print("hi:", hi)
print("f(lo):", f(lo))
print("f(hi):", f(hi))

outputs

lo: -62.991899189918996
hi: -61.02340234023403
f(lo): 81008100810
f(hi): 9765976597660

where

lo, hi = 0.0, 9999.0

outputs

lo: -32.0
hi: -31.0
f(lo): 0
f(hi): 0

execution

continue contracting until the interval width is < 1

then take the fractional part

multiply by 1e13

round

and that integer is the semantic byte

python

f = lambda x: int((x - math.floor(x)) * 1e13 + 0.5)