public Op(Node l, Node r, string op) { this.left = l; this.right = r; this.operat = op; }
public static Node Diff(Node n) { if (n is Variable) { return new Number(1); } if (n is Number) { return new Number(0); } if (n is Op) { Op expr = (Op) n; if (expr.operat == "Add") { return new Op(Diff(expr.left), Diff(expr.right),"Add"); } if (expr.operat == "Mult") { return new Op(new Op(expr.left, Diff(expr.right), "Mult"), new Op(Diff(expr.left), expr.right, "Mult"), "Add"); } else return null; } else return null; }