Пример #1
0
Value* Pair(Value* h, Value* t, EnvironmentFrame* env, Allocator* a)
{
    gcguard<Value> head = Eval(h, env);
    gcguard<Value> tail = Eval(t, env);

    return a->allocate<ConsPair>(head.ptr(), tail.ptr());
}
Пример #2
0
int main(int argc, char *argv[]) {

    printf("\n");

    if (argc < 2) {
        printf("not enough arguments\n\n");
        return 1;
    }

    printf("STARTING MATLAB ENGINE\n\n");
    Engine *ep = engOpen("");
    if (ep == NULL) {
        printf("unable to start MATLAB engine\n\n");
        return 1;
    }
    engSetVisible(ep, false);
    char out[BUFSIZE];
    engOutputBuffer(ep, out, BUFSIZE);

    printf("SETTING PATH TO CNS\n\n");
    Eval(ep, out, "run(fullfile('%s', 'cns_path'));", argv[1]);

    bool ok = RunDemo(ep, out);

    printf("PRESS RETURN TO CONTINUE: ");
    fgets(out, BUFSIZE, stdin);
    printf("\n");

    printf("CLOSING MATLAB ENGINE\n\n");
    Eval(ep, out, "close all;");
    engClose(ep);

    return ok ? 0 : 1;

}
void CEvaluatingFunction::generatePoints(COUNTER FitCaseNum){

		F<double> IntervalSize = (RangeMax-RangeMin)/(double)FitCaseNum;
		destroyPoints();
		try{
			FunctionX1.push_back(RangeMin);
			FunctionY.push_back(Eval(RangeMin));
			for(COUNTER i=1; i<FitCaseNum-1; i++){
			
				F<double> x = RangeMin + ((F<double>)i*IntervalSize);	//Pick a point 
				int somewhere = rand()%100;		//in the interval,
				if (somewhere) x+= ((F<double>)1.0f/(F<double>)(somewhere))*IntervalSize;	//somewhere in the interval.
			
				FunctionX1.push_back(x);
				FunctionY.push_back(Eval(x));
			}
			FunctionX1.push_back(RangeMax);
			FunctionY.push_back(Eval(RangeMax));
		}
		catch(CString Exc){

			throw Exc;

		}
}
Пример #4
0
double ExplicitCurve2d :: NumericalProjectParam (const Point<2> & p, double lb, double ub) const
  {
  double t(-1);
  Vec<2> tan;
  Vec<2> curv;
  Point<2> cp;
  double f, fl, fu;
  int cnt;
  
  tan = EvalPrime (lb);
  cp = Eval (lb);
  fl = tan * (cp - p);
  if (fl > 0)			// changed by wmf, originally fl >= 0
    {
      //      cerr << "tan = " << tan << " cp - p = " << (cp - p) << endl;
      //      cerr << "ExplicitCurve2d::NumericalProject: lb wrong" << endl;
      return 0;
    }
  
  tan = EvalPrime (ub);
  cp = Eval (ub);
  fu = tan * (cp - p);
  if (fu < 0)			// changed by wmf, originally fu <= 0
    {
      //    cerr << "tan = " << tan << " cp - p = " << (cp - p) << endl;
      //    cerr << "ExplicitCurve2d::NumericalProject: ub wrong" << endl;
    return 0;
    }
    
  cnt = 0;
  while (ub - lb > 1e-12 && fu - fl > 1e-12)
    {
    cnt++;
    if (cnt > 50)
      {
      (*testout) << "Num Proj, cnt = " << cnt << endl;
      }
     
    t = (lb * fu - ub * fl) / (fu - fl);
    if (t > 0.9 * ub + 0.1 * lb) t = 0.9 * ub + 0.1 * lb;
    if (t < 0.1 * ub + 0.9 * lb) t = 0.1 * ub + 0.9 * lb;
    
    tan = EvalPrime (t);
    cp = Eval (t);
    f = tan * (cp - p);
    
    if (f >= 0)
      {
      ub = t;
      fu = f;
      }
    else
      {
      lb = t;
      fl = f;
      }
    }
    
  return t;
  }
