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

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

First import of a version circa 1997.

File size: 3.0 KB
Line 
1head 1.4;
2access;
3symbols;
4locks; strict;
5comment @;;; @;
6
7
81.4
9date 2009.01.22.04.00.56; author marek; state Exp;
10branches;
11next 1.3;
12
131.3
14date 2009.01.19.09.24.56; author marek; state Exp;
15branches;
16next 1.2;
17
181.2
19date 2009.01.19.07.40.35; author marek; state Exp;
20branches;
21next 1.1;
22
231.1
24date 2009.01.19.06.48.09; author marek; state Exp;
25branches;
26next ;
27
28
29desc
30@@
31
32
331.4
34log
35@*** empty log message ***
36@
37text
38@#|
39 $Id$
40 *--------------------------------------------------------------------------*
41 | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@@math.arizona.edu) |
42 | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
43 | |
44 | Everyone is permitted to copy, distribute and modify the code in this |
45 | directory, as long as this copyright note is preserved verbatim. |
46 *--------------------------------------------------------------------------*
47|#
48(defpackage "DIVISION"
49 (:use "MONOM" "ORDER" "TERM" "POLY" "COEFFICIENT-RING" "COMMON-LISP")
50 (:export divide poly-exact-divide))
51
52(in-package "DIVISION")
53
54#+debug(proclaim '(optimize (speed 0) (debug 3)))
55#-debug(proclaim '(optimize (speed 3) (debug 0)))
56
57(defun divide (f fl &optional
58 (pred #'lex>)
59 (ring *coefficient-ring*)
60 &aux (s (length fl)))
61 "Divide polynomial F by a list of polynomials FL; use predicate PRED
62to sort monomials; assumes that the polynomials have initially been
63sorted according to PRED. It returnes multiple values. The first value
64is a list of quotients A. The second value is the remainder R. These
65object satisfy the quation F = SUM A[J]*FL[I] + R."
66 (do ((a (make-list s))
67 r
68 (p f)
69 (division-occurred nil nil))
70 ((endp p) (values (mapcar #'reverse a) (reverse r)))
71 (declare (list a r p))
72 (do ((fl fl (rest fl))
73 (a a (rest a)))
74 ((or (endp fl) division-occurred))
75 (when (term-divides-p (car (first fl)) (first p))
76 (let ((quot (term/ (first p) (car (first fl)) ring)))
77 (push quot (car a))
78 (setf p (poly-op (rest p) quot (rest (first fl)) pred ring)
79 division-occurred t))))
80 (when (not division-occurred)
81 (setf r (cons (first p) r)
82 p (rest p)))))
83
84(defun poly-exact-divide (f g &optional (order #'lex>) (ring *coefficient-ring*))
85 "Divide a polynomial F by another polynomial G. Assume that exact division
86with no remainder is possible. Returns the quotient."
87 (multiple-value-bind (q r)
88 (divide f (list g) order ring)
89 (unless (endp r) (error "Exact division failed."))
90 (car q)))
91@
92
93
941.3
95log
96@*** empty log message ***
97@
98text
99@d17 2
100a18 2
101;;(proclaim '(optimize (speed 0) (debug 3)))
102(proclaim '(optimize (speed 3) (debug 0)))
103@
104
105
1061.2
107log
108@*** empty log message ***
109@
110text
111@d17 2
112a18 1
113(proclaim '(optimize (speed 0) (debug 3)))
114@
115
116
1171.1
118log
119@Initial revision
120@
121text
122@d2 1
123a2 1
124 $Id: division.lisp,v 1.16 1997/12/04 03:44:32 marek Exp $
125d17 1
126a17 2
127(eval-when (compile)
128 (proclaim '(optimize (safety 0) (speed 3))))
129@
Note: See TracBrowser for help on using the repository browser.