AFTD Auto-Formalizing Theoretical Domains

rat_self_delimiting_code

def

The binary word encoding a rational number q: the bit true if q < 0 and false otherwise, followed by the self-delimiting code nat_self_delimiting_code of the absolute value of the numerator of q in lowest terms, followed by the self-delimiting code of the (positive) denominator of q in lowest terms.

Statement

def rat_self_delimiting_code (q : ℚ) : List Bool
Source
Input/output encoding, helper for the polynomial-time statement of OP-2019 (arXiv:2611.24611 (Inapproximability of Euclidean Steiner Tree), Section 6.1, after Corollary 20 (open question: is planar Euclidean Cable Steiner Tree APX-hard or does it admit a PTAS?)); a standard prefix-free binary code of rationals built on nat_self_delimiting_code.
Verified
23 Nov 2026
Axioms
none listed
Built on 1
  • nat_self_delimiting_codeThe self-delimiting binary code of a natural number m: each bit b of the binary expansion of m (least significant bit first, as in…
Used by 4
  • rat_self_delimiting_code_zeroThe code of the rational 0 is false, false, true, true, false.
  • ks2_instance_codeWith explicit arguments α : ℚ, d : ℕ and vs : List (ℚ × List (ℚ × ℚ)), in this order: the Bool word (List Bool) that is the concatenation…
  • rat_self_delimiting_code_neg_halfThe code of -1/2: sign true, numerator 1 as true,true,false, denominator 2 as true,false,true,true,false.
  • rat_segment_list_codeThe binary word encoding a list S of plane segments, each given by two endpoints ((x1, y1), (x2, y2)) with rational coordinates: the…

Lean source view module on GitHub

/-- The self-delimiting binary code of a rational number: a sign bit, then the absolute value of the numerator and the denominator (lowest terms) each in `nat_self_delimiting_code`. -/
def rat_self_delimiting_code (q : ℚ) : List Bool :=
  [decide (q < 0)] ++ nat_self_delimiting_code q.num.natAbs ++ nat_self_delimiting_code q.den
See it in the graphDiscuss this resultChallenge it