This file is indexed.

/usr/share/hol88-2.02.19940316/contrib/Z/TelephoneBook.ml is in hol88-contrib-source 2.02.19940316-35.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
%============================================================================%
% HOL theory to represent the "Telephone Book" from  the paper               %
% "A Simple Demonstration of Balzac" by Rodger Collinson                     %
%============================================================================%

%----------------------------------------------------------------------------%
% First load the ML code to support Z.                                       %
%----------------------------------------------------------------------------%

loadf `SCHEMA`;;

%----------------------------------------------------------------------------%
% Declare a new theory called `TelephoneBook`.                               %
%----------------------------------------------------------------------------%

force_new_theory `TelephoneBook`;;

%----------------------------------------------------------------------------%
% The telphone book                                                          %
%----------------------------------------------------------------------------%

sets `NUMBER SUBSCRIBER`;;

%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%
% The following two axioms are NOT assumed in Balzac, since it assumes       %
% ALL basic types are non-empty. This is not standard!                       %
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%

declare_axiom "NUMBER =/= {}";;       

declare_axiom "SUBSCRIBER =/= {}";;

declare
 `TelephoneBook`
 "SCHEMA
   [book :: SUBSCRIBER -+> NUMBER;
    known :: (P SUBSCRIBER);
    free :: (P NUMBER)]
   %---------------------------%
   [known = dom book;
    free = NUMBER DIFF (ran book)]";;

%----------------------------------------------------------------------------%
% A general purpose tactic for proving goals of the form:                    %
%                                                                            %
%    |-? EXISTS [<schema>] true                                              %
%----------------------------------------------------------------------------%

let EXISTS_CONSISTENT_TAC =
 REWRITE_TAC[::;-+>;<->;><;P;SUBSET_DEF;NOT_IN_EMPTY;true_DEF]
  THEN SET_SPEC_TAC
  THEN REWRITE_TAC
        [NOT_IN_EMPTY;dom_EMPTY;ran_EMPTY;DIFF_EMPTY;IN_SING;UNION_EMPTY;
         dom_SING;ran_SING;NOT_IN;IN_DIFF;|->;PAIR_EQ]
  THEN SET_SPEC_TAC
  THEN REPEAT STRIP_TAC
  THEN ((EXISTS_TAC "CHOICE SUBSCRIBER" THEN EXISTS_TAC "CHOICE NUMBER")
        ORELSE ALL_TAC)
  THEN ASM_REWRITE_TAC
        [GSYM CHOICE;Axiom_1;Axiom_2;GSYM |->;RangeAntiResSING;Ap_SING];;

prove_theorem
 (`TelephoneBook_consistent`,
  "EXISTS [TelephoneBook] true",
  EXISTS_TAC "{}:(SUBSCRIBER # NUMBER)set"
   THEN EXISTS_TAC "{}:(SUBSCRIBER)set"
   THEN EXISTS_TAC "NUMBER"
   THEN EXISTS_CONSISTENT_TAC);;

declare
 `Connect`
 "SCHEMA
   [DELTA TelephoneBook;
    subscriber? :: SUBSCRIBER;
    number! :: NUMBER]
   %-------------------------------------------%
   [free =/= {};
    subscriber? NOT_IN known;
    number! IN free;
    book' = book UNION{subscriber? |-> number!}]";;

prove_theorem
 (`Connect_consistent`,
  "EXISTS [Connect] true",
  EXISTS_TAC "{}:(SUBSCRIBER # NUMBER)set"
   THEN EXISTS_TAC "{}:(SUBSCRIBER)set"
   THEN EXISTS_TAC "NUMBER"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER |-> CHOICE NUMBER}"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER}"
   THEN EXISTS_TAC "NUMBER DIFF {CHOICE NUMBER}"
   THEN EXISTS_TAC "CHOICE SUBSCRIBER"
   THEN EXISTS_TAC "CHOICE NUMBER"
   THEN EXISTS_CONSISTENT_TAC);;

prove_theorem
 (`Connect_proof_1`,
  "FORALL [Connect] (known' = known UNION {subscriber?})",
  REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[dom_UNION;dom_SING]);;

prove_theorem
 (`Connect_proof_2`,
  "FORALL [Connect] (free' = free DIFF {number!})",
  REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[ran_UNION;ran_SING;EXTENSION;DIFF_UNION]);;

declare
 `Disconnect`
 "SCHEMA
   [DELTA TelephoneBook;
    number? :: NUMBER]
   %-------------------------%
   [number? IN ran book;
    book' = book +> {number?}]";;

prove_theorem
 (`Disconnect_consistent`,
  "EXISTS [Disconnect] true",
  EXISTS_TAC "{CHOICE SUBSCRIBER |-> CHOICE NUMBER}"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER}"
   THEN EXISTS_TAC "NUMBER DIFF {CHOICE NUMBER}"
   THEN EXISTS_TAC "{}:(SUBSCRIBER # NUMBER)set"
   THEN EXISTS_TAC "{}:(SUBSCRIBER)set"
   THEN EXISTS_TAC "NUMBER"
   THEN EXISTS_TAC "CHOICE NUMBER"
   THEN EXISTS_CONSISTENT_TAC);;

