1 ;;; -*- mode: lisp; package: cl-maxima; syntax: common-lisp; -*-
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;;; Copyright (c) 1984 by William Schelter,University of Texas ;;;;;
5 ;;; All rights reserved ;;;;;
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10 ;;returns the I'th open of the blowup of the FIRSTK coord of ZOPEN
11 (defun iblowup (zopen i firstk
&aux ichart pss qss ineq answ
)
12 (setq ichart
(ichart i firstk
(zopen-dim zopen
)))
13 (setq pss
(compose-rmap (zopen-coord ichart
)
19 (setq ineq
(function-numerator (apply-rmap (zopen-inv ichart
) (zopen-inequality zopen
))))
20 (setq answ
(zl-copy-structure zopen zopen- coord pss inv qss inequality ineq
))
23 (defun s-blow ( simp-pls open-number component-number
)
25 (pls empty-opens codim
)
26 (normalize-pls simp-pls open-number component-number
)
27 (show empty-opens codim
)
28 (simplify-svar-ldata (blowup-sheaf pls codim
:opens-not-to-blowup empty-opens
))))
30 (defun high-dimensional-component (pls &aux tem ld-num
)
31 (loop for open-number from
0
32 for lis-dat in
(pls-data pls
)
33 with min-open-number
= 0
35 do
(loop for v in lis-dat
37 when
(< (setq tem
(length (ldata-eqns v
))) prev-min
)
38 do
(setq min-open-number open-number ld-num ld-number
)
40 finally
(return (values (list min-open-number ld-num
) prev-min
))))
42 (defmacro vformat
(&rest l
)
43 `(cond (*verbose
* (format t
,@ l
))
46 (defmacro vdes
(&rest l
)
47 `(cond (*verbose
* (des ,@ l
))
50 (defun blowup-pls-using-high-dimensional-components (pls n
&key
(one-open t
) already-blown-up
&aux
(current-pls pls
) op codim
)
52 (loop for i from n while
(pls-data current-pls
)
53 with new-pls
= current-pls
54 with red-pls
= current-pls
56 when
(null first-time
)
58 (vformat t
"reduced pls:")
60 (vformat t
"homogeneous simplified pls:")
61 ;;if keeping more than one open the current-pls will be simplified inside blowup
62 ;;since that way we only simplify opens blownup.
63 (cond (one-open (setq current-pls
(simplify-svar-homogeneous current-pls
))))
65 (cond ((null (pls-data red-pls
))
66 (return (list blew-up i
))))
67 (multiple-value (op codim
) (high-dimensional-component red-pls
))
69 (format t
"~%The ~A blowup: the ~A component of the ~A open of codimension ~A."
70 i
(second op
) (car op
) codim
)
71 (setq new-pls
(blowup-pls current-pls
(nth (car op
) (pls-opens red-pls
))
72 (ldata-eqns (nth (second op
)
73 (nth (car op
) (pls-data red-pls
))))
74 :simplify-homogeneous
(null one-open
)))
77 collecting
(list (format nil
"Before the ~A blowup the homogeneous equations on one of the nontrivial opens looked like :" i
)
78 current-pls
) into blew-up
80 collecting
(list (format nil
"~%The ~A blowup was by the ~A ldata of the following open:" i
(second op
)) (open-sub-scheme red-pls
(car op
)))
85 for ope in
(pls-opens new-pls
)
87 (setq red-pls
(simplify-svar-ldata (open-sub-scheme new-pls ii
)))
88 (show ii
(length (pls-data red-pls
)))
89 (format t
"Open history: ~A" (zopen-history (car (pls-opens current-pls
))))
90 when
(pls-data red-pls
)
92 (cond (one-open (setq current-pls
(open-sub-scheme new-pls ii
)))
93 (t (setq current-pls new-pls
)))
94 (format t
"~%Taking the ~A open with history " ii
)
96 else do
(format t
"~%The ~A open is empty")
97 finally
(return-from sue
(append already-blown-up blew-up
)))
98 finally
(return (list (append already-blown-up blew-up
) i
)))))
100 ;(defun blowup-pls-using-choices (pls n &key (query-user t) (one-open t) already-blown-up
101 ; (number-to-reduce 3) &aux (current-pls pls) choice
103 ; (loop named sue for i from n while (pls-data current-pls)
104 ; with new-pls = current-pls
105 ;; with red-pls = current-pls
106 ; with first-time = t
107 ; when (null first-time)
109 ; (cond ((null query-user)
110 ; (vformat t "Going to blowup wrt to reduced pls:")
112 ; (vformat t "homogeneous simplified pls:")))
114 ; ;;if keeping more than one open the current-pls will be simplified inside blowup
115 ; ;;since that way we only simplify opens blownup.
116 ; (cond (one-open (setq current-pls (simplify-svar-homogeneous current-pls))))
118 ;; (cond ((null (pls-data red-pls))
119 ;; (return (list blew-up i))))
120 ;; (multiple-value ( op codim)
121 ;; (high-dimensional-component red-pls))
123 ; (cond ((null query-user)
124 ; (format t "~%The ~A blowup: The coordinates and the equations" i)
125 ; (des (second choice)) (des (third choice))))
126 ; (setq new-pls (blowup-pls current-pls (second choice)
127 ; (ldata-eqns (third choice))
128 ; :simplify-homogeneous t))
130 ; collecting (list (format nil "Before the ~A blowup the homogeneous equations ~
131 ; on one of the nontrivial opens looked like :" i)current-pls)
135 ; (format nil "~%The ~A blowup was by :"
136 ; i ) (second choice) (third choice))
141 ; (setq first-time nil)
143 ; (provide-some-choices-to-blowup new-pls :query-user query-user :number-to-reduce number-to-reduce))
144 ; (cond ((null (third choice))(return-from sue (append already-blown-up blew-up))))
146 ; (loop for op in (pls-opens new-pls)
148 ; do (setq current-op-number op-num)
149 ; when (zopen-equal op (second choice))
150 ; do (setq current-pls (open-sub-scheme new-pls op-num))
152 ; (finally (merror "could not find the open"))))
153 ; (t (setq current-pls new-pls)))
154 ; finally (return-from sue (append already-blown-up blew-up))))
155 (defvar *blew-up
* nil
)
156 (defvar *previous-blowups
* nil
)
160 (defun eliminate-empty-and-larger-opens ( pls
&aux pairs
)
161 (loop for v in
(pls-opens pls
)
162 for lis-dat in
(pls-data pls
)
164 collecting
(cons v lis-dat
) into paired-dat
166 ; (setq paired-dat (eliminate-smaller paired-dat :key 'car
167 ; :test 'zopen-special-subset))
168 (return (construct-pre-ldata-sheaves :opens
(mapcar 'car paired-dat
)
169 :data
(mapcar 'cdr paired-dat
)))))
170 (defvar *query-user
* t
)
172 (defun blowup-pls-using-choices (pls n
&key
(query-user t
) (one-open t
) already-blown-up
173 (number-to-reduce 3) &aux
(current-pls pls
) choice
176 (setq *query-user
* query-user
)
177 (loop named sue for i from n while
(pls-data current-pls
)
178 with new-pls
= current-pls
180 when
(null first-time
)
182 (cond ((null query-user
)
183 (vformat t
"Going to blowup wrt to reduced pls:")
185 (vformat t
"homogeneous simplified pls:")))
187 ;;if keeping more than one open the current-pls will be simplified inside blowup
188 ;;since that way we only simplify opens blownup.
189 ; (cond (one-open (setq current-pls (simplify-svar-homogeneous current-pls))))
191 (loop for vch on choices
192 do
(setq choice
(car vch
))
194 (cond ((null query-user
)
195 (format t
"~%The ~A blowup: The coordinates and the equations" i
)
196 (des (second choice
)) (des (third choice
))))
198 (setq new-pls
(blowup-pls current-pls
(second choice
)
199 (ldata-eqns (third choice
))
200 :simplify-homogeneous t
)))
202 (setq new-pls
(eliminate-empty-and-larger-opens new-pls
))
204 finally
(fsignal "Ran out of choices"))
207 (format nil
"~%The ~A blowup was by equations on the ~A open :"
208 i current-op-number
) (second choice
) (third choice
))
211 collecting
(list (format nil
"After the ~A blowup the homogeneous equations ~
212 on one of the nontrivial opens looked like :" i
)new-pls
)
214 and do
(setq *blew-up
* blew-up
)
215 do
(push *blew-up
* *previous-blowups
*) (setq *blew-up
* blew-up
)
216 ; (user:write-object "Alonzo:wfs>blew-up.tem" (nthcdr (- (length *blew-up*) 2) *blew-up*))
217 (setq first-time nil
)
219 (provide-some-choices-to-blowup new-pls
220 :query-user query-user
221 :number-to-reduce number-to-reduce
))
222 (cond ((null choices
)(return-from sue
(append already-blown-up blew-up
))))
223 (setq choice
(car choices
))
224 (loop for op in
(pls-opens new-pls
)
226 do
(setq current-op-number op-num
)
227 when
(zopen-special-subset (second choice
) op
)
229 (finally (fsignal "could not find the open")))
230 (cond (one-open (setq current-pls
(open-sub-scheme new-pls
232 (t (setq current-pls new-pls
)))
233 finally
(return-from sue
(append already-blown-up blew-up
))))
234 (defun restart-blowup ( &key part use-blewup one-open query-user
(after 0) (number-to-reduce 3) &aux pls
)
235 (cond (part (setq pls
(second part
))
236 (blowup-pls-using-choices pls after
:query-user query-user
:one-open one-open
237 :already-blown-up
(list part
) :number-to-reduce
241 (let ((las (nth (1- (length *blew-up
*)) *blew-up
*))
242 (blas (nth (- (length *blew-up
*) 2) *blew-up
*))
243 (n (quotient (length *blew-up
*) 2)))
244 (cond ((search "after" (car las
) :test
#'char-equal
) (setq pls
(second las
)))
245 (t (setq pls
(second blas
)) (setq *blew-up
* (butlast *blew-up
*))))
246 (blowup-pls-using-choices pls n
:query-user query-user
:one-open one-open
247 :number-to-reduce number-to-reduce
248 :already-blown-up
*blew-up
*)))))
251 ;(defun restart-blowup (&key one-open query-user after &aux pls)
252 ; (let ((las (nth (1- (length *blew-up*)) *blew-up*))
253 ; (blas (nth (- (length *blew-up*) 2) *blew-up*))
254 ; (n (quotient (length *blew-up*) 2)))
255 ; (cond ((search "after" (car las) :test #'char-equal) (setq pls (second las)))
256 ; (t (setq pls (second blas)) (setq *blew-up* (butlast *blew-up*))))
257 ; (blowup-pls-using-choices pls n :query-user query-user :one-open one-open
258 ; :already-blown-up *blew-up*)))
259 (defun gen-pcomplexity (lis)
261 ((affine-polynomialp lis
) (pcomplexity lis
))
262 ((rational-functionp lis
) (+ (pcomplexity (num lis
))
263 (pcomplexity (denom lis
))))
264 ((listp lis
) (loop for v in lis summing
(gen-pcomplexity v
)))
265 (t (merror "don't know how complex"))))
267 ;(defmacro user-supply (var)
268 ; `(let ((*print-level* 3) ( prinlength 3) .new.)
271 ; (format t "~%The value of ~A is ~A ." ',var ,var)
272 ; (format t "~%Supply a form to evaluate to use for ~A or 'keep to keep same :" ',var)
273 ; (setq .new. (eval (read)))
274 ; (cond ((eq .new. 'keep)(return ,var))
276 ; (format t "~%Use ~A?" .new.)
277 ; (cond ((y-or-n-p )(return (setq ,var .new.)))))))))
281 (defvar *reduced-history
* nil
)
282 ;;returns an ordered list of choices..
283 (defun provide-some-choices-to-blowup (new-pls &key
(query-user t
) (number-to-reduce 3)
284 &aux component-number an-open-number a-red-pls
285 n len red-pls choices red-choices pcomp min-pcomp some-red-pls the-min comp-eqns min-comp number-eqns opens-not-to-try the-max
286 opens-to-try
(check-the-worst t
) where-complex where-the-max answ
)
288 ((or (null query-user
)
289 (yes-or-no-p " Simplify and provide choices of open and equation "))
290 (loop for lis-ld in
(pls-data new-pls
)
292 collecting
(setq len
(length (ldata-eqns (car lis-ld
)))) into tem
294 collecting
(setq pcomp
295 (gen-pcomplexity (ldata-eqns (car lis-ld
))))
297 else collecting
0 into tem
298 and collecting
0 into tem1
300 minimize len into the-min1
302 maximize len into the-max1
304 minimize pcomp into min-pcomp1
306 maximize pcomp into max-pcomp1
307 finally
(setq the-min the-min1 min-pcomp min-pcomp1 number-eqns tem
308 comp-eqns tem1 the-max the-max1
)
309 (setq where-complex
(find-position-in-list max-pcomp1 comp-eqns
)))
310 (vformat t
"%The number of equations are ~A and their complexity is ~A"
311 number-eqns comp-eqns
)
312 (setq where-the-max
(find-position-in-list the-max number-eqns
))
313 (loop for v in number-eqns
315 for lis-ld in
(pls-data new-pls
)
316 for op in
(pls-opens new-pls
)
319 do
(format t
"~%On open ~A there are ~A equations of complexity ~A ." i v w
)
320 when
(equal v the-min
)
321 do
(push (list (format nil
"Least homogeneous equations")
322 op
(car lis-ld
) ) choices
)
323 when
(eql w min-comp
)
324 do
(push (list (format nil
"Least complex equations")
325 op
(car lis-ld
) ) choices
))
326 (cond(query-user (user-supply check-the-worst
)))
327 (cond (query-user (user-supply opens-not-to-try
)
328 (user-supply opens-to-try
)))
331 for op in
(pls-opens new-pls
)
333 (and (null (member ii opens-not-to-try
:test
#'equal
))
335 (< (length some-red
) number-to-reduce
) (member ii opens-to-try
:test
#'equal
)))
336 do
(push ii opens-not-to-try
) (format t
"~%Reducing the ~A open" ii
)
337 (show ii opens-not-to-try
(member ii opens-not-to-try
:test
#'equal
)
338 (null (member ii opens-not-to-try
:test
#'equal
)))
340 (simplify-svar-ldata (open-sub-scheme new-pls ii
)))
341 (push (car (make-component-history red-pls
))(zopen-history op
))
343 when
(null (pls-data red-pls
))
344 do
(setf (nth ii
(pls-data new-pls
)) nil
)
346 else collecting red-pls into some-red
348 (show the-max opens-not-to-try where-the-max
)
349 (cond ((and check-the-worst
(null (mem where-the-max opens-not-to-try
:test
#'eq
)))
351 (cons (simplify-svar-ldata
352 (open-sub-scheme new-pls where-the-max
)) some-red
)))
353 (t (setq some-red-pls some-red
))))
355 (loop for red-pls in some-red-pls
357 (loop for lis-ld in
(pls-data red-pls
)
358 for op in
(pls-opens red-pls
)
360 (loop for ld in lis-ld
361 collecting
(list "Reduced ld" op ld
)))))
362 (setq red-choices
(sort red-choices
363 #'(lambda (u v
) (order-ldata (third u
) (third v
)))))
364 (setq choices
(append red-choices choices
))
365 (push some-red-pls
*Reduced-history
*)
367 (loop while
(yes-or-no-p "Show the reduced pls's?")
368 do
(des some-red-pls
))))
370 (loop named kay for v in choices while
(y-or-n-p "show next?")
372 do
(format t
"~3% Number**** ~A :" i
)
374 (loop for ww in v do
(des ww
))
377 (format t
"~%Type the number of the one do you want:")
379 (cond ((not (and (numberp n
) (< n
(length choices
)))) nil
)
380 (t (des (nth n choices
))
381 (cond ((yes-or-no-p "~%Choosing this one?")
383 (cons (nth n choices
)
384 (delete-nth n choices
))))
391 (format t
"enter a form to evaluate giving (list nil open ldata-to-blowup) ~
392 or T to enter pls and component numbers: ")
394 (setq answ
(eval (read)))
396 (user-supply a-red-pls
)
397 (user-supply an-open-number
)
398 (user-supply component-number
)
401 (nth an-open-number
(pls-opens a-red-pls
))
402 (nth component-number
(nth an-open-number
(pls-data
404 (iassert (and (eq (car (second answ
)) 'zopen
)))
405 (iassert (and (eq (car (third answ
)) 'ldata
)))
407 (cond ((y-or-n-p "Use it?")
408 (return (list answ
))))))))
411 (defun sort-the-reduced-history (some-red-pls &aux red-choices
)
413 (loop for red-pls in some-red-pls
415 (loop for lis-ld in
(pls-data red-pls
)
416 for op in
(pls-opens red-pls
)
418 (loop for ld in lis-ld collecting
(list "Reduced ld" op ld
)))))
419 (setq red-choices
(sort red-choices
#'(lambda (u v
) (order-ldata (third u
) (third v
))))))
421 (defun order-ldata (u v
)
422 (cond ((< (length (ldata-eqns u
))
423 (length (ldata-eqns v
))))
424 ((= (length (ldata-eqns u
))
425 (length (ldata-eqns v
)))
426 (< (gen-pcomplexity (ldata-eqns u
))
427 (gen-pcomplexity (ldata-eqns v
))))
431 ;;;the following works to blow up following one open thru
432 ;(defun blowup-pls-using-high-dimensional-components (pls n &aux (current-pls pls)
434 ; (loop named sue for i from n while (pls-data current-pls)
435 ; with new-pls = current-pls
436 ; with red-pls = current-pls
437 ; with first-time = t
438 ; when (null first-time)
440 ; (format t "reduced pls:")
442 ; (format t "homogeneous simplified pls:")
443 ; (setq current-pls (simplify-svar-homogeneous current-pls))
445 ; (cond ((null (pls-data red-pls))
446 ; (return (list blew-up i))))
447 ; (multiple-value ( op codim)
448 ; (high-dimensional-component red-pls))
450 ; (format t "~%The ~A blowup: the ~A component of the ~A open of codimension ~A."
451 ; i (second op) (car op) codim)
453 ; (setq new-pls (blowup-pls current-pls (nth (car op) (pls-opens red-pls))
454 ; (nth (second op) (nth (car op) (pls-data red-pls)))))
457 ; collecting (list (format nil "Before the ~A blowup the homogeneous equations on one of the nontrivial opens looked like :" i)current-pls) into blew-up
460 ; (format nil "~%The ~A blowup was by the ~A ldata of the following open:" i (second op)) (open-sub-scheme red-pls (car op)))
463 ; (setq first-time nil)
464 ; (loop for ii from 0
465 ; for ope in (pls-opens new-pls)
467 ; (setq red-pls (simplify-svar-ldata
468 ; (open-sub-scheme new-pls ii)))
469 ; (show ii (length (pls-data red-pls)))
470 ; (format t "Open history" (zopen-history (car (pls-opens current-pls))))
471 ; when (pls-data red-pls)
472 ; do (setq current-pls (open-sub-scheme new-pls ii))
473 ; (format t "~%Taking the ~A open with history " ii)
475 ; else do (format t "~%The ~A open is empty")
476 ; finally (return-from sue blew-up))
477 ; finally (return (list blew-up i))))
479 ;(defun blowup-pls-using-high-dimensional-components (pls n &aux (current-pls pls)
481 ; (loop for i from n while (pls-data current-pls)
482 ; do (multiple-value ( op codim)
483 ; (high-dimensional-component pls))
484 ; (format t "~%The ~A blowup: the ~A component of the ~A open of codimension ~A."
485 ; i (second op) (car op) codim)
486 ; (setq current-pls (copy-tree (s-blow current-pls (car op) (second op))))))
489 ;;performs the transform of a list of equations into new equations on the
490 ;;ITH blowup of the FIRSTK coordinates AMBIENT-DIM space
491 ;(defun proper-transform (list-eqns ith firstk ambient-dim &aux
492 ; ichart fns subs trans answ gg)
493 ; (cond ((eq (car list-eqns) 'ldata)
494 ; (setq gg (ldata-inequality list-eqns))
495 ; (setq list-eqns (ldata-eqns list-eqns))))
496 ; (setq ichart (ichart ith firstk ambient-dim))
497 ; (setq fns (rmap-fns (zopen-inv ichart)))
498 ; (setq subs (my-pairlis *xxx* fns))
499 ; (setq trans (loop for v in list-eqns collecting (psublis subs 1 v)))
500 ; (cond (gg (setq gg (psublis subs 1 gg))))
501 ; (setq answ($cancel_factors_and_denominators (cons '(mlist)
502 ; trans) (list (xxx ith)) t))
503 ; (cond (gg (make-ldata :eqns answ :inequality gg))
506 (defun proper-transform (ld ith firstk ambient-dim
&aux
508 (setq ichart
(ichart ith firstk ambient-dim
))
509 (setq ld
(copy-list ld
))
510 (setq trans
(apply-rmap (zopen-inv ichart
) ld
))
511 (format t
"~%Exceptional divisor is ~/maxima::tilde-q-fsh/." (xxx ith
))
513 (cdr (eliminate-common-factors (cons (pexpt (xxx ith
) 10) (ldata-eqns trans
) ))))
516 ;(setq answ($cancel_factors_and_denominators (cons '(mlist)(ldata-eqns trans))
518 ;;homogeneous cancellation
520 (setf (ldata-eqns trans
) answ
)
526 ;(defun blowup-sheaf (pls firstk &key opens-not-to-blowup opens-to-blowup
527 ; simplify-homogeneous
528 ; throw-out-components-in-exceptional-divisor
529 ; (keep-history t)&aux answ tem pt)
531 ; (setq pls (copy-list-structure pls))
532 ; (let* ((svar (pls-s-var pls))
533 ; (data (pls-data pls))
534 ; (opens (sv-zopens svar))
536 ; (setq dim (zopen-dim (first (pls-opens pls))))
537 ; (loop for op in opens
540 ; when (or (and (null opens-to-blowup) (not (member ii opens-not-to-blowup :test #'eq)))
541 ; (mem ii opens-to-blowup :test #'eq))
542 ; do (format t "~%Blowing up open number ~A " ii)
545 ; (loop for i from 1 to firstk
546 ; do (setq tem (iblowup op i firstk))
547 ; (setq pt (loop for ldat in dl
549 ; (proper-transform ldat
551 ; (iassert (eq (car tem) 'zopen))
552 ; (push (xxx i) (zopen-history tem))
553 ; when throw-out-components-in-exceptional-divisor
554 ; do (setq pt (loop for v in pt collecting
558 ; (loop for f in (ldata-eqns v)
559 ; with mon = (pexpt (xxx i) 10)
561 ; (car (eliminate-common-factors
564 ; when simplify-homogeneous
565 ; do (setq pt (loop for v in pt appending (ldata-simplify-homogeneous v
566 ; (zopen-inequality tem))))
567 ; collecting (cons tem pt))
570 ; collecting (cons op dl) into paired-data
571 ; finally (return(setq answ (make-pre-ldata-sheaves
572 ; s-var (make-s-var zopens (mapcar 'car paired-data))
573 ; data (mapcar 'cdr paired-data)))))
575 ; (cond (keep-history (add-pls-zopen-history answ)))
578 (defun blowup-sheaf (pls firstk
&key opens-not-to-blowup opens-to-blowup
579 simplify-homogeneous add-exceptional-divisor-ldata
580 (keep-history t
)&aux answ tem pt
)
581 (setq pls
(copy-list-structure pls
))
583 (let* ((svar (pls-s-var pls
))
584 (data (pls-data pls
))
585 (opens (sv-zopens svar
))
587 (setq dim
(zopen-dim (first (pls-opens pls
))))
588 (loop for op in opens
593 when
(or (and (null opens-to-blowup
) (not (member ii opens-not-to-blowup
:test
#'eq
)))
594 (member ii opens-to-blowup
:test
#'eq
))
595 do
(format t
"~%Blowing up open number ~A " ii
)
599 (loop for i from
1 to firstk
600 do
(setq tem
(iblowup op i firstk
))
601 (setq pt
(loop for ldat in dl
602 do
(iassert (ldatap ldat
))
604 (proper-transform ldat
606 (iassert (eq (car tem
) 'zopen
))
607 (push (xxx i
) (zopen-history tem
))
608 when simplify-homogeneous
609 do
(setq pt
(loop for v in pt appending
(ldata-simplify-homogeneous v
610 (zopen-inequality tem
))))
611 when add-exceptional-divisor-ldata
612 do
(setq pt
(append pt
(list (make-ldata :eqns
(list (xxx i
))))))
613 collecting
(cons tem pt
))
616 collecting
(progn (cond (add-exceptional-divisor-ldata
617 (setq dl
(append dl
(list
618 (make-ldata :eqns
'(1)))))))
619 (cons op dl
)) into paired-data
620 finally
(return(setq answ
(make-pre-ldata-sheaves
621 :s-var
(make-s-var :zopens
(mapcar 'car paired-data
))
622 :data
(mapcar 'cdr paired-data
)))))
623 (cond (keep-history (add-pls-zopen-history answ
)))
627 (defun linear-poly-solve (poly var
)
628 (ratreduce (pminus (pcoeff poly
1 (list var
))) (pcoeff poly
(list var
1 1))))
630 (defun unused-variables (n &optional strin
)
631 (cond (strin (setq strin
(concatenate 'string
(string strin
) "NEW")))
632 (t (setq strin
"NEW")))
633 (loop for i from
1 to n
634 collecting
(add-newvar (intern (format nil
"$~A~A" strin i
)))))
636 ;(defun apply-rmap (rmap fns &key (coords-for-fn *xxx*) subs
637 ; &aux (the-denom (rmap-denom rmap)))
638 ; "Argument may be list of polys, or rat'l fns, result is always rat'l"
640 ; (t (setq subs(my-pairlis coords-for-fn (rmap-fns rmap)))))
641 ; (cond ((affine-polynomialp fns)
642 ; (rsublis subs the-denom fns :reduce t))
643 ; ((rational-functionp fns)
644 ; (ratquotient (rsublis subs the-denom (num fns) )
645 ; (rsublis subs the-denom (denom fns))))
646 ; ((eq (car fns) 'ldata)
647 ; (make-ldata eqns (loop for v in (ldata-eqns fns)
648 ; collecting (function-numerator (apply-rmap rmap v
652 ; inequality (function-numerator(apply-rmap rmap (ldata-inequality fns)
656 ; ((or (affine-polynomialp (car fns))
657 ; (rational-functionp (car fns))
658 ; (ldatap (car fns)))
660 ; collecting (apply-rmap rmap v :coords-for-fn coords-for-fn
662 ; (t (merror "fns should be a polynomial, rat'l fn,ldata or list of such"))))
664 ;(defun apply-rmap (rmap fns &key (coords-for-fn *xxx*) subs
666 ; "Argument may be list of polys, or rat'l fns, result is always rat'l"
668 ; (t (setq subs (subs-for-simple-rat-sublis
670 ; (loop for f in (rmap-fns rmap)
671 ; collecting (ratreduce
673 ; (rmap-denom rmap)))))))
674 ; (cond ((or (affine-polynomialp fns)(rational-functionp fns))
675 ; (simple-rat-sublis subs fns))
676 ; ((eq (car fns) 'ldata)
677 ; (make-ldata eqns (loop for v in (ldata-eqns fns)
678 ; collecting (function-numerator (apply-rmap rmap v
682 ; inequality (function-numerator(apply-rmap rmap (ldata-inequality fns)
686 ; ((or (affine-polynomialp (car fns))
687 ; (rational-functionp (car fns))
688 ; (ldatap (car fns)))
690 ; collecting (apply-rmap rmap v :coords-for-fn coords-for-fn
692 ; (t (merror "fns should be a polynomial, rat'l fn,ldata or list of such"))))
694 (defun apply-rmap (rmap fns
&key
(coords-for-fn *xxx
*) subs
&aux answ
)
695 "Argument may be list of polys, or rat'l fns, result is always rat'l"
700 (setq subs
(subs-for-simple-rat-sublis coords-for-fn
(rmap-fns rmap
)))))
701 (cond ((or (affine-polynomialp fns
) (rational-functionp fns
))
702 (setq answ
(simple-rat-sublis subs fns
))
705 ((eq (car fns
) 'ldata
)
707 (loop for v in
(ldata-eqns fns
)
708 collecting
(function-numerator (apply-rmap rmap v
712 :inequality
(function-numerator(apply-rmap rmap
(ldata-inequality fns
)
716 ((or (affine-polynomialp (car fns
))
717 (rational-functionp (car fns
))
720 collecting
(apply-rmap rmap v
:coords-for-fn coords-for-fn
722 (t (merror "fns should be a polynomial, rat'l fn,ldata or list of such"))))
725 (and (consp obj
)(eq (car obj
) 'ldata
)))
727 ;;;;idea is to take the eqns in ldata and
728 ;;;;construct an rmap to a coordinate system where the
729 ;;;;elements of ldata are transformed to the first n
730 ;;;;eqns where n is the number of eqns in ldata
731 ;;;;we need the ldata since the gg is necessary to figure out which
732 ;;;;variables were linear and should be solved for.
733 ;;(defun normalize-zopen (ldata dim &aux (gg (ldata-inequality ldata))
734 ;; (eqns (ldata-eqns ldata))
735 ;; vari all-eqns all-vari lis map fns
736 ;; other newvars new-eqns denom
738 ;; (setq vari (loop for v in eqns
739 ;; when (setq tem (any-linearp v gg ))
742 ;; else do (merror "Hey this is not linear ~A" v)))
743 ;; (setq other (loop for w in *xxx*
745 ;; when (not (member w vari :test #'eq))
747 ;; (setq all-vari (append vari other))
748 ;; (setq newvars (unused-variables dim))
749 ;; (cond ((not (eql (length all-vari) dim)) (merror "Some variables are wrong in vari")))
751 ;; (loop for v in eqns
754 ;; collecting (linear-poly-solve (pdifference v (list u 1 1)) va)))
755 ;; (setq fns (append eqns other))
756 ;; (setq all-eqns (append new-eqns (loop for u in (nthcdr (length eqns) newvars)
757 ;; collecting (list u 1 1))))
758 ;; (setq all-eqns (gen-psublis (append vari other) newvars all-eqns))
760 ;;; (gen-psublis other (nthcdr (length eqns) newvars)
763 ;; (sublis (pairlis newvars *xxx*)
765 ;; (setq lis (make-list dim))
766 ;; (loop for v in all-vari
768 ;; do (setq n (find-position-in-list v *xxx*))
769 ;; (setf (nth n lis) u))
770 ;; (setq map (construct-rmap lis))
771 ;; (setq gg (num (apply-rmap map gg)))
772 ;; (setq fns (construct-rmap fns))
773 ;; (make-zopen coord fns inv (construct-rmap lis) inequality gg))
775 ;;;idea is to take the eqns in ldata and
776 ;;;construct an rmap to a coordinate system where the
777 ;;;elements of ldata are transformed to the first n
778 ;;;eqns where n is the number of eqns in ldata
779 ;;;we need the ldata since the gg is necessary to figure out which
780 ;;;variables were linear and should be solved for.
782 ;(defun normalize-zopen
783 ; (ldata dim &aux (gg (ldata-inequality ldata))
784 ; (eqns (ldata-eqns ldata))
786 ; other newvars new-eqns subs rest-new map denom
788 ; (setq vari (loop for v in eqns
789 ; when (setq tem (any-linearp v gg ))
792 ; else do (merror "Hey this is not linear ~A" v)))
793 ; (setq other (loop for w in *xxx*
795 ; when (not (member w vari :test #'eq))
797 ; (setq vari (append vari other))
798 ; (setq newvars (unused-variables dim))
799 ; (cond ((not (eql (length vari) dim)) (merror "Some variables are wrong in vari")))
801 ; (loop for v in eqns
804 ; collecting (linear-poly-solve (pdifference v (list u 1 1)) va)))
805 ; (setq rest-new (loop for i from (length eqns) below dim
806 ; collecting (nth i newvars)))
807 ; (setq all-new (append new-eqns rest-new))
808 ; (setq subs (subs-for-psublis other rest-new ))
810 ; (loop for w in new-eqns
811 ; collecting (cons (psublis subs 1 (car w))
812 ; (psublis subs 1 (cdr w)))))
813 ;; (setq all-subs (append subs (my-pairlis vari new-eqns)))
814 ; (setq new-eqns (append new-eqns rest-new))
815 ;; (make-zopen coord vari inv (append new-eqns rest-new)
816 ; (setq map (construct-rmap new-eqns))
817 ; ;;assumes denom in x1,x2,.. coords
818 ;; (setq denom (apply-rmap map gg))
819 ; (setq fns (rmap-fns map))
821 ; (loop for v in vari
822 ; do (setq n (find-position-in-list v vari))
823 ; collecting (nth n fns)))
825 ; (show (subs-for-psublis newvars *xxx*))
826 ; (setq new-eqns (gen-psublis newvars *xxx* new-eqns))
827 ; (setf (rmap-fns map) new-eqns)
828 ; (setf (rmap-denom map) (gen-psublis newvars *xxx* (rmap-denom map)))
833 ; "takes as arguments a list of polys or rat'l fns and tries to make
834 ; these into the first coordinates. It tries to find the inverse.
835 ; It will check whether it has found the inverse, and error if not
837 ; some variable. It collects these linear variables and then completes
838 ; them to get a list up to the dimension of the space. (f1,f2, ..
839 ; fm,xi1,xi2,..) is then the set of coordinates, and it calculates the
840 ; inverse of this set. It returns the open with inequality gg and coord
841 ; (f1,...) and inverse These are to become the first nwhich are to be the
842 ; first in the list of coordinates of some open. It then completes the
845 (defun make-normal-zopen (eqns dim gg
&aux
(check-inverse t
)
846 variables fns tem all-variables answ
847 coords newvar coord-eqns solu dif-eqns other-monoms other-variables
)
848 (setq newvar
(unused-variables dim
))
849 (setq dif-eqns
(loop for v in eqns
852 (function-numerator (n- v
(list u
1 1)))))
853 (setq variables
(linear-ldatap (make-ldata :eqns eqns
) :open-g gg
))
854 (cond ((null variables
)
856 (loop for v in dif-eqns
857 collecting
(setq tem
(any-linearp v gg
:variables-to-exclude newvar
))
859 (merror "this equation contains no linear " (sh v
))))))
860 (setq other-variables
(loop for v in
*xxx
*
862 when
(not (member v variables
:test
#'eq
))
864 (setq all-variables
(append variables other-variables
))
866 (loop for v in other-variables
867 collecting
(list v
1 1)))
869 (setq coord-eqns
(loop for v in
(setq coords
(append eqns other-monoms
))
871 collecting
(function-numerator (n- v
(list u
1 1)))))
872 (setq solu
(solve-simple-system (mapcar 'function-numerator coord-eqns
) all-variables
874 ; (setq solu (loop for v in all-variables
875 ; for eqn in coord-eqns
876 ; collecting (linear-poly-solve eqn v)))
877 ; (setq solu (gen-psublis other-variables (nthcdr (length eqns) newvar) solu))
878 (setq solu
(gen-psublis newvar
*xxx
* solu
))
879 (setq fns
(make-list dim
))
880 (setq fns
(loop for v in all-variables
882 collecting
(nth (find-position-in-list v
*xxx
*) solu
)))
883 (loop for v in all-variables
885 do
(setf (nth (find-position-in-list v
*xxx
*) fns
) f
))
886 (setq answ
(make-zopen :coord
887 (construct-rmap coords
) :inv
(construct-rmap fns
) :inequality gg
))
888 (cond (check-inverse (check-zopen-inv answ
)))
891 ;(defun make-normal-zopen (eqns dim gg &aux (check-inverse t)
892 ; variables fns tem all-variables answ
894 ; newvar coord-eqns solu other-monoms other-variables)
896 ; "takes as arguments a list of polys f1,f2,..each of which is linear in
897 ; some variable. It collects these linear variables and then completes
898 ; them to get a list up to the dimension of the space. (f1,f2, ..
899 ; fm,xi1,xi2,..) is then the set of coordinates, and it calculates the
900 ; inverse of this set. It returns the open with inequality gg and coord
901 ; (f1,...) and inverse These are to become the first nwhich are to be the
902 ; first in the list of coordinates of some open. It then completes the
905 ; (loop for v in eqns
906 ; collecting (setq tem (any-linearp v gg))
908 ; (merror "this equation contains no linear " (sh v))))
909 ; (setq other-variables (loop for v in *xxx*
911 ; when (not (member v variables :test #'eq))
913 ; (setq all-variables (append variables other-variables))
915 ; (loop for v in other-variables
916 ; collecting (list v 1 1)))
917 ; (setq newvar (unused-variables dim))
918 ; (setq coord-eqns (loop for v in (setq coords (append eqns other-monoms))
920 ; collecting (pdifference v (list u 1 1))))
921 ; (setq solu (solve-simple-system (mapcar 'function-numerator coord-eqns) all-variables
923 ;; (setq solu (loop for v in all-variables
924 ;; for eqn in coord-eqns
925 ;; collecting (linear-poly-solve eqn v)))
926 ;; (setq solu (gen-psublis other-variables (nthcdr (length eqns) newvar) solu))
927 ; (setq solu (gen-psublis newvar *xxx* solu))
928 ; (setq fns (make-list dim))
929 ; (setq fns (loop for v in all-variables
931 ; collecting (nth (find-position-in-list v *xxx*) solu)))
932 ; (loop for v in all-variables
934 ; do (setf (nth (find-position-in-list v *xxx*) fns) f))
935 ; (setq answ (make-zopen coord
936 ; (construct-rmap coords) inv (construct-rmap fns) inequality gg))
937 ; (cond (check-inverse (check-zopen-inv answ)))
941 (defun check-zopen-inv (zopen &aux ma
)
942 (setq ma
(compose-rmap (zopen-inv zopen
) (zopen-coord zopen
)))
943 (loop for v in
(rmap-fns ma
)
945 when
(not (eql (caar v
) u
))
946 do
(return (merror "not the inverse")))
949 (defun solve-simple-system (eqns variables
950 &key
(invertible 1) &aux used-up simpl-eqns
951 (all (copy-list eqns
)) tem v
)
954 do
(setq v
(car all
))
955 when
(setq tem
(any-linearp v invertible
:among-variables variables
))
956 do
(setq all
(replace-functions all v tem
:invertible-g invertible
))
957 (setq used-up
(cons v
(replace-functions
958 used-up v tem
:invertible-g invertible
)))
959 finally
(return (append used-up all
))))
960 (loop for v in variables
962 (loop for w in simpl-eqns
963 when
(eql (pdegree w v
) 1)
964 ;;(poly-linearp w v invertible) the variables get replaced
965 do
(return (linear-poly-solve w v
)))))
967 (defun normalize-zopen (zopen eqns
&key inequality data
&aux op answ
)
968 ; (declare (values norm-open data))
969 (cond ((null inequality
) (setq inequality
(zopen-inequality zopen
))))
970 (setq op
(make-normal-zopen eqns
(zopen-dim zopen
) inequality
))
971 (setq answ
(copy-list zopen
))
972 (set-slots answ zopen- coord
(compose-rmap (zopen-coord op
) (zopen-coord zopen
))
973 inv
(compose-rmap (zopen-inv zopen
) (zopen-inv op
))
974 inequality
(function-numerator (apply-rmap (zopen-inv op
) inequality
)))
975 (cond (data (setq data
(apply-rmap (zopen-inv op
) data
))))
979 (defun normalize-zopen-in-pls (pls zopen-number eqns
980 &key copy
&aux new-open opens open lis-dat MAPL
)
982 (cond (copy (setq pls
(copy-tree pls
)))
983 (t (setq pls
(copy-list-structure pls
))))
984 (setq opens
(pls-opens pls
))
985 (setq open
(nth zopen-number opens
))
986 (setq lis-dat
(nth zopen-number
(pls-data pls
)))
987 (setq new-open
(normalize-zopen open eqns
))
988 (setq MAPL
(find-ring-map open new-open
))
989 (setf (nth zopen-number opens
) new-open
)
990 (setf (nth zopen-number
(pls-data pls
))
991 (apply-rmap MAPL lis-dat
))
993 (defun copy-list-structure (expr)
994 (cond ((atom expr
) expr
)
995 ((member (car expr
) '(zopens pre-ldata-sheaves rmap s-var ldata
) :test
#'eq
)
997 (t (loop for v on expr
998 do
(setf (car v
) (copy-list-structure (car v
)))))))
1000 ;(defun open-all-refinement ( list-eqns open-g )
1001 ; (loop for v in list-eqns
1002 ; when (setq tem (all-linearp v open-g))
1003 ; collecting v into lin-eqns
1004 ; collecting lin-vars into lin-vars
1006 ; collecting v into fns
1007 ; collecting (setq tem (gm-all-prepared v :inequal open-g)) into prep-vars
1009 ; (loop for v in prep-vars
1010 ; for w in fns when (null v)do (fsignal "Not gm-prepared ~A" w))
1012 ;;(setq vtree (gm-all-prepared (st-rat #$x*y+x^2*w+s*t+1$)))
1013 ;((#:S #:W #:Y . OK) (#:S #:Y #:W . OK)
1014 ; (#:T #:W #:Y . OK)
1015 ; (#:T #:Y #:W . OK)
1016 ; (#:W #:S #:Y . OK)
1017 ; (#:W #:T #:Y . OK)
1018 ; (#:W #:Y #:S . OK)
1019 ; (#:W #:Y #:T . OK)
1020 ; (#:Y #:S #:W . OK)
1021 ; (#:Y #:T #:W . OK)
1022 ; (#:Y #:W #:S . OK)
1023 ; (#:Y #:W #:T . OK))
1024 ;;now check refinements wrt to different ones for lower complexity
1025 ;;will get for each f a list of lists of cofs that need inverting to make
1026 ;;covering. We can factor them and use eliminate-larger to find the best
1030 ;;should return an open cover such that the functions are all linear
1031 ;;they should start out well prepared. You shortest such covering
1032 ;;Note some functions depend on the fact that the first
1033 ;;element returned by best-open-cover is the function itself and
1034 (defun best-open-cover (list-fns open-g
&aux tem inv-list prep-fns
)
1035 (cond ((all-linearp list-fns open-g
)
1037 (t (setq prep-fns
(loop for v in list-fns
1038 when
(setq tem
(gm-prepared v
:inequal open-g
))
1040 (cond ((eql (length prep-fns
) 1)
1041 (best-open-cover1 prep-fns open-g
))
1042 (t (loop for v in prep-fns
1045 (setq tem
( best-open-cover1
(list v
) open-g
))
1049 (best-open-cover (delete v
(copy-list prep-fns
) :test
#'equal
)
1050 (sftimes open-g gg
))))
1052 (setq inv-list
(eliminate-multiples inv-list
))
1053 collecting inv-list into possible
1054 minimize
(length inv-list
) into min
1059 (loop for v in possible
1060 when
(eql (length v
) min
)
1061 do
(return v
)))))))))
1063 (defun eliminate-multiples (list-fns &key
(square-free t
) &aux tem facts
)
1064 (setq facts
(loop for v in list-fns
1065 collecting
(setq tem
(non-constant-factors v
))
1067 do
(loop for v on tem by
#'cddr do
(setf (second v
) 1))))
1068 (mapcar #'multiply-out-factorization
(eliminate-larger facts
:test
'a-factor
)))
1070 ;;this works for a list of one function..
1071 (defun best-open-cover1 (list-fns open-g
&aux tem compl-tem the-prep-fns answ possible-refs lis-prep-cofs lis-prep-var
)
1072 (loop for f in list-fns
1073 when
(any-linearp f open-g
)
1074 collecting f into lins
1075 else collecting f into prep-fns
1076 finally
(setq the-prep-fns prep-fns
)
1078 (loop for f in prep-fns
1079 collecting
(nsubst nil
'ok
(gm-all-prepared f
:inequal open-g
))))
1082 (loop for f in prep-fns
1083 for lis in lis-prep-var
1085 (loop for varl in lis
1089 (setq tem
(non-constant-factors (pcoeff f
(list v
1 1 ))))
1090 do
(loop for v on tem by
#'cddr
1091 do
(setf (second v
) 1)))))))
1092 (setq possible-refs
(all-perms lis-prep-cofs
))
1093 (loop for v in possible-refs
1094 collecting
(setq tem
(eliminate-larger v
:test
'a-factor
)) into facts
1095 minimize
(length tem
) into min
1097 (loop for v in facts
1099 when
(eql (length v
) min
)
1100 collecting
(setq compl-tem
(cons i
(gen-pcomplexity tem
))) into compl
1101 minimize
(cdr compl-tem
) into min-compl
1102 finally
(loop for v in compl-tem
1103 when
(eq (cdr compl-tem
) min-compl
)
1104 ;;return the factors for refinement
1105 do
(return (setq answ
(nth (car compl-tem
) facts
))))))
1106 (loop for w in
(append the-prep-fns
(mapcar 'multiply-out-factorization answ
))
1107 collecting
(nplcm open-g w
)))
1109 (defun all-perms (list-lists)
1110 (cond ((eql (length list-lists
) 1) (car list-lists
))
1111 (t (loop for v in
(car list-lists
)
1113 (loop for w in
(all-perms (cdr list-lists
))
1117 (defun open-refinement (zopen gmprep-poly m
&aux mzopens next-open cofs
)
1118 "Will return m+1 opens covering the zopen. It is gm-prepared wrt the
1119 inequality g of zopen."
1120 (let* ((gg (zopen-inequality zopen
))
1121 (vari (gm-prepared gmprep-poly
:m m
:inequal gg
)))
1122 (check-arg zopen
(eq (car zopen
) 'zopen
) "a zopen")
1123 (check-arg gmprep-poly affine-polynomialp
"poly")
1124 (setq cofs
(loop for v in vari
1125 collecting
(pcoeff gmprep-poly
(list v
1 1))))
1130 (zl-copy-structure zopen
1131 zopen- inequality
(nplcm cof gg
)
1132 coord
(zopen-coord zopen
)
1133 inv
(zopen-inv zopen
))))
1136 (zl-copy-structure zopen zopen- inequality
(nplcm gg
1138 (cons next-open mzopens
)))
1140 ;(defun ldata-refinement (ldata gmprep-poly m &key (inequality 1)
1141 ; &aux all-ldata cofs)
1142 ; "Will return m ldata covering the zopen. It is gm-prepared wrt the
1143 ; inequality g of zopen."
1144 ; (let* ((gg (nplcm inequality (ldata-inequality ldata)))
1145 ;; (m (length (any-gm-prepared gmprep-poly gg)))
1146 ; (vari (gm-prepared gmprep-poly :m m :inequal gg)))
1147 ; (check-arg gmprep-poly affine-polynomialp "poly")
1148 ; (setq cofs (loop for v in vari
1149 ; collecting (pcoeff gmprep-poly (list v 1 1))))
1154 ; (copy-structure ldata
1155 ; ldata- inequality (nplcm cof gg))))
1158 (defun ldata-refinement (ldata gmprep-poly m
&key
(inequality 1)
1159 &aux all-ldata cofs
)
1160 "Will return m ldata covering the ldata. The open-gs can
1161 be used as the open number for the simplification."
1162 ; (declare (values all-data open-gs))
1163 (let* (;;(gg (nplcm inequality (ldata-inequality ldata)))
1164 ; (m (length (any-gm-prepared gmprep-poly gg)))
1165 (vari (gm-prepared gmprep-poly
:m m
:inequal inequality
)))
1166 (check-arg gmprep-poly affine-polynomialp
"poly")
1167 (setq cofs
(loop for v in vari
1168 collecting
(pcoeff gmprep-poly
(list v
1 1))))
1169 (eliminate-multiples cofs
)
1170 (setq cofs
(mapcar 'square-free cofs
))
1175 (zl-copy-structure ldata
1176 ldata- inequality
(nplcm cof
(ldata-inequality ldata
)))))
1177 (values all-ldata cofs
)))
1179 ;(defun ldata-refinement (ldata gmprep-poly m &key (inequality 1)
1180 ; &aux all-ldata cofs)
1181 ; "Will return m ldata covering the ldata. The open-gs can
1182 ; be used as the open number for the simplification."
1183 ; (declare (values all-data open-gs))
1184 ; (check-arg gmprep-poly affine-polynomialp "poly")
1185 ; (setq cofs (best-open-cover gmprep-poly inequality))
1186 ; (iassert (may-invertp gmprep-poly (car cofs)))
1187 ; (setq cofs (cdr cofs))
1192 ; (copy-structure ldata
1193 ; ldata- inequality (sftimes cof (ldata-inequality ldata)))))
1194 ; (values all-ldata cofs))
1195 ;;; the following would have been empty:
1197 ; (copy-structure ldata ldata- inequality (nplcm gg
1199 ; (cons next-ld all-ldata)))
1201 ;;want s-var-ldata-simplifications to take
1202 ;;a pre-ldata-sheaves and simplify it.
1203 ;; this may involve adding more opens if we meet m-prepared's in
1204 ;;the ldata, it will return a pre-ldata-sheaves
1206 ;;notes add an argument to (ldata-simplifications ldata gg)
1207 ;;to allow passing the gg from the current open. The
1208 ;;computation of the mpreprared should be wrt that gg.
1209 ;;still have to modify the ldata-simplifications to return
1210 ;; in *stop-simplify* the mprepared fn and m. (and to stop work )
1212 (defun simplify-svar-ldata (pls &key keep-opens-with-empty-ldata
1213 (check-containment t
)
1214 (set-ldata-inequalities-to-one t
)
1216 (keep-history t
) opens-not-to-simplify
&aux simped-ld w refs
1217 ;;to make the gm-prepared
1218 (*refine-opens
* refine-opens
)
1219 some-ld gg a-list answ
)
1220 (setq pls
(copy-list-structure pls
))
1221 (loop for i in opens-not-to-simplify
1222 collecting
(nth i
(pls-opens pls
)) into tem
1223 finally
(setq opens-not-to-simplify tem
))
1224 (let ((svar (pls-s-var pls
))
1225 (data (pls-data pls
))
1226 (*inside-simplify-svar-ldata
* t
))
1227 (setq a-list
(loop for op in
(sv-zopens svar
)
1229 collecting
(cons op dl
)))
1230 (loop for v on a-list
1234 (format t
"~%Open Number : ~A"(find-position-in-list (car w
) (pls-opens pls
)))
1235 (setq gg
(zopen-inequality (car w
)))
1236 (setq *stop-simplify
* nil
)
1237 when
(not (member (car w
) opens-not-to-simplify
:test
#'equal
))
1239 (loop for ld on
(cdr w
)
1240 do
(setq some-ld
(LDATA-SIMPLIFICATIONS (car ld
) :open-g gg
))
1242 appending some-ld into tem
1243 when
*stop-simplify
*
1245 (show *stop-simplify
*)
1247 ;;set v so that (cdr v) will be the rest of
1248 ;;the pairs (zopen . (list ldata1 ldata2..))
1249 (setq refs
(open-refinement (car w
) (first *stop-simplify
*)
1250 (second *stop-simplify
*)))
1251 (format t
"~%Refining open number ~D into ~D opens with inequalities ~/maxima::tilde-q-fsh/"
1252 (find-position-in-list (car w
) (pls-opens pls
))
1253 (length refs
) (loop for v in refs collecting
1254 (zopen-inequality v
)))
1255 (iassert (not (null *refine-opens
*)))
1256 (loop for vv in tem do
(check-arg vv
(eq (car vv
)'ldata
) "an ldata"))
1259 (loop for open in refs
1260 collecting
(cons open
1261 (copy-tree (append tem
1265 finally
(setq simped-ld
1266 (delete-redundant-ldata tem
:ignore-ldata-inequalities t
1267 :gg
(zopen-inequality
1270 else do
(setq simped-ld
(cdr w
))
1271 when
(and (null *stop-simplify
*) (or (member (car w
) opens-not-to-simplify
:test
#'equal
)
1272 keep-opens-with-empty-ldata simped-ld
))
1275 (setq simped-ld
(delete-redundant-ldata
1276 simped-ld
:gg
(zopen-inequality (car w
))))
1278 (cond (check-containment
1279 (check-component-containment (cdr w
)
1281 (zopen-inequality (car w
)))))))
1288 collecting simped-ld into ldata-list
1290 (return (setq answ
(make-pre-ldata-sheaves
1291 :s-var
(make-s-var :zopens opens
)
1292 :data ldata-list
)))))
1293 (cond (set-ldata-inequalities-to-one
1294 (set-inequalities-to-one answ
) answ
))
1295 (cond (keep-history (add-pls-zopen-history answ
)))
1300 `(let (*give-coordinates
*)
1303 ;(defun set-inequalities-to-one (lis)
1304 ; (cond ((atom lis) lis)
1305 ; ((eq (car lis) 'ldata) (setf (ldata-inequality lis) 1))
1307 ; (loop for v on lis while (not (atom v))
1309 ; do (set-inequalities-to-one v)))))
1311 ;(defun set-inequalities-to-one (lis)
1312 ; (cond ((listp lis)
1313 ; (cond ((and (listp lis)(eq (car lis) 'ldata))
1314 ; (setf (ldata-inequality lis) 1))
1316 ; (loop for v in lis
1318 ; (set-inequalities-to-one v)))))))
1319 (defun set-inequalities-to-one (form)
1320 (cond ((null form
) nil
)
1322 ((eq (car form
) 'ldata
)
1323 (setf (ldata-inequality form
) 1)
1325 (t (do ((r form
(cdr r
)))
1326 ((not (consp r
)) form
)
1327 (setf (car r
) (set-inequalities-to-one (car r
))))
1330 (defvar *signal-component-error
* nil
)
1332 (defun check-component-containment (orig-ldata-list list-ldat
&optional
(open-g 1) &aux bad-components
1333 answ unit
(use-ldata-inverse t
) gg
)
1334 (cond ((null open-g
) (setq open-g
1)))
1335 (cond ((ldatap orig-ldata-list
)(setq orig-ldata-list
(list orig-ldata-list
))))
1336 (loop for v in list-ldat
1339 (loop for ld in orig-ldata-list
1340 when use-ldata-inverse
1341 do
(setq gg
(plcm open-g
(ldata-inequality v
)))
1342 else do
(setq gg open-g
)
1344 (multiple-value-setq
1345 (answ unit
)(grobner-subset (ldata-eqns ld
) (ldata-eqns v
) gg
))
1346 when unit do
(format t
"~%**The component is empty***")
1349 (format t
"~% Component ~D verified:" i
) (des v
) (return 'ok
)
1352 finally
(push i bad-components
)
1353 (format t
"**The component ~/maxima::tilde-q-fsh/ ~%does not contain the original data***** " v
)
1354 (cond (*signal-component-error
* (fsignal "not contained" v
)))))
1357 (defun check-components-contain-original (ldata list-ldat
&aux bad-components answ
)
1358 (loop for v in list-ldat
1361 (setq answ
(catch 'took-too-long
(grobner-remember (ldata-eqns v
))))
1363 (loop for u in
(ldata-eqns ldata
)
1364 when
(not ($zerop
(polysimp u
)))
1365 do
(mshow u
(polysimp u
))
1367 (format t
"**The ideal: ~/maxima::tilde-q-fsh/ ~%does not contain the original one *** : ~/maxima::tilde-q-fsh/"
1369 (push-new i bad-components
)
1371 (format t
"~% Component ~D verified:" i
)
1373 (cond (bad-components (format t
"~%All but components ~A contained the originals." bad-components
)))
1376 (defun variable-doesnt-occur (var &rest lists-fns
)
1377 (loop for v in lists-fns
1378 when
(member var
(list-variables v
:test
#'eq
))
1380 finally
(return t
)))
1382 ;(defun simplify-svar-ldata (pls &aux simped-dat-list some-ld gg ref the-partial-ldat answ)
1383 ; (let ((svar (pls-s-var pls))
1384 ; (data (pls-data pls))
1385 ; ( *inside-simplify-svar-ldata* t))
1386 ; (loop for op on (sv-zopens svar)
1387 ; for dat-list on data
1391 ; (setq gg (zopen-inequality (car op)))
1393 ; (setq *stop-simplify* nil)
1394 ; (loop for ld in (car dat-list)
1395 ; do (setq some-ld (ldata-simplifications ld gg ))
1396 ; when (null *stop-simplify*)
1397 ; appending some-ld into tem
1400 ; (setq ref (apply 'refinement
1401 ; (cons (car op) *stop-simplify*)))
1402 ; (setq op (cons nil (append ref (cdr op))))
1403 ; (setq the-partial-ldat (append tem some-ld (cdr ld)))
1404 ; (setq dat-list (cons nil (append
1405 ; (make-list (length ref)
1411 ; finally (setq simped-dat-list tem)(show simped-dat-list))
1412 ; ;;otherwise the open will be picked up next trip through the loop
1413 ; when (null *stop-simplify*)
1414 ; collecting (car op) into ops
1416 ; collecting simped-dat-list into dats
1417 ; finally (return (setq answ (make-pre-ldata-sheaves :s-var
1418 ; (make-s-var zopens ops)
1422 ;;the following is for converting back things which have been dumped to file.
1423 ;;or after we have reset the genvar
1424 (defun replace-rmaps-by-new-ones (form)
1425 (cond ((null form
) nil
)
1427 ((eq (car form
) 'rmap
)
1428 (convert-rmap-to-new form
))
1429 (t (do ((r form
(cdr r
)))
1430 ((not (consp r
)) form
)
1431 (setf (car r
) (replace-rmaps-by-new-ones (car r
)))))))
1434 (cond ((null form
) nil
)
1435 ((and (symbolp form
)
1436 (not (member form
'(ldata s-var zopens rmap zopen pre-ldata-sheaves
1437 quote inequality eqns
) :test
#'eq
)))
1438 (add-newvar (intern (string-append "$" (string form
)))))
1439 (t (do ((r form
(cdr r
)))
1440 ((not (consp r
)) form
)
1441 (setf (car r
) (rerat (car r
)))))))
1445 ;(construct-pre-ldata-sheaves :s-var
1446 ; (make-s-var :zopens (list (affine-open (firstn 2 *xxx*) )))
1449 ; (loop for v in '(1 2)
1450 ; collecting (nth v (grobner-monomials #$[x1,x2]$ 3)))
1456 ; (construct-pre-ldata-sheaves
1458 ; (make-s-var zopens (list (affine-open (firstn 8 *xxx*) #$1$)))
1460 ; (make-ldata eqns (st-rat
1461 ; #$[x1*x2+1+x3*x4,x3^2+x1^2]$)
1464 (defun affine-svar (&key dim eqns
(inequality 1) (ld-inequality 1) list-ldata
)
1465 (cond ((null list-ldata
)
1466 (setq list-ldata
(list (make-ldata :eqns eqns
:inequality ld-inequality
)))))
1467 (construct-pre-ldata-sheaves
1469 (make-s-var :zopens
(list (affine-open (subseq *xxx
* 0 dim
) inequality
)))
1470 :data
(list list-ldata
)))
1472 (defun affine-ldata (n eqns inequality
)
1473 (construct-pre-ldata-sheaves
1475 (make-s-var :zopens
(list (affine-open (subseq *xxx
* 0 n
) inequality
)))
1477 (make-ldata :eqns eqns
1478 :inequality inequality
)))))
1482 (defmacro for-editor
(&body body
)
1488 (defmacro desn-editor
(expr &aux me
)
1489 (setq me
`(setq ,expr
(rerat (quote ,(symbol-value expr
)))))
1490 (for-editor (desn (symbol-value expr
)))
1494 (defun change-strings-to-symbols (tree)
1495 (cond ((stringp tree
) (make-symbol tree
))
1499 do
(setf (car v
) (change-strings-to-symbols (car v
)))
1500 finally
(return tree
)))))
1503 (defun des-file (expr file-name
)
1504 (with-open-file (st file-name
:direction
:output
)
1505 (let ((linel 75)(*standard-output
* st
)
1510 ;(defmacro des-editor (expr &optional slash &aux me)
1511 ; (setq me `(setq ,expr (rerat (quote ,(eval expr)))))
1512 ; (time:print-current-time)
1513 ; (for-editor (des (symbol-value expr)))
1515 ; (format t "~%~s" me))
1516 ; (t (format t "~%~a" me)))
1520 (defun sh-comp (com)
1521 (loop for v in
(car com
)do
(format t
"~%~A" v
)))
1523 ;(defun des-editor (expr)
1524 ; (for-editor (format t "~A" expr)))
1525 ;(defun find-map (open1 open2 &aux answ)
1526 ; "produces a map so that g so that g(coord open1) = (coord open2)"
1527 ; (let ((subs (subs-for-psublis *xxx* (rmap-fns (zopen-inv open1))))
1528 ; (coord2 (zopen-coord open2)))
1529 ; (setq answ (loop for v in (rmap-fns coord2)
1530 ; collecting (psublis subs 1 v) into tem
1531 ; finally (return (make-rmap fns tem denom
1532 ; (psublis subs 1 (rmap-denom coord2))))))
1533 ; (setq answ (reduce-rational-map answ))))
1535 (defun find-ring-map (from-open to-open
)
1536 (compose-rmap (zopen-coord from-open
) (zopen-inv to-open
)))
1540 (defun translate-component (from-open to-open ldata
&key pls
&aux MAPL
)
1542 (setq to-open
(nth to-open
(pls-opens pls
)))
1543 (setq ldata
(nth ldata
(nth from-open
(pls-data pls
))))
1544 (setq from-open
(nth from-open
(pls-opens pls
)))))
1546 (cond ((equal from-open to-open
) ldata
)
1548 (setq MAPL
(find-ring-map from-open to-open
))
1549 (show (length (ldata-eqns ldata
)))
1550 (apply-rmap MAPL ldata
))))
1552 ;(defun translate-component-and-reduce (from-open to-open ldata
1553 ; &aux *refine-opens* hh gg red-transl transl map )
1554 ; (setq map (find-ring-map from-open to-open))
1555 ; (setq transl (apply-rmap map ldata))
1556 ; (setq red-transl (ldata-simplifications transl
1557 ; (setq gg (zopen-inequality to-open))))
1559 ; (setq hh (nplcm (rmap-denom map) gg))
1560 ; (setq hh (nplcm (function-numerator (apply-rmap map (zopen-inequality from-open)))
1563 ; (loop for v in red-transl
1564 ; when (not (unit-idealp (ldata-eqns v) hh))
1565 ; collecting v into tem
1566 ; finally (return (cond ((> (length tem) 1)
1568 ; "~%The image had two components meet the intersection.")
1569 ; (des tem) (break 'two))
1570 ; ((= (length tem) 1) (car tem))
1573 (defun sftimes (f g
)
1574 (square-free (ptimes f g
)))
1578 (defun apply-rmap-to-square-free-factors (mapl pol
&aux answ
)
1579 (let ((facts (non-constant-factors pol
)))
1580 (cond ((null facts
) (cons pol
1))
1583 for v in facts by
#'cddr
1584 collecting v into tem
1585 finally
(setq answ
(apply-rmap mapl tem
))
1587 with answer
= (cons 1 1)
1588 do
(setq answer
(rattimes answer v t
))
1589 finally
(return-from sue answer
)))))))
1591 ;;;did not need to compute the translated ldata except on the intersection
1592 (defun translate-component-and-reduce (from-open to-open ldata
&key
(use-inverse-inequal t
)
1593 &aux
*refine-opens
* hh gg red-transl answ
1594 inv inv-denom transl MAPL
)
1595 ; (declare (values ldata intersection-inequality-on-to-open))
1596 (setq MAPL
(find-ring-map from-open to-open
))
1598 (setq gg
(zopen-inequality to-open
))
1599 (cond (use-inverse-inequal
1600 (setq inv
(find-ring-map to-open from-open
))
1601 (setq inv-denom
(function-numerator (apply-rmap-to-square-free-factors
1602 MAPL
(rmap-denom inv
))))
1603 (setq hh
(sftimes gg inv-denom
))
1607 (setq transl
(apply-rmap MAPL ldata
))
1608 (setq hh
(sftimes (rmap-denom MAPL
) hh
))
1609 (setq hh
(sftimes (function-numerator (apply-rmap MAPL
(zopen-inequality from-open
)))
1611 ;;calculate on open intersection (possibly using the inv-denom !!)
1612 (setq red-transl
(ldata-simplifications transl
:open-g hh
))
1615 (loop for v in red-transl
1616 when
(not (unit-idealp (ldata-eqns v
) hh
))
1617 collecting v into tem
1618 finally
(return (cond ((> (length tem
) 1)
1620 "~%The image had two components meet the intersection.")
1621 (des tem
) (fsignal 'two-components
))
1622 ((= (length tem
) 1) (car tem
))
1626 ;(defun translate-reduced-component-and-reduce (from-open to-open ldata &aux leng)
1627 ; (multiple-value-bind ( answ hh)
1628 ; (translate-component-and-reduce from-open to-open ldata
1629 ; :use-inverse-inequal nil)
1631 ; (cond ((null answ) (values answ hh))
1632 ; ((equal leng (length (ldata-eqns ldata)))
1633 ; (cond ((null use-inverse-inequal)
1635 ; (translate-component-and-reduce from-open to-open ldata
1636 ; :use-inverse-inequal t
1638 ; (t (values answ hh)))))
1640 (defun ldata-codim (ldata)
1641 (length (ldata-eqns ldata
)))
1642 ;;to hell with the expense: use translate the correct intersection inequality.
1643 (defun translate-reduced-component-and-reduce (from-open to-open ldata
1644 &key homogeneous-ldata-on-to-open
1645 &aux answer int-transl
1646 contract simp-contract
)
1647 (multiple-value-bind ( answ hh
)
1648 (translate-component-and-reduce from-open to-open ldata
1649 :use-inverse-inequal t
)
1650 (cond ((null answ
)(values answ hh
))
1655 (linear-solvedp (ldata-eqns answ
))
1656 (linear-ldatap answ
:open-g
(zopen-inequality to-open
)))
1659 (contract-ideal-localization (ldata-eqns answ
)
1662 (setq simp-contract
(simplify-ldata (make-ldata :eqns contract
)
1664 (zopen-inequality to-open
)))
1665 (cond ((null simp-contract
) (values simp-contract hh
))
1666 ((> (length simp-contract
) 2)
1667 (loop for v in simp-contract
1668 when
(and (null (unit-idealp (ldata-eqns v
) hh
))
1669 (equal (ldata-codim v
)
1670 (ldata-codim ldata
)))
1671 collecting v into some-ld
1672 finally
(cond ((> (length some-ld
) 1)
1673 (fsignal "Too many components"))
1674 ((eql (length some-ld
) 1)
1677 (t (setq simp-contract
(car simp-contract
)))))))
1678 (cond ((not (equal (length (ldata-eqns answer
))
1679 (length (ldata-eqns ldata
))))
1680 (cond ((null *query-user
*)
1681 (throw 'new-choice nil
))
1682 (homogeneous-ldata-on-to-open
1684 (intersect-ldata homogeneous-ldata-on-to-open
1686 (fsignal "Wrong dimension or not complete intersection ~
1687 look at the value of int-transl "))
1688 (t (setq answer answ
)))
1691 (cond ((and *query-user
* answer
1692 (loop for v in
(ldata-eqns answer
)
1693 when
(not (or (any-linearp v
(zopen-inequality to-open
))
1694 (gm-prepared v
:inequal
(zopen-inequality to-open
))))
1696 (fsignal "not linear or well prepared on to open")))
1697 (values answer hh
)))
1699 ;(defun translate-reduced-component (from-open to-open ldata pls
1700 ; &key( break-bad-component t)
1701 ; &aux map gg hh answer
1702 ; image answ cont unit *stop-simplify*)
1703 ; "Takes eqns (which one might want to turn into coordinates) and translates them
1704 ; around to the other opens. For example if one had an ldata of some one open
1705 ; and wanted to blow it up one would need the translates of this, before blowing up."
1708 ; (cond ((eq from-open to-open) ldata)
1710 ; (setq to-open (nth to-open (pls-opens pls)))
1711 ; (setq from-open (nth from-open (pls-opens pls)))
1712 ; (setq hh (zopen-inequality to-open ))
1713 ; (setq gg (zopen-inequality from-open ))
1714 ; (cond ((ldatap ldata) nil)
1715 ; (t (setq ldata (make-ldata :eqns ldata :inequality
1717 ; (setq map (find-ring-map from-open to-open))
1718 ; (setq image (apply-rmap map ldata))
1719 ; (setq gg (function-numerator (apply-rmap map gg)))
1720 ; (setq hh (nplcm hh gg))
1721 ; (setq hh (nplcm (rmap-denom map) hh))
1722 ; (setq answ (ldata-simplifications image))
1723 ; (loop for v in answ
1724 ; do (multiple-value
1726 ; (grobner-subset (ldata-eqns v)
1727 ; (ldata-eqns image)
1729 ; (cond (unit (format t "%intersection is empty") (return 'empty))
1730 ; (cont (return (setq answer v))))
1731 ; finally (cond (answ (return
1732 ; (cond (break-bad-component
1733 ; (merror "bad-comp")
1734 ; (break 'bad-component))
1735 ; (t (format t "****Bad component: not trivial****")))))))
1740 (defun ldata-subset (ld ldd
)
1741 (grobner-subset (ldata-eqns ld
) (ldata-eqns ldd
) (ldata-inequality ldd
)))
1743 ;(defun test (pl n m l &aux opens im (ldata (nth n (nth m (pls-data pl)))))
1744 ; (setq opens (pls-opens pl))
1745 ; (setq im (translate-component (nth m opens) (nth l opens) ldata))
1746 ;; (setq denom (apply-rmap ma (rmap-denom (coord
1747 ; (loop for ld in (nth l (pls-data pl))
1748 ; when (grobner-subset ld im)
1749 ; do (format t "image is:") (shl im)
1750 ; (format t" containing")(des ld)
1751 ; (des (nth l (pls-data pl)))))
1754 (defun pls-ldata (pls OPEN
&key ldata-number
&aux answer
)
1755 "Gets the list of ldata corresponding to OPEN"
1756 (cond ((numberp open
)(setq open
(nth open
(pls-opens pls
)))))
1757 (check-arg open
(eq (car open
) 'zopen
) "an open")
1758 (setq answer
(loop for v in
(pls-opens pls
)
1759 for w in
(pls-data pls
)
1762 (cond (ldata-number (nth ldata-number answer
))
1765 ;(defun function-numerator (f)
1766 ; (cond ((affine-polynomialp f) f)
1767 ; ((rational-functionp f) (num f))
1768 ; (t (num (new-rat f)))))
1770 ;(defun match-components (pls nth-open &aux map opens open gg image cont unit answ)
1771 ; (setq opens (pls-opens pls))
1772 ; (setq open (nth nth-open opens))
1774 ; (loop for ld in (pls-ldata pls open)
1777 ; (loop for op in opens
1779 ; for lis-ld in (pls-data pls)
1780 ; when (not (eql i nth-open))
1783 ; (setq map (find-ring-map open op))
1784 ; (setq image (apply-rmap map ld))
1785 ; (setq gg (function-numerator (apply-rmap map (zopen-inequality open))))
1786 ; (setq gg (plcm (rmap-denom map) gg))
1787 ; (loop for ldd in lis-ld
1790 ; (multiple-value (cont unit)
1791 ; (grobner-subset (ldata-eqns ldd)
1792 ; (ldata-eqns image)
1793 ; (plcm (zopen-inequality op) gg)))
1798 ; "~%The intersection with the ~D open is empty."
1800 ; (cond ((and (null unit) cont)
1801 ; (cond ((null (grobner-subset
1802 ; (ldata-eqns image)
1804 ; (plcm (zopen-inequality op) gg)))
1806 ; (merror "containment only one way!!")))))
1807 ; when unit do (return nil)
1808 ; when (and (null unit)cont)
1809 ; collecting (cons i j) into tem
1811 ; (cond ((and lis-ld (null tem))
1812 ; (merror "this component not trivial")))
1814 ; (loop for u in answ
1816 ; (loop for vv in (cdr u)
1821 ; "~%on open ~A the ~D component is contained in its image"
1822 ; (car v)(cdr v)))))
1826 (defun union-equal (&rest lists
&aux result
)
1827 (loop for l in lists do
1829 (pushnew w result
:test
#'equal
)))
1832 (defun intersection-equal1 (&rest l
)
1833 (cond ((eql (length l
) 1) (car l
))
1834 (t (apply #'intersection-equal
(loop for v in
(car l
)
1835 when
(member v
(second l
) :test
#'equal
)
1839 (defun intersectp (a b
&key test
)
1840 (loop named sue for v in a
1842 when
(funcall test v w
)
1843 do
(return-from sue t
))))
1846 ;;;doesn 't work!! eg if str1 is nil
1847 ;(defun build-equivalence-relation1 (str1 str2 &aux str3)
1849 ; (loop for v in str1
1851 ; (loop for w in str2
1852 ; when (intersectp v w :test 'equal)
1853 ; appending (union-equal v w) into tem))))
1855 (defun build-equiv (lis &key
(test #'equal
))
1858 do
(loop for w in lis
1859 when
(and (not (eql v w
)) (intersectp v w
:test test
))
1861 (setq lis
(cons (union-equal v w
)
1862 (delete w
(delete v lis
:test
#'equal
) :test
#'equal
)))
1863 (return-from sue
(build-equiv lis
:test test
)))
1864 finally
(return (mapcar #'union-equal lis
)))))
1866 (defun check-equivalence-relation (lis-equiv-classes)
1868 (loop for v in lis-equiv-classes
1869 do
(loop for w in lis-equiv-classes
1870 when
(intersectp v w
:test
'equal
)
1871 do
(cond ((not (eql v w
)) (return-from sue nil
))))
1872 finally
(return t
))))
1874 (defun add-zopen-history (zopen n
)
1875 (cond ((>= (length zopen
) 5)
1876 (zl-copy-structure zopen zopen- history
(cons n
(zopen-history zopen
))))
1877 (t (setq zopen
(nconc zopen
(copy-list (list nil
) )))
1878 (add-zopen-history zopen n
))))
1880 (defvar *bad-components
* nil
)
1882 ;(defun new-match-components (pls open-number)
1883 ; (declare (special str))
1884 ; (loop for ld in (pls-ldata open-number)
1887 ; (new-match-component pls open-number ii)))
1889 ;(defun new-match-component (pls open ld-number &aux (opens (pls-opens pls)) hh nth-open
1890 ; ok map image gg simped images cont unit *bad-components* ld)
1891 ; (setq nth-open (find-position-in-list opens))
1892 ; (setq ld (pls-ldata 0 :ldata-number ld-number))
1893 ; (loop for op in (pls-opens pls)
1895 ; for lis-ld in (pls-data pls)
1896 ; when (equal op open)
1897 ; do (push (cons nth-open ld-number ) str)
1899 ; do (setq map (find-ring-map op open))
1900 ; (setq image (apply-rmap map ld))
1901 ; (setq gg (function-numerator (apply-rmap map (zopen-inequality open))))
1902 ; (setq gg (plcm (rmap-denom map) gg))
1903 ; (setq images (list image))
1906 ; (loop while images
1907 ; do (setq image (car images))
1908 ; (setq images (cdr images))
1909 ; (loop for an-ld in lis-ld
1912 ; (multiple-value (cont unit)
1913 ; (grobner-subset (ldata-eqns an-ld)
1914 ; (ldata-eqns image)
1915 ; (setq hh (plcm (zopen-inequality op) gg))))
1917 ; do (setq ok t) (push (cons nth-open j) str)
1919 ; do (push (cons nth-open nil) str)
1920 ; (setq ok t) (return 'empty))
1921 ; finally (cond ((and lis-ld (null ok))
1922 ; (cond ((null simped)
1923 ; (setq images (ldata-simplifications image))
1925 ; (cond ((equal (ldata-eqns (car images))
1926 ; (ldata-eqns image))
1927 ; (setq images nil))))
1930 ; (push (list nth-open i ld-number) *bad-components*)
1931 ; (format t "~%Bad component ~A" (car *bad-components*)))))))))
1933 (defun final-check-contained-in (lis-ld orig-image hh current-open
1934 current-ld-number nth-open
1935 &aux images cont unit
*refine-opens
*)
1936 (setq images
(ldata-simplifications orig-image
:open-g hh
))
1937 (loop named sue for image in images
1939 (loop for v in lis-ld
1942 (multiple-value (cont unit
)
1943 (grobner-subset (ldata-eqns v
) (ldata-eqns image
) hh
))
1947 cont do
(cond ((eql (length (ldata-eqns v
))
1948 (length (ldata-eqns image
)))
1949 (return-from sue
(cons current-open i
)))
1950 (t (format t
"image properly contains zl-SOME part"))))
1952 finally
(push (list nth-open current-open
1953 current-ld-number
) *bad-components
*)
1954 (format t
"~%Bad component ~A" (car *bad-components
*))
1957 ;(defun match-components (pls nth-open &key check-equal break-on-bad ignore-empty-opens
1958 ; ldata-number &aux map opens open gg hh image cont unit answ found-one str lis-dat rev-cont)
1959 ; (setq opens (pls-opens pls))
1960 ; (setq open (nth nth-open opens))
1961 ; (setq lis-dat (pls-ldata pls open) )
1962 ; (cond (ldata-number (setq lis-dat (list (nth ldata-number lis-dat)))))
1964 ; (loop for ld in lis-dat
1966 ; ;;str will be ( (open number . ld number) ...)
1968 ; do (setq str (list (cons nth-open ldata-number)))
1971 ; (setq str (list (cons nth-open ii)))
1973 ; (loop for op in opens
1975 ; for lis-ld in (pls-data pls)
1976 ; when (and (not (eql i nth-open)) (or lis-ld (null ignore-empty-opens)))
1977 ; do (setq found-one nil)
1979 ; (setq map (find-ring-map open op))
1980 ; (setq image (apply-rmap map ld))
1981 ; (setq gg (function-numerator (apply-rmap map (zopen-inequality open))))
1982 ; (setq gg (nplcm (rmap-denom map) gg))
1983 ; (loop for ldd in lis-ld
1986 ; (multiple-value (cont unit)
1987 ; (grobner-subset (ldata-eqns ldd)
1988 ; (ldata-eqns image)
1989 ; (setq hh (nplcm (zopen-inequality op) gg))))
1990 ; (cond ((and cont check-equal (null unit))
1991 ; (setq rev-cont (grobner-subset (ldata-eqns ldd)
1992 ; (ldata-eqns image)
1994 ; (cond ((null rev-cont)
1995 ; (cond (break-on-bad (break 'not-equal)))))))
2000 ; "~%The intersection with the ~D open is empty."
2002 ;; (cond ((and (null unit) cont)
2003 ;; (cond ((null (grobner-subset
2004 ;; (ldata-eqns image)
2006 ;; (nplcm (zopen-inequality op) gg)))
2008 ;; (merror "containment only one way!!")))))
2009 ; when unit do (push (cons i nil) str)(setq found-one t)
2010 ; when (and (null unit)cont)
2011 ; do (push (cons i j) str) (setq found-one t)
2013 ; (cond ((and lis-ld (null found-one))
2014 ; (push (list nth-open ii i open ld) *bad-components*)
2015 ; (format t "~%*****Bad component..****")
2016 ; (format t " original open and component are:")
2017 ; (des open) (des ld)
2018 ; (format t "%On the image open the components are:")
2019 ; (loop for l in lis-ld do (des l))
2020 ; (format t "while image is :")
2022 ; (cond (break-on-bad (break t))))
2025 ; ; "this component not trivial but doesn't seem to be here"))))))
2031 (defun match-components (pls nth-open
&key check-equal break-on-bad ignore-empty-opens
2032 ldata-number
&aux MAPL opens open gg hh tem
2033 image cont unit answ found-one str lis-dat rev-cont
)
2034 (setq opens
(pls-opens pls
))
2035 (setq open
(nth nth-open opens
))
2036 (setq lis-dat
(pls-ldata pls open
) )
2037 (cond (ldata-number (setq lis-dat
(list (nth ldata-number lis-dat
)))))
2039 (loop for ld in lis-dat
2041 ;;str will be ( (open number . ld number) ...)
2043 do
(setq str
(list (cons nth-open ldata-number
)))
2046 (setq str
(list (cons nth-open ii
)))
2048 (loop for op in opens
2050 for lis-ld in
(pls-data pls
)
2051 when
(and (not (eql i nth-open
)) (or lis-ld
(null ignore-empty-opens
)))
2052 do
(setq found-one nil
)
2054 (setq MAPL
(find-ring-map open op
))
2055 (setq image
(apply-rmap MAPL ld
))
2056 (setq gg
(function-numerator (apply-rmap MAPL
(zopen-inequality open
))))
2057 (setq gg
(nplcm (rmap-denom MAPL
) gg
))
2058 (loop for ldd in lis-ld
2061 (multiple-value (cont unit
)
2062 (grobner-subset (ldata-eqns ldd
)
2064 (setq hh
(nplcm (zopen-inequality op
) gg
))))
2065 (cond ((and cont check-equal
(null unit
))
2066 (setq rev-cont
(grobner-subset (ldata-eqns ldd
)
2069 (cond ((null rev-cont
)
2070 (cond (break-on-bad (break 'not-equal
)))))))
2075 "~%The intersection with the ~D open is empty."
2077 ; (cond ((and (null unit) cont)
2078 ; (cond ((null (grobner-subset
2079 ; (ldata-eqns image)
2081 ; (nplcm (zopen-inequality op) gg)))
2083 ; (merror "containment only one way!!")))))
2084 when unit do
(push (cons i nil
) str
)(setq found-one t
)
2085 when
(and (null unit
)cont
)
2086 do
(push (cons i j
) str
) (setq found-one t
)
2088 (cond ((and lis-ld
(null found-one
))
2089 (setq tem
(final-check-contained-in
2090 lis-ld image hh i j nth-open
))
2091 (cond (tem (push tem str
))))
2092 ; (push (list nth-open ii i open ld) *bad-components*)
2093 ; (format t "~%*****Bad component..****")
2094 ; (format t " original open and component are:")
2095 ; (des open) (des ld)
2096 ; (format t "%On the image open the components are:")
2097 ; (loop for l in lis-ld do (des l))
2098 ; (format t "while image is :")
2100 ; (cond (break-on-bad (break t))))
2103 ; "this component not trivial but doesn't seem to be here"))))))
2111 (defun list-opens1 (components &aux answ
)
2112 (loop for com in components
2113 do
(loop for v in com do
2114 (push-new (car v
) answ
))
2115 finally
(return answ
)))
2117 (defun short-list-open-numbers ( components-to-cover
&optional opens-used
2118 &aux where an-answ ops
)
2119 (cond ((null components-to-cover
) opens-used
)
2120 (t (setq ops
(list-opens1 components-to-cover
))
2122 with prev-min
= 10000000
2125 (loop for com in components-to-cover
2126 when
(not (assoc op com
:test
#'eq
))
2127 collecting com into tem
2128 finally
(return (short-list-open-numbers tem
2129 (cons op opens-used
)))))
2130 when
(< (length an-answ
) prev-min
)
2131 do
(setq prev-min
(length an-answ
)) (setq where an-answ
)
2132 finally
(return where
)))))
2136 (defun fast-match-components (pls &aux components-to-cover transl hh to-open to-lis-dat
2137 components all-codims ops bad-one
)
2138 "we assume that the pls has been reduced"
2139 (loop for op in
(pls-opens pls
)
2141 for lis-dat in
(pls-data pls
)
2143 (setq components-to-cover nil
)
2144 (loop for ld in lis-dat
2146 when
(not (or (linear-solvedp (ldata-eqns ld
))
2147 (linear-ldatap ld
)))
2148 do
(setq bad-one ld
)
2149 (setq components-to-cover components
) (return 'done
)
2152 (loop for dim in all-codims
2153 for comp in components
2154 when
(equal dim
(length (ldata-eqns ld
)))
2155 do
(push-new comp components-to-cover
)))
2156 (setq ops
(short-list-open-numbers components-to-cover
))
2157 (setq ops
(ml-sort ops
))
2159 (loop for to-op-num in ops
2161 do
(setq to-open
(nth to-op-num
(pls-opens pls
)))
2162 (setq to-lis-dat
(nth to-op-num
(pls-data pls
)))
2163 (loop for lld in lis-dat
2165 when
(not (member lld accounted-for
:test
#'eq
))
2167 (multiple-value-setq
2168 (transl hh
) (translate-reduced-component-and-reduce
2172 (loop for ld in to-lis-dat
2175 (and (not (unit-idealp (ldata-eqns ld
) hh
))
2176 (variety-ldata-subset ld transl
:open-g hh
2177 :ignore-ldata-inequalities t
))
2180 ((variety-ldata-subset
2181 transl ld
:open-g hh
2182 :ignore-ldata-inequalities t
)
2183 (nconc (get-component components
(cons to-op-num ld-num
))
2184 (list (cons op-num lld-num
)))
2185 (push lld accounted-for
))
2186 (t (fsignal "containment one way")))))
2187 finally
(loop for lld in lis-dat
2189 when
(not (member lld accounted-for
:test
#'eq
))
2190 do
(show to-op-num lld-num
)
2192 collecting
(list (cons op-num lld-num
)) into comps
2194 collecting
(length (ldata-eqns lld
)) into dims
2195 finally
(setq components
(nconc components comps
))
2196 (setq all-codims
(append all-codims dims
)))))
2197 (values components all-codims
))
2199 (defun get-component (components cons-op-ld
)
2200 (loop for com in components
2201 when
(member cons-op-ld com
:test
#'equal
)
2203 (defun list-opens-with-component (pls open-num compon-num
&aux answ
)
2204 (setq answ
(nth compon-num
(match-components pls open-num
)))
2205 (des (nth compon-num
(nth open-num
(pls-data pls
))))
2206 (format t
"~%is in opens: ")
2207 (loop for op in
(pls-opens pls
)
2209 when
(eq (cdr (assoc i answ
:test
#'equal
)) compon-num
)
2212 (defun match-all-components (pls &key
(ignore-empty-opens t
)
2213 &aux all equiv opens
*bad-components
*)
2215 (setq opens
(pls-opens pls
))
2216 (setq all
(loop for i below
(length opens
)
2217 appending
(match-components pls i
:ignore-empty-opens ignore-empty-opens
)))
2218 (setq equiv
(build-equiv all
:test
#'(lambda (u v
)
2219 (and (equal u v
) (cdr v
)))))
2221 ; (cond ((check-equivalence-relation equiv) equiv)
2222 ; (t (merror "some components don't match up ~A" equiv)))
2223 (setq equiv
(loop for v in equiv
2224 collecting
(sort v
#'(lambda (u v
) (< (car u
) (car v
))))))
2225 (list 'components equiv
*bad-components
*))
2227 (defun verify-simplification (pl1 pl2simp
)
2228 (loop for open in
(sv-zopens (pls-s-var pl1
))
2230 for lis-dat in
(pls-data pl1
)
2232 (format t
"~%**For the original ~:R open" i
)
2233 (loop for op2 in
(sv-zopens (pls-s-var pl2simp
))
2235 for lis-dat2 in
(pls-data pl2simp
)
2236 when
(equal (zopen-coord open
) (zopen-coord op2
))
2237 ;; should really look at inequal when (equal open op2)
2238 do
(format t
" whose coordinates are equal to those on open ~D" j
)
2240 (check-component-containment lis-dat lis-dat2
))
2241 ; (check-components-contain-original (car lis-dat) lis-dat2))
2242 (t (format t
"the data was empty"))))))
2245 ;;the following system of equations does not admit a nice solution using the above.
2246 ;;maybe we have to add another divide-dichotomy machine:
2247 ;;If have two polynomials with leading term x6 could do a dichotomy:
2248 ;;f=y^i*a+.. g=y^j*b+.. then do
2249 ;; while y is the main variable you make dichotomy
2250 ;;between (third (vdivide f g))=0 and (third (vdivide f g)) invertible.
2251 ;;in the latter system you have the additional ldata of remainder.
2253 ;;(LDATA ((X7 1 1) (X8 1 1) (X5 2 1 1 (X4 2 -2 0 (X3 1 (X2 1 1))) 0 (X4 4 1 2 (X3 1 (X2 1 1)) 1 (X3 1 (X1 1 2)))) (X6 1 (X5 1 (X2 1 1) 0 (X4 2 (X2 1 1) 1 (X1 1 2))) 0 (X5 1 (X4 1 (X2 1 3) 0 (X1 1 2)) 0 (X4 3 (X2 1 -1)))) (X6 1 (X5 1 1 0 (X4 2 -1)) 0 (X5 1 (X4 1 -1) 0 (X4 3 1 1 (X3 1 (X2 1 -1)) 0 (X3 1 (X1 1 -1))))) (X5 1 (X2 2 1) 0 (X1 2 -1))) 1 2)
2254 (defmacro minimize
( for v in a-list quantity
)
2255 ; (declare (values where-its-miniminum))
2256 (iassert (and (eq for
'for
) in
'in
))
2257 `(loop for
,v in
,a-list
2258 with .prev-min.
= 10000000
2260 do
(setq .tem.
,quantity
)
2261 when
(< .tem. .prev-min.
)
2262 do
(setq .where.
,v
)
2263 (setq .prev-min. .tem.
)
2264 finally
(return .where.
)))
2266 (defmacro for
(v in-or-on a-list
&rest body
&aux when-clause operation quantity pred op init
)
2267 "operation may be :minimize, maximize, general-summing, or general-product;
2268 and the the quantity will ususually involve the variable v. The result of the
2269 minimize is where the minimum is"
2270 (iassert (member in-or-on
'(in on
) :test
#'eq
))
2271 (cond ((equal (car body
) 'when
)
2272 (setq when-clause
(subseq body
0 2) body
(cddr body
)))
2273 (t (iassert (eql (length body
) 2))))
2274 (setq operation
(first body
) quantity
(second body
))
2275 (cond ((member operation
'(minimize maximize
) :test
#'equal
)
2276 (cond ((eq operation
'minimize
)
2278 (setq init
10000000))
2279 (t (setq pred
'>) (setq init -
100000000)))
2280 `(loop for
,v
,in-or-on
,a-list
2281 with .prev-min.
= ,init
2285 (setq .tem.
,quantity
)
2286 ,@ (cond (when-clause '(and))(t nil
))
2287 when
(,pred .tem. .prev-min.
)
2288 do
(setq .where.
,v
)
2289 (setq .prev-min. .tem.
)
2290 finally
(return .where.
)))
2291 ((member operation
'(general-summing general-product
) :test
#'equal
)
2292 (cond ((eq operation
'general-summing
)
2293 (setq op
'N
+) (setq init
0))
2294 ((eq operation
'general-product
)
2295 (setq op
'n
*) (setq init
1)))
2296 `(loop for
,v
,in-or-on
,a-list
2297 with .answer.
= ,init
2299 do
(setq .answer.
(,op
,quantity .answer.
))
2300 finally
(return .answer.
)))
2301 (t (fsignal "The operation was not one of minimize, maximize, general-summing, or general-product"))))
2305 ;;(for v in '(-1 -3 -.5 2 3) when (< v 0) minimize (abs v ))
2307 ;;(for v in '(-1 $x -3 -.5 2 3) general-product v )
2308 ;;(for v in '(-1 $x -3 -.5 2 3) when (> v 0) general-product v )
2311 ;(defun good-order-variables (eqns &aux variable-occurs (varl (list-variables eqns)))
2312 ; (declare (special mult))
2313 ; (declare (values . (list ordered-list variable-occurs-in)))
2314 ; (setq variable-occurs (mapcar 'list-variables eqns))
2320 ; (loop for w in variable-occurs
2322 ; when (member v w :test #'eq)
2324 ; (setq mult (sort mult #'(lambda (u v)
2325 ; (< (cdr u) (cdr v)))))
2326 ; (list (mapcar 'car mult) variable-occurs))
2329 ;;this allowed me to do the troublesome ldata
2330 ;;it tries to order the variables so that the variables belonging to
2331 ;;simpler and less equations come first.
2332 ;(defun good-order-variables (eqns &aux variable-occurs (varl (list-variables eqns))
2334 ; (declare (special mult))
2335 ; (declare (values . (list ordered-list variable-occurs-in)))
2336 ; (setq variable-occurs (mapcar 'list-variables eqns))
2337 ; (setq compl (loop for v in eqns collecting (gen-pcomplexity v)))
2343 ; (loop for w in variable-occurs
2345 ; when (member v w :test #'eq)
2346 ; count 1 into the-mult
2347 ; finally (return (* the-mult (loop for com in compl
2348 ; for ww in variable-occurs
2349 ; when (member v ww :test #'eq)
2350 ; minimize com)))))))
2351 ; (setq mult (sort mult #'(lambda (u v)
2352 ; (< (cdr u) (cdr v)))))
2353 ; (list (mapcar 'car mult) variable-occurs))
2355 (defun good-order-variables (ldata &aux variable-occurs varl order eqns
2357 (declare (special mult
))
2358 ; (declare (values . (list ordered-list variable-occurs-in)))
2359 (cond ((ldatap ldata
)
2360 (cond ((ldata-variables ldata
)(list (ldata-variables ldata
) (mapcar 'list-variables
2361 (ldata-eqns ldata
))))
2362 (t (setq order
(good-order-variables (ldata-eqns ldata
)))
2363 (setf (ldata-variables ldata
) (car order
))
2365 (t (setq eqns ldata
)
2366 (setq varl
(list-variables eqns
))
2367 (setq variable-occurs
(mapcar 'list-variables eqns
))
2368 (setq compl
(loop for v in eqns collecting
(gen-pcomplexity v
)))
2373 (loop for w in variable-occurs
2375 when
(member v w
:test
#'eq
)
2376 count
1 into the-mult
2377 finally
(return (* the-mult
(loop for com in compl
2378 for ww in variable-occurs
2379 when
(member v ww
:test
#'eq
)
2381 (setq mult
(sort mult
#'(lambda (u v
)
2382 (< (cdr u
) (cdr v
)))))
2383 (list (mapcar 'car mult
) variable-occurs
))))
2386 (defun charactaristic-setp (eqns &aux lis answ ordered-vars highest-vars occurs
)
2387 (setq lis
(good-order-variables eqns
))
2388 (setq ordered-vars
(first lis
))
2390 (loop for v in
(setq occurs
(second lis
))
2391 collecting
(loop for u in ordered-vars
2392 when
(member u v
:test
#'eq
)
2394 (setq answ
(loop for v on highest-vars
2395 when
(member (car v
) (cdr v
) :test
#'eq
)
2397 finally
(return t
)))
2398 (values answ ordered-vars occurs highest-vars
))
2402 ;(defun order-equations (eqns variables &optional occurs &aux all-eqns)
2403 ; (cond ((null occurs) (setq occurs (mapcar 'list-variables eqns))))
2404 ; (loop for va in variables
2406 ; (loop for eqn in eqns
2408 ; when (member va oc :test #'eq)
2409 ; do (push-new eqn all-eqns)))
2410 ; (nreverse all-eqns))
2412 (defun order-equations (eqns &aux tem
)
2413 ; (declare (values eqns ch-set))
2414 (multiple-value-bind (ch-set vars ignore highest-vars
)
2415 (charactaristic-setp eqns
)
2416 (setq eqns
(cond (ch-set
2418 when
(setq tem
(find-position-in-list v highest-vars
))
2419 collecting
(nth tem eqns
)))
2421 (values eqns ch-set
)))
2423 (defun highest-variables (variables occurs
)
2424 (loop for oc in occurs
2425 collecting
(loop for v in variables
2426 when
(member v oc
:test
#'eq
) do
(return v
))))
2428 (defun all-linear-variables (f &optional g
&aux varl
)
2429 (setq varl
(degree-one-variables f
))
2430 (loop for v in varl when
(may-invertp (pcoeff f
(list v
1 1 ) ) g
)
2433 (defun poly-relations-from-simplifications (&optional
(simps *poly-simplifications
*))
2434 (loop for
(seq repl
) on simps by
#'cddr
2435 when
(numberp seq
) do
(return '( 1))
2438 (ptimes (convert-deg-sequence-to-monomial seq
)
2442 (defun simplify-ldata (ldata &key
(open-g 1) refine-opens error-check-containments
2443 &aux answ result changed
)
2444 (let ((*refine-opens
* refine-opens
) *stop-simplify
*)
2445 (setq answ
(ldata-simplifications ldata
:open-g open-g
:error-check-containments
2446 error-check-containments
))
2448 (setq answ
(loop for ld in answ
2449 when
(linear-ldatap ld
:open-g open-g
)
2452 do
(loop for fn in
(ldata-eqns ld
)
2453 when
(> (length (non-constant-factors fn
)) 2)
2455 (return (setq result
(make-dichotomy ld
:open-g open-g
)))
2456 finally
(setq result
(list ld
)))
2458 (cond (changed (setq answ
(delete-redundant-ldata answ
:gg open-g
))))
2461 ;;this is hoky. It should try much harder!!
2462 (defvar *dont-try-factor-irreducible-ldata
* nil
)
2464 (defun try-factor-irreducible-ldata (ldata &optional
(open-g 1) &aux answ orig-ldata answer
2465 lin-vars eqn varl comp new-ldata tem
(eqns (ldata-eqns ldata
)))
2466 (declare (special *already-tried
*))
2467 (cond ((not (boundp '*already-tried
*)) (setq *already-tried
* nil
)))
2468 (setq orig-ldata ldata
)
2469 ;;should be wrt open-g
2470 (cond ((member(setq tem
(list ldata open-g
)) *already-tried
* :test
#'equal
)
2472 (*dont-try-factor-irreducible-ldata
* (list ldata
))
2475 (catch 'took-too-long
2476 (push tem
*already-tried
*)
2478 ((setq varl
(linear-ldatap ldata
:open-g open-g
))
2479 (setq eqns
(reduce-linear-ldata ldata varl
:open-g open-g
))
2480 (cond ((grobner-subset '(1) eqns open-g
) nil
)
2481 (t (list (zl-copy-structure ldata ldata- eqns eqns
)))))
2482 ((< (setq comp
(gen-pcomplexity (ldata-eqns ldata
))) 200)
2483 (LET (*poly-simplifications
*)
2484 (grobner-remember (ldata-eqns ldata
))
2485 (cond (*poly-simplifications
*
2486 (setq new-ldata
(make-ldata :eqns
(poly-relations-from-simplifications)
2487 :inequality
(plcm open-g
(ldata-inequality ldata
)))))))
2488 (cond ((< (gen-pcomplexity (ldata-eqns new-ldata
)) (* 1.1 comp
))
2489 (setq ldata new-ldata
)))
2491 (setq lin-vars
(loop for f in eqns collecting
(all-linear-variables f open-g
)))
2495 (loop for v in lin-vars
2498 do
(setq varl
(list-variables f
))
2499 (loop for w in lin-vars
2501 when
(setq tem
(intersection w varl
))
2504 do
(setq eqn
(gen-prem f ff uu
))
2505 when
(> (length (non-constant-factors eqn open-g
)) 2)
2506 do
(return-from sue
(make-dichotomy
2507 (zl-copy-structure ldata ldata- eqns
(subst eqn f eqns
))
2509 finally
(return (list ldata
)))))
2510 (loop for ld in answ
2511 minimize
(length (ldata-eqns ld
)) into min
2512 finally
(cond ((> min
(length (ldata-eqns orig-ldata
)))
2513 (setq answ
(list orig-ldata
)))
2517 (cond ((eq answer
'took-too-long
)
2521 (defun matrix-to-sparse-matrix (mat &key
(re-use-sparse-matrix *sparse-matrix
*))
2522 (convert-to-sparse-matrix (matrix-rows mat
) :re-use-sparse-matrix re-use-sparse-matrix
2525 (defun matrix-rank (mat &aux sp
)
2526 (setq sp
(matrix-to-sparse-matrix mat
))
2528 (sp-number-of-pivots sp
))
2531 (defun show-matrix (mat)
2533 (let* ((dimensions (array-dimensions mat
))
2534 (number-dims (length dimensions
)))
2535 (cond ((eql number-dims
2)
2536 (loop for i below
(car dimensions
)
2538 (loop for j below
(second dimensions
)
2539 do
(format t
"~3D" (aref mat i j
)))))
2540 ((eql number-dims
3)
2541 (loop for i below
(car dimensions
)
2542 do
(format t
"~%~%Block ~D " i
)
2543 (loop for j below
(second dimensions
)
2545 (loop for k below
(third dimensions
)
2546 do
(format t
"~3D" (aref mat i j k
)))))))))
2548 (loop for v in
(matrix-rows mat
)
2549 do
(format t
"~% ~A " v
)))))
2551 (defun jacobian-matrix (list-eqns &optional variables
&aux mat
)
2552 (cond ((null variables
)(setq variables
(ml-sort (list-variables list-eqns
)))))
2553 (setq mat
(loop for f in list-eqns
2556 collecting
(pderivative f v
))))
2557 (make-matrix :rows mat
))
2561 ;(defun divide-dichotomy (ldata &key (open-g 1) &aux (eqns (ldata-eqns ldata)) f new-eqns
2562 ; occurs vars highest-vars orig-rep repeat eqns-rep gg ld1 ld2)
2564 ; "endeavors to turn ldata into an triangular list of eqns
2565 ; so that each equation has possibly one more variable occurring than the
2566 ; previous. It takes a good order for the variables and then takes the first variable
2567 ; to be highest in two succeeding eqns, and does a division to try to correct this. If
2568 ; the leading variable is not invertible it does a dichotomy. This dichotomy must be
2569 ; at the level of open sets, since otherwise we will not get component containment."
2570 ; ;;ordering should take into account open-g
2571 ; (setq vars (good-order-variables eqns))
2572 ; (setq occurs (second vars))
2573 ; (setq vars (first vars))
2574 ; (setq highest-vars
2575 ; (loop for v in occurs
2576 ; collecting (loop for u in vars
2577 ; when (member u v :test #'eq)
2579 ; (show vars highest-vars)
2581 ; (loop named rep for v in vars
2583 ; (loop for w on highest-vars
2584 ; when (and (eq (car w) v)
2585 ; (member v (cdr w) :test #'eq))
2586 ; do (return-from rep v))))
2589 ; (setq eqns-rep (loop for v in eqns
2590 ; for u in highest-vars
2591 ; when (eq u repeat)
2593 ; (setq orig-rep (copy-list eqns-rep))
2594 ; (show (length eqns-rep))
2595 ; (setq eqns-rep (sort-key eqns-rep '< 'pdegree repeat))
2596 ;; (progn (declare (special repeat))
2597 ;; (setq eqns-rep (sort eqns-rep
2598 ;; #'(lambda (u v) (< (pdegree u repeat) (pdegree v repeat))))
2599 ; (show (length eqns-rep))
2601 ; (cond ((eq ( pdegree (first eqns-rep) repeat)
2602 ; (pdegree (second eqns-rep) repeat))
2603 ; ;;choose the least complex leading coefficient to divide by
2605 ; (sort-key (firstn 2 eqns-rep) '<
2606 ; #'(lambda (u var) (pcomplexity
2607 ; (leading-coefficient u var)))
2609 ; (setq f (second eqns-rep))
2613 ; (multiple-value-bind (rem c-reqd)
2614 ; (gen-prem f (first eqns-rep) repeat)
2616 ; (shl (list f (first eqns-rep)))
2617 ; (setq new-eqns (delete f
2618 ; (copy-list eqns)))
2619 ; (cond (($zerop rem) nil)
2620 ; (t (setq new-eqns ;;these have f replaced by rem
2621 ; (append new-eqns (list rem)))))
2622 ;; (setq gg (nplcm open-g (ldata-inequality ldata)))
2623 ;; (cond ((may-invertp c-reqd gg)
2624 ;; (setq ld2 (make-ldata eqns new-eqns
2625 ;; inequality gg )))
2626 ;; ;;make two ldata one where c-reqd is invertible and f replaced by rem
2627 ;; ;; and other where its zero and f is still there.
2628 ;; (t (setq ld2 (make-ldata eqns new-eqns
2629 ;; inequality (nplcm gg c-reqd)))
2630 ;; (setq ld1 (make-ldata eqns
2631 ;; (cons c-reqd eqns)
2632 ;; inequality gg))))
2634 ;; (format t "~%Breaking into dichotomy on:")
2636 ;; (format t "%original ldata followed by consequents:" )
2637 ;; (des ldata)(des ld1) (des ld2 )
2639 ;; (append (ldata-simplifications ld1)
2640 ;; (ldata-simplifications ld2)))
2642 ;; (format t "~%The c-reqd was invertible: ")
2644 ;; (ldata-simplifications ld2)))))
2645 ;; (t (list ldata))))
2648 ;;;I hope this was the one to keep
2649 ;(defun divide-dichotomy (ldata &key (open-g 1) &aux answ (eqns (ldata-eqns ldata)) f new-eqns
2650 ; occurs vars highest-vars orig-rep repeat eqns-rep gg ld1 ld2)
2652 ; "endeavors to turn ldata into an triangular list of eqns
2653 ; so that each equation has possibly one more variable occurring than the
2654 ; previous. It takes a good order for the variables and then takes the first variable
2655 ; to be highest in two succeeding eqns, and does a division to try to correct this. If
2656 ; the leading variable is not invertible it does a dichotomy. This dichotomy must be
2657 ; at the level of open sets, since otherwise we will not get component containment."
2658 ; ;;ordering should take into account open-g
2659 ; (setq vars (good-order-variables eqns))
2660 ; (setq occurs (second vars))
2661 ; (setq vars (first vars))
2662 ; (setq highest-vars
2663 ; (loop for v in occurs
2664 ; collecting (loop for u in vars
2665 ; when (member u v :test #'eq)
2667 ; (show vars highest-vars)
2669 ; (loop named rep for v in vars
2671 ; (loop for w on highest-vars
2672 ; when (and (eq (car w) v)
2673 ; (member v (cdr w) :test #'eq))
2674 ; do (return-from rep v))))
2677 ; (setq eqns-rep (loop for v in eqns
2678 ; for u in highest-vars
2679 ; when (eq u repeat)
2681 ; (setq orig-rep (copy-list eqns-rep))
2682 ; (show (length eqns-rep))
2683 ; (setq eqns-rep (sort-key eqns-rep '< 'pdegree repeat))
2684 ;; (progn (declare (special repeat))
2685 ;; (setq eqns-rep (sort eqns-rep
2686 ;; #'(lambda (u v) (< (pdegree u repeat) (pdegree v repeat))))
2687 ; (show (length eqns-rep))
2689 ; (cond ((eq ( pdegree (first eqns-rep) repeat)
2690 ; (pdegree (second eqns-rep) repeat))
2691 ; ;;choose the least complex leading coefficient to divide by
2693 ; (sort-key (firstn 2 eqns-rep) '<
2694 ; #'(lambda (u var) (pcomplexity
2695 ; (leading-coefficient u var)))
2697 ; (setq f (second eqns-rep))
2698 ; (cond ((not (equal (ml-sort (copy-list eqns-rep))
2699 ; (ml-sort (copy-list orig-rep))))
2700 ; (merror "not sorted but destroyed!!")))
2703 ; (multiple-value-bind (rem c-reqd)
2704 ; (gen-prem f (first eqns-rep) repeat)
2705 ; (shl (list f (first eqns-rep)))
2706 ; (setq new-eqns (delete f
2707 ; (copy-list eqns)))
2708 ; (cond (($zerop rem) nil)
2709 ; (t (setq new-eqns ;;these have f replaced by rem
2710 ; (append new-eqns (list rem)))))
2711 ; (setq gg (nplcm open-g (ldata-inequality ldata)))
2713 ; (cond ((may-invertp c-reqd gg)
2714 ; (list (ldata-simplifications (make-ldata eqns new-eqns
2715 ; inequality gg ) open-g)))
2717 ; (setq ld1 (make-ldata eqns (cons f new-eqns) inequality (plcm c-reqd gg)))
2718 ; (setq ld2 (make-ldata eqns (cons c-reqd (ldata-eqns ldata)) inequality gg))
2719 ; (check-component-containment ldata (list ld1 ld2) open-g)
2721 ; (ldata-simplifications ld1 open-g)
2722 ; (ldata-simplifications ld2 open-g)))
2723 ; (check-component-containment ldata answ open-g)
2725 ; (t (list ldata))))
2728 ;;from version 7 ;;this worked on orig so be careful about modifying it!!!.
2729 ;;watch out for the use-inverse in delete redundant switch.
2731 (defvar *used-divisors
* nil
)
2733 (defun find-repeats (highest-variables eqns
&aux first-repeat repeat-eqns
)
2735 (loop for v on highest-variables
2737 when
(member (car v
) (cdr v
) :test
#'eq
)
2738 do
(cond ((cddr (setq repeat-eqns
2739 (loop for eqn in eqnss
2742 (not (member eqn
*used-divisors
* :test
#'equal
)))
2744 (return (car v
))))))
2745 (cond ((null (cddr repeat-eqns
)) (setq repeat-eqns nil
)))
2746 (values repeat-eqns first-repeat
))
2749 ;(defun new-divide-dichotomy (ldata &key (open-g 1) &aux var-and-occurs variables eqns occurs highest-variables
2751 ; repeated-eqns high-var)
2752 ; (setq var-and-occurs (good-order-variables ldata))
2753 ; (setq variables (car var-and-occurs) occurs (second var-and-occurs))
2754 ; (setq eqns (order-equations (ldata-eqns ldata) variables occurs))
2755 ; (setq occurs (mapcar 'list-variables eqns))
2756 ; (setq highest-variables (highest-variables variables occurs))
2757 ; (multiple-value-setq (repeated-eqns high-var)
2758 ; (find-repeats highest-variables eqns))
2761 ; (setq repeated-eqns (sort-key repeated-eqns '< 'pdegree high-var))
2764 ; (loop for v in repeated-eqns
2765 ; find v minimizing (+ (* 1000 (pdegree v high-var))
2766 ; (pcomplexity v))))
2767 ; (multiple-value-bind (rem c-reqd)
2768 ; (gen-prem (second repeated-eqns) divisor high-var)
2769 ; (setq ld1 (copy-list-structure ldata))
2770 ; (setf (ldata-eqns ld1)
2771 ; (cons rem (delete (second repeated-eqns) (copy-list eqns))))
2772 ; (iassert (not (member (second repeated-eqns) (ldata-eqns ld1))))
2773 ; (mshow divisor (second repeated-eqns) rem c-reqd)
2774 ; (cond ((may-invertp c-reqd open-g)
2775 ; (format t " which was invertible")
2776 ; (ldata-simplifications
2777 ; ld1 :open-g open-g))
2779 ; (setq ld2 (copy-list-structure ldata))
2780 ; (setf (ldata-eqns ld2) (cons c-reqd (ldata-eqns ldata)))
2781 ; (setf (ldata-inequality ld1) (nplcm (ldata-inequality ldata)
2783 ; (des ld1)(des ld2)
2785 ; (ldata-simplifications
2786 ; ld1 :open-g open-g)
2787 ; (ldata-simplifications
2788 ; ld2 :open-g open-g))))))
2789 ; (t (list ldata))))
2797 (defun divide-dichotomy (ldata &key
(open-g 1) &aux answer used
2798 (eqns (ldata-eqns ldata
)) f new-eqns
2799 occurs vars highest-vars orig-rep repeat eqns-rep gg ld1 ld2
)
2801 "endeavors to turn ldata into an triangular list of eqns
2802 so that each equation has possibly one more variable occurring than the
2803 previous. It takes a good order for the variables and then takes the first variable
2804 to be highest in two succeeding eqns, and does a division to try to correct this. If
2805 the leading variable is not invertible it does a dichotomy "
2807 ;;ordering should take into account open-g
2809 (setq ldata
(copy-list-structure ldata
))
2810 (setq vars
(copy-tree (good-order-variables eqns
)))
2811 (setq occurs
(second vars
))
2812 (setq vars
(first vars
))
2814 (loop for v in occurs
2815 collecting
(loop for u in vars
2816 when
(member u v
:test
#'eq
)
2818 (show vars highest-vars
)
2820 (multiple-value-setq (eqns-rep repeat
)
2821 (find-repeats vars eqns
))
2826 (setq orig-rep
(copy-list eqns-rep
))
2827 (show (length eqns-rep
))
2828 (setq eqns-rep
(sort-key eqns-rep
'< 'pdegree repeat
))
2829 (setq used
(cons repeat
(pdegree (first eqns-rep
) repeat
)))
2830 ; (push repeat *used-divisors*)
2831 (show (length eqns-rep
))
2832 (cond ((eql (pdegree (first eqns-rep
) repeat
)
2833 (pdegree (second eqns-rep
) repeat
))
2834 ;;choose the least complex leading coefficient to divide by
2836 (sort-key (subseq eqns-rep
0 2) '<
2837 #'(lambda (u var
) (pcomplexity
2838 (leading-coefficient u var
)))
2840 (setq f
(second eqns-rep
))
2842 (multiple-value-bind (zl-REM c-reqd
)
2843 (gen-prem f
(first eqns-rep
) repeat
)
2844 (push f
*used-divisors
*)
2845 (mshow f
(first eqns-rep
))
2846 (setq new-eqns
(delete f
(copy-list eqns
)))
2847 (cond (($zerop zl-REM
) nil
)
2848 (t (setq new-eqns
;;these have f replaced by rem
2849 (append new-eqns
(list zl-REM
)))))
2850 (setq gg
(nplcm open-g
(ldata-inequality ldata
)))
2851 (cond ((may-invertp c-reqd gg
)
2852 (setq ld2
(make-ldata :eqns new-eqns
2853 :inequality gg
:variables vars
)))
2854 ;;make two ldata one where c-reqd is invertible and f replaced by rem
2855 ;; and other where its zero and f is still there.
2856 (t (setq ld2
(make-ldata :eqns new-eqns
2857 :inequality
(nplcm gg c-reqd
)
2859 (setq ld1
(make-ldata :eqns
2867 (format t
"~%Breaking into dichotomy on:")
2869 (format t
"%original ldata followed by consequents:" )
2870 (des ldata
)(des ld1
) (des ld2
)
2871 ; (loop for v in (list ld1 ld2)
2872 ; when (not (unit-idealp (ldata-eqns v) (ldata-inequality v)))
2873 ; appending (ldata-simplifications v )))
2875 (append (ldata-simplifications ld1
2876 :open-g open-g
:recursive-p t
)
2877 (ldata-simplifications
2878 ld2
:open-g open-g
:recursive-p t
)))
2880 (format t
"~%The c-reqd was invertible: ")
2882 (iassert (not (member f
(ldata-eqns ld2
) :test
#'equal
)))
2884 (ldata-simplifications
2885 ld2
:open-g open-g
:recursive-p t
))))))
2886 (t (setq answer
(list ldata
)))))
2887 (setq *used-divisors
* nil
))
2893 ;;;;;the following was the divide-dichotomy in force at XMAS 84
2894 ;(defun divide-dichotomy (ldata &key (open-g 1) &aux answer used
2895 ; (eqns (ldata-eqns ldata)) f new-eqns
2896 ; occurs vars highest-vars orig-rep repeat eqns-rep gg ld1 ld2)
2898 ; "endeavors to turn ldata into an triangular list of eqns
2899 ; so that each equation has possibly one more variable occurring than the
2900 ; previous. It takes a good order for the variables and then takes the first variable
2901 ; to be highest in two succeeding eqns, and does a division to try to correct this. If
2902 ; the leading variable is not invertible it does a dichotomy "
2904 ; ;;ordering should take into account open-g
2906 ; (setq ldata (copy-list-structure ldata))
2907 ; (setq vars (copy-tree (good-order-variables eqns)))
2908 ; (setq occurs (second vars))
2909 ; (setq vars (first vars))
2910 ; (setq highest-vars
2911 ; (loop for v in occurs
2912 ; collecting (loop for u in vars
2913 ; when (member u v :test #'eq)
2915 ; (show vars highest-vars)
2917 ; (loop named rep for v in vars
2919 ; (loop for w on highest-vars
2920 ; when (and (eq (car w) v)
2921 ; (member v (cdr w) :test #'eq))
2922 ; do (return-from rep v))))
2928 ; (setq eqns-rep (loop for v in eqns
2929 ; for u in highest-vars
2930 ; when (eq u repeat)
2932 ; (setq orig-rep (copy-list eqns-rep))
2933 ; (show (length eqns-rep))
2934 ; (setq eqns-rep (sort-key eqns-rep '< 'pdegree repeat))
2935 ; (setq used (cons repeat (pdegree (first eqns-rep) repeat)))
2936 ;; (push repeat *used-divisors*)
2937 ; (show (length eqns-rep))
2938 ; (cond ((eq ( pdegree (first eqns-rep) repeat)
2939 ; (pdegree (second eqns-rep) repeat))
2940 ; ;;choose the least complex leading coefficient to divide by
2942 ; (sort-key (firstn 2 eqns-rep) '<
2943 ; #'(lambda (u var) (pcomplexity
2944 ; (leading-coefficient u var)))
2946 ; (setq f (second eqns-rep))
2948 ; (multiple-value-bind (rem c-reqd)
2949 ; (gen-prem f (first eqns-rep) repeat)
2950 ; (push f *used-divisors*)
2951 ; (mshow f (first eqns-rep))
2952 ; (setq new-eqns (delete f
2953 ; (copy-list eqns)))
2954 ; (cond (($zerop rem) nil)
2955 ; (t (setq new-eqns ;;these have f replaced by rem
2956 ; (append new-eqns (list rem)))))
2957 ; (setq gg (nplcm open-g (ldata-inequality ldata)))
2958 ; (cond ((may-invertp c-reqd gg)
2959 ; (setq ld2 (make-ldata eqns new-eqns
2960 ; inequality gg variables vars )))
2961 ; ;;make two ldata one where c-reqd is invertible and f replaced by rem
2962 ; ;; and other where its zero and f is still there.
2963 ; (t (setq ld2 (make-ldata eqns new-eqns
2964 ; inequality (nplcm gg c-reqd)
2966 ; (setq ld1 (make-ldata eqns
2967 ; (cons c-reqd eqns)
2969 ; variables vars))))
2974 ; (format t "~%Breaking into dichotomy on:")
2976 ; (format t "%original ldata followed by consequents:" )
2977 ; (des ldata)(des ld1) (des ld2 )
2978 ;; (loop for v in (list ld1 ld2)
2979 ;; when (not (unit-idealp (ldata-eqns v) (ldata-inequality v)))
2980 ;; appending (ldata-simplifications v )))
2982 ; (append (ldata-simplifications ld1
2983 ; :open-g open-g :recursive-p t)
2984 ; (ldata-simplifications
2985 ; ld2 :open-g open-g :recursive-p t)))
2987 ; (format t "~%The c-reqd was invertible: ")
2989 ; (iassert (not (member f (ldata-eqns ld2))))
2991 ; (ldata-simplifications
2992 ; ld2 :open-g open-g :recursive-p t))))))
2993 ; (t (setq answer (list ldata)))))
2994 ; (setq *used-divisors* nil))
2997 ;;attempt to repeat use of the variable order
2998 ;(defun divide-dichotomy (ldata &key (open-g 1) &aux answer used
2999 ; (eqns (ldata-eqns ldata)) f new-eqns
3000 ; occurs vars highest-vars orig-rep repeat eqns-rep gg ld1 ld2)
3002 ; "endeavors to turn ldata into an triangular list of eqns
3003 ; so that each equation has possibly one more variable occurring than the
3004 ; previous. It takes a good order for the variables and then takes the first variable
3005 ; to be highest in two succeeding eqns, and does a division to try to correct this. If
3006 ; the leading variable is not invertible it does a dichotomy "
3008 ; ;;ordering should take into account open-g
3010 ; (setq ldata (copy-list-structure ldata))
3011 ; (setq vars (good-order-variables eqns))
3012 ; (setq occurs (second vars))
3013 ; (setq vars (first vars))
3014 ; (loop for v in *used-divisors*
3015 ; do (setq vars (delete v vars)))
3016 ; (setq highest-vars
3017 ; (loop for v in occurs
3018 ; collecting (loop for u in vars
3019 ; when (member u v :test #'eq)
3021 ; (show vars highest-vars)
3023 ; (loop named rep for v in vars
3025 ; (loop for w on highest-vars
3026 ; when (and (eq (car w) v)
3027 ; (member v (cdr w) :test #'eq))
3028 ; do (return-from rep v))))
3034 ; (setq eqns-rep (loop for v in eqns
3035 ; for u in highest-vars
3036 ; when (eq u repeat)
3038 ; (setq orig-rep (copy-list eqns-rep))
3039 ; (show (length eqns-rep))
3040 ; (setq eqns-rep (sort-key eqns-rep '< 'pdegree repeat))
3041 ; (setq used (cons repeat (pdegree (first eqns-rep) repeat)))
3042 ;; (push repeat *used-divisors*)
3043 ; (show (length eqns-rep))
3044 ; (cond ((eq ( pdegree (first eqns-rep) repeat)
3045 ; (pdegree (second eqns-rep) repeat))
3046 ; ;;choose the least complex leading coefficient to divide by
3048 ; (sort-key (firstn 2 eqns-rep) '<
3049 ; #'(lambda (u var) (pcomplexity
3050 ; (leading-coefficient u var)))
3052 ; (setq f (second eqns-rep))
3054 ; (multiple-value-bind (rem c-reqd)
3055 ; (gen-prem f (first eqns-rep) repeat)
3056 ; (push f *used-divisors*)
3057 ; (mshow f (first eqns-rep))
3058 ; (setq new-eqns (delete f
3059 ; (copy-list eqns)))
3060 ; (cond (($zerop rem) nil)
3061 ; (t (setq new-eqns ;;these have f replaced by rem
3062 ; (append new-eqns (list rem)))))
3063 ; (setq gg (nplcm open-g (ldata-inequality ldata)))
3064 ; (cond ((may-invertp c-reqd gg)
3065 ; (setq ld2 (make-ldata eqns new-eqns
3066 ; inequality gg variables vars )))
3067 ; ;;make two ldata one where c-reqd is invertible and f replaced by rem
3068 ; ;; and other where its zero and f is still there.
3069 ; (t (setq ld2 (make-ldata eqns new-eqns
3070 ; inequality (nplcm gg c-reqd)
3072 ; (setq ld1 (make-ldata eqns
3073 ; (cons c-reqd eqns)
3075 ; variables vars))))
3078 ; (format t "~%Breaking into dichotomy on:")
3080 ; (format t "%original ldata followed by consequents:" )
3081 ; (des ldata)(des ld1) (des ld2 )
3082 ;; (loop for v in (list ld1 ld2)
3083 ;; when (not (unit-idealp (ldata-eqns v) (ldata-inequality v)))
3084 ;; appending (ldata-simplifications v )))
3086 ; (append (ldata-simplifications ld1
3087 ; :open-g open-g :recursive-p t)
3088 ; (ldata-simplifications
3089 ; ld2 :open-g open-g :recursive-p t)))
3091 ; (format t "~%The c-reqd was invertible: ")
3093 ; (iassert (not (member f (ldata-eqns ld2))))
3095 ; (ldata-simplifications
3096 ; ld2 :open-g open-g :recursive-p t))))))
3097 ; (t (setq answer (list ldata)))))
3098 ; (setq *used-divisors* nil))
3103 ;;evaluates the key function only once for each term
3104 ;;orders by (pred (key u) (key v)) true ==> u earlier than v in sorted list
3106 (defun triangularp (ldata &aux vars
(eqns (ldata-eqns ldata
)) occurs highest-vars repeat
)
3107 (setq vars
(good-order-variables eqns
))
3108 (setq occurs
(second vars
))
3109 (setq vars
(first vars
))
3110 (loop for v in
*used-divisors
*
3111 do
(setq vars
(delete v vars
:test
#'equal
)))
3113 (loop for v in occurs
3114 collecting
(loop for u in vars
3115 when
(member u v
:test
#'eq
)
3117 (show vars highest-vars
)
3119 (loop named rep for v in vars
3121 (loop for w on highest-vars
3122 when
(and (eq (car w
) v
)
3123 (member v
(cdr w
) :test
#'eq
))
3124 do
(return-from rep v
)))))
3126 (defun sort-expensive-key (a-list pred key
&aux clist
)
3127 (declare (special pred
))
3128 (setq clist
(copy-list a-list
))
3129 (loop for v on clist do
(setf (car v
)
3130 (cons (funcall key
(car v
)) (car v
))))
3131 (setq clist
(sort clist
#'(lambda (u v
) (funcall pred
(car u
) (car v
)))))
3132 (loop for v on clist do
(setf (car v
) (cdar v
)))
3135 ;;one should do divide dichot on the simplest functions and
3136 ;;the lowest degree variables..
3138 ;(defun second-divide-dichotomy (ldata &key (open-g 1) &aux tem
3139 ; variables-to-exclude non-lin-eqns)
3142 ; (loop for eqn in (ldata-eqns ldata)
3143 ; when (setq tem (any-linearp eqn open-g :variables-to-exclude
3144 ; variables-to-exclude))
3145 ; do (push tem variables-to-exclude)
3147 ; collecting eqn into lin-eqn
3149 ; collecting eqn into non-lin
3150 ; finally (setq non-lin-eqns non-lin))
3151 ; (setq non-lin-eqns (sort-expensive-key
3152 ; non-lin-eqns #'< #'gen-pcomplexity))
3153 ; (loop for eqn in non-lin-eqns
3154 ; collecting (degree-one-variables eqn) into deg-1
3155 ; collecting (list-variables eqn) into all-vars
3157 ; (setq deg1-divisions
3158 ; (loop for d1 in deg-1
3159 ; for f in non-lin-eqns
3162 ; (loop for al in all-vars
3164 ; for g in non-lin-eqns
3165 ; when (and (not (eql i j))
3166 ; (setq tem(intersect d1 al)))
3167 ; collecting (list tem g f ) into possible-1)))
3168 ; (setq higher-divisions
3169 ; (loop for d1 in all-vars
3170 ; for f in non-lin-eqns
3173 ; (loop for al in all-vars
3175 ; for g in non-lin-eqns
3176 ; when (and (not (eql i j))
3177 ; (setq tem(intersect d1 al)))
3178 ; collecting (list tem g f ) into possible-1)))
3181 ; (loop for try in deg1-divisions
3183 ; (loop for va in (third try)
3184 ; when (not (member (cons va (cdr try))
3186 ; collecting (append
3187 ; (multiple-value-list (gen-prem (first try)
3190 ; (loop for f in non-lin-eqns
3191 ; when (may-invertp (second v) open-g))))
3194 ; (setq *used-divisors* nil)))
3196 (defun linear-dichotomy (ldata &key
(open-g 1) in-linear-dich
&aux answer varl fns ans1 ans2
)
3199 (in-linear-dich (list ldata
))
3200 ((multiple-value-setq (varl fns
) (linear-solvedp (ldata-eqns ldata
) :order-functions t
))
3201 (cond ((linear-ldatap ldata
:open-g open-g
) (list ldata
))
3202 (t (loop for va in varl
3205 do
(setq answ
(ptimes answ
(pcoeff f
(list va
1 1))))
3208 (cond ((may-invertp answ open-g
)(list ldata
))
3213 (ldata-simplifications
3214 (make-ldata :eqns
(ldata-eqns ldata
)
3215 :inequality
(sftimes answ
3218 :open-g open-g
:recursive-p t
))
3219 (setq ans2
(ldata-simplifications
3220 (make-ldata :eqns
(cons answ
(ldata-eqns ldata
))
3221 :inequality
(ldata-inequality
3223 :open-g open-g
:recursive-p t
))))
3228 (contract-ideal-localization (ldata-eqns v
)
3229 (ldata-inequality v
)))))
3230 (setq answer
(append ans1 ans2
))
3231 (setq answer
(delete-redundant-ldata answer
:gg open-g
))
3235 (t (format t
"~%**Unchanged")
3238 (defun simplify-affine-ldata (ldata &key
(open-g 1) &aux vari sheaf op
)
3239 (setq vari
(ml-sort (list-variables (ldata-eqns ldata
)) ))
3240 (setq op
(let ((*xxx
* vari
))(make-normal-zopen nil
(length vari
) open-g
)))
3241 (setq sheaf
(construct-pre-ldata-sheaves :opens
(list op
) :data
(list (list ldata
))))
3242 (simplify-svar-ldata sheaf
))
3244 (defvar *answer
* nil
)
3245 (defun simplify-affine-ldata-write (ldata &key
(open-g 1) (pathname "haskell:>wfs>answer.lisp") &aux answ
)
3246 (setq *answer
* (setq answ
(simplify-affine-ldata ldata
:open-g open-g
)))
3247 (with-open-file (st pathname
:direction
:output
)
3248 (let ((*standard-output
* st
) *print-radix
*)
3249 (for-editor (des answ
))
3250 (format st
"~%(setq (answ (rerat '~A)))" answ
))))