This file is indexed.

/usr/share/acl2-7.2dfsg/books/misc/int-division.lisp is in acl2-books-source 7.2dfsg-3.

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
;  Book           int-division
;  Contributed by Matyas Sustik
;  Date created   2000-05-05
;  $Id: int-division.lisp,v 1.16 2001/09/05 19:14:10 matyas Exp $
;
;  Special thanks to Robert Bellarmine Krug and Matt Kaufmann for
;  their insight and help in simplifying the proofs.
;
;  Matt K. pointed out numerous unnecesarry hypotheses, wrongly formed
;  rewrite rules which prevented them from being used, helped to use
;  rewrite rules where I originally used forward-chaining ones.


(in-package "ACL2")
(include-book "arithmetic/equalities" :dir :system)
(include-book "arithmetic/inequalities" :dir :system)

(defun integer-quotient (a b)
  (if (and (integerp a)
	   (integerp b))
      (if (equal 0 a)
	  (if (equal 0 b)
	      1
	    nil)
	(if (integerp (/ b a))
	    (/ b a)
	  nil))
    nil))

(defthm integer-quotient-type
  (or (integerp (integer-quotient a b))
      (equal (integer-quotient a b) nil))
  :rule-classes :type-prescription)

; Should be a rewrite rule?!
(defthm integer-quotient-arg-1-type
  (implies (integerp (integer-quotient a b))
	   (equal (integerp a) t))
  :rule-classes :type-prescription)

(defthm integer-quotient-arg-2-type
  (implies (integerp (integer-quotient a b))
	   (equal (integerp b) t))
  :rule-classes :type-prescription)

(defthm integer-quotient-spec-0-0
  (equal (integer-quotient 0 0) 1))

(defthm integer-quotient-spec-a-0
  (implies (and (integerp a)
		(case-split (not (equal 0 a))))
	   (equal (integer-quotient a 0) 0)))

; Is this ever used??
(defthm integer-quotient-spec-0-b
  (implies (integerp (integer-quotient 0 b))
	   (equal 0 b))
  :rule-classes :forward-chaining)

(defthm integer-quotient-spec-a-a
  (equal (integer-quotient a a)
	 (if (integerp a)
	     1
	   nil)))

(local
 (defthm inequality-lemma-1
   (implies (and (integerp a)
		 (< 0 a)
		 (not (equal 1 a)))
	    (<= 2 a))
   :rule-classes :forward-chaining))  ; no maximal terms

(local
 (defthm inequality-lemma-2
   (implies (and (integerp a)
		 (< a 0)
		 (not (equal -1 a)))
	    (<= a -2))
   :rule-classes :forward-chaining))

(local
 (defthm inequality-lemma-3
   (implies (and (integerp (/ a))
		 (integerp a)
		 (case-split (not (equal 0 a))))
	    (or (equal 1 a)
		(equal -1 a)))
   :rule-classes :forward-chaining
   :hints (("Goal"
	    :use (inequality-lemma-1
		  inequality-lemma-2
		  (:instance inequality-lemma-1 (a (/ a)))
		  (:instance inequality-lemma-2 (a (/ a))))))))

(defthm integer-quotient-spec-a-1
  (implies (and (integerp (integer-quotient a 1)))
	   (or (equal 1 a)
	       (equal -1 a)))
  :rule-classes :forward-chaining)

(defthm integer-quotient-spec-1-b
  (equal (integer-quotient 1 b)
	 (if (integerp b)
	     b
	   nil)))

(defthm integer-quotient-commutes-with-+
  (implies (and	(integerp (integer-quotient a b))
		(integerp (integer-quotient a c))
		(case-split (not (equal 0 a))))
	   (equal (integer-quotient a (+ b c))
		  (+ (integer-quotient a b)
		     (integer-quotient a c)))))

(defthm integer-quotient-commutes-with-unary-minus-1
  (equal (integer-quotient a (- a))
	 (if (integerp a)
	     (if (equal 0 a)
		 1
	       (- 1))
	   nil)))

(defthm integer-quotient-commutes-with-unary-minus-2
  (equal (integer-quotient (- a) a)
	 (if (integerp a)
	     (if (equal 0 a)
		 1
	       (- 1))
	   nil)))

(local
 (defun ind-int-abs (n)
   (if (integerp n)
       (if (equal 0 n)
	   t
	 (if (< 0 n)
	     (ind-int-abs (+ -1 n))
	   (ind-int-abs (+ +1 n))))
     t)))

;; Is this used??
(defthm integer-quotient-commutes-with-*
  (implies (and	(integerp (integer-quotient a b))
		(case-split (not (equal 0 b)))
		(integerp c))
	   (equal (integer-quotient a (* b c))
		  (* (integer-quotient a b) c)))
  :hints (("Goal" :induct (ind-int-abs c))))

(in-theory (disable integer-quotient-commutes-with-*))

(defthm integer-quotient-commutes-with-*-alt
  (equal (integer-quotient a (* b c))
	 (if (and (integerp (integer-quotient a b))
		  (case-split (not (equal 0 b)))
		  (integerp c))
	     (* (integer-quotient a b) c)
	   (integer-quotient a (* b c))))
  :hints (("Goal" :induct (ind-int-abs c))))

