Exemple #1
0
	/********************************
	 * Interface to create a domain *
	 ********************************/
	ALGEB lbCreateDomain (MKernelVector kv, ALGEB *argv){
		M_INT argc = MapleNumArgs(kv, (ALGEB) argv);
		const DomainKey *key;
		try {
			if (argc < 1){
				LB_GMP_SET();
				key = &createDomain(0);
				LB_GMP_RESTORE();
				return DomainKeyToMaple(kv, *key);
			}
			//LinBox::integer *p = GMPMapleToLinBox(kv, argv[1]);
			LinBox::integer p;
			GMPMapleToLinBox(p, kv, argv[1]);

			if (argc == 1){
				LB_GMP_SET();
				key = &createDomain(p);
				LB_GMP_RESTORE();
				return DomainKeyToMaple(kv, *key);
			}
			if (argc == 2){
				LB_GMP_SET();
				key = &createDomain(p, MapleToString(kv, argv[2]));
				LB_GMP_RESTORE();
				return DomainKeyToMaple(kv, *key);
			}
			if (argc > 2){
				MapleRaiseError(kv, "wrong number of argument");
				return ToMapleNULL(kv);
			}
		}
		catch ( lb_runtime_error &t )
			{ lbRaiseError(kv, t); return ToMapleNULL(kv);}
		return ToMapleNULL(kv);
	}
Exemple #2
0
	/***********************************
	 * Interface to write a polynomial *
	 ***********************************/
	ALGEB lbWritePolynomial (MKernelVector kv, ALGEB *argv){
		try {
			std::ofstream os(MapleToString(kv, argv[2]));
			const VectorKey *key = &MapleToVectorKey(kv, argv[1]);
			writePolynomial(*key, os);
			return ToMapleNULL(kv);
		}
       		catch (lb_runtime_error &t)
			{ lbRaiseError(kv, t);}
		return ToMapleNULL(kv);
	}
Exemple #3
0
	/************************************************
	 * Interface to change globally the vector type *
	 ************************************************/
	ALGEB lbSetVector (MKernelVector kv, ALGEB *argv){
		M_INT argc = MapleNumArgs(kv, (ALGEB) argv);
		if (argc != 1){
			MapleRaiseError(kv, "wrong number of arguments");
			return ToMapleNULL(kv);
		}
		if (!IsMapleString(kv, argv[1])){
			MapleRaiseError(kv, "String expected as 1st argument");
			return ToMapleNULL(kv);
		}
		setVector(MapleToString(kv, argv[1]));
		return ToMapleNULL(kv);
	}
Exemple #4
0
	/**************************************************
	 * Interface to change globally the blackbox type *
	 **************************************************/
	ALGEB lbSetBlackbox (MKernelVector kv, ALGEB *argv){
		M_INT argc = MapleNumArgs(kv, (ALGEB) argv);
		if (argc != 1){
			MapleRaiseError(kv, "wrong number of parameter in lbSetBlackbox");
			return ToMapleNULL(kv);
		}
		if (!IsMapleString(kv, argv[1])){
			MapleRaiseError(kv, "lbSetBlackbox expects a string as parameter");
			return ToMapleNULL(kv);
		}
		setBlackbox(MapleToString(kv, argv[1]));
		return ToMapleNULL(kv);
	}
Exemple #5
0
int main( int argc, char *argv[] )
{
    char err[2048];  /* command input and error string buffers */
    MKernelVector kv;  /* Maple kernel handle */
    MCallBackVectorDesc cb = {  textCallBack, 
				0,   /* errorCallBack not used */
				0,   /* statusCallBack not used */
				0,   /* readLineCallBack not used */
				0,   /* redirectCallBack not used */
				0,   /* streamCallBack not used */
			        0,   /* queryInterrupt not used */ 
				0    /* callBackCallBack not used */
			    };
    ALGEB r, l;  /* Maple data-structures */

    /* initialize Maple */
    if( (kv=StartMaple(argc,argv,&cb,NULL,NULL,err)) == NULL ) {
	printf("Fatal error, %s\n",err);
	return( 1 );
    }
 
    /* example 1: find out where maple is installed */
    r = MapleKernelOptions(kv,"mapledir",NULL);
    if( IsMapleString(kv,r) )
        printf("Maple directory = \"%s\"\n\n",MapleToString(kv,r));

    /* example 2: compute an integral */
    /* output goes through the textCallBack */
    printf("Evaluate an integral: \n\t");
    r = EvalMapleStatement(kv,"int(1/(x^4+1),x);");

    /* example 3: assign x a value and reevaluate the integral */
    MapleAssign(kv,
        ToMapleName(kv,"x",TRUE),
        ToMapleInteger(kv,0));
    r = MapleEval(kv,r);
    MapleALGEB_Printf(kv,"\nEvaluated at x=0, the integral is: %a\n",r);

    /* example 4: create a list with 3 elements */
    l = MapleListAlloc(kv,3);
    MapleListAssign(kv,l,1,r);
    MapleListAssign(kv,l,2,ToMapleBoolean(kv,1));
    MapleListAssign(kv,l,3,ToMapleFloat(kv,3.14));
    MapleALGEB_Printf(kv,"\nHere's the list: %a\n",l);

    return( 0 );
}
Exemple #6
0
	ALGEB lbCreateVector (MKernelVector kv, ALGEB *argv){
		M_INT argc = MapleNumArgs(kv, (ALGEB) argv);
		const VectorKey *key;
		if ((argc < 1) || (argc > 4)){
			MapleRaiseError(kv, "wrong number of arguments");
			return ToMapleNULL(kv);
		}
		try {
			if (argc == 1){
				if (IsMapleRTable(kv, argv[1]))
					return lbCreateVectorFromVector(kv, argv[1], LinBox::integer(0));
			}
			if (argc == 2){
				if (IsMapleInteger(kv, argv[1]) && IsMapleRTable(kv, argv[2])){
					//LinBox::integer *p = GMPMapleToLinBox(kv, argv[1]);
					LinBox::integer p;
					GMPMapleToLinBox(p, kv, argv[1]);
					LB_GMP_SET();
					ALGEB ret = lbCreateVectorFromVector(kv, argv[2], p);
					LB_GMP_RESTORE();
					return ret;
				}

				if ( IsMapleDomainKey(kv, argv[1]) && IsMapleInteger(kv, argv[2])) {
					const DomainKey *k = &MapleToDomainKey(kv, argv[1]);
					LB_GMP_SET();
					key = &createVector(*k, MapleToInteger32(kv, argv[2]));
					LB_GMP_RESTORE();
					return VectorKeyToMaple(kv, *key);
				}
			}
			if (argc == 3){
				if ( IsMapleDomainKey(kv, argv[1]) && IsMapleInteger(kv, argv[2]) && IsMapleString(kv, argv[3])){
					const DomainKey *k = &MapleToDomainKey(kv, argv[1]);
					LB_GMP_SET();
					key = &createVector(*k, MapleToInteger32(kv, argv[2]), MapleToString(kv, argv[3]));
					LB_GMP_RESTORE();
					return VectorKeyToMaple(kv, *key);
				}
			}
			MapleRaiseError(kv, "wrong types of arguments");
		}
		catch ( lb_runtime_error &t )
			{ lbRaiseError(kv, t); }
		return ToMapleNULL(kv);
	}