Annotation of OpenXM_contrib2/asir2018/builtin/dp.c, Revision 1.26
1.1 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.26 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2018/builtin/dp.c,v 1.25 2020/06/30 01:52:17 noro Exp $
1.1 noro 49: */
50: #include "ca.h"
51: #include "base.h"
52: #include "parse.h"
53:
54: extern int dp_fcoeffs;
55: extern int dp_nelim;
56: extern int dp_order_pair_length;
57: extern struct order_pair *dp_order_pair;
58: extern struct order_spec *dp_current_spec;
59: extern struct modorder_spec *dp_current_modspec;
60: extern int nd_rref2;
61:
1.22 noro 62: extern int do_weyl;
1.1 noro 63:
1.3 noro 64: void Pdp_monomial_hilbert_poincare();
1.1 noro 65: void Pdp_sort();
66: void Pdp_mul_trunc(),Pdp_quo();
67: void Pdp_ord(), Pdp_ptod(), Pdp_dtop(), Phomogenize();
68: void Pdp_ptozp(), Pdp_ptozp2(), Pdp_red(), Pdp_red2(), Pdp_lcm(), Pdp_redble();
69: void Pdp_sp(), Pdp_hm(), Pdp_ht(), Pdp_hc(), Pdp_rest(), Pdp_td(), Pdp_sugar();
70: void Pdp_set_sugar();
71: void Pdp_cri1(),Pdp_cri2(),Pdp_subd(),Pdp_mod(),Pdp_red_mod(),Pdp_tdiv();
72: void Pdp_prim(),Pdp_red_coef(),Pdp_mag(),Pdp_set_kara(),Pdp_rat();
73: void Pdp_nf(),Pdp_true_nf(),Pdp_true_nf_marked(),Pdp_true_nf_marked_mod();
74:
75: void Pdp_true_nf_and_quotient(),Pdp_true_nf_and_quotient_mod();
76: void Pdp_true_nf_and_quotient_marked(),Pdp_true_nf_and_quotient_marked_mod();
77:
78: void Pdp_nf_mod(),Pdp_true_nf_mod();
79: void Pdp_criB(),Pdp_nelim();
80: void Pdp_minp(),Pdp_sp_mod();
81: void Pdp_homo(),Pdp_dehomo();
1.26 ! noro 82: void Pdpm_homo(),Pdpm_dehomo(),Pdpm_mod();
1.1 noro 83: void Pdp_gr_mod_main(),Pdp_gr_f_main();
84: void Pdp_gr_main(),Pdp_gr_hm_main(),Pdp_gr_d_main(),Pdp_gr_flags();
85: void Pdp_interreduce();
86: void Pdp_f4_main(),Pdp_f4_mod_main(),Pdp_f4_f_main();
87: void Pdp_gr_print();
88: void Pdp_mbase(),Pdp_lnf_mod(),Pdp_nf_tab_mod(),Pdp_mdtod(), Pdp_nf_tab_f();
89: void Pdp_vtoe(), Pdp_etov(), Pdp_dtov(), Pdp_idiv(), Pdp_sep();
90: void Pdp_cont();
91: void Pdp_gr_checklist();
92: void Pdp_ltod(),Pdpv_ord(),Pdpv_ht(),Pdpv_hm(),Pdpv_hc();
1.17 noro 93: void Pdpm_ltod(),Pdpm_dtol(),Pdpm_set_schreyer(),Pdpm_nf(),Pdpm_weyl_nf(),Pdpm_sp(),Pdpm_weyl_sp(),Pdpm_nf_and_quotient(),Pdpm_nf_and_quotient2();
1.18 noro 94: void Pdpm_schreyer_frame(),Pdpm_set_schreyer_level();
1.19 noro 95: void Pdpm_list_to_array(),Pdpm_sp_nf(),Pdpm_insert_to_zlist();
1.21 noro 96: void Pdpm_hm(),Pdpm_ht(),Pdpm_hc(),Pdpm_hp(),Pdpm_rest(),Pdpm_shift(),Pdpm_split(),Pdpm_extract(),Pdpm_sort(),Pdpm_dptodpm(),Pdpm_redble();
1.15 noro 97: void Pdpm_schreyer_base(),Pdpm_simplify_syz(),Pdpm_td();
1.21 noro 98: void Pdpm_remove_cont();
1.1 noro 99:
100: void Pdp_weyl_red();
101: void Pdp_weyl_sp();
102:
103: void Pdp_weyl_nf(),Pdp_weyl_nf_mod();
104: void Pdp_weyl_true_nf_and_quotient(),Pdp_weyl_true_nf_and_quotient_mod();
105: void Pdp_weyl_true_nf_and_quotient_marked(),Pdp_weyl_true_nf_and_quotient_marked_mod();
106:
107: void Pdp_weyl_gr_main(),Pdp_weyl_gr_mod_main(),Pdp_weyl_gr_f_main();
108: void Pdp_weyl_f4_main(),Pdp_weyl_f4_mod_main(),Pdp_weyl_f4_f_main();
109: void Pdp_weyl_mul(),Pdp_weyl_mul_mod(),Pdp_weyl_act();
110: void Pdp_weyl_set_weight();
111: void Pdp_set_weight(),Pdp_set_top_weight(),Pdp_set_module_weight();
112: void Pdp_nf_f(),Pdp_weyl_nf_f();
113: void Pdpm_nf_f(),Pdpm_weyl_nf_f();
114: void Pdp_lnf_f();
115: void Pnd_gr(),Pnd_gr_trace(),Pnd_f4(),Pnd_f4_trace();
1.25 noro 116: void Pnd_sba(),Pnd_sba_f4();
1.1 noro 117: void Pnd_gr_postproc(), Pnd_weyl_gr_postproc();
118: void Pnd_gr_recompute_trace(), Pnd_btog();
119: void Pnd_weyl_gr(),Pnd_weyl_gr_trace();
120: void Pnd_nf(),Pnd_weyl_nf();
121: void Pdp_initial_term();
122: void Pdp_order();
123: void Pdp_inv_or_split();
124: void Pdp_compute_last_t();
125: void Pdp_compute_last_w();
126: void Pdp_compute_essential_df();
127: void Pdp_get_denomlist();
128: void Pdp_symb_add();
129: void Pdp_mono_raddec();
130: void Pdp_mono_reduce();
131: void Pdp_rref2(),Psumi_updatepairs(),Psumi_symbolic();
132:
133: LIST dp_initial_term();
134: LIST dp_order();
135: void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo,
136: int *modular,struct order_spec **ord);
137: NODE dp_inv_or_split(NODE gb,DP f,struct order_spec *spec, DP *inv);
138:
139: LIST remove_zero_from_list(LIST);
140:
141: struct ftab dp_tab[] = {
142: /* content reduction */
143: {"dp_ptozp",Pdp_ptozp,1},
144: {"dp_ptozp2",Pdp_ptozp2,2},
145: {"dp_prim",Pdp_prim,1},
146: {"dp_red_coef",Pdp_red_coef,2},
147: {"dp_cont",Pdp_cont,1},
1.21 noro 148: {"dpm_remove_cont",Pdpm_remove_cont,1},
1.1 noro 149:
150: /* polynomial ring */
151: /* special operations */
152: {"dp_mul_trunc",Pdp_mul_trunc,3},
153: {"dp_quo",Pdp_quo,2},
154:
155: /* s-poly */
156: {"dp_sp",Pdp_sp,2},
157: {"dp_sp_mod",Pdp_sp_mod,3},
158:
159: /* m-reduction */
160: {"dp_red",Pdp_red,3},
161: {"dp_red_mod",Pdp_red_mod,4},
162:
163: /* normal form */
164: {"dp_nf",Pdp_nf,4},
165: {"dp_nf_mod",Pdp_nf_mod,5},
166: {"dp_nf_f",Pdp_nf_f,4},
1.9 noro 167: {"dpm_nf_and_quotient",Pdpm_nf_and_quotient,-3},
1.17 noro 168: {"dpm_nf_and_quotient2",Pdpm_nf_and_quotient2,-3},
1.11 noro 169: {"dpm_nf_f",Pdpm_nf_f,-4},
170: {"dpm_weyl_nf_f",Pdpm_weyl_nf_f,-4},
171: {"dpm_nf",Pdpm_nf,-4},
1.1 noro 172: {"dpm_sp",Pdpm_sp,2},
173: {"dpm_weyl_sp",Pdpm_weyl_sp,2},
174:
175: {"dp_true_nf",Pdp_true_nf,4},
176: {"dp_true_nf_mod",Pdp_true_nf_mod,5},
177: {"dp_true_nf_marked",Pdp_true_nf_marked,4},
178: {"dp_true_nf_marked_mod",Pdp_true_nf_marked_mod,5},
179:
180: {"dp_true_nf_and_quotient",Pdp_true_nf_and_quotient,3},
181: {"dp_true_nf_and_quotient_mod",Pdp_true_nf_and_quotient_mod,4},
182: {"dp_true_nf_and_quotient_marked",Pdp_true_nf_and_quotient_marked,4},
183: {"dp_true_nf_and_quotient_marked_mod",Pdp_true_nf_and_quotient_marked_mod,5},
184:
185: {"dp_lnf_mod",Pdp_lnf_mod,3},
186: {"dp_nf_tab_f",Pdp_nf_tab_f,2},
187: {"dp_nf_tab_mod",Pdp_nf_tab_mod,3},
188: {"dp_lnf_f",Pdp_lnf_f,2},
189:
190: /* Buchberger algorithm */
191: {"dp_gr_main",Pdp_gr_main,-5},
192: {"dp_interreduce",Pdp_interreduce,3},
193: {"dp_gr_mod_main",Pdp_gr_mod_main,5},
194: {"dp_gr_f_main",Pdp_gr_f_main,4},
195: {"dp_gr_checklist",Pdp_gr_checklist,2},
196: {"nd_f4",Pnd_f4,-4},
197: {"nd_gr",Pnd_gr,-4},
1.24 noro 198: {"nd_sba",Pnd_sba,-4},
1.25 noro 199: {"nd_sba_f4",Pnd_sba_f4,-4},
1.1 noro 200: {"nd_gr_trace",Pnd_gr_trace,-5},
201: {"nd_f4_trace",Pnd_f4_trace,-5},
202: {"nd_gr_postproc",Pnd_gr_postproc,5},
203: {"nd_gr_recompute_trace",Pnd_gr_recompute_trace,5},
204: {"nd_btog",Pnd_btog,-6},
205: {"nd_weyl_gr_postproc",Pnd_weyl_gr_postproc,5},
206: {"nd_weyl_gr",Pnd_weyl_gr,-4},
207: {"nd_weyl_gr_trace",Pnd_weyl_gr_trace,-5},
208: {"nd_nf",Pnd_nf,5},
209: {"nd_weyl_nf",Pnd_weyl_nf,5},
210:
211: /* F4 algorithm */
212: {"dp_f4_main",Pdp_f4_main,3},
213: {"dp_f4_mod_main",Pdp_f4_mod_main,4},
214:
215: /* weyl algebra */
216: /* multiplication */
217: {"dp_weyl_mul",Pdp_weyl_mul,2},
218: {"dp_weyl_mul_mod",Pdp_weyl_mul_mod,3},
219: {"dp_weyl_act",Pdp_weyl_act,2},
220:
221: /* s-poly */
222: {"dp_weyl_sp",Pdp_weyl_sp,2},
223:
224: /* m-reduction */
225: {"dp_weyl_red",Pdp_weyl_red,3},
226:
227: /* normal form */
228: {"dp_weyl_nf",Pdp_weyl_nf,4},
1.11 noro 229: {"dpm_weyl_nf",Pdpm_weyl_nf,-4},
1.1 noro 230: {"dp_weyl_nf_mod",Pdp_weyl_nf_mod,5},
231: {"dp_weyl_nf_f",Pdp_weyl_nf_f,4},
232:
233: {"dp_weyl_true_nf_and_quotient",Pdp_weyl_true_nf_and_quotient,3},
234: {"dp_weyl_true_nf_and_quotient_mod",Pdp_weyl_true_nf_and_quotient_mod,4},
235: {"dp_weyl_true_nf_and_quotient_marked",Pdp_weyl_true_nf_and_quotient_marked,4},
236: {"dp_weyl_true_nf_and_quotient_marked_mod",Pdp_weyl_true_nf_and_quotient_marked_mod,5},
237:
238:
239: /* Buchberger algorithm */
240: {"dp_weyl_gr_main",Pdp_weyl_gr_main,-5},
241: {"dp_weyl_gr_mod_main",Pdp_weyl_gr_mod_main,5},
242: {"dp_weyl_gr_f_main",Pdp_weyl_gr_f_main,4},
243:
244: /* F4 algorithm */
245: {"dp_weyl_f4_main",Pdp_weyl_f4_main,3},
246: {"dp_weyl_f4_mod_main",Pdp_weyl_f4_mod_main,4},
247:
1.3 noro 248: /* Hilbert function */
249: {"dp_monomial_hilbert_poincare",Pdp_monomial_hilbert_poincare,2},
250:
1.1 noro 251: /* misc */
252: {"dp_inv_or_split",Pdp_inv_or_split,3},
253: {"dp_set_weight",Pdp_set_weight,-1},
254: {"dp_set_module_weight",Pdp_set_module_weight,-1},
255: {"dp_set_top_weight",Pdp_set_top_weight,-1},
256: {"dp_weyl_set_weight",Pdp_weyl_set_weight,-1},
257:
258: {"dp_get_denomlist",Pdp_get_denomlist,0},
259: {0,0,0},
260: };
261:
262: struct ftab dp_supp_tab[] = {
263: /* setting flags */
264: {"dp_sort",Pdp_sort,1},
265: {"dp_ord",Pdp_ord,-1},
1.9 noro 266: {"dpm_set_schreyer",Pdpm_set_schreyer,-1},
1.18 noro 267: {"dpm_set_schreyer_level",Pdpm_set_schreyer_level,1},
268: {"dpm_schreyer_frame",Pdpm_schreyer_frame,1},
1.1 noro 269: {"dpv_ord",Pdpv_ord,-2},
270: {"dp_set_kara",Pdp_set_kara,-1},
271: {"dp_nelim",Pdp_nelim,-1},
272: {"dp_gr_flags",Pdp_gr_flags,-1},
273: {"dp_gr_print",Pdp_gr_print,-1},
274:
275: /* converters */
276: {"homogenize",Phomogenize,3},
277: {"dp_ptod",Pdp_ptod,-2},
278: {"dp_dtop",Pdp_dtop,2},
279: {"dp_homo",Pdp_homo,1},
280: {"dp_dehomo",Pdp_dehomo,1},
281: {"dp_etov",Pdp_etov,1},
282: {"dp_vtoe",Pdp_vtoe,1},
283: {"dp_dtov",Pdp_dtov,1},
284: {"dp_mdtod",Pdp_mdtod,1},
285: {"dp_mod",Pdp_mod,3},
286: {"dp_rat",Pdp_rat,1},
287: {"dp_ltod",Pdp_ltod,-2},
288:
289: {"dpm_ltod",Pdpm_ltod,2},
1.9 noro 290: {"dpm_dptodpm",Pdpm_dptodpm,2},
1.14 noro 291: {"dpm_dtol",Pdpm_dtol,2},
1.16 noro 292: {"dpm_homo",Pdpm_homo,1},
293: {"dpm_dehomo",Pdpm_dehomo,1},
1.26 ! noro 294: {"dpm_mod",Pdpm_mod,2},
1.1 noro 295:
296: /* criteria */
297: {"dp_cri1",Pdp_cri1,2},
298: {"dp_cri2",Pdp_cri2,2},
299: {"dp_criB",Pdp_criB,3},
300:
301: /* simple operation */
302: {"dp_subd",Pdp_subd,2},
303: {"dp_lcm",Pdp_lcm,2},
304: {"dp_hm",Pdp_hm,1},
305: {"dp_ht",Pdp_ht,1},
306: {"dp_hc",Pdp_hc,1},
307: {"dpv_hm",Pdpv_hm,1},
308: {"dpv_ht",Pdpv_ht,1},
309: {"dpv_hc",Pdpv_hc,1},
310: {"dpm_hm",Pdpm_hm,1},
311: {"dpm_ht",Pdpm_ht,1},
312: {"dpm_hc",Pdpm_hc,1},
1.10 noro 313: {"dpm_hp",Pdpm_hp,1},
314: {"dpm_rest",Pdpm_rest,1},
1.9 noro 315: {"dpm_shift",Pdpm_shift,2},
316: {"dpm_split",Pdpm_split,2},
1.21 noro 317: {"dpm_extract",Pdpm_extract,2},
1.9 noro 318: {"dpm_sort",Pdpm_sort,1},
1.1 noro 319: {"dp_rest",Pdp_rest,1},
320: {"dp_initial_term",Pdp_initial_term,1},
321: {"dp_order",Pdp_order,1},
322: {"dp_symb_add",Pdp_symb_add,2},
323:
324: /* degree and size */
325: {"dp_td",Pdp_td,1},
326: {"dp_mag",Pdp_mag,1},
327: {"dp_sugar",Pdp_sugar,1},
328: {"dp_set_sugar",Pdp_set_sugar,2},
1.15 noro 329: {"dpm_td",Pdpm_td,1},
1.1 noro 330:
331: /* misc */
332: {"dp_mbase",Pdp_mbase,1},
333: {"dp_redble",Pdp_redble,2},
1.9 noro 334: {"dpm_redble",Pdpm_redble,2},
1.1 noro 335: {"dp_sep",Pdp_sep,2},
336: {"dp_idiv",Pdp_idiv,2},
337: {"dp_tdiv",Pdp_tdiv,2},
338: {"dp_minp",Pdp_minp,2},
339: {"dp_compute_last_w",Pdp_compute_last_w,5},
340: {"dp_compute_last_t",Pdp_compute_last_t,5},
341: {"dp_compute_essential_df",Pdp_compute_essential_df,2},
342: {"dp_mono_raddec",Pdp_mono_raddec,2},
343: {"dp_mono_reduce",Pdp_mono_reduce,2},
1.11 noro 344: {"dpm_schreyer_base",Pdpm_schreyer_base,1},
1.19 noro 345: {"dpm_list_to_array",Pdpm_list_to_array,1},
346: {"dpm_sp_nf",Pdpm_sp_nf,4},
347: {"dpm_insert_to_zlist",Pdpm_insert_to_zlist,3},
1.12 noro 348: {"dpm_simplify_syz",Pdpm_simplify_syz,2},
1.1 noro 349:
350: {"dp_rref2",Pdp_rref2,2},
351: {"sumi_updatepairs",Psumi_updatepairs,3},
352: {"sumi_symbolic",Psumi_symbolic,5},
353:
354: {0,0,0}
355: };
356:
357: NODE compute_last_w(NODE g,NODE gh,int n,int **v,int row1,int **m1,int row2,int **m2);
358: Q compute_last_t(NODE g,NODE gh,Q t,VECT w1,VECT w2,NODE *homo,VECT *wp);
359:
1.3 noro 360: int comp_by_tdeg(DP *a,DP *b)
361: {
362: int da,db;
363:
364: da = BDY(*a)->dl->td;
365: db = BDY(*b)->dl->td;
366: if ( da>db ) return 1;
367: else if ( da<db ) return -1;
368: else return 0;
369: }
370:
371: void dl_print(DL d,int n)
372: {
373: int i;
374:
375: printf("<<");
376: for ( i = 0; i < n; i++ )
377: printf("%d ",d->d[i]);
378: printf(">>\n");
379: }
380:
381: int simple_check(VECT b,int nv)
382: {
383: int n,i,j;
384: DL *p;
385:
386: n = b->len; p = (DL *)b->body;
387: for ( i = 0; i < n; i++ ) {
388: for ( j = 0; j < nv; j++ ) {
389: if ( p[i]->d[j] ) break;
390: }
391: if ( p[i]->d[j] != p[i]->td ) return 0;
392: }
393: return 1;
394: }
395:
396: void make_reduced(VECT b,int nv)
397: {
398: int n,i,j;
399: DL *p;
400: DL pi;
401:
402: n = b->len;
403: p = (DL *)BDY(b);
404: for ( i = 0; i < n; i++ ) {
405: pi = p[i];
406: if ( !pi ) continue;
407: for ( j = 0; j < n; j++ )
408: if ( i != j && p[j] && _dl_redble(pi,p[j],nv) ) p[j] = 0;
409: }
410: for ( i = j = 0; i < n; i++ )
411: if ( p[i] ) p[j++] = p[i];
412: b->len = j;
413: }
414:
415: void make_reduced2(VECT b,int k,int nv)
416: {
417: int n,i,j,l;
418: DL *p;
419: DL pi;
420:
421: n = b->len;
422: p = (DL *)BDY(b);
423: for ( i = l = k; i < n; i++ ) {
424: pi = p[i];
425: for ( j = 0; j < k; j++ )
426: if ( _dl_redble(p[j],pi,nv) ) break;
427: if ( j == k )
428: p[l++] = pi;
429: }
430: b->len = l;
431: }
432:
433: int i_all,i_simple;
434:
435: P mhp_simple(VECT b,VECT x,P t)
436: {
437: int n,i,j,nv;
438: DL *p;
439: P hp,mt,s,w;
440: Z z;
441:
442: n = b->len; nv = x->len; p = (DL *)BDY(b);
443: hp = (P)ONE;
444: for ( i = 0; i < n; i++ ) {
445: for ( j = 0; j < nv; j++ )
446: if ( p[i]->d[j] ) break;
447: STOZ(p[i]->d[j],z);
448: chsgnp(t,&mt); mt->dc->d =z;
449: addp(CO,mt,(P)ONE,&s); mulp(CO,hp,s,&w); hp = w;
450: }
451: return hp;
452: }
453:
454: struct oEGT eg_comp;
455:
456: void mhp_rec(VECT b,VECT x,P t,P *r)
457: {
458: int n,i,j,k,l,i2,nv,len;
459: int *d;
460: Z mone,z;
461: DCP dc,dc1;
462: P s;
463: P *r2;
464: DL *p,*q;
465: DL pi,xj,d1;
466: VECT c;
467: struct oEGT eg0,eg1;
468:
469: i_all++;
470: n = b->len; nv = x->len; p = (DL *)BDY(b);
471: if ( !n ) {
472: r[0] = (P)ONE;
473: return;
474: }
475: if ( n == 1 && p[0]->td == 0 )
476: return;
477: for ( i = 0; i < n; i++ )
478: if ( p[i]->td > 1 ) break;
479: if ( i == n ) {
480: r[n] = (P)ONE;
481: return;
482: }
483: #if 0
484: if ( simple_check(b,nv) ) {
485: i_simple++;
486: r[0] = mhp_simple(b,x,t);
487: return;
488: }
489: #endif
490: for ( j = 0, d = p[i]->d; j < nv; j++ )
491: if ( d[j] ) break;
492: xj = BDY(x)[j];
493: MKVECT(c,n); q = (DL *)BDY(c);
494: for ( i = k = l = 0; i < n; i++ )
495: if ( p[i]->d[j] ) {
496: pi = p[i];
497: NEWDL(d1,nv); d1->td =pi->td - 1;
498: memcpy(d1->d,pi->d,nv*sizeof(int));
499: d1->d[j]--;
500: p[k++] = d1;
501: } else
502: q[l++] = p[i];
503: for ( i = k, i2 = 0; i2 < l; i++, i2++ )
504: p[i] = q[i2];
505: /* b=(b[0]/xj,...,b[k-1]/xj,b[k],...b[n-1]) where
506: b[0],...,b[k-1] are divisible by k */
507: make_reduced2(b,k,nv);
508: mhp_rec(b,x,t,r);
509: /* c = (b[0],...,b[l-1],xj) */
510: q[l] = xj; c->len = l+1;
511: r2 = (P *)CALLOC(nv+1,sizeof(P));
512: mhp_rec(c,x,t,r2);
513: // get_eg(&eg0);
514: for ( i = 0; i <= nv; i++ ) {
515: mulp(CO,r[i],t,&s); addp(CO,s,r2[i],&r[i]);
516: }
517: // get_eg(&eg1); add_eg(&eg_comp,&eg0,&eg1);
518: }
519:
1.4 noro 520: /* (n+a)Cb as a polynomial of n; return (n+a)*...*(n+a-b+1) */
521:
522: P binpoly(P n,int a,int b)
523: {
524: Z z;
525: P s,r,t;
526: int i;
527:
528: STOZ(a,z); addp(CO,n,(P)z,&s); r = (P)ONE;
529: for ( i = 0; i < b; i++ ) {
530: mulp(CO,r,s,&t); r = t;
531: subp(CO,s,(P)ONE,&t); s = t;
532: }
533: return r;
534: }
535:
1.9 noro 536: void ibin(unsigned long int n,unsigned long int k,Z *r);
537:
1.8 noro 538: void mhp_to_hf(VL vl,P hp,int n,P *plist,VECT *head,P *hf)
1.5 noro 539: {
540: P tv,gcd,q,h,hphead,tt,ai,hpoly,nv,bp,w;
1.8 noro 541: Z d,z;
1.5 noro 542: DCP dc,topdc;
543: VECT hfhead;
544: int i,s,qd;
545:
546: if ( !hp ) {
547: MKVECT(hfhead,0); *head = hfhead;
1.8 noro 548: *hf = 0;
1.5 noro 549: } else {
550: makevar("t",&tv);
551: ezgcdp(CO,hp,plist[n],&gcd);
552: if ( NUM(gcd) ) {
553: s = n;
554: q = hp;
555: } else {
556: s = n-ZTOS(DEG(DC(gcd)));
557: divsp(CO,hp,plist[n-s],&q);
558: }
559: if ( NUM(q) ) qd = 0;
560: else qd = ZTOS(DEG(DC(q)));
1.6 noro 561: if ( s == 0 ) {
562: MKVECT(hfhead,qd+1);
563: for ( i = 0; i <= qd; i++ ) {
564: coefp(q,i,(P *)&BDY(hfhead)[i]);
1.5 noro 565: }
1.6 noro 566: *head = hfhead;
567: *hf = 0;
568: } else {
569: if ( qd ) {
570: topdc = 0;
571: for ( i = 0; i < qd; i++ ) {
572: NEWDC(dc); NEXT(dc) = topdc;
1.9 noro 573: ibin(i+s-1,s-1,(Z *)&COEF(dc));
1.6 noro 574: STOZ(i,d); DEG(dc) = d;
575: topdc = dc;
576: }
577: MKP(VR(tv),topdc,h);
578: mulp(CO,h,q,&hphead);
579: }
580: MKVECT(hfhead,qd);
581: for ( i = 0; i < qd; i++ )
582: coefp(hphead,i,(P *)&BDY(hfhead)[i]);
583: *head = hfhead;
584: hpoly = 0;
585: makevar("n",&nv);
586: for ( i = 0; i <= qd; i++ ) {
587: coefp(q,i,&ai);
588: bp = binpoly(nv,s-i-1,s-1);
589: mulp(CO,ai,bp,&tt);
590: addp(CO,hpoly,tt,&w);
591: hpoly = w;
592: }
1.8 noro 593: if ( s > 2 ) {
594: factorialz(s-1,&z);
595: divsp(CO,hpoly,(P)z,&tt); hpoly = tt;
596: }
1.6 noro 597: *hf = hpoly;
1.8 noro 598: for ( i = qd-1; i >= 0; i-- ) {
599: UTOZ(i,z);
600: substp(CO,hpoly,VR(nv),(P)z,&tt);
601: if ( cmpz((Z)tt,(Z)BDY(hfhead)[i]) ) break;
602: }
603: hfhead->len = i+1;
1.5 noro 604: }
605: }
606: }
607:
608: /* create (1,1-t,...,(1-t)^n) */
609:
610: P *mhp_prep(int n,P *tv) {
611: P *plist;
612: P mt,t1;
613: int i;
614:
615: plist = (P *)MALLOC((n+1)*sizeof(P));
616: /* t1 = 1-t */
617: makevar("t",tv); chsgnp(*tv,&mt); addp(CO,mt,(P)ONE,&t1);
618: for ( plist[0] = (P)ONE, i = 1; i <= n; i++ )
619: mulp(CO,plist[i-1],t1,&plist[i]);
620: return plist;
621: }
622:
623: P mhp_ctop(P *r,P *plist,int n)
624: {
625: int i;
626: P hp,u,w;
627:
628: for ( hp = 0, i = 0; i <= n; i++ ) {
629: mulp(CO,plist[i],r[i],&u); addp(CO,u,hp,&w); hp = w;
630: }
631: return hp;
632: }
633:
1.3 noro 634: void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp)
635: {
636: LIST g,v;
637: VL vl;
1.5 noro 638: int m,n,i;
639: VECT b,x,hfhead;
1.3 noro 640: NODE t,nd;
1.5 noro 641: Z z,den;
642: P hp,tv,mt,t1,u,w,hpoly;
1.3 noro 643: DP a;
644: DL *p;
645: P *plist,*r;
1.4 noro 646: Obj val;
1.3 noro 647:
648: i_simple = i_all = 0;
649: g = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
650: pltovl(v,&vl);
651: m = length(BDY(g)); MKVECT(b,m); p = (DL *)BDY(b);
652: for ( t = BDY(g), i = 0; t; t = NEXT(t), i++ ) {
1.5 noro 653: if ( !BDY(t) )
654: p[i] = 0;
655: else {
656: ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl;
657: }
1.3 noro 658: }
659: n = length(BDY(v)); MKVECT(x,n); p = (DL *)BDY(x);
660: for ( t = BDY(v), i = 0; t; t = NEXT(t), i++ ) {
661: ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl;
662: }
1.5 noro 663:
1.3 noro 664: r = (P *)CALLOC(n+1,sizeof(P));
1.5 noro 665: plist = mhp_prep(n,&tv);
1.3 noro 666: make_reduced(b,n);
667: mhp_rec(b,x,tv,r);
1.5 noro 668: hp = mhp_ctop(r,plist,n);
1.8 noro 669: mhp_to_hf(CO,hp,n,plist,&hfhead,&hpoly);
1.4 noro 670: UTOZ(n,z);
1.8 noro 671: nd = mknode(4,hp,z,hfhead,hpoly);
1.5 noro 672: MKLIST(*rp,nd);
1.3 noro 673: }
1.5 noro 674:
1.1 noro 675: void Pdp_compute_last_t(NODE arg,LIST *rp)
676: {
677: NODE g,gh,homo,n;
678: LIST hlist;
679: VECT v1,v2,w;
680: Q t;
681:
682: g = (NODE)BDY((LIST)ARG0(arg));
683: gh = (NODE)BDY((LIST)ARG1(arg));
684: t = (Q)ARG2(arg);
685: v1 = (VECT)ARG3(arg);
686: v2 = (VECT)ARG4(arg);
687: t = compute_last_t(g,gh,t,v1,v2,&homo,&w);
688: MKLIST(hlist,homo);
689: n = mknode(3,t,w,hlist);
690: MKLIST(*rp,n);
691: }
692:
693: void Pdp_compute_last_w(NODE arg,LIST *rp)
694: {
695: NODE g,gh,r;
696: VECT w,rv;
697: LIST l;
698: MAT w1,w2;
699: int row1,row2,i,j,n;
700: int *v;
701: int **m1,**m2;
702: Z q;
703:
704: g = (NODE)BDY((LIST)ARG0(arg));
705: gh = (NODE)BDY((LIST)ARG1(arg));
706: w = (VECT)ARG2(arg);
707: w1 = (MAT)ARG3(arg);
708: w2 = (MAT)ARG4(arg);
709: n = w1->col;
710: row1 = w1->row;
711: row2 = w2->row;
712: if ( w ) {
713: v = W_ALLOC(n);
1.2 noro 714: for ( i = 0; i < n; i++ ) v[i] = ZTOS((Q)w->body[i]);
1.1 noro 715: } else v = 0;
716: m1 = almat(row1,n);
717: for ( i = 0; i < row1; i++ )
1.2 noro 718: for ( j = 0; j < n; j++ ) m1[i][j] = ZTOS((Q)w1->body[i][j]);
1.1 noro 719: m2 = almat(row2,n);
720: for ( i = 0; i < row2; i++ )
1.2 noro 721: for ( j = 0; j < n; j++ ) m2[i][j] = ZTOS((Q)w2->body[i][j]);
1.1 noro 722: r = compute_last_w(g,gh,n,&v,row1,m1,row2,m2);
723: if ( !r ) *rp = 0;
724: else {
725: MKVECT(rv,n);
726: for ( i = 0; i < n; i++ ) {
1.2 noro 727: STOZ(v[i],q); rv->body[i] = (pointer)q;
1.1 noro 728: }
729: MKLIST(l,r);
730: r = mknode(2,rv,l);
731: MKLIST(*rp,r);
732: }
733: }
734:
735: NODE compute_essential_df(DP *g,DP *gh,int n);
736:
737: void Pdp_compute_essential_df(NODE arg,LIST *rp)
738: {
739: VECT g,gh;
740: NODE r;
741:
742: g = (VECT)ARG0(arg);
743: gh = (VECT)ARG1(arg);
744: r = (NODE)compute_essential_df((DP *)BDY(g),(DP *)BDY(gh),g->len);
745: MKLIST(*rp,r);
746: }
747:
748: void Pdp_inv_or_split(NODE arg,Obj *rp)
749: {
750: NODE gb,newgb;
751: DP f,inv;
752: struct order_spec *spec;
753: LIST list;
754:
755: do_weyl = 0; dp_fcoeffs = 0;
756: asir_assert(ARG0(arg),O_LIST,"dp_inv_or_split");
757: asir_assert(ARG1(arg),O_DP,"dp_inv_or_split");
758: if ( !create_order_spec(0,(Obj)ARG2(arg),&spec) )
759: error("dp_inv_or_split : invalid order specification");
760: gb = BDY((LIST)ARG0(arg));
761: f = (DP)ARG1(arg);
762: newgb = (NODE)dp_inv_or_split(gb,f,spec,&inv);
763: if ( !newgb ) {
764: /* invertible */
765: *rp = (Obj)inv;
766: } else {
767: MKLIST(list,newgb);
768: *rp = (Obj)list;
769: }
770: }
771:
772: void Pdp_sort(NODE arg,DP *rp)
773: {
774: dp_sort((DP)ARG0(arg),rp);
775: }
776:
777: void Pdp_mdtod(NODE arg,DP *rp)
778: {
779: MP m,mr,mr0;
780: DP p;
781: P t;
782:
783: p = (DP)ARG0(arg);
784: if ( !p )
785: *rp = 0;
786: else {
787: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
788: mptop((P)m->c,&t); NEXTMP(mr0,mr); mr->c = (Obj)t; mr->dl = m->dl;
789: }
790: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar;
791: }
792: }
793:
794: void Pdp_sep(NODE arg,VECT *rp)
795: {
796: DP p,r;
797: MP m,t;
798: MP *w0,*w;
799: int i,n,d,nv,sugar;
800: VECT v;
801: pointer *pv;
802:
803: p = (DP)ARG0(arg); m = BDY(p);
1.2 noro 804: d = ZTOS((Q)ARG1(arg));
1.1 noro 805: for ( t = m, n = 0; t; t = NEXT(t), n++ );
806: if ( d > n )
807: d = n;
808: MKVECT(v,d); *rp = v;
809: pv = BDY(v); nv = p->nv; sugar = p->sugar;
810: w0 = (MP *)MALLOC(d*sizeof(MP)); bzero(w0,d*sizeof(MP));
811: w = (MP *)MALLOC(d*sizeof(MP)); bzero(w,d*sizeof(MP));
812: for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, i %= d ) {
813: NEXTMP(w0[i],w[i]); w[i]->c = t->c; w[i]->dl = t->dl;
814: }
815: for ( i = 0; i < d; i++ ) {
816: NEXT(w[i]) = 0; MKDP(nv,w0[i],r); r->sugar = sugar;
817: pv[i] = (pointer)r;
818: }
819: }
820:
821: void Pdp_idiv(NODE arg,DP *rp)
822: {
823: dp_idiv((DP)ARG0(arg),(Z)ARG1(arg),rp);
824: }
825:
826: void Pdp_cont(NODE arg,Z *rp)
827: {
828: dp_cont((DP)ARG0(arg),rp);
829: }
830:
1.21 noro 831: void dpm_ptozp(DPM p,Z *cont,DPM *r);
832:
833: void Pdpm_remove_cont(NODE arg,LIST *rp)
834: {
835: NODE nd;
836: Z cont;
837: DPM p;
838:
839: dpm_ptozp((DPM)ARG0(arg),&cont,&p);
840: nd = mknode(2,cont,p);
841: MKLIST(*rp,nd);
842: }
843:
1.1 noro 844: void Pdp_dtov(NODE arg,VECT *rp)
845: {
846: dp_dtov((DP)ARG0(arg),rp);
847: }
848:
849: void Pdp_mbase(NODE arg,LIST *rp)
850: {
851: NODE mb;
852:
853: asir_assert(ARG0(arg),O_LIST,"dp_mbase");
854: dp_mbase(BDY((LIST)ARG0(arg)),&mb);
855: MKLIST(*rp,mb);
856: }
857:
858: void Pdp_etov(NODE arg,VECT *rp)
859: {
860: DP dp;
861: int n,i;
862: int *d;
863: VECT v;
864: Z t;
865:
866: dp = (DP)ARG0(arg);
867: asir_assert(dp,O_DP,"dp_etov");
868: n = dp->nv; d = BDY(dp)->dl->d;
869: MKVECT(v,n);
870: for ( i = 0; i < n; i++ ) {
1.2 noro 871: STOZ(d[i],t); v->body[i] = (pointer)t;
1.1 noro 872: }
873: *rp = v;
874: }
875:
876: void Pdp_vtoe(NODE arg,DP *rp)
877: {
878: DP dp;
879: DL dl;
880: MP m;
881: int n,i,td;
882: int *d;
883: VECT v;
884:
885: v = (VECT)ARG0(arg);
886: asir_assert(v,O_VECT,"dp_vtoe");
887: n = v->len;
888: NEWDL(dl,n); d = dl->d;
889: for ( i = 0, td = 0; i < n; i++ ) {
1.2 noro 890: d[i] = ZTOS((Q)(v->body[i])); td += MUL_WEIGHT(d[i],i);
1.1 noro 891: }
892: dl->td = td;
893: NEWMP(m); m->dl = dl; m->c = (Obj)ONE; NEXT(m) = 0;
894: MKDP(n,m,dp); dp->sugar = td;
895: *rp = dp;
896: }
897:
898: void Pdp_lnf_mod(NODE arg,LIST *rp)
899: {
900: DP r1,r2;
901: NODE b,g,n;
902: int mod;
903:
904: asir_assert(ARG0(arg),O_LIST,"dp_lnf_mod");
905: asir_assert(ARG1(arg),O_LIST,"dp_lnf_mod");
906: asir_assert(ARG2(arg),O_N,"dp_lnf_mod");
907: b = BDY((LIST)ARG0(arg)); g = BDY((LIST)ARG1(arg));
1.2 noro 908: mod = ZTOS((Q)ARG2(arg));
1.1 noro 909: dp_lnf_mod((DP)BDY(b),(DP)BDY(NEXT(b)),g,mod,&r1,&r2);
910: NEWNODE(n); BDY(n) = (pointer)r1;
911: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)r2;
912: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
913: }
914:
915: void Pdp_lnf_f(NODE arg,LIST *rp)
916: {
917: DP r1,r2;
918: NODE b,g,n;
919:
920: asir_assert(ARG0(arg),O_LIST,"dp_lnf_f");
921: asir_assert(ARG1(arg),O_LIST,"dp_lnf_f");
922: b = BDY((LIST)ARG0(arg)); g = BDY((LIST)ARG1(arg));
923: dp_lnf_f((DP)BDY(b),(DP)BDY(NEXT(b)),g,&r1,&r2);
924: NEWNODE(n); BDY(n) = (pointer)r1;
925: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)r2;
926: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
927: }
928:
929: void Pdp_nf_tab_mod(NODE arg,DP *rp)
930: {
931: asir_assert(ARG0(arg),O_DP,"dp_nf_tab_mod");
932: asir_assert(ARG1(arg),O_VECT,"dp_nf_tab_mod");
933: asir_assert(ARG2(arg),O_N,"dp_nf_tab_mod");
934: dp_nf_tab_mod((DP)ARG0(arg),(LIST *)BDY((VECT)ARG1(arg)),
1.2 noro 935: ZTOS((Q)ARG2(arg)),rp);
1.1 noro 936: }
937:
938: void Pdp_nf_tab_f(NODE arg,DP *rp)
939: {
940: asir_assert(ARG0(arg),O_DP,"dp_nf_tab_f");
941: asir_assert(ARG1(arg),O_VECT,"dp_nf_tab_f");
942: dp_nf_tab_f((DP)ARG0(arg),(LIST *)BDY((VECT)ARG1(arg)),rp);
943: }
944:
1.9 noro 945: extern int dpm_ordtype;
946:
1.1 noro 947: void Pdp_ord(NODE arg,Obj *rp)
948: {
949: struct order_spec *spec;
950: LIST v;
951: struct oLIST f;
952: Num homo;
953: int modular;
954:
955: f.id = O_LIST; f.body = 0;
956: if ( !arg && !current_option )
957: *rp = dp_current_spec->obj;
958: else {
959: if ( current_option )
960: parse_gr_option(&f,current_option,&v,&homo,&modular,&spec);
961: else if ( !create_order_spec(0,(Obj)ARG0(arg),&spec) )
962: error("dp_ord : invalid order specification");
963: initd(spec); *rp = spec->obj;
1.15 noro 964: if ( spec->id >= 256 ) dpm_ordtype = spec->module_ordtype;
1.1 noro 965: }
966: }
967:
968: void Pdp_ptod(NODE arg,DP *rp)
969: {
970: P p;
971: NODE n;
972: VL vl,tvl;
973: struct oLIST f;
974: int ac;
975: LIST v;
976: Num homo;
977: int modular;
978: struct order_spec *ord;
979:
980: asir_assert(ARG0(arg),O_P,"dp_ptod");
981: p = (P)ARG0(arg);
982: ac = argc(arg);
983: if ( ac == 1 ) {
984: if ( current_option ) {
985: f.id = O_LIST; f.body = mknode(1,p);
986: parse_gr_option(&f,current_option,&v,&homo,&modular,&ord);
987: initd(ord);
988: } else
989: error("dp_ptod : invalid argument");
990: } else {
991: asir_assert(ARG1(arg),O_LIST,"dp_ptod");
992: v = (LIST)ARG1(arg);
993: }
994: for ( vl = 0, n = BDY(v); n; n = NEXT(n) ) {
995: if ( !vl ) {
996: NEWVL(vl); tvl = vl;
997: } else {
998: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
999: }
1000: VR(tvl) = VR((P)BDY(n));
1001: }
1002: if ( vl )
1003: NEXT(tvl) = 0;
1004: ptod(CO,vl,p,rp);
1005: }
1006:
1007: void Phomogenize(NODE arg,Obj *rp)
1008: {
1009: P p;
1010: DP d,h;
1011: NODE n;
1012: V hv;
1013: VL vl,tvl,last;
1014: struct oLIST f;
1015: LIST v;
1016:
1017: asir_assert(ARG0(arg),O_P,"homogenize");
1018: p = (P)ARG0(arg);
1019: asir_assert(ARG1(arg),O_LIST,"homogenize");
1020: v = (LIST)ARG1(arg);
1021: asir_assert(ARG2(arg),O_P,"homogenize");
1022: hv = VR((P)ARG2(arg));
1023: for ( vl = 0, n = BDY(v); n; n = NEXT(n) ) {
1024: if ( !vl ) {
1025: NEWVL(vl); tvl = vl;
1026: } else {
1027: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
1028: }
1029: VR(tvl) = VR((P)BDY(n));
1030: }
1031: if ( vl ) {
1032: last = tvl;
1033: NEXT(tvl) = 0;
1034: }
1035: ptod(CO,vl,p,&d);
1036: dp_homo(d,&h);
1037: NEWVL(NEXT(last)); last = NEXT(last);
1038: VR(last) = hv; NEXT(last) = 0;
1039: dtop(CO,vl,h,rp);
1040: }
1041:
1042: void Pdp_ltod(NODE arg,DPV *rp)
1043: {
1044: NODE n;
1045: VL vl,tvl;
1046: LIST f,v;
1047: int sugar,i,len,ac,modular;
1048: Num homo;
1049: struct order_spec *ord;
1050: DP *e;
1051: NODE nd,t;
1052:
1053: ac = argc(arg);
1054: asir_assert(ARG0(arg),O_LIST,"dp_ptod");
1055: f = (LIST)ARG0(arg);
1056: if ( ac == 1 ) {
1057: if ( current_option ) {
1058: parse_gr_option(f,current_option,&v,&homo,&modular,&ord);
1059: initd(ord);
1060: } else
1061: error("dp_ltod : invalid argument");
1062: } else {
1063: asir_assert(ARG1(arg),O_LIST,"dp_ptod");
1064: v = (LIST)ARG1(arg);
1065: }
1066: for ( vl = 0, n = BDY(v); n; n = NEXT(n) ) {
1067: if ( !vl ) {
1068: NEWVL(vl); tvl = vl;
1069: } else {
1070: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
1071: }
1072: VR(tvl) = VR((P)BDY(n));
1073: }
1074: if ( vl )
1075: NEXT(tvl) = 0;
1076:
1077: nd = BDY(f);
1078: len = length(nd);
1079: e = (DP *)MALLOC(len*sizeof(DP));
1080: sugar = 0;
1081: for ( i = 0, t = nd; i < len; i++, t = NEXT(t) ) {
1082: ptod(CO,vl,(P)BDY(t),&e[i]);
1083: if ( e[i] )
1084: sugar = MAX(sugar,e[i]->sugar);
1085: }
1086: MKDPV(len,e,*rp);
1087: }
1088:
1089: void Pdpm_ltod(NODE arg,DPM *rp)
1090: {
1091: NODE n;
1092: VL vl,tvl;
1093: LIST f,v;
1094: int i,len;
1095: NODE nd;
1096: NODE t;
1097: DP d;
1098: DPM s,u,w;
1099:
1100: f = (LIST)ARG0(arg);
1101: v = (LIST)ARG1(arg);
1102: for ( vl = 0, n = BDY(v); n; n = NEXT(n) ) {
1103: if ( !vl ) {
1104: NEWVL(vl); tvl = vl;
1105: } else {
1106: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
1107: }
1108: VR(tvl) = VR((P)BDY(n));
1109: }
1110: if ( vl )
1111: NEXT(tvl) = 0;
1112:
1113: nd = BDY(f);
1114: len = length(nd);
1.9 noro 1115: for ( i = 1, t = nd, s = 0; i <= len; i++, t = NEXT(t) ) {
1.1 noro 1116: ptod(CO,vl,(P)BDY(t),&d);
1117: dtodpm(d,i,&u);
1118: adddpm(CO,s,u,&w); s = w;
1119: }
1120: *rp = s;
1121: }
1122:
1.9 noro 1123: // c*[monomial,i]+... -> c*<<monomial:i>>+...
1124:
1125: void Pdpm_dptodpm(NODE arg,DPM *rp)
1126: {
1127: DP p;
1128: MP mp;
1.16 noro 1129: int pos,shift;
1.9 noro 1130: DMM m0,m;
1131:
1132: p = (DP)ARG0(arg);
1133: pos = ZTOS((Z)ARG1(arg));
1134: if ( pos <= 0 )
1135: error("dpm_mtod : position must be positive");
1136: if ( !p ) *rp = 0;
1137: else {
1138: for ( m0 = 0, mp = BDY(p); mp; mp = NEXT(mp) ) {
1139: NEXTDMM(m0,m); m->dl = mp->dl; m->c = mp->c; m->pos = pos;
1140: }
1.21 noro 1141: if ( dp_current_spec->module_top_weight ) {
1.16 noro 1142: if ( pos > dp_current_spec->module_rank )
1143: error("dpm_dptodpm : inconsistent order spec");
1144: shift = dp_current_spec->module_top_weight[pos-1];
1145: m->dl->td += shift;
1146: } else
1147: shift = 0;
1148:
1149: MKDPM(p->nv,m0,*rp); (*rp)->sugar = p->sugar+shift;
1.9 noro 1150: }
1151: }
1152:
1.1 noro 1153: void Pdpm_dtol(NODE arg,LIST *rp)
1154: {
1155: DPM a;
1156: NODE nd,nd1;
1157: VL vl,tvl;
1158: int n,len,i,pos,nv;
1159: MP *w;
1160: DMM t;
1161: DMM *wa;
1162: MP m;
1163: DP u;
1164: Obj s;
1165:
1166: a = (DPM)ARG0(arg);
1.14 noro 1167: if ( !a ) {
1168: MKLIST(*rp,0);
1169: return;
1170: }
1.1 noro 1171: for ( vl = 0, nd = BDY((LIST)ARG1(arg)), nv = 0; nd; nd = NEXT(nd), nv++ ) {
1172: if ( !vl ) {
1173: NEWVL(vl); tvl = vl;
1174: } else {
1175: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
1176: }
1177: VR(tvl) = VR((P)BDY(nd));
1178: }
1179: if ( vl )
1180: NEXT(tvl) = 0;
1.14 noro 1181: for ( t = BDY(a), n = 0; t; t = NEXT(t) )
1182: if ( t->pos > n ) n = t->pos;
1.1 noro 1183: w = (MP *)CALLOC(n,sizeof(MP));
1184: for ( t = BDY(a), len = 0; t; t = NEXT(t) ) len++;
1185: wa = (DMM *)MALLOC(len*sizeof(DMM));
1186: for ( t = BDY(a), i = 0; t; t = NEXT(t), i++ ) wa[i] = t;
1187: for ( i = len-1; i >= 0; i-- ) {
1188: NEWMP(m); m->dl = wa[i]->dl; C(m) = C(wa[i]);
1189: pos = wa[i]->pos;
1.14 noro 1190: NEXT(m) = w[pos-1];
1191: w[pos-1] = m;
1.1 noro 1192: }
1193: nd = 0;
1194: for ( i = n-1; i >= 0; i-- ) {
1195: MKDP(nv,w[i],u); u->sugar = a->sugar; /* XXX */
1196: dtop(CO,vl,u,&s);
1197: MKNODE(nd1,s,nd); nd = nd1;
1198: }
1199: MKLIST(*rp,nd);
1200: }
1201:
1202: void Pdp_dtop(NODE arg,Obj *rp)
1203: {
1204: NODE n;
1205: VL vl,tvl;
1206:
1207: asir_assert(ARG0(arg),O_DP,"dp_dtop");
1208: asir_assert(ARG1(arg),O_LIST,"dp_dtop");
1209: for ( vl = 0, n = BDY((LIST)ARG1(arg)); n; n = NEXT(n) ) {
1210: if ( !vl ) {
1211: NEWVL(vl); tvl = vl;
1212: } else {
1213: NEWVL(NEXT(tvl)); tvl = NEXT(tvl);
1214: }
1215: VR(tvl) = VR((P)BDY(n));
1216: }
1217: if ( vl )
1218: NEXT(tvl) = 0;
1219: dtop(CO,vl,(DP)ARG0(arg),rp);
1220: }
1221:
1222: extern LIST Dist;
1223:
1224: void Pdp_ptozp(NODE arg,Obj *rp)
1225: {
1226: Z t;
1227: NODE tt,p;
1228: NODE n,n0;
1229: char *key;
1230: DP pp;
1231: LIST list;
1232: int get_factor=0;
1233:
1234: asir_assert(ARG0(arg),O_DP,"dp_ptozp");
1235:
1236: /* analyze the option */
1237: if ( current_option ) {
1238: for ( tt = current_option; tt; tt = NEXT(tt) ) {
1239: p = BDY((LIST)BDY(tt));
1240: key = BDY((STRING)BDY(p));
1241: /* value = (Obj)BDY(NEXT(p)); */
1242: if ( !strcmp(key,"factor") ) get_factor=1;
1243: else {
1244: error("ptozp: unknown option.");
1245: }
1246: }
1247: }
1248:
1249: dp_ptozp3((DP)ARG0(arg),&t,&pp);
1250:
1251: /* printexpr(NULL,t); */
1252: /* if the option factor is given, then it returns the answer
1253: in the format [zpoly, num] where num*zpoly is equal to the argument.*/
1254: if (get_factor) {
1255: n0 = mknode(2,pp,t);
1256: MKLIST(list,n0);
1257: *rp = (Obj)list;
1258: } else
1259: *rp = (Obj)pp;
1260: }
1261:
1262: void Pdp_ptozp2(NODE arg,LIST *rp)
1263: {
1264: DP p0,p1,h,r;
1265: NODE n0;
1266:
1267: p0 = (DP)ARG0(arg); p1 = (DP)ARG1(arg);
1268: asir_assert(p0,O_DP,"dp_ptozp2");
1269: asir_assert(p1,O_DP,"dp_ptozp2");
1270: dp_ptozp2(p0,p1,&h,&r);
1271: NEWNODE(n0); BDY(n0) = (pointer)h;
1272: NEWNODE(NEXT(n0)); BDY(NEXT(n0)) = (pointer)r;
1273: NEXT(NEXT(n0)) = 0;
1274: MKLIST(*rp,n0);
1275: }
1276:
1277: void Pdp_prim(NODE arg,DP *rp)
1278: {
1279: DP t;
1280:
1281: asir_assert(ARG0(arg),O_DP,"dp_prim");
1282: dp_prim((DP)ARG0(arg),&t); dp_ptozp(t,rp);
1283: }
1284:
1285: void Pdp_mod(NODE arg,DP *rp)
1286: {
1287: DP p;
1288: int mod;
1289: NODE subst;
1290:
1291: asir_assert(ARG0(arg),O_DP,"dp_mod");
1292: asir_assert(ARG1(arg),O_N,"dp_mod");
1293: asir_assert(ARG2(arg),O_LIST,"dp_mod");
1.2 noro 1294: p = (DP)ARG0(arg); mod = ZTOS((Q)ARG1(arg));
1.1 noro 1295: subst = BDY((LIST)ARG2(arg));
1296: dp_mod(p,mod,subst,rp);
1297: }
1298:
1.26 ! noro 1299: void dpm_mod(DPM,int,DPM *);
! 1300:
! 1301: void Pdpm_mod(NODE arg,DPM *rp)
! 1302: {
! 1303: DPM p;
! 1304: int mod;
! 1305: NODE subst;
! 1306:
! 1307: asir_assert(ARG0(arg),O_DP,"dp_mod");
! 1308: asir_assert(ARG1(arg),O_N,"dp_mod");
! 1309: p = (DPM)ARG0(arg); mod = ZTOS((Q)ARG1(arg));
! 1310: dpm_mod(p,mod,rp);
! 1311: }
! 1312:
! 1313:
1.1 noro 1314: void Pdp_rat(NODE arg,DP *rp)
1315: {
1316: asir_assert(ARG0(arg),O_DP,"dp_rat");
1317: dp_rat((DP)ARG0(arg),rp);
1318: }
1319:
1320: extern int DP_Multiple;
1321:
1322: void Pdp_nf(NODE arg,DP *rp)
1323: {
1324: NODE b;
1325: DP *ps;
1326: DP g;
1327: int full;
1328:
1329: do_weyl = 0; dp_fcoeffs = 0;
1330: asir_assert(ARG0(arg),O_LIST,"dp_nf");
1331: asir_assert(ARG1(arg),O_DP,"dp_nf");
1332: asir_assert(ARG2(arg),O_VECT,"dp_nf");
1333: asir_assert(ARG3(arg),O_N,"dp_nf");
1334: if ( !(g = (DP)ARG1(arg)) ) {
1335: *rp = 0; return;
1336: }
1337: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1338: full = (Q)ARG3(arg) ? 1 : 0;
1339: dp_nf_z(b,g,ps,full,DP_Multiple,rp);
1340: }
1341:
1342: void Pdp_weyl_nf(NODE arg,DP *rp)
1343: {
1344: NODE b;
1345: DP *ps;
1346: DP g;
1347: int full;
1348:
1349: asir_assert(ARG0(arg),O_LIST,"dp_weyl_nf");
1350: asir_assert(ARG1(arg),O_DP,"dp_weyl_nf");
1351: asir_assert(ARG2(arg),O_VECT,"dp_weyl_nf");
1352: asir_assert(ARG3(arg),O_N,"dp_weyl_nf");
1353: if ( !(g = (DP)ARG1(arg)) ) {
1354: *rp = 0; return;
1355: }
1356: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1357: full = (Q)ARG3(arg) ? 1 : 0;
1358: do_weyl = 1;
1359: dp_nf_z(b,g,ps,full,DP_Multiple,rp);
1360: do_weyl = 0;
1361: }
1362:
1363: void Pdpm_nf(NODE arg,DPM *rp)
1364: {
1365: NODE b;
1.11 noro 1366: VECT ps;
1.1 noro 1367: DPM g;
1.11 noro 1368: int ac,full;
1.1 noro 1369:
1370: if ( !(g = (DPM)ARG1(arg)) ) {
1371: *rp = 0; return;
1372: }
1373: do_weyl = 0; dp_fcoeffs = 0;
1.11 noro 1374: ac = argc(arg);
1375: if ( ac < 3 )
1376: error("dpm_nf: invalid arguments");
1377: else if ( ac == 3 ) {
1378: asir_assert(ARG1(arg),O_VECT,"dpm_nf");
1379: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1380: } else if ( ac == 4 ) {
1381: asir_assert(ARG0(arg),O_LIST,"dpm_nf");
1382: asir_assert(ARG2(arg),O_VECT,"dpm_nf");
1383: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1384: full = (Q)ARG3(arg) ? 1 : 0;
1385: }
1.1 noro 1386: dpm_nf_z(b,g,ps,full,DP_Multiple,rp);
1387: }
1388:
1.9 noro 1389: DP *dpm_nf_and_quotient(NODE b,DPM g,VECT ps,DPM *rp,P *dnp);
1.17 noro 1390: DPM dpm_nf_and_quotient2(NODE b,DPM g,VECT ps,DPM *rp,P *dnp);
1.9 noro 1391:
1392: void Pdpm_nf_and_quotient(NODE arg,LIST *rp)
1393: {
1394: NODE b;
1395: VECT ps;
1396: DPM g,nm;
1397: P dn;
1398: VECT quo;
1399: NODE n;
1400: int ac;
1401:
1402: do_weyl = 0; dp_fcoeffs = 0;
1403: ac = argc(arg);
1404: if ( ac < 2 )
1405: error("dpm_nf_and_quotient : invalid arguments");
1406: else if ( ac == 2 ) {
1.11 noro 1407: asir_assert(ARG1(arg),O_VECT,"dpm_nf_and_quotient");
1.9 noro 1408: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1409: } else if ( ac == 3 ) {
1.11 noro 1410: asir_assert(ARG0(arg),O_LIST,"dpm_nf_and_quotient");
1411: asir_assert(ARG2(arg),O_VECT,"dpm_nf_and_quotient");
1.9 noro 1412: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1413: }
1.10 noro 1414: NEWVECT(quo); quo->len = ps->len;
1415: if ( g ) {
1416: quo->body = (pointer *)dpm_nf_and_quotient(b,g,ps,&nm,&dn);
1417: } else {
1418: quo->body = (pointer *)MALLOC(quo->len*sizeof(pointer));
1419: nm = 0; dn = (P)ONE;
1.9 noro 1420: }
1421: n = mknode(3,nm,dn,quo);
1422: MKLIST(*rp,n);
1423: }
1424:
1.17 noro 1425: void Pdpm_nf_and_quotient2(NODE arg,LIST *rp)
1426: {
1427: NODE b;
1428: VECT ps;
1429: DPM g,nm,q;
1430: P dn;
1431: NODE n;
1432: int ac;
1433:
1434: do_weyl = 0; dp_fcoeffs = 0;
1435: ac = argc(arg);
1436: if ( ac < 2 )
1437: error("dpm_nf_and_quotient2 : invalid arguments");
1438: else if ( ac == 2 ) {
1439: asir_assert(ARG1(arg),O_VECT,"dpm_nf_and_quotient2");
1440: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1441: } else if ( ac == 3 ) {
1442: asir_assert(ARG0(arg),O_LIST,"dpm_nf_and_quotient2");
1443: asir_assert(ARG2(arg),O_VECT,"dpm_nf_and_quotient2");
1444: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1445: }
1446: if ( g ) {
1447: q = dpm_nf_and_quotient2(b,g,ps,&nm,&dn);
1448: } else {
1449: q = 0; nm = 0; dn = (P)ONE;
1450: }
1451: n = mknode(3,nm,dn,q);
1452: MKLIST(*rp,n);
1453: }
1454:
1.1 noro 1455: void Pdpm_weyl_nf(NODE arg,DPM *rp)
1456: {
1457: NODE b;
1.11 noro 1458: VECT ps;
1.1 noro 1459: DPM g;
1.11 noro 1460: int ac,full;
1.1 noro 1461:
1462: if ( !(g = (DPM)ARG1(arg)) ) {
1463: *rp = 0; return;
1464: }
1.11 noro 1465: do_weyl = 1; dp_fcoeffs = 0;
1466: ac = argc(arg);
1467: if ( ac < 3 )
1468: error("dpm_weyl_nf: invalid arguments");
1469: else if ( ac == 3 ) {
1470: asir_assert(ARG1(arg),O_VECT,"dpm_nf");
1471: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1472: } else if ( ac == 4 ) {
1473: asir_assert(ARG0(arg),O_LIST,"dpm_weyl_nf");
1474: asir_assert(ARG2(arg),O_VECT,"dpm_weyl_nf");
1475: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1476: full = (Q)ARG3(arg) ? 1 : 0;
1477: }
1.1 noro 1478: dpm_nf_z(b,g,ps,full,DP_Multiple,rp);
1479: do_weyl = 0;
1480: }
1481:
1482: /* nf computation using field operations */
1483:
1484: void Pdp_nf_f(NODE arg,DP *rp)
1485: {
1486: NODE b;
1487: DP *ps;
1488: DP g;
1489: int full;
1490:
1491: do_weyl = 0;
1492: asir_assert(ARG0(arg),O_LIST,"dp_nf_f");
1493: asir_assert(ARG1(arg),O_DP,"dp_nf_f");
1494: asir_assert(ARG2(arg),O_VECT,"dp_nf_f");
1495: asir_assert(ARG3(arg),O_N,"dp_nf_f");
1496: if ( !(g = (DP)ARG1(arg)) ) {
1497: *rp = 0; return;
1498: }
1499: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1500: full = (Q)ARG3(arg) ? 1 : 0;
1501: dp_nf_f(b,g,ps,full,rp);
1502: }
1503:
1504: void Pdp_weyl_nf_f(NODE arg,DP *rp)
1505: {
1506: NODE b;
1507: DP *ps;
1508: DP g;
1509: int full;
1510:
1511: asir_assert(ARG0(arg),O_LIST,"dp_weyl_nf_f");
1512: asir_assert(ARG1(arg),O_DP,"dp_weyl_nf_f");
1513: asir_assert(ARG2(arg),O_VECT,"dp_weyl_nf_f");
1514: asir_assert(ARG3(arg),O_N,"dp_weyl_nf_f");
1515: if ( !(g = (DP)ARG1(arg)) ) {
1516: *rp = 0; return;
1517: }
1518: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1519: full = (Q)ARG3(arg) ? 1 : 0;
1520: do_weyl = 1;
1521: dp_nf_f(b,g,ps,full,rp);
1522: do_weyl = 0;
1523: }
1524:
1525: void Pdpm_nf_f(NODE arg,DPM *rp)
1526: {
1527: NODE b;
1.11 noro 1528: VECT ps;
1.1 noro 1529: DPM g;
1.11 noro 1530: int ac,full;
1.1 noro 1531:
1532: if ( !(g = (DPM)ARG1(arg)) ) {
1533: *rp = 0; return;
1534: }
1.11 noro 1535: ac = argc(arg);
1536: if ( ac < 3 )
1537: error("dpm_nf_f: invalid arguments");
1538: else if ( ac == 3 ) {
1539: asir_assert(ARG1(arg),O_VECT,"dpm_nf_f");
1540: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1541: } else if ( ac == 4 ) {
1542: asir_assert(ARG0(arg),O_LIST,"dpm_nf_f");
1543: asir_assert(ARG2(arg),O_VECT,"dpm_nf_f");
1544: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1545: full = (Q)ARG3(arg) ? 1 : 0;
1546: }
1547: do_weyl = 0;
1.1 noro 1548: dpm_nf_f(b,g,ps,full,rp);
1549: }
1550:
1551: void Pdpm_weyl_nf_f(NODE arg,DPM *rp)
1552: {
1553: NODE b;
1.11 noro 1554: VECT ps;
1.1 noro 1555: DPM g;
1.11 noro 1556: int ac,full;
1.1 noro 1557:
1558: if ( !(g = (DPM)ARG1(arg)) ) {
1559: *rp = 0; return;
1560: }
1.11 noro 1561: ac = argc(arg);
1562: if ( ac < 3 )
1563: error("dpm_weyl_nf_f: invalid arguments");
1564: else if ( ac == 3 ) {
1565: asir_assert(ARG1(arg),O_VECT,"dpm_weyl_nf_f");
1566: b = 0; g = (DPM)ARG0(arg); ps = (VECT)ARG1(arg);
1567: } else if ( ac == 4 ) {
1568: asir_assert(ARG0(arg),O_LIST,"dpm_weyl_nf_f");
1569: asir_assert(ARG2(arg),O_VECT,"dpm_weyl_nf_f");
1570: b = BDY((LIST)ARG0(arg)); g = (DPM)ARG1(arg); ps = (VECT)ARG2(arg);
1571: full = (Q)ARG3(arg) ? 1 : 0;
1572: }
1.1 noro 1573: do_weyl = 1;
1574: dpm_nf_f(b,g,ps,full,rp);
1575: do_weyl = 0;
1576: }
1577:
1578:
1579: void Pdp_nf_mod(NODE arg,DP *rp)
1580: {
1581: NODE b;
1582: DP g;
1583: DP *ps;
1584: int mod,full,ac;
1585: NODE n,n0;
1586:
1587: do_weyl = 0;
1588: ac = argc(arg);
1589: asir_assert(ARG0(arg),O_LIST,"dp_nf_mod");
1590: asir_assert(ARG1(arg),O_DP,"dp_nf_mod");
1591: asir_assert(ARG2(arg),O_VECT,"dp_nf_mod");
1592: asir_assert(ARG3(arg),O_N,"dp_nf_mod");
1593: asir_assert(ARG4(arg),O_N,"dp_nf_mod");
1594: if ( !(g = (DP)ARG1(arg)) ) {
1595: *rp = 0; return;
1596: }
1597: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1.2 noro 1598: full = ZTOS((Q)ARG3(arg)); mod = ZTOS((Q)ARG4(arg));
1.1 noro 1599: for ( n0 = n = 0; b; b = NEXT(b) ) {
1600: NEXTNODE(n0,n);
1.2 noro 1601: BDY(n) = (pointer)ZTOS((Q)BDY(b));
1.1 noro 1602: }
1603: if ( n0 )
1604: NEXT(n) = 0;
1605: dp_nf_mod(n0,g,ps,mod,full,rp);
1606: }
1607:
1608: void Pdp_true_nf(NODE arg,LIST *rp)
1609: {
1610: NODE b,n;
1611: DP *ps;
1612: DP g;
1613: DP nm;
1614: P dn;
1615: int full;
1616:
1617: do_weyl = 0; dp_fcoeffs = 0;
1618: asir_assert(ARG0(arg),O_LIST,"dp_true_nf");
1619: asir_assert(ARG1(arg),O_DP,"dp_true_nf");
1620: asir_assert(ARG2(arg),O_VECT,"dp_true_nf");
1621: asir_assert(ARG3(arg),O_N,"dp_nf");
1622: if ( !(g = (DP)ARG1(arg)) ) {
1623: nm = 0; dn = (P)ONE;
1624: } else {
1625: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1626: full = (Q)ARG3(arg) ? 1 : 0;
1627: dp_true_nf(b,g,ps,full,&nm,&dn);
1628: }
1629: NEWNODE(n); BDY(n) = (pointer)nm;
1630: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)dn;
1631: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
1632: }
1633:
1634: DP *dp_true_nf_and_quotient_marked(NODE b,DP g,DP *ps,DP *hps,DP *rp,P *dnp);
1635:
1636: void Pdp_true_nf_and_quotient_marked(NODE arg,LIST *rp)
1637: {
1638: NODE b,n;
1639: DP *ps,*hps;
1640: DP g;
1641: DP nm;
1642: VECT quo;
1643: P dn;
1644: int full;
1645:
1646: do_weyl = 0; dp_fcoeffs = 0;
1647: asir_assert(ARG0(arg),O_LIST,"dp_true_nf_and_quotient_marked");
1648: asir_assert(ARG1(arg),O_DP,"dp_true_nf_and_quotient_marked");
1649: asir_assert(ARG2(arg),O_VECT,"dp_true_nf_and_quotient_marked");
1650: asir_assert(ARG3(arg),O_VECT,"dp_true_nf_and_quotient_marked");
1651: if ( !(g = (DP)ARG1(arg)) ) {
1652: nm = 0; dn = (P)ONE;
1653: } else {
1654: b = BDY((LIST)ARG0(arg));
1655: ps = (DP *)BDY((VECT)ARG2(arg));
1656: hps = (DP *)BDY((VECT)ARG3(arg));
1657: NEWVECT(quo); quo->len = ((VECT)ARG2(arg))->len;
1658: quo->body = (pointer *)dp_true_nf_and_quotient_marked(b,g,ps,hps,&nm,&dn);
1659: }
1660: n = mknode(3,nm,dn,quo);
1661: MKLIST(*rp,n);
1662: }
1663:
1664: void Pdp_true_nf_and_quotient(NODE arg,LIST *rp)
1665: {
1666: NODE narg = mknode(4,ARG0(arg),ARG1(arg),ARG2(arg),ARG2(arg));
1667: Pdp_true_nf_and_quotient_marked(narg,rp);
1668: }
1669:
1670:
1671: DP *dp_true_nf_and_quotient_marked_mod (NODE b,DP g,DP *ps,DP *hps,int mod,DP *rp,P *dnp);
1672:
1673: void Pdp_true_nf_and_quotient_marked_mod(NODE arg,LIST *rp)
1674: {
1675: NODE b,n;
1676: DP *ps,*hps;
1677: DP g;
1678: DP nm;
1679: VECT quo;
1680: P dn;
1681: int full,mod;
1682:
1683: do_weyl = 0; dp_fcoeffs = 0;
1684: asir_assert(ARG0(arg),O_LIST,"dp_true_nf_and_quotient_marked_mod");
1685: asir_assert(ARG1(arg),O_DP,"dp_true_nf_and_quotient_marked_mod");
1686: asir_assert(ARG2(arg),O_VECT,"dp_true_nf_and_quotient_marked_mod");
1687: asir_assert(ARG3(arg),O_VECT,"dp_true_nf_and_quotient_marked_mod");
1688: asir_assert(ARG4(arg),O_N,"dp_true_nf_and_quotient_marked_mod");
1689: if ( !(g = (DP)ARG1(arg)) ) {
1690: nm = 0; dn = (P)ONE;
1691: } else {
1692: b = BDY((LIST)ARG0(arg));
1693: ps = (DP *)BDY((VECT)ARG2(arg));
1694: hps = (DP *)BDY((VECT)ARG3(arg));
1.2 noro 1695: mod = ZTOS((Q)ARG4(arg));
1.1 noro 1696: NEWVECT(quo); quo->len = ((VECT)ARG2(arg))->len;
1697: quo->body = (pointer *)dp_true_nf_and_quotient_marked_mod(b,g,ps,hps,mod,&nm,&dn);
1698: }
1699: n = mknode(3,nm,dn,quo);
1700: MKLIST(*rp,n);
1701: }
1702:
1703: void Pdp_true_nf_and_quotient_mod(NODE arg,LIST *rp)
1704: {
1705: NODE narg = mknode(5,ARG0(arg),ARG1(arg),ARG2(arg),ARG2(arg),ARG3(arg));
1706: Pdp_true_nf_and_quotient_marked_mod(narg,rp);
1707: }
1708:
1709: void Pdp_true_nf_marked(NODE arg,LIST *rp)
1710: {
1711: NODE b,n;
1712: DP *ps,*hps;
1713: DP g;
1714: DP nm;
1715: Q cont;
1716: P dn;
1717: int full;
1718:
1719: do_weyl = 0; dp_fcoeffs = 0;
1720: asir_assert(ARG0(arg),O_LIST,"dp_true_nf_marked");
1721: asir_assert(ARG1(arg),O_DP,"dp_true_nf_marked");
1722: asir_assert(ARG2(arg),O_VECT,"dp_true_nf_marked");
1723: asir_assert(ARG3(arg),O_VECT,"dp_true_nf_marked");
1724: if ( !(g = (DP)ARG1(arg)) ) {
1725: nm = 0; dn = (P)ONE;
1726: } else {
1727: b = BDY((LIST)ARG0(arg));
1728: ps = (DP *)BDY((VECT)ARG2(arg));
1729: hps = (DP *)BDY((VECT)ARG3(arg));
1730: dp_true_nf_marked(b,g,ps,hps,&nm,(P *)&cont,(P *)&dn);
1731: }
1732: n = mknode(3,nm,cont,dn);
1733: MKLIST(*rp,n);
1734: }
1735:
1736: void Pdp_true_nf_marked_mod(NODE arg,LIST *rp)
1737: {
1738: NODE b,n;
1739: DP *ps,*hps;
1740: DP g;
1741: DP nm;
1742: P dn;
1743: int mod;
1744:
1745: do_weyl = 0; dp_fcoeffs = 0;
1746: asir_assert(ARG0(arg),O_LIST,"dp_true_nf_marked_mod");
1747: asir_assert(ARG1(arg),O_DP,"dp_true_nf_marked_mod");
1748: asir_assert(ARG2(arg),O_VECT,"dp_true_nf_marked_mod");
1749: asir_assert(ARG3(arg),O_VECT,"dp_true_nf_marked_mod");
1750: asir_assert(ARG4(arg),O_N,"dp_true_nf_marked_mod");
1751: if ( !(g = (DP)ARG1(arg)) ) {
1752: nm = 0; dn = (P)ONE;
1753: } else {
1754: b = BDY((LIST)ARG0(arg));
1755: ps = (DP *)BDY((VECT)ARG2(arg));
1756: hps = (DP *)BDY((VECT)ARG3(arg));
1.2 noro 1757: mod = ZTOS((Q)ARG4(arg));
1.1 noro 1758: dp_true_nf_marked_mod(b,g,ps,hps,mod,&nm,&dn);
1759: }
1760: n = mknode(2,nm,dn);
1761: MKLIST(*rp,n);
1762: }
1763:
1764: void Pdp_weyl_nf_mod(NODE arg,DP *rp)
1765: {
1766: NODE b;
1767: DP g;
1768: DP *ps;
1769: int mod,full,ac;
1770: NODE n,n0;
1771:
1772: ac = argc(arg);
1773: asir_assert(ARG0(arg),O_LIST,"dp_weyl_nf_mod");
1774: asir_assert(ARG1(arg),O_DP,"dp_weyl_nf_mod");
1775: asir_assert(ARG2(arg),O_VECT,"dp_weyl_nf_mod");
1776: asir_assert(ARG3(arg),O_N,"dp_weyl_nf_mod");
1777: asir_assert(ARG4(arg),O_N,"dp_weyl_nf_mod");
1778: if ( !(g = (DP)ARG1(arg)) ) {
1779: *rp = 0; return;
1780: }
1781: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1.2 noro 1782: full = ZTOS((Q)ARG3(arg)); mod = ZTOS((Q)ARG4(arg));
1.1 noro 1783: for ( n0 = n = 0; b; b = NEXT(b) ) {
1784: NEXTNODE(n0,n);
1.2 noro 1785: BDY(n) = (pointer)ZTOS((Q)BDY(b));
1.1 noro 1786: }
1787: if ( n0 )
1788: NEXT(n) = 0;
1789: do_weyl = 1;
1790: dp_nf_mod(n0,g,ps,mod,full,rp);
1791: do_weyl = 0;
1792: }
1793:
1794: void Pdp_true_nf_mod(NODE arg,LIST *rp)
1795: {
1796: NODE b;
1797: DP g,nm;
1798: P dn;
1799: DP *ps;
1800: int mod,full;
1801: NODE n;
1802:
1803: do_weyl = 0;
1804: asir_assert(ARG0(arg),O_LIST,"dp_nf_mod");
1805: asir_assert(ARG1(arg),O_DP,"dp_nf_mod");
1806: asir_assert(ARG2(arg),O_VECT,"dp_nf_mod");
1807: asir_assert(ARG3(arg),O_N,"dp_nf_mod");
1808: asir_assert(ARG4(arg),O_N,"dp_nf_mod");
1809: if ( !(g = (DP)ARG1(arg)) ) {
1810: nm = 0; dn = (P)ONEM;
1811: } else {
1812: b = BDY((LIST)ARG0(arg)); ps = (DP *)BDY((VECT)ARG2(arg));
1.2 noro 1813: full = ZTOS((Q)ARG3(arg)); mod = ZTOS((Q)ARG4(arg));
1.1 noro 1814: dp_true_nf_mod(b,g,ps,mod,full,&nm,&dn);
1815: }
1816: NEWNODE(n); BDY(n) = (pointer)nm;
1817: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)dn;
1818: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
1819: }
1820:
1821: void Pdp_weyl_true_nf_and_quotient_marked(NODE arg,LIST *rp)
1822: {
1823: NODE b,n;
1824: DP *ps,*hps;
1825: DP g;
1826: DP nm;
1827: VECT quo;
1828: P dn;
1829: int full;
1830:
1831: do_weyl = 1; dp_fcoeffs = 0;
1832: asir_assert(ARG0(arg),O_LIST,"dp_weyl_true_nf_and_quotient_marked");
1833: asir_assert(ARG1(arg),O_DP,"dp_weyl_true_nf_and_quotient_marked");
1834: asir_assert(ARG2(arg),O_VECT,"dp_weyl_true_nf_and_quotient_marked");
1835: asir_assert(ARG3(arg),O_VECT,"dp_weyl_true_nf_and_quotient_marked");
1836: if ( !(g = (DP)ARG1(arg)) ) {
1837: nm = 0; dn = (P)ONE;
1838: } else {
1839: b = BDY((LIST)ARG0(arg));
1840: ps = (DP *)BDY((VECT)ARG2(arg));
1841: hps = (DP *)BDY((VECT)ARG3(arg));
1842: NEWVECT(quo); quo->len = ((VECT)ARG2(arg))->len;
1843: quo->body = (pointer *)dp_true_nf_and_quotient_marked(b,g,ps,hps,&nm,&dn);
1844: }
1845: n = mknode(3,nm,dn,quo);
1846: MKLIST(*rp,n);
1847: }
1848:
1849: void Pdp_weyl_true_nf_and_quotient(NODE arg,LIST *rp)
1850: {
1851: NODE narg = mknode(4,ARG0(arg),ARG1(arg),ARG2(arg),ARG2(arg));
1852: Pdp_weyl_true_nf_and_quotient_marked(narg,rp);
1853: }
1854:
1855:
1856: void Pdp_weyl_true_nf_and_quotient_marked_mod(NODE arg,LIST *rp)
1857: {
1858: NODE b,n;
1859: DP *ps,*hps;
1860: DP g;
1861: DP nm;
1862: VECT quo;
1863: P dn;
1864: int full,mod;
1865:
1866: do_weyl = 1; dp_fcoeffs = 0;
1867: asir_assert(ARG0(arg),O_LIST,"dp_weyl_true_nf_and_quotient_marked_mod");
1868: asir_assert(ARG1(arg),O_DP,"dp_weyl_true_nf_and_quotient_marked_mod");
1869: asir_assert(ARG2(arg),O_VECT,"dp_weyl_true_nf_and_quotient_marked_mod");
1870: asir_assert(ARG3(arg),O_VECT,"dp_weyl_true_nf_and_quotient_marked_mod");
1871: asir_assert(ARG4(arg),O_N,"dp_weyl_true_nf_and_quotient_marked_mod");
1872: if ( !(g = (DP)ARG1(arg)) ) {
1873: nm = 0; dn = (P)ONE;
1874: } else {
1875: b = BDY((LIST)ARG0(arg));
1876: ps = (DP *)BDY((VECT)ARG2(arg));
1877: hps = (DP *)BDY((VECT)ARG3(arg));
1.2 noro 1878: mod = ZTOS((Q)ARG4(arg));
1.1 noro 1879: NEWVECT(quo); quo->len = ((VECT)ARG2(arg))->len;
1880: quo->body = (pointer *)dp_true_nf_and_quotient_marked_mod(b,g,ps,hps,mod,&nm,&dn);
1881: }
1882: n = mknode(3,nm,dn,quo);
1883: MKLIST(*rp,n);
1884: }
1885:
1886: void Pdp_weyl_true_nf_and_quotient_mod(NODE arg,LIST *rp)
1887: {
1888: NODE narg = mknode(5,ARG0(arg),ARG1(arg),ARG2(arg),ARG2(arg),ARG3(arg));
1889: Pdp_weyl_true_nf_and_quotient_marked_mod(narg,rp);
1890: }
1891:
1892:
1893: void Pdp_tdiv(NODE arg,DP *rp)
1894: {
1895: MP m,mr,mr0;
1896: DP p;
1897: Z d,q,r;
1898: int sgn;
1899:
1900: asir_assert(ARG0(arg),O_DP,"dp_tdiv");
1901: asir_assert(ARG1(arg),O_N,"dp_tdiv");
1902: p = (DP)ARG0(arg); d = (Z)ARG1(arg);
1903: if ( !p )
1904: *rp = 0;
1905: else {
1906: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
1907: divqrz((Z)m->c,d,&q,&r);
1908: if ( r ) {
1909: *rp = 0; return;
1910: } else {
1911: NEXTMP(mr0,mr);
1912: mr->c = (Obj)q; mr->dl = m->dl;
1913: }
1914: }
1915: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar;
1916: }
1917: }
1918:
1919: void Pdp_red_coef(NODE arg,DP *rp)
1920: {
1921: MP m,mr,mr0;
1922: P q,r;
1923: DP p;
1924: P mod;
1925:
1926: p = (DP)ARG0(arg); mod = (P)ARG1(arg);
1927: asir_assert(p,O_DP,"dp_red_coef");
1928: asir_assert(mod,O_P,"dp_red_coef");
1929: if ( !p )
1930: *rp = 0;
1931: else {
1932: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
1933: divsrp(CO,(P)m->c,mod,&q,&r);
1934: if ( r ) {
1935: NEXTMP(mr0,mr); mr->c = (Obj)r; mr->dl = m->dl;
1936: }
1937: }
1938: if ( mr0 ) {
1939: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar;
1940: } else
1941: *rp = 0;
1942: }
1943: }
1944:
1945: void Pdp_redble(NODE arg,Z *rp)
1946: {
1947: asir_assert(ARG0(arg),O_DP,"dp_redble");
1948: asir_assert(ARG1(arg),O_DP,"dp_redble");
1949: if ( dp_redble((DP)ARG0(arg),(DP)ARG1(arg)) )
1950: *rp = ONE;
1951: else
1952: *rp = 0;
1953: }
1954:
1.9 noro 1955: void Pdpm_redble(NODE arg,Z *rp)
1956: {
1957: asir_assert(ARG0(arg),O_DPM,"dpm_redble");
1958: asir_assert(ARG1(arg),O_DPM,"dpm_redble");
1959: if ( dpm_redble((DPM)ARG0(arg),(DPM)ARG1(arg)) )
1960: *rp = ONE;
1961: else
1962: *rp = 0;
1963: }
1964:
1.11 noro 1965: void dpm_schreyer_base(LIST g,LIST *s);
1.19 noro 1966: void dpm_schreyer_base_zlist(LIST g,LIST *s);
1.11 noro 1967:
1968: void Pdpm_schreyer_base(NODE arg,LIST *rp)
1969: {
1970: asir_assert(ARG0(arg),O_LIST,"dpm_schreyer_base");
1.19 noro 1971: dpm_schreyer_base_zlist((LIST)ARG0(arg),rp);
1.11 noro 1972: }
1973:
1.19 noro 1974: void dpm_list_to_array(LIST g,VECT *psv,VECT *psiv);
1975:
1976: void Pdpm_list_to_array(NODE arg,LIST *rp)
1977: {
1978: VECT psv,psiv;
1979: NODE nd;
1980:
1981: asir_assert(ARG0(arg),O_LIST,"dpm_list_to_array");
1982: dpm_list_to_array((LIST)ARG0(arg),&psv,&psiv);
1983: nd = mknode(2,psv,psiv);
1984: MKLIST(*rp,nd);
1985: }
1986:
1.21 noro 1987: /* [quo,nf] = dpm_sp_nf(psv,psiv,i,j,top) */
1988: DPM dpm_sp_nf_zlist(VECT psv,VECT psiv,int i,int j,int top,DPM *nf);
1.19 noro 1989:
1990: void Pdpm_sp_nf(NODE arg,LIST *rp)
1991: {
1992: VECT psv,psiv;
1993: DPM quo,nf;
1.21 noro 1994: Obj val;
1995: int i,j,top;
1.19 noro 1996: NODE nd;
1997:
1998: asir_assert(ARG0(arg),O_VECT,"dpm_sp_nf"); psv = (VECT)ARG0(arg);
1999: asir_assert(ARG1(arg),O_VECT,"dpm_sp_nf"); psiv = (VECT)ARG1(arg);
2000: asir_assert(ARG2(arg),O_N,"dpm_sp_nf"); i = ZTOS((Q)ARG2(arg));
2001: asir_assert(ARG3(arg),O_N,"dpm_sp_nf"); j = ZTOS((Q)ARG3(arg));
1.21 noro 2002: if ( get_opt("top",&val) && val )
2003: top = 1;
2004: else
2005: top = 0;
2006: quo = dpm_sp_nf_zlist(psv,psiv,i,j,top,&nf);
1.19 noro 2007: nd = mknode(2,quo,nf);
2008: MKLIST(*rp,nd);
2009: }
2010:
2011: void dpm_insert_to_zlist(VECT psiv,int pos,int i);
2012:
2013: /* insert_to_zlist(indarray,dpm_hp(f),i) */
2014: void Pdpm_insert_to_zlist(NODE arg,VECT *rp)
2015: {
2016: VECT psiv;
2017: int i,pos;
2018:
2019: asir_assert(ARG0(arg),O_VECT,"dpm_insert_to_zlist"); psiv = (VECT)ARG0(arg);
2020: asir_assert(ARG1(arg),O_N,"dpm_insert_to_zlist"); pos = ZTOS((Q)ARG1(arg));
2021: asir_assert(ARG2(arg),O_N,"dpm_insert_to_zlist"); i = ZTOS((Q)ARG2(arg));
2022: dpm_insert_to_zlist(psiv,pos,i);
2023: *rp = psiv;
2024: }
2025:
2026:
1.16 noro 2027: void dpm_simplify_syz(LIST m,LIST s,LIST *m1,LIST *s1,LIST *w1);
1.12 noro 2028:
2029: void Pdpm_simplify_syz(NODE arg,LIST *rp)
2030: {
1.16 noro 2031: LIST s1,m1,w1;
1.12 noro 2032: NODE t;
2033:
2034: asir_assert(ARG0(arg),O_LIST,"dpm_simplify_syz");
2035: asir_assert(ARG1(arg),O_LIST,"dpm_simplify_syz");
1.16 noro 2036: dpm_simplify_syz((LIST)ARG0(arg),(LIST)ARG1(arg),&s1,&m1,&w1);
2037: t = mknode(3,s1,m1,w1);
1.12 noro 2038: MKLIST(*rp,t);
2039: }
2040:
2041:
1.1 noro 2042: void Pdp_red_mod(NODE arg,LIST *rp)
2043: {
2044: DP h,r;
2045: P dmy;
2046: NODE n;
2047:
2048: do_weyl = 0;
2049: asir_assert(ARG0(arg),O_DP,"dp_red_mod");
2050: asir_assert(ARG1(arg),O_DP,"dp_red_mod");
2051: asir_assert(ARG2(arg),O_DP,"dp_red_mod");
2052: asir_assert(ARG3(arg),O_N,"dp_red_mod");
1.2 noro 2053: dp_red_mod((DP)ARG0(arg),(DP)ARG1(arg),(DP)ARG2(arg),ZTOS((Q)ARG3(arg)),
1.1 noro 2054: &h,&r,&dmy);
2055: NEWNODE(n); BDY(n) = (pointer)h;
2056: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)r;
2057: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
2058: }
2059:
2060: void Pdp_subd(NODE arg,DP *rp)
2061: {
2062: DP p1,p2;
2063:
2064: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2065: asir_assert(p1,O_DP,"dp_subd");
2066: asir_assert(p2,O_DP,"dp_subd");
2067: dp_subd(p1,p2,rp);
2068: }
2069:
2070: void Pdp_symb_add(NODE arg,DP *rp)
2071: {
2072: DP p1,p2,r;
2073: NODE s0;
2074: MP mp0,mp;
2075: int nv;
2076:
2077: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2078: asir_assert(p1,O_DP,"dp_symb_add");
2079: asir_assert(p2,O_DP,"dp_symb_add");
2080: if ( !p1 ) { *rp = p2; return; }
2081: else if ( !p2 ) { *rp = p1; return; }
2082: if ( p1->nv != p2->nv )
2083: error("dp_sumb_add : invalid input");
2084: nv = p1->nv;
2085: s0 = symb_merge(dp_dllist(p1),dp_dllist(p2),nv);
2086: for ( mp0 = 0; s0; s0 = NEXT(s0) ) {
2087: NEXTMP(mp0,mp); mp->dl = (DL)BDY(s0); mp->c = (Obj)ONE;
2088: }
2089: NEXT(mp) = 0;
2090: MKDP(nv,mp0,r); r->sugar = MAX(p1->sugar,p2->sugar);
2091: *rp = r;
2092: }
2093:
2094: void Pdp_mul_trunc(NODE arg,DP *rp)
2095: {
2096: DP p1,p2,p;
2097:
2098: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg); p = (DP)ARG2(arg);
2099: asir_assert(p1,O_DP,"dp_mul_trunc");
2100: asir_assert(p2,O_DP,"dp_mul_trunc");
2101: asir_assert(p,O_DP,"dp_mul_trunc");
2102: comm_muld_trunc(CO,p1,p2,BDY(p)->dl,rp);
2103: }
2104:
2105: void Pdp_quo(NODE arg,DP *rp)
2106: {
2107: DP p1,p2;
2108:
2109: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2110: asir_assert(p1,O_DP,"dp_quo");
2111: asir_assert(p2,O_DP,"dp_quo");
2112: comm_quod(CO,p1,p2,rp);
2113: }
2114:
2115: void Pdp_weyl_mul(NODE arg,DP *rp)
2116: {
2117: DP p1,p2;
2118:
2119: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2120: asir_assert(p1,O_DP,"dp_weyl_mul"); asir_assert(p2,O_DP,"dp_weyl_mul");
2121: do_weyl = 1;
2122: muld(CO,p1,p2,rp);
2123: do_weyl = 0;
2124: }
2125:
2126: void Pdp_weyl_act(NODE arg,DP *rp)
2127: {
2128: DP p1,p2;
2129:
2130: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2131: asir_assert(p1,O_DP,"dp_weyl_act"); asir_assert(p2,O_DP,"dp_weyl_act");
2132: weyl_actd(CO,p1,p2,rp);
2133: }
2134:
2135:
2136: void Pdp_weyl_mul_mod(NODE arg,DP *rp)
2137: {
2138: DP p1,p2;
2139: Q m;
2140:
2141: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg); m = (Q)ARG2(arg);
2142: asir_assert(p1,O_DP,"dp_weyl_mul_mod");
2143: asir_assert(p2,O_DP,"dp_mul_mod");
2144: asir_assert(m,O_N,"dp_mul_mod");
2145: do_weyl = 1;
1.2 noro 2146: mulmd(CO,ZTOS(m),p1,p2,rp);
1.1 noro 2147: do_weyl = 0;
2148: }
2149:
2150: void Pdp_red(NODE arg,LIST *rp)
2151: {
2152: NODE n;
2153: DP head,rest,dmy1;
2154: P dmy;
2155:
2156: do_weyl = 0;
2157: asir_assert(ARG0(arg),O_DP,"dp_red");
2158: asir_assert(ARG1(arg),O_DP,"dp_red");
2159: asir_assert(ARG2(arg),O_DP,"dp_red");
2160: dp_red((DP)ARG0(arg),(DP)ARG1(arg),(DP)ARG2(arg),&head,&rest,&dmy,&dmy1);
2161: NEWNODE(n); BDY(n) = (pointer)head;
2162: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)rest;
2163: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
2164: }
2165:
2166: void Pdp_weyl_red(NODE arg,LIST *rp)
2167: {
2168: NODE n;
2169: DP head,rest,dmy1;
2170: P dmy;
2171:
2172: asir_assert(ARG0(arg),O_DP,"dp_weyl_red");
2173: asir_assert(ARG1(arg),O_DP,"dp_weyl_red");
2174: asir_assert(ARG2(arg),O_DP,"dp_weyl_red");
2175: do_weyl = 1;
2176: dp_red((DP)ARG0(arg),(DP)ARG1(arg),(DP)ARG2(arg),&head,&rest,&dmy,&dmy1);
2177: do_weyl = 0;
2178: NEWNODE(n); BDY(n) = (pointer)head;
2179: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)rest;
2180: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
2181: }
2182:
2183: void Pdp_sp(NODE arg,DP *rp)
2184: {
2185: DP p1,p2;
2186:
2187: do_weyl = 0;
2188: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2189: asir_assert(p1,O_DP,"dp_sp"); asir_assert(p2,O_DP,"dp_sp");
2190: dp_sp(p1,p2,rp);
2191: }
2192:
2193: void Pdp_weyl_sp(NODE arg,DP *rp)
2194: {
2195: DP p1,p2;
2196:
2197: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2198: asir_assert(p1,O_DP,"dp_weyl_sp"); asir_assert(p2,O_DP,"dp_weyl_sp");
2199: do_weyl = 1;
2200: dp_sp(p1,p2,rp);
2201: do_weyl = 0;
2202: }
2203:
1.9 noro 2204: void Pdpm_sp(NODE arg,Obj *rp)
1.1 noro 2205: {
1.9 noro 2206: DPM p1,p2,sp;
2207: DP mul1,mul2;
2208: Obj val;
2209: NODE nd;
2210: LIST l;
1.1 noro 2211:
2212: do_weyl = 0;
2213: p1 = (DPM)ARG0(arg); p2 = (DPM)ARG1(arg);
2214: asir_assert(p1,O_DPM,"dpm_sp"); asir_assert(p2,O_DPM,"dpm_sp");
1.9 noro 2215: dpm_sp(p1,p2,&sp,&mul1,&mul2);
2216: if ( get_opt("coef",&val) && val ) {
2217: nd = mknode(3,sp,mul1,mul2);
2218: MKLIST(l,nd);
2219: *rp = (Obj)l;
2220: } else {
2221: *rp = (Obj)sp;
2222: }
1.1 noro 2223: }
2224:
1.9 noro 2225: void Pdpm_weyl_sp(NODE arg,Obj *rp)
1.1 noro 2226: {
1.9 noro 2227: DPM p1,p2,sp;
2228: DP mul1,mul2;
2229: Obj val;
2230: NODE nd;
2231: LIST l;
1.1 noro 2232:
2233: p1 = (DPM)ARG0(arg); p2 = (DPM)ARG1(arg);
2234: asir_assert(p1,O_DPM,"dpm_weyl_sp"); asir_assert(p2,O_DPM,"dpm_weyl_sp");
2235: do_weyl = 1;
1.9 noro 2236: dpm_sp(p1,p2,&sp,&mul1,&mul2);
1.1 noro 2237: do_weyl = 0;
1.9 noro 2238: if ( get_opt("coef",&val) && val ) {
2239: nd = mknode(3,sp,mul1,mul2);
2240: MKLIST(l,nd);
2241: *rp = (Obj)l;
2242: } else {
2243: *rp = (Obj)sp;
2244: }
1.1 noro 2245: }
2246:
2247: void Pdp_sp_mod(NODE arg,DP *rp)
2248: {
2249: DP p1,p2;
2250: int mod;
2251:
2252: do_weyl = 0;
2253: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2254: asir_assert(p1,O_DP,"dp_sp_mod"); asir_assert(p2,O_DP,"dp_sp_mod");
2255: asir_assert(ARG2(arg),O_N,"dp_sp_mod");
1.2 noro 2256: mod = ZTOS((Q)ARG2(arg));
1.1 noro 2257: dp_sp_mod(p1,p2,mod,rp);
2258: }
2259:
2260: void Pdp_lcm(NODE arg,DP *rp)
2261: {
2262: int i,n,td;
2263: DL d1,d2,d;
2264: MP m;
2265: DP p1,p2;
2266:
2267: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2268: asir_assert(p1,O_DP,"dp_lcm"); asir_assert(p2,O_DP,"dp_lcm");
2269: n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl;
2270: NEWDL(d,n);
2271: for ( i = 0, td = 0; i < n; i++ ) {
2272: d->d[i] = MAX(d1->d[i],d2->d[i]); td += MUL_WEIGHT(d->d[i],i);
2273: }
2274: d->td = td;
2275: NEWMP(m); m->dl = d; m->c = (Obj)ONE; NEXT(m) = 0;
2276: MKDP(n,m,*rp); (*rp)->sugar = td; /* XXX */
2277: }
2278:
2279: void Pdp_hm(NODE arg,DP *rp)
2280: {
2281: DP p;
2282:
2283: p = (DP)ARG0(arg); asir_assert(p,O_DP,"dp_hm");
2284: dp_hm(p,rp);
2285: }
2286:
2287: void Pdp_ht(NODE arg,DP *rp)
2288: {
2289: DP p;
2290: MP m,mr;
2291:
2292: p = (DP)ARG0(arg); asir_assert(p,O_DP,"dp_ht");
2293: dp_ht(p,rp);
2294: }
2295:
2296: void Pdp_hc(NODE arg,Obj *rp)
2297: {
2298: asir_assert(ARG0(arg),O_DP,"dp_hc");
2299: if ( !ARG0(arg) )
2300: *rp = 0;
2301: else
2302: *rp = BDY((DP)ARG0(arg))->c;
2303: }
2304:
2305: void Pdp_rest(NODE arg,DP *rp)
2306: {
2307: asir_assert(ARG0(arg),O_DP,"dp_rest");
2308: if ( !ARG0(arg) )
2309: *rp = 0;
2310: else
2311: dp_rest((DP)ARG0(arg),rp);
2312: }
2313:
2314: void Pdp_td(NODE arg,Z *rp)
2315: {
2316: DP p;
2317:
2318: p = (DP)ARG0(arg); asir_assert(p,O_DP,"dp_td");
2319: if ( !p )
2320: *rp = 0;
2321: else
1.2 noro 2322: STOZ(BDY(p)->dl->td,*rp);
1.1 noro 2323: }
2324:
1.15 noro 2325: void Pdpm_td(NODE arg,Z *rp)
2326: {
2327: DPM p;
2328:
2329: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_td");
2330: if ( !p )
2331: *rp = 0;
2332: else
2333: STOZ(BDY(p)->dl->td,*rp);
2334: }
2335:
1.1 noro 2336: void Pdp_sugar(NODE arg,Z *rp)
2337: {
2338: DP p;
2339:
2340: p = (DP)ARG0(arg); asir_assert(p,O_DP,"dp_sugar");
2341: if ( !p )
2342: *rp = 0;
2343: else
1.2 noro 2344: STOZ(p->sugar,*rp);
1.1 noro 2345: }
2346:
2347: void Pdp_initial_term(NODE arg,Obj *rp)
2348: {
2349: struct order_spec *ord;
2350: Num homo;
2351: int modular,is_list;
2352: LIST v,f,l,initiallist;
2353: NODE n;
2354:
2355: f = (LIST)ARG0(arg);
2356: if ( f && OID(f) == O_LIST )
2357: is_list = 1;
2358: else {
2359: n = mknode(1,f); MKLIST(l,n); f = l;
2360: is_list = 0;
2361: }
2362: if ( current_option ) {
2363: parse_gr_option(f,current_option,&v,&homo,&modular,&ord);
2364: initd(ord);
2365: } else
2366: ord = dp_current_spec;
2367: initiallist = dp_initial_term(f,ord);
2368: if ( !is_list )
2369: *rp = (Obj)BDY(BDY(initiallist));
2370: else
2371: *rp = (Obj)initiallist;
2372: }
2373:
2374: void Pdp_order(NODE arg,Obj *rp)
2375: {
2376: struct order_spec *ord;
2377: Num homo;
2378: int modular,is_list;
2379: LIST v,f,l,ordlist;
2380: NODE n;
2381:
2382: f = (LIST)ARG0(arg);
2383: if ( f && OID(f) == O_LIST )
2384: is_list = 1;
2385: else {
2386: n = mknode(1,f); MKLIST(l,n); f = l;
2387: is_list = 0;
2388: }
2389: if ( current_option ) {
2390: parse_gr_option(f,current_option,&v,&homo,&modular,&ord);
2391: initd(ord);
2392: } else
2393: ord = dp_current_spec;
2394: ordlist = dp_order(f,ord);
2395: if ( !is_list )
2396: *rp = (Obj)BDY(BDY(ordlist));
2397: else
2398: *rp = (Obj)ordlist;
2399: }
2400:
2401: void Pdp_set_sugar(NODE arg,Q *rp)
2402: {
2403: DP p;
2404: Q q;
2405: int i;
2406:
2407: p = (DP)ARG0(arg);
2408: q = (Q)ARG1(arg);
2409: if ( p && q) {
2410: asir_assert(p,O_DP,"dp_set_sugar");
2411: asir_assert(q,O_N, "dp_set_sugar");
1.2 noro 2412: i = ZTOS(q);
1.1 noro 2413: if (p->sugar < i) {
2414: p->sugar = i;
2415: }
2416: }
2417: *rp = 0;
2418: }
2419:
2420: void Pdp_cri1(NODE arg,Z *rp)
2421: {
2422: DP p1,p2;
2423: int *d1,*d2;
2424: int i,n;
2425:
2426: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2427: asir_assert(p1,O_DP,"dp_cri1"); asir_assert(p2,O_DP,"dp_cri1");
2428: n = p1->nv; d1 = BDY(p1)->dl->d; d2 = BDY(p2)->dl->d;
2429: for ( i = 0; i < n; i++ )
2430: if ( d1[i] > d2[i] )
2431: break;
2432: *rp = i == n ? ONE : 0;
2433: }
2434:
2435: void Pdp_cri2(NODE arg,Z *rp)
2436: {
2437: DP p1,p2;
2438: int *d1,*d2;
2439: int i,n;
2440:
2441: p1 = (DP)ARG0(arg); p2 = (DP)ARG1(arg);
2442: asir_assert(p1,O_DP,"dp_cri2"); asir_assert(p2,O_DP,"dp_cri2");
2443: n = p1->nv; d1 = BDY(p1)->dl->d; d2 = BDY(p2)->dl->d;
2444: for ( i = 0; i < n; i++ )
2445: if ( MIN(d1[i],d2[i]) >= 1 )
2446: break;
2447: *rp = i == n ? ONE : 0;
2448: }
2449:
2450: void Pdp_minp(NODE arg,LIST *rp)
2451: {
2452: NODE tn,tn1,d,dd,dd0,p,tp;
2453: LIST l,minp;
2454: DP lcm,tlcm;
2455: int s,ts;
2456:
2457: asir_assert(ARG0(arg),O_LIST,"dp_minp");
2458: d = BDY((LIST)ARG0(arg)); minp = (LIST)BDY(d);
2459: p = BDY(minp); p = NEXT(NEXT(p)); lcm = (DP)BDY(p); p = NEXT(p);
2460: if ( !ARG1(arg) ) {
1.2 noro 2461: s = ZTOS((Q)BDY(p)); p = NEXT(p);
1.1 noro 2462: for ( dd0 = 0, d = NEXT(d); d; d = NEXT(d) ) {
2463: tp = BDY((LIST)BDY(d)); tp = NEXT(NEXT(tp));
2464: tlcm = (DP)BDY(tp); tp = NEXT(tp);
1.2 noro 2465: ts = ZTOS((Q)BDY(tp)); tp = NEXT(tp);
1.1 noro 2466: NEXTNODE(dd0,dd);
2467: if ( ts < s ) {
2468: BDY(dd) = (pointer)minp;
2469: minp = (LIST)BDY(d); lcm = tlcm; s = ts;
2470: } else if ( ts == s ) {
2471: if ( compd(CO,lcm,tlcm) > 0 ) {
2472: BDY(dd) = (pointer)minp;
2473: minp = (LIST)BDY(d); lcm = tlcm; s = ts;
2474: } else
2475: BDY(dd) = BDY(d);
2476: } else
2477: BDY(dd) = BDY(d);
2478: }
2479: } else {
2480: for ( dd0 = 0, d = NEXT(d); d; d = NEXT(d) ) {
2481: tp = BDY((LIST)BDY(d)); tp = NEXT(NEXT(tp));
2482: tlcm = (DP)BDY(tp);
2483: NEXTNODE(dd0,dd);
2484: if ( compd(CO,lcm,tlcm) > 0 ) {
2485: BDY(dd) = (pointer)minp; minp = (LIST)BDY(d); lcm = tlcm;
2486: } else
2487: BDY(dd) = BDY(d);
2488: }
2489: }
2490: if ( dd0 )
2491: NEXT(dd) = 0;
2492: MKLIST(l,dd0); MKNODE(tn,l,0); MKNODE(tn1,minp,tn); MKLIST(*rp,tn1);
2493: }
2494:
2495: void Pdp_criB(NODE arg,LIST *rp)
2496: {
2497: NODE d,ij,dd,ddd;
2498: int i,j,s,n;
2499: DP *ps;
2500: DL ts,ti,tj,lij,tdl;
2501:
2502: asir_assert(ARG0(arg),O_LIST,"dp_criB"); d = BDY((LIST)ARG0(arg));
1.2 noro 2503: asir_assert(ARG1(arg),O_N,"dp_criB"); s = ZTOS((Q)ARG1(arg));
1.1 noro 2504: asir_assert(ARG2(arg),O_VECT,"dp_criB"); ps = (DP *)BDY((VECT)ARG2(arg));
2505: if ( !d )
2506: *rp = (LIST)ARG0(arg);
2507: else {
2508: ts = BDY(ps[s])->dl;
2509: n = ps[s]->nv;
2510: NEWDL(tdl,n);
2511: for ( dd = 0; d; d = NEXT(d) ) {
2512: ij = BDY((LIST)BDY(d));
1.2 noro 2513: i = ZTOS((Q)BDY(ij)); ij = NEXT(ij);
2514: j = ZTOS((Q)BDY(ij)); ij = NEXT(ij);
1.1 noro 2515: lij = BDY((DP)BDY(ij))->dl;
2516: ti = BDY(ps[i])->dl; tj = BDY(ps[j])->dl;
2517: if ( lij->td != lcm_of_DL(n,lij,ts,tdl)->td
2518: || !dl_equal(n,lij,tdl)
2519: || (lij->td == lcm_of_DL(n,ti,ts,tdl)->td
2520: && dl_equal(n,tdl,lij))
2521: || (lij->td == lcm_of_DL(n,tj,ts,tdl)->td
2522: && dl_equal(n,tdl,lij)) ) {
2523: MKNODE(ddd,BDY(d),dd);
2524: dd = ddd;
2525: }
2526: }
2527: MKLIST(*rp,dd);
2528: }
2529: }
2530:
2531: void Pdp_nelim(NODE arg,Z *rp)
2532: {
2533: if ( arg ) {
2534: asir_assert(ARG0(arg),O_N,"dp_nelim");
1.2 noro 2535: dp_nelim = ZTOS((Q)ARG0(arg));
1.1 noro 2536: }
1.2 noro 2537: STOZ(dp_nelim,*rp);
1.1 noro 2538: }
2539:
2540: void Pdp_mag(NODE arg,Z *rp)
2541: {
2542: DP p;
2543: int s;
2544: MP m;
2545:
2546: p = (DP)ARG0(arg);
2547: asir_assert(p,O_DP,"dp_mag");
2548: if ( !p )
2549: *rp = 0;
2550: else {
2551: for ( s = 0, m = BDY(p); m; m = NEXT(m) )
2552: s += p_mag((P)m->c);
1.2 noro 2553: STOZ(s,*rp);
1.1 noro 2554: }
2555: }
2556:
2557: /* kara_mag is no longer used. */
2558:
2559: void Pdp_set_kara(NODE arg,Z *rp)
2560: {
2561: *rp = 0;
2562: }
2563:
2564: void Pdp_homo(NODE arg,DP *rp)
2565: {
2566: asir_assert(ARG0(arg),O_DP,"dp_homo");
2567: dp_homo((DP)ARG0(arg),rp);
2568: }
2569:
2570: void Pdp_dehomo(NODE arg,DP *rp)
2571: {
2572: asir_assert(ARG0(arg),O_DP,"dp_dehomo");
2573: dp_dehomo((DP)ARG0(arg),rp);
2574: }
2575:
1.16 noro 2576: void dpm_homo(DPM a,DPM *b);
2577: void dpm_dehomo(DPM a,DPM *b);
2578:
2579: void Pdpm_homo(NODE arg,DPM *rp)
2580: {
2581: asir_assert(ARG0(arg),O_DPM,"dpm_homo");
2582: dpm_homo((DPM)ARG0(arg),rp);
2583: }
2584:
2585: void Pdpm_dehomo(NODE arg,DPM *rp)
2586: {
2587: asir_assert(ARG0(arg),O_DPM,"dpm_dehomo");
2588: dpm_dehomo((DPM)ARG0(arg),rp);
2589: }
2590:
2591:
1.1 noro 2592: void Pdp_gr_flags(NODE arg,LIST *rp)
2593: {
2594: Obj name,value;
2595: NODE n;
2596:
2597: if ( arg ) {
2598: asir_assert(ARG0(arg),O_LIST,"dp_gr_flags");
2599: n = BDY((LIST)ARG0(arg));
2600: while ( n ) {
2601: name = (Obj)BDY(n); n = NEXT(n);
2602: if ( !n )
2603: break;
2604: else {
2605: value = (Obj)BDY(n); n = NEXT(n);
2606: }
2607: dp_set_flag(name,value);
2608: }
2609: }
2610: dp_make_flaglist(rp);
2611: }
2612:
2613: extern int DP_Print, DP_PrintShort;
2614:
2615: void Pdp_gr_print(NODE arg,Z *rp)
2616: {
2617: Z q;
2618: int s;
2619:
2620: if ( arg ) {
2621: asir_assert(ARG0(arg),O_N,"dp_gr_print");
2622: q = (Z)ARG0(arg);
1.2 noro 2623: s = ZTOS(q);
1.1 noro 2624: switch ( s ) {
2625: case 0:
2626: DP_Print = 0; DP_PrintShort = 0;
2627: break;
2628: case 1:
2629: DP_Print = 1;
2630: break;
2631: case 2:
2632: DP_Print = 0; DP_PrintShort = 1;
2633: break;
2634: default:
2635: DP_Print = s; DP_PrintShort = 0;
2636: break;
2637: }
2638: } else {
2639: if ( DP_Print ) {
1.2 noro 2640: STOZ(1,q);
1.1 noro 2641: } else if ( DP_PrintShort ) {
1.2 noro 2642: STOZ(2,q);
1.1 noro 2643: } else
2644: q = 0;
2645: }
2646: *rp = q;
2647: }
2648:
2649: void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo,
2650: int *modular,struct order_spec **ord)
2651: {
2652: NODE t,p;
2653: Z m,z;
2654: char *key;
2655: Obj value,dmy;
2656: int ord_is_set = 0;
2657: int modular_is_set = 0;
2658: int homo_is_set = 0;
2659: VL vl,vl0;
2660: LIST vars;
2661: char xiname[BUFSIZ];
2662: NODE x0,x;
2663: DP d;
2664: P xi;
2665: int nv,i;
2666:
2667: /* extract vars */
2668: vars = 0;
2669: for ( t = opt; t; t = NEXT(t) ) {
2670: p = BDY((LIST)BDY(t));
2671: key = BDY((STRING)BDY(p));
2672: value = (Obj)BDY(NEXT(p));
2673: if ( !strcmp(key,"v") ) {
2674: /* variable list */
2675: vars = (LIST)value;
2676: break;
2677: }
2678: }
2679: if ( vars ) {
2680: *v = vars; pltovl(vars,&vl);
2681: } else {
2682: for ( t = BDY(f); t; t = NEXT(t) )
2683: if ( BDY(t) && OID((Obj)BDY(t))==O_DP )
2684: break;
2685: if ( t ) {
2686: /* f is DP list */
2687: /* create dummy var list */
2688: d = (DP)BDY(t);
2689: nv = NV(d);
2690: for ( i = 0, vl0 = 0, x0 = 0; i < nv; i++ ) {
2691: NEXTVL(vl0,vl);
2692: NEXTNODE(x0,x);
2693: sprintf(xiname,"x%d",i);
2694: makevar(xiname,&xi);
2695: x->body = (pointer)xi;
2696: vl->v = VR((P)xi);
2697: }
2698: if ( vl0 ) {
2699: NEXT(vl) = 0;
2700: NEXT(x) = 0;
2701: }
2702: MKLIST(vars,x0);
2703: *v = vars;
2704: vl = vl0;
2705: } else {
2706: get_vars((Obj)f,&vl); vltopl(vl,v);
2707: }
2708: }
2709:
2710: for ( t = opt; t; t = NEXT(t) ) {
2711: p = BDY((LIST)BDY(t));
2712: key = BDY((STRING)BDY(p));
2713: value = (Obj)BDY(NEXT(p));
2714: if ( !strcmp(key,"v") ) {
2715: /* variable list; ignore */
2716: } else if ( !strcmp(key,"order") ) {
2717: /* order spec */
2718: if ( !vl )
2719: error("parse_gr_option : variables must be specified");
2720: create_order_spec(vl,value,ord);
2721: ord_is_set = 1;
2722: } else if ( !strcmp(key,"block") ) {
2723: create_order_spec(0,value,ord);
2724: ord_is_set = 1;
2725: } else if ( !strcmp(key,"matrix") ) {
2726: create_order_spec(0,value,ord);
2727: ord_is_set = 1;
2728: } else if ( !strcmp(key,"sugarweight") ) {
2729: /* weight */
2730: Pdp_set_weight(NEXT(p),&dmy);
2731: } else if ( !strcmp(key,"homo") ) {
2732: *homo = (Num)value;
2733: homo_is_set = 1;
2734: } else if ( !strcmp(key,"trace") ) {
2735: m = (Z)value;
1.2 noro 2736: STOZ(0x80000000,z);
1.1 noro 2737: if ( !m )
2738: *modular = 0;
2739: else if ( cmpz(m,z) >= 0 )
2740: error("parse_gr_option : too large modulus");
2741: else
1.2 noro 2742: *modular = ZTOS(m);
1.1 noro 2743: modular_is_set = 1;
2744: } else if ( !strcmp(key,"dp") ) {
2745: /* XXX : ignore */
2746: } else
2747: error("parse_gr_option : not implemented");
2748: }
2749: if ( !ord_is_set ) create_order_spec(0,0,ord);
2750: if ( !modular_is_set ) *modular = 0;
2751: if ( !homo_is_set ) *homo = 0;
2752: }
2753:
2754: void Pdp_gr_main(NODE arg,LIST *rp)
2755: {
2756: LIST f,v;
2757: VL vl;
2758: Num homo;
2759: Z m,z;
2760: int modular,ac;
2761: struct order_spec *ord;
2762:
2763: do_weyl = 0;
2764: asir_assert(ARG0(arg),O_LIST,"dp_gr_main");
2765: f = (LIST)ARG0(arg);
2766: f = remove_zero_from_list(f);
2767: if ( !BDY(f) ) {
2768: *rp = f; return;
2769: }
2770: if ( (ac = argc(arg)) == 5 ) {
2771: asir_assert(ARG1(arg),O_LIST,"dp_gr_main");
2772: asir_assert(ARG2(arg),O_N,"dp_gr_main");
2773: asir_assert(ARG3(arg),O_N,"dp_gr_main");
2774: v = (LIST)ARG1(arg);
2775: homo = (Num)ARG2(arg);
2776: m = (Z)ARG3(arg);
1.2 noro 2777: STOZ(0x80000000,z);
1.1 noro 2778: if ( !m )
2779: modular = 0;
2780: else if ( cmpz(m,z) >= 0 )
2781: error("dp_gr_main : too large modulus");
2782: else
1.2 noro 2783: modular = ZTOS(m);
1.1 noro 2784: create_order_spec(0,ARG4(arg),&ord);
2785: } else if ( current_option )
2786: parse_gr_option(f,current_option,&v,&homo,&modular,&ord);
2787: else if ( ac == 1 )
2788: parse_gr_option(f,0,&v,&homo,&modular,&ord);
2789: else
2790: error("dp_gr_main : invalid argument");
2791: dp_gr_main(f,v,homo,modular,0,ord,rp);
2792: }
2793:
2794: void Pdp_interreduce(NODE arg,LIST *rp)
2795: {
2796: LIST f,v;
2797: VL vl;
2798: int ac;
2799: struct order_spec *ord;
2800:
2801: do_weyl = 0;
2802: asir_assert(ARG0(arg),O_LIST,"dp_interreduce");
2803: f = (LIST)ARG0(arg);
2804: f = remove_zero_from_list(f);
2805: if ( !BDY(f) ) {
2806: *rp = f; return;
2807: }
2808: if ( (ac = argc(arg)) == 3 ) {
2809: asir_assert(ARG1(arg),O_LIST,"dp_interreduce");
2810: v = (LIST)ARG1(arg);
2811: create_order_spec(0,ARG2(arg),&ord);
2812: }
2813: dp_interreduce(f,v,0,ord,rp);
2814: }
2815:
2816: void Pdp_gr_f_main(NODE arg,LIST *rp)
2817: {
2818: LIST f,v;
2819: Num homo;
2820: int m,field,t;
2821: struct order_spec *ord;
2822: NODE n;
2823:
2824: do_weyl = 0;
2825: asir_assert(ARG0(arg),O_LIST,"dp_gr_f_main");
2826: asir_assert(ARG1(arg),O_LIST,"dp_gr_f_main");
2827: asir_assert(ARG2(arg),O_N,"dp_gr_f_main");
2828: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
2829: f = remove_zero_from_list(f);
2830: if ( !BDY(f) ) {
2831: *rp = f; return;
2832: }
2833: homo = (Num)ARG2(arg);
2834: #if 0
2835: asir_assert(ARG3(arg),O_N,"dp_gr_f_main");
1.2 noro 2836: m = ZTOS((Q)ARG3(arg));
1.1 noro 2837: if ( m )
2838: error("dp_gr_f_main : trace lifting is not implemented yet");
2839: create_order_spec(0,ARG4(arg),&ord);
2840: #else
2841: m = 0;
2842: create_order_spec(0,ARG3(arg),&ord);
2843: #endif
2844: field = 0;
2845: for ( n = BDY(f); n; n = NEXT(n) ) {
2846: t = get_field_type(BDY(n));
2847: if ( !t )
2848: continue;
2849: if ( t < 0 )
2850: error("dp_gr_f_main : incosistent coefficients");
2851: if ( !field )
2852: field = t;
2853: else if ( t != field )
2854: error("dp_gr_f_main : incosistent coefficients");
2855: }
2856: dp_gr_main(f,v,homo,m?1:0,field,ord,rp);
2857: }
2858:
2859: void Pdp_f4_main(NODE arg,LIST *rp)
2860: {
2861: LIST f,v;
2862: struct order_spec *ord;
2863:
2864: do_weyl = 0;
2865: asir_assert(ARG0(arg),O_LIST,"dp_f4_main");
2866: asir_assert(ARG1(arg),O_LIST,"dp_f4_main");
2867: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
2868: f = remove_zero_from_list(f);
2869: if ( !BDY(f) ) {
2870: *rp = f; return;
2871: }
2872: create_order_spec(0,ARG2(arg),&ord);
2873: dp_f4_main(f,v,ord,rp);
2874: }
2875:
2876: /* dp_gr_checklist(list of dp) */
2877:
2878: void Pdp_gr_checklist(NODE arg,LIST *rp)
2879: {
2880: VECT g;
2881: LIST dp;
2882: NODE r;
2883: int n;
2884:
2885: do_weyl = 0;
2886: asir_assert(ARG0(arg),O_LIST,"dp_gr_checklist");
2887: asir_assert(ARG1(arg),O_N,"dp_gr_checklist");
1.2 noro 2888: n = ZTOS((Q)ARG1(arg));
1.1 noro 2889: gbcheck_list(BDY((LIST)ARG0(arg)),n,&g,&dp);
2890: r = mknode(2,g,dp);
2891: MKLIST(*rp,r);
2892: }
2893:
2894: void Pdp_f4_mod_main(NODE arg,LIST *rp)
2895: {
2896: LIST f,v;
2897: int m;
2898: struct order_spec *ord;
2899:
2900: do_weyl = 0;
2901: asir_assert(ARG0(arg),O_LIST,"dp_f4_mod_main");
2902: asir_assert(ARG1(arg),O_LIST,"dp_f4_mod_main");
2903: asir_assert(ARG2(arg),O_N,"dp_f4_mod_main");
1.2 noro 2904: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg); m = ZTOS((Q)ARG2(arg));
1.1 noro 2905: f = remove_zero_from_list(f);
2906: if ( !BDY(f) ) {
2907: *rp = f; return;
2908: }
2909: if ( !m )
2910: error("dp_f4_mod_main : invalid argument");
2911: create_order_spec(0,ARG3(arg),&ord);
2912: dp_f4_mod_main(f,v,m,ord,rp);
2913: }
2914:
2915: void Pdp_gr_mod_main(NODE arg,LIST *rp)
2916: {
2917: LIST f,v;
2918: Num homo;
2919: int m;
2920: struct order_spec *ord;
2921:
2922: do_weyl = 0;
2923: asir_assert(ARG0(arg),O_LIST,"dp_gr_mod_main");
2924: asir_assert(ARG1(arg),O_LIST,"dp_gr_mod_main");
2925: asir_assert(ARG2(arg),O_N,"dp_gr_mod_main");
2926: asir_assert(ARG3(arg),O_N,"dp_gr_mod_main");
2927: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
2928: f = remove_zero_from_list(f);
2929: if ( !BDY(f) ) {
2930: *rp = f; return;
2931: }
1.2 noro 2932: homo = (Num)ARG2(arg); m = ZTOS((Q)ARG3(arg));
1.1 noro 2933: if ( !m )
2934: error("dp_gr_mod_main : invalid argument");
2935: create_order_spec(0,ARG4(arg),&ord);
2936: dp_gr_mod_main(f,v,homo,m,ord,rp);
2937: }
2938:
2939: void Psetmod_ff(NODE node, Obj *val);
2940:
2941: void Pnd_f4(NODE arg,LIST *rp)
2942: {
2943: LIST f,v;
2944: int m,homo,retdp,ac;
2945: Obj val;
2946: Z mq,z;
2947: Num nhomo;
2948: NODE node;
2949: struct order_spec *ord;
2950:
2951: do_weyl = 0;
2952: nd_rref2 = 0;
2953: retdp = 0;
2954: if ( (ac = argc(arg)) == 4 ) {
2955: asir_assert(ARG0(arg),O_LIST,"nd_f4");
2956: asir_assert(ARG1(arg),O_LIST,"nd_f4");
2957: asir_assert(ARG2(arg),O_N,"nd_f4");
2958: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
2959: f = remove_zero_from_list(f);
2960: if ( !BDY(f) ) {
2961: *rp = f; return;
2962: }
2963: mq = (Z)ARG2(arg);
1.2 noro 2964: STOZ((unsigned long)0x40000000,z);
1.1 noro 2965: if ( cmpz(mq,z) >= 0 ) {
2966: node = mknode(1,mq);
2967: Psetmod_ff(node,&val);
2968: m = -2;
2969: } else
1.2 noro 2970: m = ZTOS(mq);
1.1 noro 2971: create_order_spec(0,ARG3(arg),&ord);
2972: homo = 0;
2973: if ( get_opt("homo",&val) && val ) homo = 1;
2974: if ( get_opt("dp",&val) && val ) retdp = 1;
2975: if ( get_opt("rref2",&val) && val ) nd_rref2 = 1;
2976: } else if ( ac == 1 ) {
2977: f = (LIST)ARG0(arg);
2978: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 2979: homo = ZTOS((Q)nhomo);
1.1 noro 2980: if ( get_opt("dp",&val) && val ) retdp = 1;
2981: if ( get_opt("rref2",&val) && val ) nd_rref2 = 1;
2982: } else
2983: error("nd_f4 : invalid argument");
2984: nd_gr(f,v,m,homo,retdp,1,ord,rp);
2985: }
2986:
2987: void Pnd_gr(NODE arg,LIST *rp)
2988: {
2989: LIST f,v;
2990: int m,homo,retdp,ac;
2991: Obj val;
2992: Z mq,z;
2993: Num nhomo;
2994: NODE node;
2995: struct order_spec *ord;
2996:
2997: do_weyl = 0;
2998: retdp = 0;
2999: if ( (ac=argc(arg)) == 4 ) {
3000: asir_assert(ARG0(arg),O_LIST,"nd_gr");
3001: asir_assert(ARG1(arg),O_LIST,"nd_gr");
3002: asir_assert(ARG2(arg),O_N,"nd_gr");
3003: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3004: f = remove_zero_from_list(f);
3005: if ( !BDY(f) ) {
3006: *rp = f; return;
3007: }
3008: mq = (Z)ARG2(arg);
1.2 noro 3009: STOZ(0x40000000,z);
1.1 noro 3010: if ( cmpz(mq,z) >= 0 ) {
3011: node = mknode(1,mq);
3012: Psetmod_ff(node,&val);
3013: m = -2;
3014: } else
1.2 noro 3015: m = ZTOS(mq);
1.1 noro 3016: create_order_spec(0,ARG3(arg),&ord);
3017: homo = 0;
3018: if ( get_opt("homo",&val) && val ) homo = 1;
3019: if ( get_opt("dp",&val) && val ) retdp = 1;
3020: } else if ( ac == 1 ) {
3021: f = (LIST)ARG0(arg);
3022: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 3023: homo = ZTOS((Q)nhomo);
1.1 noro 3024: if ( get_opt("dp",&val) && val ) retdp = 1;
3025: } else
3026: error("nd_gr : invalid argument");
3027: nd_gr(f,v,m,homo,retdp,0,ord,rp);
3028: }
3029:
1.25 noro 3030: void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int f4,struct order_spec *ord,LIST *rp);
1.24 noro 3031:
3032: void Pnd_sba(NODE arg,LIST *rp)
3033: {
3034: LIST f,v;
3035: int m,homo,retdp,ac;
3036: Obj val;
3037: Z mq,z;
3038: Num nhomo;
3039: NODE node;
3040: struct order_spec *ord;
3041:
3042: do_weyl = 0;
3043: retdp = 0;
3044: if ( (ac=argc(arg)) == 4 ) {
3045: asir_assert(ARG0(arg),O_LIST,"nd_sba");
3046: asir_assert(ARG1(arg),O_LIST,"nd_sba");
3047: asir_assert(ARG2(arg),O_N,"nd_sba");
3048: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3049: f = remove_zero_from_list(f);
3050: if ( !BDY(f) ) {
3051: *rp = f; return;
3052: }
3053: mq = (Z)ARG2(arg);
3054: STOZ(0x40000000,z);
3055: if ( cmpz(mq,z) >= 0 ) {
3056: node = mknode(1,mq);
3057: Psetmod_ff(node,&val);
3058: m = -2;
3059: } else
3060: m = ZTOS(mq);
3061: create_order_spec(0,ARG3(arg),&ord);
3062: homo = 0;
3063: if ( get_opt("homo",&val) && val ) homo = 1;
3064: if ( get_opt("dp",&val) && val ) retdp = 1;
3065: } else if ( ac == 1 ) {
3066: f = (LIST)ARG0(arg);
3067: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
3068: homo = ZTOS((Q)nhomo);
3069: if ( get_opt("dp",&val) && val ) retdp = 1;
3070: } else
3071: error("nd_gr : invalid argument");
1.25 noro 3072: nd_sba(f,v,m,homo,retdp,0,ord,rp);
3073: }
3074:
3075: void Pnd_sba_f4(NODE arg,LIST *rp)
3076: {
3077: LIST f,v;
3078: int m,homo,retdp,ac;
3079: Obj val;
3080: Z mq,z;
3081: Num nhomo;
3082: NODE node;
3083: struct order_spec *ord;
3084:
3085: do_weyl = 0;
3086: retdp = 0;
3087: if ( (ac=argc(arg)) == 4 ) {
3088: asir_assert(ARG0(arg),O_LIST,"nd_sba");
3089: asir_assert(ARG1(arg),O_LIST,"nd_sba");
3090: asir_assert(ARG2(arg),O_N,"nd_sba");
3091: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3092: f = remove_zero_from_list(f);
3093: if ( !BDY(f) ) {
3094: *rp = f; return;
3095: }
3096: mq = (Z)ARG2(arg);
3097: STOZ(0x40000000,z);
3098: if ( cmpz(mq,z) >= 0 ) {
3099: node = mknode(1,mq);
3100: Psetmod_ff(node,&val);
3101: m = -2;
3102: } else
3103: m = ZTOS(mq);
3104: create_order_spec(0,ARG3(arg),&ord);
3105: homo = 0;
3106: if ( get_opt("homo",&val) && val ) homo = 1;
3107: if ( get_opt("dp",&val) && val ) retdp = 1;
3108: } else if ( ac == 1 ) {
3109: f = (LIST)ARG0(arg);
3110: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
3111: homo = ZTOS((Q)nhomo);
3112: if ( get_opt("dp",&val) && val ) retdp = 1;
3113: } else
3114: error("nd_gr : invalid argument");
3115: nd_sba(f,v,m,homo,retdp,1,ord,rp);
1.24 noro 3116: }
3117:
1.1 noro 3118: void Pnd_gr_postproc(NODE arg,LIST *rp)
3119: {
3120: LIST f,v;
3121: int m,do_check;
3122: Z mq,z;
3123: Obj val;
3124: NODE node;
3125: struct order_spec *ord;
3126:
3127: do_weyl = 0;
3128: asir_assert(ARG0(arg),O_LIST,"nd_gr");
3129: asir_assert(ARG1(arg),O_LIST,"nd_gr");
3130: asir_assert(ARG2(arg),O_N,"nd_gr");
3131: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3132: f = remove_zero_from_list(f);
3133: if ( !BDY(f) ) {
3134: *rp = f; return;
3135: }
3136: mq = (Z)ARG2(arg);
1.2 noro 3137: STOZ(0x40000000,z);
1.1 noro 3138: if ( cmpz(mq,z) >= 0 ) {
3139: node = mknode(1,mq);
3140: Psetmod_ff(node,&val);
3141: m = -2;
3142: } else
1.2 noro 3143: m = ZTOS(mq);
1.1 noro 3144: create_order_spec(0,ARG3(arg),&ord);
3145: do_check = ARG4(arg) ? 1 : 0;
3146: nd_gr_postproc(f,v,m,ord,do_check,rp);
3147: }
3148:
3149: void Pnd_gr_recompute_trace(NODE arg,LIST *rp)
3150: {
3151: LIST f,v,tlist;
3152: int m;
3153: struct order_spec *ord;
3154:
3155: do_weyl = 0;
3156: asir_assert(ARG0(arg),O_LIST,"nd_gr_recompute_trace");
3157: asir_assert(ARG1(arg),O_LIST,"nd_gr_recompute_trace");
3158: asir_assert(ARG2(arg),O_N,"nd_gr_recompute_trace");
3159: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
1.2 noro 3160: m = ZTOS((Q)ARG2(arg));
1.1 noro 3161: create_order_spec(0,ARG3(arg),&ord);
3162: tlist = (LIST)ARG4(arg);
3163: nd_gr_recompute_trace(f,v,m,ord,tlist,rp);
3164: }
3165:
3166: Obj nd_btog_one(LIST f,LIST v,int m,struct order_spec *ord,LIST tlist,int pos);
3167: Obj nd_btog(LIST f,LIST v,int m,struct order_spec *ord,LIST tlist);
3168:
3169: void Pnd_btog(NODE arg,Obj *rp)
3170: {
3171: LIST f,v,tlist;
3172: Z mq,z;
3173: int m,ac,pos;
3174: struct order_spec *ord;
3175: NODE node;
3176: pointer val;
3177:
3178: do_weyl = 0;
3179: asir_assert(ARG0(arg),O_LIST,"nd_btog");
3180: asir_assert(ARG1(arg),O_LIST,"nd_btog");
3181: asir_assert(ARG2(arg),O_N,"nd_btog");
3182: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3183: mq = (Z)ARG2(arg);
1.2 noro 3184: STOZ(0x40000000,z);
1.1 noro 3185: if ( cmpz(mq,z) >= 0 ) {
3186: node = mknode(1,mq);
3187: Psetmod_ff(node,(Obj *)&val);
3188: m = -2;
3189: } else
1.2 noro 3190: m = ZTOS(mq);
1.1 noro 3191: create_order_spec(0,ARG3(arg),&ord);
3192: tlist = (LIST)ARG4(arg);
3193: if ( (ac = argc(arg)) == 6 ) {
3194: asir_assert(ARG5(arg),O_N,"nd_btog");
1.2 noro 3195: pos = ZTOS((Q)ARG5(arg));
1.1 noro 3196: *rp = nd_btog_one(f,v,m,ord,tlist,pos);
3197: } else if ( ac == 5 )
3198: *rp = nd_btog(f,v,m,ord,tlist);
3199: else
3200: error("nd_btog : argument mismatch");
3201: }
3202:
3203: void Pnd_weyl_gr_postproc(NODE arg,LIST *rp)
3204: {
3205: LIST f,v;
3206: int m,do_check;
3207: struct order_spec *ord;
3208:
3209: do_weyl = 1;
3210: asir_assert(ARG0(arg),O_LIST,"nd_gr");
3211: asir_assert(ARG1(arg),O_LIST,"nd_gr");
3212: asir_assert(ARG2(arg),O_N,"nd_gr");
3213: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3214: f = remove_zero_from_list(f);
3215: if ( !BDY(f) ) {
3216: *rp = f; do_weyl = 0; return;
3217: }
1.2 noro 3218: m = ZTOS((Q)ARG2(arg));
1.1 noro 3219: create_order_spec(0,ARG3(arg),&ord);
3220: do_check = ARG4(arg) ? 1 : 0;
3221: nd_gr_postproc(f,v,m,ord,do_check,rp);
3222: do_weyl = 0;
3223: }
3224:
3225: void Pnd_gr_trace(NODE arg,LIST *rp)
3226: {
3227: LIST f,v;
3228: int m,homo,ac;
1.9 noro 3229: Obj val;
3230: int retdp;
1.1 noro 3231: Num nhomo;
3232: struct order_spec *ord;
3233:
3234: do_weyl = 0;
3235: if ( (ac = argc(arg)) == 5 ) {
3236: asir_assert(ARG0(arg),O_LIST,"nd_gr_trace");
3237: asir_assert(ARG1(arg),O_LIST,"nd_gr_trace");
3238: asir_assert(ARG2(arg),O_N,"nd_gr_trace");
3239: asir_assert(ARG3(arg),O_N,"nd_gr_trace");
3240: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3241: f = remove_zero_from_list(f);
3242: if ( !BDY(f) ) {
3243: *rp = f; return;
3244: }
1.2 noro 3245: homo = ZTOS((Q)ARG2(arg));
3246: m = ZTOS((Q)ARG3(arg));
1.1 noro 3247: create_order_spec(0,ARG4(arg),&ord);
3248: } else if ( ac == 1 ) {
3249: f = (LIST)ARG0(arg);
3250: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 3251: homo = ZTOS((Q)nhomo);
1.1 noro 3252: } else
3253: error("nd_gr_trace : invalid argument");
1.9 noro 3254: retdp = 0;
3255: if ( get_opt("dp",&val) && val ) retdp = 1;
3256: nd_gr_trace(f,v,m,homo,retdp,0,ord,rp);
1.1 noro 3257: }
3258:
3259: void Pnd_f4_trace(NODE arg,LIST *rp)
3260: {
3261: LIST f,v;
3262: int m,homo,ac;
1.9 noro 3263: int retdp;
3264: Obj val;
1.1 noro 3265: Num nhomo;
3266: struct order_spec *ord;
3267:
3268: do_weyl = 0;
3269: if ( (ac = argc(arg))==5 ) {
3270: asir_assert(ARG0(arg),O_LIST,"nd_f4_trace");
3271: asir_assert(ARG1(arg),O_LIST,"nd_f4_trace");
3272: asir_assert(ARG2(arg),O_N,"nd_f4_trace");
3273: asir_assert(ARG3(arg),O_N,"nd_f4_trace");
3274: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3275: f = remove_zero_from_list(f);
3276: if ( !BDY(f) ) {
3277: *rp = f; return;
3278: }
1.2 noro 3279: homo = ZTOS((Q)ARG2(arg));
3280: m = ZTOS((Q)ARG3(arg));
1.1 noro 3281: create_order_spec(0,ARG4(arg),&ord);
3282: } else if ( ac == 1 ) {
3283: f = (LIST)ARG0(arg);
3284: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 3285: homo = ZTOS((Q)nhomo);
1.1 noro 3286: } else
3287: error("nd_gr_trace : invalid argument");
1.9 noro 3288: retdp = 0;
3289: if ( get_opt("dp",&val) && val ) retdp = 1;
3290: nd_gr_trace(f,v,m,homo,retdp,1,ord,rp);
1.1 noro 3291: }
3292:
3293: void Pnd_weyl_gr(NODE arg,LIST *rp)
3294: {
3295: LIST f,v;
3296: int m,homo,retdp,ac;
3297: Obj val;
3298: Num nhomo;
3299: struct order_spec *ord;
3300:
3301: do_weyl = 1;
3302: retdp = 0;
3303: if ( (ac = argc(arg)) == 4 ) {
3304: asir_assert(ARG0(arg),O_LIST,"nd_weyl_gr");
3305: asir_assert(ARG1(arg),O_LIST,"nd_weyl_gr");
3306: asir_assert(ARG2(arg),O_N,"nd_weyl_gr");
3307: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3308: f = remove_zero_from_list(f);
3309: if ( !BDY(f) ) {
3310: *rp = f; do_weyl = 0; return;
3311: }
1.2 noro 3312: m = ZTOS((Q)ARG2(arg));
1.1 noro 3313: create_order_spec(0,ARG3(arg),&ord);
3314: homo = 0;
3315: if ( get_opt("homo",&val) && val ) homo = 1;
3316: if ( get_opt("dp",&val) && val ) retdp = 1;
3317: } else if ( ac == 1 ) {
3318: f = (LIST)ARG0(arg);
3319: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 3320: homo = ZTOS((Q)nhomo);
1.1 noro 3321: if ( get_opt("dp",&val) && val ) retdp = 1;
3322: } else
3323: error("nd_weyl_gr : invalid argument");
3324: nd_gr(f,v,m,homo,retdp,0,ord,rp);
3325: do_weyl = 0;
3326: }
3327:
3328: void Pnd_weyl_gr_trace(NODE arg,LIST *rp)
3329: {
3330: LIST f,v;
1.9 noro 3331: int m,homo,ac,retdp;
3332: Obj val;
1.1 noro 3333: Num nhomo;
3334: struct order_spec *ord;
3335:
3336: do_weyl = 1;
3337: if ( (ac = argc(arg)) == 5 ) {
3338: asir_assert(ARG0(arg),O_LIST,"nd_weyl_gr_trace");
3339: asir_assert(ARG1(arg),O_LIST,"nd_weyl_gr_trace");
3340: asir_assert(ARG2(arg),O_N,"nd_weyl_gr_trace");
3341: asir_assert(ARG3(arg),O_N,"nd_weyl_gr_trace");
3342: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3343: f = remove_zero_from_list(f);
3344: if ( !BDY(f) ) {
3345: *rp = f; do_weyl = 0; return;
3346: }
1.2 noro 3347: homo = ZTOS((Q)ARG2(arg));
3348: m = ZTOS((Q)ARG3(arg));
1.1 noro 3349: create_order_spec(0,ARG4(arg),&ord);
3350: } else if ( ac == 1 ) {
3351: f = (LIST)ARG0(arg);
3352: parse_gr_option(f,current_option,&v,&nhomo,&m,&ord);
1.2 noro 3353: homo = ZTOS((Q)nhomo);
1.1 noro 3354: } else
3355: error("nd_weyl_gr_trace : invalid argument");
1.9 noro 3356: retdp = 0;
3357: if ( get_opt("dp",&val) && val ) retdp = 1;
3358: nd_gr_trace(f,v,m,homo,retdp,0,ord,rp);
1.1 noro 3359: do_weyl = 0;
3360: }
3361:
3362: void Pnd_nf(NODE arg,Obj *rp)
3363: {
3364: Obj f;
3365: LIST g,v;
3366: struct order_spec *ord;
3367:
3368: do_weyl = 0;
3369: asir_assert(ARG1(arg),O_LIST,"nd_nf");
3370: asir_assert(ARG2(arg),O_LIST,"nd_nf");
3371: asir_assert(ARG4(arg),O_N,"nd_nf");
3372: f = (Obj)ARG0(arg);
3373: g = (LIST)ARG1(arg); g = remove_zero_from_list(g);
3374: if ( !BDY(g) ) {
3375: *rp = f; return;
3376: }
3377: v = (LIST)ARG2(arg);
3378: create_order_spec(0,ARG3(arg),&ord);
1.2 noro 3379: nd_nf_p(f,g,v,ZTOS((Q)ARG4(arg)),ord,rp);
1.1 noro 3380: }
3381:
3382: void Pnd_weyl_nf(NODE arg,Obj *rp)
3383: {
3384: Obj f;
3385: LIST g,v;
3386: struct order_spec *ord;
3387:
3388: do_weyl = 1;
3389: asir_assert(ARG1(arg),O_LIST,"nd_weyl_nf");
3390: asir_assert(ARG2(arg),O_LIST,"nd_weyl_nf");
3391: asir_assert(ARG4(arg),O_N,"nd_weyl_nf");
3392: f = (Obj)ARG0(arg);
3393: g = (LIST)ARG1(arg); g = remove_zero_from_list(g);
3394: if ( !BDY(g) ) {
3395: *rp = f; return;
3396: }
3397: v = (LIST)ARG2(arg);
3398: create_order_spec(0,ARG3(arg),&ord);
1.2 noro 3399: nd_nf_p(f,g,v,ZTOS((Q)ARG4(arg)),ord,rp);
1.1 noro 3400: }
3401:
3402: /* for Weyl algebra */
3403:
3404: void Pdp_weyl_gr_main(NODE arg,LIST *rp)
3405: {
3406: LIST f,v;
3407: Num homo;
3408: Z m,z;
3409: int modular,ac;
3410: struct order_spec *ord;
3411:
3412:
3413: asir_assert(ARG0(arg),O_LIST,"dp_weyl_gr_main");
3414: f = (LIST)ARG0(arg);
3415: f = remove_zero_from_list(f);
3416: if ( !BDY(f) ) {
3417: *rp = f; return;
3418: }
3419: if ( (ac = argc(arg)) == 5 ) {
3420: asir_assert(ARG1(arg),O_LIST,"dp_weyl_gr_main");
3421: asir_assert(ARG2(arg),O_N,"dp_weyl_gr_main");
3422: asir_assert(ARG3(arg),O_N,"dp_weyl_gr_main");
3423: v = (LIST)ARG1(arg);
3424: homo = (Num)ARG2(arg);
3425: m = (Z)ARG3(arg);
1.2 noro 3426: STOZ(0x80000000,z);
1.1 noro 3427: if ( !m )
3428: modular = 0;
3429: else if ( cmpz(m,z) >= 0 )
3430: error("dp_weyl_gr_main : too large modulus");
3431: else
1.2 noro 3432: modular = ZTOS(m);
1.1 noro 3433: create_order_spec(0,ARG4(arg),&ord);
3434: } else if ( current_option )
3435: parse_gr_option(f,current_option,&v,&homo,&modular,&ord);
3436: else if ( ac == 1 )
3437: parse_gr_option(f,0,&v,&homo,&modular,&ord);
3438: else
3439: error("dp_weyl_gr_main : invalid argument");
3440: do_weyl = 1;
3441: dp_gr_main(f,v,homo,modular,0,ord,rp);
3442: do_weyl = 0;
3443: }
3444:
3445: void Pdp_weyl_gr_f_main(NODE arg,LIST *rp)
3446: {
3447: LIST f,v;
3448: Num homo;
3449: struct order_spec *ord;
3450:
3451: asir_assert(ARG0(arg),O_LIST,"dp_weyl_gr_main");
3452: asir_assert(ARG1(arg),O_LIST,"dp_weyl_gr_main");
3453: asir_assert(ARG2(arg),O_N,"dp_weyl_gr_main");
3454: asir_assert(ARG3(arg),O_N,"dp_weyl_gr_main");
3455: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3456: f = remove_zero_from_list(f);
3457: if ( !BDY(f) ) {
3458: *rp = f; return;
3459: }
3460: homo = (Num)ARG2(arg);
3461: create_order_spec(0,ARG3(arg),&ord);
3462: do_weyl = 1;
3463: dp_gr_main(f,v,homo,0,1,ord,rp);
3464: do_weyl = 0;
3465: }
3466:
3467: void Pdp_weyl_f4_main(NODE arg,LIST *rp)
3468: {
3469: LIST f,v;
3470: struct order_spec *ord;
3471:
3472: asir_assert(ARG0(arg),O_LIST,"dp_weyl_f4_main");
3473: asir_assert(ARG1(arg),O_LIST,"dp_weyl_f4_main");
3474: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3475: f = remove_zero_from_list(f);
3476: if ( !BDY(f) ) {
3477: *rp = f; return;
3478: }
3479: create_order_spec(0,ARG2(arg),&ord);
3480: do_weyl = 1;
3481: dp_f4_main(f,v,ord,rp);
3482: do_weyl = 0;
3483: }
3484:
3485: void Pdp_weyl_f4_mod_main(NODE arg,LIST *rp)
3486: {
3487: LIST f,v;
3488: int m;
3489: struct order_spec *ord;
3490:
3491: asir_assert(ARG0(arg),O_LIST,"dp_weyl_f4_main");
3492: asir_assert(ARG1(arg),O_LIST,"dp_weyl_f4_main");
3493: asir_assert(ARG2(arg),O_N,"dp_f4_main");
1.2 noro 3494: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg); m = ZTOS((Q)ARG2(arg));
1.1 noro 3495: f = remove_zero_from_list(f);
3496: if ( !BDY(f) ) {
3497: *rp = f; return;
3498: }
3499: if ( !m )
3500: error("dp_weyl_f4_mod_main : invalid argument");
3501: create_order_spec(0,ARG3(arg),&ord);
3502: do_weyl = 1;
3503: dp_f4_mod_main(f,v,m,ord,rp);
3504: do_weyl = 0;
3505: }
3506:
3507: void Pdp_weyl_gr_mod_main(NODE arg,LIST *rp)
3508: {
3509: LIST f,v;
3510: Num homo;
3511: int m;
3512: struct order_spec *ord;
3513:
3514: asir_assert(ARG0(arg),O_LIST,"dp_weyl_gr_mod_main");
3515: asir_assert(ARG1(arg),O_LIST,"dp_weyl_gr_mod_main");
3516: asir_assert(ARG2(arg),O_N,"dp_weyl_gr_mod_main");
3517: asir_assert(ARG3(arg),O_N,"dp_weyl_gr_mod_main");
3518: f = (LIST)ARG0(arg); v = (LIST)ARG1(arg);
3519: f = remove_zero_from_list(f);
3520: if ( !BDY(f) ) {
3521: *rp = f; return;
3522: }
1.2 noro 3523: homo = (Num)ARG2(arg); m = ZTOS((Q)ARG3(arg));
1.1 noro 3524: if ( !m )
3525: error("dp_weyl_gr_mod_main : invalid argument");
3526: create_order_spec(0,ARG4(arg),&ord);
3527: do_weyl = 1;
3528: dp_gr_mod_main(f,v,homo,m,ord,rp);
3529: do_weyl = 0;
3530: }
3531:
3532: VECT current_dl_weight_vector_obj;
3533: int *current_dl_weight_vector;
3534: int dp_negative_weight;
3535:
3536: void Pdp_set_weight(NODE arg,VECT *rp)
3537: {
3538: VECT v;
3539: int i,n;
3540: NODE node;
3541:
3542: if ( !arg )
3543: *rp = current_dl_weight_vector_obj;
3544: else if ( !ARG0(arg) ) {
3545: current_dl_weight_vector_obj = 0;
3546: current_dl_weight_vector = 0;
3547: dp_negative_weight = 0;
3548: *rp = 0;
3549: } else {
3550: if ( OID(ARG0(arg)) != O_VECT && OID(ARG0(arg)) != O_LIST )
3551: error("dp_set_weight : invalid argument");
3552: if ( OID(ARG0(arg)) == O_VECT )
3553: v = (VECT)ARG0(arg);
3554: else {
3555: node = (NODE)BDY((LIST)ARG0(arg));
3556: n = length(node);
3557: MKVECT(v,n);
3558: for ( i = 0; i < n; i++, node = NEXT(node) )
3559: BDY(v)[i] = BDY(node);
3560: }
3561: current_dl_weight_vector_obj = v;
3562: n = v->len;
3563: current_dl_weight_vector = (int *)CALLOC(n,sizeof(int));
3564: for ( i = 0; i < n; i++ )
1.2 noro 3565: current_dl_weight_vector[i] = ZTOS((Q)v->body[i]);
1.1 noro 3566: for ( i = 0; i < n; i++ )
3567: if ( current_dl_weight_vector[i] < 0 ) break;
3568: if ( i < n )
3569: dp_negative_weight = 1;
3570: else
3571: dp_negative_weight = 0;
3572: *rp = v;
3573: }
3574: }
3575:
3576: VECT current_module_weight_vector_obj;
3577: int *current_module_weight_vector;
3578:
3579: void Pdp_set_module_weight(NODE arg,VECT *rp)
3580: {
3581: VECT v;
3582: int i,n;
3583: NODE node;
3584:
3585: if ( !arg )
3586: *rp = current_module_weight_vector_obj;
3587: else if ( !ARG0(arg) ) {
3588: current_module_weight_vector_obj = 0;
3589: current_module_weight_vector = 0;
3590: *rp = 0;
3591: } else {
3592: if ( OID(ARG0(arg)) != O_VECT && OID(ARG0(arg)) != O_LIST )
3593: error("dp_module_set_weight : invalid argument");
3594: if ( OID(ARG0(arg)) == O_VECT )
3595: v = (VECT)ARG0(arg);
3596: else {
3597: node = (NODE)BDY((LIST)ARG0(arg));
3598: n = length(node);
3599: MKVECT(v,n);
3600: for ( i = 0; i < n; i++, node = NEXT(node) )
3601: BDY(v)[i] = BDY(node);
3602: }
3603: current_module_weight_vector_obj = v;
3604: n = v->len;
3605: current_module_weight_vector = (int *)CALLOC(n,sizeof(int));
3606: for ( i = 0; i < n; i++ )
1.2 noro 3607: current_module_weight_vector[i] = ZTOS((Q)v->body[i]);
1.1 noro 3608: *rp = v;
3609: }
3610: }
3611:
3612: extern Obj current_top_weight;
3613: extern Obj nd_top_weight;
3614:
3615: void Pdp_set_top_weight(NODE arg,Obj *rp)
3616: {
3617: VECT v;
3618: MAT m;
3619: Obj obj;
3620: int i,j,n,id,row,col;
3621: Q *mi;
3622: NODE node;
3623:
3624: if ( !arg )
3625: *rp = current_top_weight;
3626: else if ( !ARG0(arg) ) {
3627: reset_top_weight();
3628: *rp = 0;
3629: } else {
3630: id = OID(ARG0(arg));
3631: if ( id != O_VECT && id != O_MAT && id != O_LIST )
3632: error("dp_set_top_weight : invalid argument");
3633: if ( id == O_LIST ) {
3634: node = (NODE)BDY((LIST)ARG0(arg));
3635: n = length(node);
3636: MKVECT(v,n);
3637: for ( i = 0; i < n; i++, node = NEXT(node) )
3638: BDY(v)[i] = BDY(node);
3639: obj = (Obj)v;
3640: } else
3641: obj = ARG0(arg);
3642: if ( OID(obj) == O_VECT ) {
3643: v = (VECT)obj;
3644: for ( i = 0; i < v->len; i++ )
3645: if ( !INT((Q)BDY(v)[i]) || sgnz((Z)BDY(v)[i]) < 0 )
3646: error("dp_set_top_weight : each element must be a non-negative integer");
3647: } else {
3648: m = (MAT)obj; row = m->row; col = m->col;
3649: for ( i = 0; i < row; i++ )
3650: for ( j = 0, mi = (Q *)BDY(m)[i]; j < col; j++ )
3651: if ( !INT((Q)mi[j]) || sgnz((Z)mi[j]) < 0 )
3652: error("dp_set_top_weight : each element must be a non-negative integer");
3653: }
3654: current_top_weight = obj;
3655: nd_top_weight = obj;
3656: *rp = current_top_weight;
3657: }
3658: }
3659:
3660: LIST get_denomlist();
3661:
3662: void Pdp_get_denomlist(LIST *rp)
3663: {
3664: *rp = get_denomlist();
3665: }
3666:
3667: static VECT current_weyl_weight_vector_obj;
3668: int *current_weyl_weight_vector;
3669:
3670: void Pdp_weyl_set_weight(NODE arg,VECT *rp)
3671: {
3672: VECT v;
3673: NODE node;
3674: int i,n;
3675:
3676: if ( !arg )
3677: *rp = current_weyl_weight_vector_obj;
3678: else if ( !ARG0(arg) ) {
3679: current_weyl_weight_vector_obj = 0;
3680: current_weyl_weight_vector = 0;
3681: *rp = 0;
3682: } else {
3683: if ( OID(ARG0(arg)) != O_VECT && OID(ARG0(arg)) != O_LIST )
3684: error("dp_weyl_set_weight : invalid argument");
3685: if ( OID(ARG0(arg)) == O_VECT )
3686: v = (VECT)ARG0(arg);
3687: else {
3688: node = (NODE)BDY((LIST)ARG0(arg));
3689: n = length(node);
3690: MKVECT(v,n);
3691: for ( i = 0; i < n; i++, node = NEXT(node) )
3692: BDY(v)[i] = BDY(node);
3693: }
3694: current_weyl_weight_vector_obj = v;
3695: n = v->len;
3696: current_weyl_weight_vector = (int *)CALLOC(n,sizeof(int));
3697: for ( i = 0; i < n; i++ )
1.2 noro 3698: current_weyl_weight_vector[i] = ZTOS((Q)v->body[i]);
1.1 noro 3699: *rp = v;
3700: }
3701: }
3702:
3703: NODE mono_raddec(NODE ideal);
3704:
3705: void Pdp_mono_raddec(NODE arg,LIST *rp)
3706: {
3707: NODE ideal,rd,t,t1,r,r1,u;
3708: VL vl0,vl;
3709: int nv,i,bpi;
3710: int *s;
3711: DP dp;
3712: P *v;
3713: LIST l;
3714:
3715: ideal = BDY((LIST)ARG0(arg));
3716: if ( !ideal ) *rp = (LIST)ARG0(arg);
3717: else {
3718: t = BDY((LIST)ARG1(arg));
3719: nv = length(t);
3720: v = (P *)MALLOC(nv*sizeof(P));
3721: for ( vl0 = 0, i = 0; t; t = NEXT(t), i++ ) {
3722: NEXTVL(vl0,vl); VR(vl) = VR((P)BDY(t));
3723: MKV(VR(vl),v[i]);
3724: }
3725: if ( vl0 ) NEXT(vl) = 0;
3726: for ( t = 0, r = ideal; r; r = NEXT(r) ) {
3727: ptod(CO,vl0,BDY(r),&dp); MKNODE(t1,dp,t); t = t1;
3728: }
3729: rd = mono_raddec(t);
3730: r = 0;
3731: bpi = (sizeof(int)/sizeof(char))*8;
3732: for ( u = rd; u; u = NEXT(u) ) {
3733: s = (int *)BDY(u);
3734: for ( i = nv-1, t = 0; i >= 0; i-- )
3735: if ( s[i/bpi]&(1<<(i%bpi)) ) {
3736: MKNODE(t1,v[i],t); t = t1;
3737: }
3738: MKLIST(l,t); MKNODE(r1,l,r); r = r1;
3739: }
3740: MKLIST(*rp,r);
3741: }
3742: }
3743:
3744: void Pdp_mono_reduce(NODE arg,LIST *rp)
3745: {
3746: NODE t,t0,t1,r0,r;
3747: int i,n;
3748: DP m;
3749: DP *a;
3750:
3751: t0 = BDY((LIST)ARG0(arg));
3752: t1 = BDY((LIST)ARG1(arg));
3753: n = length(t0);
3754: a = (DP *)MALLOC(n*sizeof(DP));
3755: for ( i = 0; i < n; i++, t0 = NEXT(t0) ) a[i] = (DP)BDY(t0);
3756: for ( t = t1; t; t = NEXT(t) ) {
3757: m = (DP)BDY(t);
3758: for ( i = 0; i < n; i++ )
3759: if ( a[i] && dp_redble(a[i],m) ) a[i] = 0;
3760: }
3761: for ( i = n-1, r0 = 0; i >= 0; i-- )
3762: if ( a[i] ) { NEXTNODE(r0,r); BDY(r) = a[i]; }
3763: if ( r0 ) NEXT(r) = 0;
3764: MKLIST(*rp,r0);
3765: }
3766:
3767: #define BLEN (8*sizeof(unsigned long))
3768:
3769: void showmat2(unsigned long **a,int row,int col)
3770: {
3771: int i,j;
3772:
3773: for ( i = 0; i < row; i++, putchar('\n') )
3774: for ( j = 0; j < col; j++ )
3775: if ( a[i][j/BLEN] & (1L<<(j%BLEN)) ) putchar('1');
3776: else putchar('0');
3777: }
3778:
3779: int rref2(unsigned long **a,int row,int col)
3780: {
3781: int i,j,k,l,s,wcol,wj;
3782: unsigned long bj;
3783: unsigned long *ai,*ak,*as,*t;
3784: int *pivot;
3785:
3786: wcol = (col+BLEN-1)/BLEN;
3787: pivot = (int *)MALLOC_ATOMIC(row*sizeof(int));
3788: i = 0;
3789: for ( j = 0; j < col; j++ ) {
3790: wj = j/BLEN; bj = 1L<<(j%BLEN);
3791: for ( k = i; k < row; k++ )
3792: if ( a[k][wj] & bj ) break;
3793: if ( k == row ) continue;
3794: pivot[i] = j;
3795: if ( k != i ) {
3796: t = a[i]; a[i] = a[k]; a[k] = t;
3797: }
3798: ai = a[i];
3799: for ( k = i+1; k < row; k++ ) {
3800: ak = a[k];
3801: if ( ak[wj] & bj ) {
3802: for ( l = wj; l < wcol; l++ )
3803: ak[l] ^= ai[l];
3804: }
3805: }
3806: i++;
3807: }
3808: for ( k = i-1; k >= 0; k-- ) {
3809: j = pivot[k]; wj = j/BLEN; bj = 1L<<(j%BLEN);
3810: ak = a[k];
3811: for ( s = 0; s < k; s++ ) {
3812: as = a[s];
3813: if ( as[wj] & bj ) {
3814: for ( l = wj; l < wcol; l++ )
3815: as[l] ^= ak[l];
3816: }
3817: }
3818: }
3819: return i;
3820: }
3821:
3822: void Pdp_rref2(NODE arg,VECT *rp)
3823: {
3824: VECT f,term,ret;
3825: int row,col,wcol,size,nv,i,j,rank,td;
3826: unsigned long **mat;
3827: unsigned long *v;
3828: DL d;
3829: DL *t;
3830: DP dp;
3831: MP m,m0;
3832:
3833: f = (VECT)ARG0(arg);
3834: row = f->len;
3835: term = (VECT)ARG1(arg);
3836: col = term->len;
3837: mat = (unsigned long **)MALLOC(row*sizeof(unsigned long *));
3838: size = sizeof(unsigned long)*((col+BLEN-1)/BLEN);
3839: nv = ((DP)term->body[0])->nv;
3840: t = (DL *)MALLOC(col*sizeof(DL));
3841: for ( i = 0; i < col; i++ ) t[i] = BDY((DP)BDY(term)[i])->dl;
3842: for ( i = 0; i < row; i++ ) {
3843: v = mat[i] = (unsigned long *)MALLOC_ATOMIC_IGNORE_OFF_PAGE(size);
3844: bzero(v,size);
3845: for ( j = 0, m = BDY((DP)BDY(f)[i]); m; m = NEXT(m) ) {
3846: d = m->dl;
3847: for ( ; !dl_equal(nv,d,t[j]); j++ );
3848: v[j/BLEN] |= 1L <<(j%BLEN);
3849: }
3850: }
3851: rank = rref2(mat,row,col);
3852: MKVECT(ret,rank);
3853: *rp = ret;
3854: for ( i = 0; i < rank; i++ ) {
3855: v = mat[i];
3856: m0 = 0;
3857: td = 0;
3858: for ( j = 0; j < col; j++ ) {
3859: if ( v[j/BLEN] & (1L<<(j%BLEN)) ) {
3860: NEXTMP(m0,m);
3861: m->dl = t[j];
3862: m->c = (Obj)ONE;
3863: td = MAX(td,m->dl->td);
3864: }
3865: }
3866: NEXT(m) = 0;
3867: MKDP(nv,m0,dp);
3868: dp->sugar = td;
3869: BDY(ret)[i] = (pointer)dp;
3870: }
3871: }
3872:
3873: #define HDL(f) (BDY(f)->dl)
3874:
3875: NODE sumi_criB(int nv,NODE d,DP *f,int m)
3876: {
3877: LIST p;
3878: NODE r0,r;
3879: int p0,p1;
3880: DL p2,lcm;
3881:
3882: NEWDL(lcm,nv);
3883: r0 = 0;
3884: for ( ; d; d = NEXT(d) ) {
3885: p = (LIST)BDY(d);
1.2 noro 3886: p0 = ZTOS((Q)ARG0(BDY(p)));
3887: p1 = ZTOS((Q)ARG1(BDY(p)));
1.1 noro 3888: p2 = HDL((DP)ARG2(BDY(p)));
3889: if(!_dl_redble(HDL((DP)f[m]),p2,nv) ||
3890: dl_equal(nv,lcm_of_DL(nv,HDL(f[p0]),HDL(f[m]),lcm),p2) ||
3891: dl_equal(nv,lcm_of_DL(nv,HDL(f[p1]),HDL(f[m]),lcm),p2) ) {
3892: NEXTNODE(r0,r);
3893: BDY(r) = p;
3894: }
3895: }
3896: if ( r0 ) NEXT(r) = 0;
3897: return r0;
3898: }
3899:
3900: NODE sumi_criFMD(int nv,DP *f,int m)
3901: {
3902: DL *a;
3903: DL l1,dl1,dl2;
3904: int i,j,k,k2;
3905: NODE r,r1,nd;
3906: MP mp;
3907: DP u;
3908: Z iq,mq;
3909: LIST list;
3910:
3911: /* a[i] = lcm(LT(f[i]),LT(f[m])) */
3912: a = (DL *)ALLOCA(m*sizeof(DL));
3913: for ( i = 0; i < m; i++ ) {
3914: a[i] = lcm_of_DL(nv,HDL(f[i]),HDL(f[m]),0);
3915: }
3916: r = 0;
3917: for( i = 0; i < m; i++) {
3918: l1 = a[i];
3919: if ( !l1 ) continue;
3920: /* Tkm = Tim (k<i) */
3921: for( k = 0; k < i; k++)
3922: if( dl_equal(nv,l1,a[k]) ) break;
3923: if( k == i ){
3924: /* Tk|Tim && Tkm != Tim (k<m) */
3925: for ( k2 = 0; k2 < m; k2++ )
3926: if ( _dl_redble(HDL(f[k2]),l1,nv) &&
3927: !dl_equal(nv,l1,a[k2]) ) break;
3928: if ( k2 == m ) {
3929: dl1 = HDL(f[i]); dl2 = HDL(f[m]);
3930: for ( k2 = 0; k2 < nv; k2++ )
3931: if ( dl1->d[k2] && dl2->d[k2] ) break;
3932: if ( k2 < nv ) {
3933: NEWMP(mp); mp->dl = l1; C(mp) = (Obj)ONE;
3934: NEXT(mp) = 0; MKDP(nv,mp,u); u->sugar = l1->td;
1.2 noro 3935: STOZ(i,iq); STOZ(m,mq);
1.1 noro 3936: nd = mknode(3,iq,mq,u);
3937: MKLIST(list,nd);
3938: MKNODE(r1,list,r);
3939: r = r1;
3940: }
3941: }
3942: }
3943: }
3944: return r;
3945: }
3946:
3947: LIST sumi_updatepairs(LIST d,DP *f,int m)
3948: {
3949: NODE old,new,t;
3950: LIST l;
3951: int nv;
3952:
3953: nv = f[0]->nv;
3954: old = sumi_criB(nv,BDY(d),f,m);
3955: new = sumi_criFMD(nv,f,m);
3956: if ( !new ) new = old;
3957: else {
3958: for ( t = new ; NEXT(t); t = NEXT(t) );
3959: NEXT(t) = old;
3960: }
3961: MKLIST(l,new);
3962: return l;
3963: }
3964:
3965: VECT ltov(LIST l)
3966: {
3967: NODE n;
3968: int i,len;
3969: VECT v;
3970:
3971: n = BDY(l);
3972: len = length(n);
3973: MKVECT(v,len);
3974: for ( i = 0; i < len; i++, n = NEXT(n) )
3975: BDY(v)[i] = BDY(n);
3976: return v;
3977: }
3978:
3979: DL subdl(int nv,DL d1,DL d2)
3980: {
3981: int i;
3982: DL d;
3983:
3984: NEWDL(d,nv);
3985: d->td = d1->td-d2->td;
3986: for ( i = 0; i < nv; i++ )
3987: d->d[i] = d1->d[i]-d2->d[i];
3988: return d;
3989: }
3990:
3991: DP dltodp(int nv,DL d)
3992: {
3993: MP mp;
3994: DP dp;
3995:
3996: NEWMP(mp); mp->dl = d; C(mp) = (Obj)ONE;
3997: NEXT(mp) = 0; MKDP(nv,mp,dp); dp->sugar = d->td;
3998: return dp;
3999: }
4000:
4001: LIST sumi_simplify(int nv,DL t,DP p,NODE f2,int simp)
4002: {
4003: DL d,h,hw;
4004: DP u,w,dp;
4005: int n,i,last;
4006: LIST *v;
4007: LIST list;
4008: NODE s,r;
4009:
4010: d = t; u = p;
4011: /* only the last history is used */
4012: if ( f2 && simp && t->td != 0 ) {
4013: adddl(nv,t,HDL(p),&h);
4014: n = length(f2);
4015: last = 1;
4016: if ( simp > 1 ) last = n;
4017: v = (LIST *)ALLOCA(n*sizeof(LIST));
4018: for ( r = f2, i = 0; r; r = NEXT(r), i++ ) v[n-i-1] = BDY(r);
4019: for ( i = 0; i < last; i++ ) {
4020: for ( s = BDY((LIST)v[i]); s; s = NEXT(s) ) {
4021: w = (DP)BDY(s); hw = HDL(w);
4022: if ( _dl_redble(hw,h,nv) ) {
4023: u = w;
4024: d = subdl(nv,h,hw);
4025: goto fin;
4026: }
4027: }
4028: }
4029: }
4030: fin:
4031: dp = dltodp(nv,d);
4032: r = mknode(2,dp,u);
4033: MKLIST(list,r);
4034: return list;
4035: }
4036:
4037: LIST sumi_symbolic(NODE l,int q,NODE f2,DP *g,int simp)
4038: {
4039: int nv;
4040: NODE t,r;
4041: NODE f0,f,fd0,fd,done0,done,red0,red;
4042: DL h,d;
4043: DP mul;
4044: int m;
4045: LIST tp,l0,l1,l2,l3,list;
4046: VECT v0,v1,v2,v3;
4047:
4048: nv = ((DP)BDY(l))->nv;
4049: t = 0;
4050:
4051: f0 = 0; fd0 = 0; done0 = 0; red0 = 0;
4052:
4053: for ( ; l; l = NEXT(l) ) {
4054: t = symb_merge(t,dp_dllist((DP)BDY(l)),nv);
4055: NEXTNODE(fd0,fd); BDY(fd) = BDY(l);
4056: }
4057:
4058: while ( t ) {
4059: h = (DL)BDY(t);
4060: NEXTNODE(done0,done); BDY(done) = dltodp(nv,h);
4061: t = NEXT(t);
4062: for(m = 0; m < q; m++)
4063: if ( _dl_redble(HDL(g[m]),h,nv) ) break;
4064: if ( m == q ) {
4065: } else {
4066: d = subdl(nv,h,HDL(g[m]));
4067: tp = sumi_simplify(nv,d,g[m],f2,simp);
4068:
4069: muldm(CO,ARG1(BDY(tp)),BDY((DP)ARG0(BDY(tp))),&mul);
4070: t = symb_merge(t,NEXT(dp_dllist(mul)),nv);
4071:
4072: NEXTNODE(f0,f); BDY(f) = tp;
4073: NEXTNODE(fd0,fd); BDY(fd) = mul;
4074: NEXTNODE(red0,red); BDY(red) = mul;
4075: }
4076: }
4077: if ( fd0 ) NEXT(fd) = 0; MKLIST(l0,fd0);
4078: v0 = ltov(l0);
4079: if ( done0 ) NEXT(done) = 0; MKLIST(l1,done0);
4080: v1 = ltov(l1);
4081: if ( f0 ) NEXT(f) = 0; MKLIST(l2,f0);
4082: v2 = ltov(l2);
4083: if ( red0 ) NEXT(red) = 0; MKLIST(l3,red0);
4084: v3 = ltov(l3);
4085: r = mknode(4,v0,v1,v2,v3);
4086: MKLIST(list,r);
4087: return list;
4088: }
4089:
4090: void Psumi_symbolic(NODE arg,LIST *rp)
4091: {
4092: NODE l,f2;
4093: DP *g;
4094: int q,simp;
4095:
4096: l = BDY((LIST)ARG0(arg));
1.2 noro 4097: q = ZTOS((Q)ARG1(arg));
1.1 noro 4098: f2 = BDY((LIST)ARG2(arg));
4099: g = (DP *)BDY((VECT)ARG3(arg));
1.2 noro 4100: simp = ZTOS((Q)ARG4(arg));
1.1 noro 4101: *rp = sumi_symbolic(l,q,f2,g,simp);
4102: }
4103:
4104: void Psumi_updatepairs(NODE arg,LIST *rp)
4105: {
4106: LIST d,l;
4107: DP *f;
4108: int m;
4109:
4110: d = (LIST)ARG0(arg);
4111: f = (DP *)BDY((VECT)ARG1(arg));
1.2 noro 4112: m = ZTOS((Q)ARG2(arg));
1.1 noro 4113: *rp = sumi_updatepairs(d,f,m);
4114: }
4115:
4116: LIST remove_zero_from_list(LIST l)
4117: {
4118: NODE n,r0,r;
4119: LIST rl;
4120:
4121: asir_assert(l,O_LIST,"remove_zero_from_list");
4122: n = BDY(l);
4123: for ( r0 = 0; n; n = NEXT(n) )
4124: if ( BDY(n) ) {
4125: NEXTNODE(r0,r);
4126: BDY(r) = BDY(n);
4127: }
4128: if ( r0 )
4129: NEXT(r) = 0;
4130: MKLIST(rl,r0);
4131: return rl;
4132: }
4133:
4134: int get_field_type(P p)
4135: {
4136: int type,t;
4137: DCP dc;
4138:
4139: if ( !p )
4140: return 0;
4141: else if ( NUM(p) )
4142: return NID((Num)p);
4143: else {
4144: type = 0;
4145: for ( dc = DC(p); dc; dc = NEXT(dc) ) {
4146: t = get_field_type(COEF(dc));
4147: if ( !t )
4148: continue;
4149: if ( t < 0 )
4150: return t;
4151: if ( !type )
4152: type = t;
4153: else if ( t != type )
4154: return -1;
4155: }
4156: return type;
4157: }
4158: }
4159:
4160: void Pdpv_ord(NODE arg,Obj *rp)
4161: {
4162: int ac,id;
4163: LIST shift;
4164:
4165: ac = argc(arg);
4166: if ( ac ) {
1.2 noro 4167: id = ZTOS((Q)ARG0(arg));
1.1 noro 4168: if ( ac > 1 && ARG1(arg) && OID((Obj)ARG1(arg))==O_LIST )
4169: shift = (LIST)ARG1(arg);
4170: else
4171: shift = 0;
4172: create_modorder_spec(id,shift,&dp_current_modspec);
4173: }
4174: *rp = dp_current_modspec->obj;
4175: }
4176:
1.9 noro 4177: extern int dpm_ordtype;
1.15 noro 4178: extern DMMstack dmm_stack;
1.9 noro 4179:
1.11 noro 4180: void set_schreyer_order(LIST n);
1.1 noro 4181:
1.10 noro 4182: void Pdpm_set_schreyer(NODE arg,LIST *rp)
1.1 noro 4183: {
1.9 noro 4184: if ( argc(arg) ) {
1.17 noro 4185: set_schreyer_order(ARG0(arg)?(LIST)ARG0(arg):0);
1.1 noro 4186: }
1.17 noro 4187: if ( dmm_stack )
4188: *rp = dmm_stack->obj;
4189: else
4190: *rp = 0;
1.1 noro 4191: }
4192:
1.18 noro 4193: DMMstack_array Schreyer_Frame;
1.23 noro 4194: DMMstack_array dpm_schreyer_frame(NODE n,int lex);
1.18 noro 4195: void set_schreyer_level(DMMstack_array array,int level);
4196:
4197: void Pdpm_set_schreyer_level(NODE arg,Q *rp)
4198: {
4199: set_schreyer_level(Schreyer_Frame,ZTOS((Q)ARG0(arg)));
4200: *rp = (Q)ARG0(arg);
4201: }
4202:
4203: void Pdpm_schreyer_frame(NODE arg,LIST *rp)
4204: {
4205: DMMstack_array a;
4206: DMMstack *body;
1.20 noro 4207: DMM *in,*sum;
4208: DPM f,s;
4209: NODE b,b1,nd;
1.18 noro 4210: LIST l;
1.20 noro 4211: VECT v;
4212: Z lev,deg,ind;
1.23 noro 4213: int len,i,nv,rank,j,lex;
4214: NODE tt,p;
4215: char *key;
4216: Obj value;
1.18 noro 4217:
1.23 noro 4218: lex = 0;
4219: if ( current_option ) {
4220: for ( tt = current_option; tt; tt = NEXT(tt) ) {
4221: p = BDY((LIST)BDY(tt));
4222: key = BDY((STRING)BDY(p));
4223: value = (Obj)BDY(NEXT(p));
4224: if ( !strcmp(key,"lex") )
4225: lex = value!=0?1:0;
4226: else {
4227: error("dpm_schreyer_frame: unknown option.");
4228: }
4229: }
4230: }
4231: Schreyer_Frame = a = dpm_schreyer_frame(BDY((LIST)ARG0(arg)),lex);
1.18 noro 4232: len = a->len;
4233: body = a->body;
1.20 noro 4234: /* XXX */
4235: nv = ((DPM)BDY(BDY((LIST)body[0]->obj)))->nv;
1.18 noro 4236: b = 0;
4237: for ( i = 0; i < len; i++ ) {
1.20 noro 4238: rank = body[i]->rank;
4239: in = body[i]->in;
4240: sum = body[i]->sum;
4241: MKVECT(v,rank+1);
4242: STOZ(i+1,lev);
4243: for ( j = 1; j <= rank; j++ ) {
4244: MKDPM(nv,in[j],f); f->sugar = in[j]->dl->td;
4245: MKDPM(nv,sum[j],s);s->sugar = sum[j]->dl->td;
4246: STOZ(s->sugar,deg);
4247: STOZ(j,ind);
4248: nd = mknode(5,f,s,ind,lev,deg);
4249: MKLIST(l,nd);
4250: BDY(v)[j] = (pointer)l;
4251: }
4252: MKNODE(b1,(pointer)v,b);
1.18 noro 4253: b = b1;
4254: }
4255: MKLIST(l,b);
4256: *rp = l;
4257: }
4258:
4259:
1.1 noro 4260: void Pdpm_hm(NODE arg,DPM *rp)
4261: {
4262: DPM p;
4263:
4264: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_hm");
4265: dpm_hm(p,rp);
4266: }
4267:
4268: void Pdpm_ht(NODE arg,DPM *rp)
4269: {
4270: DPM p;
4271:
1.9 noro 4272: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_ht");
1.1 noro 4273: dpm_ht(p,rp);
4274: }
4275:
1.10 noro 4276: void dpm_rest(DPM p,DPM *r);
4277:
4278: void Pdpm_rest(NODE arg,DPM *rp)
4279: {
4280: DPM p;
4281:
4282: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_ht");
4283: dpm_rest(p,rp);
4284: }
4285:
4286:
4287: void Pdpm_hp(NODE arg,Z *rp)
4288: {
4289: DPM p;
4290: int pos;
4291:
4292: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_ht");
4293: pos = BDY(p)->pos;
4294: STOZ(pos,*rp);
4295: }
4296:
1.9 noro 4297: void dpm_shift(DPM p,int s,DPM *rp);
4298:
4299: void Pdpm_shift(NODE arg,DPM *rp)
4300: {
4301: DPM p;
4302: int s;
4303:
4304: p = (DPM)ARG0(arg); asir_assert(p,O_DPM,"dpm_shift");
4305: s = ZTOS((Z)ARG1(arg));
4306: dpm_shift(p,s,rp);
4307: }
4308:
4309: void dpm_sort(DPM p,DPM *rp);
4310:
4311: void Pdpm_sort(NODE arg,DPM *rp)
4312: {
4313: DPM p;
4314: int s;
4315:
1.10 noro 4316: p = (DPM)ARG0(arg);
4317: if ( !p ) *rp = 0;
1.21 noro 4318: else dpm_sort(p,rp);
1.9 noro 4319: }
4320:
4321: void dpm_split(DPM p,int s,DPM *up,DPM *lo);
1.21 noro 4322: void dpm_extract(DPM p,int s,DP *r);
1.9 noro 4323:
4324: void Pdpm_split(NODE arg,LIST *rp)
4325: {
4326: DPM p,up,lo;
4327: int s;
4328: NODE nd;
4329:
1.10 noro 4330: p = (DPM)ARG0(arg);
1.9 noro 4331: s = ZTOS((Z)ARG1(arg));
4332: dpm_split(p,s,&up,&lo);
4333: nd = mknode(2,up,lo);
4334: MKLIST(*rp,nd);
4335: }
4336:
1.21 noro 4337: void Pdpm_extract(NODE arg,DP *rp)
4338: {
4339: DPM p;
4340: int s;
4341:
4342: p = (DPM)ARG0(arg);
4343: s = ZTOS((Z)ARG1(arg));
4344: dpm_extract(p,s,rp);
4345: }
4346:
1.9 noro 4347:
1.13 noro 4348: void Pdpm_hc(NODE arg,DP *rp)
1.1 noro 4349: {
1.13 noro 4350: DPM p;
4351: DP d;
4352: MP m;
4353:
1.1 noro 4354: asir_assert(ARG0(arg),O_DPM,"dpm_hc");
4355: if ( !ARG0(arg) )
4356: *rp = 0;
1.13 noro 4357: else {
4358: p = (DPM)ARG0(arg);
4359: NEWMP(m);
4360: m->dl = BDY(p)->dl;
4361: m->c = BDY(p)->c;
4362: NEXT(m) = 0;
4363: MKDP(NV(p),m,d); d->sugar = p->sugar;
4364: *rp = d;
4365: }
1.1 noro 4366: }
4367:
4368: void Pdpv_ht(NODE arg,LIST *rp)
4369: {
4370: NODE n;
4371: DP ht;
4372: int pos;
4373: DPV p;
4374: Z q;
4375:
4376: asir_assert(ARG0(arg),O_DPV,"dpv_ht");
4377: p = (DPV)ARG0(arg);
4378: pos = dpv_hp(p);
4379: if ( pos < 0 )
4380: ht = 0;
4381: else
4382: dp_ht(BDY(p)[pos],&ht);
1.2 noro 4383: STOZ(pos,q);
1.1 noro 4384: n = mknode(2,q,ht);
4385: MKLIST(*rp,n);
4386: }
4387:
4388: void Pdpv_hm(NODE arg,LIST *rp)
4389: {
4390: NODE n;
4391: DP ht;
4392: int pos;
4393: DPV p;
4394: Z q;
4395:
4396: asir_assert(ARG0(arg),O_DPV,"dpv_hm");
4397: p = (DPV)ARG0(arg);
4398: pos = dpv_hp(p);
4399: if ( pos < 0 )
4400: ht = 0;
4401: else
4402: dp_hm(BDY(p)[pos],&ht);
1.2 noro 4403: STOZ(pos,q);
1.1 noro 4404: n = mknode(2,q,ht);
4405: MKLIST(*rp,n);
4406: }
4407:
4408: void Pdpv_hc(NODE arg,LIST *rp)
4409: {
4410: NODE n;
4411: P hc;
4412: int pos;
4413: DPV p;
4414: Z q;
4415:
4416: asir_assert(ARG0(arg),O_DPV,"dpv_hc");
4417: p = (DPV)ARG0(arg);
4418: pos = dpv_hp(p);
4419: if ( pos < 0 )
4420: hc = 0;
4421: else
4422: hc = (P)BDY(BDY(p)[pos])->c;
1.2 noro 4423: STOZ(pos,q);
1.1 noro 4424: n = mknode(2,q,hc);
4425: MKLIST(*rp,n);
4426: }
4427:
4428: int dpv_hp(DPV p)
4429: {
4430: int len,i,maxp,maxw,w,slen;
4431: int *shift;
4432: DP *e;
4433:
4434: len = p->len;
4435: e = p->body;
4436: slen = dp_current_modspec->len;
4437: shift = dp_current_modspec->degree_shift;
4438: switch ( dp_current_modspec->id ) {
4439: case ORD_REVGRADLEX:
4440: for ( maxp = -1, i = 0; i < len; i++ )
4441: if ( !e[i] ) continue;
4442: else if ( maxp < 0 ) {
4443: maxw = BDY(e[i])->dl->td+(i<slen?shift[i]:0); maxp = i;
4444: } else {
4445: w = BDY(e[i])->dl->td+(i<slen?shift[i]:0);
4446: if ( w >= maxw ) {
4447: maxw = w; maxp = i;
4448: }
4449: }
4450: return maxp;
4451: case ORD_GRADLEX:
4452: for ( maxp = -1, i = 0; i < len; i++ )
4453: if ( !e[i] ) continue;
4454: else if ( maxp < 0 ) {
4455: maxw = BDY(e[i])->dl->td+(i<slen?shift[i]:0); maxp = i;
4456: } else {
4457: w = BDY(e[i])->dl->td+(i<slen?shift[i]:0);
4458: if ( w > maxw ) {
4459: maxw = w; maxp = i;
4460: }
4461: }
4462: return maxp;
4463: break;
4464: case ORD_LEX:
4465: for ( i = 0; i < len; i++ )
4466: if ( e[i] ) return i;
4467: return -1;
4468: break;
1.9 noro 4469: default:
4470: error("dpv_hp : unsupported term ordering");
4471: return -1;
4472: break;
1.1 noro 4473: }
4474: }
4475:
4476: int get_opt(char *key0,Obj *r) {
4477: NODE tt,p;
4478: char *key;
4479:
4480: if ( current_option ) {
4481: for ( tt = current_option; tt; tt = NEXT(tt) ) {
4482: p = BDY((LIST)BDY(tt));
4483: key = BDY((STRING)BDY(p));
4484: /* value = (Obj)BDY(NEXT(p)); */
4485: if ( !strcmp(key,key0) ) {
4486: *r = (Obj)BDY(NEXT(p));
4487: return 1;
4488: }
4489: }
4490: }
4491: return 0;
4492: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>