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