prove_theorem
 (`Disconnect_proof_1`,
  "FORALL 
    [Disconnect] 
    (known' = known DIFF {s | s IN SUBSCRIBER /\ (book s = number?)})",
  REWRITE_TAC[::]
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[DIFF_DEF;EXTENSION;+>;|->;dom;PAIR_EQ]
   THEN SET_SPEC_TAC
   THEN REWRITE_TAC[PAIR_EQ;IN_SING]
   THEN GEN_TAC
   THEN EQ_TAC
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[]
   THEN SMART_ELIMINATE_TAC
   THENL
    [EXISTS_TAC "y':NUMBER"
      THEN ASM_REWRITE_TAC[];
     LITE_IMP_RES_TAC ApFunCor
      THEN POP_ASSUM(ASSUME_TAC o SYM)
      THEN RES_TAC;
     EXISTS_TAC "y:NUMBER"
      THEN EXISTS_TAC "x:SUBSCRIBER"
      THEN EXISTS_TAC "y:NUMBER"
      THEN ASM_REWRITE_TAC[]
      THEN LITE_IMP_RES_TAC ApFunCor
      THEN LITE_IMP_RES_TAC IN_dom_ran
      THEN RW_ASM_THEN ACCEPT_TAC [el 2;el 3] (el 4)]);;

prove_theorem
 (`Disconnect_proof_2`,
  "FORALL 
    [Disconnect] 
    (free' = free UNION {number?})",
  REWRITE_TAC[::]
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[DIFF_DEF;EXTENSION;+>;|->;ran;PAIR_EQ]
   THEN SET_SPEC_TAC
   THEN REWRITE_TAC[PAIR_EQ;IN_UNION;IN_SING]
   THEN GEN_TAC
   THEN SET_SPEC_TAC
   THEN CONV_TAC(TOP_DEPTH_CONV NOT_EXISTS_CONV)
   THEN EQ_TAC
   THEN REPEAT STRIP_TAC
   THEN SMART_ELIMINATE_TAC
   THEN ASM_REWRITE_TAC[]
   THEN REPEAT STRIP_TAC
   THEN RES_TAC
   THEN POP_ASSUM
        (STRIP_ASSUME_TAC                     o 
         CONV_RULE(DEPTH_CONV FORALL_OR_CONV) o
         GEN_ALL                              o
         REWRITE_RULE[DE_MORGAN_THM]          o 
         SPECL["x:SUBSCRIBER";"x:SUBSCRIBER";"x:NUMBER"])
   THEN ASM_REWRITE_TAC[]);;

declare
 `FindNumber`
 "SCHEMA
   [XI TelephoneBook;
    subscriber? :: SUBSCRIBER;
    number! :: NUMBER]
   %--------------------------%
   [subscriber? IN known;
    number! = book subscriber?]";;

prove_theorem
 (`FindNumber_consistent`,
  "EXISTS [FindNumber] true",
  REWRITE_TAC[PAIR_EQ]
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER |-> CHOICE NUMBER}"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER}"
   THEN EXISTS_TAC "NUMBER DIFF {CHOICE NUMBER}"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER |-> CHOICE NUMBER}"
   THEN EXISTS_TAC "{CHOICE SUBSCRIBER}"
   THEN EXISTS_TAC "NUMBER DIFF {CHOICE NUMBER}"
   THEN EXISTS_TAC "CHOICE SUBSCRIBER"
   THEN EXISTS_TAC "CHOICE NUMBER"
   THEN EXISTS_CONSISTENT_TAC);;

declare
 `initTelephoneBook`
 "SCHEMA
   [TelephoneBook]
   %-------------%
   [known = {}]";;

prove_theorem
 (`initTelephoneBook_consistent`,
  "EXISTS [initTelephoneBook] true",
  EXISTS_TAC "{}:(SUBSCRIBER # NUMBER)set"
   THEN EXISTS_TAC "{}:(SUBSCRIBER)set"
   THEN EXISTS_TAC "NUMBER"
   THEN EXISTS_CONSISTENT_TAC);;

free_set  `REPORT = ok 
                  | full_book 
                  | already_known 
                  | unknown_number 
                  | unknown_subscriber`;;

declare
 `Success`
 "SCHEMA
   [result! :: REPORT]
   %-----------------%
   [result! = ok]";;

declare
 `FullBook`
 "SCHEMA
   [XI TelephoneBook;
    result! :: REPORT]
   %-----------------%
   [free = {};
    result! = full_book]";;

declare
 `AlreadyKnown`
 "SCHEMA
   [XI TelephoneBook;
    subscriber? :: SUBSCRIBER;
    result! :: REPORT]
   %-----------------%
   [subscriber? IN known;
    result! = already_known]";;

declare
 `RConnect`
 "(Connect AND Success) OR FullBook OR AlreadyKnown";;

