[BACK]Return to dp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / builtin

Annotation of OpenXM_contrib2/asir2018/builtin/dp.c, Revision 1.30

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>