Beispiel #1
0
void alg2_decommon_n(Term a2)
	{
    List l1;
	int cnum,cden;
	Term t;

	l1=CompoundArgN(a2,5);
	if(is_empty_list(l1))
		{
		SetCompoundArg(a2,2,0);
		return;
		}

	t=ConsumeCompoundArg(a2,2);
	cnum=IntegerValue(CompoundArg1(t));
	cden=IntegerValue(CompoundArg2(t));
	FreeAtomic(t);

	while(!is_empty_list(l1))
		{
		Term t;
		int c1,c2,c3;
		c1=cnum*IntegerValue(CompoundArg1(ListFirst(l1)));
		c2=cden;
		c3=gcf(c1,c2);
		c1/=c3;
		c2/=c3;
		t=MakeCompound2(OPR_DIV,NewInteger(c1),NewInteger(c2));
		SetCompoundArg(ListFirst(l1),1,t);
		l1=ListTail(l1);
		}


	}
Beispiel #2
0
static Term l2expr(List l, int n)
{
	List l1;
	Term t, res=0;
	Atom pw;
	if(CalcOutput)
		pw=OPR_POW;
	else
		pw=OPR_POW;
	
	if(l==0)
		return NewInteger(n);
	if(n>1 || n<-1)
		res=NewInteger(n);
	else
	{
	t=ListFirst(l);
	if(CompoundArg2(t)==NewInteger(1))
		res=CompoundArg1(t);
	else if(CompoundArg2(t)==NewInteger(-1))
		res=MakeCompound2(OPR_DIV,NewInteger(1),CompoundArg1(t));
	else if(IntegerValue(CompoundArg2(t))>1)
		res=MakeCompound2(pw,CompoundArg1(t),CompoundArg2(t));
	else
		res=MakeCompound2(OPR_DIV,NewInteger(1),
			MakeCompound2(pw,CompoundArg1(t),
				NewInteger(-IntegerValue(CompoundArg2(t)))));
	if(n<0)
		res=MakeCompound1(OPR_MINUS,res);
	l=ListTail(l);
	}
	
	for(l1=l;l1;l1=ListTail(l1))
	{
		t=ListFirst(l1);
		if(CompoundArg2(t)==NewInteger(1))
			res=MakeCompound2(OPR_MLT,res,CompoundArg1(t));
		else if(CompoundArg2(t)==NewInteger(-1))
			res=MakeCompound2(OPR_DIV,res,CompoundArg1(t));
		else if(IntegerValue(CompoundArg2(t))>1)
			res=MakeCompound2(OPR_MLT,res,
			MakeCompound2(pw,CompoundArg1(t),CompoundArg2(t)));
		else
			res=MakeCompound2(OPR_DIV,res,
				MakeCompound2(pw,CompoundArg1(t),
					NewInteger(-IntegerValue(CompoundArg2(t)))));
	}
	return res;
	
}
Beispiel #3
0
void alg2_recommon_n(Term a2)
	{
    List m2l,l,l1,nl;
    int cnum,n,d;
	m2l=CompoundArgN(a2,5);
    nl=NewList();
	l=m2l;
	if(is_empty_list(l))
		return;


	while(!is_empty_list(l))
		{
        nl=AppendLast(nl,CompoundArg1(ListFirst(l)));
		l=ListTail(l);
		}

	cnum=gcf_list(nl);
	if(IntegerValue(ListFirst(nl))<0)
		cnum*=-1;
    if(cnum==1)
        {
        RemoveList(nl);
        return;
        }

    l1=m2l;
	l=nl;
	while(!is_empty_list(l))
		{
        SetCompoundArg(ListFirst(l1),1,
            NewInteger(IntegerValue(ListFirst(l))/cnum));
		l=ListTail(l);
		l1=ListTail(l1);
		}

	RemoveList(nl);
    n=IntegerValue(CompoundArg1(CompoundArg2(a2)));
    d=IntegerValue(CompoundArg2(CompoundArg2(a2)));
    n*=cnum;
    cnum=gcf(n,d);
    n/=cnum;
    d/=cnum;
    SetCompoundArg(CompoundArg2(a2),1,NewInteger(n));
    SetCompoundArg(CompoundArg2(a2),2,NewInteger(d));

	return ;
	}
// ir_make_real
Operand* ir_make_real(Ty ty, Int iVal)
{
    if (ty_int32 == ty || ty_uint32 == ty ||
        ty_int16 == ty || ty_uint16 == ty ||
        ty_int8  == ty || ty_uint8  == ty ||
        ty_int64 == ty || ty_uint64 == ty )
    {
        return NewInteger(iVal);
    }

    if (ty_float32 == ty || ty_float64 == ty)
    {
        error(L"NYI: ir_make_real: float");
    }

    if (ty_subtypep(ty, Qdouble_float))
    {
        error(L"NYI: ir_make_real: float");
    }

    if (ty_subtypep(ty, Qsingle_float))
    {
        error(L"NYI: ir_make_real: single float");
    }

    // (complex double-float)
    // (complex single-float)

    return NewLiteral(iVal);
} // ir_make_real
Beispiel #5
0
void alg2_decommon_s(Term a2)
	{
	Term cfl;
	List l;
	
	cfl=ConsumeCompoundArg(a2,3);
	if(is_empty_list(cfl))
		return;
	
	for(l=CompoundArgN(a2,5);l;l=ListTail(l))
		{
		List pfl;
		List l1,l2;
		
		pfl=ConsumeCompoundArg(ListFirst(l),2);
		for(l1=cfl;l1;l1=ListTail(l1))
			{
			Atom p;
			p=CompoundArg1(ListFirst(l1));
			for(l2=pfl;l2;l2=ListTail(l2))
				{
				if(CompoundArg1(ListFirst(l2))==p)
					{
					int pw;
					pw=IntegerValue(CompoundArg2(ListFirst(l2)))
						+IntegerValue(CompoundArg2(ListFirst(l1)));
					SetCompoundArg(ListFirst(l2),2,NewInteger(pw));
					break;
					}
				}
			if(is_empty_list(l2))
				pfl=AppendFirst(pfl,CopyTerm(ListFirst(l1)));
			}
	rr:
		for(l1=pfl;l1;l1=ListTail(l1))
			if(CompoundArg2(ListFirst(l1))==NewInteger(0))
				{
				pfl=CutFromList(pfl,l1);
				goto rr;
				}
		pfl=SortedList(pfl,prtcmp);
		SetCompoundArg(ListFirst(l),2,pfl);
		}
		
	FreeAtomic(cfl);
		
	}
Beispiel #6
0
Local<String> V8EngineProxy::GetErrorMessage(TryCatch &tryCatch)
{
	auto msg = tryCatch.Exception()->ToString();

	auto stack = tryCatch.StackTrace();
	bool showStackMsg = !stack.IsEmpty() && !stack->IsUndefined();
	Local<String> stackStr;

	if (showStackMsg)
	{
		stackStr = stack->ToString();

		// ... detect if the start of the stack message is the same as the exception message, then remove it (seems to happen when managed side returns an error) ...

		if (stackStr->Length() >= msg->Length())
		{
			uint16_t* ss = new uint16_t[stackStr->Length() + 1];
			stack->ToString()->Write(ss);
			auto subStackStr = NewSizedUString(ss, msg->Length());
			auto stackPartStr = NewSizedUString(ss + msg->Length(), stackStr->Length() - msg->Length());
			delete[] ss;

			if (msg->Equals(subStackStr))
				stackStr = stackPartStr;
		}
	}

	msg = msg->Concat(msg, NewString("\r\n"));

	msg = msg->Concat(msg, NewString("  Line: "));
	auto line = NewInteger(tryCatch.Message()->GetLineNumber())->ToString();
	msg = msg->Concat(msg, line);

	msg = msg->Concat(msg, NewString("  Column: "));
	auto col = NewInteger(tryCatch.Message()->GetStartColumn())->ToString();
	msg = msg->Concat(msg, col);
	msg = msg->Concat(msg, NewString("\r\n"));

	if (showStackMsg)
	{
		msg = msg->Concat(msg, NewString("  Stack: "));
		msg = msg->Concat(msg, stackStr);
		msg = msg->Concat(msg, NewString("\r\n"));
	}

	return msg;
}
Beispiel #7
0
static Atom remcc(Atom a)
{
	Term prop=GetAtomProperty(a,PROP_TYPE);
	if(is_compound(prop) && CompoundName(prop)==OPR_FIELD &&
					CompoundArg2(prop)==NewInteger(4))
				return CompoundArg1(prop);
	return a;
}
Beispiel #8
0
static void mult_no(List e1, int no)
	{
	while(!is_empty_list(e1))
		{
		int v;
		v=IntegerValue(CompoundArg1(ListFirst(e1)));
		v*=no;
		SetCompoundArg(ListFirst(e1),1,NewInteger(v));
		e1=ListTail(e1);
		}
	}
Beispiel #9
0
JNIEXPORT jint JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_Initialize
  (JNIEnv *env, jclass cls, jobject $idInst, jint afCmd)
{
	DWORD idInst = 0;

	UINT initError = DdeInitialize(
			&idInst, // receives instance identifier
			(PFNCALLBACK) DdeCallback, // pointer to callback function
			afCmd, 0);

	SetObjectInPointer(env, $idInst, NewInteger(env, idInst));

	return initError;
}
Beispiel #10
0
static void invert_term(Term t)
	{
	
		{
		int i1,i2;
		i1=IntegerValue(CompoundArg1(t));
		i2=IntegerValue(CompoundArg2(t));
		if(i1<0 && i2>0)
			{
			i1=-i1;
			i2=-i2;
			goto ee;
			}
		if(i1>0 && i2<0)
			{
			i1=-i1;
			goto ee;
			}
		if(i1<0 && i2<0)
			{
			i2=-i2;
			goto ee;
			}
	ee:
		SetCompoundArg(t,1,NewInteger(i2));
		SetCompoundArg(t,2,NewInteger(i1));
		}
		
		{
		Term t1,t2;
		t1=ConsumeCompoundArg(t,3);
		t2=ConsumeCompoundArg(t,4);
		SetCompoundArg(t,3,t2);
		SetCompoundArg(t,4,t1);
		}
		
	}
