ContainerCompareIntTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:basis Basics.comparebasis Basics.ltbasis Basics.gebasis Basics.gt
Translated into Lean for the mechanisation of the book: see its Lean translation.
Ordering of pairs, triples and lists of `Int` with `compare` and the relational operators. The cases cover order decided at different positions, negative against positive values, a list that is a prefix of another being less, and the empty list being less than any other list. The number literals are not annotated, so where nothing else fixes their type A Standard Definition of Elm? takes them to be Float (ruling A27); Floats with these integral values order and compare as the Ints would, so the results are the same.
Results
elm-0.19.1
passran in 68 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. pairLt: LT pairGt: GT pairEq: EQ pairSecondDecides: LT pairNegFirst: LT pairNegSecond: GT tripleFirstDecides: LT tripleThirdDecides: GT tripleEq: EQ tripleNegMix: LT listLt: LT listShorterIsLess: LT listEq: EQ listEmptyIsLeast: LT listNegVsPos: LT pairLtOp: True pairGeOp: True tripleLtOp: True listGtOp: True
elm-0.19.2
passran in 57 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. pairLt: LT pairGt: GT pairEq: EQ pairSecondDecides: LT pairNegFirst: LT pairNegSecond: GT tripleFirstDecides: LT tripleThirdDecides: GT tripleEq: EQ tripleNegMix: LT listLt: LT listShorterIsLess: LT listEq: EQ listEmptyIsLeast: LT listNegVsPos: LT pairLtOp: True pairGeOp: True tripleLtOp: True listGtOp: True
elm-0.19.3
passran in 48 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. pairLt: LT pairGt: GT pairEq: EQ pairSecondDecides: LT pairNegFirst: LT pairNegSecond: GT tripleFirstDecides: LT tripleThirdDecides: GT tripleEq: EQ tripleNegMix: LT listLt: LT listShorterIsLess: LT listEq: EQ listEmptyIsLeast: LT listNegVsPos: LT pairLtOp: True pairGeOp: True tripleLtOp: True listGtOp: True
lamdera-1.5.0
passran in 103 msOutput
pairLt: LT pairGt: GT pairEq: EQ pairSecondDecides: LT pairNegFirst: LT pairNegSecond: GT tripleFirstDecides: LT tripleThirdDecides: GT tripleEq: EQ tripleNegMix: LT listLt: LT listShorterIsLess: LT listEq: EQ listEmptyIsLeast: LT listNegVsPos: LT pairLtOp: True pairGeOp: True tripleLtOp: True listGtOp: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/ContainerCompareIntTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ContainerCompareIntTest exposing (main)
{-| Ordering of pairs, triples and lists of `Int` with `compare` and the
relational operators.
The cases cover order decided at different positions, negative against positive
values, a list that is a prefix of another being less, and the empty list being
less than any other list.
The number literals are not annotated, so where nothing else fixes their type A Standard
Definition of Elm? takes them to be Float (ruling A27); Floats with these integral values order and
compare as the Ints would, so the results are the same.
-}
-- TAGS: elm-spec, b:Basics.compare, b:Basics.lt, b:Basics.ge, b:Basics.gt
-- CHECK: pairLt: LT
-- CHECK: pairGt: GT
-- CHECK: pairEq: EQ
-- CHECK: pairSecondDecides: LT
-- CHECK: pairNegFirst: LT
-- CHECK: pairNegSecond: GT
-- CHECK: tripleFirstDecides: LT
-- CHECK: tripleThirdDecides: GT
-- CHECK: tripleEq: EQ
-- CHECK: tripleNegMix: LT
-- CHECK: listLt: LT
-- CHECK: listShorterIsLess: LT
-- CHECK: listEq: EQ
-- CHECK: listEmptyIsLeast: LT
-- CHECK: listNegVsPos: LT
-- CHECK: pairLtOp: True
-- CHECK: pairGeOp: True
-- CHECK: tripleLtOp: True
-- CHECK: listGtOp: True
import Html exposing (text)
main =
let
emptyInts : List Int
emptyInts = []
-- Tuple2 ---------------------------------------------------------
_ = Debug.log "pairLt" (compare (1, 2) (1, 3))
_ = Debug.log "pairGt" (compare (2, 0) (1, 9))
_ = Debug.log "pairEq" (compare (5, 5) (5, 5))
_ = Debug.log "pairSecondDecides" (compare (1, 2) (1, 5))
_ = Debug.log "pairNegFirst" (compare (-5, 0) (1, 0))
_ = Debug.log "pairNegSecond" (compare (0, -1) (0, -5))
-- Tuple3 ---------------------------------------------------------
_ = Debug.log "tripleFirstDecides" (compare (1, 9, 9) (2, 0, 0))
_ = Debug.log "tripleThirdDecides" (compare (1, 2, 5) (1, 2, 4))
_ = Debug.log "tripleEq" (compare (1, 2, 3) (1, 2, 3))
_ = Debug.log "tripleNegMix" (compare (-1, 0, 1) (0, -1, 1))
-- List -----------------------------------------------------------
_ = Debug.log "listLt" (compare [1, 2] [1, 3])
_ = Debug.log "listShorterIsLess" (compare [1, 2] [1, 2, 0])
_ = Debug.log "listEq" (compare [1, 2, 3] [1, 2, 3])
_ = Debug.log "listEmptyIsLeast" (compare emptyInts [-2147483648])
_ = Debug.log "listNegVsPos" (compare [-1, 0] [1, 0])
-- Relational operators ------------------------------------------
_ = Debug.log "pairLtOp" ((1, 2) < (1, 3))
_ = Debug.log "pairGeOp" ((5, 5) >= (5, 5))
_ = Debug.log "tripleLtOp" ((1, 2, 3) < (1, 2, 4))
_ = Debug.log "listGtOp" ([2, 0] > [1, 9])
in
text "done"
Lean translation
This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_core_ContainerCompareIntTest, in StandardElmMech/Generated/ElmCore_CompareI.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
pairLt | LT | LT | t_elm_core_ContainerCompareIntTest |
pairGt | GT | GT | t_elm_core_ContainerCompareIntTest |
pairEq | EQ | EQ | t_elm_core_ContainerCompareIntTest |
pairSecondDecides | LT | LT | t_elm_core_ContainerCompareIntTest |
pairNegFirst | LT | LT | t_elm_core_ContainerCompareIntTest |
pairNegSecond | GT | GT | t_elm_core_ContainerCompareIntTest |
tripleFirstDecides | LT | LT | t_elm_core_ContainerCompareIntTest |
tripleThirdDecides | GT | GT | t_elm_core_ContainerCompareIntTest |
tripleEq | EQ | EQ | t_elm_core_ContainerCompareIntTest |
tripleNegMix | LT | LT | t_elm_core_ContainerCompareIntTest |
listLt | LT | LT | t_elm_core_ContainerCompareIntTest |
listShorterIsLess | LT | LT | t_elm_core_ContainerCompareIntTest |
listEq | EQ | EQ | t_elm_core_ContainerCompareIntTest |
listEmptyIsLeast | LT | LT | t_elm_core_ContainerCompareIntTest |
listNegVsPos | LT | LT | t_elm_core_ContainerCompareIntTest |
pairLtOp | True | True | t_elm_core_ContainerCompareIntTest |
pairGeOp | True | True | t_elm_core_ContainerCompareIntTest |
tripleLtOp | True | True | t_elm_core_ContainerCompareIntTest |
listGtOp | True | True | t_elm_core_ContainerCompareIntTest |
/-- tests/elm-core/src/ContainerCompareIntTest.elm -/
def g_elm_core_ContainerCompareIntTest : Program := {
name := "ContainerCompareIntTest", source := "tests/elm-core/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [],
defs := [
.fn "main" [] (letDefs [.fn "emptyInts" [] (listE []), .pat pw (ap (qv "Debug" "log") [str "pairLt", .atexp (.paren (ap (v "compare") [tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))), tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 3)))]))]), .pat pw (ap (qv "Debug" "log") [str "pairGt", .atexp (.paren (ap (v "compare") [tup2 (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 0))), tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 9)))]))]), .pat pw (ap (qv "Debug" "log") [str "pairEq", .atexp (.paren (ap (v "compare") [tup2 (.atexp (.scon (.intF 5))) (.atexp (.scon (.intF 5))), tup2 (.atexp (.scon (.intF 5))) (.atexp (.scon (.intF 5)))]))]), .pat pw (ap (qv "Debug" "log") [str "pairSecondDecides", .atexp (.paren (ap (v "compare") [tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))), tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 5)))]))]), .pat pw (ap (qv "Debug" "log") [str "pairNegFirst", .atexp (.paren (ap (v "compare") [tup2 (.atexp (neg (.scon (.intF 5)))) (.atexp (.scon (.intF 0))), tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 0)))]))]), .pat pw (ap (qv "Debug" "log") [str "pairNegSecond", .atexp (.paren (ap (v "compare") [tup2 (.atexp (.scon (.intF 0))) (.atexp (neg (.scon (.intF 1)))), tup2 (.atexp (.scon (.intF 0))) (.atexp (neg (.scon (.intF 5))))]))]), .pat pw (ap (qv "Debug" "log") [str "tripleFirstDecides", .atexp (.paren (ap (v "compare") [tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 9))) (.atexp (.scon (.intF 9))), tup3 (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 0)))]))]), .pat pw (ap (qv "Debug" "log") [str "tripleThirdDecides", .atexp (.paren (ap (v "compare") [tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 5))), tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 4)))]))]), .pat pw (ap (qv "Debug" "log") [str "tripleEq", .atexp (.paren (ap (v "compare") [tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3))), tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3)))]))]), .pat pw (ap (qv "Debug" "log") [str "tripleNegMix", .atexp (.paren (ap (v "compare") [tup3 (.atexp (neg (.scon (.intF 1)))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 1))), tup3 (.atexp (.scon (.intF 0))) (.atexp (neg (.scon (.intF 1)))) (.atexp (.scon (.intF 1)))]))]), .pat pw (ap (qv "Debug" "log") [str "listLt", .atexp (.paren (ap (v "compare") [listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))], listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 3))]]))]), .pat pw (ap (qv "Debug" "log") [str "listShorterIsLess", .atexp (.paren (ap (v "compare") [listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))], listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 0))]]))]), .pat pw (ap (qv "Debug" "log") [str "listEq", .atexp (.paren (ap (v "compare") [listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))], listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))]]))]), .pat pw (ap (qv "Debug" "log") [str "listEmptyIsLeast", .atexp (.paren (ap (v "compare") [v "emptyInts", listE [.atexp (neg (A (i 2147483648)))]]))]), .pat pw (ap (qv "Debug" "log") [str "listNegVsPos", .atexp (.paren (ap (v "compare") [listE [.atexp (neg (.scon (.intF 1))), .atexp (.scon (.intF 0))], listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 0))]]))]), .pat pw (ap (qv "Debug" "log") [str "pairLtOp", .atexp (.paren (bin "<" (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2)))) (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 3))))))]), .pat pw (ap (qv "Debug" "log") [str "pairGeOp", .atexp (.paren (bin ">=" (tup2 (.atexp (.scon (.intF 5))) (.atexp (.scon (.intF 5)))) (tup2 (.atexp (.scon (.intF 5))) (.atexp (.scon (.intF 5))))))]), .pat pw (ap (qv "Debug" "log") [str "tripleLtOp", .atexp (.paren (bin "<" (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3)))) (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 4))))))]), .pat pw (ap (qv "Debug" "log") [str "listGtOp", .atexp (.paren (bin ">" (listE [.atexp (.scon (.intF 2)), .atexp (.scon (.intF 0))]) (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 9))])))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "pairLt: LT" .data,
chk .check "pairGt: GT" .data,
chk .check "pairEq: EQ" .data,
chk .check "pairSecondDecides: LT" .data,
chk .check "pairNegFirst: LT" .data,
chk .check "pairNegSecond: GT" .data,
chk .check "tripleFirstDecides: LT" .data,
chk .check "tripleThirdDecides: GT" .data,
chk .check "tripleEq: EQ" .data,
chk .check "tripleNegMix: LT" .data,
chk .check "listLt: LT" .data,
chk .check "listShorterIsLess: LT" .data,
chk .check "listEq: EQ" .data,
chk .check "listEmptyIsLeast: LT" .data,
chk .check "listNegVsPos: LT" .data,
chk .check "pairLtOp: True" .data,
chk .check "pairGeOp: True" .data,
chk .check "tripleLtOp: True" .data,
chk .check "listGtOp: True" .data ] }Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.
Static semantics (Chapters 4, 5 and 9): legal_elm_core_ContainerCompareIntTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_core_ContainerCompareIntTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_core_ContainerCompareIntTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_ContainerCompareIntTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.