source: CGBLisp/src/RCS/prover.lisp,v@ 1

Last change on this file since 1 was 1, checked in by Marek Rychlik, 15 years ago

First import of a version circa 1997.

File size: 8.3 KB
Line 
1head 1.3;
2access;
3symbols;
4locks; strict;
5comment @;;; @;
6
7
81.3
9date 2009.01.22.04.06.51; author marek; state Exp;
10branches;
11next 1.2;
12
131.2
14date 2009.01.19.09.30.03; author marek; state Exp;
15branches;
16next 1.1;
17
181.1
19date 2009.01.19.07.52.10; author marek; state Exp;
20branches;
21next ;
22
23
24desc
25@@
26
27
281.3
29log
30@*** empty log message ***
31@
32text
33@;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: Grobner; Base: 10 -*-
34#|
35 $Id$
36 *--------------------------------------------------------------------------*
37 | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@@math.arizona.edu) |
38 | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
39 | |
40 | Everyone is permitted to copy, distribute and modify the code in this |
41 | directory, as long as this copyright note is preserved verbatim. |
42 *--------------------------------------------------------------------------*
43|#
44(defpackage "PROVER"
45 (:use "COMMON-LISP" "GROBNER" "PARSE" "ORDER" "COEFFICIENT-RING" "PRINTER")
46 (:export identical-points perpendicular parallel collinear translate-theorem prove-theorem
47 equidistant midpoint translate-statements real-identical-points
48 euclidean-distance
49 *prover-order*))
50
51(in-package "PROVER")
52
53#+debug(proclaim '(optimize (speed 0) (debug 3)))
54#-debug(proclaim '(optimize (speed 3) (safety 0)))
55
56(defvar *prover-order* #'grevlex>
57 "Admissible monomial order used internally in the proofs of theorems.")
58
59;; Translate a geometric theorem specification into a statement of the
60;; form
61;; for all u1, u2, ... , us f1=f2=...=fn=0 => g=0
62
63(defun csym (symbol number)
64 "Return symbol whose name is a concatenation of (SYMBOL-NAME SYMBOL)
65and a number NUMBER."
66 (intern (concatenate 'string (symbol-name symbol) (format nil "~d" number))))
67
68(defmacro real-identical-points (A B)
69 "Return [ (A1-B1)**2 + (A2-B2)**2 ] in lisp (prefix) notation.
70The second value is the list of variables (A1 B1 A2 B2). Note that
71if the distance between two complex points A, B is zero, it does not
72mean that the points are identical. Use IDENTICAL-POINTS to express
73the fact that A and B are really identical. Use this macro in conclusions
74of theorems, as it may not be possible to prove that A and B are trully
75identical in the complex domain."
76 (let ((A1 (csym A 1))
77 (A2 (csym A 2))
78 (B1 (csym B 1))
79 (B2 (csym B 2)))
80 `(list
81 '((+ (expt (- ,A1 ,B1) 2) (expt (- ,A2 ,B2) 2)))
82 '(,A1 ,A2 ,B1 ,B2))))
83
84(defmacro identical-points (A B)
85 "Return [ A1-B1, A2-B2 ] in lisp (prefix) notation.
86The second value is the list of variables (A1 B1 A2 B2). Note that
87sometimes one is able to prove only that (A1-B1)**2 + (A2-B2)**2 = 0.
88This equation in the complex domain has solutions with A and B distinct.
89Use REAL-IDENTICAL-POINTS to express the fact that the distance between
90two points is 0. Use this macro in assumptions of theorems, although this
91is seldom necessary because we assume most of the time that in assumptions
92all points are distinct if they are denoted by different symbols."
93 (let ((A1 (csym A 1))
94 (A2 (csym A 2))
95 (B1 (csym B 1))
96 (B2 (csym B 2)))
97 `(list
98 '((- ,A1 ,B1) (- ,A2 ,B2))
99 '(,A1 ,A2 ,B1 ,B2))))
100
101(defmacro perpendicular (A B C D)
102 "Return [ (A1-B1) * (C1-D1) + (A2-B2) * (C2-D2) ] in lisp (prefix) notation.
103The second value is the list of variables (A1 A2 B1 B2 C1 C2 D1 D2)."
104 (let ((A1 (csym A 1))
105 (A2 (csym A 2))
106 (B1 (csym B 1))
107 (B2 (csym B 2))
108 (C1 (csym C 1))
109 (C2 (csym C 2))
110 (D1 (csym D 1))
111 (D2 (csym D 2)))
112 `(list
113 '((+ (* (- ,A1 ,B1) (- ,C1 ,D1))
114 (* (- ,A2 ,B2) (- ,C2 ,D2))))
115 '(,A1 ,A2 ,B1 ,B2 ,C1 ,C2 ,D1 ,D2))))
116
117(defmacro parallel (A B C D)
118 "Return [ (A1-B1) * (C2-D2) - (A2-B2) * (C1-D1) ] in lisp (prefix) notation.
119The second value is the list of variables (A1 A2 B1 B2 C1 C2 D1 D2)."
120 (let ((A1 (csym A 1))
121 (A2 (csym A 2))
122 (B1 (csym B 1))
123 (B2 (csym B 2))
124 (C1 (csym C 1))
125 (C2 (csym C 2))
126 (D1 (csym D 1))
127 (D2 (csym D 2)))
128 `(list
129 '((- (* (- ,A1 ,B1) (- ,C2 ,D2))
130 (* (- ,A2 ,B2) (- ,C1 ,D1))))
131 '(,A1 ,A2 ,B1 ,B2 ,C1 ,C2 ,D1 ,D2))))
132
133
134(defmacro collinear (A B C)
135 "Return the determinant det([[A1,A2,1],[B1,B2,1],[C1,C2,1]]) in lisp (prefix) notation.
136The second value is the list of variables (A1 A2 B1 B2 C1 C2)."
137 (let ((A1 (csym A 1))
138 (A2 (csym A 2))
139 (B1 (csym B 1))
140 (B2 (csym B 2))
141 (C1 (csym C 1))
142 (C2 (csym C 2)))
143 `(list
144 '((+ (- (* ,B1 ,C2) (* ,B2 ,C1))
145 (- (* ,A2 ,C1) (* ,A1 ,C2))
146 (- (* ,A1 ,B2) (* ,A2 ,B1))))
147 '(,A1 ,A2 ,B1 ,B2 ,C1 ,C2))))
148
149(defmacro equidistant (A B C D)
150 "Return the polynomial [(A1-B1)**2+(A2-B2)**2-(C1-D1)**2-(C2-D2)**2] in lisp (prefix)
151notation. The second value is the list of variables (A1 A2 B1 B2 C1 C2 D1 D2)."
152 (let ((A1 (csym A 1))
153 (A2 (csym A 2))
154 (B1 (csym B 1))
155 (B2 (csym B 2))
156 (C1 (csym C 1))
157 (C2 (csym C 2))
158 (D1 (csym D 1))
159 (D2 (csym D 2)))
160 `(list
161 '((- (+ (expt (- ,A1 ,B1) 2) (expt (- ,A2 ,B2) 2))
162 (+ (expt (- ,C1 ,D1) 2) (expt (- ,C2 ,D2) 2))))
163 '(,A1 ,A2 ,B1 ,B2 ,C1 ,C2 ,D1 ,D2))))
164
165(defmacro euclidean-distance (A B R)
166 "Return the polynomial [(A1-B1)**2+(A2-B2)**2-R^2] in lisp (prefix)
167notation. The second value is the list of variables (A1 A2 B1 B2 R)."
168 (let ((A1 (csym A 1))
169 (A2 (csym A 2))
170 (B1 (csym B 1))
171 (B2 (csym B 2)))
172 `(list
173 '((- (+ (expt (- ,A1 ,B1) 2) (expt (- ,A2 ,B2) 2))
174 (expt ,R 2)))
175 '(,A1 ,A2 ,B1 ,B2 ,R))))
176
177(defmacro midpoint (A B C)
178 "Express the fact that C is a midpoint of the segment AB.
179Returns the list [ 2*C1-A1-B1, 2*C2-A2-B2 ]. The second value returned is the list
180of variables (A1 A2 B1 B2 C1 C2)."
181 (let ((A1 (csym A 1))
182 (A2 (csym A 2))
183 (B1 (csym B 1))
184 (B2 (csym B 2))
185 (C1 (csym C 1))
186 (C2 (csym C 2)))
187 `(list
188 '((- (* 2 ,C1) ,A1 ,B1) (- (* 2 ,C2) ,A2 ,B2))
189 '(,A1 ,A2 ,B1 ,B2 ,C1 ,C2))))
190
191(defmacro translate-statements (&rest statements)
192 `(list (mapcar #'car (list ,@@statements))
193 (remove-duplicates (apply #'append (mapcar #'cadr (list ,@@statements))))))
194
195(defmacro translate-assumptions (&rest assumptions)
196 (let ((x (gensym)))
197 `(let ((,x (translate-statements ,@@assumptions)))
198 (list (apply #'append (car ,x))
199 (cadr ,x)))))
200
201(defmacro translate-conclusions (&rest conclusions)
202 `(translate-statements ,@@conclusions))
203
204(defmacro translate-theorem ((&rest assumptions) (&rest conclusions))
205 "Translates a planar geometry theorem into a system of polynomial equations.
206Each assumption or conclusion takes form of a declaration (RELATION-NAME A B C ...)
207where A B C are points, entered as symbols and RELATION-NAME is a name of
208a geometric relation, for example, (COLLINEAR A B C) means that points A, B, C
209are all collinear. The translated equations use the convention that (A1,A2)
210are the coordinates of the point A. This macro returns multiple values.
211The first value is a list of polynomial expressions and the second value
212is an automatically generated list of variables from points A, B, C, etc.
213For convenience, several macros have been defined in order to make specifying
214common geometric relations easy."
215 `(values
216 (translate-assumptions ,@@assumptions)
217 (translate-conclusions ,@@conclusions)))
218
219(defmacro prove-theorem ((&rest assumptions) (&rest conclusions)
220 &key (order *prover-order*))
221 "Proves a geometric theorem, specified in the same manner as in
222the macro TRANSLATE-THEOREM. The proof is achieved by a call to
223IDEAL-POLYSATURATION. The theorem is true if the returned value
224is a trivial ideal containing 1."
225 (let ((vars (gensym))
226 (ideal (gensym))
227 (assump (gensym))
228 (concl (gensym)))
229 `(multiple-value-bind (,assump ,concl)
230 (translate-theorem ,assumptions ,conclusions)
231 (let* ((,vars (union (second ,assump) (second ,concl)))
232 (,ideal (ideal-polysaturation
233 (cdr (poly-eval `(:[ ,@@(car ,assump)) ,vars
234 ,order *ring-of-integers*))
235 (mapcar #'(lambda (x)
236 (cdr (poly-eval (cons :[ x) ,vars
237 ,order *ring-of-integers*)))
238 (car ,concl))
239 ,order
240 0
241 nil
242 *ring-of-integers*)))
243 (poly-print (cons '[ ,ideal) ,vars)
244 (values)))))
245@
246
247
2481.2
249log
250@*** empty log message ***
251@
252text
253@d21 2
254a22 2
255;;(proclaim '(optimize (speed 0) (debug 3)))
256(proclaim '(optimize (speed 3) (safety 0)))
257@
258
259
2601.1
261log
262@Initial revision
263@
264text
265@d3 1
266a3 1
267 $Id: prover.lisp,v 1.51 1997/12/13 16:36:30 marek Exp $
268d21 2
269a22 1
270(proclaim '(optimize (speed 0) (debug 3)))
271@
Note: See TracBrowser for help on using the repository browser.