Beispiel #11
0
static Term multiply(Term t1, Term t2)
	{
	Term ret;
	int n1,n2,d1,d2,num,den,cf;
	List l1,l2;
	ret=MakeCompound(A_MTERM,4);
	n1=IntegerValue(CompoundArg1(t1));
	n2=IntegerValue(CompoundArg1(t2));
	d1=IntegerValue(CompoundArg2(t1));
	d2=IntegerValue(CompoundArg2(t2));
	num=n1*n2;
	den=d1*d2;
	if(den<0) den=-den;
	cf=gcf(num,den);
	num/=cf;
	den/=cf;
	if(d1<0 && d2<0)
		{
		num=-num;
		}
	else
		if((d1<0 && d2>0) || (d1>0 && d2<0))
			{
			den=-den;
			}
	SetCompoundArg(ret,1,NewInteger(num));
	SetCompoundArg(ret,2,NewInteger(den));
	l1=ConsumeCompoundArg(t1,3);
	l2=ConsumeCompoundArg(t2,3);
	SetCompoundArg(ret,3,ConcatList(l1,l2));
	l1=ConsumeCompoundArg(t1,4);
	l2=ConsumeCompoundArg(t2,4);
	SetCompoundArg(ret,4,ConcatList(l1,l2));
	FreeAtomic(t1); FreeAtomic(t2);
	return ret;
	}
Beispiel #12
0
static Term finda2(List pl, int del)
{
	int pli, ii;
	List l;
	pli=ListLength(pl);
	mmmpos=0;
	for(ii=0;ii<LagrHashSize;ii++)
	{
	
		for(l=lagr_hash[ii];l;l=ListTail(l))
		{
			List cpl=CompoundArg1(ListFirst(l));
			List vpl=0;
			List ll1,ll2;
			int pos=1;

			if(cpl==0 || ListLength(cpl)!=pli)
				continue;
			for(ll1=cpl;ll1;ll1=ListTail(ll1),pos++)
			{
				Atom a,prp;
				a=CompoundArg1(ListFirst(ll1));
				prp=GetAtomProperty(a,PROP_TYPE);
				if(is_compound(prp)&&CompoundName(prp)==OPR_FIELD &&
					CompoundArg2(prp)==NewInteger(4))
					a=CompoundArg1(prp);
				if(a==mmm)
					mmmpos=pos;
				vpl=AppendLast(vpl,a);
			}
				
			vpl=SortedList(vpl, acmp);

			for(ll1=pl,ll2=vpl;ll1;ll1=ListTail(ll1),ll2=ListTail(ll2))
				if(ListFirst(ll1)!=ListFirst(ll2))
					break;
			if(is_empty_list(ll1))
				break;
		}
	if(l)
		break;
	}
	
	if(l && del)
		lagr_hash[ii]=CutFromList(lagr_hash[ii],l);
	
	return l;
}
Beispiel #13
0
static void alg1_set_cos0(Term a1)
	{
	List l;
	Term c0;
	int scno=0;
	for(l=CompoundArg1(a1);l;l=ListTail(l))
		{
		List l2;
		for(l2=CompoundArgN(ListFirst(l),3);l2;l2=ListTail(l2))
			{
			Term t=ListFirst(l2);
			if(CompoundName(t)==OPR_PARAMETER && 
			 (CompoundArg2(t)==A_SIN || CompoundArg2(t)==A_COS))
			 	scno++;
			if(CompoundName(t)==OPR_WILD)
				{
				List l3;
				for(l3=CompoundArg2(t);l3;l3=ListTail(l3))
					alg1_set_cos0(ListFirst(l3));
				}
			}
		}
	if(scno==0)
		return;
	
	c0=MakeCompound3(OPR_PARAMETER,0,A_COS,NewInteger(0));
	
	for(l=CompoundArg1(a1);l;l=ListTail(l))
		{
		List l2;
		scno=0;
		for(l2=CompoundArgN(ListFirst(l),3);l2;l2=ListTail(l2))
			{
			Term t=ListFirst(l2);
			if(CompoundName(t)==OPR_PARAMETER && 
			 (CompoundArg2(t)==A_SIN || CompoundArg2(t)==A_COS))
			 	scno++;
			}
		if(scno)
			continue;
		l2=ConsumeCompoundArg(ListFirst(l),3);
		l2=AppendLast(l2,CopyTerm(c0));
		SetCompoundArg(ListFirst(l),3,l2);
		}
	FreeAtomic(c0);
	/*WriteTerm(a1);puts("\n");*/
	
	}
Beispiel #14
0
JNIEXPORT jbyteArray JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_ClientTransaction
  (JNIEnv *env, jclass cls, jint idInst, jbyteArray jpData, jint hConv, jstring jhszItem,
		  jint wFmt, jint wType, jint dwTimeout, jobject $dwResult)
{
	HSZ hszItem = UtilCreateStringHandle(env, idInst, jhszItem);
	HDDEDATA pData = NULL;
	DWORD dwResult = 0;

	if (jpData != NULL) {
		jsize cb = env->GetArrayLength(jpData);
		jbyte *pSrc = env->GetByteArrayElements(jpData, 0);
		pData = DdeCreateDataHandle(idInst, (LPBYTE) pSrc, cb, 0, hszItem, wFmt, 0);
		env->ReleaseByteArrayElements(jpData, pSrc, 0);
	}

	HDDEDATA hddeData = DdeClientTransaction(
			(LPBYTE) pData,
			0xFFFFFFFF,
			(HCONV) hConv,
			hszItem,
			wFmt,
			wType,
			dwTimeout,
			&dwResult
	);

	if (pData != NULL) {
		DdeFreeDataHandle(pData);
	}

	UtilFreeStringHandle(idInst, hszItem);

	if ($dwResult != NULL) {
		SetObjectInPointer(env, $dwResult, NewInteger(env, dwResult));
	}

	if (hddeData == NULL) {
		return NULL;
	}
	else if (wType == XTYP_REQUEST) {
		jbyteArray result = ExtractData(env, hddeData);
		DdeFreeDataHandle(hddeData);
		return result;
	}

	return env->NewByteArray(0);
}
Beispiel #15
0
/*
 * Class:     disy_jnipcap_Pcap
 * Method:    listTstampTypes
 * Signature: (JLjava/util/ArrayList;)I
 */
JNIEXPORT jint JNICALL
Java_disy_jnipcap_Pcap_listTstampTypes (JNIEnv *env, jclass jcls, jlong jptr, jobject jtypes)
{
	pcap_t *p = (pcap_t *) jptr;
	if (p == NULL) return -1;
	int *carr;
	int ret = pcap_list_tstamp_types (p, &carr);
	if (ret >= 0) {
		int i = 0;
		for (;i<ret;i++) {
			jobject ji = NewInteger(env,carr[i]);
			(*env)->CallBooleanMethod (env, jtypes, mid_ArrayList_add_object, ji);
		}
	}
	pcap_free_tstamp_types(carr);
	return ret;
}
HandleProxy* FunctionTemplateProxy::CreateInstance(int32_t managedObjectID, int32_t argCount, HandleProxy** args)
{
	auto hArgs = new Handle<Value>[argCount];
    for (auto i = 0; i < argCount; i++)
        hArgs[i] = args[i]->Handle();
    auto obj = _FunctionTemplate->GetFunction()->NewInstance(argCount, hArgs);
    delete[] hArgs; // TODO: (does "disposed" still need to be called here for each item?)

    if (managedObjectID == -1)
        managedObjectID = _EngineProxy->GetNextNonTemplateObjectID();

    auto proxyVal = _EngineProxy->GetHandleProxy(obj);
    proxyVal->_ObjectID = managedObjectID;
    //??auto count = obj->InternalFieldCount();
    obj->SetAlignedPointerInInternalField(0, this); // (stored a reference to the proxy instance for the call-back functions)
    obj->SetInternalField(1, NewExternal(reinterpret_cast<void*>(managedObjectID))); // (stored a reference to the managed object for the call-back functions)
    obj->SetHiddenValue(NewString("ManagedObjectID"), NewInteger(managedObjectID)); // (won't be used on template created objects [fields are faster], but done anyhow for consistency)
    return proxyVal;
}
Beispiel #17
0
Term VarVer(Term t, Term ind)
	{
	List l,l1,l2;
	puts("Parameters");
	l=all_param_list();
	for(l1=l;!is_empty_list(l1);l1=ListTail(l1))
		{
		Term aa;
		aa=CompoundArg1(ListFirst(l1));
		if(!is_float(aa) && !is_integer(aa))
			{
			printf("%s: ",AtomValue(CompoundName(ListFirst(l1))));
			WriteTerm(aa);
			printf(" ->  ");
			WriteTerm(dif_term(aa));
			puts("");
			}
		}
		
	puts("\nVertices");

	l2=l=all_vert_list();
		
	for(l1=l;!is_empty_list(l1);l1=ListTail(l1))
		{
		Term a2;
		List l,lp,lm;
		a2=CopyTerm(ListFirst(l1));
		alg2_symmetrize(a2);
		alg2_common_s(a2);
		alg2_common_n(a2);
		alg2_red_cos(a2);
		alg2_red_orth(a2);
		if(CompoundArg2(a2)==NewInteger(0) ||
			 is_empty_list(CompoundArgN(a2,5)))
				continue;


		WriteVertex(CompoundArg1(a2));
		printf(" ");
		if(CompoundArgN(a2,3))
			WriteTerm(CompoundArgN(a2,3));
		else
			printf("[]");
		printf(" ");
		lp=lm=NewList();
		for(l=CompoundArgN(a2,3);!is_empty_list(l);l=ListTail(l))
			{
			Term aa;
			aa=ListFirst(l);
			if(IntegerValue(CompoundArg2(aa))<0)
				{
				aa=CopyTerm(aa);
				SetCompoundArg(aa,2,NewInteger(-IntegerValue(CompoundArg2(aa))));
				if(IntegerValue(CompoundArg2(aa))==1)
					lm=AppendLast(lm,CompoundArg1(aa));
				else
					lm=AppendLast(lm,aa);
				}
			else
				{
				if(IntegerValue(CompoundArg2(aa))==1)
					lp=AppendLast(lp,CompoundArg1(aa));
				else
					lp=AppendLast(lp,aa);
				}
			}
			
		if(lp)
			lp=l2mult(lp);
		if(lm)
			lm=l2mult(lm);
		if(lp==0 && lm==0)
			{
			printf("0");
			goto cnt;
			}
		if(lm==0)
			{
			WriteTerm(dif_term(lp));
			goto cnt;
			}
		if(lp==0)
			{
			WriteTerm(dif_term(MakeCompound2(OPR_DIV,NewInteger(1),lm)));
			goto cnt;
			}
		WriteTerm(dif_term(MakeCompound2(OPR_DIV,lp,lm)));
		
		cnt:
		puts("");
		FreeAtomic(a2);
		}
	FreeAtomic(l2);
	return 0;
	}
