This file is indexed.

/usr/share/minlog/src/boole.scm is in minlog 4.0.99.20100221-5.2.

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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
; $Id: boole.scm 2346 2009-11-13 11:41:47Z schwicht $
; 7. Formulas and comprehension terms
; ===================================

; First we add some tokens (this can only be done after loading
; minitab.scm, which is done immediately before loading the present file)

(add-token "andd" 'and-jct make-andd)
(add-token "andr" 'and-jct make-andr)
(add-token "andu" 'and-jct make-andu)

(add-token "ord" 'or-jct make-ord)
(add-token "orl" 'or-jct make-orl)
(add-token "orr" 'or-jct make-orr)
(add-token "oru" 'or-jct make-oru)

(add-token "eqd" 'pred-infix make-eqd)
(add-idpredconst-display "EqD" 'pred-infix "eqd")

(add-token "exd" 'quantor (lambda (v k) (apply mk-exd (append v (list k)))))
(add-token "exl" 'quantor (lambda (v k) (apply mk-exl (append v (list k)))))
(add-token "exr" 'quantor (lambda (v k) (apply mk-exr (append v (list k)))))
(add-token "exu" 'quantor (lambda (v k) (apply mk-exu (append v (list k)))))


; 7-8. Booleans
; =============

; We need to initialize some global variables (needed for is-used?),
; before we can call add-alg.

(define THEOREMS '())
(define INITIAL-THEOREMS THEOREMS)

(define GLOBAL-ASSUMPTIONS '())
(define INITIAL-GLOBAL-ASSUMPTIONS GLOBAL-ASSUMPTIONS)

(add-alg "unit" '("Dummy" "unit"))
(define dummy-const (constr-name-to-constr "Dummy"))

(add-alg "boole" '("True" "boole") '("False" "boole"))

(add-new-application
 (lambda (type) (equal? type (make-alg "boole")))
 (lambda (test alt1)
   (let* ((type (term-to-type alt1))
	  (var (type-to-new-var type)))
     (make-term-in-abst-form
      var (make-term-in-if-form
	   test (list alt1 (make-term-in-var-form var)))))))

(add-display
 (py "boole")
 (lambda (term)
   (let ((op (term-in-app-form-to-final-op term))
	 (args (term-in-app-form-to-args term)))
     (if (and (term-in-const-form? op)
	      (string=? "=" (const-to-name (term-in-const-form-to-const op)))
	      (= 2 (length args)))
	 (list 'rel-op "="
	       (term-to-token-tree (car args))
	       (term-to-token-tree (cadr args)))
	 #f))))

(add-display
 (py "boole")
 (lambda (term)
   (let ((op (term-in-app-form-to-final-op term))
	 (args (term-in-app-form-to-args term)))
     (if (and (term-in-const-form? op)
	      (string=? "E" (const-to-name (term-in-const-form-to-const op)))
	      (= 1 (length args)))
	 (list 'prefix-op "E" (term-to-token-tree (car args)))
	 #f))))

(define (trueval? val)
  (and (nbe-constr-value? val)
       (string=? "True"
		 (const-to-name (nbe-constr-value-to-constr val)))))

(define true-const (constr-name-to-constr "True"))
(define trueobj (const-to-object-or-arity true-const))
(define truth (make-atomic-formula (make-term-in-const-form true-const)))
(add-token "T" 'const (make-term-in-const-form true-const))

(define (falseval? val)
  (and (nbe-constr-value? val)
       (string=? "False"
		 (const-to-name (nbe-constr-value-to-constr val)))))

(define false-const (constr-name-to-constr "False"))
(define falseobj (const-to-object-or-arity false-const))
(define falsity (make-atomic-formula (make-term-in-const-form false-const)))
(add-token "F" 'const (make-term-in-const-form false-const))

(define (make-negation formula) (make-imp formula falsity))
(add-token "not" 'prefix-jct make-negation)

(define falsity-log
  (make-predicate-formula
   (make-pvar (make-arity) -1 h-deg-zero n-deg-zero "bot")))

; (define falsity-log
;   (make-predicate-formula
;    (make-pvar (make-arity) -1 h-deg-one n-deg-one "bot")))

(define (make-negation-log formula) (make-imp formula falsity-log))
(add-token "notl" 'prefix-jct make-negation-log)

; 2004-12-31 Moved here from pconst.scm.  Reason: =-at and e-at need
; AndConst, which requires the algebra boole.

(define (finalg-to-=-const finalg)
  (if (not (finalg? finalg))
      (myerror "finalg-to-=-const" "finitary algebra expected" finalg)
      (make-const (=-at finalg)
		  "=" 'fixed-rules
		  (mk-arrow finalg finalg (make-alg "boole")) empty-subst
		  1 'rel-op)))

(add-program-constant "AndConst" (py "boole=>boole=>boole") t-deg-one)

(add-computation-rule (pt "AndConst True boole^") (pt "boole^"))
(add-computation-rule (pt "AndConst boole^ True") (pt "boole^"))
(add-computation-rule (pt "AndConst False boole^") (pt "False"))
(add-computation-rule (pt "AndConst boole^ False") (pt "False"))

; We add infix notation "andb" (also "and") (left associative) for AndConst.
; Coq has "/\"

(add-token
 "andb" 'and-op
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form (pconst-name-to-pconst "AndConst")) x y)))

(add-token
 "and" 'and-op
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form (pconst-name-to-pconst "AndConst")) x y)))

(add-display
 (py "boole")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "AndConst"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'and-op "andb"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(define and-const (term-in-const-form-to-const (pt "AndConst")))


(add-program-constant "ImpConst" (py "boole=>boole=>boole") t-deg-one)

(add-computation-rule (pt "ImpConst False boole^") (pt "True"))
(add-computation-rule (pt "ImpConst True boole^") (pt "boole^"))
(add-computation-rule (pt "ImpConst boole^ True") (pt "True"))

; We add an infix notation "impb" (left associative) for ImpConst

(add-token
 "impb" 'imp-op
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form (pconst-name-to-pconst "ImpConst")) x y)))

(add-display
 (py "boole")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ImpConst"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'imp-op "impb"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))
   
(define imp-const (term-in-const-form-to-const (pt "ImpConst")))


(add-program-constant "OrConst" (py "boole=>boole=>boole") t-deg-one)

(add-computation-rule (pt "OrConst True boole^") (pt "True"))
(add-computation-rule (pt "OrConst boole^ True") (pt "True"))
(add-computation-rule (pt "OrConst False boole^") (pt "boole^"))
(add-computation-rule (pt "OrConst boole^ False") (pt "boole^"))

; We add an infix notation "orb" (left associative) for OrConst
; Coq has "\/"

(add-token
 "orb" 'or-op
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form (pconst-name-to-pconst "OrConst")) x y)))

(add-display
 (py "boole")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "OrConst"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'or-op "orb"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(define or-const (term-in-const-form-to-const (pt "OrConst")))


(add-program-constant "NegConst" (py "boole=>boole") t-deg-one)

(add-computation-rule (pt "NegConst True") (pt "False"))
(add-computation-rule (pt "NegConst False") (pt "True"))

; We add a prefix notation "negb" for NegConst

(add-token
 "negb" 'prefix-op
 (lambda (x)
   (mk-term-in-app-form
    (make-term-in-const-form (pconst-name-to-pconst "NegConst")) x)))

(add-display
 (py "boole")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "NegConst"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 1 (length args)))
	     (list 'prefix-op "negb"
		   (term-to-token-tree (car args)))
	     #f))
       #f)))

(define neg-const (term-in-const-form-to-const (pt "NegConst")))

; In pproof.scm we have
; and-atom-to-left-proof "boole1 andb boole2 -> boole1"
; atoms-to-and-atom-proof "boole1 -> boole2 -> boole1 andb boole2

; In atr.scm we have
; imp-to-atom-proof "(boole1 -> boole2) -> ImpConst boole1 boole2"
; and-to-atom-proof "boole1 & boole2 -> boole1 and boole2"
; atom-to-imp-proof "ImpConst boole1 boole2 -> boole1 -> boole2
; atom-to-and-proof "boole1 and boole2 -> boole1 & boole2"
; qf-to-atom-imp-qf-proof: atom(r_C) -> C
; qf-to-qf-imp-atom-proof: C -> atom(r_C)


(define (=-at finalg)
  (nbe-make-object
   (mk-arrow finalg finalg (make-alg "boole"))
   (lambda (obj1)
     (nbe-make-object
      (mk-arrow finalg (make-alg "boole"))
      (lambda (obj2)
	(let* ((val1 (nbe-object-to-value obj1))
	       (val2 (nbe-object-to-value obj2))
	       (constr1? (nbe-constr-value? val1))
	       (constr2? (nbe-constr-value? val2))
	       (reprod-obj (nbe-make-object
			    (make-alg "boole")
			    (nbe-make-termfam
			     (make-alg "boole")
			     (lambda (k)
			       (mk-term-in-app-form
				(make-term-in-const-form
				 (finalg-to-=-const finalg))
				(nbe-fam-apply (nbe-reify obj1) k)
				(nbe-fam-apply (nbe-reify obj2) k)))))))
	  (cond
	   ((and constr1? constr2?)
	    (let ((name1 (nbe-constr-value-to-name val1))
		  (name2 (nbe-constr-value-to-name val2)))
	      (if
	       (not (string=? name1 name2))
	       falseobj
	       (let* ((args1 (nbe-constr-value-to-args val1))
		      (args2 (nbe-constr-value-to-args val2))
		      (argtypes1 (map nbe-object-to-type args1))
		      (argtypes2 (map nbe-object-to-type args2))
		      (argtypes
		       (if (equal? argtypes1 argtypes2)
			   argtypes1
			   (myerror "=-at" "equal argtypes expected"
				    (map type-to-string argtypes1)
				    (map type-to-string argtypes2))))
		      (prevs
		       (do ((l1 args1 (cdr l1))
			    (l2 args2 (cdr l2))
			    (ltypes argtypes (cdr ltypes))
			    (res
			     '()
			     (let* ((arg1 (car l1))
				    (arg2 (car l2))
				    (type (car ltypes))
				    (prev
				     (case (tag type)
				       ((alg)
					(nbe-object-app (=-at type)
							arg1 arg2))
				       ((arrow) ;unit -> finalg
					(nbe-object-app
					 (=-at (arrow-form-to-val-type type))
					 (nbe-object-app
					  arg1
					  (const-to-object-or-arity
					   dummy-const))
					 (nbe-object-app
					  arg2
					  (const-to-object-or-arity
					   dummy-const))))
				       (else (myerror "=-at" "type expected"
						      type)))))
			       (let ((prevval (nbe-object-to-value prev)))
				 (cond
				  ((trueval? prevval) res)
				  ((falseval? prevval) (cons 'f res))
				  (else (cons prev res)))))))
			   ((or (memq 'f res) (null? l1)) res))))
		 (cond
		  ((null? prevs)
		   trueobj)
		  ((memq 'f prevs)
		   falseobj)
		  (else
		   (do ((l (cdr prevs) (cdr l))
			(obj
			 (car prevs)
			 (nbe-make-object
			  (make-alg "boole")
			  (nbe-make-termfam
			   (make-alg "boole")
			   (lambda (k)
			     (mk-term-in-app-form
			      (make-term-in-const-form
			       (pconst-name-to-pconst "AndConst"))
			      (nbe-fam-apply (nbe-reify (car l)) k)
			      (nbe-fam-apply (nbe-reify obj) k)))))))
		       ((null? l) obj))))))))
	   ((or constr1? constr2?)
	    (let* ((constr-obj (if constr1? obj1 obj2))
		   (constr-val (if constr1? val1 val2))
		   (obj (if constr1? obj2 obj1)))
	      (do ((l (nbe-constr-value-to-args constr-val) (cdr l)))
		  ((or (null? l)
		       (let* ((arg (car l))
			      (argalg (nbe-object-to-type arg))
			      (prev (nbe-object-app (in-at finalg argalg)
						    obj arg))
			      (prevval (nbe-object-to-value prev)))
			 (trueval? prevval)))
		   (if (null? l)
		       reprod-obj
		       falseobj)))))
	   ((and (nbe-fam-value? val1) (nbe-fam-value? val2))
	    (let ((term1 (nbe-extract val1))
		  (term2 (nbe-extract val2)))
	      (if (and (term=? term1 term2)
		       (synt-total? term1) (synt-total? term2))
		  trueobj
		  reprod-obj)))
	   (else reprod-obj))))))))

(define (in-at finalg1 finalg2)
  (nbe-make-object
   (mk-arrow finalg1 finalg2 (make-alg "boole"))
   (lambda (obj1)
     (nbe-make-object
      (mk-arrow finalg2 (make-alg "boole"))
      (lambda (obj2)
	(let ((val1 (nbe-object-to-value obj1))
	      (val2 (nbe-object-to-value obj2)))
	  (cond
	   ((and (equal? finalg1 finalg2)
		 (trueval? (nbe-object-to-value
			    (nbe-object-app (=-at finalg1) obj1 obj2))))
	    trueobj)
	   ((nbe-constr-value? val2)
	    (do ((l (nbe-constr-value-to-args val2) (cdr l)))
		((or (null? l)
		     (let* ((arg (car l))
			    (argtype (nbe-object-to-type arg))
			    (prev (nbe-object-app (in-at finalg1 argtype)
						  obj1 arg))
			    (prevval (nbe-object-to-value prev)))
		       (trueval? prevval)))
		 (if (null? l)
		     falseobj
		     trueobj))))
	   (else falseobj))))))))

(define (finalg-to-e-const finalg)
  (if (not (finalg? finalg))
      (myerror "finalg-to-e-const" "finitary algebra expected" finalg)
      (make-const (e-at finalg)
		  "E" 'fixed-rules
		  (make-arrow finalg (make-alg "boole")) empty-subst
		  1 'prefix-op)))

(define (e-at finalg)
  (nbe-make-object
   (make-arrow finalg (make-alg "boole"))
   (lambda (obj)
     (let ((val (nbe-object-to-value obj))
	   (reprod-obj (nbe-make-object
			(make-alg "boole")
			(nbe-make-termfam
			 (make-alg "boole")
			 (lambda (k)
			   (mk-term-in-app-form
			    (make-term-in-const-form
			     (finalg-to-e-const finalg))
			    (nbe-fam-apply (nbe-reify obj) k)))))))
       (cond
	((nbe-constr-value? val)
	 (let* ((args (nbe-constr-value-to-args val))
		(argtypes (map nbe-object-to-type args))
		(prevs
		 (do ((l args (cdr l))
		      (ltypes argtypes (cdr ltypes))
		      (res
		       '()
		       (let* ((arg (car l))
			      (type (car ltypes))
			      (prev (nbe-object-app (e-at type) arg)))
			 (if (trueval? (nbe-object-to-value prev))
			     res
			     (cons prev res)))))
		     ((null? l) res))))
	   (if (null? prevs)
	       trueobj
	       (do ((l (cdr prevs) (cdr l))
		    (obj
		     (car prevs)
		     (nbe-make-object
		      (make-alg "boole")
		      (nbe-make-termfam
		       (make-alg "boole")
		       (lambda (k)
			 (mk-term-in-app-form
			  (make-term-in-const-form
			   (pconst-name-to-pconst "AndConst"))
			  (nbe-fam-apply (nbe-reify (car l)) k)
			  (nbe-fam-apply (nbe-reify obj) k)))))))
		   ((null? l) obj)))))
	((and (nbe-fam-value? val) (synt-total? (nbe-extract val)))
	 trueobj)
	(else reprod-obj))))))

(define (sfinalg-to-se-const sfinalg)
  (if (not (sfinalg? sfinalg))
      (myerror "sfinalg-to-se-const"
	       "structure finitary algebra expected"
	       sfinalg)
      (make-const (se-at sfinalg)
		  "SE" 'fixed-rules
		  (make-arrow sfinalg (make-alg "boole")) empty-subst
		  1 'prefix-op)))

(define (se-at sfinalg)
  (nbe-make-object
   (make-arrow sfinalg (make-alg "boole"))
   (lambda (obj)
     (let ((val (nbe-object-to-value obj)))
       (cond
        ((nbe-constr-value? val)
         (let* ((alg-name (alg-form-to-name sfinalg))
                (alg-names (alg-name-to-simalg-names alg-name))
                (args (nbe-constr-value-to-args val))
                (argtypes (map nbe-object-to-type args))
                (prevs
                 (do ((l args (cdr l))
                      (ltypes argtypes (cdr ltypes))
                      (res
                       '()
                       (let* ((arg (car l))
                              (type (car ltypes))
                              (prev
                               (if (and (alg-form? type)
                                        (member (alg-form-to-name type)
                                                alg-names))
                                   (nbe-object-app (se-at type) arg)
                                   '())))
                         (if (or (null? prev)
                                 (trueval? (nbe-object-to-value prev)))
                             res
                             (cons prev res)))))
                     ((null? l) res))))
           (if (null? prevs)
               trueobj
               (do ((l (cdr prevs) (cdr l))
                    (obj
                     (car prevs)
                     (nbe-make-object
                      (make-alg "boole")
                      (nbe-make-termfam
                       (make-alg "boole")
                       (lambda (k)
                         (mk-term-in-app-form
                          (make-term-in-const-form
                           (pconst-name-to-const "AndConst"))
                          (nbe-fam-apply (nbe-reify (car l)) k)
                          (nbe-fam-apply (nbe-reify obj) k)))))))
                   ((null? l) obj)))))
        ((and (nbe-fam-value? val) (synt-total? (nbe-extract val)))
	 trueobj)
        ((nbe-fam-value? val) ;reproduce
         (nbe-make-object
          (make-alg "boole")
          (nbe-make-termfam
           (make-alg "boole")
           (lambda (k)
             (mk-term-in-app-form
              (make-term-in-const-form
               (sfinalg-to-se-const sfinalg))
              (nbe-fam-apply (nbe-reify obj) k))))))
        (else (myerror "se-at" "value expected" val)))))))

; The pconst "Inhab" is a constscheme providing a canonical inhabitant
; of an arbitrary type alpha.  It can be given a concrete value.
; Example: (add-computation-rule (pt "(Inhab boole)") (pt "False"))

; (Inhab alpha) considered as total.  Reason: since every algebra is
; required to have nullary constructors, every (closed) type rho can
; be given a total canonical inhabitant.

(add-program-constant "Inhab" (py "alpha") t-deg-one)