lib/integral.js
function(expr, context) {
      if(expr.type === "OperatorNode" && expr.op === '^' && expr.args[0].equals(context.variable) && context.isConstant(expr.args[1])) {
        // Simplify Exponent if constant
        var exponentValue = getNumericValue(expr.args[1]);
        if(exponentValue === -1) {
          return new FunctionNode('log', [
            new FunctionNode('abs', [
              context.variable.clone()
            ])
          ]);
        } else {
          return new OperatorNode('*', 'multiply', [
            new OperatorNode('/', 'divide', [
              new ConstantNode(1),
              new OperatorNode('+', 'add', [
                expr.args[1].clone(),
                new ConstantNode(1)
              ])
            ]),
            new OperatorNode('^', 'pow', [
              expr.args[0].clone(),
              new OperatorNode('+', 'add', [
                expr.args[1].clone(),
                new ConstantNode(1)
              ])
            ])
          ]);
        }
      }
    }
function(expr, context) {
      if(expr.type === "OperatorNode" && expr.op === '^' && expr.args[0].equals(context.variable) && context.isConstant(expr.args[1])) {
        // Simplify Exponent if constant
        var exponentValue = getNumericValue(expr.args[1]);
        if(exponentValue === -1) {
          return new FunctionNode('log', [
            new FunctionNode('abs', [
              context.variable.clone()
            ])
          ]);
        } else {
          return new OperatorNode('*', 'multiply', [
            new OperatorNode('/', 'divide', [
              new ConstantNode(1),
              new OperatorNode('+', 'add', [
                expr.args[1].clone(),
                new ConstantNode(1)
              ])
            ]),
            new OperatorNode('^', 'pow', [
              expr.args[0].clone(),
              new OperatorNode('+', 'add', [
                expr.args[1].clone(),
                new ConstantNode(1)
              ])
            ])
          ]);
        }
      }
    }
function ( expr , context ) { if ( expr . type === "OperatorNode" && expr . op === '^' && expr . args [ 0 ] . equals ( context . variable ) && context . isConstant ( expr . args [ 1 ] ) ) { // Simplify Exponent if constant var exponentValue = getNumericValue ( expr . args [ 1 ] ) ; if ( exponentValue === - 1 ) { return new FunctionNode ( 'log' , [ new FunctionNode ( 'abs' , [ context . variable . clone ( ) ] ) ] ) ; } else { return new OperatorNode ( '*' , 'multiply' , [ new OperatorNode ( '/' , 'divide' , [ new ConstantNode ( 1 ) , new OperatorNode ( '+' , 'add' , [ expr . args [ 1 ] . clone ( ) , new ConstantNode ( 1 ) ] ) ] ) , new OperatorNode ( '^' , 'pow' , [ expr . args [ 0 ] . clone ( ) , new OperatorNode ( '+' , 'add' , [ expr . args [ 1 ] . clone ( ) , new ConstantNode ( 1 ) ] ) ] ) ] ) ; } } }
integral(x^c, x) = 1/(c+1) * x^(c+1) and integral(x^(-1)) = log(x)
integral ( x^c x ) = 1 / ( c + 1 ) * x^ ( c + 1 ) and integral ( x^ ( - 1 )) = log ( x )