---
title: "Discriminant"
language: "en"
type: "Symbol"
summary: "Discriminant[poly, var] computes the discriminant of the polynomial poly with respect to the variable var. Discriminant[poly, var, Modulus -> p] computes the discriminant modulo p."
keywords: 
- discriminant
- multiple roots
- resultant
- Sylvester matrix
- Bezout matrix
- subresultants
- modular
canonical_url: "https://reference.wolfram.com/language/ref/Discriminant.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Polynomial Systems"
    link: "https://reference.wolfram.com/language/guide/PolynomialSystems.en.md"
  - 
    title: "Polynomial Algebra"
    link: "https://reference.wolfram.com/language/guide/PolynomialAlgebra.en.md"
  - 
    title: "Finite Fields"
    link: "https://reference.wolfram.com/language/guide/FiniteFields.en.md"
related_functions: 
  - 
    title: "Resultant"
    link: "https://reference.wolfram.com/language/ref/Resultant.en.md"
  - 
    title: "Det"
    link: "https://reference.wolfram.com/language/ref/Det.en.md"
  - 
    title: "Tr"
    link: "https://reference.wolfram.com/language/ref/Tr.en.md"
  - 
    title: "SquareFreeQ"
    link: "https://reference.wolfram.com/language/ref/SquareFreeQ.en.md"
---
# Discriminant

Discriminant[poly, var] computes the discriminant of the polynomial poly with respect to the variable var.

Discriminant[poly, var, Modulus -> p] computes the discriminant modulo $p$.

## Details and Options

* The discriminant of a polynomial with leading coefficient one is the product over all pairs of roots $x_i$, $x_j$ of $\left(x_i-x_j\right){}^2$.

* ``Discriminant`` takes the following options:

|          |           |                                |
| -------- | --------- | ------------------------------ |
| Method   | Automatic | method to use                  |
| Modulus  | 0         | modulus to assume for integers |

* Typical possible values for ``Method`` are ``Automatic``, ``"SylvesterMatrix"``, ``"BezoutMatrix"``, ``"Subresultants"`` and ``"Modular"``.

---

## Examples (18)

### Basic Examples (1)

Discriminant of a quadratic:

```wl
In[1]:= Discriminant[a x ^ 2 + b x + c, x]

Out[1]= b^2 - 4 a c
```

### Scope (7)

Discriminant of a polynomial with numeric coefficients:

```wl
In[1]:= Discriminant[x ^ 10 - 5x ^ 7 - 3 x + 9, x]

Out[1]= 177945374758153510836
```

---

Discriminant of a general cubic:

```wl
In[1]:= Discriminant[a x ^ 3 + b x ^ 2 + c x  + d, x]

Out[1]= b^2 c^2 - 4 a c^3 - 4 b^3 d + 18 a b c d - 27 a^2 d^2
```

---

Discriminant of a general quintic:

```wl
In[1]:= Discriminant[Sum[Subscript[a, i]x ^ i, {i, 0, 5}], x]

Out[1]= Subsuperscript[a, 1, 2] Subsuperscript[a, 2, 2] Subsuperscript[a, 3, 2] Subsuperscript[a, 4, 2] - 4 Subscript[a, 0] Subsuperscript[a, 2, 3] Subsuperscript[a, 3, 2] Subsuperscript[a, 4, 2] - 4 Subsuperscript[a, 1, 3] Subsuperscript[a, 3, 3] Subsuper ... perscript[a, 5, 3] - 3750 Subsuperscript[a, 0, 3] Subscript[a, 2] Subscript[a, 3] Subsuperscript[a, 5, 3] - 2500 Subsuperscript[a, 0, 3] Subscript[a, 1] Subscript[a, 4] Subsuperscript[a, 5, 3] + 3125 Subsuperscript[a, 0, 4] Subsuperscript[a, 5, 4]
```

---

Discriminants are squares of differences of roots:

```wl
In[1]:= Discriminant[(x - a)(x - b)(x - c)(x - d), x]

Out[1]= (a - b)^2 (a - c)^2 (b - c)^2 (a - d)^2 (b - d)^2 (c - d)^2
```

---

Discriminant over integers modulo 3:

