Annotation of OpenXM/src/ox_maple/c2m.c, Revision 1.1
1.1 ! iwane 1: /* $OpenXM$ */
! 2: /************************************************************************
! 3: * CMO ==> MapleObject converter
! 4: *
! 5: *
! 6: *********************************************************************** */
! 7:
! 8: #include <stdio.h>
! 9: #include <string.h>
! 10:
! 11: #include "oxmaple.h"
! 12: #include "maplec.h"
! 13:
! 14: #define DPRINTF(x) printf x; fflush(stdout)
! 15:
! 16:
! 17:
! 18: /*********************************************************************
! 19: *
! 20: *********************************************************************/
! 21: static ALGEB
! 22: convert_cmolist_to_maple(
! 23: MKernelVector kv,
! 24: cmo_list *c)
! 25: {
! 26: cell *cl;
! 27: ALGEB list;
! 28: int i;
! 29:
! 30: cl = list_first(c);
! 31: list = MapleListAlloc(kv, c->length);
! 32: for (i = 0; i < c->length; i++) {
! 33: ALGEB alg = convert_cmo_to_maple(kv, cl->cmo, NULL);
! 34: if (alg == NULL) {
! 35: return (NULL);
! 36: }
! 37: MapleListAssign(kv, list, i+1, alg);
! 38: cl = list_next(cl);
! 39: }
! 40:
! 41: return (list);
! 42: }
! 43:
! 44: /*********************************************************************
! 45: *
! 46: *********************************************************************/
! 47: static ALGEB
! 48: convert_cmorpoly_to_maple(
! 49: MKernelVector kv,
! 50: cmo_recursive_polynomial *c)
! 51: {
! 52: return (convert_cmo_to_maple(kv, c->coef, c->ringdef));
! 53: }
! 54:
! 55: /*********************************************************************
! 56: *
! 57: *********************************************************************/
! 58: static ALGEB
! 59: convert_cmo1poly_to_maple(
! 60: MKernelVector kv,
! 61: cmo_polynomial_in_one_variable *c,
! 62: cmo_list *ringdef)
! 63: {
! 64: ALGEB t, n;
! 65: int i;
! 66: ALGEB var, tm;
! 67: char *str;
! 68: cell *cl;
! 69: cmo *ob;
! 70: char buf[100];
! 71:
! 72: if (ringdef == NULL) {
! 73: return (NULL);
! 74: }
! 75:
! 76: cl = list_first(ringdef);
! 77: for (i = 0; i < c->var; i++) {
! 78: cl = list_next(cl);
! 79: }
! 80: ob = cl->cmo;
! 81: if (ob->tag == CMO_INDETERMINATE) {
! 82: ob = ((cmo_indeterminate *)ob)->ob;
! 83: }
! 84:
! 85: var = ToMapleString(kv, ((cmo_string *)ob)->s);
! 86:
! 87:
! 88: sprintf(buf, "vArNaMe_%d_tt", c->var);
! 89: tm = ToMapleString(kv, buf);
! 90: t = ToMapleName(kv, buf, TRUE);
! 91: n = MapleAssign(kv, t, ToMapleInteger(kv, 0));
! 92:
! 93: cl = list_first((cmo_list *)c);
! 94: for (; !list_endof((cmo_list *)c, cl); cl = list_next(cl)) {
! 95: n = convert_cmo_to_maple(kv, cl->cmo, ringdef);
! 96: if (n == NULL) {
! 97: return (NULL);
! 98: }
! 99: if (cl->exp == 0) {
! 100: n = MapleALGEB_SPrintf(kv, "%s := %s+(%a):", tm, tm, n);
! 101: str = MapleToString(kv, n);
! 102: } else {
! 103: n = MapleALGEB_SPrintf(kv, "%s := %s+(%a) * %s^%d:", tm, tm, n, var, ToMapleInteger(kv, cl->exp));
! 104: str = MapleToString(kv, n);
! 105: }
! 106:
! 107: n = EvalMapleStatement(kv, str);
! 108: }
! 109:
! 110: return (n);
! 111: }
! 112:
! 113: /*********************************************************************
! 114: * convert CMO to Maple Object
! 115: *********************************************************************/
! 116: ALGEB
! 117: convert_cmo_to_maple(MKernelVector kv, cmo *c, cmo_list *ringdef)
! 118: {
! 119: char *str, *str2;
! 120: ALGEB alg = NULL;
! 121: printf("tag=%d @ conv_cmo2maple\n", c->tag);
! 122: switch (c->tag) {
! 123: case CMO_ZERO:
! 124: alg = ToMapleInteger(kv, 0);
! 125: break;
! 126: case CMO_INT32:
! 127: alg = ToMapleInteger(kv, ((cmo_int32 *)c)->i);
! 128: break;
! 129: case CMO_ZZ:
! 130: str2 = new_string_set_cmo((cmo *)c);
! 131: str = MapleAlloc(kv, strlen(str2) + 3);
! 132: sprintf(str, "%s:", str2);
! 133: printf("ZZ=%s, alg=%p\n", str, alg);
! 134: alg = EvalMapleStatement(kv, str);
! 135: printf("ZZ=%s, alg=%p\n", str, alg);
! 136: MapleALGEB_Printf(kv, "alg=%a\n", alg);
! 137: break;
! 138: case CMO_STRING:
! 139: alg = ToMapleString(kv, ((cmo_string *)c)->s);
! 140: break;
! 141: case CMO_LIST:
! 142: alg = convert_cmolist_to_maple(kv, (cmo_list *)c);
! 143: break;
! 144: case CMO_RECURSIVE_POLYNOMIAL:
! 145: alg = convert_cmorpoly_to_maple(kv, (cmo_recursive_polynomial *)c);
! 146: break;
! 147: case CMO_POLYNOMIAL_IN_ONE_VARIABLE:
! 148: alg = convert_cmo1poly_to_maple(kv, (cmo_polynomial_in_one_variable *)c, ringdef);
! 149: break;
! 150: case CMO_QQ:
! 151: str2 = mpq_get_str(NULL, 10, ((cmo_qq *)c)->mpq);
! 152: str = MapleAlloc(kv, strlen(str2) + 3);
! 153: sprintf(str, "%s:", str2);
! 154: alg = EvalMapleStatement(kv, str);
! 155: default:
! 156: alg = NULL;
! 157: }
! 158:
! 159: return (alg);
! 160: }
! 161:
! 162:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>