void ListAdder::add(HWND hwnd) {
	env->CallBooleanMethod(list, method, NewInteger((int)hwnd));
}
Beispiel #19
0
static List mk_let_d(Term m1,  Term a1)
	{
	List l,l2;
	List lb;
	List sd;
	int num1,den1;
	int io1=0,io2=0,rmn=0;
	
	for(l=CompoundArgN(m1,3);l;l=ListTail(l))
	{
		Term prp=0;
		if(CompoundName(ListFirst(l))==OPR_PARAMETER)
				prp=GetAtomProperty(CompoundArg2(ListFirst(l)),A_INFINITESIMAL);
		if(prp && IntegerValue(CompoundArg1(prp))>0)
				io1+=IntegerValue(CompoundArg1(prp));
		if(CompoundName(ListFirst(l))==A_INFINITESIMAL)
				io1+=IntegerValue(CompoundArg2(ListFirst(l)));
	}


	l=ConsumeCompoundArg(a1,1);
	FreeAtomic(a1);
	a1=l;


	for(l2=a1;l2;l2=ListTail(l2))
	{
		Term m11=ListFirst(l2);
		io2=0;
		for(l=CompoundArgN(m11,3);l;l=ListTail(l))
		{
			Term prp=0;
			if(CompoundName(ListFirst(l))==OPR_PARAMETER)
					prp=GetAtomProperty(CompoundArg2(ListFirst(l)),A_INFINITESIMAL);
			if(prp && IntegerValue(CompoundArg1(prp))>0)
					io2+=IntegerValue(CompoundArg1(prp));
			if(CompoundName(ListFirst(l))==A_INFINITESIMAL)
					io2+=IntegerValue(CompoundArg2(ListFirst(l)));
		}
		if(io1+io2>infi_order)
		{
			FreeAtomic(ListFirst(l2));
			ChangeList(l2,0);
			rmn++;
		}
	}
	
	if(rmn)
		do
		{
			for(l=a1;l;l=ListTail(l))
				if(ListFirst(l)==0)
				{
					a1=CutFromList(a1,l);
					break;
				}
		}
		while(l);

	
	num1=IntegerValue(ConsumeCompoundArg(m1,1));
	den1=IntegerValue(ConsumeCompoundArg(m1,2));
	l=ConsumeCompoundArg(m1,3);
	sd=ConsumeCompoundArg(m1,4);
	lb=l;
	FreeAtomic(m1);
	
	l=a1;
	while(!is_empty_list(l))
		{
		int n1,n2,d1,d2,num,den,cf;
		List lb1,lm;
		m1=ListFirst(l);
		lm=ConsumeCompoundArg(m1,3);
		lb1=CopyTerm(lb);
		lb1=ConcatList(lb1,lm);
		SetCompoundArg(m1,3,lb1);
		
		lm=ConsumeCompoundArg(m1,4);
		lm=ConcatList(lm,CopyTerm(sd));
		SetCompoundArg(m1,4,lm);
		
		n1=num1;
		d1=den1;
		n2=IntegerValue(CompoundArg1(m1));
		d2=IntegerValue(CompoundArg2(m1));
		num=n1*n2;
		den=d1*d2;
		if(den<0) den=-den;
		cf=gcf(num,den);
		num/=cf;
		den/=cf;
		if(d1<0 && d2<0)
			{
			num=-num;
			}
		else
			if((d1<0 && d2>0) || (d1>0 && d2<0))
				{
				den=-den;
				}
		SetCompoundArg(m1,1,NewInteger(num));
		SetCompoundArg(m1,2,NewInteger(den));
		l=ListTail(l);
		}
	FreeAtomic(lb);
	FreeAtomic(sd);
	return a1;
	}
Beispiel #20
0
void alg1_opt_let(Term a1)
{
	List l,l1,l2,lm=ConsumeCompoundArg(a1,1);
	List nl=0;
	Label mylbl=NewLabel();
	
	/*printf("%d -> ",ListLength(lm));*/
	
	for(l=lm;l;l=ListTail(l))
	{
		Term m1=ListFirst(l);
		int n,d,g;
		List ln=ConsumeCompoundArg(m1,3);
		List ld=ConsumeCompoundArg(m1,4);
		Term f1=0, f2=0, w=0;
		n=IntegerValue(CompoundArg1(m1));
		d=IntegerValue(CompoundArg2(m1));
				
	rpt1:
		for(l1=ld;l1;l1=ListTail(l1))
		{
			int n=ListMember(ln,ListFirst(l1));
			if(n)
			{
				ld=CutFromList(ld,l1);
				l1=ListNthList(ln,n);
				ln=CutFromList(ln,l1);
				goto rpt1;
			}
			if(CompoundArg2(ListFirst(l1))==A_SQRT2)
			{
				Term t=ListFirst(l1);
				ChangeList(l1,0);
				ld=CutFromList(ld,l1);
				ln=AppendFirst(ln,t);
				d*=2;
				goto rpt1;
			}
		}
	rpt2:
		for(l1=ln;l1;l1=ListTail(l1))
			if(CompoundArg2(ListFirst(l1))==A_SQRT2)
			{
				List l2;
				for(l2=ListTail(l1);l2;l2=ListTail(l2))
					if(CompoundArg2(ListFirst(l2))==A_SQRT2)
					{
						ln=CutFromList(ln,l1);
						ln=CutFromList(ln,l2);
						n*=2;
						goto rpt2;
					}
				}
		g=gcf(n,d);
		n/=g;
		d/=g;
		
		for(l1=ln;l1;l1=l1?ListTail(l1):0)
		{
			Term sp=ListFirst(l1);
			if(CompoundName(sp)==OPR_PARAMETER)
				continue;
			if(CompoundName(sp)==OPR_FIELD)
			{
				if(f1==0)
					f1=l1;
				else if(f2==0)
					f2=l1;
				else
				{
					ErrorInfo(1280);
					puts("bad let-sub: >2 prtc");
					return;
				}
				continue;
			}
			if(CompoundName(sp)==OPR_WILD)
			{
				if(w)
				{
					ErrorInfo(1281);
					puts("bad let-sub: unk spec");
					return;
				}
				w=l1;
				continue;
			}
			ErrorInfo(110);
			WriteTerm(sp);puts(" : bad let: unk stuff");
			return;
		}
		
		if(f2==0)
		{
			ErrorInfo(112);
			puts("bad let-subs: not 2 prtc");
			return;
		}
		
		l1=f1;f1=ListFirst(f1);ChangeList(l1,0);ln=CutFromList(ln,l1);
		l1=f2;f2=ListFirst(f2);ChangeList(l1,0);ln=CutFromList(ln,l1);
		if(w)
		{l1=w;w=ListFirst(w);ChangeList(l1,0);ln=CutFromList(ln,l1);}
		
		ln=SortedList(ln,prmcmp);
		ld=SortedList(ld,prmcmp);
		
		if((GetAtomProperty(CompoundArg2(f1),A_ANTI)==CompoundArg2(f1) ||
				GetAtomProperty(CompoundArg2(f2),A_ANTI)==CompoundArg2(f2))
			&& strcmp(AtomValue(CompoundArg2(f1)),AtomValue(CompoundArg2(f2)))>0)
		{
			Term tmp=f1;
			f1=f2;
			f2=tmp;
		}
		
		if(ListLength(CompoundArg1(f1))==1 && ListLength(CompoundArg1(f1))==1)
		{
			Term i1=ListFirst(CompoundArg1(f1));
			Term i2=ListFirst(CompoundArg1(f2));
			if(CompoundName(CompoundArg1(i1))!=A_COLOR ||
				CompoundName(CompoundArg1(i2))!=A_COLOR ||
					CompoundArg2(i1)!=CompoundArg2(i2))
			{
				ErrorInfo(233);
				puts("bad color stru in let-sub.");
				return;
			}
			SetCompoundArg(i1,2,mylbl);
			SetCompoundArg(i2,2,mylbl);
		}
		
		ln=AppendLast(ln,f1);
		ln=AppendLast(ln,f2);
		if(w) ln=AppendLast(ln,w);
		
		SetCompoundArg(m1,1,NewInteger(n));
		SetCompoundArg(m1,2,NewInteger(d));
		SetCompoundArg(m1,3,ln);
		SetCompoundArg(m1,4,ld);
		
		for(l1=nl;l1;l1=ListTail(l1))
		{
			if(EqualTerms(CompoundArgN(ListFirst(l1),3),ln) &&
					EqualTerms(CompoundArgN(ListFirst(l1),4),ld) &&
					IntegerValue(CompoundArg2(ListFirst(l1)))*d>0)
			{
				Term om1=ListFirst(l1);
				int n1=IntegerValue(CompoundArg1(om1));
				int d1=IntegerValue(CompoundArg2(om1));
				int rn,rd,cc=0;
				if(d1<0)
				{
					d=-d;d1=-d1;cc=1;
				}
				rn=n*d1+n1*d;
				rd=d*d1;
				if(rn==0)
				{
					nl=CutFromList(nl,l1);
					break;
				}
				g=gcf(rn,rd);
				rn/=g; rd/=g;
				if(cc) rd=-rd;
				SetCompoundArg(om1,1,NewInteger(rn));
				SetCompoundArg(om1,2,NewInteger(rd));
				FreeAtomic(m1);
				break;
			}
		}
		
		if(l1==0)
			nl=AppendLast(nl,m1);
		
	}
	
	RemoveList(lm);
	/*DumpList(nl);*/
	
	/*printf("%d\n",ListLength(nl));*/
	SetCompoundArg(a1,1,nl);
}
Beispiel #21
0
static Atomic read_a(char *s, int *len)
	{
	if(s[0]=='(')
		{ *len=1; return A_RBRA; }
	if(s[0]==')')
		{ *len=1; return A_RCET; }
	if(s[0]=='{')
		{ *len=1; return A_FBRA; }
	if(s[0]=='}')
		{ *len=1; return A_FCET; }
	if(s[0]=='[')
		{ *len=1; return A_QBRA; }
	if(s[0]==']')
		{ *len=1; return A_QCET; }
	if(s[0]=='.')
		{ *len=1; return A_POINT; }
	if(s[0]==';')
		{ *len=1; return A_SECO; }
	if(s[0]==',')
		{ *len=1; return A_COMMA; }
	if(s[0]=='\'')
		return read_quoted(s,len,'\'');
	if(s[0]=='\"')
		return read_quoted(s,len,'\"');
	if(s[0]=='`')
		{ *len=1; return A_RQUOTE; }
	
	if(isalpha(s[0]) || s[0]=='_' || s[0]=='~')
		{
		int alen;
		alen=0;
		while(isalnum(s[alen]) || s[alen]=='_' || s[alen]=='~' )
			alen++;
		*len=alen;
		return NewAtom(s,alen);
		}
	/* test for numbers */
	if(isdigit(s[0]) /*|| (s[0]=='-' && isdigit(s[1]))*/ )
		{
		int negflag=0;
		int alen=0;
		int lll;
		if(s[0]=='-')
			{negflag=1; s++; alen++; }
		lll=0;
		while(isdigit(s[lll])) lll++;
		if((s[lll]=='e' || s[lll]=='E') && (isdigit(s[lll+1]) || s[lll+1]=='-'))
			{
			double f=0.0;
			int eneg=0,exp=0;
			while(s[0]!='e' && s[0]!='E')
				{
				f*=10.0;
				f+=s[0]-'0';
				s++;
				alen++;
				}
			if(negflag) f=-f;
			s++; alen++;
			if(s[0]=='-')
				{
				s++; alen++; eneg=1;
				}
			if(s[0]=='+')
				{
				s++; alen++;
				}
			while(isdigit(s[0]))
				{
				exp*=10;
				exp+=s[0]-'0';
				s++; alen++;
				}
			if(eneg) exp=-exp;
			f*=pow(10.0,exp);
			*len=alen;
			return NewFloat(f);
			}
				
		if(s[lll]=='.' && isdigit(s[lll+1]))
			{
			double f=0.0;
			double fact=1.0;
			while(s[0]!='.')
				{
				f*=10.0;
				f+=s[0]-'0';
				s++;
				alen++;
				}
			s++; alen++;
			while(isdigit(s[0]))
				{
				fact/=10.0;
				f+=fact*(s[0]-'0');
				s++; alen++;
				}
			if(negflag) f=-f;
			if(s[0]=='e' || s[0]=='E')
				{
				int eneg=0;
				int exp=0;
				s++; alen++;
				if(s[0]=='-')
					{
					s++; alen++; eneg=1;
					}
				if(s[0]=='+')
					{
					s++; alen++;
					}
				while(isdigit(s[0]))
					{
					exp*=10;
					exp+=s[0]-'0';
					s++; alen++;
					}
				if(eneg) exp=-exp;
				f*=pow(10.0,exp);
				}
			*len=alen;
			return NewFloat(f);
			}
		lll=0;
		while(isdigit(s[0]))
			{
			lll*=10;
			lll+=s[0]-'0';
			s++;
			alen++;
			}
		if(negflag) lll=-lll;
		*len=alen;
		return NewInteger(lll);
		}
				
			
		
	if(ispunct(s[0]))
		{
		int alen;
		alen=0;
		while(ispunct(s[alen]) && !alone(s[alen]) && 
			!(alen>0 && s[alen-1] == '=' && s[alen]!= '=') )
			alen++;
		*len=alen;
		return NewAtom(s,alen);
		}
	
			
	*len=1;
	return NewAtom("???",0);
	}
