// 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:   MulNode.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, PlusNode

public class MulNode extends TimesNode
    implements TermNode
{

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

    public Node simplifyOperation()
    {
        if ((super.l instanceof ConstantNode) && super.l.evaluate() == 0.0D)
            return super.l;
        if ((super.r instanceof ConstantNode) && super.r.evaluate() == 0.0D)
            return super.r;
        if ((super.l instanceof ConstantNode) && super.l.evaluate() == 1.0D)
            return super.r;
        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();
        if (super.l instanceof ConstantNode)
            return super.l.evaluate();
        else
            return (double)1;
    }

    public Node termNode()
    {
        if (super.r instanceof ConstantNode)
            return super.l;
        if (super.l instanceof ConstantNode)
            return super.r;
        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
            vector.addElement(super.r);
    }

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

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

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