```wl
In[1]:= Discriminant[x ^ 5 - x y + y ^ 2 - 1, x, Modulus -> 3]

Out[1]= 2 + y^2 + 2 y^5 + y^6 + 2 y^8
```

---

Discriminant over a finite field:

```wl
In[1]:= ℱ = FiniteField[17, 3];

In[2]:= Discriminant[ℱ[1]x ^ 5 + ℱ[123]x y + ℱ[456], x]

Out[2]= [image]
```

---

Compute the discriminant of a polynomial of degree $1000$ :

```wl
In[1]:=
rpoly[n_] := RandomInteger[{-2 ^ 10, 2 ^ 10}, {n + 1}].x ^ Range[0, n]
SeedRandom[1234];
p = rpoly[1000];

In[2]:= Discriminant[p, x]//Short//AbsoluteTiming

Out[2]= {2.20456, -77921107669926779964331155238639496107952«10256»692072454910452578130689479008673384862896}
```

### Options (4)

#### Method (1)

This compares timings of the available methods of discriminant computation:

```wl
In[1]:= Timing[Discriminant[x ^ 100 - 2x ^ 77 + 3x + 4, x, Method -> #]//Short]& /@ {Automatic, "Modular", "Subresultants", "BezoutMatrix", "SylvesterMatrix"}//Column

Out[1]=
{0., Short[5422842500716221487403423841599456404323863786540139830758371140058200324016563085794136\
240107568219605209944485701994483331550866696814350096111028127494170413103491054045854055376241847\
3541578004948144001895888514590528479011563551 ... 40342384159945640432386378654013983075837114005820032401656308\
579413624010756821960520994448570199448333155086669681435009611102812749417041310349105404585405537\
62418473541578004948144001895888514590528479011563551931558053046829820246441557]}

In[2]:= Timing[Discriminant[a x ^ 10 + b x ^ 5 + (a + b)x + a b c, x, Method -> #]//Short]& /@ {Automatic, "Modular", "Subresultants", "BezoutMatrix", "SylvesterMatrix"}//Column

Out[2]=
{0.0156001, Short[387420489*a^18 + (3874204890*a^17)*b + (17433922005*a^16)*b^2 + 
    (46490458680*a^15)*b^3 + (81358302690*a^14)*b^4 + (97629963228*a^13)*b^5 + 
    (81358302690*a^12)*b^6 + (46490458680*a^11)*b^7 + (17433922005*a^10)*b^8 + 
    ( ... 00*a^13)*b^9)*c^4 + 
    ((5904900000*a^12)*b^10)*c^4 + ((9765625*a^8)*b^14)*c^4 - ((195312500*a^10)*b^13)*c^5 + 
    ((1562500000*a^12)*b^12)*c^6 - ((6250000000*a^14)*b^11)*c^7 + ((12500000000*a^16)*b^10)*c^8 - 
    ((10000000000*a^18)*b^9)*c^9]}
```

#### Modulus (3)

By default the discriminant is computed over the rational numbers:

```wl
In[1]:= Discriminant[a x ^ 3 + b x ^ 2 + c x + d, x]

Out[1]= b^2 c^2 - 4 a c^3 - 4 b^3 d + 18 a b c d - 27 a^2 d^2
```

---

Compute the discriminant of the same polynomial over the integers modulo 2:

```wl
In[1]:= Discriminant[a x ^ 3 + b x ^ 2 + c x + d, x, Modulus -> 2]

Out[1]= b^2 c^2 + a^2 d^2
```

---

Compute the discriminant of the same polynomial over the integers modulo 3:

```wl
In[1]:= Discriminant[a x ^ 3 + b x ^ 2 + c x + d, x, Modulus -> 3]

Out[1]= b^2 c^2 + 2 a c^3 + 2 b^3 d
```

### Applications (2)

Decide whether a polynomial has multiple roots:

