{
  "id": "integral",
  "version": "d2d21c76dece",
  "status": "published",
  "name": "Integral Calculator",
  "question": "What is the integral of a function?",
  "summary": "Finds the antiderivative of a function of x, and the definite integral between two limits, each checked numerically.",
  "category": "math",
  "subcategory": "calculus",
  "url": "https://www.acalculator.org/math/integral-calculator",
  "markdown": "https://www.acalculator.org/math/integral-calculator.md",
  "kind": "function",
  "method": "Symbolic integration by a computer algebra system (nerdamer); the answer shows only when F′(x) equals f(x) at 20 points, and a definite integral F(b) − F(a) also matches numeric integration.",
  "assumptions": [
    "The variable is x; log and ln are the natural logarithm; angles are in radians.",
    "The constant of integration C is any real number; ln|u| is shown where the algebra gives ln(u), when both check.",
    "A definite integral may have f infinite at an end (the limit of F there is used, or the page says it diverges) and removable gaps inside; a pole inside gives no value.",
    "An answer that fails its numeric check is never shown (\"No verified answer\")."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "f": {
        "title": "Function f(x)",
        "description": "The function of x to integrate, typed like x^2 sin(x), e^(-x) or sqrt(1 - x^2).",
        "type": "string",
        "maxLength": 200
      },
      "type": {
        "title": "Integral",
        "description": "Indefinite gives the antiderivative; definite also gives the area between two limits.",
        "type": "string",
        "enum": [
          "indefinite",
          "definite"
        ]
      },
      "a": {
        "title": "Lower limit a",
        "description": "Where the definite integral starts: a number or a constant such as pi/2.",
        "type": "string",
        "maxLength": 40
      },
      "b": {
        "title": "Upper limit b",
        "description": "Where the definite integral ends: a number or a constant such as pi.",
        "type": "string",
        "maxLength": 40
      }
    }
  },
  "outputs": {
    "value": {
      "label": "Definite integral",
      "description": "The integral of f from a to b: the signed area between the curve and the x axis.",
      "format": "number"
    },
    "antiderivative": {
      "label": "Antiderivative",
      "description": "A function F(x) + C whose derivative is f(x), with C any constant.",
      "format": "math"
    },
    "exact": {
      "label": "Exact value",
      "description": "The definite integral as an exact expression, F(b) − F(a).",
      "format": "math"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "x^2 sin(x)",
      "type": "indefinite",
      "a": "0",
      "b": "pi"
    },
    "outputs": {
      "antiderivative": "2 cos(x) - x^2 cos(x) + 2x sin(x) + C"
    },
    "text": "An antiderivative of x^2 sin(x) is 2 cos(x) - x^2 cos(x) + 2x sin(x) + C."
  },
  "examples": [
    {
      "given": {
        "f": "x^2 sin(x)",
        "type": "indefinite"
      },
      "expect": {
        "antiderivative": "2 cos(x) - x^2 cos(x) + 2x sin(x) + C"
      },
      "source": "hand calculation in content.mdx: integration by parts twice; mpmath check in docs/progress/WP-90.md"
    },
    {
      "given": {
        "f": "x^2 sin(x)",
        "type": "definite",
        "a": "0",
        "b": "pi"
      },
      "expect": {
        "value": 5.869604401089358,
        "exact": "π^2 - 4"
      },
      "source": "hand calculation in content.mdx: F(π) − F(0) = (π² − 2) − 2 = π² − 4; mpmath quad in docs/progress/WP-90.md"
    },
    {
      "given": {
        "f": "1/x",
        "type": "indefinite"
      },
      "expect": {
        "antiderivative": "ln|x| + C"
      },
      "source": "standard table of integrals (the derivative of ln|x| is 1/x for x ≠ 0), content.mdx"
    },
    {
      "given": {
        "f": "e^(-x^2)",
        "type": "definite",
        "a": "0",
        "b": "1"
      },
      "expect": {
        "value": 0.746824132812427
      },
      "source": "(√π/2) erf(1) = 0.7468241328124270, Abramowitz and Stegun 7.1 (erf(1) = 0.8427007929497149); mpmath in docs/progress/WP-90.md",
      "tolerance": 1e-12
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 1, section 5.3 The Fundamental Theorem of Calculus: https://openstax.org/books/calculus-volume-1/pages/5-3-the-fundamental-theorem-of-calculus",
    "OpenStax, Calculus Volume 2, section 3.1 Integration by Parts: https://openstax.org/books/calculus-volume-2/pages/3-1-integration-by-parts",
    "NIST Digital Library of Mathematical Functions, section 7.2 Error functions (erf and the integral of e^(−t²)): https://dlmf.nist.gov/7.2"
  ],
  "related": [
    "slope",
    "area",
    "quadratic-formula"
  ],
  "changelog": []
}
