forked from informalsystems/quint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkettle.qnt
94 lines (78 loc) · 2.15 KB
/
kettle.qnt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// -*- mode: Bluespec; -*-
// The example from the REPL tutorial
module kettle {
// an example of a definition
val isThisMyFirstDefinition = true
// a constant value that always returns 100
val boilingTemperature = 100
// a constant value that always returns 0
val freezingTemperature = 0
// conversion from Celsius to Fahrenheit
def fahrenheit(celsius) = celsius * 9 / 5 + 32
// the low range of a thermometer (fixed)
val veryCold = fahrenheit(-40)
// the high range of a thermometer (fixed)
val veryHot = fahrenheit(40)
// the current temperature in the kettle
var temperature: int
// is the kettle currently heating?
var heatingOn: bool
// is the kettle currently beeping?
var beeping: bool
// a state initializer
action init = all {
temperature' = 20,
heatingOn' = false,
beeping' = false,
}
// a handy definition that captures the state in a record
val kettleState = {
heatingOn: heatingOn,
beeping: beeping,
temperature: temperature
}
// turn on the heating element
action pressButton = all {
not(heatingOn),
heatingOn' = true,
beeping' = false,
temperature' = temperature,
}
// turn off the kettle when the temperature is too high
action failover = all {
heatingOn,
temperature >= 100,
heatingOn' = false,
beeping' = true,
temperature' = temperature,
}
// heat up the water by 1C
action heat = all {
heatingOn,
temperature < 100,
temperature' = temperature + 1,
heatingOn' = true,
beeping' = false,
}
// turn off the heating element
action depressButton = all {
heatingOn,
heatingOn' = false,
temperature' = temperature,
beeping' = false,
}
// one step of the state machine
action step = any {
pressButton,
heat,
depressButton,
failover,
}
// initialize the state machine with non-determinism
action initNondet = all {
heatingOn' = false,
nondet temp = oneOf((-40).to(40))
temperature' = temp,
beeping' = false,
}
}