{
  "id": "composite-function",
  "version": "51a8f3525727",
  "status": "published",
  "name": "Composite Function Calculator",
  "question": "What is the composite function?",
  "summary": "Finds the composite functions (f ∘ g)(x) = f(g(x)) and (g ∘ f)(x) = g(f(x)), simplified, and their values at x = a.",
  "category": "math",
  "subcategory": "algebra",
  "url": "https://www.acalculator.org/math/composite-function-calculator",
  "markdown": "https://www.acalculator.org/math/composite-function-calculator.md",
  "kind": "function",
  "method": "f(g(x)) is f with every x replaced by g(x); the result is expanded or simplified only when the shorter form is the same function on the same domain.",
  "assumptions": [
    "The variable is x; angles in radians.",
    "The domain of f(g(x)) is the x where g(x) is in the domain of f."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "f": {
        "title": "f(x)",
        "description": "The function f, in x.",
        "type": "string",
        "maxLength": 150
      },
      "g": {
        "title": "g(x)",
        "description": "The function g, in x.",
        "type": "string",
        "maxLength": 150
      },
      "a": {
        "title": "At x = a (optional)",
        "description": "A number at which to evaluate both composites.",
        "type": "string",
        "maxLength": 40
      }
    }
  },
  "outputs": {
    "fg": {
      "label": "f(g(x)) =",
      "description": "f with g(x) in place of x.",
      "format": "math"
    },
    "gf": {
      "label": "g(f(x)) =",
      "description": "g with f(x) in place of x.",
      "format": "math"
    },
    "fga": {
      "label": "f(g(a))",
      "description": "The value of f(g(x)) at x = a.",
      "format": "number"
    },
    "gfa": {
      "label": "g(f(a))",
      "description": "The value of g(f(x)) at x = a.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "2x + 1",
      "g": "3 - x"
    },
    "outputs": {
      "fg": "-2x + 7",
      "gf": "-2x + 2"
    },
    "text": "For f(x) = 2x + 1 and g(x) = 3 - x, f(g(x)) = -2x + 7."
  },
  "examples": [
    {
      "given": {
        "f": "2x + 1",
        "g": "3 - x"
      },
      "expect": {
        "fg": "-2x + 7",
        "gf": "-2x + 2"
      },
      "source": "OpenStax, College Algebra 2e, section 3.4 Composition of Functions (https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions), Example 2: f(g(x)) = 7 − 2x and g(f(x)) = −2x + 2"
    },
    {
      "given": {
        "f": "x^2 - x",
        "g": "3x + 2",
        "a": "1"
      },
      "expect": {
        "fga": 20,
        "fg": "9x^2 + 9x + 2"
      },
      "source": "OpenStax, College Algebra 2e, section 3.4 Composition of Functions (https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions), Example 7: f(h(1)) = 20; f(h(x)) = (3x + 2)² − (3x + 2) = 9x² + 9x + 2 by hand in content.mdx"
    },
    {
      "given": {
        "f": "sqrt(x)",
        "g": "5 - x^2"
      },
      "expect": {
        "fg": "sqrt(5 - x^2)"
      },
      "source": "OpenStax, College Algebra 2e, section 3.4 Composition of Functions (https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions), Example 10: g(h(x)) = √(5 − x²)"
    }
  ],
  "sources": [
    "OpenStax, College Algebra 2e, section 3.4 Composition of Functions (retrieved 2026-10-03): https://openstax.org/books/college-algebra-2e/pages/3-4-composition-of-functions"
  ],
  "related": [
    "inverse-function",
    "function-table",
    "simplify",
    "algebra"
  ],
  "changelog": []
}