Beispiel #22
0
static Term dif_term(Term t)
	{
	if(t==A_SQRT2 || t==A_I || is_float(t) || is_integer(t))
		return 0;
	
	if(is_atom(t) && is_parameter(t))
		return MakeCompound1(OPR_USCORE,t);
	
	if(!is_compound(t))
		{
		printf("Can't variate "); WriteTerm(t); puts(""); return 0;
		}
	
	if(CompoundName(t)==OPR_PLUS && CompoundArity(t)==2)
		{
		Term d1,d2;
		d1=dif_term(CompoundArg1(t));
		d2=dif_term(CompoundArg2(t));
		if(d1==0 && d2==0)
			return 0;
		if(d1==0)
			return d2;
		if(d2==0)
			return d1;
		return MakeCompound2(OPR_PLUS,d1,d2);
		}
	if(CompoundName(t)==OPR_MINUS && CompoundArity(t)==2)
		{
		Term d1,d2;
		d1=dif_term(CompoundArg1(t));
		d2=dif_term(CompoundArg2(t));
		if(d1==0 && d2==0)
			return 0;
		if(d1==0)
			return d2;
		if(d2==0)
			return d1;
		return MakeCompound2(OPR_MINUS,d1,d2);
		}
	if(CompoundName(t)==OPR_MINUS && CompoundArity(t)==1)
		{
		Term d1;
		d1=dif_term(CompoundArg1(t));
		if(d1==0)
			return 0;
		return MakeCompound1(OPR_MINUS,d1);
		}
		
	if(CompoundName(t)==A_SQRT && CompoundArity(t)==1)
		{
		Term d1;
		d1=dif_term(CompoundArg1(t));
		if(d1==0)
			return 0;
		if(is_compound(d1) && CompoundName(d1)==OPR_MLT &&
			CompoundArg1(d1)==NewInteger(2))
				{
				Term d2;
				d2=ConsumeCompoundArg(d1,2);
				FreeAtomic(d1);
				return MakeCompound1(OPR_MINUS, 
					MakeCompound2(OPR_DIV,d2,t));
				}
		return MakeCompound1(OPR_MINUS,
			MakeCompound2(OPR_DIV, d1, 
				MakeCompound2(OPR_MLT, NewInteger(2), t)));
		}
		
	if(CompoundName(t)==OPR_POW && CompoundArity(t)==2)
		{
		Term d1;
		int ppow;
		ppow=IntegerValue(CompoundArg2(t));
		d1=dif_term(CompoundArg1(t));
		if(d1==0)
			return 0;
		if(ppow==2)
			return MakeCompound2(OPR_MLT,NewInteger(2),
				MakeCompound2(OPR_MLT, CompoundArg1(t), d1));
		return MakeCompound2(OPR_MLT, d1, MakeCompound2(OPR_POW,
			CompoundArg1(t),NewInteger(ppow-1)));
		}
	
	if(CompoundName(t)==OPR_MLT && CompoundArity(t)==2)
		{
		Term d1,d2;
		d1=dif_term(CompoundArg1(t));
		d2=dif_term(CompoundArg2(t));
		if(d1==0 && d2==0)
			return 0;
		if(d1==0)
			return MakeCompound2(OPR_MLT,CompoundArg1(t),d2);
		if(d2==0)
			return MakeCompound2(OPR_MLT,CompoundArg2(t),d1);
		return MakeCompound2(OPR_PLUS,
			MakeCompound2(OPR_MLT,CompoundArg1(t),d2),
			MakeCompound2(OPR_MLT,CompoundArg2(t),d1));
		}
		
	if(CompoundName(t)==OPR_DIV && CompoundArity(t)==2)
		{
		Term d1,d2;
		d1=dif_term(CompoundArg1(t));
		d2=dif_term(CompoundArg2(t));
		if(d1==0 && d2==0)
			return 0;
		if(d1==0)
			return 
				MakeCompound1(OPR_MINUS,
					MakeCompound2(OPR_DIV,
						MakeCompound2(OPR_MLT,d2,CompoundArg1(t)),
						MakeCompound2(OPR_POW,CompoundArg2(t),NewInteger(2))
							     )
							 );
		if(d2==0)
			return MakeCompound2(OPR_DIV,d1,CompoundArg2(t));
				
		return 
			MakeCompound2(OPR_DIV,
				MakeCompound2(OPR_MINUS,
					MakeCompound2(OPR_MLT,d1,CompoundArg2(t)),
					MakeCompound2(OPR_MLT,d2,CompoundArg1(t))
							 ),
				MakeCompound2(OPR_POW,CompoundArg2(t),NewInteger(2))
				);
		}
	
	printf("Can't variate "); WriteTerm(t); puts("");
	return 0;
	
	}
Beispiel #23
0
static int set_ppl(void)
	{
	List l;
	
	if(PROP_PPL==0) PROP_PPL=NewAtom("pprtlst",0);
	if(prop_gened)
		return 1;
	if(vlist==0) 
		
	{
		vlist=all_vert_list();
		for(l=vlist; !is_empty_list(l); l=ListTail(l))
		{
		Term a2;
		a2=ListFirst(l); 
		alg2_common_s(a2);
		alg2_common_n(a2);
		alg2_red_cos(a2);
		alg2_red_orth(a2);
		}
	}
			
	for(l=vlist; !is_empty_list(l); l=ListTail(l))
		{
		List pl,l1,l2,lr;
		
		pl=CompoundArg1(ListFirst(l));
		if(ListLength(pl)<3 || CompoundArg2(ListFirst(l))==NewInteger(0) ||
		 is_empty_list(CompoundArgN(ListFirst(l),5)))
			continue;
			

#ifdef DBG_PPL
		WriteVertex(pl); printf(": ");
#endif
		
		l1=pl;
		while(!is_empty_list(l1))
			{
			Atom pp,app;
			Term prop;
			pp=CompoundArg1(ListFirst(l1));
			prop=GetAtomProperty(pp,PROP_TYPE);
			app=remcc(pp);
			if(!ListMember(plist,app))
				plist=AppendFirst(plist,app);
			
#ifdef DBG_PPL
			WriteTerm(app); printf(" -> ");
#endif
			
			
			lr=NewList();
			l2=pl;
			while(!is_empty_list(l2))
				{
				Atom a;
				if(l2==l1)
					{
					l2=ListTail(l2);
					continue;
					}
				a=remcc(CompoundArg1(ListFirst(l2)));
				lr=AppendLast(lr,a);
				l2=ListTail(l2);
				}
			
			prop=GetAtomProperty(app,PROP_PPL);
			if(prop==0)
				SetAtomProperty(app,PROP_PPL,AppendFirst(NewList(),lr));
			else
				AppendLast(prop,lr);
#ifdef DBG_PPL
			WriteTerm(lr); printf(" ");
#endif
			while(!is_empty_list(l1) && 
					remcc(CompoundArg1(ListFirst(l1)))==app)
				l1=ListTail(l1);
			}
#ifdef DBG_PPL
		puts("");
#endif
		}
		
	if(ListLength(plist)>1)		
		plist=SortedList(plist,p__cmp);
		
	prop_gened=1;
	return 1;
	}
