package ec.gp.syntactic.simplification.numeric;

import ec.EvolutionState;
import ec.app.semanticGP.func.numeric.Log;
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 SumLogLogRule implements IRule {

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

	}

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

		return subtree.children[0] instanceof Log && subtree.children[1] instanceof Log;
	}

	@Override
	public GPNode replace(GPNode subtree) {
		assert match(subtree) : "The give tree is not log(p1) + log(p2)";

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

		Log log = new Log();
		log.children = new GPNode[] { mul };

		return log;
	}
}
