source: CGBLisp/src/monom.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.5 KB
Line 
1#|
2 $Id: monom.lisp,v 1.3 2009/01/22 04:04:31 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(defpackage "MONOM"
12 (:use "COMMON-LISP")
13 (:export monom-equal monom-divides-p monom-divisible-by-p monom-rel-prime
14 monom* nmonom* monom/
15 monom-lcm monom-gcd))
16
17(in-package "MONOM")
18
19#+debug(proclaim '(optimize (speed 0) (debug 3)))
20#-debug(proclaim '(optimize (speed 3) (debug 0)))
21
22;;----------------------------------------------------------------
23;; This package implements BASIC OPERATIONS ON MONOMIALS
24;;----------------------------------------------------------------
25;; DATA STRUCTURES: Monomials are represented as lists:
26;;
27;; monom: (n1 n2 ... nk) where ni are non-negative integers
28;;
29;;----------------------------------------------------------------
30;; EXAMPLES: Suppose that variables are x and y. Then
31;;
32;; Monom x*y^2 ---> (1 2)
33;;
34;;----------------------------------------------------------------
35
36(defun monom/ (m1 m2)
37 "Divide monomial M1 by monomial M2."
38 (mapcar #'- m1 m2))
39
40(defun monom* (m1 m2)
41 "Multiply monomial M1 by monomial M2."
42 (mapcar #'+ m1 m2))
43
44(defun nmonom* (m1 m2)
45 "Multiply monomials M1 and M2 - destructive version.
46 M1 is destructively modified, M2 is not modified."
47 (mapl #'(lambda (x y) (incf (car x) (car y))) m1 m2))
48
49(defun monom-divides-p (m1 m2)
50 "Returns T if monomial M1 divides monomial M2, NIL otherwise."
51 (every #'<= m1 m2))
52
53(defun monom-divisible-by-p (m1 m2)
54 "Returns T if monomial M1 is divisible by monomial M2, NIL otherwise."
55 (every #'>= m1 m2))
56
57(defun monom-rel-prime (m1 m2)
58 "Returns T if two monomials M1 and M2 are relatively prime (disjoint)."
59 (every #'(lambda (x y) (zerop (min x y))) m1 m2))
60
61(defun monom-equal (m1 m2)
62 "Returns T if two monomials M1 and M2 are equal."
63 (every #'= m1 m2))
64
65(defun monom-lcm (m1 m2)
66 "Returns least common multiple of monomials M1 and M2."
67 (mapcar #'max m1 m2))
68
69(defun monom-gcd (m1 m2)
70 "Returns greatest common divisor of monomials M1 and M2."
71 (mapcar #'min m1 m2))
Note: See TracBrowser for help on using the repository browser.