package ec.gp.syntactic.simplification.numeric;

import ec.EvolutionState;
import ec.app.semanticGP.func.numeric.Exp;
import ec.app.semanticGP.func.numeric.Mul;
import ec.app.semanticGP.func.numeric.Sum;
import ec.gp.GPNode;
import ec.gp.syntactic.simplification.IRule;
import ec.util.Parameter;

class MulExpExpRule implements IRule {

	private EvolutionState state;

	@Override
	public void setup(EvolutionState state, Parameter base) {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean match(GPNode subtree) {
		if (!(subtree instanceof Mul))
			return false;

		Mul m = (Mul) subtree;
		return m.children[0] instanceof Exp && m.children[1] instanceof Exp;
	}

	@Override
	public GPNode replace(GPNode subtree) {
		assert match(subtree) : "Given tree does not represent Exp(p1) * Exp(p2).";

		Sum sum = new Sum();
		sum.children = new GPNode[] { subtree.children[0].children[0], subtree.children[1].children[0] };

		Exp exp = new Exp();
		exp.children = new GPNode[] { sum };

		return exp;
	}

}