Пример #5
0
static bool controlExpression(char relOp, expADT expL, expADT expR, environmentADT env){

	valueADT leftV, rightV;

	leftV = Eval(expL, env);
	rightV = Eval(expR, env);

	if(ValueType(leftV) == IntValue && ValueType(rightV) == IntValue ){

		switch(relOp){

		case '<':
		return (GetIntValue(leftV) < GetIntValue(rightV));

		case '>':
			return (GetIntValue(leftV) > GetIntValue(rightV));

		case '=':
			return (GetIntValue(leftV) == GetIntValue(rightV));

		default:
			Error("Reloperator %c is not valid.\n", relOp);
			break;
		}
	}
	else
		Error("\nCompared expressions is not Integers\n");

}
Пример #6
0
Файл: set.cpp Проект: hyln9/nV
void Unset(Var x)
{
	if(SymQ(x))
	{
		OwnValues.erase(x);
		return;
	}
	if(VecQ(x))
	{
		size_t n = Size(x);
		for(size_t i = 0; i < n; ++i)
			Unset(At(x,i));
		return;
	}
	if(ExQ(x))
	{
		var h = Eval(Head(x));
		if(SymQ(h))
		{
			var b = Body(x);
			if(h == TAG(Property))
			{
				if(SymQ(At(b,0)) && SymQ(At(b,1)))
				{
					std::map<Var,map_t>::iterator
						iter = Properties.find(At(b,0));
					if(iter != Properties.end())
						iter->second.erase(At(b,1));
				}
				return;
			}
			b = Eval(b);
			if(FixQ(b))
			{
				std::map<Var,dict_t>::iterator
					iter = FactValues.find(h);
				if(iter != FactValues.end())
					iter->second.erase(b);
			}
			else
			{
				std::map<Var,def_t>::iterator
					iter = DownValues.find(h);
				if(iter != DownValues.end())
					iter->second.erase(b);
			}
			return;
		}
		else if(ExQ(h) && SymQ(Head(h)))
		{
			var b = Eval(Body(x));
			var t = Vec(Body(h),b);
			std::map<Var,def_t>::iterator
				iter = SubValues.find(Head(h));
			if(iter != SubValues.end())
					iter->second.erase(t);
			return;
		}
	}
}
int Minimax::Quiescence(Board *board, GameInfo *gameInfo, int depth, int alpha, int beta) {
	// Evaluate the node in its current state. If it causes a beta-cutoff, assume that there will be no move further down the
	//game tree that will result in a better evaluation. Otherwise, set it as the lower bound, alpha.
	int nodeEvaluation = Eval(board, gameInfo);
	if (nodeEvaluation >= beta) return beta;
	if (nodeEvaluation > alpha) alpha = nodeEvaluation;
	MoveList moveList;
	// If the node is in check, consider every move. Otherwise, just consider captures/promotions.
	moveList.generate(gameInfo->turn, board, gameInfo, !MoveList::InCheck(gameInfo->turn, board));
	moveList.prune((Piece::Color)!gameInfo->turn, board);
	for (MoveList::iterator moveItr = moveList.begin(); moveItr != moveList.end(); moveItr++) {
		Move move = *moveItr;
		board->executeMove(move);
		// Save any irreversible game info before making a move.
		GameInfo::Irreversible irreversible(gameInfo);
		gameInfo->executeMove(move);
		int childEval = 0;
		// If we are at depth 0, just get the score of the board (The score is negated as it is measured relative to the opposite color).
		if (depth == 0) childEval = -Eval(board, gameInfo);
		else childEval = -Quiescence(board, gameInfo, depth - 1, -beta, -alpha);
		board->reverseMove(move);
		gameInfo->reverseMove(irreversible);
		if (childEval >= beta) return beta;
		if (childEval > alpha) alpha = childEval;
	}
	return alpha;
}
Пример #8
0
double MyParser::EvalRemoveSingularity(double *xvar)
{
	try {
		double result = Eval();
		if ( gsl_isinf(result) || gsl_isnan(result) )
			throw Singularity();
		return result;
	} catch (Singularity) {
		try {
			if (isinf(Eval()))
				throw Pole();

			int n;
			frexp (*xvar, &n);
			double xp = *xvar + ldexp(DBL_EPSILON,n);
			double xm = *xvar - ldexp(DBL_EPSILON,n);
			*xvar = xp;
			double yp = Eval();
			if (gsl_isinf(yp) || gsl_isnan(yp))
				throw Pole();
			*xvar = xm;
			double ym = Eval();
			if (gsl_isinf(ym) || gsl_isnan(ym))
				throw Pole();
			return (yp + ym)/2;
		} catch (Pole) {
			SingularityErrorMessage(*xvar);
			return GSL_ESING;
		}
	}
}
Пример #9
0
double TrPdf::Integral(double xlow, double xhig) {	
  if (xlow<GetX(0)) {
    if (VERBOSE) printf("TrPdf::Integral-V xlow out of bounds, using low edge.\n");
    xlow = GetX(0);
  }
  if (xhig>GetX(GetN()-1)) {
    if (VERBOSE) printf("TrPdf::Integral-V xhigh out of bounds, using upper edge.\n");
    xhig = GetX(GetN()-1);
  }
  if (xlow>=xhig) {
    if (VERBOSE) printf("TrPdf::Integral-V xlow greater-equal than xhig, returning 0.\n");
    return 0.;
  }
  double sum = 0.;
  double y1,y0,x1,x0;
  for (int i=0; i<GetN()-1; i++) {
    if      (xlow<=GetX(i))   { x0 = GetX(i);   y0 = GetY(i);    }
    else if (xlow>=GetX(i+1)) { x0 = GetX(i+1); y0 = GetY(i+1);  } 
    else                      { x0 = xlow;      y0 = Eval(xlow); }
    if      (xhig<=GetX(i))   { x1 = GetX(i);   y1 = GetY(i);    }
    else if (xhig>=GetX(i+1)) { x1 = GetX(i+1); y1 = GetY(i+1);  }
    else                      { x1 = xhig;      y1 = Eval(xhig); }
    sum  += (y1+y0)*(x1-x0)/2.;
  }
  return sum;
}
Пример #10
0
void CParametricSurface::Vertex(Vec2 domain)
{
    Vec3 p0, p1, p2, p3;
    Vec3 normal;
    float u = domain.x;
    float v = domain.y;
	
    Eval(domain, p0);
    Vec2 z1(u + du/2, v);
    Eval(z1, p1);
    Vec2 z2(u + du/2 + du, v);
    Eval(z2, p3);
	
    if (flipped) {
        Vec2 z3(u + du/2, v - dv);
        Eval(z3, p2);
    } else {
        Vec2 z4(u + du/2, v + dv);
        Eval(z4, p2);
    }
	
    const float epsilon = 0.00001f;
	
    Vec3 tangent = p3 - p1;
    Vec3 binormal = p2 - p1;
    MatrixVec3CrossProduct(normal, tangent, binormal);
    if (normal.length() < epsilon)
        normal = p0;
    normal.normalize();
	if (tangent.length() < epsilon)
		MatrixVec3CrossProduct(tangent, binormal, normal);
	tangent.normalize();
	binormal.normalize();
	binormal = binormal * -1.0f;
	 
	/*
    if (CustomAttributeLocation() != -1)
        glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain));
	 */
	
    //glNormal(normal);
    //glTexCoord(domain);
    //glVertex(p0);
	int vertexIndex = totalVertex * 14;
	vertexBuffer[vertexIndex++] = p0.x;
	vertexBuffer[vertexIndex++] = p0.y;
	vertexBuffer[vertexIndex++] = p0.z;
	vertexBuffer[vertexIndex++] = domain.x;
	vertexBuffer[vertexIndex++] = domain.y;
	vertexBuffer[vertexIndex++] = normal.x;
	vertexBuffer[vertexIndex++] = normal.y;
	vertexBuffer[vertexIndex++] = normal.z;
	vertexBuffer[vertexIndex++] = tangent.x;
	vertexBuffer[vertexIndex++] = tangent.y;
	vertexBuffer[vertexIndex++] = tangent.z;
	vertexBuffer[vertexIndex++] = binormal.x;
	vertexBuffer[vertexIndex++] = binormal.y;
	vertexBuffer[vertexIndex++] = binormal.z;
}
Пример #11
0
int scope_run(SuperScopePrivate *priv, ScopeRunnable runnable)
{

    RESULT result;

    SetVariableNumeric("n", priv->n);
    SetVariableNumeric("b", priv->b);
    SetVariableNumeric("x", priv->x);
    SetVariableNumeric("y", priv->y);
    SetVariableNumeric("i", priv->i);
    SetVariableNumeric("v", priv->v);
    SetVariableNumeric("w", priv->w);
    SetVariableNumeric("h", priv->h);
    SetVariableNumeric("red", priv->red);
    SetVariableNumeric("green", priv->green);
    SetVariableNumeric("blue", priv->blue);
    SetVariableNumeric("linesize", priv->linesize);
    SetVariableNumeric("skip", priv->skip);
    SetVariableNumeric("drawmode", priv->drawmode);
    SetVariableNumeric("t", priv->t);
    SetVariableNumeric("d", priv->d);

    switch(runnable) {
        case SCOPE_RUNNABLE_INIT:
		Eval(priv->init, &result);
	break;
	case SCOPE_RUNNABLE_BEAT:
		Eval(priv->beat, &result);
	break;
	case SCOPE_RUNNABLE_FRAME:
		Eval(priv->frame, &result);
	break;
	case SCOPE_RUNNABLE_POINT:
		Eval(priv->point, &result);
	break;
    }

    //(FindVariable("n"))->value = NULL;
    VARIABLE var;
    var.value = NULL;
    priv->n = R2N(FindVariable("n")->value);
    priv->b = R2N(FindVariable("b")->value);
    priv->x = R2N(FindVariable("x")->value);
    priv->y = R2N(FindVariable("y")->value);
    priv->i = R2N(FindVariable("i")->value);
    priv->v = R2N(FindVariable("v")->value);
    priv->w = R2N(FindVariable("w")->value);
    priv->h = R2N(FindVariable("h")->value);
    priv->red = R2N(FindVariable("red")->value);
    priv->green = R2N(FindVariable("green")->value);
    priv->blue = R2N(FindVariable("blue")->value);
    priv->linesize = R2N(FindVariable("linesize")->value);
    priv->skip = R2N(FindVariable("skip")->value);
    priv->drawmode = R2N(FindVariable("drawmode")->value);
    priv->t = R2N(FindVariable("t")->value);
    priv->d = R2N(FindVariable("d")->value);

    return 0;
}
Пример #12
0
sint32 SlicFrame::IsEqual(SS_TYPE type1, SlicStackValue value1,
						  SS_TYPE type2, SlicStackValue value2)
{
	SlicSymbolData *sym1, *sym2;
	if(type1 == SS_TYPE_INT || type2 == SS_TYPE_INT) {
		return Eval(type1, value1) == Eval(type2, value2);
	}

	switch(type1) {
		case SS_TYPE_SYM:
		case SS_TYPE_VAR:
		{
			if(type1 == SS_TYPE_SYM) {
				sym1 = value1.m_sym;
			} else {
				sym1 = g_slicEngine->GetSymbol(value1.m_int);
			}

			if(type2 == SS_TYPE_SYM) {
				sym2 = value2.m_sym;
			} else if(type2 == SS_TYPE_VAR) {
				sym2 = g_slicEngine->GetSymbol(value2.m_int);
			} else {
				Assert(FALSE);
				return 0;
			}

			MapPoint pos1, pos2;
			Unit u1, u2;
			if(sym1->GetPos(pos1)) {
				if(sym2->GetPos(pos2)) {
					return pos1 == pos2;
				}
			} 
			if(sym1->GetUnit(u1)) {
				if(sym2->GetUnit(u2)) {
					return u1 == u2;
				}
			} 
			if(sym1->GetCity(u1)) {
				if(sym2->GetCity(u2)) {
					return u1 == u2;
				}
			}
			
			if(sym1->GetType() != SLIC_SYM_IVAR)
				return 0;

			if(sym2->GetType() != SLIC_SYM_IVAR)
				return 0;

			return Eval(type1, value1) == Eval(type2, value2);
		}
		default:
			Assert(FALSE);
			return 0;
	}
}
Пример #13
0
Файл: eval.cpp Проект: hyln9/nV
var EvalEx(Var expression)
{
	var head = Eval(Head(expression));
	var body;
	var result;
	if(SymQ(head))
	{
		std::map<Var,attr_t>::const_iterator
			iter = Attributes.find(head);
		if(iter != Attributes.end())
		{
			if (HandleAttributes(result, expression, iter->second, head, body))
			{
				return result;
			}
		}
		else
		{
			body = Eval(Body(expression));
		}

		if (SearchFactValues(result, head, body))
		{
			return result;
		}

		if (SearchDownValues(result, head, body))
		{
			return result;
		}

		if (SearchCProcs(result, head, body))
		{
			return result;
		}
	}
	else
	{
		body = Eval(Body(expression));

		if(ExQ(head) && SymQ(Head(head)))
		{
			if (SearchSubValues(result, head, body))
			{
				return result;
			}

			if (SearchCOpers(result, head, body))
			{
				return result;
			}
		}
	}
	return Ex(head,body);
}
Пример #14
0
bool CAG_RegEx::CreateNFA(string strRegEx)
{
	// Parse regular expresion using similar 
	// method to evaluate arithmetic expressions
	// But first we will detect concatenation and
	// insert char(8) at the position where 
	// concatenation needs to occur
	strRegEx = ConcatExpand(strRegEx);
	cout<<strRegEx<<" : length "<<strRegEx.size()<<endl;

	for(int i=0; i<strRegEx.size(); ++i)
	{
		// get the charcter
		char c = strRegEx[i];
		
		if(IsInput(c))
			Push(c);
		else if(m_OperatorStack.empty())
			m_OperatorStack.push(c);
		else if(IsLeftParanthesis(c))
			m_OperatorStack.push(c);
		else if(IsRightParanthesis(c))
		{
			// Evaluate everyting in paranthesis
			while(!IsLeftParanthesis(m_OperatorStack.top()))
				if(!Eval())
					return false;
			// Remove left paranthesis after the evaluation
			m_OperatorStack.pop(); 
		}
		else
		{
			while(!m_OperatorStack.empty() && Presedence(c, m_OperatorStack.top()))
				if(!Eval())
					return false;
			m_OperatorStack.push(c);
		}
	}

	// Evaluate the rest of operators
	while(!m_OperatorStack.empty())
		if(!Eval())
			return false;

	// Pop the result from the stack
	if(!Pop(m_NFATable))
		return false;

	// Last NFA state is always accepting state
	m_NFATable[m_NFATable.size()-1]->m_bAcceptingState = true;

	return true;
}
Пример #15
0
double EvalProbL(int j,int x,int layers)  {
	int i=0;
	DModel *m= (DModel*)&(models[j]);
	double error=0;
	double y=0;
	int length=m->len;
	if  (m->len < x) {
//	elog(WARNING," Future %d %d",x,m->len);
}
//	double y= Eval(j,x,&error);// no need to compute the value
	//elog(WARNING, "Model error%f requested error %f",error,err);
	//btw, compute the next values and add them to the cache
	//	return y;

	if ((layers==0)||(m->nc <= 0)) {
		//elog(WARNING," matches the error %p",cache);
		if((cache != NULL) && (m_cache>0)) {
			//    elog(WARNING, "Filling from %d len: %d",x+1+i,m_cache);	
       			cache_start=x+1;
			for(i=0;i<m->len;i++) {
			   if(i>=m_cache)break;
			   cache[i]=Eval(j,x+1+i,&error);
			 }
			 for(i=x+m->len;i<m_cache;i++) {
			    cache[i]=-1;
			 }
		}	
	y= Eval(j,x,&error);	
//	elog(WARNING,"EvalProbL layers:%d val %lf",layers,y);
	return y; // found result within the error
	}
	//elog(WARNING,"here");
	DModel *mm;

	int l=0;
	l=m->children[0];
	mm= (DModel*)&(models[l]);
        int llen = mm->len;
        int li = x / llen;
	
        if (li >= m->nc) {
          li =m-> nc - 1;
	  l=m->children[li];
	  mm= (DModel*)&(models[l]);
          llen = mm->len;
            }
	l=m->children[li];
//	printf("l %d li %d\n",l,li);
        double yy= EvalProbL(l,x % llen, layers-1);
//	elog(WARNING, "Eval Prop L layers %d %lf",layers,yy);
	return yy;
}
Пример #16
0
Expr* EvalCons(Env* env, Expr* expr, Expr* cont){
  Expr* arg1_expr = expr->next;
  Expr* arg2_expr = expr->next->next;
  Expr* arg1 = Eval(env, arg1_expr, cont);
  Expr* arg2 = Eval(env, arg2_expr, cont);
  Expr* ret = malloc(sizeof(Expr));
  ret->type = Pair_Exp;
  ret->u.list = arg1;
  //  arg1->next = NullList();
  //  ar->next  = arg2;
  ret->next = arg2;
  return ret;
}
Пример #17
0
Expr* EvalMul(Env* env, Expr* expr, Expr* cont){
  int x ,y; 
  Expr *x_expr, *y_expr;
  x_expr = Eval(env, GetSecond(expr), cont);
  x = x_expr->u.int_value;
  y_expr = Eval(env, GetThird(expr), cont);
  y = y_expr->u.int_value;
  printf("%d\n", x * y);
  Expr *ret_val = malloc(sizeof(Expr));
  ret_val->type = Number_Exp;
  ret_val->u.int_value = x * y;
  return ret_val;
}
Пример #18
0
// Send out a normal, texture coordinate, vertex coordinate, and an optional custom attribute.
void TParametricSurface::Vertex(vec2 domain)
{
    vec3 p0, p1, p2, p3;
    vec3 normal;
    float u = domain.u;
    float v = domain.v;

    Eval(domain, p0);
    vec2 z1(u + du/2, v);
    Eval(z1, p1);
    vec2 z2(u + du/2 + du, v);
    Eval(z2, p3);

    if (flipped) {
        vec2 z3(u + du/2, v - dv);
        Eval(z3, p2);
    } else {
        vec2 z4(u + du/2, v + dv);
        Eval(z4, p2);
    }

    const float epsilon = 0.00001f;

    vec3 tangent = p3 - p1;
    vec3 binormal = p2 - p1;
    normal = cross(tangent, binormal);
    if (normal.magnitude() < epsilon)
        normal = p0;
    normal.unitize();

    if (tangentLoc != -1)
    {
        if (tangent.magnitude() < epsilon)
            tangent = cross(binormal, normal);
        tangent.unitize();
        glVertexAttrib(tangentLoc, tangent);
    }

    if (binormalLoc != -1)
    {
        binormal.unitize();
        glVertexAttrib(binormalLoc, -binormal);
    }

    if (CustomAttributeLocation() != -1)
        glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain));

    glNormal(normal);
    glTexCoord(domain);
    glVertex(p0);
}
Пример #19
0
// the quiescence search
int Quiece(board_t *brd, int alpha, int beta, searchinfo_t *sinfo)
{
	if(!(sinfo->nodes & 0xfff)) CheckUp(sinfo);

	sinfo->nodes++;

	ASSERT(CheckBrd(brd));

	//if((IsRep(brd) || brd->fifty >= 100) && brd->ply) return 0;
	if(brd->ply >= MAXDEPTH-1) return Eval(brd);

	int score = Eval(brd);

	// we are probably not going to make our position worse by moving so we can say:
	if(score >= beta){	// if we are doing already too good
		return beta;	// we have a beta cutoff and we return
	}
	if(score > alpha){	// if we are better than alpha
		alpha = score;	// then we can set our minimum alpha to the score
	}

	mlist_t list;
	int i;
	score = -INFINITE;

	GenCaps(brd, &list);	// Generate all capture moves

	for(i = 0; i < list.len; i++)	// Loop through the moves
	{
		if(sinfo->stop) return 0;

		SelectNextMove(&list, i);

		if(!MakeMove(brd, list.move[i].move)) continue;

		score = -Quiece(brd, -beta, -alpha, sinfo);

		TakeBack(brd);

		if(score > alpha){
			if(score >= beta){
				return beta;
			}
			alpha = score;
		}
	}

	return alpha;
}
Пример #20
0
Файл: eval.cpp Проект: hyln9/nV
bool HandleAttributes(var &result, Var expression, const attr_t &attributes,
						var head, var &body)
{
	if(attributes.count(SequenceHold))
	{
		body = Body(expression);
	}
	else
	{
		body = FlattenSequence(Body(expression), false);
	}
	size_t n = Size(body);
	// FIXME: in mathematica, OneIdentity means "x == f[x]" only for PATTERN MATCHING purposes
// 	if(n == 1 && attributes.count(OneIdentity))
// 	{
// 		result = Eval(At(body,0));
// 		return true;
// 	}
	if(!attributes.count(HoldAll))
	{
		if(n > 0 && !attributes.count(HoldFirst))
			At(body,0) = Eval(At(body,0));
		if(n > 1 && !attributes.count(HoldRest))
			for(size_t i = 1; i < n; ++i)
				At(body,i) = Eval(At(body,i));
	}
	if(attributes.count(Listable))
	{
		// TODO: handle the case where all list must be of same length, e.g. CoprimeQ
		var t = Thread(head,body);
		if(t)
		{
			result = Eval(t);
			return true;
		}
	}
	if(attributes.count(Flat))
	{
		var t = body;
		body = Vec();
		Reserve(body,n);
		Flatten(body,head,t);
	}
	if(attributes.count(Orderless))
		Sort(body);

	return false;
}
Пример #21
0
bool CRay::IntersectSphere( const TVec &roPos, float fRadius )
{
	const TVec oVecV( m_oPos - roPos );
	const float fVh2 = oVecV.Dot( oVecV );
	
	// Mitternacht.
	const float fA = m_oDir.Dot( m_oDir );
	const float fB = 2.0f * oVecV.Dot( m_oDir );
	const float fC = fVh2 - fRadius * fRadius;
	
	const float fDet = ( fB * fB ) - ( 4.0f * fA * fC );
	
	if( fDet >= 0.0f )
	{
		const float f1dA2 = 1.0f / ( 2.0f * fA );
		const float fDetTerm = (float)sqrt( (double)fDet );
		const float fT0 = ( -fB + fDetTerm ) * f1dA2;
		const float fT1 = ( -fB - fDetTerm ) * f1dA2;
		
		float fT = MAX( fT0, fT1 );
		if( fT < 0.0f ) // Der Strahl ist eine Halbgerade!
			return false;
		m_oHit = Eval( fT );
		TVec oNormal = ( m_oHit - m_oPos ).Normalized();
		// Nur wenn Strahl mit der nach aussen gerichteten 
		// Normalen max. einen Winkel von 90° bildet.
		if( oNormal.Dot( m_oDir ) >= 0.0f ) 
			return true;
	}
	return false;
}
Пример #22
0
void ExprCopy::visit(const ExprApply& e) {
	for (int i=0; i<e.nb_args; i++)
		visit(e.arg(i));

	if (fold) {
		int i=0;
		for (; i<e.nb_args; i++) {
			if (!dynamic_cast<const ExprConstant*>(&ARG(i))) break;
		}
		if (i==e.nb_args) {
			Array<const Domain> d(e.nb_args);
			for (i=0; i<e.nb_args; i++) {
				d.set_ref(i,((const ExprConstant&) ARG(i)).get());
			}
			clone.insert(e, &ExprConstant::new_(Eval().eval(e.func,d)));
			return;
		}
	}

	Array<const ExprNode> args2(e.nb_args);
	for (int i=0; i<e.nb_args; i++) {
		args2.set_ref(i,ARG(i));
		// don't remove this node even if it is a constant because
		// it is an argument of this function call.
		mark(e.arg(i));
	}

	clone.insert(e, &ExprApply::new_(e.func, args2));
}
Пример #23
0
int CSearch::Aspiration_Search(uint64_t P, uint64_t O, uint64_t& NodeCounter, int alpha, int beta, int score, int selectivity, int depth, int empties, CLine& PV_line)
{
	int width = (depth == empties ? 2 : 1);
	int down = width;
	int up = width;

	while (true)
	{
		int low = MAX(alpha, score - down);
		int high = MIN(beta, score + up);

		score = Eval(P, O, NodeCounter, low, high, selectivity, depth, empties, &PV_line);
		print_stats(depth, selectivity);

		if (score <= low && score > alpha && down > 0) // fail low
		{
			down *= 2;
			up = 0;
		}
		else if (score >= high && score < beta && up > 0) // fail high
		{
			down = 0;
			up *= 2;
		}
		else
			break;
	}
	return score;
}
Пример #24
0
DoSetWandState(SimView *view, short state)
{
  char buf[256];

  sprintf(buf, "UISetToolState %s %d", Tk_PathName(view->tkwin), state);
  Eval(buf);
}
/* Search game tree by alpha-beta algorith */
short AlphaBeta(short alpha, short beta, short depth)
{
    short i, value, best;

    if (!depth) return Eval();

    Gen();
    best = -INFINITY;

    for (i=gen_begin[ply]; i<gen_end[ply] && best<beta; i++)
    {
        if (best > alpha) alpha = best;

        if (MakeMove(gen_dat[i].m)) value = 1000-ply;
        else value = -AlphaBeta(-beta, -alpha, depth-1);
        UnMakeMove();

        if (value > best)
        {
            best = value; if (!ply) newmove = gen_dat[i].m;
        }
    }

    return best;
}
Пример #26
0
std::string StreamBuffString(Value* eos, EnvironmentFrame* env) {
    OStream*            os  = assert_type<OStream>(Eval(eos, env));
    std::ostringstream* oss = dynamic_cast<std::ostringstream*>(os->value());
    if (!oss) throw std::runtime_error("Expected a stream buffer to read.");

    return oss->str();
}
Пример #27
0
BOOL MorphObject::PolygonCount(TimeValue t, int& faceCount, int& vertCount)
   {
   ObjectState os = Eval(t);
   Object *obj = os.obj;
   if (!obj) return FALSE;
   return obj->PolygonCount(t, faceCount, vertCount);
   }
