           expr.radicand()
         else false
 
-      invokeOrDefault: (@action)->
+      performOrDefault: (@action)->
         result = @findAndPerformAction(@expr)
         if @wasFound()
           result

    class_mixer(_FinalOpenSubExpressionApplication)


    class CloseSubExpression extends ExpressionManipulation
      invoke: (expression)->
        ret = _FinalOpenSubExpressionApplication.build(expr: expression, comps: @comps).
          invoke((expression)-> expression.close())
        ret
    class_mixer(CloseSubExpression)

    # TODO this needs to ahve final open sub expression application
    class AppendPi extends ExpressionManipulation
      invoke: (expression)->
        _ImplicitMultiplication.build(@comps).
          onNumeric(expression).
          append(@comps.build_pi())

    class_mixer(AppendPi)

    class AppendRoot extends ExpressionManipulation
      initialize: (opts={})->
        super
        @degree = opts.degree
      invoke: (expression)->
        degree = @comps.build_expression expression: [
            @comps.build_number(value: @degree)
          ]
        radicand = @comps.build_expression(expression: []).open()
        root = @comps.build_root(degree: degree, radicand: radicand)

        _ImplicitMultiplication.build(@comps).
          onNumeric(expression).
          append(root)
    class_mixer(AppendRoot)

    class AppendVariable extends ExpressionManipulation
      initialize: (opts={})->
        super
        @variable_name = opts.variable
      invoke: (expression)->
        variable = @comps.build_variable(name: @variable_name)
        _ImplicitMultiplication.build(@comps).
          onNumeric(expression).
          append(variable)


    class_mixer(AppendVariable)

    class SquareRoot extends ExpressionManipulation
      invoke: (expression)->
        value = @value(expression)
        root = Math.sqrt(parseFloat(value))
        unless isNaN(root)
          num = @comps.build_number value: "#{root}"
          @comps.classes.expression.buildWithContent [num]
        else
          @comps.classes.expression.buildError()
    class_mixer(SquareRoot)

    class _ImplicitMultiplication
      initialize: (@comps)->
      onNumeric: (expression)->
        last = expression.last()
        if last && (last.isNumber() || last instanceof @comps.classes.expression || last instanceof @comps.classes.pi)
          expression.append(@comps.build_multiplication())
        else
          expression


        if last instanceof @comps.classes.number
          new_last = last.clone()
          new_last = new_last.futureAsDecimal()
          new_exp = expression.replaceLast(new_last)
        else
          new_last = @comps.build_number(value: 0)
          new_last = new_last.futureAsDecimal()
          new_exp = expression.append(new_last)
        @pointer = @pos.build(new_exp.last().id())
        new_exp

      perform: (expression)->
        resulting_expression =
          _FinalOpenSubExpressionApplication.build(expr: expression, comps: @comps).
            performOrDefault((expr)=> @onFinalExpression(expr))

        expression: resulting_expression
        position: @pointer


    class_mixer(AppendDecimal)

