Elm Exactly
Results / elm-core /

StandardA48MinMaxNanTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:basis Basics.minbasis Basics.max

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail
Float `min` and `max` are IEEE 754-2019 minimum and maximum, whatever the order of the arguments.

A Standard Definition of Elm?, ruling A48: at floats, `min` and `max` of a NaN are NaN, and `-0`
is below `+0`. <https://elm-test-suite.netlify.app/standard/basis/Basics/min>

Elm 0.19.1 uses `if lt x y then x else y`, so the answer depends on the order of the arguments:
`min nan 1` is `1` and `min 1 nan` is NaN, and `min 0 -0` is `-0` but `min -0 0` is `0`.

Results

elm-0.19.1

failran in 46 ms
Missing pattern: min nan 1 is NaN: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
min nan 1 is NaN: False
min 1 nan is NaN: True
max nan 1 is NaN: True
max 1 nan is NaN: False
min 0 -0 is -0: True
min -0 0 is -0: False
max 0 -0 is +0: False
max -0 0 is +0: True

elm-0.19.2

failran in 69 ms
Missing pattern: min nan 1 is NaN: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
min nan 1 is NaN: False
min 1 nan is NaN: True
max nan 1 is NaN: True
max 1 nan is NaN: False
min 0 -0 is -0: True
min -0 0 is -0: False
max 0 -0 is +0: False
max -0 0 is +0: True

elm-0.19.3

failran in 38 ms
Missing pattern: min nan 1 is NaN: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
min nan 1 is NaN: False
min 1 nan is NaN: True
max nan 1 is NaN: True
max 1 nan is NaN: False
min 0 -0 is -0: True
min -0 0 is -0: False
max 0 -0 is +0: False
max -0 0 is +0: True

lamdera-1.5.0

failran in 63 ms
Missing pattern: min nan 1 is NaN: True
--- output ---
min nan 1 is NaN: False
min 1 nan is NaN: True
max nan 1 is NaN: True
max 1 nan is NaN: False
min 0 -0 is -0: True
min -0 0 is -0: False
max 0 -0 is +0: False
max -0 0 is +0: True

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-core/StandardA48MinMaxNanTest] in its title.

Source

The -- CHECK: lines give the expected output.

