# CAS Verification Demo — Automated Math Checking

> Interactive examples demonstrating AutEng's Computer Algebra System (CAS) verification. See how mathematical expressions and derivations are automatically verified with SymPy.

## Introduction

AutEng&apos;s Computer Algebra System (CAS) automatically verifies mathematical expressions and derivations. Every math step is either **verified** (✅), **failed** (❌), or explicitly **unknown** (⚠️).

This eliminates &quot;math-looking slop&quot; and ensures your derivations are trustworthy. The CAS uses SymPy for symbolic computation, running in a secure sandbox environment.

> **How It Works:** Wrap your math in a `:::cas` block with the verification mode. The system will automatically check equivalence using symbolic computation and numeric testing.

## Quick Start Examples

### Example 1: Pythagorean Identity ✅

The fundamental trigonometric identity:

```markdown

:::cas mode=equivalence engine=sympy
$$ \\sin^2(x) + \\cos^2(x) = 1 $$
:::

```

**Expected Result:** ✅ PASS — This identity holds for all values of x.

### Example 2: Common Algebra Mistake ❌

A frequent error in algebra — the binomial expansion is wrong:

```markdown

:::cas mode=equivalence engine=sympy
$$ (a+b)^2 = a^2 + b^2 $$
:::

```

**Expected Result:** ❌ FAIL — Counterexample: a=1, b=1 gives 4 ≠ 2. The missing term is 2ab.

### Example 3: Double Angle Formula ✅

Verifying a trigonometric identity:

```markdown

:::cas mode=equivalence engine=sympy
$$ \\sin(2x) = 2\\sin(x)\\cos(x) $$
:::

```

**Expected Result:** ✅ PASS

## Chain Verification (Step-by-Step Derivations)

Use `mode=chain` to verify multi-step algebraic derivations. Each step is checked against the previous one.

### Example 4: Factoring with Assumptions

This derivation requires the assumption x ≠ 1 to allow cancellation:

```markdown

:::cas mode=chain engine=sympy assumptions="x != 1"
$$ \\frac{x^2 - 1}{x - 1} $$
$$ = \\frac{(x-1)(x+1)}{x-1} $$
$$ = x + 1 $$
:::

```

**Expected Result:** ✅ PASS — All steps verified with assumption x ≠ 1.

### Example 5: Difference of Squares

```markdown

:::cas mode=chain engine=sympy assumptions="a != b"
$$ \\frac{a^2 - b^2}{a - b} $$
$$ = \\frac{(a-b)(a+b)}{a-b} $$
$$ = a + b $$
:::

```

**Expected Result:** ✅ PASS

## The Power of Assumptions

Assumptions are critical for expressions involving square roots, logarithms, and division.

### Example 6: Square Root Identity

**Without assumptions** — finds a counterexample:

```markdown

:::cas mode=equivalence engine=sympy
$$ \\sqrt{x^2} = x $$
:::

```

**Expected Result:** ❌ FAIL — Counterexample: x = -2 gives √4 = 2 ≠ -2

**With the correct assumption:**

```markdown

:::cas mode=equivalence engine=sympy assumptions="x >= 0"
$$ \\sqrt{x^2} = x $$
:::

```

**Expected Result:** ✅ PASS — With x ≥ 0, the identity holds.

### Example 7: Logarithm Identities

**Product rule** (requires positive arguments):

```markdown

:::cas mode=equivalence engine=sympy assumptions="x > 0, y > 0"
$$ \\ln(xy) = \\ln(x) + \\ln(y) $$
:::

```

**Expected Result:** ✅ PASS

**Inverse relationship:**

```markdown

:::cas mode=equivalence engine=sympy assumptions="x is real"
$$ \\ln(e^x) = x $$
:::

```

**Expected Result:** ✅ PASS

### Example 8: Invalid Logarithm Property ❌

A common mistake — this is NOT how logarithms work:

```markdown

:::cas mode=equivalence engine=sympy
$$ \\ln(x + y) = \\ln(x) + \\ln(y) $$
:::

```

**Expected Result:** ❌ FAIL — Counterexample found. The product rule is ln(xy), not ln(x+y).

## Solution-Set Verification (mode=solve)

Use `mode=solve` for equation-solving derivations where steps transform solution sets rather than just expressions.