Beispiel #24
0
Term AtomicTo1(Term t, Term ind)
	{
	List rl;
	Term ret;
	Term t1;
	Atom ttype;
	
	if(is_compound(t) && CompoundName(t)==A_ALG1)
	{
		List l;
		ttype=A_ALG1;
		rl=CopyTerm(CompoundArg2(t));
		for(l=rl;l;l=ListTail(l))
			SetCompoundArg(ListFirst(l),2,0);
		goto cnt;
	}
	
	if(is_compound(t) && CompoundName(t)==A_FBRACET)
		{
		t=alg1_mk_wild(t,&rl,&ind);
		ttype=OPR_WILD;
		goto cnt;
		}
	/*
	if(is_compound(t) && CompoundName(t)==A_CC)
		{
		t=cc_particle(t,&rl);
		ttype=OPR_FIELD;
		goto cnt;
		}
	*/
	
	if(is_let(t,&rl))
		{
		ttype=OPR_LET;
		goto cnt;
		}
	
	if(is_parameter(t) || (is_compound(t) && (CompoundName(t)==A_COS ||
						CompoundName(t)==A_SIN)) )
		{
		rl=NewList();
		ttype=OPR_PARAMETER;
		goto cnt;
		}
		
	if(is_particle(t,&rl))
		{
		ttype=OPR_FIELD;
		goto cnt;
		}
		
	if(is_special(t,&rl))
		{
		ttype=OPR_SPECIAL;
		goto cnt;
		}
	
	ErrorInfo(301);
	printf(" \'%s\' undefined object.\n",AtomValue(t));
	FreeAtomic(ind);
	longjmp(alg1_jmp_buf,1);
cnt:
	ret=MakeCompound(A_MTERM,4);
	SetCompoundArg(ret,1,NewInteger(1));
	SetCompoundArg(ret,2,NewInteger(1));
	t1=0;
	if(!is_empty_list(rl))
		{
		Term ttt;
		int skipped;
		rl=CopyTerm(rl);
		if(is_empty_list(ind))
			{
			SetCompoundArg(ret,3,AppendFirst(NewList(),MakeCompound2(ttype,rl,t)));
			return AppendFirst(NewList(),ret);
			}
		skipped=must_skip(ListLength(ind),rl);
		if(skipped==-1)
			{
			ErrorInfo(302);
			printf(" can not set indices ");
			WriteTerm(ind);
			printf(" to \'%s\'.\n",AtomValue(t));
			FreeAtomic(ind); FreeAtomic(rl);
			longjmp(alg1_jmp_buf,1);
			}
		
		t1=rl;	
		ttt=ind;
		while(!is_empty_list(rl))
			{
			if(skipped!=0 && should_skip(skipped,CompoundArg1(ListFirst(rl))))
				{ rl=ListTail(rl); continue; }
			SetCompoundArg(ListFirst(rl),2,ListFirst(ttt));
			rl=ListTail(rl);
			ttt=ListTail(ttt);
			}
		FreeAtomic(ind);
		}
		
	if(ttype==OPR_PARAMETER && is_compound(t))
	{
	Term mmm=MakeCompound(ttype,CompoundArity(t)+2);
	SetCompoundArg(mmm,1,t1);
	SetCompoundArg(mmm,2,CompoundName(t));
	SetCompoundArg(mmm,3,CompoundArg1(t));
	if(CompoundArity(t)==2)
		{
		Term m=ExprTo1(ConsumeCompoundArg(t,2));
		m=CompoundArg1(m);
		if(ListLength(m)!=1)
			{
			ErrorInfo(0);
			puts("bad expression in sin/cos.");
			longjmp(alg1_jmp_buf,1);
			}
		m=ListFirst(m);
		SetCompoundArg(mmm,4,m);
		}
	SetCompoundArg(ret,3,AppendFirst(NewList(),mmm));
	}
	else
	SetCompoundArg(ret,3,AppendFirst(NewList(),MakeCompound2(ttype,t1,t)));
	return AppendFirst(NewList(),ret);
	
	}
Beispiel #25
0
Term ProcCoefVrt(Term t, List ind)
{
	List l,pl,ml;
	int  ii;
	Term a2;
	int g=0, g5=0, re=0, im=0, abbr=0, cmplx=0;
	
	if(!is_compound(t) || CompoundArity(t)>2 || !is_list(CompoundArg1(t)))
	{
		ErrorInfo(0);
		puts("wrong parameters of CoefVrt function.");
		return 0;
	}
	
	if(lagr_hash==NULL)
	{
		ErrorInfo(107);
		puts("CoefVrt: no vertices");
		return 0;
	}
	
	mmm=0;
	if(CompoundArity(t)==2)
	{
		List ol=CompoundArg2(t);
		if(!is_list(ol))
		{
		ErrorInfo(107);
		puts("CoefVrt: second argument is not a list.");
		return 0;
		}
		for(;ol;ol=ListTail(ol))
		{
			Term o=ListFirst(ol);
			if(is_compound(o))
			{
				o=CompoundArg1(o);
				if(!is_atom(o) || !is_particle(o,0))
				{
					ErrorInfo(0);
					printf("CoefVrt: ");WriteTerm(o);
					puts(" is not a particle.\n");
					return 0;
				}
				mmm=o;
				continue;
			}
			if(!is_atom(o))
			{
				ErrorInfo(0);
				printf("CoefVrt: ");WriteTerm(o);
				puts(" is not an option.\n");
				return 0;
			}
			if(strcmp("gamma",AtomValue(o))==0)
			{
				g++;
				continue;
			}
			if(strcmp("gamma5",AtomValue(o))==0)
			{
				g5++;
				continue;
			}
			if(strcmp("re",AtomValue(o))==0)
			{
				re++;
				continue;
			}
			if(strcmp("im",AtomValue(o))==0)
			{
				im++;
				continue;
			}
			if(strcmp("abbr",AtomValue(o))==0)
			{
				abbr++;
				continue;
			}
			{
				ErrorInfo(0);
				printf("CoefVrt: ");WriteTerm(o);
				puts(" is not an option.\n");
				return 0;
			}
		}
	}
			
	if(re&&im)
		re=im=0;
			
	pl=ConsumeCompoundArg(t,1);
	for(l=pl;l;l=ListTail(l))
		if(is_function(ListFirst(l),0))
			ChangeList(l,CallFunction(ListFirst(l),0));

/*	for(l=pl;l;l=ListTail(l))
	{
		Term aa=ListFirst(l);
		if(is_compound(aa)&&CompoundName(aa)==A_ANTI)
			ChangeList(l,GetAtomProperty(CompoundArg1(aa),A_ANTI));
	}*/
	pl=SortedList(pl,acmp);
	
	l=finda2(pl,0);
	
	if(mmm && !mmmpos)
	{
		ErrorInfo(0);
		printf("CoefVrt: particle ");
		WriteTerm(mmm);
		puts(" not found in the vertex");
		return 0;
	}
	
		
	
	
	if(is_empty_list(l))
	{
	ErrorInfo(108);
	printf("CoefVrt: vertex ");
	WriteTerm(pl);
	puts(" not found");
	return NewInteger(0);
	}
	
	a2=CopyTerm(ListFirst(l));
	
	
	alg2_symmetrize(a2);
	alg2_common_n(a2);
	{
		int sv=kill_gamma_pm;
		kill_gamma_pm=1;
		alg2_red_1pm5(a2);
		kill_gamma_pm=sv;
	}
	alg2_recommon_n(a2);
		
	ml=ConsumeCompoundArg(a2,5);
	for(l=ml;l;l=ListTail(l))
	{
		List l1,ll;
		int tg=0, tg5=0, tm=0;
		for(l1=CompoundArgN(ListFirst(l),3);l1;l1=ListTail(l1))
		{
			Term tt=ListFirst(l1);
			if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA)
				tg++;
			if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA5)
				tg5++;
			if(CompoundName(tt)==A_MOMENT && CompoundArg1(tt)==
						NewInteger(mmmpos))
				tm++;
		}
		if(g!=tg || g5!=tg5 || (mmm && !tm))
		{
			SetCompoundArg(ListFirst(l),1,0);
			continue;
		}
		if(!re && !im)
			continue;
		for(l1=CompoundArg2(ListFirst(l));l1;l1=ListTail(l1))
			if(GetAtomProperty(CompoundArg1(ListFirst(l1)),A_ANTI))
				cmplx++;
	}

	if( (re||im) && !cmplx)
		for(l=ml;l;l=ListTail(l))
		{
		List ll,l1;
		if(CompoundArg1(ListFirst(l))==0)
			continue;
		ll=ConsumeCompoundArg(ListFirst(l),2);
		for(l1=ll;l1;l1=ListTail(l1))
			if(CompoundArg1(ListFirst(l1))==A_I)
				break;
		if( (re && l1) || (im && !l1) )
			SetCompoundArg(ListFirst(l),1,0);
		if(im && l1)
			ll=CutFromList(ll,l1);
		SetCompoundArg(ListFirst(l),2,ll);
		}

		
