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