StandardA45IntNegativeZeroTest
Checks, in A Standard Definition of Elm?:basis Basics.negatebasis Basics.mulbasis Basics.modBybasis Basics.remainderBybasis Basics.roundbasis Basics.ceiling
Translated into Lean for the mechanisation of the book: see its Lean translation.
Int has one zero: no Int operation gives a negative zero. A Standard Definition of Elm?, ruling A45: Int has one zero, so `toFloat` of any Int zero is `+0` and `1 / toFloat` of it is `+Infinity`. <https://elm-test-suite.netlify.app/standard/basis/Basics/negate> In Elm 0.19.1 `negate 0`, `0 * -1`, `modBy 4 -4`, `remainderBy 4 -4`, `round -0.4` and `ceiling -0.5` give a negative zero typed as an `Int`; equality does not see it, but `1 / toFloat` of it is `-Infinity`.
Results
elm-0.19.1
failran in 45 msMissing pattern: negate 0: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. negate 0: False 0 * -1: False modBy 4 -4: False remainderBy 4 -4: False round -0.4: False ceiling -0.5: False
elm-0.19.2
failran in 39 msMissing pattern: negate 0: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. negate 0: False 0 * -1: False modBy 4 -4: False remainderBy 4 -4: False round -0.4: False ceiling -0.5: False
elm-0.19.3
failran in 38 msMissing pattern: negate 0: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. negate 0: False 0 * -1: False modBy 4 -4: False remainderBy 4 -4: False round -0.4: False ceiling -0.5: False
lamdera-1.5.0
failran in 49 msMissing pattern: negate 0: True --- output --- negate 0: False 0 * -1: False modBy 4 -4: False remainderBy 4 -4: False round -0.4: False ceiling -0.5: False
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StandardA45IntNegativeZeroTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StandardA45IntNegativeZeroTest exposing (main)
{-| Int has one zero: no Int operation gives a negative zero.
A Standard Definition of Elm?, ruling A45: Int has one zero, so `toFloat` of any Int zero is `+0`
and `1 / toFloat` of it is `+Infinity`. <https://elm-test-suite.netlify.app/standard/basis/Basics/negate>
In Elm 0.19.1 `negate 0`, `0 * -1`, `modBy 4 -4`, `remainderBy 4 -4`, `round -0.4` and
`ceiling -0.5` give a negative zero typed as an `Int`; equality does not see it, but `1 /
toFloat` of it is `-Infinity`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, b:Basics.negate, b:Basics.mul, b:Basics.modBy, b:Basics.remainderBy, b:Basics.round, b:Basics.ceiling
-- CHECK: negate 0: True
-- CHECK: 0 * -1: True
-- CHECK: modBy 4 -4: True
-- CHECK: remainderBy 4 -4: True
-- CHECK: round -0.4: True
-- CHECK: ceiling -0.5: True
import Html
positiveZero : Int -> Bool
positiveZero n =
n == 0 && 1 / toFloat n > 0
main =
let
_ =
Debug.log "negate 0" (positiveZero (negate 0))
_ =
Debug.log "0 * -1" (positiveZero (0 * -1))
_ =
Debug.log "modBy 4 -4" (positiveZero (modBy 4 -4))
_ =
Debug.log "remainderBy 4 -4" (positiveZero (remainderBy 4 -4))
_ =
Debug.log "round -0.4" (positiveZero (round -0.4))
_ =
Debug.log "ceiling -0.5" (positiveZero (ceiling -0.5))
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_StandardA45IntNegativeZeroTest, 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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
negate 0 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
0 * -1 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
modBy 4 -4 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
remainderBy 4 -4 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
round -0.4 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
ceiling -0.5 | True | True | t_elm_core_StandardA45IntNegativeZeroTest |
/-- tests/elm-core/src/StandardA45IntNegativeZeroTest.elm -/
def g_elm_core_StandardA45IntNegativeZeroTest : Program := {
name := "StandardA45IntNegativeZeroTest", source := "tests/elm-core/src", native := true,
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", none⟩],
types := [],
aliases := [],
defs := [
.fn "positiveZero" [pv "n"] (andalso (bin "==" (v "n") (i 0)) (bin ">" (bin "/" (.atexp (.scon (.intF 1))) (ap (v "toFloat") [v "n"])) (.atexp (.scon (.intF 0))))),
.fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "negate 0", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (ap (v "negate") [i 0]))]))]), .pat pw (ap (qv "Debug" "log") [str "0 * -1", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (bin "*" (i 0) (.atexp (neg (A (i 1))))))]))]), .pat pw (ap (qv "Debug" "log") [str "modBy 4 -4", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (ap (v "modBy") [i 4, .atexp (neg (A (i 4)))]))]))]), .pat pw (ap (qv "Debug" "log") [str "remainderBy 4 -4", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (ap (v "remainderBy") [i 4, .atexp (neg (A (i 4)))]))]))]), .pat pw (ap (qv "Debug" "log") [str "round -0.4", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (ap (v "round") [.atexp (neg (.scon (.float 4 (-1))))]))]))]), .pat pw (ap (qv "Debug" "log") [str "ceiling -0.5", .atexp (.paren (ap (v "positiveZero") [.atexp (.paren (ap (v "ceiling") [.atexp (neg (.scon (.float 5 (-1))))]))]))])] (ap (qv "Html" "text") [str "done"])) ],
checks := [
chk .check "negate 0: True" .data,
chk .check "0 * -1: True" .data,
chk .check "modBy 4 -4: True" .data,
chk .check "remainderBy 4 -4: True" .data,
chk .check "round -0.4: True" .data,
chk .check "ceiling -0.5: 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_StandardA45IntNegativeZeroTest 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_StandardA45IntNegativeZeroTest 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_StandardA45IntNegativeZeroTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_StandardA45IntNegativeZeroTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality. One of these theorems is proved by native_decide ([native]).