rpt:
	for(l=ml;l;l=ListTail(l))
		if(CompoundArg1(ListFirst(l))==0)
		{
			ml=CutFromList(ml,l);
			break;
		}
	if(l)
		goto rpt;
	
	SetCompoundArg(a2,5,ml);
	alg2_recommon_n(a2);
	alg2_common_s(a2);
	alg2_red_cos(a2);
	alg2_red_orth(a2);
	alg2_red_sico(a2);
	alg2_red_comsico(a2);
	alg2_recommon_n(a2);
	if(abbr)
	{
		int trisv=opTriHeu;
		alg2_eval_vrt(a2);
		doing_abbr=0;
		opTriHeu=trisv;
	}
	
	{
	int n,d;
	Term cf;
	Term res;
	n=IntegerValue(CompoundArg1(CompoundArg2(a2)));
	d=IntegerValue(CompoundArg2(CompoundArg2(a2)));
	cf=l2expr(CompoundArgN(a2,3),n);
	ml=CompoundArgN(a2,5);
	if(ml==0)
		return NewInteger(0);
	res=l2expr(CompoundArg2(ListFirst(ml)),
			IntegerValue(CompoundArg1(ListFirst(ml))));
	for(l=ListTail(ml);l;l=ListTail(l))
	{
		Term ccc;
		n=IntegerValue(CompoundArg1(ListFirst(l)));
		ccc=l2expr(CompoundArg2(ListFirst(l)),n>0?n:-n);
		if(n>0)
			res=MakeCompound2(OPR_PLUS,res,ccc);
		else
			res=MakeCompound2(OPR_MINUS,res,ccc);
	}
	if(res==NewInteger(1))
		res=cf;
	else
		res=MakeCompound2(OPR_MLT,cf,res);
	if(d!=1)
		res=MakeCompound2(OPR_DIV,res,NewInteger(d));
	if( (im||re) && cmplx)
		res=MakeCompound1(NewAtom(re?"creal":"cimag",0),res);
		
	return res;
	}
	return a2;
	
}
Beispiel #26
0
Term ProcLet(Term t, Term ind)
	{
	Term t1,nm,sub,kl=0;
	List il,ol,l1;	
	int transf_fl=0;
	
	Atom anti1=0, anti2=0;
	
	ol=il=NewList();
	t1=ConsumeCompoundArg(t,1);
	FreeAtomic(t);
	
	t1=ProcessAlias(t1);
	
	if(is_compound(t1) && CompoundArity(t1)==2 && CompoundName(t1)==OPR_COMMA)
		{
		Term a1,a2;
		a1=ConsumeCompoundArg(t1,1);
		a2=ConsumeCompoundArg(t1,2);
		FreeAtomic(t1);
		ProcLet(MakeCompound1(OPR_LET,a1),0);
		ProcLet(MakeCompound1(OPR_LET,a2),0);
		return 0;
		}
		
		
	if(!is_compound(t1) || CompoundArity(t1)!=2 || 
	 (CompoundName(t1)!=OPR_EQSIGN && CompoundName(t1)!=OPR_RARROW))
		{
		ErrorInfo(325);
		printf("bad argument in let statement\n");
		return 0;
		}
		
	if(CompoundName(t1)==OPR_EQSIGN && is_atom(CompoundArg1(t1)) &&
		is_atom(CompoundArg2(t1)) &&
		(CompoundArg2(t1)==A_GAMMA5 || GetAtomProperty(CompoundArg2(t1),
		A_GAMMA5)))
		{
		SetAtomProperty(CompoundArg1(t1),A_GAMMA5,NewInteger(1));
		}
		
	if(CompoundName(t1)==OPR_RARROW)
		transf_fl=1;
	
	if(CompoundName(t1)==OPR_EQSIGN && is_atom(CompoundArg1(t1)) &&
			is_compound(CompoundArg2(t1)) && 
			CompoundName(CompoundArg2(t1))==A_ANTI &&
			is_atom(CompoundArg1(CompoundArg2(t1))))
		{
		anti1=CompoundArg1(t1);
		anti2=CompoundArg1(CompoundArg2(t1));
		}
		
	nm=ConsumeCompoundArg(t1,1);
	sub=ConsumeCompoundArg(t1,2);
	FreeAtomic(t1);
	
	if(transf_fl)
		allow_transf_lets=0;
	
	if(is_compound(nm) && (CompoundName(nm)==OPR_USCORE ||
								 CompoundName(nm)==OPR_CARET))
		nm=SplitIndices(nm,&il);
	
	if(!is_atom(nm))
		{
		ErrorInfo(325);
		printf("bad left argument in let call\n");
		FreeAtomic(sub);
		FreeAtomic(t1);
		return 0;
		}
		
	if(transf_fl)
		{
		if(!is_parameter(nm) && !is_particle(nm,NULL))
			{
			ErrorInfo(728);
			printf("Unknown object '%s'.\n",AtomValue(nm));
			return 0;
			}
		}
	
	if(GetAtomProperty(nm,A_KEEP_LETS))
	{
		Term prp;
		kl=ExprTo1kl(CopyTerm(sub));
		if(kl==0)
			return 0;
		prp=GetAtomProperty(nm,A_KEEP_LETS);
		SetCompoundArg(prp,1,kl);
	}
	
	sub=ExprTo1(sub);
	
	alg1_set_cos0(sub);
	
	if(sub==0)
		return 0;
	if(transf_fl)
		allow_transf_lets=1;
			
	t1=CopyTerm(CompoundArg2(sub));

	
	if(is_empty_list(il))
		{
		l1=t1;
		while(!is_empty_list(l1))
			{
			Term t;
			t=CompoundArg2(ListFirst(l1));
			if(!is_label(t))
				{
				ErrorInfo(326);
				printf("unbalanced index '");
				WriteTerm(t);
				printf("' in let statement\n");
				FreeAtomic(sub);
				FreeAtomic(t1);
				FreeAtomic(ol);
				return 0;
				}
			ol=AppendLast(ol,t);
			l1=ListTail(l1);
			}
		/* mk_let(nm,sub,ol,t1); */
		}
	else
		{
		List t2;
		t2=0;
		if(ListLength(il)!=ListLength(t1))
				{
				ErrorInfo(327);
				printf("distinct indices number ");
				printf("in let statement.\n");
				FreeAtomic(sub);
				FreeAtomic(t1);
				return 0;
				}			
		l1=t1;
		while(!is_empty_list(l1))
			{
			Term t;
			t=CompoundArg2(ListFirst(l1));
			if(!is_atom(t) || !ListMember(il,t))
				{
				ErrorInfo(326);
				printf("unbalanced index '");
				WriteTerm(t);
				printf("' in let statement\n");
				FreeAtomic(sub);
				FreeAtomic(t1);
				FreeAtomic(ol);
				return 0;
				}
			ol=AppendLast(ol,t);
			l1=ListTail(l1);
			}
		l1=il;
		while(!is_empty_list(l1))
			{
			List l2;
			if(!ListMember(ol,ListFirst(l1)))
				{
				ErrorInfo(326);
				printf("unbalanced index '");
				WriteTerm(t);
				printf("' in let statement\n");
				FreeAtomic(sub);
				FreeAtomic(t1);
				FreeAtomic(ol);
				return 0;
				}
				
			for(l2=t1;l2;l2=ListTail(l2))
				if(ListFirst(l1)==CompoundArg2(ListFirst(l2)))
					{
					t2=AppendLast(t2,ListFirst(l2));
					break;
					}
				
			l1=ListTail(l1);
			}
		RemoveList(t1);
		t1=t2;
		FreeAtomic(ol);
		ol=il;		
		}	
	
	/* mk_let(nm,sub,ol,t1); */
	
	
	l1=t1;
	while(!is_empty_list(l1))
		{
		SetCompoundArg(ListFirst(l1),2,0);
		l1=ListTail(l1);
		}
		
	/*WriteTerm(sub); puts(""); getchar();*/

		
	t=MakeCompound(OPR_LET,5);
	SetCompoundArg(t,1,sub);
	SetCompoundArg(t,2,ol);
	SetCompoundArg(t,3,alg1_inv_alg(sub));
	
	
	if(transf_fl==0)
		{
		Term tt;
		tt=alg1_guess_mpl(sub);
		if(tt)
		{
			SetCompoundArg(t,4,NewInteger(1));
			SetCompoundArg(t,5,tt);
		}
		else
		{
			int tp;
			tt=alg1_guess_mtr(sub, &tp);
			if(tt)
			{
				SetCompoundArg(t,4,NewInteger(tp));
				SetCompoundArg(t,5,tt);
			}
		}
		
		ReportRedefined(nm,"let-substitution");
		SetAtomProperty(nm,PROP_INDEX,t1);
		SetAtomProperty(nm,PROP_TYPE,t);
		alg1_let_cw(nm);
		if(anti1 && anti2)
			{
			SetAtomProperty(anti1,A_ANTI,anti2);
			SetAtomProperty(anti2,A_ANTI,anti1);
			}
		else
			if(only_prm(CompoundArg1(t)))
				SetAtomProperty(nm,A_ANTI,nm);
		return 0;
		}
		
	l1=GetAtomProperty(nm,PROP_INDEX);
	if(!EqualTerms(l1,t1))
		{
		ErrorInfo(729);
		puts("transformed object has other indices types");
		return 0;
		}
	if(GetAtomProperty(nm,OPR_LET))
		{
		WarningInfo(0);
		printf("Warning: transformation rule for '%s' is redefined.\n",
			AtomValue(nm));
		}
	SetAtomProperty(nm,OPR_LET,t);
	return 0;
	}
Beispiel #27
0
Term alg1_inv_alg(Term a1)
	{
	List l, l1, lm;
	Term m2_b, m2_b2;
	List m2_i;
	l=CompoundArg1(a1);
	if(CompoundArg2(a1))
		return 0;
	
	m2_i=m2_b=0;
	
	for(l1=l;l1;l1=ListTail(l1))
		{
		Term m1;
		List l2;
		int  ino;
		ino=0;
		m1=ListFirst(l1);
		for(l2=CompoundArgN(m1,3);l2;l2=ListTail(l2))
			{
			Term prp=0;
			if(CompoundName(ListFirst(l2))==OPR_PARAMETER)
				prp=GetAtomProperty(CompoundArg2(ListFirst(l2)),A_INFINITESIMAL);
			else
				{
				RemoveList(m2_i);
				return 0;
				}
			if(prp && IntegerValue(CompoundArg1(prp))>0)
				ino+=IntegerValue(CompoundArg1(prp));
			}
		if(!ino)
			{
			if(m2_b)
				{
				RemoveList(m2_i);
				return 0;
				}
			m2_b=m1;
			}
		else
			m2_i=AppendLast(m2_i,m1);
		}
	if(m2_b==0)
		return 0;
	m2_b=CopyTerm(m2_b);
	l=ConsumeCompoundArg(m2_b,3);
	l1=ConsumeCompoundArg(m2_b,4);
	SetCompoundArg(m2_b,3,l1);
	SetCompoundArg(m2_b,4,l);
		
		{
		int n, ns, d, ds;
		n=IntegerValue(CompoundArg1(m2_b));
		d=IntegerValue(CompoundArg2(m2_b));
		ns=ds=1;
		if(n<0)
			{
			ns=-1;
			n=-n;
			}
		if(d<0)
			{
			ds=-1;
			d=-d;
			}
		SetCompoundArg(m2_b,1,NewInteger(d*ns));
		SetCompoundArg(m2_b,2,NewInteger(n*ds));
		}
	
	lm=AppendLast(NewList(),m2_b);
	if(m2_i)
		{
		m2_b2=CopyTerm(m2_b);
		l=ConsumeCompoundArg(m2_b2,3);
		l=ConcatList(l,CopyTerm(l));
		SetCompoundArg(m2_b2,3,l);
		l=ConsumeCompoundArg(m2_b2,4);
		l=ConcatList(l,CopyTerm(l));
		SetCompoundArg(m2_b2,4,l);
			{
			int n,d,n1,d1;
			n=IntegerValue(CompoundArg1(m2_b2));
			d=IntegerValue(CompoundArg2(m2_b2));
			c_mlt(n,d,-n,d,&n1,&d1);
			SetCompoundArg(m2_b2,1,NewInteger(n1));
			SetCompoundArg(m2_b2,2,NewInteger(d1));
			}
		for(l=m2_i;l;l=ListTail(l))
			{
			Term a1;
			a1=MakeCompound(A_MTERM,4);
			l1=ConcatList(CopyTerm(CompoundArgN(m2_b2,3)),
						  CopyTerm(CompoundArgN(ListFirst(l),3)));
			SetCompoundArg(a1,3,l1);
			l1=ConcatList(CopyTerm(CompoundArgN(m2_b2,4)),
						  CopyTerm(CompoundArgN(ListFirst(l),4)));
			SetCompoundArg(a1,4,l1);
				{
				int n,d;
				c_mlt(	IntegerValue(CompoundArg1(m2_b2)),
						IntegerValue(CompoundArg2(m2_b2)),
						IntegerValue(CompoundArg1(ListFirst(l))),
						IntegerValue(CompoundArg2(ListFirst(l))),
						&n,&d);
				SetCompoundArg(a1,1,NewInteger(n));
				SetCompoundArg(a1,2,NewInteger(d));
				}
			lm=AppendLast(lm,a1);
			
			}
		RemoveList(m2_i);
		FreeAtomic(m2_b2);
		}
/*    DumpList(lm);*/	
	return MakeCompound2(A_ALG1,lm,0);		
	
	}	
