{
  "id": "order-of-operations",
  "version": "290410ffaa5d",
  "status": "published",
  "name": "PEMDAS Calculator",
  "question": "What is the answer with PEMDAS?",
  "summary": "Evaluates an arithmetic expression by the order of operations (PEMDAS): parentheses, exponents, multiplication and division, then addition and subtraction, one exact step at a time.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/order-of-operations-calculator",
  "markdown": "https://www.acalculator.org/math/order-of-operations-calculator.md",
  "kind": "function",
  "method": "Parentheses first (the deepest, then the leftmost), then exponents (from the right), then multiplication and division from left to right, then addition and subtraction from left to right; one operation per step, in exact fractions.",
  "assumptions": [
    "Numbers are read exactly as typed; the answer is exact (a whole number, a decimal that ends, or a fraction).",
    "−3^2 means −(3^2) = −9; write (−3)^2 for 9. 2^3^2 means 2^(3^2).",
    "A multiplication written without a sign, as in 2(3 + 1), is an ordinary × and is done left to right with ÷: 8 ÷ 2(2 + 2) = 16.",
    "Exponents must be whole numbers, so every answer is exact. 0^0 and division by 0 have no answer."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "e": {
        "title": "Expression",
        "description": "An arithmetic expression with numbers, + − × ÷ ^ and parentheses, such as 3 + 4 × (2 − 1)^2.",
        "type": "string",
        "maxLength": 200
      }
    }
  },
  "outputs": {
    "result": {
      "label": "Answer",
      "description": "The exact value: a whole number, a decimal that ends, or a fraction in lowest terms.",
      "format": "text"
    },
    "decimal": {
      "label": "As a decimal",
      "description": "The decimal value of an answer that is a fraction.",
      "format": "number"
    },
    "read": {
      "label": "Read as",
      "description": "The expression as the calculator reads it, with every multiplication sign written.",
      "format": "text"
    },
    "steps": {
      "label": "Steps",
      "description": "One operation per step, in PEMDAS order, with the expression after each step.",
      "format": "text"
    },
    "note": {
      "label": "Note",
      "description": "Shown when a multiplication without a sign follows a division, which people read in two ways.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "e": "3 + 6 × (5 + 4) ÷ 3 − 7"
    },
    "outputs": {
      "result": "14",
      "read": "3 + 6 × (5 + 4) ÷ 3 − 7",
      "steps": "Add inside the parentheses: 5 + 4 = 9, so 3 + 6 × 9 ÷ 3 − 7; Multiply: 6 × 9 = 54, so 3 + 54 ÷ 3 − 7; Divide: 54 ÷ 3 = 18, so 3 + 18 − 7; Add: 3 + 18 = 21, so 21 − 7; Subtract: 21 − 7 = 14"
    },
    "text": "3 + 6 × (5 + 4) ÷ 3 − 7 = 14."
  },
  "examples": [
    {
      "given": {
        "e": "3 + 6 × (5 + 4) ÷ 3 − 7"
      },
      "expect": {
        "result": "14",
        "steps": "Add inside the parentheses: 5 + 4 = 9, so 3 + 6 × 9 ÷ 3 − 7; Multiply: 6 × 9 = 54, so 3 + 54 ÷ 3 − 7; Divide: 54 ÷ 3 = 18, so 3 + 18 − 7; Add: 3 + 18 = 21, so 21 − 7; Subtract: 21 − 7 = 14"
      },
      "source": "hand calculation in content.mdx (PEMDAS); Python 3: 3 + 6 * (5 + 4) / 3 - 7 = 14.0; order of operations as in OpenStax Prealgebra 2e, section 2.1: https://openstax.org/books/prealgebra-2e/pages/2-1-use-the-language-of-algebra"
    },
    {
      "given": {
        "e": "3 + 4 × 2 − 6 ÷ 3"
      },
      "expect": {
        "result": "9"
      },
      "source": "hand calculation in content.mdx: 3 + 8 − 2 = 9"
    },
    {
      "given": {
        "e": "8 ÷ 2(2 + 2)"
      },
      "expect": {
        "result": "16",
        "read": "8 ÷ 2 × (2 + 2)",
        "note": "A multiplication written without a sign, as in 2(3 + 1), counts as an ordinary × here and is done left to right with ÷. To multiply first, put the product in parentheses."
      },
      "source": "hand calculation in content.mdx: × and ÷ left to right, 8 ÷ 2 × 4 = 4 × 4 = 16 (OpenStax Prealgebra 2e, 1.9 order of operations)"
    },
    {
      "given": {
        "e": "-3^2 + (1 - 4)^2"
      },
      "expect": {
        "result": "0",
        "steps": "Subtract inside the parentheses: 1 − 4 = -3, so -3^2 + (-3)^2; Exponent: 3^2 = 9, so -9 + (-3)^2; Exponent: (-3)^2 = 9, so -9 + 9; Add: -9 + 9 = 0"
      },
      "source": "hand calculation in content.mdx: −3² = −(3²) = −9 and (−3)² = 9"
    },
    {
      "given": {
        "e": "2^3^2"
      },
      "expect": {
        "result": "512"
      },
      "source": "hand calculation in content.mdx: exponents group from the right, 2^(3^2) = 2^9 = 512; Python 3: 2 ** 3 ** 2 = 512"
    },
    {
      "given": {
        "e": "1 ÷ 3 + 1 ÷ 4"
      },
      "expect": {
        "result": "7/12",
        "decimal": 0.5833333333333334,
        "steps": "Divide: 1 ÷ 3 = 1/3, so (1/3) + 1 ÷ 4; Divide: 1 ÷ 4 = 0.25, so (1/3) + 0.25; Add: (1/3) + 0.25 = 7/12"
      },
      "source": "hand calculation in content.mdx: 1/3 + 1/4 = 4/12 + 3/12 = 7/12; Python 3: Fraction(1, 3) + Fraction(1, 4) = 7/12, 7 / 12 = 0.5833333333333334"
    },
    {
      "given": {
        "e": "(2 + 1) ÷ 9"
      },
      "expect": {
        "result": "1/3",
        "decimal": 0.3333333333333333
      },
      "source": "hand calculation in content.mdx: 3 ÷ 9 = 1/3; Python 3: 3 / 9 = 0.3333333333333333"
    },
    {
      "given": {
        "e": "0.1 + 0.2 × 3"
      },
      "expect": {
        "result": "0.7"
      },
      "source": "hand calculation in content.mdx: 0.2 × 3 = 0.6, 0.1 + 0.6 = 0.7 (exact decimals)"
    }
  ],
  "sources": [
    "OpenStax, Prealgebra 2e, section 2.1 Use the Language of Algebra (order of operations): https://openstax.org/books/prealgebra-2e/pages/2-1-use-the-language-of-algebra",
    "Wikipedia, Order of operations (unary minus, stacked exponents, and mixed division and multiplication): https://en.wikipedia.org/wiki/Order_of_operations"
  ],
  "related": [
    "fraction",
    "decimal",
    "exponent",
    "multiplication"
  ],
  "changelog": []
}
