# Quadratic Formula Derivation — Step-by-Step CAS Verification

> Complete derivation of the quadratic formula with automated CAS verification. Learn how mode=solve verifies equation-solving steps and detects lost or extraneous solutions.

## Introduction

This tutorial demonstrates the `mode=solve` feature by deriving the quadratic formula with step-by-step CAS verification. You&apos;ll learn why `mode=solve` is essential for equation-solving derivations and how it detects lost or extraneous solutions.

> **Why mode=solve?:** The quadratic formula derivation involves operations that transform **solution sets** rather than just expressions. Dividing both sides by `a` is NOT an algebraic equivalence (the expressions differ by factor `a`), but the equations have the same solutions when `a ≠ 0`.

## Understanding the Difference

Let&apos;s understand why `mode=chain` fails for equation-solving derivations:

| Mode | What It Checks | Use For |
| --- | --- | --- |
| chain | Algebraic equivalence: `simplify(expr1 - expr2) == 0` | Factoring, expanding, simplifying |
| solve | Solution-set equivalence: `solveset(eq1) == solveset(eq2)` | Equation solving, isolating variables |

Consider the step &quot;divide both sides by a&quot;:

- `ax² + bx` and `x² + (b/a)x` are NOT algebraically equivalent
- But the equations `ax² + bx = -c` and `x² + (b/a)x = -c/a` have the SAME solution set

## The Derivation

### Step 1: Start with the General Quadratic Equation

We begin with the standard form of a quadratic equation where `a ≠ 0`:

```markdown

$$
ax^2 + bx + c = 0
$$

where $a \\neq 0$.

```

### Step 2: Subtract c from Both Sides

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ ax^2 + bx + c = 0 $$
$$ ax^2 + bx = -c $$
:::

```

**Expected Result:** ✅ EQUIV (same solution set)

### Step 3: Divide Both Sides by a

This is where `mode=solve` shines. This step would FAIL with `mode=chain` because the expressions are NOT algebraically equivalent.

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ ax^2 + bx = -c $$
$$ x^2 + \\frac{b}{a}x = -\\frac{c}{a} $$
:::

```

**Expected Result:** ✅ EQUIV (same solution set when a ≠ 0)

> **Why mode=chain Would Fail Here:** `mode=chain` checks if `ax² + bx` equals `x² + (b/a)x`. These are NOT equal (they differ by factor `a`). But `mode=solve` checks if the equations have the same solutions, which they do.

### Step 4: Complete the Square

Add `(b/2a)²` to both sides:

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ x^2 + \\frac{b}{a}x = -\\frac{c}{a} $$
$$ x^2 + \\frac{b}{a}x + \\frac{b^2}{4a^2} = \\frac{b^2}{4a^2} - \\frac{c}{a} $$
:::

```

**Expected Result:** ✅ EQUIV

### Step 5a: Simplify the Right Side

Combine the fractions on the right side:

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ x^2 + \\frac{b}{a}x + \\frac{b^2}{4a^2} = \\frac{b^2}{4a^2} - \\frac{c}{a} $$
$$ x^2 + \\frac{b}{a}x + \\frac{b^2}{4a^2} = \\frac{b^2 - 4ac}{4a^2} $$
:::

```

**Expected Result:** ✅ EQUIV

### Step 5b: Factor the Left Side as a Perfect Square

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ x^2 + \\frac{b}{a}x + \\frac{b^2}{4a^2} = \\frac{b^2 - 4ac}{4a^2} $$
$$ \\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2} $$
:::

```

**Expected Result:** ✅ EQUIV

### Step 6: Take the Square Root of Both Sides

This is a critical step. We must use ± to capture both solutions:

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ \\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2} $$
$$ x + \\frac{b}{2a} = \\pm \\frac{\\sqrt{b^2 - 4ac}}{2a} $$
:::

```

**Expected Result:** ✅ EQUIV (the ± captures both solutions)

> **What Happens Without ±:** If we wrote `x + b/(2a) = sqrt(b² - 4ac)/(2a)` (without ±), the CAS would return **NARROWS** because we&apos;d lose one solution.

### Step 7: Solve for x

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ x + \\frac{b}{2a} = \\pm \\frac{\\sqrt{b^2 - 4ac}}{2a} $$
$$ x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} $$
:::

```

**Expected Result:** ✅ EQUIV — We&apos;ve derived the quadratic formula!

## Full Derivation Chain

Here&apos;s the complete derivation verified in one block:

```markdown