> **When to Use mode=solve:** Use `mode=solve` when your derivation involves operations like dividing both sides, taking square roots, or any step that might lose or introduce solutions.

### Example 9: Simple Equation Solving

```markdown

:::cas mode=solve engine=sympy domain=R solve_var=x
$$ 2x + 3 = 7 $$
$$ 2x = 4 $$
$$ x = 2 $$
:::

```

**Expected Result:** ✅ EQUIV — All steps preserve the solution set.

### Example 10: Detecting Lost Solutions (NARROWS)

When taking a square root without ±, solutions are lost:

```markdown

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

```

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

### Example 11: Correct Use of ±

Using ± preserves all solutions:

```markdown

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

```

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

### Example 12: Detecting Extraneous Solutions (WIDENS)

Squaring both sides can introduce extraneous solutions:

```markdown

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

```

**Expected Result:** ⚠️ WIDENS — Added extraneous solution x = -2.

## Handling Unsupported Constructs

Some mathematical constructs are not yet supported. The CAS will return UNKNOWN with helpful suggestions.

### Example 13: Integrals (Not Supported)

```markdown

:::cas mode=equivalence engine=sympy
$$ \\int x \\, dx = \\frac{x^2}{2} + C $$
:::

```

**Expected Result:** ⚠️ UNKNOWN — Reason: `parse_unsupported`. Suggestion: Integrals, sums, products, and limits are not yet supported.

## Reference

### Supported LaTeX Constructs

| Category | Constructs |
| --- | --- |
| Arithmetic | +, -, *, /, ^ |
| Fractions | `\frac{'{a}'}
                  {'{b}'}` |
| Powers | x^2, x^{'{n+1}'} |
| Trigonometric | `\sin, \cos, \tan, \cot, \sec, \csc` |
| Inverse Trig | `\arcsin, \arccos, \arctan` |
| Exponential/Log | `\exp, \ln, \log, e^x` |
| Square Root | `\sqrt{'{x}'}, \sqrt[n]{'{x}'}` |
| Greek Letters | `\alpha, \beta, \theta, etc.` |

### Not Supported (Returns UNKNOWN)

- Integrals: `\int`, `\iint`, `\oint`
- Sums/Products: `\sum`, `\prod`
- Limits: `\lim`
- Partial derivatives: `\partial`
- Matrices, vectors, tensors

### Assumption Syntax

| Format | Meaning |
| --- | --- |
| x &gt; 0 | x is positive |
| x &gt;= 0 | x is non-negative |
| x &lt; 0 | x is negative |
| x != 0 | x is non-zero |
| x is real | x is a real number |
| x is integer | x is an integer |

### Verification Modes

| Mode | Use Case |
| --- | --- |
| equivalence | Single identity verification |
| chain | Step-by-step expression rewrites |
| solve | Equation-solving derivations |

### Status Indicators

| Status | Meaning |
| --- | --- |
| ✅ PASS / EQUIV | Verified correct |
| ❌ FAIL | Proven incorrect |
| ⚠️ UNKNOWN | Cannot determine |
| ⚠️ NARROWS | Lost solutions |
| ⚠️ WIDENS | Extraneous solutions |

## Best Practices

> **Always Include Relevant Assumptions:** For expressions involving square roots (need non-negative), logarithms (need positive), or fractions (need non-zero denominators), always specify the appropriate assumptions.

> **Break Complex Derivations into Steps:** Smaller steps are easier to verify and debug. If a step fails, you can identify exactly where the error is.

> **Use mode=solve for Equation Solving:** When your derivation involves operations that transform solution sets (dividing, taking roots), use `mode=solve` instead of `mode=chain`.

> **Check UNKNOWN Suggestions:** When you get an UNKNOWN result, read the suggestions carefully. They often point to missing assumptions or unsupported constructs.

> **Verify Incrementally:** Verify each step as you write to catch errors early. Don&apos;t wait until the end of a long derivation.

## Next Steps

Ready to see a complete derivation with CAS verification? Check out the [Quadratic Formula Derivation](/docs/math/verification/quadratic-formula-derivation) tutorial, which demonstrates `mode=solve` for equation-solving steps.

For proofs requiring induction, case analysis, or complex reasoning, check out [Lean 4 Theorem Proving](/docs/math/verification/lean-theorem-proving) — machine-checked formal proofs with Mathlib.
