summaryrefslogtreecommitdiff
path: root/books/workshops/2006/cowles-gamboa-euclid/Euclid/fld-u-poly/fuopuesto.lisp
blob: 790f562df57e9e5477128d81459ca4dfe9ce397b (plain)
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
; ACL2 Univariate Polynomials over a Field books -- Unary Minus
;; Unary Minus of Univariate Polynomials over a Field
; Copyright (C) 2006  John R. Cowles and Ruben A. Gamboa, University of
; Wyoming

; This book is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.

; This book is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.

; You should have received a copy of the GNU General Public License
; along with this book; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;; Modified by J. Cowles

;;   Last modified July 2006 (for ACL2 Version 3.0).

;; Based on
;;; ------------------------------------------------------------------
;;; Opuesto de polinomios
;;;
;;; Autores:
;;;
;;; Inmaculada Medina Bulo
;;; Francisco Palomo Lozano
;;;
;;; Descripci�n:
;;;
;;; Desarrollo del opuesto de un polinomio, que se define monomio a
;;; monomio. Su correcci�n se prueba demostrando que la funci�n que lo
;;; calcula produce el inverso aditivo. Para que �stas y otras
;;; propiedades sean incondicionales (carezcan de hip�tesis) se
;;; completa cuidadosamente la definici�n de la funci�n. Se demuestra
;;; que los polinomios con las operaciones de suma y opuesto forman un
;;; grupo conmutativo.
;;; ------------------------------------------------------------------
#|
To certify this book, first, create a world with the following packages:

(in-package "ACL2")

(defconst *import-symbols*
  (set-difference-eq
   (union-eq *acl2-exports*
	     *common-lisp-symbols-from-main-lisp-package*)
     '(null + * - < = / commutativity-of-* associativity-of-*
	    commutativity-of-+ associativity-of-+ distributivity)))

(defpkg "FLD"
  *import-symbols*)

(defpkg "FUTER"
  *import-symbols*)

