// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   MinusNode.java

package lt.monarch.function.node;

import java.util.Vector;
import lt.monarch.function.*;

// Referenced classes of package lt.monarch.function.node:
//			SumNode, OperatorNode, ConstantNode, NegativeNode

public class MinusNode extends SumNode
{

	public Node cloneNode()
	{
		return (Node)new MinusNode(super.l.cloneNode(), super.r.cloneNode());
	}

	public String toString()
	{
		return super.l + "-" + super.r;
	}

	public double evaluate()
	{
		return super.l.evaluate() - super.r.evaluate();
	}

	public Node simplifyOperation()
	{
		if((super.r instanceof ConstantNode) && super.r.evaluate() == 0.0D)
			return super.l;
		if((super.l instanceof ConstantNode) && super.l.evaluate() == 0.0D)
			return (Node)new NegativeNode(super.r);
		else
			return super.simplifyOperation();
	}

	protected void enumerateOperands(Vector vector)
	{
		Vector vector1 = new Vector();
		if(!(super.l instanceof SumNode))
			super.l = super.l.simplify();
		if(!(super.r instanceof SumNode))
			super.r = super.r.simplify();
		if(super.l instanceof SumNode)
			((SumNode)super.l).enumerateOperands(vector);
		else
			vector.addElement(super.l);
		if(super.r instanceof SumNode)
			((SumNode)super.r).enumerateOperands(vector1);
		else
			vector1.addElement(super.r);
		for(int i = 0; i < vector1.size(); i++)
		{
			Node node = (Node)vector1.elementAt(i);
			vector.addElement((new NegativeNode(node)).simplifyOperation());
		}

	}

	public Node derivative(Variable variable)
	{
		return (Node)new MinusNode(super.l.derivative(variable), super.r.derivative(variable));
	}

	public void compile(NodeCompiler nodecompiler)
	{
		super.l.compile(nodecompiler);
		super.r.compile(nodecompiler);
		nodecompiler.append(103);
		nodecompiler.freeStack(2);
	}

	public MinusNode(Node node, Node node1)
	{
		super(node, node1);
	}
}
