1 | from Singular import * |
---|
2 | from interpreter import * |
---|
3 | singular=SingularGlobalsProxy() |
---|
4 | |
---|
5 | def create_ring(char=0, nvars=1, varNames=None, ordering="dp", degvec=None, register=None): |
---|
6 | if not varNames: |
---|
7 | varNames=["x("+str(i)+")" for i in range(1,nvars+1)] |
---|
8 | else: |
---|
9 | nvars=len(varNames) |
---|
10 | if not degvec: |
---|
11 | degvec=IntVector() |
---|
12 | for i in range(0,nvars): |
---|
13 | degvec.append(1) |
---|
14 | modulweights=IntVector() |
---|
15 | modulweights.append(0) |
---|
16 | l=[char,varNames,[[ordering,degvec],["C",modulweights]], Ideal()] |
---|
17 | res=singular.ring(l) |
---|
18 | if register is None: |
---|
19 | return res |
---|
20 | else: |
---|
21 | old_ring=Ring() |
---|
22 | res.set() |
---|
23 | for i in range(nvars): |
---|
24 | v=singular.var(i+1) |
---|
25 | register[str(v)]=v |
---|
26 | |
---|
27 | old_ring.set() |
---|
28 | return res |
---|
29 | |
---|
30 | |
---|
31 | class EquivalenceRelation(object): |
---|
32 | """this class represents an equivalent relation, |
---|
33 | which is implemented by repeated evaluatation of a map |
---|
34 | c[n]=m means that n is equivalent to m""" |
---|
35 | def __init__(self): |
---|
36 | self.mydict={} |
---|
37 | def canonical(self,var): |
---|
38 | while var in self.mydict: |
---|
39 | var=self.mydict[var] |
---|
40 | return var |
---|
41 | def isCanonical(self,var): |
---|
42 | if self.canonical(var)==var: |
---|
43 | return True |
---|
44 | else: |
---|
45 | return False |
---|
46 | def all_rewritings(self,var): |
---|
47 | pass |
---|
48 | def rewrite(self, a,b): |
---|
49 | a=self.canonical(a) |
---|
50 | b=self.canonical(b) |
---|
51 | if not a==b: |
---|
52 | self.mydict[a]=b |
---|
53 | def __getitem__(self,key): |
---|
54 | return self.canonical(key) |
---|
55 | def __setitem__(self, val, key): |
---|
56 | self.rewrite(val,key) |
---|
57 | |
---|
58 | |
---|
59 | class chaintrans(object): |
---|
60 | def __init__(self, chain,full): |
---|
61 | self.table={} |
---|
62 | self.i=1 |
---|
63 | full=list(full) |
---|
64 | for c in full: |
---|
65 | if not c in chain.mydict: |
---|
66 | self.insert(c) |
---|
67 | for c in full: |
---|
68 | self.table[c]=self.table[chain[c]] |
---|
69 | def __getitem__(self, key): |
---|
70 | return self.table[key] |
---|
71 | def insert(self,key): |
---|
72 | self.table[key]=self.i |
---|
73 | self.i=self.i+1 |
---|
74 | def __str__(self): |
---|
75 | return str(self.table) |
---|