Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax489179.ThreeSUM

The integer 3-SUM problem

concepts/Lax489179/ThreeSUM.lean · lax-489179

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Definition

    The input is an array of nn distinct integers in [n3,n3][-n^3,n^3]. It is a yes-instance if three distinct entries sum to zero. The order of the array is arbitrary. The machine must output exactly one word: one for yes and zero for no. The raw input is the list of signed integer codes; lax-67 supplies its length through the input interface.

    The cubic universe is the standard integer 3-SUM convention. Arithmetic in the specification is over Z\mathbb Z, so the sum test is exact and has no modular overflow. Machine arithmetic remains bounded-word arithmetic as specified in WordProgramsWordPrograms.

    Lean source view on GitHub

    1import Lax489179.WordTime
    2import Lax489179.IntegerEncoding
    3
    4/-!
    5---
    6title: The integer 3-SUM problem
    7type: definition
    8---
    9The input is an array of nn distinct integers in [n3,n3][-n^3,n^3].
    10It is a yes-instance if three distinct entries sum to zero. The
    11order of the array is arbitrary. The machine must output exactly
    12one word: one for yes and zero for no. The raw input is the list of
    13signed integer codes; lax-67 supplies its length through the input interface.
    14
    15The cubic universe is the standard integer 3-SUM convention. Arithmetic
    16in the specification is over Z\mathbb Z, so the sum test is exact and
    17has no modular overflow. Machine arithmetic remains bounded-word
    18arithmetic as specified in `WordPrograms`.
    19-/
    20
    21namespace Lax489179.ThreeSUM
    22
    23def HasZeroSum (input : List ℤ) : Prop :=
    24 ∃ i j k : Fin input.length,
    25 i < j ∧ j < k ∧ input[i] + input[j] + input[k] = 0
    26
    27def Valid (input : List ℤ) : Prop :=
    28 input.Nodup ∧ ∀ z ∈ input, z.natAbs ≤ input.length ^ 3
    29
    30def Correct (input : List ℤ) (output : List ℕ) : Prop :=
    31 (output = [1] ∧ HasZeroSum input) ∨ (output = [0] ∧ ¬ HasZeroSum input)
    32
    33def problem : WordTime.Problem where
    34 Input := List ℤ
    35 size := List.length
    36 encode := List.map IntegerEncoding.encodeInt
    37 valid := Valid
    38 correct := Correct
    39
    40end Lax489179.ThreeSUM
    41

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…