source: CGBLisp/src/term.lisp@ 1

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

First import of a version circa 1997.

File size: 2.2 KB
Line 
1#|
2 $Id: term.lisp,v 1.4 2009/01/22 04:08:39 marek Exp $
3 *--------------------------------------------------------------------------*
4 | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@math.arizona.edu) |
5 | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
6 | |
7 | Everyone is permitted to copy, distribute and modify the code in this |
8 | directory, as long as this copyright note is preserved verbatim. |
9 *--------------------------------------------------------------------------*
10|#
11
12(defpackage "TERM"
13 (:use "MONOM" "COEFFICIENT-RING" "COMMON-LISP")
14 (:export term-divides-p term* term/ term-coefficient term-monom monom-times-term))
15
16(in-package "TERM")
17
18#+debug(proclaim '(optimize (speed 0) (debug 3)))
19#-debug(proclaim '(optimize (speed 3) (debug 0)))
20
21;;----------------------------------------------------------------
22;; Basic operations on terms
23;;----------------------------------------------------------------
24;; THE REPRESENTATION: Terms are cons cells consisting
25;; of a monom and coefficient
26;;
27;; term: (monom . coefficient)
28;;
29;;----------------------------------------------------------------
30;; EXAMPLES: Suppose that variables are x and y. Then
31;; Term 3*x*y^2 ---> ((1 2) . 3)
32;;----------------------------------------------------------------
33
34;; Multiplication of terms
35(defun term* (term1 term2 &optional (ring *coefficient-ring*))
36 (cons
37 (monom* (car term1) (car term2))
38 (funcall (ring-* ring) (cdr term1) (cdr term2))))
39
40;;;; Division of terms
41(defun term/ (term1 term2 &optional (ring *coefficient-ring*))
42 (cons
43 (monom/ (car term1) (car term2))
44 (funcall (ring-/ ring) (cdr term1) (cdr term2))))
45
46;; Multiply monomial by term
47(defun monom-times-term (m term)
48 (cons (monom* m (car term)) (cdr term)))
49
50;; Whether a term divides another term
51(defun term-divides-p (term1 term2)
52 (monom-divides-p (car term1) (car term2)))
53
54;; Accessor functions
55(defmacro term-monom (term) `(car ,term))
56(defmacro term-coefficient (term) `(cdr ,term))
57
58;; Setf methods
59(defsetf term-monom (term) (monom)
60 `(setf (car ,term) ,monom))
61
62(defsetf term-coefficient (term) (coefficient)
63 `(setf (cdr ,term) ,coefficient))
64
Note: See TracBrowser for help on using the repository browser.