;;; -*- Mode: Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program; if not, write to the Free Software ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Run tests using 5am unit testing framework ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; We assume that QuickLisp package manager is installed. ;; See : ;; https://www.quicklisp.org/beta/ ;; ;; The following is unnecessary after running: ;; * (ql:add-to-init-file) ;; at lisp prompt: ;;(load "~/quicklisp/setup") (ql:quickload :fiveam) (defpackage #:5am-buchberger (:use :cl :it.bese.fiveam :monom :polynomial :infix :symbolic-polynomial :division :priority-queue :buchberger :grobner-debug)) (in-package :5am-buchberger) (def-suite buchberger-suite :description "Buchberger algorithm suite") (in-suite buchberger-suite) (def-fixture buchberger-context () (let ((fl (cdr (string->poly "[x+y,x-2*y]" '(x y)))) (gb (cdr (string->poly "[x+y,x-2*y,y]" '(x y))))) (&body))) (test buchberger "Buchberger algorithm" (with-fixture buchberger-context () (is-true (grobner-test gb fl)) (is (every #'universal-equalp (buchberger fl) gb)) ;;(is (every #'universal-equalp (parallel-buchberger fl) gb)) ) ) ;; poly_grobner([x-3*u-3*u*v^2+u^3,y-3*v-3*u^2*v+v^3,z-3*u^2+3*v^2],[u,v,x,y,z]); (def-fixture buchberger-advanced-context () (let ((fl (cdr (string->poly "[x-3*u-3*u*v^2+u^3,y-3*v-3*u^2*v+v^3,z-3*u^2+3*v^2]" '(u v x y z)))) (gb (cdr (string->poly "[x-3*u*v^2+u^3-3*u,y+v^3-3*u^2*v-3*v,z+3*v^2-3*u^2, (-u*z)-3*x+6*u*v^2+9*u,(-v*z)+y-2*v^3-3*v,z^2+6*v^2*z-9*z-9*v*y+9*u*x, 4*u*v*z-3*u*y+3*v*x,2*u*z^2+6*x*z-18*u*z-9*u*v*y+9*v^2*x, (-8*u*z^3)-24*x*z^2+72*u*z^2-36*v^2*x*z+27*u*y^2-27*v*x*y, z^3+18*v^2*z^2-18*z^2-54*v*y*z+54*v^2*z+81*z+27*y^2-27*x^2, (-4*z^4)+48*z^3-108*v*y*z^2+108*z^2+135*y^2*z+324*v*y*z+108*x^2*z -1296*v^2*z-1944*z-243*v^2*y^2-648*y^2+243*v^2*x^2+648*x^2, 8*v*z^3-9*y*z^2+72*v*z^2+54*v^2*y*z-27*y*z-27*v*y^2+27*v*x^2, (-8*v*z^4)+12*y*z^3-96*v*z^3-216*v*z^2-135*v*y^2*z+324*y*z-27*v*x^2*z +81*y^3+81*v*y^2-81*x^2*y-81*v*x^2, (-64*v*z^6)+120*y*z^5-1152*v*z^5+288*y*z^4-5184*v*z^4-648*v*y^2*z^3 -216*y*z^3+6912*v*z^3+81*y^3*z^2-9720*v*y^2*z^2 -1539*x^2*y*z^2+31104*y*z^2+62208*v*z^2+8505*y^3*z +46656*v*y^2*z-8505*x^2*y*z-93312*y*z+729*v*y^4-23328*y^3 -1458*v*x^2*y^2-23328*v*y^2+23328*x^2*y+729*v*x^4 +23328*v*x^2, 8*z^6-72*z^5+648*v*y*z^4-648*z^4-945*y^2*z^3+5184*v*y*z^3-189*x^2*z^3 +5832*z^3+972*y^2*z^2+17496*v*y*z^2-2430*x^2*z^2+8748*v*y^3*z -19683*y^2*z+2187*x^2*z-5103*y^4-4374*v*y^3+5832*x^2*y^2 +4374*v*x^2*y-729*x^4, 8*z^7-48*z^6+648*v*y*z^5-864*z^5-945*y^2*z^4+5832*v*y*z^4-189*x^2*z^4 +3888*z^4+81*y^2*z^3+17496*v*y*z^3-2997*x^2*z^3+17496*z^3 +8748*v*y^3*z^2-16767*y^2*z^2+17496*v*y*z^2-5103*x^2*z^2 -5103*y^4*z+5832*x^2*y^2*z-6561*y^2*z-729*x^4*z+6561*x^2*z -2187*y^4+4374*x^2*y^2-2187*x^4, 64*z^9-10368*z^7+1296*y^2*z^6-1296*x^2*z^6-34992*y^2*z^5-34992*x^2*z^5 +419904*z^5+174960*y^2*z^4-174960*x^2*z^4-10935*y^4*z^3 -56862*x^2*y^2*z^3+314928*y^2*z^3-10935*x^4*z^3+314928*x^2*z^3 +118098*y^4*z^2-118098*x^4*z^2+59049*y^4*z-118098*x^2*y^2*z +59049*x^4*z+19683*y^6-59049*x^2*y^4+59049*x^4*y^2-19683*x^6]" '(u v x y z))))) (&body))) (test buchberger-advanced "Buchberger algorithm - advanced case" (with-fixture buchberger-advanced-context () (is-true (grobner-test gb fl)) ;; NOTE: Cannot compare using SET-EXCLUSIVE-OR, as the Grobner basis ;; FL was computed using "sugar" strategy and is different from ;; the one obtained with BUCHBERGER, which uses the "normal" strategy. (is (grobner-equal (buchberger fl) gb)) ;;(is (every #'universal-equalp (parallel-buchberger fl) gb)) ) ) ;; Cyclic roots of degree 5 ;; poly_reduced_grobner([x+y+z+u+v,x*y+y*z+z*u+u*v+v*x,x*y*z+y*z*u+z*u*v+u*v*x+v*x*y,x*y*z*u+y*z*u*v+z*u*v*x+u*v*x*y+v*x*y*z,x*y*z*u*v-1],[u,v,x,y,z]); (def-fixture buchberger-cyclic-5-context () (let ((fl (cdr (string->poly "[x+y+z+u+v,x*y+y*z+z*u+u*v+v*x,x*y*z+y*z*u+z*u*v+u*v*x+v*x*y,x*y*z*u+y*z*u*v+z*u*v*x+u*v*x*y+v*x*y*z,x*y*z*u*v-1]" '(u v x y z)))) (gb (cdr (string->poly "[z+y+x+v+u, 8*z^12+2*y*z^11+979*z^7+231*y*z^6-55*y^2*z^5-987*z^2-233*y*z+55*y^2, z^15+122*z^10-122*z^5-1, 1467*z^12+566*y*z^11+178981*z^7+69003*y*z^6+550*y^3*z^4-275*y^4*z^3 -1650*y^5*z^2-179073*z^2-550*y^6*z-69019*y*z-825*v*z-275*y^2 -275*v^2,(-z^11)-143*z^6-55*v*z^5+144*z+55*v, (-346*z^12)-124*y*z^11-42218*z^7-15092*y*z^6-275*y^3*z^4+275*y^4*z^3 +440*y^5*z^2+42124*z^2+110*y^6*z+15106*y*z+275*v*z-275*v*y, 867*z^12+334*y*z^11+105776*z^7+40722*y*z^6+275*y^3*z^4-275*y^4*z^3 -1045*y^5*z^2-105873*z^2-330*y^6*z-40726*y*z+550*x*z-275*v*z -550*y^2+275*x^2+275*v*x, (-568*z^13)-232*y*z^12-69289*z^8-28336*y*z^7-550*y^4*z^4+550*y^5*z^3 +69307*z^3+275*y^6*z^2+28018*y*z^2-550*x*z^2+550*y^2*z +550*x^2*z+275*x^3,(-z^11)-143*z^6-55*x*z^5+144*z+55*x, 1121*z^12+442*y*z^11+136763*z^7+53911*y*z^6+275*y^3*z^4-1210*y^5*z^2 -136674*z^2-440*y^6*z-53913*y*z+275*x*z-275*y^2-275*x*y, 1042*z^12+398*y*z^11+127116*z^7+48554*y*z^6-55*y^5*z^2-128103*z^2 -165*y^6*z-48787*y*z-55*y^7+55*y^2]" '(u v x y z))))) (&body))) (test buchberger-cyclic-5 "Buchberger algorithm - cyclic 5" (with-fixture buchberger-cyclic-5-context () (is-true (grobner-test gb fl)) ;; NOTE: Cannot compare using SET-EXCLUSIVE-OR, as the Grobner basis ;; FL was computed using "sugar" strategy and is different from ;; the one obtained with BUCHBERGER, which uses the "normal" strategy. (is (grobner-equal (buchberger fl) gb)) ;;(is (every #'universal-equalp (parallel-buchberger fl) gb)) ) ) (run! 'buchberger-suite) (format t "All tests done!~%")