:::cas mode=solve engine=sympy domain=R assumptions="a != 0" solve_var=x
$$ ax^2 + bx + c = 0 $$
$$ ax^2 + bx = -c $$
$$ x^2 + \\frac{b}{a}x = -\\frac{c}{a} $$
$$ x^2 + \\frac{b}{a}x + \\frac{b^2}{4a^2} = \\frac{b^2 - 4ac}{4a^2} $$
$$ \\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2} $$
$$ x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a} $$
:::

```

**Expected Result:** ✅ EQUIV for all steps

## Demonstrating NARROWS and WIDENS

The `mode=solve` feature can detect when derivation steps lose or introduce solutions.

### Example: NARROWS (Lost Solutions)

When we take a square root without ±, we lose solutions:

```markdown

:::cas mode=solve engine=sympy domain=R solve_var=x
$$ x^2 = 4 $$
$$ x = 2 $$
:::

```

**Expected Result:** ⚠️ NARROWS — The first equation has solutions {'{-2, 2}'}, but the second only has {'{2}'}. We lost the x = -2 solution.

### Example: WIDENS (Extraneous Solutions)

When we square both sides, we can introduce extraneous solutions:

```markdown

:::cas mode=solve engine=sympy domain=R solve_var=x
$$ x = 2 $$
$$ x^2 = 4 $$
:::

```

**Expected Result:** ⚠️ WIDENS — The first equation has solution {'{2}'}, but the second has {'{-2, 2}'}. We added the extraneous solution x = -2.

### Example: Correct Use of ±

Using ± preserves the solution set:

```markdown

:::cas mode=solve engine=sympy domain=R solve_var=x
$$ x^2 = 4 $$
$$ x = \\pm 2 $$
:::

```

**Expected Result:** ✅ EQUIV — Both equations have the same solution set {'{-2, 2}'}.

## Domain Options

The `domain` attribute specifies where to look for solutions:

| Domain | Description | Example |
| --- | --- | --- |
| R (default) | Real numbers | x² = 4 → {'{-2, 2}'} |
| C | Complex numbers | x² = -1 → {'{i, -i}'} |
| Z | Integers | 2x = 4 → {'{2}'} |
| N | Natural numbers | x = 2 → {'{2}'} |

### Example: Complex Domain

```markdown

:::cas mode=solve engine=sympy domain=C solve_var=x
$$ x^2 = -1 $$
$$ x^2 + 1 = 0 $$
:::

```

**Expected Result:** ✅ EQUIV — Both have solutions {'{i, -i}'} in the complex domain.

## When to Use Each Mode

| Scenario | Mode | Reason |
| --- | --- | --- |
| Verify identity: sin²(x) + cos²(x) = 1 | equivalence | Expression identity |
| Factor: x² - 1 = (x-1)(x+1) | chain | Expression rewrite |
| Simplify: (x²-1)/(x-1) = x+1 | chain | Algebraic simplification |
| Solve: ax² + bx + c = 0 → quadratic formula | solve | Equation derivation |
| Isolate variable: 2x + 3 = 7 → x = 2 | solve | Solution-set transformation |

## Status Indicators for mode=solve

| Status | Meaning | Example |
| --- | --- | --- |
| ✅ EQUIV | Same solution set (valid transformation) | 2x = 4 → x = 2 |
| ⚠️ NARROWS | Lost solutions (e.g., forgot ± when taking square root) | x² = 4 → x = 2 |
| ⚠️ WIDENS | Extraneous solutions (e.g., squared both sides) | x = 2 → x² = 4 |
| ❓ UNKNOWN | Cannot determine relationship | Complex expressions |
| ❌ ERROR | Parse or solve failed | Invalid LaTeX |

## Multiple Solutions Syntax

Use `\pm` or `\text{'{or}'}` to express multiple solutions:

```markdown

Using ±:
$$ x = \\pm 2 $$

Using "or":
$$ x = 2 \\,\\,\\text{or}\\,\\, x = -2 $$

```

Both are equivalent to the solution set {'{-2, 2}'}.

## Best Practices

> **Always Use mode=solve for Equation Derivations:** When your derivation involves dividing both sides, taking roots, or any operation that might change the solution set, use `mode=solve`.

> **Include the a ≠ 0 Assumption:** For the quadratic formula derivation, always include `assumptions=&quot;a != 0&quot;` since we divide by `a`.

> **Use ± When Taking Square Roots:** Always use `\pm` when taking square roots of both sides to preserve all solutions. The CAS will warn you with NARROWS if you forget.

> **Specify the Solve Variable:** Use `solve_var=x` to explicitly tell the CAS which variable you&apos;re solving for. This helps when you have multiple variables like `a`, `b`, `c`, and `x`.

## Next Steps

Now that you understand `mode=solve`, explore more CAS verification examples in the [CAS Verification Demo](/docs/math/verification/cas-demo) , which covers `mode=equivalence` and `mode=chain` for expression verification.
