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

package lt.monarch.function.node;

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

// Referenced classes of package lt.monarch.function.node:
//            TimesNode, TermNode, OperatorNode, ConstantNode, 
//            SumNode, PowerNode, MinusNode, MulNode

public class DivNode extends TimesNode
    implements TermNode
{

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

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

    public String toString()
    {
        return ((super.l instanceof SumNode) ? "(" + super.l + ")" : super.l.toString()) + "/" + ((super.r instanceof SumNode) ? "(" + super.r + ")" : super.r.toString());
    }

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

    public double multiplier()
    {
        if (super.r instanceof ConstantNode)
            return super.r.evaluate();
        else
            return (double)1;
    }

    public Node termNode()
    {
        if (super.r instanceof ConstantNode)
            return super.l;
        else
            return (Node)this;
    }

    protected void enumerateOperands(Vector vector)
    {
        if (!(super.l instanceof TimesNode))
            super.l = super.l.simplify();
        if (!(super.r instanceof TimesNode))
            super.r = super.r.simplify();
        if (super.l instanceof TimesNode)
            ((TimesNode)super.l).enumerateOperands(vector);
        else
            vector.addElement(super.l);
        if (super.r instanceof TimesNode)
        {
            ((TimesNode)super.r).enumerateOperands(vector);
        } else
        {
            Node node = (new PowerNode(super.r, new ConstantNode(-1D))).simplifyOperation();
            vector.addElement(node);
        }
    }

    public Node derivative(Variable variable)
    {
        return (Node)new DivNode(new MinusNode(new MulNode(super.l.derivative(variable), super.r), new MulNode(super.l, super.r.derivative(variable))), new PowerNode(super.r, new ConstantNode(2D)));
    }

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

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