(defpkg "FUMON"
  (union-eq *import-symbols*
	    '(FLD::fdp FUTER::terminop)))

(defpkg "FUPOL"
  (union-eq *import-symbols*
	    '(FUTER::naturalp FUTER::terminop FUMON::monomio FUMON::coeficiente
			    FUMON::termino FUMON::monomiop)))

(certify-book "fuopuesto"
	      5
	      nil ;;compile-flg
	      )
|#
(in-package "FUPOL")

;;(include-book "congruencias-suma")
(include-book "fucongruencias-suma"
	      :load-compiled-file nil)

;;; ---------------------
;;; Opuesto de polinomios
;;; ---------------------

;;; La siguiente desactivaci�n es necesaria para la verificaci�n de la
;;; protecci�n del opuesto

(in-theory (disable FUMON::monomio-coeficiente-termino))

(defun - (p)
  (cond ((or (not (polinomiop p)) (nulop p))
	 (nulo))
	(t
	 (+M (FUMON::- (primero p)) (- (resto p))))))

(in-theory (enable FUMON::monomio-coeficiente-termino))

;;; Clausura

(defthm polinomiop--
  (polinomiop (- p))
  :rule-classes (:type-prescription
		 :rewrite))

;;; Distributividad respecto de la suma de monomio y polinomio

(defthm |- p =e (- mp(p)) +M (- (resto(p)))|
  (implies (and (polinomiop (double-rewrite p))
		(not (nulop p)))
	   (equal (- p)
		  (+M (FUMON::- (primero p)) (- (resto p))))))

;;; Inverso de la suma

(defthm |m +M (- m +M 0) = 0|
  (implies (monomiop (double-rewrite m))
	   (= (+M m (+M (FUMON::- m) (nulo)))
	      (nulo))))

(defthm |p + (- p) = 0|
  (= (+ p (- p)) (nulo))
  :hints (("Goal"
	   :in-theory (disable = + +M - FUMON::-)
	   :induct (fn p))
	  ("Subgoal *1/1" :in-theory (enable = + +M))
	  ("Subgoal *1/2"
	   :use ((:instance |p + q = q + p|
			    (p (+M (FUMON::- (primero p)) (- (resto p))))
			    (q (resto p)))))))

;;; Distributividad respecto de la suma en orden de monomio y
;;; polinomio

;; (defthm |- (m +Mo p) =e (- m) +Mo (- p)|
;;   (implies (and (monomiop (double-rewrite m))
;; 		(polinomiop (double-rewrite p)))
;; 	   (equal (- (+-monomio m p))
;; 		  (+-monomio (FUMON::- m) (- p)))))

(defthm |- (m +Mo p) =P (- m) +Mo (- p)|
  (implies (and (monomiop (double-rewrite m))
		(polinomiop (double-rewrite p)))
	   (=P (- (+-monomio m p))
	       (+-monomio (FUMON::- m) (- p)))))

;;; -------------------------------------------------------
;;; Congruencia de la igualdad de polinomios con el opuesto
;;; -------------------------------------------------------

(defthm
  |FUMON::nulop_-|
  (implies (monomiop (double-rewrite m))
	   (equal (FUMON::nulop (FUMON::- m))
		  (FUMON::nulop m))))

(defthm
  =P-implies-=P_-
  (implies (=P p1 p2)
	   (=P (- p1)
	       (- p2)))
  :rule-classes :congruence)

(defthm
  Ordenadop_-
  (implies (ordenadop p)
	   (ordenadop (- p))))

;; (local
;;   (defthm |fn(- p) = - fn(p)|
;;     (equal (fn (- p)) (- (fn p)))
;;     :hints (("Goal" :in-theory (disable MON::- )))))

(local
  (defthm |fn(- p) =P - fn(p)|
    (=P (fn (- p)) (- (fn p)))
    :hints (("Goal" :in-theory (disable FUMON::- )))))

;; (defcong = = (- p) 1)

(defthm
  =-implies-=_-
  (implies (= p1 p2)
	   (= (- p1)
	      (- p2)))
  :rule-classes :congruence)

;;; ---------------
;;; Desactivaciones
;;; ---------------

(local (in-theory (disable polinomiop = + -)))

;;; -----------------------------------------------------------------------
;;; El inverso debe ser invisible para la primera operaci�n y para s� mismo
;;; -----------------------------------------------------------------------
(ACL2::set-invisible-fns-table ((+ -) (- -)))


;;; El opuesto de una suma de polinomios es la suma de los opuestos.

(defthm |p + r = q + r <=> p = q|
  (implies (and (polinomiop (double-rewrite p))
		(polinomiop (double-rewrite q)))
	   (iff (= (+ p r) (+ q r)) (= p q)))
  :hints (("Goal"
	   :in-theory (disable |p + q = q + p| |p + 0 = p|)
	   :use ((:instance |p + q = q + p| (p (+ p r)) (q (- r)))
	         (:instance |p + q = q + p| (p (- r)) (q (+ q r)))
		 (:instance |p + 0 = p| (p q))
		 |p + 0 = p|))))

(local
  (defthm |p + q = q <=> p = 0|
    (implies (and (polinomiop (double-rewrite p))
		  (polinomiop (double-rewrite q)))
	     (iff (= (+ p q) q) (= p (nulo))))
    :hints (("Goal"
	     :in-theory (disable |p + r = q + r <=> p = q|)
	     :use (:instance |p + r = q + r <=> p = q| (q (nulo)) (r q))))))

(local
  (defthm |p + q = 0 <=> q = - p|
    (implies (and (polinomiop (double-rewrite p))
		  (polinomiop (double-rewrite q)))
	     (iff (= (+ p q) (nulo)) (= q (- p))))
    :hints (("Goal"
	     :in-theory (disable |p + r = q + r <=> p = q|)
	     :use (:instance |p + r = q + r <=> p = q| (p q) (q (- p)) (r p))))))

;;; Mezcla de asociatividad y conmutatividad

(defthm |p + (q + r) = q + (p + r)|
  (= (+ p (+ q r)) (+ q (+ p r)))
  :hints (("Goal"
	   :in-theory (disable |(p + q) + r = p + (q + r)|)
	   :use (|(p + q) + r = p + (q + r)|
		 (:instance |(p + q) + r = p + (q + r)| (p q) (q p))))))

;;; Idempotencia del inverso

(defthm |- (- p) = p|
  (implies (polinomiop (double-rewrite p))
	   (= (- (- p)) p))
  :hints (("Goal"
	   :in-theory (disable |p + q = 0 <=> q = - p|)
	   :use (:instance |p + q = 0 <=> q = - p| (p (- p)) (q p)))))

;;; Distributividad de la inversa sobre la primera operaci�n

(defthm |- (p + q) = (- p) + (- q)|
  (= (- (+ p q)) (+ (- p) (- q)))
  :hints (("Goal"
	   :in-theory (disable |p + q = 0 <=> q = - p|)
	   :use (:instance |p + q = 0 <=> q = - p| (p (+ p q)) (q (+ (- p) (- q)))))))