public Equation(String expression) {
        this.expression = expression;

        try {
            //Conditional function
            CustomFunction conditionalFunction = new CustomFunction("if", 3) {
                public double applyFunction(double[] values) {
                    if (values[0] >= 0) {
                        return values[1];
                    }
                    else {
                        return values[2];
                    }
                }
            };
            //Boolean operator
            CustomOperator greaterThan = new CustomOperator(">", true, 10, 2) {
                @Override
                public double applyOperation(double[] values) {
                    if (values[0] > values[1]) {
                        return 1.0;
                    }
                    return 0.0;
                }
            };

            //Turn the infix expression into a postfix expression using the EXP4J library
            Calculable calc = new ExpressionBuilder(expression)
                    .withVariableNames("x", "y", "z", "r", "g", "b").withOperation(greaterThan).withCustomFunction
                            (conditionalFunction).build();
            String postfixExpression = calc.getExpression();

            //Get an array of the individual components of the postfix expression
            String arr[] = postfixExpression.split(" ");

            //The stack that will be used to build the expression tree
            Stack<Node> stack = new Stack<>();

            //Loop through each component of the postfix expression. A component can be either a number, variable,
            // or operator
            for (int i = 0; i < arr.length; i++) {
                /*
                EXP4J represents negatives using the apostrophe:
                "-5" becomes ["5", "'"]
                Therefore, if you reach an apostrophe, pop off the last component from the stack and negate it
                to create an expression tree with negatives and not apostrophes.
                 */
                if (arr[i].equals("'")) {
                    Node n = stack.pop();
                    n.setValue("-" + n.getValue());
                    stack.push(n);
                    continue;
                }

                //Create a Node representing the component currently being looked at
                Node n = new Node(arr[i]);

                //If the component is not an operator, we can just push it onto the stack
                if (!n.isOperator()) {
                    stack.push(n);
                }
                else if (n.isTernaryOperator()) {
                    //Ternary operators operators have left, middle, and right children.
                    Node right = stack.pop();
                    Node left = stack.pop();
                    Node middle = stack.pop();

                    n.setLeft(left);
                    n.setRight(right);
                    n.setMiddle(middle);
                    left.setParent(n);
                    right.setParent(n);
                    middle.setParent(n);

                    stack.push(n);
                }
                else if (n.isBinaryOperator()) {
                    //Binary operators (+-*/ ...) have left and right children.
                    Node right = stack.pop();
                    Node left = stack.pop();

                    n.setLeft(left);
                    n.setRight(right);
                    left.setParent(n);
                    right.setParent(n);

                    stack.push(n);
                }
                else {
                    //Unary operators (sin cos tan...) have only one child. We define single children to be the right
                    // child of a Node.
                    Node right = stack.pop();
                    n.setRight(right);
                    right.setParent(n);

                    stack.push(n);
                }
            }
            //The root of the expression tree is the last Node on the stack after all components have been examined
            root = stack.pop();

            //Create a list of all Nodes in the expression tree
            trace();
        } catch (UnparsableExpressionException | InvalidCustomFunctionException | UnknownFunctionException e) {
            e.printStackTrace();
        }
    }