ContainerEqualityCustomFloatTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:basis Basics.eq
Translated into Lean for the mechanisation of the book: see its Lean translation.
Checks `==` on custom-type values whose fields are `Float`, including NaN,
infinities and negative zero.
A constructor's fields are compared with `Float` equality, so `NaN` is unequal
even to itself, `-0.0` equals `0.0`, and the two infinities differ from each
other. Custom types are not `comparable`, so only `==` is used.
- `Point` (two fields): equal, differing in each field, `0.0` against `-0.0`
(True), NaN in either field (False), positive infinity on both sides (True)
and opposite infinities (False).
- `Triple` (three fields): equal, differing in the middle, zeros of mixed
sign (True), NaN in the middle (False), and infinities with mixed-sign zeros
(True).
- Two different constructors of `Shape` with the same payload (False).Results
elm-0.19.1
passran in 58 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. ptEqual: True ptXDiff: False ptYDiff: False ptNegZero: True ptNaNFirst: False ptNaNSecond: False ptPosInf: True ptInfSign: False triEqual: True triMidDiff: False triAllNegZero: True triNaNMid: False triMixedInf: True mixedCtorDiff: False
elm-0.19.2
passran in 52 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. ptEqual: True ptXDiff: False ptYDiff: False ptNegZero: True ptNaNFirst: False ptNaNSecond: False ptPosInf: True ptInfSign: False triEqual: True triMidDiff: False triAllNegZero: True triNaNMid: False triMixedInf: True mixedCtorDiff: False
elm-0.19.3
passran in 68 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. ptEqual: True ptXDiff: False ptYDiff: False ptNegZero: True ptNaNFirst: False ptNaNSecond: False ptPosInf: True ptInfSign: False triEqual: True triMidDiff: False triAllNegZero: True triNaNMid: False triMixedInf: True mixedCtorDiff: False
lamdera-1.5.0
passran in 63 msOutput
ptEqual: True ptXDiff: False ptYDiff: False ptNegZero: True ptNaNFirst: False ptNaNSecond: False ptPosInf: True ptInfSign: False triEqual: True triMidDiff: False triAllNegZero: True triNaNMid: False triMixedInf: True mixedCtorDiff: False
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/ContainerEqualityCustomFloatTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ContainerEqualityCustomFloatTest exposing (main)
{-| Checks `==` on custom-type values whose fields are `Float`, including NaN,
infinities and negative zero.
A constructor's fields are compared with `Float` equality, so `NaN` is unequal
even to itself, `-0.0` equals `0.0`, and the two infinities differ from each
other. Custom types are not `comparable`, so only `==` is used.
- `Point` (two fields): equal, differing in each field, `0.0` against `-0.0`
(True), NaN in either field (False), positive infinity on both sides (True)
and opposite infinities (False).
- `Triple` (three fields): equal, differing in the middle, zeros of mixed
sign (True), NaN in the middle (False), and infinities with mixed-sign zeros
(True).
- Two different constructors of `Shape` with the same payload (False).
-}
-- TAGS: elm-spec, b:Basics.eq
-- CHECK: ptEqual: True
-- CHECK: ptXDiff: False
-- CHECK: ptYDiff: False
-- CHECK: ptNegZero: True
-- CHECK: ptNaNFirst: False
-- CHECK: ptNaNSecond: False
-- CHECK: ptPosInf: True
-- CHECK: ptInfSign: False
-- CHECK: triEqual: True
-- CHECK: triMidDiff: False
-- CHECK: triAllNegZero: True
-- CHECK: triNaNMid: False
-- CHECK: triMixedInf: True
-- CHECK: mixedCtorDiff: False
import Html exposing (text)
type Point
= Point Float Float
type Triple
= Triple Float Float Float
type Shape
= Circle Float
| Square Float
main =
let
nan = 0.0 / 0.0
posInf = 1.0 / 0.0
negInf = -1.0 / 0.0
-- Two-field custom type -----------------------------------------
_ = Debug.log "ptEqual" (Point 1.5 2.5 == Point 1.5 2.5)
_ = Debug.log "ptXDiff" (Point 1.5 2.5 == Point 2.5 2.5)
_ = Debug.log "ptYDiff" (Point 1.5 2.5 == Point 1.5 3.5)
_ = Debug.log "ptNegZero" (Point 0.0 1.0 == Point -0.0 1.0)
_ = Debug.log "ptNaNFirst" (Point nan 1.0 == Point nan 1.0)
_ = Debug.log "ptNaNSecond" (Point 1.0 nan == Point 1.0 nan)
_ = Debug.log "ptPosInf" (Point posInf 1.0 == Point posInf 1.0)
_ = Debug.log "ptInfSign" (Point posInf 1.0 == Point negInf 1.0)
-- Three-field custom type ---------------------------------------
_ = Debug.log "triEqual" (Triple 1.0 2.0 3.0 == Triple 1.0 2.0 3.0)
_ = Debug.log "triMidDiff" (Triple 1.0 2.0 3.0 == Triple 1.0 9.0 3.0)
_ = Debug.log "triAllNegZero" (Triple 0.0 -0.0 0.0 == Triple -0.0 0.0 -0.0)
_ = Debug.log "triNaNMid" (Triple 1.0 nan 3.0 == Triple 1.0 nan 3.0)
_ = Debug.log "triMixedInf" (Triple posInf negInf 0.0 == Triple posInf negInf -0.0)
-- Different constructors should never be equal even with same payload
_ = Debug.log "mixedCtorDiff" (Circle 1.0 == Square 1.0)
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_ContainerEqualityCustomFloatTest, 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 |
|---|---|---|---|
ptEqual | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
ptXDiff | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
ptYDiff | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
ptNegZero | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
ptNaNFirst | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
ptNaNSecond | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
ptPosInf | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
ptInfSign | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
triEqual | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
triMidDiff | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
triAllNegZero | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
triNaNMid | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
triMixedInf | True | True | t_elm_core_ContainerEqualityCustomFloatTest |
mixedCtorDiff | False | False | t_elm_core_ContainerEqualityCustomFloatTest |
/-- tests/elm-core/src/ContainerEqualityCustomFloatTest.elm -/
def g_elm_core_ContainerEqualityCustomFloatTest : Program := {
name := "ContainerEqualityCustomFloatTest", source := "tests/elm-core/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [("Point", [("Point", 2)]), ("Shape", [("Circle", 1), ("Square", 1)]), ("Triple", [("Triple", 3)])],
aliases := [],
defs := [
.fn "main" [] (letDefs [.fn "nan" [] (bin "/" (.atexp (.scon (.float 0 (-1)))) (.atexp (.scon (.float 0 (-1))))), .fn "posInf" [] (bin "/" (.atexp (.scon (.float 10 (-1)))) (.atexp (.scon (.float 0 (-1))))), .fn "negInf" [] (bin "/" (.atexp (neg (.scon (.float 10 (-1))))) (.atexp (.scon (.float 0 (-1))))), .pat pw (ap (qv "Debug" "log") [str "ptEqual", .atexp (.paren (bin "==" (ap (c "Point") [.atexp (.scon (.float 15 (-1))), .atexp (.scon (.float 25 (-1)))]) (ap (c "Point") [.atexp (.scon (.float 15 (-1))), .atexp (.scon (.float 25 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptXDiff", .atexp (.paren (bin "==" (ap (c "Point") [.atexp (.scon (.float 15 (-1))), .atexp (.scon (.float 25 (-1)))]) (ap (c "Point") [.atexp (.scon (.float 25 (-1))), .atexp (.scon (.float 25 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptYDiff", .atexp (.paren (bin "==" (ap (c "Point") [.atexp (.scon (.float 15 (-1))), .atexp (.scon (.float 25 (-1)))]) (ap (c "Point") [.atexp (.scon (.float 15 (-1))), .atexp (.scon (.float 35 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptNegZero", .atexp (.paren (bin "==" (ap (c "Point") [.atexp (.scon (.float 0 (-1))), .atexp (.scon (.float 10 (-1)))]) (ap (c "Point") [.atexp (neg (.scon (.float 0 (-1)))), .atexp (.scon (.float 10 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptNaNFirst", .atexp (.paren (bin "==" (ap (c "Point") [v "nan", .atexp (.scon (.float 10 (-1)))]) (ap (c "Point") [v "nan", .atexp (.scon (.float 10 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptNaNSecond", .atexp (.paren (bin "==" (ap (c "Point") [.atexp (.scon (.float 10 (-1))), v "nan"]) (ap (c "Point") [.atexp (.scon (.float 10 (-1))), v "nan"])))]), .pat pw (ap (qv "Debug" "log") [str "ptPosInf", .atexp (.paren (bin "==" (ap (c "Point") [v "posInf", .atexp (.scon (.float 10 (-1)))]) (ap (c "Point") [v "posInf", .atexp (.scon (.float 10 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "ptInfSign", .atexp (.paren (bin "==" (ap (c "Point") [v "posInf", .atexp (.scon (.float 10 (-1)))]) (ap (c "Point") [v "negInf", .atexp (.scon (.float 10 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "triEqual", .atexp (.paren (bin "==" (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), .atexp (.scon (.float 20 (-1))), .atexp (.scon (.float 30 (-1)))]) (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), .atexp (.scon (.float 20 (-1))), .atexp (.scon (.float 30 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "triMidDiff", .atexp (.paren (bin "==" (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), .atexp (.scon (.float 20 (-1))), .atexp (.scon (.float 30 (-1)))]) (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), .atexp (.scon (.float 90 (-1))), .atexp (.scon (.float 30 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "triAllNegZero", .atexp (.paren (bin "==" (ap (c "Triple") [.atexp (.scon (.float 0 (-1))), .atexp (neg (.scon (.float 0 (-1)))), .atexp (.scon (.float 0 (-1)))]) (ap (c "Triple") [.atexp (neg (.scon (.float 0 (-1)))), .atexp (.scon (.float 0 (-1))), .atexp (neg (.scon (.float 0 (-1))))])))]), .pat pw (ap (qv "Debug" "log") [str "triNaNMid", .atexp (.paren (bin "==" (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), v "nan", .atexp (.scon (.float 30 (-1)))]) (ap (c "Triple") [.atexp (.scon (.float 10 (-1))), v "nan", .atexp (.scon (.float 30 (-1)))])))]), .pat pw (ap (qv "Debug" "log") [str "triMixedInf", .atexp (.paren (bin "==" (ap (c "Triple") [v "posInf", v "negInf", .atexp (.scon (.float 0 (-1)))]) (ap (c "Triple") [v "posInf", v "negInf", .atexp (neg (.scon (.float 0 (-1))))])))]), .pat pw (ap (qv "Debug" "log") [str "mixedCtorDiff", .atexp (.paren (bin "==" (ap (c "Circle") [.atexp (.scon (.float 10 (-1)))]) (ap (c "Square") [.atexp (.scon (.float 10 (-1)))])))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "ptEqual: True" .data,
chk .check "ptXDiff: False" .data,
chk .check "ptYDiff: False" .data,
chk .check "ptNegZero: True" .data,
chk .check "ptNaNFirst: False" .data,
chk .check "ptNaNSecond: False" .data,
chk .check "ptPosInf: True" .data,
chk .check "ptInfSign: False" .data,
chk .check "triEqual: True" .data,
chk .check "triMidDiff: False" .data,
chk .check "triAllNegZero: True" .data,
chk .check "triNaNMid: False" .data,
chk .check "triMixedInf: True" .data,
chk .check "mixedCtorDiff: False" .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_ContainerEqualityCustomFloatTest 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_ContainerEqualityCustomFloatTest 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_ContainerEqualityCustomFloatTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_ContainerEqualityCustomFloatTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.