```wl
In[1]:= Discriminant[x ^ 11 - 2x ^ 10 + x ^ 9 - 2x ^ 3 + 11x ^ 2 - 16x + 7, x]

Out[1]= 0

In[2]:= FactorSquareFree[x ^ 11 - 2x ^ 10 + x ^ 9 - 2x ^ 3 + 11x ^ 2 - 16x + 7]

Out[2]= (-1 + x)^2 (7 - 2 x + x^9)

In[3]:= Discriminant[x ^ 11 - 2x ^ 10 + x ^ 9 - 2x ^ 3 + 11x ^ 2 - 16x - 7, x]

Out[3]= 813583724618463631662004

In[4]:= FactorSquareFree[x ^ 11 - 2x ^ 10 + x ^ 9 - 2x ^ 3 + 11x ^ 2 - 16x - 7]

Out[4]= -7 - 16 x + 11 x^2 - 2 x^3 + x^9 - 2 x^10 + x^11
```

---

Find the condition for a cubic to have multiple roots:

```wl
In[1]:= Solve[Discriminant[x ^ 3 + x + c , x] == 0, c]

Out[1]= {{c -> -(2 I/3 Sqrt[3])}, {c -> (2 I/3 Sqrt[3])}}

In[2]:= FactorSquareFree[x ^ 3 + x + c /. %, Extension -> Automatic]

Out[2]= {-(1/27) I (2 Sqrt[3] - 3 I x) (Sqrt[3] + 3 I x)^2, (1/27) I (Sqrt[3] - 3 I x)^2 (2 Sqrt[3] + 3 I x)}
```

### Properties & Relations (3)

The discriminant is zero if and only if the polynomial has multiple roots:

```wl
In[1]:= Discriminant[(x - 1)(x - 2)(x - 3), x]

Out[1]= 4

In[2]:= Discriminant[(x - 1)(x - 2)(x - 1), x]

Out[2]= 0
```

---

The discriminant can be represented in terms of roots as $D(f)\text{==}a_n{}^{2n-2}\prod _{1\leq i<j\leq n} \left(r_i-r_j\right){}^2$ :

```wl
In[1]:= x /. Solve[a x ^ 2 + b x + c == 0, x]

Out[1]= {(-b - Sqrt[b^2 - 4 a c]/2 a), (-b + Sqrt[b^2 - 4 a c]/2 a)}

In[2]:= Expand[a ^ (2 2 - 2)(%[[1]] - %[[2]]) ^ 2]

Out[2]= b^2 - 4 a c

In[3]:= Discriminant[a x ^ 2 + b x + c, x]

Out[3]= b^2 - 4 a c
```

---

Equation $(-1)^{n(n-1)/2}a_nD(f)\text{==}R(f,f')$ relates ``Discriminant`` and ``Resultant`` :

```wl
In[1]:= f = 3x ^ 7 - 5x + 4;

In[2]:= Resultant[f, D[f, x], x]

Out[2]= 4720053663936

In[3]:= (-1) ^ (7 6 / 2)Coefficient[f, x, 7]Discriminant[f, x]

Out[3]= 4720053663936
```

### Possible Issues (1)

Using exact coefficients, this indicates no common root:

```wl
In[1]:= Discriminant[(x - 1 + 10 ^ (-17))(x - 1), x]

Out[1]= (1/10000000000000000000000000000000000)
```

With approximate coefficients, this does indicate a common root:

```wl
In[2]:= Discriminant[(x - 1. + 10 ^ (-17))(x - 1), x]

Out[2]= 0
```

in this case, using higher precision resolves the problem:

```wl
In[3]:= Discriminant[(x - 1`20 + 10 ^ (-17))(x - 1), x]

Out[3]= 1.`2.3979400086720384*^-34
```

## See Also

* [`Resultant`](https://reference.wolfram.com/language/ref/Resultant.en.md)
* [`Det`](https://reference.wolfram.com/language/ref/Det.en.md)
* [`Tr`](https://reference.wolfram.com/language/ref/Tr.en.md)
* [`SquareFreeQ`](https://reference.wolfram.com/language/ref/SquareFreeQ.en.md)

## Related Guides

* [Polynomial Systems](https://reference.wolfram.com/language/guide/PolynomialSystems.en.md)
* [Polynomial Algebra](https://reference.wolfram.com/language/guide/PolynomialAlgebra.en.md)
* [Finite Fields](https://reference.wolfram.com/language/guide/FiniteFields.en.md)

## History

* [Introduced in 2007 (6.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn60.en.md) \| [Updated in 2022 (13.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn132.en.md) ▪ [2023 (13.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn133.en.md)