Chalkboard - v3.0.1
    Preparing search index...

    Function parse

    • Parses, simplifies, and optionally evaluates a real number expression.

      Parameters

      • expr: string

        The real number expression to parse

      • config: {
            returnAST?: boolean;
            returnJSON?: boolean;
            returnLaTeX?: boolean;
            roundTo?: number;
            values?: Record<string, number>;
        } = ...
        • OptionalreturnAST?: boolean

          If true, returns an abstract syntax tree (AST) instead of a string

        • OptionalreturnJSON?: boolean

          If true, returns an AST in JSON instead of a string

        • OptionalreturnLaTeX?: boolean

          If true, returns LaTeX code instead of a string

        • OptionalroundTo?: number

          Optional number of decimal places to round the result to

        • Optionalvalues?: Record<string, number>

          Optional object mapping variable names to values

      Returns string | number | { type: string; [key: string]: any }

      // Returns 5
      const expr1 = Chalkboard.real.parse("x^2 + 1", { values: { x: 2 } });

      // Returns 16x^4 + 81y^4 + 96x^3y + 216x^2y^2 + 216y^3x
      const expr2 = Chalkboard.real.parse("(2x + 3y)^4");

      // Returns 25.1672 + 8.3891sin(4x)
      const expr3 = Chalkboard.real.parse("(1 + exp(2))(3 + sin(4x))");

      // Returns y^{2}\mathrm{tan}\left(x\right) + 2y \cdot \mathrm{tan}\left(x\right) + \mathrm{tan}\left(x\right)
      const expr4 = Chalkboard.real.parse("tan(x)(y + 1)^2", { returnLaTeX: true });

      // Returns {"type":"mul","left":{"type":"func","name":"tan","args":[{"type":"var","name":"x"}]},"right":{"type":"pow","base":{"type":"add","left":{"type":"var","name":"y"},"right":{"type":"num","value":1}},"exponent":{"type":"num","value":2}}}
      const expr5 = Chalkboard.real.parse("tan(x)(y + 1)^2", { returnJSON: true });