source: git/Singular/LIB/ncloc.lib @ 61fbaf

spielwiese
Last change on this file since 61fbaf was 6391eb, checked in by Hans Schoenemann <hannes@…>, 5 years ago
version numbers
  • Property mode set to 100644
File size: 10.8 KB
Line 
1//////////////////////////////////////////////////////////////////////
2version="version ncloc.lib 4.1.2.0 Feb_2019 "; // $Id$
3category="Noncommutative";
4info="
5LIBRARY:   ncloc.lib  Ore-localization in G-Algebras
6AUTHOR:    Johannes Hoffmann, email: johannes.hoffmann at math.rwth-aachen.de
7
8OVERVIEW:
9This library introduces a new type: ncloc.
10This type wraps the localization data defined as in olga.lib.
11An element of type ncloc has two members:
12  - int locType
13  - def locData
14
15OPERATIONS:
16string(ncloc);
17  give a string representation of the data describing the localization
18print(ncloc);
19  prints the string representation of the localization
20status(ncloc);
21  report on the status/validity of the localization
22test(ncloc);
23  check if the localization is valid
24
25INFIX OPERATIONS:
26ncloc == ncloc;
27  compare two localizations
28ncloc != ncloc;
29  compare two localizations
30ncloc = list/poly
31  create a monoidal localization from the given data
32ncloc = ideal
33  create a geometric localization from the given data
34ncloc = intvec
35  create a rational localization from the given data
36
37PROCEDURES:
38isDenom(poly, ncloc);
39  determine if a polynomial is in the denominator set of the localization
40testNcloc();
41  execute a series of internal testing procedures
42testNclocExamples();
43  execute the examples of all procedures in this library
44";
45//////////////////////////////////////////////////////////////////////
46proc testNclocExamples()
47"USAGE:   testNclocExamples()
48PURPOSE: execute the examples of all procedures in this library
49RETURN:  nothing
50NOTE:
51EXAMPLE: "
52{
53    example isDenom;
54}
55//////////////////////////////////////////////////////////////////////
56proc testNcloc()
57"USAGE:   testNcloc()
58PURPOSE: execute a series of internal testing procedures
59RETURN:  nothing
60NOTE:
61EXAMPLE: "
62{
63    print("testing ncloc.lib...");
64    testNclocCreation();
65    testNclocComparison();
66    testDenominatorDetection();
67    print("testing complete - ncloc.lib OK");
68}
69//////////////////////////////////////////////////////////////////////
70static proc mod_init() {
71    LIB "olga.lib";
72    /* new type: ncloc (non-commutative localization) */
73    newstruct("ncloc", "def locData, int locType");
74    // types: 0 - monoidal, 1 - geometric, 2 - rational
75    system("install", "ncloc", "string", nclocToString, 1);
76    system("install", "ncloc", "print", printNcloc, 1);
77    system("install", "ncloc", "=", createNcloc, 1);
78    system("install", "ncloc", "==", compareNclocs, 2);
79    system("install", "ncloc", "!=", invertedCompareNclocs, 2);
80    system("install", "ncloc", "test", testNcloc, 4);
81    system("install", "ncloc", "status", statusNcloc, 4);
82}
83////////// status and printing ///////////////////////////////////////
84static proc statusNcloc(ncloc loc) {
85    return(locStatus(loc.locType, loc.locData)); // locStatus from olga.lib
86}
87//////////////////////////////////////////////////////////////////////
88static proc testNcloc(ncloc loc) {
89    list stat = status(loc);
90    if(!stat[1]) {
91        ERROR(stat[2]);
92    } else {
93        return();
94    }
95}
96//////////////////////////////////////////////////////////////////////
97static proc nclocToString(ncloc loc) {
98    list stat = status(loc);
99    if (!stat[1]) {
100        return(stat[2]);
101    }
102    string result;
103    int locT = loc.locType;
104    int i;
105    if (locT == 0) {
106        list data = loc.locData;
107        result = result + "monoidal localization generated by:" + newline;
108        result = result + string(data[1]);
109        for (i = 2; i <= size(data); i++) {
110            result = result + ", " + string(data[i]);
111        }
112    }
113    if (locT == 1) {
114        ideal data = loc.locData;
115        result = result + "geometric localization at prime ideal:" + newline;
116        result = result + data;
117    }
118    if (locT == 2) {
119        intvec data = loc.locData;
120        result = result + "rational localization generated by:" + newline;
121        result = result + string(var(data[1]));
122        for (i = 2; i <= size(data); i++) {
123            result = result + ", " + string(var(data[i]));
124        }
125    }
126    if (result == "") {
127        result = "invalid localization";
128    }
129    return(result);
130}
131//////////////////////////////////////////////////////////////////////
132static proc printNcloc(ncloc loc) {
133    print(string(loc));
134}
135////////// initialization, comparison and declaration ////////////////
136static proc createNcloc(def input) {
137    string inputType = typeof(input);
138    ncloc result;
139    if (inputType == "list") {
140        result.locType = 0;
141        result.locData = normalizeMonoidal(input);
142    }
143    if (inputType == "poly") {
144        result.locType = 0;
145        result.locData = normalizeMonoidal(list(input));
146    }
147    if (inputType == "ideal") {
148        result.locType = 1;
149        result.locData = std(input);
150    }
151    if (inputType == "intvec") {
152        result.locType = 2;
153        result.locData = normalizeRational(input);
154    }
155    test(result);
156    return(result);
157}
158//////////////////////////////////////////////////////////////////////
159static proc compareNclocs(ncloc loc1, ncloc loc2) {
160    // only detects "naturally" isomorphic localizations
161    test(loc1);
162    test(loc2);
163    int locT = loc1.locType;
164    if (locT != loc2.locType) {
165        return(0); // different types of localizations
166    }
167    if (locT == 0) {
168        int i, j, found;
169        list L1 = loc1.locData;
170        list L2 = loc2.locData;
171        for (i = 1; i <= size(L1); i++) { // test if L1 subset of L2
172            found = 0;
173            for (j = 1; j <= size(L2); j++) {
174                if (L1[i] == L2[j]) {
175                    found = 1;
176                    break;
177                }
178            }
179            if (!found) {
180                return(0);
181            }
182        }
183        for (j = 1; j <= size(L2); j++) { // test if L2 subset of L1
184            found = 0;
185            for (i = 1; i <= size(L1); i++) {
186                if (L1[i] == L2[j]) {
187                    found = 1;
188                    break;
189                }
190            }
191            if (!found) {
192                return(0);
193            }
194        }
195        return(1);
196    }
197    if (locT == 1) {
198        ideal I1 = std(loc1.locData);
199        ideal I2 = std(loc2.locData);
200        if (size(NF(I1,I2)) != 0) { // test if I1 subset of I2
201            return(0);
202        }
203        if (size(NF(I2,I1)) != 0) { // test if I2 subset of I1
204            return(0);
205        }
206        return(1);
207    }
208    if (locT == 2) {
209        return(loc1.locData == loc2.locData); // direct comparison of intvec
210    }
211    ERROR("unreachable state reached"); // enforced by testNcloc
212}
213//////////////////////////////////////////////////////////////////////
214static proc invertedCompareNclocs(ncloc loc1, ncloc loc2) {
215    return(!(compareNclocs(loc1, loc2)));
216}
217//////////////////////////////////////////////////////////////////////
218proc isDenom(poly p, ncloc loc)
219"USAGE:   isDenom(p, loc), poly a, ncloc loc
220PURPOSE: check if p is a valid denominator in the localization loc
221RETURN:  int
222NOTE:    returns 1 or 0, depending whether p is a valid denominator
223EXAMPLE: example isDenom; shows examples"
224{
225    return(isInS(p, loc.locType, loc.locData, 1)); // isInS from olga.lib
226}
227example
228{
229    "EXAMPLE:"; echo = 2;
230    ring R = 0,(x,y,Dx,Dy),dp;
231    def S = Weyl();
232    setring S; S;
233    // monoidal localization
234    ncloc loc;
235    poly g1 = x^2*y+x+2;
236    poly g2 = y^3+x*y;
237    list L = g1,g2;
238    loc = L;
239    poly g = g1^2*g2;
240    poly f = g - 1;
241    isDenom(g, loc);
242    isDenom(f, loc);
243    // geometrical localization
244    loc = ideal(x-1,y-3);
245    g = x^2+y-3;
246    f = (x-1)*g;
247    isDenom(g, loc);
248    isDenom(f, loc);
249    // rational localization
250    intvec v = 2;
251    loc = v;
252    g = y^5+17*y^2-4;
253    f = x*y;
254    isDenom(g, loc);
255    isDenom(f, loc);
256}
257//////////////////////////////////////////////////////////////////////
258////////// internal testing procedures ///////////////////////////////
259static proc testNclocCreation()
260{
261    print("  testing ncloc creation...");
262    ring r = 0,(x,y,Dx,Dy),dp;
263    def R = Weyl();
264    setring R;
265    ncloc loc1 = list(x*y,4*x); // create from list
266    ncloc loc2 = 3*Dx*Dy+2; // create from poly
267    ncloc loc3 = ideal(x-3,y2+y+1); // create from ideal
268    ncloc loc4 = intvec(1,2); // create from intvec
269    ncloc loc5 = intvec(3);
270    print("    ncloc creation OK");
271}
272//////////////////////////////////////////////////////////////////////
273static proc testNclocComparison()
274{
275    print("  testing ncloc comparison...");
276    ring r = 0,(x,y,Dx,Dy),dp;
277    def R = Weyl();
278    setring R;
279    // monoidal localization
280    ncloc monloc1 = list(x,y-3);
281    ncloc monloc2 = list(x*(y-3)^2);
282    ncloc monloc3 = list(y-3);
283    if (!(monloc1 == monloc2)) {
284        ERROR("monoidal comparison failed");
285    }
286    if (!(monloc1 != monloc3)) {
287        ERROR("monoidal inverted comparison failed");
288    }
289    // geometric localization
290    ncloc geoloc1 = ideal(x*y-y+2, y^2-x-2);
291    ncloc geoloc2 = ideal(x*y-y+2, y^2-x-2, x^2+x+2*y-2);
292    ncloc geoloc3 = ideal(x*y-y+1, y^2-x-2);
293    if (!(geoloc1 == geoloc2)) {
294        ERROR("geometric comparison failed");
295    }
296    if (!(geoloc1 != geoloc3)) {
297        ERROR("geometric inverted comparison failed");
298    }
299    // rational localization
300    ncloc ratloc1 = intvec(1);
301    ncloc ratloc2 = intvec(1,1);
302    ncloc ratloc3 = intvec(2);
303    if (!(ratloc1 == ratloc2)) {
304        ERROR("rational comparison failed");
305    }
306    if (!(ratloc1 != ratloc3)) {
307        ERROR("rational inverted comparison failed");
308    }
309    print("    ncloc comparison OK");
310}
311//////////////////////////////////////////////////////////////////////
312static proc testDenominatorDetection() {
313    print("  testing ncloc denominator detection...");
314    ring R = 0,(x,y,Dx,Dy),dp;
315    def S = Weyl();
316    setring S;
317    // monoidal localization
318    ncloc loc;
319    poly g1 = x^2*y+x+2;
320    poly g2 = y^3+x*y;
321    loc = list(g1,g2);
322    poly g = g1^2*g2;
323    poly f = g - 1;
324    if (!isDenom(g, loc)) {
325        ERROR("monoidal positive denominator detection error");
326    }
327    if (isDenom(f, loc)) {
328        ERROR("monoidal negative denominator detection error");
329    }
330    // geometric localization
331    loc = ideal(x-1,y-3);
332    g = x^2+y-3;
333    f = (x-1)*g;
334    if (!isDenom(g, loc)) {
335        ERROR("geometric maximal positive denominator detection error");
336    }
337    if (isDenom(f, loc)) {
338        ERROR("geometric maximal negative denominator detection error");
339    }
340    loc = ideal(x);
341    g = x*y^2-7*y+3;
342    f = x^2-3*x;
343    if (!isDenom(g, loc)) {
344        ERROR("geometric prime positive denominator detection error");
345    }
346    if (isDenom(f, loc)) {
347        ERROR("geometric prime negative denominator detection error");
348    }
349    // rational localization
350    loc = intvec(2);
351    g = y^5+17*y^2-4;
352    f = x*y;
353    if (!isDenom(g, loc)) {
354        ERROR("rational positive denominator detection error");
355    }
356    if (isDenom(f, loc)) {
357        ERROR("rational negative denominator detection error");
358    }
359    print("    ncloc denominator detection OK");
360}
361//////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.