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@ 399

Last change on this file since 399 was 399, checked in by Marek Rychlik, 10 years ago

* empty log message *

File size: 3.6 KB
RevLine 
[78]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
[397]22(defpackage "TERM"
[398]23 (:use :cl :monomial)
[397]24 (:export))
[78]25
[142]26
[51]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)))
[399]33 "Construct a term in the polynomial ring RING[X0,X1,X2,...X(NVARS-1)]
34over the ring RING which represents a single variable. It assumes
35number of variables NVARS and the variable is at position
36POS. Optionally, the variable may appear raised to power POWER.
37Optionally, the term may appear with an arbitrary coefficient, which
38defaults to the unit of the RING."
[51]39 (declare (fixnum nvars pos power))
40 (incf (monom-elt monom pos) power)
41 (make-term monom coeff))
42
43(defstruct (term
44 (:constructor make-term (monom coeff))
45 ;;(:constructor make-term-variable)
46 ;;(:type list)
47 )
48 (monom (make-monom 0) :type monom)
49 (coeff nil))
50
51(defun term-sugar (term)
52 (monom-sugar (term-monom term)))
53
54(defun termlist-sugar (p &aux (sugar -1))
55 (declare (fixnum sugar))
56 (dolist (term p sugar)
57 (setf sugar (max sugar (term-sugar term)))))
58
59;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60;;
61;; Additional structure operations on a list of terms
62;;
63;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64
65(defun termlist-contract (p &optional (k 1))
66 "Eliminate first K variables from a polynomial P."
67 (mapcar #'(lambda (term) (make-term (monom-contract k (term-monom term))
68 (term-coeff term)))
69 p))
70
71(defun termlist-extend (p &optional (m (make-monom 1 :initial-element 0)))
72 "Extend every monomial in a polynomial P by inserting at the
73beginning of every monomial the list of powers M."
74 (mapcar #'(lambda (term) (make-term (monom-append m (term-monom term))
75 (term-coeff term)))
76 p))
77
78(defun termlist-add-variables (p n)
79 "Add N variables to a polynomial P by inserting zero powers
80at the beginning of each monomial."
81 (declare (fixnum n))
82 (mapcar #'(lambda (term)
83 (make-term (monom-append (make-monom n :initial-element 0)
84 (term-monom term))
85 (term-coeff term)))
86 p))
[377]87
88(defun term-mul (ring term1 term2)
89 "Returns the product of the terms TERM1 and TERM2,
90or NIL when the product is 0. This definition takes care of divisors of 0
91in the coefficient ring."
92 (let ((c (funcall (ring-mul ring) (term-coeff term1) (term-coeff term2))))
93 (unless (funcall (ring-zerop ring) c)
[378]94 (make-term (monom-mul (term-monom term1) (term-monom term2)) c))))
Note: See TracBrowser for help on using the repository browser.