StandardA42ModByZeroTest
Checks, in A Standard Definition of Elm?:basis Basics.modBy
Translated into Lean for the mechanisation of the book: see its Lean translation.
Issue: elm/core#1147, elm/core#1072
`modBy 0 x` is `0`. <https://github.com/elm/core/issues/1147> <https://github.com/elm/core/issues/1072> A Standard Definition of Elm?, ruling A42: `x // 0`, `modBy 0 x` and `remainderBy 0 x` are `0`, so that no evaluation ends in a run-time error. <https://elm-test-suite.netlify.app/standard/basis/Basics/modBy> Elm 0.19.1 stops the program: "Cannot perform mod 0. Division by zero error." (The result is compared with `1` after adding `1`: Elm 0.19.1 compiles `x == 0` as `!x`, elm/core #1115.)
Results
elm-0.19.1
failran in 51 msexit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:781
throw new Error('Cannot perform mod 0. Division by zero error.');
^
Error: Cannot perform mod 0. Division by zero error.
at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:781:10)
at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:812:5)
at A2 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:56:28)
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:4441:4
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:4447:2
at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA42ModByZeroTest.js:4448:128)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
Node.js v22.23.5
elm-0.19.2
failran in 83 msexit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:781
throw new Error('Cannot perform mod 0. Division by zero error.');
^
Error: Cannot perform mod 0. Division by zero error.
at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:781:10)
at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:812:5)
at A2 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:56:28)
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:4441:4
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:4447:2
at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA42ModByZeroTest.js:4448:128)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
Node.js v22.23.5
elm-0.19.3
failran in 66 msexit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:516
throw new Error('Cannot perform mod 0. Division by zero error.');
^
Error: Cannot perform mod 0. Division by zero error.
at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:516:10)
at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:812:5)
at A2 (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:56:28)
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:4441:4
at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:4447:2
at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA42ModByZeroTest.js:4448:128)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
Node.js v22.23.5
lamdera-1.5.0
failran in 81 msexit code 1, expected 0
--- output ---
/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:535
throw new Error('Cannot perform mod 0. Division by zero error.');
^
Error: Cannot perform mod 0. Division by zero error.
at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:535:10)
at Function.f (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:859:5)
at A2 (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:61:28)
at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:5511:4
at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:5517:2
at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA42ModByZeroTest.js:5520:3)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
Node.js v22.23.5
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StandardA42ModByZeroTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StandardA42ModByZeroTest exposing (main)
{-| `modBy 0 x` is `0`.
<https://github.com/elm/core/issues/1147>
<https://github.com/elm/core/issues/1072>
A Standard Definition of Elm?, ruling A42: `x // 0`, `modBy 0 x` and `remainderBy 0 x` are `0`,
so that no evaluation ends in a run-time error. <https://elm-test-suite.netlify.app/standard/basis/Basics/modBy>
Elm 0.19.1 stops the program: "Cannot perform mod 0. Division by zero error." (The result is
compared with `1` after adding `1`: Elm 0.19.1 compiles `x == 0` as `!x`, elm/core #1115.)
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, b:Basics.modBy
-- CHECK: modBy 0 7 + 1 == 1: True
-- CHECK: modBy 0 -7 + 1 == 1: True
import Html
main =
let
_ =
Debug.log "modBy 0 7 + 1 == 1" (modBy 0 7 + 1 == 1)
_ =
Debug.log "modBy 0 -7 + 1 == 1" (modBy 0 -7 + 1 == 1)
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_StandardA42ModByZeroTest, 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 |
|---|---|---|---|
modBy 0 7 + 1 == 1 | True | True | t_elm_core_StandardA42ModByZeroTest |
modBy 0 -7 + 1 == 1 | True | True | t_elm_core_StandardA42ModByZeroTest |
/-- tests/elm-core/src/StandardA42ModByZeroTest.elm -/
def g_elm_core_StandardA42ModByZeroTest : Program := {
name := "StandardA42ModByZeroTest", source := "tests/elm-core/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", none⟩],
types := [],
aliases := [],
defs := [
.fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "modBy 0 7 + 1 == 1", .atexp (.paren (bin "==" (bin "+" (ap (v "modBy") [i 0, i 7]) (i 1)) (i 1)))]), .pat pw (ap (qv "Debug" "log") [str "modBy 0 -7 + 1 == 1", .atexp (.paren (bin "==" (bin "+" (ap (v "modBy") [i 0, .atexp (neg (A (i 7)))]) (i 1)) (i 1)))])] (ap (qv "Html" "text") [str "done"])) ],
checks := [
chk .check "modBy 0 7 + 1 == 1: True" .data,
chk .check "modBy 0 -7 + 1 == 1: 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_StandardA42ModByZeroTest 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_StandardA42ModByZeroTest 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_StandardA42ModByZeroTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_StandardA42ModByZeroTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.