module StandardA48MinMaxNanTest exposing (main)
{-| Float `min` and `max` are IEEE 754-2019 minimum and maximum, whatever the order of the arguments.
A Standard Definition of Elm?, ruling A48: at floats, `min` and `max` of a NaN are NaN, and `-0`
is below `+0`. <https://elm-test-suite.netlify.app/standard/basis/Basics/min>
Elm 0.19.1 uses `if lt x y then x else y`, so the answer depends on the order of the arguments:
`min nan 1` is `1` and `min 1 nan` is NaN, and `min 0 -0` is `-0` but `min -0 0` is `0`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, b:Basics.min, b:Basics.max
-- CHECK: min nan 1 is NaN: True
-- CHECK: min 1 nan is NaN: True
-- CHECK: max nan 1 is NaN: True
-- CHECK: max 1 nan is NaN: True
-- CHECK: min 0 -0 is -0: True
-- CHECK: min -0 0 is -0: True
-- CHECK: max 0 -0 is +0: True
-- CHECK: max -0 0 is +0: True
import Html
nan : Float
nan =
0 / 0
zero : Float
zero =
0
negativeZero : Float
negativeZero =
-zero
main =
let
_ =
Debug.log "min nan 1 is NaN" (isNaN (min nan 1))
_ =
Debug.log "min 1 nan is NaN" (isNaN (min 1 nan))
_ =
Debug.log "max nan 1 is NaN" (isNaN (max nan 1))
_ =
Debug.log "max 1 nan is NaN" (isNaN (max 1 nan))
_ =
Debug.log "min 0 -0 is -0" (1 / min zero negativeZero < 0)
_ =
Debug.log "min -0 0 is -0" (1 / min negativeZero zero < 0)
_ =
Debug.log "max 0 -0 is +0" (1 / max zero negativeZero > 0)
_ =
Debug.log "max -0 0 is +0" (1 / max negativeZero zero > 0)
in
Html.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_StandardA48MinMaxNanTest, in StandardElmMech/Generated/ElmCore_StandardA42.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.

CheckExpected (CHECK)Lean evaluatorProved by
min nan 1 is NaNTrueTruet_elm_core_StandardA48MinMaxNanTest
min 1 nan is NaNTrueTruet_elm_core_StandardA48MinMaxNanTest
max nan 1 is NaNTrueTruet_elm_core_StandardA48MinMaxNanTest
max 1 nan is NaNTrueTruet_elm_core_StandardA48MinMaxNanTest
min 0 -0 is -0TrueTruet_elm_core_StandardA48MinMaxNanTest
min -0 0 is -0TrueTruet_elm_core_StandardA48MinMaxNanTest
max 0 -0 is +0TrueTruet_elm_core_StandardA48MinMaxNanTest
max -0 0 is +0TrueTruet_elm_core_StandardA48MinMaxNanTest
/-- tests/elm-core/src/StandardA48MinMaxNanTest.elm -/
def g_elm_core_StandardA48MinMaxNanTest : Program := {
  name := "StandardA48MinMaxNanTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", none⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "nan" [] (bin "/" (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 0)))),
    .fn "zero" [] (.atexp (.scon (.intF 0))),
    .fn "negativeZero" [] (.atexp (neg (A (v "zero")))),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "min nan 1 is NaN", .atexp (.paren (ap (v "isNaN") [.atexp (.paren (ap (v "min") [v "nan", .atexp (.scon (.intF 1))]))]))]), .pat pw (ap (qv "Debug" "log") [str "min 1 nan is NaN", .atexp (.paren (ap (v "isNaN") [.atexp (.paren (ap (v "min") [.atexp (.scon (.intF 1)), v "nan"]))]))]), .pat pw (ap (qv "Debug" "log") [str "max nan 1 is NaN", .atexp (.paren (ap (v "isNaN") [.atexp (.paren (ap (v "max") [v "nan", .atexp (.scon (.intF 1))]))]))]), .pat pw (ap (qv "Debug" "log") [str "max 1 nan is NaN", .atexp (.paren (ap (v "isNaN") [.atexp (.paren (ap (v "max") [.atexp (.scon (.intF 1)), v "nan"]))]))]), .pat pw (ap (qv "Debug" "log") [str "min 0 -0 is -0", .atexp (.paren (bin "<" (bin "/" (.atexp (.scon (.intF 1))) (ap (v "min") [v "zero", v "negativeZero"])) (.atexp (.scon (.intF 0)))))]), .pat pw (ap (qv "Debug" "log") [str "min -0 0 is -0", .atexp (.paren (bin "<" (bin "/" (.atexp (.scon (.intF 1))) (ap (v "min") [v "negativeZero", v "zero"])) (.atexp (.scon (.intF 0)))))]), .pat pw (ap (qv "Debug" "log") [str "max 0 -0 is +0", .atexp (.paren (bin ">" (bin "/" (.atexp (.scon (.intF 1))) (ap (v "max") [v "zero", v "negativeZero"])) (.atexp (.scon (.intF 0)))))]), .pat pw (ap (qv "Debug" "log") [str "max -0 0 is +0", .atexp (.paren (bin ">" (bin "/" (.atexp (.scon (.intF 1))) (ap (v "max") [v "negativeZero", v "zero"])) (.atexp (.scon (.intF 0)))))])] (ap (qv "Html" "text") [str "done"])) ],
  checks := [
    chk .check "min nan 1 is NaN: True" .data,
    chk .check "min 1 nan is NaN: True" .data,
    chk .check "max nan 1 is NaN: True" .data,
    chk .check "max 1 nan is NaN: True" .data,
    chk .check "min 0 -0 is -0: True" .data,
    chk .check "min -0 0 is -0: True" .data,
    chk .check "max 0 -0 is +0: True" .data,
    chk .check "max -0 0 is +0: 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_StandardA48MinMaxNanTest 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_StandardA48MinMaxNanTest 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_StandardA48MinMaxNanTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_StandardA48MinMaxNanTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.