; Is this used??
(defthm integer-quotient-*-cancellation
  (implies (and (integerp a)
		(case-split (not (equal 0 a)))
		(integerp q))
	   (equal (integer-quotient a (* a q)) q)))

(local
 (defthm crap001
   (implies (and (integerp a)
		 (integerp b)
		 (integerp c)
		 (not (equal 0 a))
		 (not (equal 0 b)))
	    (equal (* (/ b a) (/ c b))
		   (/ c a)))
   :rule-classes nil))

(local
 (defthm crap002
   (implies (and (integerp a)
		 (integerp b))
	    (integerp (* a b)))
   :rule-classes :type-prescription))

; Care must be taken when formulating the next lemma.  In order for
; ACL2 to use it automatically the first term should include the free
; variable b.  Furthermore the conclusion must have exactly (* (/ a)
; c)) and not (* c (/ a)) or (/ c a).  Note that when storing a rule
; ACL2 does not normalize the terms, therefore to have successful
; match the user has to do the work.
 (defthm crap003
   (implies (and (integerp (* (/ a) b))
		 (integerp a)
		 (integerp b)
		 (integerp c)
		 (not (equal 0 a))
		 (not (equal 0 b))
		 (integerp (/ c b)))
	    (integerp (* (/ a) c)))
   :hints (("Goal"
	    :use (crap001
		  (:instance crap002
			     (a (/ b a))
			     (b (/ c b)))))))

(defthm integer-quotient-factorization
  (implies (and (integerp a)
		(integerp b)
		(integerp c)
		(case-split (not (equal 0 a)))
		(case-split (not (equal 0 b)))
		(integerp (integer-quotient a b))
		(integerp (integer-quotient b c)))
  (equal (* (integer-quotient a b) (integer-quotient b c))
	 (integer-quotient a c))))

(defun divides (a b)
  (and (integerp a)
       (integerp b)
       (equal b (* a (integer-quotient a b)))))

; The type of divides is deduced automatically.

(defthm divides-integer-quotient-equivalence
  (equal (divides a b)
	 (and (integerp a)
	      (integerp b)
	      (integerp (integer-quotient a b))
	      (equal b (* a (integer-quotient a b))))))

(in-theory (disable divides))

(defthm divides-spec-0-0
  (divides 0 0))

(defthm divides-spec-a-0
  (implies (integerp a)
	   (divides a 0)))

(defthm divides-spec-0-b
  (implies (divides 0 b)
	   (equal 0 b))
  :rule-classes :forward-chaining)

(defthm divides-spec-a-1
  (implies (divides a 1)
	   (or (equal 1 a)
	       (equal -1 a)))
  :rule-classes :forward-chaining)

(defthm divides-spec-1-b
  (implies (integerp b)
	   (divides 1 b)))

(defthm divide-sum
  (implies (and	(divides d a)
		(divides d b))
	   (divides d (+ a b))))

; Is this needed?
(defthm divide-factor
  (implies (and (equal b (* a q))
		(integerp a)
		(integerp q))
	   (divides a b)))

; Is this used??
(defthm divides-reflexivity
  (implies (integerp a)
	   (divides a a)))

(defthm divide-product
  (implies (and	(integerp b)
		(divides d a))
	   (divides d (* a b)))
  :hints (("Goal"
	   :use ((:Instance crap002
			    (a (* a (/ d))))))))

(defthm divide-factorization
  (implies (divides a b)
	   (equal (* a (integer-quotient a b))
		  b)))

(in-theory (disable divide-factorization))

(local
 (defthm inequality-lemma-4
   (implies (and (integerp a)
		 (< 0 a)
		 (integerp q)
		 (< 0 q))
	    (<= a (* a q)))
   :rule-classes :forward-chaining))

(in-theory (disable integer-quotient))

(defthm divider-<
  (implies (and (divides a b)
		(integerp a)
		(<= 0 a)
		(integerp b)
		(< 0 b))
	   (<= a b))
  :rule-classes :forward-chaining
  :hints (("Goal"
	   :use ((:instance inequality-lemma-4
			    (q (integer-quotient a b)))))))

(in-theory (enable integer-quotient))

(defthm divide-transitivity
  (implies (and (divides a b)
		(divides b c))
	   (divides a c))
  :hints (("Goal"
	   :in-theory (enable integer-quotient)
	   :use crap003)))

(defthm equality-from-division
  (implies (and (divides a b)
		(divides b a)
		(integerp a)
		(< 0 a)
		(integerp b)
		(< 0 b))
	   (equal a b))
  :rule-classes :forward-chaining
  :hints (("Goal"
	   :in-theory (disable divider-<)
	   :use (divider-<
		 (:instance divider-<
			   (a b)
			   (b a))))))

(defthm divide-linear-combination
  (implies (and (integerp x)
		(integerp y))
	   (implies (and (divides d a)
			 (divides d b))
		    (divides d (+ (* a x) (* b y))))))

(in-theory (disable divides))
(in-theory (disable integer-quotient))