package org.matheclipse.core.generic;

import org.matheclipse.core.eval.EvalEngine;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.generic.interfaces.BiPredicate;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;

/**
 * Check if the evaluation of a binary AST object gives False
 * 
 */
public class IsBinaryFalse extends ExprComparator implements  BiPredicate  {
	protected final EvalEngine fEngine;

	protected final IAST fAST;

	/**
	 * Define a binary AST with the header head.
	 * 
	 * @param head
	 *          the AST's head expresion
	 */
	public IsBinaryFalse(final IExpr head) {
		fEngine = EvalEngine.get();
		fAST = F.ast(head, 1, false);
	}

	/**
	 * Check if the evaluation of a binary AST object gives False
	 * by settings it's first argument to firstArg and settings
	 * it's second argument to secondArg
	 * 
	 */
	public boolean apply(final IExpr firstArg, final IExpr secondArg) {
		final IAST ast = fAST.clone();
		ast.add(firstArg);
		ast.add(secondArg);
		if (fEngine.evaluate(ast).equals(F.False)) {
			return true;
		}
		return false;
	}

	public int compare(final IExpr firstArg, final IExpr secondArg) {
		final IAST ast = fAST.clone();
		ast.add(firstArg);
		ast.add(secondArg);
		IExpr temp = fEngine.evaluate(ast);
		if (temp.equals(F.False)) {
			return 1;
		}
		if (temp.equals(F.True)) {
			return -1;
		}
		return 0;
	}
}

 

Ads help maintain this website.