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/5am-division.lisp@ 4153

Last change on this file since 4153 was 4088, checked in by Marek Rychlik, 8 years ago
File size: 3.5 KB
RevLine 
[4088]1;;; -*- Mode: Lisp -*-
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;;
24;; Run tests using 5am unit testing framework
25;;
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
28;; We assume that QuickLisp package manager is installed.
29;; See :
30;; https://www.quicklisp.org/beta/
31;;
32
33;; The following is unnecessary after running:
34;; * (ql:add-to-init-file)
35;; at lisp prompt:
36;;(load "~/quicklisp/setup")
37
38(ql:quickload :fiveam)
39
40;; Unless NGROBNER system loaded by ASDF,
41;; load the dependencies directly
42#-ngrobner
43(progn
44 (require :utils "utils")
45 (require :copy "copy")
46 (require :monom "monom")
47 (require :polynomial "polynomial")
48 (require :infix "infix")
49 (require :symbolic-polynomial "symbolic-polynomial")
50 (require :division "division"))
51
52(defpackage #:5am-division
53 (:use :cl :it.bese.fiveam :monom :polynomial :infix :symbolic-polynomial :division))
54
55(in-package :5am-division)
56
57(def-suite division-suite
58 :description "Division algorithm suite")
59
60(in-suite division-suite)
61
62;; Manual calculation supporting the test below.
63;; We divide X^2 by [X+Y,X-2*Y] with LEX> as order.
64;; LM(X^2)=X^2 is divisible by LM(X+Y)=X so the first partial quotient is X.
65;; Next, X^2 - X*(X+Y) = -X*Y.
66;; LM(-X*Y)=X*Y is divibile by LM(X+Y)=X so the second partial quotient is -Y.
67;; Next, -X*Y-(-Y)*(X+Y) = Y^2.
68;; LM(Y^2)=Y^2 is not divisible by LM(X+Y)=X or LM(X-2*Y)=X. Hence, division
69;; ends. The list of quotients is [X-Y,0]. The remainder is Y^2
70
71(def-fixture division-context ()
72 (let* ((f (string->poly "x^2" '(x y)))
73 (y-sq (string->poly "y^2" '(x y)))
74 (fl (cdr (string->poly "[x+y,x-2*y]" '(x y))))
75 (quotients (cdr (string->poly "[x-y,0]" '(x y)))))
76 (&body)))
77
78(test normal-form
79 "Normal form"
80 (with-fixture division-context ()
81 (is (universal-equalp (multiple-value-list (normal-form f fl)) (list y-sq 1 2)))
82 (is (universal-equalp (multiple-value-list (poly-pseudo-divide f fl))
83 (list quotients y-sq 1 2)))
84 (is-false (buchberger-criterion fl))))
85
86(def-fixture exact-division-context ()
87 (let* ((f (string->poly "x^2-4*y^2" '(x y)))
88 (g (string->poly "x+2*y" '(x y)))
89 (h (string->poly "x-2*y" '(x y))))
90 (&body)))
91
92(test exact-division
93 "Exact division in polynomial ring"
94 (with-fixture exact-division-context ()
95 (is (universal-equalp (poly-exact-divide f g) h))))
96
97
98(run! 'division-suite)
99(format t "All tests done!~%")
100
101
Note: See TracBrowser for help on using the repository browser.