Beispiel #28
0
HandleProxy* V8EngineProxy::CreateInteger(int32_t num)
{
	return GetHandleProxy(NewInteger(num));
}
Beispiel #29
0
Term ProcMkProc(Term t, Term ind)
{
	Atom prt[4];
	Atom mass[4];
	Term color[4];
	int spin[4];
	int i;
	int neufact=1;
	double thcut=0.0;
	int dec=0;
	char pname[128];
	FILE *f;
	
	if(CompoundArity(t)==1)
	{
		List l,dlist;
		double m1;
		set_ppl();
		
		l=GetAtomProperty(CompoundArg1(t),PROP_TYPE);
		if(!is_compound(l)||CompoundName(l)!=OPR_PARTICLE ||
				CompoundArgN(l,5)==0)
			{
			ErrorInfo(0);
			WriteTerm(t);
			printf(" : decays are not generated.\n");
			return 0;
			}
		m1=fabs(EvalParameter(CompoundArgN(l,5)));
		
		dlist=GetAtomProperty(CompoundArg1(t),PROP_PPL);
		for(l=dlist;l;l=ListTail(l))
		{
			List pl=ListFirst(l);
			Atom prp,a;
			Atom ap1, ap2;
			double m2,m3;
			int is_neut;
			
			if(ListLength(pl)!=2)
				continue;
			prp=GetAtomProperty(ListFirst(pl),PROP_TYPE);
			if(!is_compound(prp)||CompoundName(prp)!=OPR_PARTICLE)
				continue;
			if(CompoundArgN(prp,7)==OPR_MLT)
				continue;
			a=CompoundArgN(prp,5);
			if(a==0)
				continue;
			else
				m2=fabs(EvalParameter(a));
				
			prp=GetAtomProperty(ListFirst(ListTail(pl)),PROP_TYPE);
			if(!is_compound(prp)||CompoundName(prp)!=OPR_PARTICLE)
				continue;
			if(CompoundArgN(prp,7)==OPR_MLT)
				continue;
			a=CompoundArgN(prp,5);
			if(a==0)
				continue;
			else
				m3=fabs(EvalParameter(a));
				
			if(m1<=m2+m3)
				continue;
			
			is_neut=(CompoundArg1(t)==GetAtomProperty(CompoundArg1(t),A_ANTI));
			
			ap1=GetAtomProperty(ListFirst(pl),A_ANTI);
			ap2=GetAtomProperty(ListFirst(ListTail(pl)),A_ANTI);
			
			if(is_neut)
			{
				List l1;
				for(l1=dlist;l1!=l;l1=ListTail(l1))
				{
				if( (ListFirst(ListFirst(l1))==ap1 && 
							ListFirst(ListTail(ListFirst(l1)))==ap2) ||
					(ListFirst(ListFirst(l1))==ap2 && 
							ListFirst(ListTail(ListFirst(l1)))==ap1))
					break;
				}
				if(l1!=l)
					continue;
			}
			
			/*WriteTerm(CompoundArg1(t));printf(" -> ");
			WriteTerm(pl);puts("");*/
			prp=MakeCompound(A_I,4);
			SetCompoundArg(prp,1,CompoundArg1(t));
			SetCompoundArg(prp,2,NewInteger(0));
			SetCompoundArg(prp,3,is_neut?ListFirst(pl):ap1);
			SetCompoundArg(prp,4,is_neut?ListFirst(ListTail(pl)):ap2);
			ProcMkProc(prp,0);
			
		}
		return 0;
	}
	
	if(CompoundArity(t)<4)
		{
		ErrorInfo(2000);
		puts("mkProc: wrong argument number.");
		return 0;
		}
		
	for(i=5;i<=CompoundArity(t);i++)
		{
		Term t1=CompoundArgN(t,i);
		if(is_compound(t1) && is_atom(CompoundArg1(t1)) &&
			strcmp(AtomValue(CompoundArg1(t1)),"THETACUT")==0)
			{
			if(is_integer(CompoundArg2(t1)))
				thcut=IntegerValue(CompoundArg2(t1));
			else if(is_float(CompoundArg2(t1)))
				thcut=FloatValue(CompoundArg2(t1));
			else
				{
				ErrorInfo(303);puts("wrong THETACUT value.");
				continue;
				}
			continue;
			}
		ErrorInfo(304);
		puts("wrong argument in mkProc.");
		}
			
		
		
	for(i=0;i<4;i++)
		{
		Term prp, t7;
		prt[i]=CompoundArgN(t,i+1);
		if(prt[i]==NewInteger(0)&&i==1)
			{
			dec=1;spin[i]=0;color[1]=0;
			continue;
			}
		if(!is_particle(prt[i],NULL))
			{
			ErrorInfo(2001);
			WriteTerm(prt[i]);
			puts(": is not a particle.");
			return 0;
			}
		prp=GetAtomProperty(prt[i],PROP_TYPE);
		if(CompoundName(prp)!=OPR_PARTICLE)
			{
			ErrorInfo(2001);
			WriteTerm(prt[i]);
			puts(": is not a particle.");
			return 0;
			}
		if(prt[i]==CompoundArg2(prp))
			prp=GetAtomProperty(CompoundArg1(prp),PROP_TYPE);
		spin[i]=IntegerValue(CompoundArgN(prp,4));
		mass[i]=CompoundArgN(prp,5);
		color[i]=GetAtomProperty(prt[i],A_COLOR);
		t7=CompoundArgN(prp,7);
		if(i<2 && (t7==A_LEFT||t7==A_RIGHT))
			neufact*=2;
		}
	
	if(dec==0)	
	sprintf(pname,"%s%s__%s%s",AtomValue(prt[0]),AtomValue(prt[1]),
			AtomValue(prt[2]),AtomValue(prt[3]));
	else
	sprintf(pname,"%s__%s%s",AtomValue(prt[0]),
			AtomValue(prt[2]),AtomValue(prt[3]));
	
	
	for(i=0;pname[i];i++)
		{
		if(pname[i]=='~') pname[i]='_';
		if(pname[i]=='+') pname[i]='p';
		if(pname[i]=='-') pname[i]='m';
		}
	
	f=fopen("scan.bat",inifile?"a":"w");
	if(f==NULL)
		{
		ErrorInfo(2000);
		puts("mkProc: can not open scan.bat");
		return 0;
		}
		
	if(!inifile)
		{
		fprintf(f,"#!/bin/sh\n\n");
		inifile=1;
		}
		
	fprintf(f,"echo Generating process %s   `date`\n\n",pname);
	fprintf(f,"echo Process %s:  >> scan.log\n",pname);
	fprintf(f,"num0=`date +%%s`\n");
	fprintf(f,"cat > proc.m <<END\n");
	if(dec==0)
	fprintf(f,"process = {prt[\"%s\"],prt[\"%s\"]} ->",
			AtomValue(prt[0]),AtomValue(prt[1]));
	else
	fprintf(f,"process = {prt[\"%s\"]} ->",
			AtomValue(prt[0]));
	
	fprintf(f," {prt[\"%s\"],prt[\"%s\"]}\n",
			AtomValue(prt[2]),AtomValue(prt[3]));
	if(FAver==4)
		fprintf(f,"dir = SetupCodeDir[\"scan_%s\"]\n",pname);
	if(FAver>4)
		fprintf(f,"name = \"%s\"\n",pname);
	fprintf(f,"SetOptions[InsertFields,Model->model%d, GenericModel->model%d,\n",
				ModelNumber,ModelNumber);
	fprintf(f,"       ExcludeParticles->{ ");
	if(color[0]&&color[1]&&color[2]&&color[3])
		{
		int glu=1,gno=1;
		if(GetAtomProperty(prt[0],A_ANTI)!=prt[1]) glu=0;
		if(spin[0]==0&&spin[1]==0&&spin[2]==0&&spin[3]==0) gno=0;
		if(glu)
			fprintf(f,"prt[\"G\"]%c ",gno?',':' ');
		if(gno)
			fprintf(f,"prt[\"~%c\"] ",ModelNumber>30?'G':'g');
		}
	fprintf(f,"} ]\n");
	
	fprintf(f,"END\n\n");
	
	fprintf(f,"if test ! -d scan_%s/squaredme ;\n",pname);
	fprintf(f,"then  math < %s.m;\n",dec?"scand":"scan");
	fprintf(f,"fi\n\n");
	
	fprintf(f,"num1=$((`date +%%s`-num0))\nnum0=`date +%%s`\n\n");
	
	fprintf(f,"if test ! -d scan_%s/squaredme ;\n",pname);
	fprintf(f,"then echo Output directory is not created | tee -a scan.log && exit;\n");
	fprintf(f,"fi\n\n");
	
        fprintf(f,"if test ! -d drivers/F ;\n");
	fprintf(f,"then cat > scan_%s/process.h <<END\n",pname);
	for(i=1;i<=4;i++)
		{
		int i1=i;
		if(dec&&i==2) continue;
		if(dec&&i>2) i1=i-1;
		fprintf(f,"#define TYPE%d %s\n",i1,
				spin[i-1]==0?"SCALAR":(spin[i-1]==1?"FERMION":
					(mass[i-1]==0?"PHOTON":"VECTOR")));
		fprintf(f,"#define MASS%d %s\n",i1,mass[i-1]?AtomValue(mass[i-1]):"0");
		fprintf(f,"#define CHARGE%d 0\n\n",i1);
		}
	fprintf(f,"#define IDENTICALFACTOR %s\n",(prt[2]==prt[3])?"0.5":"1");
	fprintf(f,"#define COLOURFACTOR %dD0",neufact);
	if(color[0] && color[1]) fprintf(f,"/9D0");
	else if(color[0] || color[1]) fprintf(f,"/3D0");
	fprintf(f,"\n");
	if(FAver>4)
	{fprintf(f,"#define SCALE sqrtS\n#define LUMI \"lumi_parton.F\"\n");
	 fprintf(f,"c#define FORCE_ONSHELL\n");
	}
	fprintf(f,"#define NCOMP 2\n#include \"%cto2.F\"\nEND\n\nfi\n\n",dec?'1':'2');
	
	
	/*
	fprintf(f,"cp model%d.h scan_%s/model.h\n",ModelNumber,pname);
	fprintf(f,"cp mdl_ini%d.F scan_%s/mdl_ini.F\n\n",ModelNumber,pname);
	*/
        
	if(FAver==4)
		fprintf(f,"cp main.F scan_%s/\n\n",pname);
	
	if(thcut!=0.0)
		{
		fprintf(f,"echo \"#define THETACUT (%f*degree)\" > scan_%s/run.F\n",
					thcut,pname);
		fprintf(f,"grep -v THETACUT drivers/run.F >> scan_%s/run.F\n",pname);
		} 
	
	fprintf(f,"cd scan_%s\n",pname);
	
	fprintf(f,"sz0=`du -sm .`\n");
	
	fprintf(f,"if test ! -f run ;\n");
	fprintf(f,"then ./configure ;\n");
	fprintf(f,"fi\n\n");
	fprintf(f,"rm run ru*.01000*/*\n");
	fprintf(f,"gmake\n");
	fprintf(f,"if test ! -f run  ;\n");
	fprintf(f,"then echo Run file is not created | tee -a ../scan.log && exit;\n");
	fprintf(f,"fi\n");	
	
	fprintf(f,"num2=$((`date +%%s`-num0))\nnum0=`date +%%s`\n\n");
	fprintf(f,"sz1=`du -sm .`\n");

	fprintf(f,"./run uuuu 1000,1000\n");
	if(FAver>4)
		fprintf(f,"../exval6 ru*.01000*/* >> ../scan.log\n\n\n");
	fprintf(f,"cd ..\n");
//	fprintf(f,"grep \"|    1000.000\" scan_%s/ru*.01000*/* >> scan.log\n\n\n",
//				pname);

    if(FAver==4)
		fprintf(f,"./exval scan_%s/ru*.01000*/* >> scan.log\n\n\n",pname);
	
	fprintf(f,"num3=$((`date +%%s`-num0))\n\n");
	fprintf(f,"echo  $num1 + $num2 + $num3 = $(((num1+num2+num3)/60))");
	fprintf(f," min \\\n $sz0/$sz1 MB >> scan.log\n");
	fprintf(f,"rm -rf scan_%s\n\n",pname);
	fclose(f);
	return 0;
	
	}
