package ec.app.semanticGP.func.logic;

import library.semantics.BitSet;
import ec.gp.semantic.BooleanSemantics;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.BinaryNode;

public final class Nand extends BinaryNode<Boolean> {

	@Override
	public String toString() {
		return "nand";
	}
	
	@Override
	public boolean isSymmetric() {
		return true;
	}

	@Override
	protected ISemantics execute(ISemantics... arguments) {
		BitSet semantics = (BitSet)((BitSet)arguments[0].getValue()).clone();
		semantics.and((BitSet)arguments[1].getValue());
		semantics.flip(0, semantics.length()); // not

		return new BooleanSemantics(semantics);
	}

	@Override
	public Boolean[] invert(Boolean output, int missingArgIdx, Boolean... restOfArguments) {
		if (!restOfArguments[0]) {
			if (output)
				return Inversions.DONT_CARE;
			else
				return Inversions.INCONSISTENT;
		}

		assert restOfArguments[0];
		
		return output ? Inversions.FALSE : Inversions.TRUE;
		//return !output /* && restOfArguments[0] */ ? Inversions.TRUE : Inversions.FALSE;
		//return new Boolean[] { !output /* && restOfArguments[0] */};
	}
}