Пример #28
0
/// @memberof isnan/1
static Int
p_isinf( USES_REGS1 )
{                               /* X is Y        */
  Term out = 0L;

  while (!(out = Eval(Deref(ARG1) PASS_REGS))) {
    if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
      LOCAL_Error_TYPE = YAP_NO_ERROR;
      if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
        Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
        return FALSE;
      }
    } else {
      Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
      return FALSE;
    }
  }
  if (IsVarTerm(out)) {
    Yap_EvalError(INSTANTIATION_ERROR, out, "isinf/1");
    return FALSE;
  }
  if (!IsFloatTerm(out)) {
    Yap_EvalError(TYPE_ERROR_FLOAT, out, "isinf/1");
    return FALSE;
  }
  return isinf(FloatOfTerm(out));
}
Пример #29
0
/// @memberof between/3
static Int cont_between( USES_REGS1 )
{
  Term t1 = EXTRA_CBACK_ARG(3,1);
  Term t2 = EXTRA_CBACK_ARG(3,2);
  
  Yap_unify(ARG3, t1);
  if (IsIntegerTerm(t1)) {
    Int i1;
    Term tn;

    if (t1 == t2)
      cut_succeed();
    i1 = IntegerOfTerm(t1);
    tn = add_int(i1, 1 PASS_REGS);
    EXTRA_CBACK_ARG(3,1) = tn;
    HB = B->cp_h = HR;
    return TRUE;
  } else {
    Term t[2];
    Term tn;
    Int cmp;

    cmp = Yap_acmp(t1, t2 PASS_REGS);
    if (cmp == 0)
      cut_succeed();
    t[0] = t1;
    t[1] = MkIntTerm(1);
    tn = Eval(Yap_MkApplTerm(FunctorPlus, 2, t) PASS_REGS);
    EXTRA_CBACK_ARG(3,1) = tn;
    HB = B->cp_h = HR;
    return TRUE;
  }
}
Пример #30
0
Object* MorphObject::ConvertToType(TimeValue t, Class_ID obtype)
   {
   ObjectState os = Eval(t);
   Object *obj = os.obj->ConvertToType(t,obtype);
   if (!obj) return NULL;
   return (Object*)CloneRefHierarchy(obj);
   }