Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Primitive-Recursive Signed Integer Arithmetic

Definition
Monodromy_IntegerPrimrec

by Xiaoyang Liu · Nov 5, 2026 · Mathlib 0df444a (Lean v4.33.1)

computabilitycovering-spacesmonodromy-computation

Uses the canonical natural-number encoding of signed integers to define and prove effective integer case analysis, arithmetic, order tests, scaling, and positive-base Euclidean quotients and remainders. These functions provide the arithmetic interface for the integer interpretation of native programs.

Definition code
-- Generated by Lean-fact skeleton subtraction; original source is frozen in imports/monodromy/source.
module
public import Mathlib.Computability.Primrec.Basic
public import Mathlib.Data.Int.ModEq
public import Mathlib.Tactic.Ring

@[expose] public section


/-!
# Effective integer primitives

The canonical signed encoding reduces integer arithmetic and positive-base
Euclidean division to primitive recursive operations on natural numbers.
-/

@[expose] public section

namespace Monodromy.IntegerPrimrec

def split (value : ℤ) : ℕ ⊕ ℕ := Equiv.intEquivNatSumNat value

def join (value : ℕ ⊕ ℕ) : ℤ := Sum.elim Int.ofNat Int.negSucc value











def difference (first second : ℕ) : ℤ :=
  if second ≤ first then Int.ofNat (first - second) else Int.negSucc (second - first - 1)

















end Monodromy.IntegerPrimrec
Source
Authoritative local working-tree snapshot SHA-256 e03ce2d08e07ee663140bec213fb21e995f44153a3c556c908fcf1c8d6fefe6c; repository https://github.com/ERHUTUZI123/monodromy. The remote Git base is incomplete and is not asserted to contain these declarations. src/Monodromy/IntegerPrimrec.lean (file SHA-256 6dc5f3bfec05f346981b78d5c7c30dc668be696591a8e9fbc305500db06e6ae3): Monodromy.IntegerPrimrec.split at L18-L18 [UTF-8 373:443]. Monodromy.IntegerPrimrec.join at L20-L20 [UTF-8 445:521]. Monodromy.IntegerPrimrec.difference at L40-L41 [UTF-8 1457:1593].
Read-back

What the Lean code literally says, in plain math · OpenAI Codex (independent agent)

For every integer zzz, split sends a nonnegative integer nnn to the left copy of nnn in N⊔N\mathbb N\sqcup\mathbb NN⊔N, and sends −(n+1)-(n+1)−(n+1) to the right copy of nnn; join sends those two cases back to nnn and −(n+1)-(n+1)−(n+1) respectively. For all naturals a,ba,ba,b, difference is the integer whose defining formula is the nonnegative constructor applied to the natural subtraction a−ba-ba−b if b≤ab\le ab≤a, and the negative-successor constructor applied to b−a−1b-a-1b−a−1 otherwise; thus the latter case represents −((b−a−1)+1)-((b-a-1)+1)−((b−a−1)+1). The subtractions inside these expressions are natural-number truncated subtraction, and the branch hypotheses ensure the indicated cases include a=ba=ba=b, a=0a=0a=0 and b=0b=0b=0 with their literal values. These are total definitions and contain no partiality or asserted running-time bound.

Human review
  • Endorsed by marwahaha · Nov 6, 2026

  • Endorsed by Xiaoyang Liu · Nov 6, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me