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

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