close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/term.lisp@ 397

Last change on this file since 397 was 397, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 3.3 KB
Line 
1;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*-
2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3;;;
4;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
5;;;
6;;; This program is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 2 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19;;;
20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21
22(defpackage "TERM"
23 (:use :cl :monom)
24 (:export))
25
26
27(defun make-term-variable (ring nvars pos
28 &optional
29 (power 1)
30 (coeff (funcall (ring-unit ring)))
31 &aux
32 (monom (make-monom nvars :initial-element 0)))
33 (declare (fixnum nvars pos power))
34 (incf (monom-elt monom pos) power)
35 (make-term monom coeff))
36
37(defstruct (term
38 (:constructor make-term (monom coeff))
39 ;;(:constructor make-term-variable)
40 ;;(:type list)
41 )
42 (monom (make-monom 0) :type monom)
43 (coeff nil))
44
45(defun term-sugar (term)
46 (monom-sugar (term-monom term)))
47
48(defun termlist-sugar (p &aux (sugar -1))
49 (declare (fixnum sugar))
50 (dolist (term p sugar)
51 (setf sugar (max sugar (term-sugar term)))))
52
53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54;;
55;; Additional structure operations on a list of terms
56;;
57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
59(defun termlist-contract (p &optional (k 1))
60 "Eliminate first K variables from a polynomial P."
61 (mapcar #'(lambda (term) (make-term (monom-contract k (term-monom term))
62 (term-coeff term)))
63 p))
64
65(defun termlist-extend (p &optional (m (make-monom 1 :initial-element 0)))
66 "Extend every monomial in a polynomial P by inserting at the
67beginning of every monomial the list of powers M."
68 (mapcar #'(lambda (term) (make-term (monom-append m (term-monom term))
69 (term-coeff term)))
70 p))
71
72(defun termlist-add-variables (p n)
73 "Add N variables to a polynomial P by inserting zero powers
74at the beginning of each monomial."
75 (declare (fixnum n))
76 (mapcar #'(lambda (term)
77 (make-term (monom-append (make-monom n :initial-element 0)
78 (term-monom term))
79 (term-coeff term)))
80 p))
81
82(defun term-mul (ring term1 term2)
83 "Returns the product of the terms TERM1 and TERM2,
84or NIL when the product is 0. This definition takes care of divisors of 0
85in the coefficient ring."
86 (let ((c (funcall (ring-mul ring) (term-coeff term1) (term-coeff term2))))
87 (unless (funcall (ring-zerop ring) c)
88 (make-term (monom-mul (term-monom term1) (term-monom term2)) c))))
Note: See TracBrowser for help on using the repository browser.