import mpmath as mp
mp.mp.dps = 130
def komornik_loreti(M):
# Approximation for any positive integer M; certification is in generate.py.
if int(M) != M or M < 1:
raise ValueError("M must be a positive integer")
k = M // 2
lo = mp.mpf(3)/2 if M == 1 else mp.mpf(k+1)
hi = mp.mpf(k+2)
for _ in range(420):
q = (lo+hi)/2
z = 1/q
power, product = z, mp.mpf(1)
for j in range(12):
product *= 1-power
power *= power
A = (1/(1-z)-product)/2
digit_sum = k/(q-1) + (A if M % 2 else (1-z)*A)
if digit_sum > 1:
lo = q
else:
hi = q
return (lo+hi)/2
komornik_loreti(33)The defining digit sum is continuous and strictly decreasing for $q>1$: every digit is nonnegative and the first digit is positive. For $S_N(q)=\sum_{n=1}^N d_nq^{-n}$, the remainder is between $0$ and $Mq^{-N}/(q-1)$. Exact rational bisection endpoints are certified by $S_N(l)>1$ and $S_N(u)+Mu^{-N}/(u-1)<1$, using $512$-bit Arb arithmetic. The default computation uses $128$ to $1024$ digits of the sequence, a tail bound below $10^{-135}$, and a root-bracket width below $10^{-112}$. The source least-base theorem identifies these isolated roots; numerical monotonicity alone does not establish minimality among univoque bases.
A separate implementation uses $640$-bit MPFI arithmetic and twelve product factors with $z=1/q$, bounding the omitted product by $z^{4096}/(1-z^{4096})$. It certifies opposite signs at both endpoints of every stored decimal interval, and rejects shifted intervals. Known nonzero product-coefficient and digit-sum controls check the implementation; separately constructed substitution digits check the indexing and both parity prefixes. Full generator verification and executable evidence are attached. The displayed mpmath program is an illustrative approximation, distinct from the certified generator.