#| $Id: term.lisp,v 1.4 2009/01/22 04:08:39 marek Exp $ *--------------------------------------------------------------------------* | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@math.arizona.edu) | | Department of Mathematics, University of Arizona, Tucson, AZ 85721 | | | | Everyone is permitted to copy, distribute and modify the code in this | | directory, as long as this copyright note is preserved verbatim. | *--------------------------------------------------------------------------* |# (defpackage "TERM" (:use "MONOM" "COEFFICIENT-RING" "COMMON-LISP") (:export term-divides-p term* term/ term-coefficient term-monom monom-times-term)) (in-package "TERM") #+debug(proclaim '(optimize (speed 0) (debug 3))) #-debug(proclaim '(optimize (speed 3) (debug 0))) ;;---------------------------------------------------------------- ;; Basic operations on terms ;;---------------------------------------------------------------- ;; THE REPRESENTATION: Terms are cons cells consisting ;; of a monom and coefficient ;; ;; term: (monom . coefficient) ;; ;;---------------------------------------------------------------- ;; EXAMPLES: Suppose that variables are x and y. Then ;; Term 3*x*y^2 ---> ((1 2) . 3) ;;---------------------------------------------------------------- ;; Multiplication of terms (defun term* (term1 term2 &optional (ring *coefficient-ring*)) (cons (monom* (car term1) (car term2)) (funcall (ring-* ring) (cdr term1) (cdr term2)))) ;;;; Division of terms (defun term/ (term1 term2 &optional (ring *coefficient-ring*)) (cons (monom/ (car term1) (car term2)) (funcall (ring-/ ring) (cdr term1) (cdr term2)))) ;; Multiply monomial by term (defun monom-times-term (m term) (cons (monom* m (car term)) (cdr term))) ;; Whether a term divides another term (defun term-divides-p (term1 term2) (monom-divides-p (car term1) (car term2))) ;; Accessor functions (defmacro term-monom (term) `(car ,term)) (defmacro term-coefficient (term) `(cdr ,term)) ;; Setf methods (defsetf term-monom (term) (monom) `(setf (car ,term) ,monom)) (defsetf term-coefficient (term) (coefficient) `(setf (cdr ,term) ,coefficient))