prove_theorem
 (`RConnect_total`,
  "FORALL [RConnect] (pre RConnect)",
  REWRITE_TAC[::;SCHEMA;CONJL;NOT_IN]
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[DIFF_DEF;EXTENSION;+>;|->;dom;PAIR_EQ]
   THEN SET_SPEC_TAC
   THEN REWRITE_TAC[PAIR_EQ;IN_SING]
   THEN EXISTS_TAC
         "((free =/= {}) /\ (subscriber? NOT_IN known))
           => (book UNION {subscriber? |-> number!}) 
           | book"
   THEN EXISTS_TAC
         "((free =/= {}) /\ (subscriber? NOT_IN known))
          => dom(book UNION {subscriber? |-> number!}) |
             dom book"
   THEN EXISTS_TAC
         "((free =/= {}) /\ (subscriber? NOT_IN known))
          => NUMBER DIFF ran(book UNION {subscriber? |-> number!}) |
             NUMBER DIFF ran book"
   THEN EXISTS_TAC "number!"
   THEN EXISTS_TAC "result!"
   THEN ASM_CASES_TAC "(free =/= {}) /\ (subscriber? NOT_IN known)"
   THEN LITE_IMP_RES_TAC UNION_SING_IN_P
   THEN LITE_IMP_RES_TAC domPfunIN
   THEN LITE_IMP_RES_TAC ranPfunIN
   THEN SMART_ELIMINATE_TAC
   THEN LITE_IMP_RES_TAC UNION_SING_Pfun
   THEN ASM_REWRITE_TAC[DIFF_IN_P]
   THEN RW_ASM_THEN ASSUME_TAC [K =/=;K NOT_IN;K DE_MORGAN_THM;el 10] (el 7)
   THEN RES_TAC
   THEN ASM_F_TAC);;

declare
 `UnknownNumber`
 "SCHEMA
   [XI TelephoneBook;
    number? :: NUMBER;
    result! :: REPORT]
   %-----------------%
   [number? IN free;
    result! = unknown_number]";;

declare
 `RDisconnect`
 "(Disconnect AND Success) OR UnknownNumber";;

prove_theorem
 (`RDisconnect_total`,
  "FORALL [RDisconnect] (pre RDisconnect)",
  REWRITE_TAC[::;SCHEMA;CONJL;NOT_IN]
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[DIFF_DEF;EXTENSION;+>;|->;dom;PAIR_EQ]
   THEN SET_SPEC_TAC
   THEN REWRITE_TAC[PAIR_EQ;IN_SING]
   THEN EXISTS_TAC
         "(number? IN ran book /\ (result! = ok))
           => book +> {number?}
           | book"
   THEN EXISTS_TAC
         "(number? IN ran book /\ (result! = ok))
          => dom(book +> {number?}) |
             dom book"
   THEN EXISTS_TAC
         "(number? IN ran book /\ (result! = ok))
          => NUMBER DIFF ran(book +> {number?}) |
             NUMBER DIFF ran book"
   THEN EXISTS_TAC "result!"
   THEN ASM_CASES_TAC "number? IN ran book /\ (result! = ok)"
   THEN LITE_IMP_RES_TAC UNION_SING_IN_P
   THEN LITE_IMP_RES_TAC domPfunIN
   THEN LITE_IMP_RES_TAC ranPfunIN
   THEN SMART_ELIMINATE_TAC
   THEN LITE_IMP_RES_TAC UNION_SING_Pfun
   THEN LITE_IMP_RES_TAC RangeAntiResPfun
   THEN LITE_IMP_RES_TAC domRangeAntiResPfun
   THEN REWRITE_ASMS_TAC[]
   THEN ASM_REWRITE_TAC[DIFF_IN_P]
   THEN RES_TAC);;

declare
 `UnknownSubscriber`
 "SCHEMA
   [XI TelephoneBook;
    subscriber? :: SUBSCRIBER;
    result! :: REPORT]
   %-----------------%
   [subscriber? NOT_IN known;
    result! = unknown_subscriber]";;

declare
 `RFindNumber`
 "(FindNumber AND Success) OR UnknownSubscriber";;

prove_theorem
 (`RFindNumber_total`,
  "FORALL [RFindNumber] (pre RFindNumber)",
  REWRITE_TAC[::;SCHEMA;CONJL;NOT_IN]
   THEN REPEAT STRIP_TAC
   THEN ASM_REWRITE_TAC[DIFF_DEF;EXTENSION;+>;|->;dom;PAIR_EQ]
   THEN SET_SPEC_TAC
   THEN REWRITE_TAC[PAIR_EQ;IN_SING]
   THEN EXISTS_TAC "book"
   THEN EXISTS_TAC "known"
   THEN EXISTS_TAC "free"
   THEN EXISTS_TAC 
         "(subscriber? IN dom book) => book^^subscriber? | number!"
   THEN EXISTS_TAC "(subscriber? IN dom book) => ok | unknown_subscriber"
   THEN ASSUM_LIST(STRIP_ASSUME_TAC o REWRITE_RULE[PAIR_EQ] o el 4)
   THEN SMART_ELIMINATE_TAC
   THEN (SMART_ELIMINATE_TAC ORELSE ALL_TAC)
   THEN ASM_REWRITE_TAC[REPORT;IN_UNIV]);;