1
; Copyright (C) 2007 by Shant Harutunian
2
; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2.
6
(include-book "arith-nsa4")
8
(include-book "computed-hints")
9
(include-book "o-real-p")
12
;; Enable abs, <-cancel-divisors and divisor cancellation as needed.
14
(in-theory (disable equal-cancel-divisors <-cancel-divisors))
16
(set-default-hints '((staged-hints stable-under-simplificationp
17
nil ;;restart on new id
18
'((:in-theory (enable abs
19
equal-cancel-divisors <-cancel-divisors)))
22
;; Macro defining non-negative real
24
(defmacro nneg-realp (r)
28
;; Macro defining the constraint on the variable eps.
29
;; In this case, we require that 0 < eps <= 1/100.
31
(defmacro small-realp (eps)
36
;; Define accessor function for accessing particular variables
54
;; Define a function which creates a system state, consisting
55
;; of the variables of the system.
57
(defun make-state (posReq preset pos posAo tmr)
58
(list posReq preset pos posAo tmr))
60
;; Define theorems relating the accessor function and the make
65
(equal (getPosReq (make-state posReq preset pos posAo tmr)) posReq)
66
(equal (getPreset (make-state posReq preset pos posAo tmr)) preset)
67
(equal (getPos (make-state posReq preset pos posAo tmr)) pos)
68
(equal (getPosAo (make-state posReq preset pos posAo tmr)) posAo)
69
(equal (getTmr (make-state posReq preset pos posAo tmr)) tmr)))
71
;; Disable the accessor functions and make-state function and rely upon the
72
;; rewrite rules associated with above theorem.
74
(in-theory (disable getPosReq getPreset getPos getPosAo getTmr
77
;; StateP is a predicate which recognizes whether some variable is a
82
(make-state (getPosReq x)
88
;; The system assignment function, Y, includes the definition of the
90
;; the floor function representing the analog to digital conversion,
91
;; and the reset of the timer variable.
100
((> (- (floor1 (getPos X)) (getposReq X)) 2)
102
((< (- (floor1 (getPos X)) (getposReq X)) -3)
108
;; The step definition of the physical system, including timer
116
((> (getPos X) (getPosAo X))
118
((< (getPos X) (getPosAo X))
126
(>= (getTmr X) (getPreset X)))
128
;; The system step function, as define by the single step function
129
;; sigma, the assignment function Y, and assignment predicate B-Y.
131
(defun sys-step (X eps)
136
;; The positive clamp function "clamps" the given r to a non-negative value.
137
;; If the value is negative, it returns zero. Otherwise, it returns
139
;; It should be noted that the function is continuous in r.
145
;; A component function of the overall measure m.
146
;; Intuitively, this measure function measures that the difference
147
;; between pos and posAo decreases over time.
148
;; This measure is 'active' when the difference between pos and
153
((<= (abs (- (getPosAo X) (getPos X)))
154
(+ eps (pos-clamp (- (getPreset X) (getTmr X))))) 0)
155
(t (+ 1 (/ (- (abs (- (getPosAo X) (getPos X)))
156
(+ (- (getPreset X) (getTmr X)) eps))
159
;; A component function of the overall measure m.
160
;; Intuitively, this measure function measures that the difference
161
;; between posReq and posAo decreases over time.
164
(declare (ignore eps))
166
(<= (- (getPosAo X) (getPosReq X)) 3)
167
(>= (- (getPosAo X) (getPosReq X)) -3))
169
(abs (- (getPosAo X) (getPosReq X)))))
171
;; A component function of the overall measure m.
172
;; Intuitively, this measure function measures that the difference
173
;; between pos and posAo decreases over time.
174
;; This measure is 'active' when the difference between pos and
178
(if (<= (abs (- (getPos X) (getPosAo X))) eps)
180
(/ (abs (- (getPos X) (getPosAo X))) eps)))
182
;; A component function of the overall measure m.
183
;; Intuitively, this measure function measures that the
184
;; timer changes in each step. This is useful for showing a
185
;; decreasing measure while the other system variables are unchanging.
189
((< (getPreset X) (getTmr X)) 0)
190
(t (+ 1 (/ (- (getPreset X) (getTmr X)) eps)))))
192
;; The overall measure function
198
(make-ord 1 (+ 1 (m3 x eps))
201
(make-ord 2 (+ 1 (m2 x eps))
202
(make-ord 1 (+ 1 (m3 x eps))
204
(t (make-ord 3 (+ 1 (m1 x eps)) (m4 x eps)))))
206
;; Definition of the domain of the system variables and constants.
208
(defun valid-state (X eps)
209
(and (realp (getPos X))
210
(realp (getPreset X))
212
(integerp (getPosAo X))
213
(integerp (getPosReq X))
214
(<= 51/10 (getPreset X))
216
(<= (getTmr x) (+ (getpreset x) eps))))
218
;; Cuong Chau: Disable the following control output setting.
219
;; (set-inhibit-output-lst '(proof-tree prove))
221
;; By requirement A1, we must show that if the assignment
222
;; predicate is satisfied in the current step, it is
223
;; not satisfied in the next step.
233
;; Since the computer executes every delta time
234
;; period which is greater than preset, and since this
235
;; preset is a positive, standard number, then
236
;; to satisfy requirement A2, we must show that
237
;; the assignment function is limited if the
238
;; state variables are limited and satisfy B-Y.
245
(i-limited (getPosAo x))
246
(i-limited (getTmr x))
247
(i-limited (getPos x))
248
(i-limited (getPreset x))
249
(i-limited (getPosReq x)))
251
(i-limited (getPosAo (Y x)))
252
(i-limited (getTmr (Y x)))
253
(i-limited (getPos (Y x)))
254
(i-limited (getPreset (Y x)))
255
(i-limited (getPosReq (Y x)))))
257
:hints (("Goal" :in-theory (disable i-large))))
259
; Added by Matt K.: Avoids rewriter loop in m1-lt-1.
260
(local (in-theory (disable commutativity-2-of-+)))
262
;; A theorem that states the formula (< (m1 x eps) 1) is equal
263
;; to the corresponding safety predicate
264
;; Hence, we will use the shorter formula
265
;; (< (m1 x eps) 1) in the remainder of this session.
272
(iff (< (m1 x eps) 1)
273
(<= (abs (- (getPosAo X) (getPos X)))
274
(+ eps (pos-clamp (- (getPreset X) (getTmr X)))))))
277
;; A theorem that states the formula (< (m2 x eps) 1) is equal
278
;; to the corresponding safety predicate
279
;; Hence, we will use the shorter formula (< (m2 x eps) 1)
280
;; in the remainder of this session.
287
(iff (< (m2 x eps) 1)
289
(<= (- (getPosAo X) (getPosReq X)) 3)
290
(>= (- (getPosAo X) (getPosReq X)) -3))))
293
;; Check that a valid state is an ordinal real
295
(defthm ordinal-real-thm
297
(and (valid-state x eps)
302
(<= (abs (- (getpos x) (getPosReq x))) (+ 3 (* 2 eps))))))
303
(o-real-p (m x eps))))
305
;; If we start in valid state, then next state also satisfies valid state
307
(defthm valid-state-preserve
309
(and (valid-state x eps)
311
(valid-state (sys-step x eps) eps)))
313
;; The following theorem shows that once m1 < 1, then it remains so
314
;; similarly, once m2 < 1, it remains so. These results
315
;; are used to show that if m1 < 1 and m2 < 1, then
316
;; -3-eps <= (abs (- pos PosReq)) <= 3+eps is true
317
;; for all ensuing states.
321
(and (valid-state x eps)
324
(< (m1 (sys-step x eps) eps) 1))
325
:rule-classes :linear)
329
(and (valid-state x eps)
333
(< (m2 (sys-step x eps) eps) 1))
334
:rule-classes :linear)
336
(defthm pos-posReq-preserve
338
(and (valid-state x eps)
342
(<= (abs (- (getpos x) (getPosReq x))) (+ 3 (* 2 eps))))
343
(<= (abs (- (getpos (sys-step x eps))
344
(getposReq (sys-step x eps)))) (+ 3 (* 2 eps))))
345
:rule-classes :linear)
347
(defthm safety-property-preserve
349
(and (valid-state x eps)
353
(<= (abs (- (getpos x) (getPosReq x))) (+ 3 (* 2 eps))))
355
(valid-state (sys-step x eps) eps) ;; Cuong Chau: I changed "(valid-state x
356
;; eps)" to "(valid-state (sys-step x eps) eps)"
357
(< (m1 (sys-step x eps) eps) 1)
358
(< (m2 (sys-step x eps) eps) 1)
359
(<= (abs (- (getpos (sys-step x eps))
360
(getposReq (sys-step x eps)))) (+ 3 (* 2 eps)))))
362
:hints (("Goal" :in-theory (disable sys-step valid-state m1 m2))
363
("Subgoal 2" :use ((:instance pos-posReq-preserve)))))
365
;; The measure is decreasing on the real ordinals, with
368
(defthm m-1-decreases
370
(and (valid-state x eps)
372
(not (< (m1 x eps) 1)))
373
(o<-1 (m (sys-step x eps) eps) (m x eps))))
375
(defthm m-2-decreases
377
(and (valid-state x eps)
380
(not (< (m2 x eps) 1)))
381
(o<-1 (m (sys-step x eps) eps) (m x eps))))
385
(and (valid-state x eps)
390
(<= (abs (- (getpos x) (getPosReq x))) (+ 3 (* 2 eps))))))
391
(o<-1 (m (sys-step x eps) eps) (m x eps))))
393
;; Cuong Chau: Disable the following control output setting.
394
;; (set-inhibit-output-lst '(proof-tree))
396
(in-theory (disable o<-1 o-floor1 o-real-p sys-step valid-state m m1 m2 m3))
398
;; Fix m so that it always returns an ordinal
402
((not (and (valid-state x eps)
407
(<= (abs (- (getpos x) (getPosReq x)))
410
(t (o-floor1 (m x eps)))))
412
;; m-fix is an ordinal
417
;; sys-step decreases, using measure m-fix
419
(defthm m-fix-decreases
421
(and (valid-state x eps)
426
(<= (abs (- (getpos x) (getPosReq x)))
428
(o< (m-fix (sys-step x eps) eps) (m-fix x eps))))