Annotation of OpenXM/src/ox_ntl/ntl.cpp, Revision 1.2
1.2 ! iwane 1: /* $OpenXM: OpenXM/src/ox_ntl/ntl.cpp,v 1.1 2003/11/03 03:11:21 iwane Exp $ */
1.1 iwane 2:
3: #include <NTL/ZZXFactoring.h>
4:
1.2 ! iwane 5: #include "ox_toolkit.h"
1.1 iwane 6: #include "ntl.h"
7:
1.2 ! iwane 8: #if __NTL_DEBUG
! 9: #define __NTL_PRINT (1)
! 10: #endif
1.1 iwane 11:
12: /****************************************************************************
13: *
14: * Factorize polynomial over the integers.
15: *
16: * PARAM : I : arg : polynomial
17: * : I : argc :
18: * RETURN: [num,[[factor1,multiplicity1],[factor2,multiplicity2],...]]
19: *
20: * EX : ntl_fctr([2*x^11+4*x^8-2*x^6+2*x^5-4*x^3-2],1) ==>
21: : [2,[[x-1,1],[x^4+x^3+x^2+x+1,1],[x+1,2],[x^2-x+1,2]]]
22: *
23: ****************************************************************************/
24: cmo *
25: ntl_fctr(cmo **arg, int argc)
26: {
27: cmo *poly = arg[0];
28: cmo_indeterminate *x;
29: ZZX f;
30: ZZ c;
31:
32: int ret;
33:
34: vec_pair_ZZX_long factors;
35:
36: cmo_list *ans;
37: cmo *fcts;
38:
39: if (argc != 1) {
40: return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(#)")));
41: }
42:
43: ret = cmo_to_ZZX(f, poly, x);
44: if (ret != NTL_SUCCESS) {
45: /* format error */
46: return ((cmo *)new_cmo_error2((cmo *)new_cmo_string("Invalid Parameter(type)")));
47: }
48:
1.2 ! iwane 49: #if __NTL_PRINT
! 50: cout << "input: " << f << endl;
! 51: #endif
! 52:
1.1 iwane 53: factor(c, factors, f);
54:
1.2 ! iwane 55: #if __NTL_PRINT
! 56: cout << "fctr : " << factors << endl;
! 57: #endif
! 58:
1.1 iwane 59: cmo_zz *zz = ZZ_to_cmo_zz(c);
60:
61: ans = new_cmo_list();
62:
1.2 ! iwane 63: fcts = (cmo *)vec_pair_ZZX_long_to_cmo(factors, x);
1.1 iwane 64:
65: list_appendl(ans, zz, (cmo *)fcts, NULL);
66:
67: return ((cmo *)ans);
68: }
69:
1.2 ! iwane 70:
! 71: #if __NTL_DEBUG
! 72:
! 73: int
! 74: main(int argc, char *argv[])
! 75: {
! 76: ZZX f;
! 77: const char *str = "[1 -1 -1 1]";
! 78: int num = 1;
! 79: char *var = "x";
! 80: cmo *c;
! 81:
! 82: f = to_ZZ(str);;
! 83:
! 84: cmo_indeterminate *x = new_cmo_indeterminate((cmo *)new_cmo_string(var));
! 85: cmo_recursive_polynomial *poly = ZZX_to_cmo(f, x);
! 86: cmo *arg[3];
! 87:
! 88: arg[0] = (cmo *)poly;
! 89:
! 90: c = ntl_fctr(arg, num);
! 91:
! 92: return (0);
! 93: }
! 94:
! 95: #endif
1.1 iwane 96:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>