lawspec 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
|
@@ -9,99 +9,100 @@ import example.abilities as payments
|
|
|
9
9
|
-- and goes on with `;`.
|
|
10
10
|
ability Log is
|
|
11
11
|
note :: Text -> Unit
|
|
12
|
-
end
|
|
12
|
+
end ability
|
|
13
13
|
|
|
14
14
|
-- A log that keeps what it is told.
|
|
15
15
|
handler keptLog for Log with state lines :: List Text start [] is
|
|
16
|
-
note message is ~lines := Cons message lines; unitValue end
|
|
17
|
-
end
|
|
16
|
+
operation note message is ~lines := Cons message lines; unitValue end operation
|
|
17
|
+
end handler
|
|
18
18
|
|
|
19
19
|
-- A store of one value, at any type. This unit uses it at two.
|
|
20
20
|
ability Store (a :: Type) is
|
|
21
21
|
load :: a
|
|
22
22
|
save :: a -> Unit
|
|
23
|
-
end
|
|
23
|
+
end ability
|
|
24
24
|
|
|
25
25
|
handler countStore for Store Int32 with state count :: Int32 start 0 is
|
|
26
|
-
load is count end
|
|
27
|
-
save value is ~count := value; unitValue end
|
|
28
|
-
end
|
|
26
|
+
operation load is count end operation
|
|
27
|
+
operation save value is ~count := value; unitValue end operation
|
|
28
|
+
end handler
|
|
29
29
|
|
|
30
30
|
handler nameStore for Store Text with state name :: Text start "" is
|
|
31
|
-
load is name end
|
|
32
|
-
save value is ~name := value; unitValue end
|
|
33
|
-
end
|
|
31
|
+
operation load is name end operation
|
|
32
|
+
operation save value is ~name := value; unitValue end operation
|
|
33
|
+
end handler
|
|
34
34
|
|
|
35
35
|
-- A meter whose readings are never negative: every handler owes that.
|
|
36
36
|
ability Meter is
|
|
37
37
|
reading :: (r :: Int32 where r >= 0)
|
|
38
|
-
end
|
|
38
|
+
end ability
|
|
39
39
|
|
|
40
40
|
handler fixedMeter for Meter is
|
|
41
|
-
reading is 7 end
|
|
42
|
-
end
|
|
41
|
+
operation reading is 7 end operation
|
|
42
|
+
end handler
|
|
43
43
|
|
|
44
44
|
-- A handler whose clauses use another ability: it notes each payment.
|
|
45
45
|
handler notingGateway for Gateway is
|
|
46
|
-
authorize cents is note "authorize"; Approved cents end
|
|
47
|
-
capture cents is note "capture"; Receipt cents end
|
|
48
|
-
fee is 0 end
|
|
49
|
-
end
|
|
46
|
+
operation authorize cents is note "authorize"; Approved cents end operation
|
|
47
|
+
operation capture cents is note "capture"; Receipt cents end operation
|
|
48
|
+
operation fee is 0 end operation
|
|
49
|
+
end handler
|
|
50
50
|
|
|
51
51
|
-- Effects run in order: `a; b` runs a, then b; `let x = e in body` runs e
|
|
52
52
|
-- once and names its value.
|
|
53
|
-
|
|
53
|
+
procedure buy (cents :: Int32) -> Bool uses Gateway, Log is
|
|
54
54
|
note "buying";
|
|
55
55
|
let approved = payments.checkout cents in
|
|
56
56
|
note "bought";
|
|
57
|
-
approved
|
|
58
|
-
end
|
|
57
|
+
approved end let
|
|
58
|
+
end procedure
|
|
59
59
|
|
|
60
60
|
-- handle ... with h end runs its body with h answering h's ability, so the
|
|
61
61
|
-- definition does not use that ability itself.
|
|
62
|
-
|
|
63
|
-
handle payments.checkout cents with fakeGateway end
|
|
64
|
-
end
|
|
62
|
+
function trial (cents :: Int32) -> Bool is
|
|
63
|
+
handle payments.checkout cents with fakeGateway end handle
|
|
64
|
+
end function
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
procedure remember (count :: Int32) -> Int32 uses Store Int32 is
|
|
67
67
|
save count; load
|
|
68
|
-
end
|
|
68
|
+
end procedure
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
procedure rename (name :: Text) -> Text uses Store Text is
|
|
71
71
|
save name; load
|
|
72
|
-
end
|
|
72
|
+
end procedure
|
|
73
73
|
|
|
74
74
|
-- A native adapter that may fail. Its native code raises the failure
|
|
75
75
|
-- through the runtime's Fail.
|
|
76
76
|
refund :: Int32 -> Int32 uses Gateway fails with payments.PaymentError
|
|
77
77
|
|
|
78
|
-
law
|
|
79
|
-
definition
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
law
|
|
85
|
-
definition
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
law
|
|
91
|
-
definition
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
law
|
|
95
|
-
definition
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
law
|
|
99
|
-
definition
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
law
|
|
103
|
-
definition
|
|
104
|
-
|
|
105
|
-
prelude.attempt (refund cents) = Left payments.TooLarge
|
|
106
|
-
end
|
|
107
|
-
end
|
|
78
|
+
law "|trial approves small amounts| is
|
|
79
|
+
definition :
|
|
80
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 10000) => trial cents = true end for all
|
|
81
|
+
end definition
|
|
82
|
+
end law
|
|
83
|
+
|
|
84
|
+
law "|buying with a noting gateway approves small amounts| using notingGateway, keptLog is
|
|
85
|
+
definition :
|
|
86
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 10000) => buy cents = true end for all
|
|
87
|
+
end definition
|
|
88
|
+
end law
|
|
89
|
+
|
|
90
|
+
law "|a stored count comes back| is
|
|
91
|
+
definition : for all (count :: Int32) => remember count = count end for all end definition
|
|
92
|
+
end law
|
|
93
|
+
|
|
94
|
+
law "|a stored name comes back| is
|
|
95
|
+
definition : for all (name :: Text) => rename name = name end for all end definition
|
|
96
|
+
end law
|
|
97
|
+
|
|
98
|
+
law "|a reading is small| using fixedMeter is
|
|
99
|
+
definition : reading <= 100 end definition
|
|
100
|
+
end law
|
|
101
|
+
|
|
102
|
+
law "|refunds of large amounts fail| is
|
|
103
|
+
definition :
|
|
104
|
+
for all (cents :: Int32 where cents > 100000) =>
|
|
105
|
+
prelude.attempt (refund cents) = Left payments.TooLarge end for all
|
|
106
|
+
end definition
|
|
107
|
+
end law
|
|
108
|
+
end unit
|
|
@@ -7,7 +7,7 @@ unit example.actors
|
|
|
7
7
|
-- from several callers at once. Runs also crash the actor between
|
|
8
8
|
-- messages: it restarts from its last state by reopen, and the model's state
|
|
9
9
|
-- follows modelReopen.
|
|
10
|
-
type Account is
|
|
10
|
+
type Account is a record{ balance :: Int64} end type
|
|
11
11
|
|
|
12
12
|
openAccount :: Unit -> Account
|
|
13
13
|
deposit :: Account -> UInt8 -> Pair Int64 Account
|
|
@@ -17,16 +17,16 @@ close :: Account -> Account
|
|
|
17
17
|
-- After a crash, the account reopens with the balance it had.
|
|
18
18
|
reopen :: Account -> Account
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function modelDeposit (amount :: UInt8) (n :: Int64 where n >= 0 && n <= 1000000) -> Pair Int64 Int64 is
|
|
21
21
|
Pair (n + amount) (n + amount)
|
|
22
|
-
end
|
|
22
|
+
end function
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
function modelWithdrawAll (n :: Int64) -> Pair Int64 Int64 is Pair n 0 end function
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
function modelBalance (n :: Int64) -> Pair Int64 Int64 is Pair n n end function
|
|
27
|
+
function modelClose (n :: Int64) -> Int64 is 0 end function
|
|
28
|
+
function modelReopen (n :: Int64) -> Int64 is n end function
|
|
29
|
+
function solvent (n :: Int64) -> Bool is n >= 0 end function
|
|
30
30
|
|
|
31
31
|
actor account :: Account by Int64 is
|
|
32
32
|
start openAccount by 0
|
|
@@ -36,15 +36,15 @@ actor account :: Account by Int64 is
|
|
|
36
36
|
on balance by modelBalance
|
|
37
37
|
on close by modelClose
|
|
38
38
|
invariant solvent
|
|
39
|
-
end
|
|
39
|
+
end actor
|
|
40
40
|
|
|
41
41
|
-- Implementation code uses the generated typed actor: depositTwice starts an
|
|
42
42
|
-- account and deposits from two callers at once.
|
|
43
43
|
depositTwice :: UInt8 -> Int64
|
|
44
44
|
|
|
45
|
-
law
|
|
46
|
-
definition
|
|
47
|
-
end
|
|
45
|
+
law "|two callers' deposits both land| is
|
|
46
|
+
definition : for all (x :: UInt8) => depositTwice x = 2 * x end for all end definition
|
|
47
|
+
end law
|
|
48
48
|
|
|
49
49
|
-- A supervisor starts its actors and restarts them after a crash: one for
|
|
50
50
|
-- one restarts only the actor that crashed. The account restarts from its
|
|
@@ -53,22 +53,22 @@ supervisor bank is
|
|
|
53
53
|
one for one
|
|
54
54
|
at most 3 restarts in 5s
|
|
55
55
|
permanent account
|
|
56
|
-
end
|
|
56
|
+
end supervisor
|
|
57
57
|
|
|
58
58
|
-- survivesCrash starts the bank, deposits, crashes the account, and reads
|
|
59
59
|
-- its balance through the same handle.
|
|
60
60
|
survivesCrash :: UInt8 -> Int64
|
|
61
61
|
|
|
62
|
-
law
|
|
63
|
-
definition
|
|
64
|
-
end
|
|
62
|
+
law "|a crashed account keeps its balance| is
|
|
63
|
+
definition : for all (x :: UInt8) => survivesCrash x = x end for all end definition
|
|
64
|
+
end law
|
|
65
65
|
|
|
66
66
|
-- A scenario runs the actor's messages from processes that talk over
|
|
67
67
|
-- channels. Some runs crash one process at a random point: a receive from a
|
|
68
68
|
-- process that failed runs its or else instead of waiting forever.
|
|
69
69
|
protocol Receipt is
|
|
70
70
|
send Int64
|
|
71
|
-
end
|
|
71
|
+
end protocol
|
|
72
72
|
|
|
73
73
|
scenario `a deposit's receipt, or the balance if the teller fails` in account is
|
|
74
74
|
channel receipt :: Receipt
|
|
@@ -78,10 +78,10 @@ scenario `a deposit's receipt, or the balance if the teller fails` in account is
|
|
|
78
78
|
with
|
|
79
79
|
receive receipt m or else
|
|
80
80
|
balance
|
|
81
|
-
end
|
|
81
|
+
end or else
|
|
82
82
|
expect m = 5
|
|
83
|
-
end
|
|
84
|
-
end
|
|
83
|
+
end par
|
|
84
|
+
end scenario
|
|
85
85
|
|
|
86
86
|
-- A mailbox has many senders and one receiver: two tellers report their
|
|
87
87
|
-- deposits to one auditor, who receives both reports.
|
|
@@ -96,5 +96,6 @@ scenario `two tellers report to one auditor` in account is
|
|
|
96
96
|
with
|
|
97
97
|
receive reports first
|
|
98
98
|
receive reports second
|
|
99
|
-
end
|
|
100
|
-
end
|
|
99
|
+
end par
|
|
100
|
+
end scenario
|
|
101
|
+
end unit
|
|
@@ -9,157 +9,157 @@ subtractValue :: Integer -> Integer -> Integer
|
|
|
9
9
|
divideLeft :: Integer -> Integer -> Integer
|
|
10
10
|
divideRight :: Integer -> Integer -> Integer
|
|
11
11
|
|
|
12
|
-
law
|
|
13
|
-
definition
|
|
14
|
-
|
|
15
|
-
end
|
|
12
|
+
law "|addition is commutative| is
|
|
13
|
+
definition :
|
|
14
|
+
apply law "|commutative| add
|
|
15
|
+
end definition
|
|
16
16
|
|
|
17
|
-
example
|
|
17
|
+
example "|3 plus 5 and 5 plus 3 both produce 8| :
|
|
18
18
|
x = 3
|
|
19
19
|
y = 5
|
|
20
20
|
expect add x y = 8
|
|
21
21
|
expect add y x = 8
|
|
22
|
-
end
|
|
22
|
+
end example
|
|
23
23
|
|
|
24
|
-
example
|
|
24
|
+
example "|addition exceeds the Int32 maximum without wrapping| :
|
|
25
25
|
x = 2147483647
|
|
26
26
|
y = 1
|
|
27
27
|
expect add x y = 2147483648
|
|
28
28
|
expect add y x = 2147483648
|
|
29
|
-
end
|
|
29
|
+
end example
|
|
30
30
|
|
|
31
|
-
example
|
|
31
|
+
example "|addition remains exact beyond machine and safe-number bounds| :
|
|
32
32
|
x = 18446744073709551615
|
|
33
33
|
y = 2
|
|
34
34
|
expect add x y = 18446744073709551617
|
|
35
35
|
expect add y x = 18446744073709551617
|
|
36
|
-
end
|
|
37
|
-
end
|
|
36
|
+
end example
|
|
37
|
+
end law
|
|
38
38
|
|
|
39
|
-
law
|
|
40
|
-
definition
|
|
41
|
-
|
|
42
|
-
end
|
|
39
|
+
law "|addition is associative| is
|
|
40
|
+
definition :
|
|
41
|
+
apply law "|associative| add
|
|
42
|
+
end definition
|
|
43
43
|
|
|
44
|
-
example
|
|
44
|
+
example "|both groupings of 3 plus 5 plus 7 produce 15| :
|
|
45
45
|
x = 3
|
|
46
46
|
y = 5
|
|
47
47
|
z = 7
|
|
48
48
|
expect add (add x y) z = 15
|
|
49
49
|
expect add x (add y z) = 15
|
|
50
|
-
end
|
|
51
|
-
end
|
|
50
|
+
end example
|
|
51
|
+
end law
|
|
52
52
|
|
|
53
|
-
law
|
|
54
|
-
definition
|
|
55
|
-
|
|
56
|
-
end
|
|
53
|
+
law "|zero is left identity for addition| is
|
|
54
|
+
definition :
|
|
55
|
+
apply law "|left identity| add 0
|
|
56
|
+
end definition
|
|
57
57
|
|
|
58
|
-
example
|
|
58
|
+
example "|adding zero on left preserves 3| :
|
|
59
59
|
x = 3
|
|
60
60
|
expect add 0 x = 3
|
|
61
|
-
end
|
|
62
|
-
end
|
|
61
|
+
end example
|
|
62
|
+
end law
|
|
63
63
|
|
|
64
|
-
law
|
|
65
|
-
definition
|
|
66
|
-
|
|
67
|
-
end
|
|
64
|
+
law "|zero is right identity for addition| is
|
|
65
|
+
definition :
|
|
66
|
+
apply law "|right identity| add 0
|
|
67
|
+
end definition
|
|
68
68
|
|
|
69
|
-
example
|
|
69
|
+
example "|adding zero on right preserves 3| :
|
|
70
70
|
x = 3
|
|
71
71
|
expect add x 0 = 3
|
|
72
|
-
end
|
|
73
|
-
end
|
|
72
|
+
end example
|
|
73
|
+
end law
|
|
74
74
|
|
|
75
|
-
law
|
|
76
|
-
definition
|
|
77
|
-
|
|
78
|
-
end
|
|
75
|
+
law "|zero is two-sided identity for addition| is
|
|
76
|
+
definition :
|
|
77
|
+
apply law "|identity| add 0
|
|
78
|
+
end definition
|
|
79
79
|
|
|
80
|
-
example
|
|
80
|
+
example "|adding zero on both sides preserves 3| :
|
|
81
81
|
x = 3
|
|
82
82
|
expect add 0 x = 3
|
|
83
83
|
expect add x 0 = 3
|
|
84
|
-
end
|
|
85
|
-
end
|
|
84
|
+
end example
|
|
85
|
+
end law
|
|
86
86
|
|
|
87
|
-
law
|
|
88
|
-
definition
|
|
89
|
-
|
|
90
|
-
end
|
|
87
|
+
law "|zero absorbs multiplication left| is
|
|
88
|
+
definition :
|
|
89
|
+
apply law "|left absorbing element| multiply 0
|
|
90
|
+
end definition
|
|
91
91
|
|
|
92
|
-
example
|
|
92
|
+
example "|zero on left of multiplication produces zero| :
|
|
93
93
|
x = 3
|
|
94
94
|
expect multiply 0 x = 0
|
|
95
|
-
end
|
|
96
|
-
end
|
|
95
|
+
end example
|
|
96
|
+
end law
|
|
97
97
|
|
|
98
|
-
law
|
|
99
|
-
definition
|
|
100
|
-
|
|
101
|
-
end
|
|
98
|
+
law "|zero absorbs multiplication right| is
|
|
99
|
+
definition :
|
|
100
|
+
apply law "|right absorbing element| multiply 0
|
|
101
|
+
end definition
|
|
102
102
|
|
|
103
|
-
example
|
|
103
|
+
example "|zero on right of multiplication produces zero| :
|
|
104
104
|
x = 3
|
|
105
105
|
expect multiply x 0 = 0
|
|
106
|
-
end
|
|
107
|
-
end
|
|
106
|
+
end example
|
|
107
|
+
end law
|
|
108
108
|
|
|
109
|
-
law
|
|
110
|
-
definition
|
|
111
|
-
|
|
112
|
-
end
|
|
109
|
+
law "|zero absorbs multiplication on both sides| is
|
|
110
|
+
definition :
|
|
111
|
+
apply law "|absorbing element| multiply 0
|
|
112
|
+
end definition
|
|
113
113
|
|
|
114
|
-
example
|
|
114
|
+
example "|zero on both sides of multiplication produces zero| :
|
|
115
115
|
x = 3
|
|
116
116
|
expect multiply 0 x = 0
|
|
117
117
|
expect multiply x 0 = 0
|
|
118
|
-
end
|
|
119
|
-
end
|
|
118
|
+
end example
|
|
119
|
+
end law
|
|
120
120
|
|
|
121
|
-
law
|
|
122
|
-
definition
|
|
123
|
-
|
|
124
|
-
end
|
|
121
|
+
law "|multiplication distributes over addition left| is
|
|
122
|
+
definition :
|
|
123
|
+
apply law "|left distributive| multiply add
|
|
124
|
+
end definition
|
|
125
125
|
|
|
126
|
-
example
|
|
126
|
+
example "|left distribution produces 36| :
|
|
127
127
|
x = 3
|
|
128
128
|
y = 5
|
|
129
129
|
z = 7
|
|
130
130
|
expect multiply x (add y z) = 36
|
|
131
131
|
expect add (multiply x y) (multiply x z) = 36
|
|
132
|
-
end
|
|
132
|
+
end example
|
|
133
133
|
|
|
134
|
-
example
|
|
134
|
+
example "|multiplication preserves products outside Int32| :
|
|
135
135
|
x = 2147483647
|
|
136
136
|
y = 2147483647
|
|
137
137
|
z = 1
|
|
138
138
|
expect multiply x y = 4611686014132420609
|
|
139
139
|
expect multiply x (add y z) = 4611686016279904256
|
|
140
|
-
end
|
|
141
|
-
end
|
|
140
|
+
end example
|
|
141
|
+
end law
|
|
142
142
|
|
|
143
|
-
law
|
|
144
|
-
definition
|
|
145
|
-
|
|
146
|
-
end
|
|
143
|
+
law "|multiplication distributes over addition right| is
|
|
144
|
+
definition :
|
|
145
|
+
apply law "|right distributive| multiply add
|
|
146
|
+
end definition
|
|
147
147
|
|
|
148
|
-
example
|
|
148
|
+
example "|right distribution produces 56| :
|
|
149
149
|
x = 3
|
|
150
150
|
y = 5
|
|
151
151
|
z = 7
|
|
152
152
|
expect multiply (add x y) z = 56
|
|
153
153
|
expect add (multiply x z) (multiply y z) = 56
|
|
154
|
-
end
|
|
155
|
-
end
|
|
154
|
+
end example
|
|
155
|
+
end law
|
|
156
156
|
|
|
157
|
-
law
|
|
158
|
-
definition
|
|
159
|
-
|
|
160
|
-
end
|
|
157
|
+
law "|multiplication distributes over addition on both sides| is
|
|
158
|
+
definition :
|
|
159
|
+
apply law "|distributive| multiply add
|
|
160
|
+
end definition
|
|
161
161
|
|
|
162
|
-
example
|
|
162
|
+
example "|left distribution produces 36; right distribution produces 56| :
|
|
163
163
|
x = 3
|
|
164
164
|
y = 5
|
|
165
165
|
z = 7
|
|
@@ -167,91 +167,91 @@ law `multiplication distributes over addition on both sides` is
|
|
|
167
167
|
expect add (multiply x y) (multiply x z) = 36
|
|
168
168
|
expect multiply (add x y) z = 56
|
|
169
169
|
expect add (multiply x z) (multiply y z) = 56
|
|
170
|
-
end
|
|
171
|
-
end
|
|
170
|
+
end example
|
|
171
|
+
end law
|
|
172
172
|
|
|
173
|
-
law
|
|
174
|
-
definition
|
|
175
|
-
|
|
176
|
-
end
|
|
173
|
+
law "|maximum is an idempotent operation| is
|
|
174
|
+
definition :
|
|
175
|
+
apply law "|idempotent operation| maximumValue
|
|
176
|
+
end definition
|
|
177
177
|
|
|
178
|
-
example
|
|
178
|
+
example "|the maximum of 3 and itself is 3| :
|
|
179
179
|
x = 3
|
|
180
180
|
expect maximumValue x x = 3
|
|
181
|
-
end
|
|
182
|
-
end
|
|
181
|
+
end example
|
|
182
|
+
end law
|
|
183
183
|
|
|
184
|
-
law
|
|
185
|
-
definition
|
|
186
|
-
|
|
187
|
-
end
|
|
184
|
+
law "|negation supplies left additive inverses| is
|
|
185
|
+
definition :
|
|
186
|
+
apply law "|left inverse element| add negateValue 0
|
|
187
|
+
end definition
|
|
188
188
|
|
|
189
|
-
example
|
|
189
|
+
example "|3 has inverse -3; the left inverse equation produces zero| :
|
|
190
190
|
x = 3
|
|
191
191
|
expect negateValue x = -3
|
|
192
192
|
expect add (negateValue x) x = 0
|
|
193
|
-
end
|
|
194
|
-
end
|
|
193
|
+
end example
|
|
194
|
+
end law
|
|
195
195
|
|
|
196
|
-
law
|
|
197
|
-
definition
|
|
198
|
-
|
|
199
|
-
end
|
|
196
|
+
law "|negation supplies right additive inverses| is
|
|
197
|
+
definition :
|
|
198
|
+
apply law "|right inverse element| add negateValue 0
|
|
199
|
+
end definition
|
|
200
200
|
|
|
201
|
-
example
|
|
201
|
+
example "|3 has inverse -3; the right inverse equation produces zero| :
|
|
202
202
|
x = 3
|
|
203
203
|
expect negateValue x = -3
|
|
204
204
|
expect add x (negateValue x) = 0
|
|
205
|
-
end
|
|
206
|
-
end
|
|
205
|
+
end example
|
|
206
|
+
end law
|
|
207
207
|
|
|
208
|
-
law
|
|
209
|
-
definition
|
|
210
|
-
|
|
211
|
-
end
|
|
208
|
+
law "|negation supplies both additive inverses| is
|
|
209
|
+
definition :
|
|
210
|
+
apply law "|invertible| add negateValue 0
|
|
211
|
+
end definition
|
|
212
212
|
|
|
213
|
-
example
|
|
213
|
+
example "|3 has inverse -3; the left and right inverse equation produces zero| :
|
|
214
214
|
x = 3
|
|
215
215
|
expect negateValue x = -3
|
|
216
216
|
expect add (negateValue x) x = 0
|
|
217
217
|
expect add x (negateValue x) = 0
|
|
218
|
-
end
|
|
219
|
-
end
|
|
218
|
+
end example
|
|
219
|
+
end law
|
|
220
220
|
|
|
221
|
-
law
|
|
222
|
-
definition
|
|
223
|
-
|
|
224
|
-
end
|
|
221
|
+
law "|subtraction has left division| is
|
|
222
|
+
definition :
|
|
223
|
+
apply law "|left division| subtractValue divideLeft
|
|
224
|
+
end definition
|
|
225
225
|
|
|
226
|
-
example
|
|
226
|
+
example "|left solution is -2 since 3 - (-2) = 5; reversing the operation recovers 5| :
|
|
227
227
|
x = 3
|
|
228
228
|
y = 5
|
|
229
229
|
expect divideLeft x y = -2
|
|
230
230
|
expect subtractValue x (divideLeft x y) = 5
|
|
231
231
|
expect divideLeft x (subtractValue x y) = 5
|
|
232
|
-
end
|
|
233
|
-
end
|
|
232
|
+
end example
|
|
233
|
+
end law
|
|
234
234
|
|
|
235
|
-
law
|
|
236
|
-
definition
|
|
237
|
-
|
|
238
|
-
end
|
|
235
|
+
law "|subtraction has right division| is
|
|
236
|
+
definition :
|
|
237
|
+
apply law "|right division| subtractValue divideRight
|
|
238
|
+
end definition
|
|
239
239
|
|
|
240
|
-
example
|
|
240
|
+
example "|right solution is 8 since 8 - 5 = 3; reversing the operation recovers 3| :
|
|
241
241
|
x = 3
|
|
242
242
|
y = 5
|
|
243
243
|
expect divideRight x y = 8
|
|
244
244
|
expect subtractValue (divideRight x y) y = 3
|
|
245
245
|
expect divideRight (subtractValue x y) y = 3
|
|
246
|
-
end
|
|
247
|
-
end
|
|
246
|
+
end example
|
|
247
|
+
end law
|
|
248
248
|
|
|
249
|
-
law
|
|
250
|
-
definition
|
|
251
|
-
|
|
252
|
-
end
|
|
249
|
+
law "|subtraction has divisible| is
|
|
250
|
+
definition :
|
|
251
|
+
apply law "|divisible| subtractValue divideLeft divideRight
|
|
252
|
+
end definition
|
|
253
253
|
|
|
254
|
-
example
|
|
254
|
+
example "|left solution is -2; right solution is 8; both recovery directions hold| :
|
|
255
255
|
x = 3
|
|
256
256
|
y = 5
|
|
257
257
|
expect divideLeft x y = -2
|
|
@@ -260,23 +260,24 @@ law `subtraction has divisible` is
|
|
|
260
260
|
expect divideRight x y = 8
|
|
261
261
|
expect subtractValue (divideRight x y) y = 3
|
|
262
262
|
expect divideRight (subtractValue x y) y = 3
|
|
263
|
-
end
|
|
264
|
-
end
|
|
263
|
+
end example
|
|
264
|
+
end law
|
|
265
265
|
|
|
266
|
-
law
|
|
267
|
-
definition
|
|
268
|
-
|
|
269
|
-
end
|
|
266
|
+
law "|negation is an involution| is
|
|
267
|
+
definition :
|
|
268
|
+
apply law "|involution| negateValue
|
|
269
|
+
end definition
|
|
270
270
|
|
|
271
|
-
example
|
|
271
|
+
example "|negating -3 twice restores -3| :
|
|
272
272
|
x = -3
|
|
273
273
|
expect negateValue x = 3
|
|
274
274
|
expect negateValue (negateValue x) = -3
|
|
275
|
-
end
|
|
275
|
+
end example
|
|
276
276
|
|
|
277
|
-
example
|
|
277
|
+
example "|negating the Int32 minimum produces a positive integer| :
|
|
278
278
|
x = -2147483648
|
|
279
279
|
expect negateValue x = 2147483648
|
|
280
280
|
expect negateValue (negateValue x) = -2147483648
|
|
281
|
-
end
|
|
282
|
-
end
|
|
281
|
+
end example
|
|
282
|
+
end law
|
|
283
|
+
end unit
|