package org.matheclipse.core.reflection.system;

import org.matheclipse.core.eval.exception.Validate;
import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.generic.ExprComparator;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;

/**
 * Intersection of 2 sets
 * 
 * See: Intersection (set theory)
 */
public class Intersection extends AbstractFunctionEvaluator {

	public Intersection() {
	}

	@Override
	public IExpr evaluate(final IAST ast) {
		Validate.checkSize(ast, 3);
		
		if (!ast.arg1().isAtom() && !ast.get(2).isAtom()) {
			final IAST result = F.List();
			((IAST) ast.arg1()).args().intersection(result,
					((IAST) ast.get(2)).args());
			return result.args().sort(ExprComparator.CONS);
		}
		return null;
	}

}

 

Ads help maintain this website.