-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathspeedcontrol.kyx
273 lines (228 loc) · 6.31 KB
/
speedcontrol.kyx
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
ArchiveEntry "01 Exercise: Speed Control Loop Invariant"
Description "Find a Loop Invariant for Braking".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep;
Real A;
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=D & S>=0 & B>0 & __________
->
[
{
{ a := -B; }
{x'=v, v'=a & v>=0}
}*@invariant(__________)
](x>=D -> v<=S)
End.
Tactic "Speed Control: Explore"
explore
End.
Tactic "Speed Control: Solution"
implyR(1) ; loop("v^2-S^2<=2*B*(D-x)", 1) ; doall(master)
End.
End.
ArchiveEntry "02 Solution: Speed Control Loop Invariant"
Description "Find a Loop Invariant for Braking".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep;
Real A;
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=D & S>=0 & B>0 & v^2-S^2<=2*B*(D-x)
->
[
{
{ a := -B; }
{x'=v, v'=a & v>=0}
}*@invariant(v^2-S^2<=2*B*(D-x))
](x>=D -> v<=S)
End.
Tactic "Speed Control: Solution Automatic Proof"
master
End.
End.
ArchiveEntry "03 Exercise: Speed Control Coasting Condition"
Description "Find a Control Condition for Coasting".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep; /* reaction time */
Real A;
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=S & S>=0 &B>0 & v^2-S^2<=2*B*(D-x) & ep>0
->
[
{
{ a := -B;
++ ?v^2-S^2<=2*B*(D-x-__________); a:=0; }
t:=0;
{x'=v, v'=a, t'=1 & v>=0 & t<=ep}
}*@invariant(v^2-S^2<=2*B*(D-x))
](x>=D -> v<=S)
End.
Tactic "Speed Control: Explore"
explore
End.
End.
ArchiveEntry "04 Solution: Speed Control Coasting Condition"
Description "Find a Control Condition for Coasting".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep; /* reaction time */
Real A;
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=S & S>=0 &B>0 & v^2-S^2<=2*B*(D-x) & ep>0
->
[
{
{ a := -B;
++ ?v^2-S^2<=2*B*(D-x-v*ep); a:=0; }
t:=0;
{x'=v, v'=a, t'=1 & v>=0 & t<=ep}
}*@invariant(v^2-S^2<=2*B*(D-x))
](x>=D -> v<=S)
End.
Tactic "Speed Control: Solution Interactive Proof"
implyR(1) ; loop("v^2-S^2<=2*B*(D-x)", 1) ; <(
id,
QE,
composeb(1) ; composeb(1.1) ; solve(1.1.1) ;
assignb(1.1) ; choiceb(1) ; andR(1) ; <(
assignb(1) ; QE,
composeb(1) ; testb(1) ; implyR(1) ; assignb(1) ; QE
)
)
End.
Tactic "Speed Control: Solution Automatic Proof"
master
End.
End.
ArchiveEntry "05 Exercise: Accelerating Car"
Description "Find a Control Condition for Accelerating".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep; /* reaction time */
Real A; /* maximum acceleration */
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=S & S>=0 &B>0 & v^2-S^2<=2*B*(D-x) & ep>0 & __________
->
[
{
{ a := -B;
++ ?v^2-S^2<=2*B*(D-x-v*ep); a:=0;
++ ?__________;a:=A; }
t:=0;
{x'=v, v'=a, t'=1 & v>=0 & t<=ep}
}*@invariant(v^2-S^2<=2*B*(D-x))
](x>=D -> v<=S)
End.
Tactic "Accelerating Car: Explore"
explore
End.
End.
ArchiveEntry "06 Solution: Accelerating Car"
Description "Find a Control Condition for Coasting".
Definitions /* function symbols cannot change their value */
Real D; /* speed limit sign position */
Real S; /* posted speed limit */
Real B; /* brakes */
Real ep; /* reaction time */
Real A; /* maximum acceleration */
End.
ProgramVariables /* program variables may change their value over time */
Real x, v, a; /* car position, speed, and acceleration */
Real t; /* time */
End.
Problem
x<=S & S>=0 &B>=0 & v^2-S^2<=2*B*(D-x) & ep>0 & A>=0
->
[
{
{ a := -B;
++ ?v^2-S^2<=2*B*(D-x-v*ep); a:=0;
++ ?(v+A*ep)^2-S^2<=2*B*(D-x-v*ep-A/2*ep^2); a:=A; }
t:=0;
{x'=v, v'=a, t'=1 & v>=0 & t<=ep}
}*@invariant(v^2-S^2<=2*B*(D-x))
](x>=D -> v<=S)
End.
Tactic "Speed Control: Explore"
explore
End.
End.
ArchiveEntry "07 Car Drives Curve"
Description "Car picks steering to not exceed maximum angular speed".
Description "Find a Control Condition for Coasting".
Definitions /* function symbols cannot change their value */
Real ep; /* reaction time */
Real W; /* maximum angular speed before tires slip */
Real A;
Real B;
End.
ProgramVariables /* program variables may change their value over time */
Real x, y, v, a; /* car position, speed, and acceleration */
Real k, w; /* steering, angular speed */
Real t; /* time */
End.
Problem
B>0 & A>=0 & ep>0 & W>=0 & abs(w)<=W
->
[
{
a:=*; ?(-B<=a & a<=A);
k:=*; ?((a>=0&abs(k)*(v+a*ep)<=W) | (a<=0&abs(k)*v<=W));
w:=v*k;
t:=0;
{{x'=-k*y*v, y'=k*x*v, v'=a, w'=a*k,
t'=1 & v>=0 & t<=ep}@invariant(t>=0,w=v*k,v=old(v)+a*t)}
}*@invariant(abs(w)<=W)
]abs(w)<=W
End.
Tactic "Proof"
implyR(1) ; loop("abs(w)<=W()", 1) ; <(
id,
id,
unfold ; dC("t>=0&w=v*k", 1) ; <(
dC("v=old(v)+a*t", 1) ; <(
dW(1) ; QE,
dI(1)
),
dI(1)
)
)
End.
End.