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