Beispiel #30
0
Term ExpandTerm(Term t)
	{
	List il=0;
	Term res;
	/*puts("");
	WriteTerm(t);
	puts("\n");*/
	if(is_compound(t) && (CompoundName(t)==OPR_USCORE || CompoundName(t)==OPR_CARET))
		{
		t=SplitIndices(t,&il);
		if(t==0)
			longjmp(alg1_jmp_buf,1);
		}
	if(is_function(t,NULL))
		return ExpandTerm(CallFunction(t,il));
	if(is_float(t))
		{
		ErrorInfo(303);
		printf(" illegal use of floating point number %f.\n",FloatValue(t));
		FreeAtomic(t);
		longjmp(alg1_jmp_buf,1);
		}
	if(is_integer(t))
		{
		if(IntegerValue(t)==0)
			return 0;
		
		if(il)
			{
			ErrorInfo(304);
			puts("Integer can't have indices.\n");
			longjmp(alg1_jmp_buf,1);
			}
			
		res=MakeCompound(A_MTERM,4);
		SetCompoundArg(res,1,t);
		SetCompoundArg(res,2,NewInteger(1));
		return AppendFirst(0,res);
		}
		
	if(t==A_I)
		{
		res=MakeCompound(A_MTERM,4);
		SetCompoundArg(res,1,NewInteger(1));
		SetCompoundArg(res,2,NewInteger(-1));
		return AppendFirst(0,res);
		}
		
	if(is_atom(t) || (is_compound(t) && CompoundName(t)==A_FBRACET) ||
		(is_compound(t) && CompoundName(t)==A_ALG1 && CompoundArity(t)==2) ||
		(is_compound(t) && (CompoundName(t)==A_SIN || CompoundName(t)==A_COS)
		 	&& CompoundArity(t)<3 && is_integer(CompoundArg1(t))))
		 return AtomicTo1(t,il);
	
	if(!is_empty_list(il))
		{
		ErrorInfo(307);
		printf(" bad indices ");
		WriteTerm(il);
		printf(" in expression.\n");
		longjmp(alg1_jmp_buf,1);
		}


	if(opSetGpm && is_compound(t) && CompoundArity(t)==2 && CompoundArg1(t)==NewInteger(1)
			&& is_atom(CompoundArg2(t))
			&& (CompoundArg2(t)==A_GAMMA5 || GetAtomProperty(CompoundArg2(t),A_GAMMA5))
			&& (CompoundName(t)==OPR_PLUS || CompoundName(t)==OPR_MINUS))
	{
		Term ret,sp;
		ret=MakeCompound(A_MTERM,4);
		SetCompoundArg(ret,1,NewInteger(2));
		SetCompoundArg(ret,2,NewInteger(1));
		sp=MakeCompound(OPR_SPECIAL,2);
		if(CompoundName(t)==OPR_PLUS)
			SetCompoundArg(sp,2,A_GAMMAP);
		else
			SetCompoundArg(sp,2,A_GAMMAM);
		SetCompoundArg(sp,1,CopyTerm(GetAtomProperty(A_GAMMA5,PROP_INDEX)));
		SetCompoundArg(ret,3,AppendLast(NewList(),sp));
		return AppendLast(NewList(),ret);
	}
		

	
	
	if(is_compound(t) && CompoundName(t)==OPR_PLUS && CompoundArity(t)==2)
		{
		Term t1,t2;
		t1=ConsumeCompoundArg(t,1);
		t2=ConsumeCompoundArg(t,2);
		FreeAtomic(t);
		t1=ExpandTerm(t1);
		t2=ExpandTerm(t2);
		return ConcatList(t1,t2);
		}
		
	if(is_compound(t) && CompoundName(t)==OPR_MINUS && CompoundArity(t)==2)
		{
		Term t1,t2;
		t1=ConsumeCompoundArg(t,1);
		t2=ConsumeCompoundArg(t,2);
		FreeAtomic(t);
		t1=ExpandTerm(t1);
		t2=ExpandTerm(t2);
		mult_no(t2,-1);
		return ConcatList(t1,t2);
		}
		
	if(is_compound(t) && CompoundName(t)==OPR_MINUS && CompoundArity(t)==1)
		{
		Term t1;
		t1=ConsumeCompoundArg(t,1);
		FreeAtomic(t);
		t1=ExpandTerm(t1);
		mult_no(t1,-1);
		return t1;
		}
	
	if(is_compound(t) && CompoundName(t)==OPR_MLT && CompoundArity(t)==2)
		{
		Term t1,t2;
		t1=ConsumeCompoundArg(t,1);
		t2=ConsumeCompoundArg(t,2);
		FreeAtomic(t);
		t1=ExpandTerm(t1);
		t2=ExpandTerm(t2);
		return multiply_l(t1,t2);
		}
		
	if(is_compound(t) && CompoundName(t)==OPR_DIV && CompoundArity(t)==2)
		{
		Term t1,t2,t2s;
		t1=ConsumeCompoundArg(t,1);
		t2=ConsumeCompoundArg(t,2);
		FreeAtomic(t);
		t1=ExpandTerm(t1);
		t2s=CopyTerm(t2);
		t2=ExpandTerm(t2);
		if(ListLength(t2)!=1)
			{
			ErrorInfo(306);
			printf(" cannot divide by \'");
			WriteTerm(t2s); printf("\'.\n");
			FreeAtomic(t1); FreeAtomic(t2); FreeAtomic(t2s);
			longjmp(alg1_jmp_buf,1);
			}
		FreeAtomic(t2s);
		invert_term(ListFirst(t2));
		return multiply_l(t1,t2);
		}
		
	if(is_compound(t) && CompoundName(t)==OPR_POW && CompoundArity(t)==2)
		{
		Term t1,t2,ret;
		int i,pp;
		t1=ConsumeCompoundArg(t,1);
		t2=ConsumeCompoundArg(t,2);
		FreeAtomic(t);
		if(!is_integer(t2) || IntegerValue(t2)<1)
			{
			ErrorInfo(307);
			printf(" illegal power \'");
			WriteTerm(t2); printf("\'.\n");
			FreeAtomic(t1); FreeAtomic(t2);
			longjmp(alg1_jmp_buf,1);
			}
		pp=IntegerValue(t2);
		t1=ExpandTerm(t1);
		ret=CopyTerm(t1);
		for(i=2;i<=pp;i++)
			{
			Term tmp;
			tmp=CopyTerm(t1);
			ret=multiply_l(ret,tmp);
			}
		FreeAtomic(t1);
		return ret;
		}
	
	ErrorInfo(309);
	printf("bad expression ");
	WriteTerm(t);
	puts("");
	longjmp(alg1_jmp_buf,1);	
	
	}