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

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

* empty log message *

File size: 2.9 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
23(defun make-term-variable (ring nvars pos
24 &optional
25 (power 1)
26 (coeff (funcall (ring-unit ring)))
27 &aux
28 (monom (make-monom nvars :initial-element 0)))
29 (declare (fixnum nvars pos power))
30 (incf (monom-elt monom pos) power)
31 (make-term monom coeff))
32
33(defstruct (term
34 (:constructor make-term (monom coeff))
35 ;;(:constructor make-term-variable)
36 ;;(:type list)
37 )
38 (monom (make-monom 0) :type monom)
39 (coeff nil))
40
41(defun term-sugar (term)
42 (monom-sugar (term-monom term)))
43
44(defun termlist-sugar (p &aux (sugar -1))
45 (declare (fixnum sugar))
46 (dolist (term p sugar)
47 (setf sugar (max sugar (term-sugar term)))))
48
49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50;;
51;; Additional structure operations on a list of terms
52;;
53;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54
55(defun termlist-contract (p &optional (k 1))
56 "Eliminate first K variables from a polynomial P."
57 (mapcar #'(lambda (term) (make-term (monom-contract k (term-monom term))
58 (term-coeff term)))
59 p))
60
61(defun termlist-extend (p &optional (m (make-monom 1 :initial-element 0)))
62 "Extend every monomial in a polynomial P by inserting at the
63beginning of every monomial the list of powers M."
64 (mapcar #'(lambda (term) (make-term (monom-append m (term-monom term))
65 (term-coeff term)))
66 p))
67
68(defun termlist-add-variables (p n)
69 "Add N variables to a polynomial P by inserting zero powers
70at the beginning of each monomial."
71 (declare (fixnum n))
72 (mapcar #'(lambda (term)
73 (make-term (monom-append (make-monom n :initial-element 0)
74 (term-monom term))
75 (term-coeff term)))
76 p))
Note: See TracBrowser for help on using the repository browser.