[BACK]Return to ntl.cpp CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_ntl

Annotation of OpenXM/src/ox_ntl/ntl.cpp, Revision 1.3

1.3     ! iwane       1: /* $OpenXM: OpenXM/src/ox_ntl/ntl.cpp,v 1.2 2003/11/08 12:34:00 iwane Exp $ */
1.1       iwane       2:
                      3: #include <NTL/ZZXFactoring.h>
1.3     ! iwane       4: #include <NTL/LLL.h>
1.1       iwane       5:
1.2       iwane       6: #include "ox_toolkit.h"
1.1       iwane       7: #include "ntl.h"
                      8:
1.2       iwane       9: #if __NTL_DEBUG
                     10: #define __NTL_PRINT (1)
                     11: #endif
1.1       iwane      12:
1.3     ! iwane      13: #define __NTL_PRINT (1)
        !            14: #define DPRINTF(x)     printf x; fflush(stdout)
        !            15:
1.1       iwane      16: /****************************************************************************
                     17:  *
                     18:  * Factorize polynomial over the integers.
                     19:  *
                     20:  * PARAM : I : arg  : polynomial
                     21:  *       : I : argc :
                     22:  * RETURN: [num,[[factor1,multiplicity1],[factor2,multiplicity2],...]]
                     23:  *
                     24:  * EX    : ntl_fctr([2*x^11+4*x^8-2*x^6+2*x^5-4*x^3-2],1) ==>
                     25:          : [2,[[x-1,1],[x^4+x^3+x^2+x+1,1],[x+1,2],[x^2-x+1,2]]]
                     26:  *
                     27:  ****************************************************************************/
                     28: cmo *
                     29: ntl_fctr(cmo **arg, int argc)
                     30: {
                     31:        cmo *poly = arg[0];
                     32:        cmo_indeterminate *x;
                     33:        ZZX f;
                     34:        int ret;
                     35:
                     36:        if (argc != 1) {
                     37:                return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(#)")));
                     38:        }
                     39:
                     40:        ret = cmo_to_ZZX(f, poly, x);
                     41:        if (ret != NTL_SUCCESS) {
                     42:                /* format error */
                     43:                return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(type)")));
                     44:        }
                     45:
1.2       iwane      46: #if __NTL_PRINT
                     47:        cout << "input: " << f << endl;
                     48: #endif
                     49:
1.3     ! iwane      50:        cmon_factors_t *factors = new_cmon_factors();
        !            51:        factors->x = x;
        !            52:
        !            53:        factor(*factors->cont, *factors->f, f);
1.1       iwane      54:
1.2       iwane      55: #if __NTL_PRINT
1.3     ! iwane      56:        cout << "fctr : " << *factors->f << endl;
1.2       iwane      57: #endif
                     58:
1.1       iwane      59:
1.3     ! iwane      60:        return ((cmo *)factors);
        !            61: }
1.1       iwane      62:
1.3     ! iwane      63: /****************************************************************************
        !            64:  *
        !            65:  * Factorize polynomial over the integers.
        !            66:  *
        !            67:  * PARAM : I : arg  : polynomial
        !            68:  *       : I : argc :
        !            69:  * RETURN: [num,[[factor1,multiplicity1],[factor2,multiplicity2],...]]
        !            70:  *
        !            71:  * EX    : ntl_fctr([2*x^11+4*x^8-2*x^6+2*x^5-4*x^3-2],1) ==>
        !            72:          : [2,[[x-1,1],[x^4+x^3+x^2+x+1,1],[x+1,2],[x^2-x+1,2]]]
        !            73:  *
        !            74:  ****************************************************************************/
        !            75: cmo *
        !            76: ntl_lll(cmo **arg, int argc)
        !            77: {
        !            78:        cmo *poly = arg[0];
        !            79:        cmo_indeterminate *x;
        !            80:        ZZX f;
        !            81:        int ret;
        !            82:        cmon_mat_zz_t *mat;
        !            83:
        !            84: DPRINTF(("lll start\n"));
        !            85:
        !            86:        if (argc != 1) {
        !            87: DPRINTF(("invalid argc %d\n", argc));
        !            88:                return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(#)")));
        !            89:        }
        !            90:
        !            91:        mat = new_cmon_mat_zz();
        !            92:        ret = cmo_to_mat_zz(*mat->mat, arg[0]);
        !            93: DPRINTF(("ret = %d, convert\n", ret));
        !            94:        if (ret != NTL_SUCCESS) {
        !            95: DPRINTF(("convert failed\n", ret));
        !            96:                delete_cmon_mat_zz(mat);
        !            97:                /* format error */
        !            98:                return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(type)")));
        !            99:        }
1.1       iwane     100:
1.3     ! iwane     101: DPRINTF(("convert success\n", ret));
1.1       iwane     102:
1.3     ! iwane     103: #if __NTL_PRINT
        !           104: DPRINTF(("convert success\n", ret));
        !           105:        cout << "input: " << (*mat->mat) << endl;
        !           106: #endif
        !           107:
        !           108:
        !           109: DPRINTF(("lll start\n", ret));
        !           110:        ZZ det2;
        !           111:        long rd = LLL(det2, *mat->mat);
        !           112:
        !           113:
        !           114: #if __NTL_PRINT
        !           115:        cout << "output: " << (*mat->mat) << endl;
        !           116: #endif
        !           117:
        !           118:        return ((cmo *)mat);
1.1       iwane     119: }
                    120:
1.2       iwane     121:
1.3     ! iwane     122:
        !           123: #if __NTL_DEBUG /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
1.2       iwane     124:
                    125: int
                    126: main(int argc, char *argv[])
                    127: {
                    128:        ZZX f;
                    129:        const char *str = "[1 -1 -1 1]";
                    130:        int num = 1;
                    131:        char *var = "x";
                    132:        cmo *c;
                    133:
                    134:        f = to_ZZ(str);;
                    135:
                    136:        cmo_indeterminate *x = new_cmo_indeterminate((cmo *)new_cmo_string(var));
                    137:        cmo_recursive_polynomial *poly = ZZX_to_cmo(f, x);
                    138:        cmo *arg[3];
                    139:
                    140:        arg[0] = (cmo *)poly;
                    141:
                    142:        c = ntl_fctr(arg, num);
                    143:
                    144:        return (0);
                    145: }
                    146:
                    147: #endif
1.1       iwane     148:

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