Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/interfaces/gfan.py
4057 views
1
r"""
2
Interface to Groebner Fan
3
4
AUTHOR:
5
-- Anders Nedergaard Jensen: Write gfan C++ program, which implements
6
algorithms many of which were invented by Jensen, Komei
7
Fukuda, and Rekha Thomas.
8
-- William Stein (2006-03-18): wrote gfan interface (first version)
9
-- Marshall Hampton (2008-03-17): modified to use gfan-0.3, subprocess instead of os.popen2
10
11
TODO -- much functionality of gfan-0.3 is still not exposed
12
13
* at most 52 variables:
14
use gfan_substitute to make easier (?)
15
MH: I think this is now irrelevant since gfan can accept the original ring variables
16
17
* --symmetry is really useful
18
- permutations are 0-based *not* cycle notation; a <---> 0
19
output is broken up much more nicely.
20
21
* -- can work in Z/pZ for p <= 32749
22
23
* -- can compute individual GB's for lex and revlex (via buchberger)
24
"""
25
26
#*****************************************************************************
27
# Copyright (C) 2006 William Stein <[email protected]>
28
#
29
# Distributed under the terms of the GNU General Public License (GPL)
30
#
31
# This code is distributed in the hope that it will be useful,
32
# but WITHOUT ANY WARRANTY; without even the implied warranty of
33
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34
# General Public License for more details.
35
#
36
# The full text of the GPL is available at:
37
#
38
# http://www.gnu.org/licenses/
39
#*****************************************************************************
40
41
from subprocess import *
42
43
class Gfan:
44
"""
45
Interface to Anders Jensen's Groebner Fan program.
46
"""
47
def __call__(self, I, cmd='',verbose = False, format=True):
48
if cmd != '' and cmd.lstrip()[0] != '-':
49
cmd = 'gfan_%s'%cmd
50
else:
51
cmd = 'gfan'
52
53
if len(cmd.split(' ')) > 1:
54
cmd = cmd.split(' ')
55
56
if verbose:
57
print "gfan command:\n%s"%cmd
58
print "gfan input:\n%s"%I
59
60
gfan_processes = Popen(cmd,stdin = PIPE, stdout=PIPE, stderr=PIPE)
61
ans, err = gfan_processes.communicate(input = I)
62
63
# since version 0.4, gfan indicates which LP algorithm it is using.
64
# we avoid interpreting this as an error
65
if (len(err) > 0) and not (err.startswith('LP algorithm being used:')):
66
raise RuntimeError, err
67
68
return ans
69
70
# The instance
71
gfan = Gfan()
72
73
74