# Finding critical points of a function

Let's say we'd like to find the critical points of the function $f(x)=\sqrt{x-x^2}$. Finding out where the derivative is 0 is straightforward with Reduce:

f[x_] := Sqrt[x - x^2]
f'[x] == 0
Reduce[%]


which yields:

(1 - 2 x)/(2 Sqrt[x - x^2]) == 0

x == 1/2


To find out where the real values of the derivative do not exist, I look for values of $x$ that make the denominator 0:

Reduce[2 Sqrt[x - x^2] == 0]


which yields:

x == 0 || x == 1


To do this, I manually extracted the denominator expression from the derivative and ran it through Reduce.

My question is, is there a better way to ask Mathematica for values of $x$ where an expression doesn't have a real value? E.g. in this case, I'd like to pass in the expression for the derivative $\frac{1-2x}{2\sqrt{x-x^2}}$, and have it report that at 0 and 1, the real value doesn't exist.

• For even more fun, try it with $x^3\exp(-1/x^2)$ or $x^3\exp(1/x^2)$ :-). Mar 2, 2012 at 17:31

Slightly more generally than the solution by @Sjoerd, you may look for roots of the reciprocal function - if you are interested in pole-like or root-like singularities:

f[x_] := (1 - 2 x)/(2 Sqrt[x - x^2])

Reduce[1/f[x] == 0, x]

(*
==> x == 0 || x == 1
*)


A simple method is to test for reality directly, as follows

Reduce[f'[x] ∈ Reals, x, Reals]

0 < x < 1


which does not give you the points where $f^\prime(x) \notin \mathbb{R}$. Alternatively, you can test the denominator directly for reality, as follows

Reduce[Denominator[f'[x]] ∈ Reals, x, Reals]

0 <= x <= 1


which taken with the previous result clearly shows that at $x = 0,1$, $f^\prime(x) \notin \mathbb{R}$. Explicitly searching for those points by combining the two equations, though, gives an odd result

Reduce[! (f'[x] ∈ Reals)
&& (Denominator[f'[x]] ∈ Reals), x]

Im[x] != 0 && Re[x] == 1/2


despite the results being compatible when the search is expanded to include $x \in \mathbb{C}$

Reduce[f'[x] ∈ Reals, x]
Reduce[Denominator[f'[x]] ∈ Reals, x] // LogicalExpand // Simplify
Reduce[!%% && %, x, Reals]

0 < Re[x] < 1 && Im[x] == 0
(Im[x] == 0 && 0 <= Re[x] <= 1) || 2 Re[x] == 1
x == 0 || x == 1


Edit: in case anyone was wondering, looking for the region where $f^\prime(x) \notin \mathbb{R}$ directly

Reduce[! (f'[x] ∈ Reals), x]


Im[(1 - 2 x)/Sqrt[x - x^2]] != 0


However, this does better

!Reduce[(f'[x] ∈ Reals), x] // LogicalExpand // Simplify

Re[x] <= 0 || Re[x] >= 1 || Im[x] != 0


Here's one approach, though it possibly answers a slightly different question:

Reduce[-Infinity < f'[x] < Infinity, x]

0 < Re[x] < 1 && Im[x] == 0


or

Reduce[-Infinity < f'[x] < Infinity, x, Reals]

0 < x < 1


For expressions involving ratios you could try Denominator

Reduce[Denominator[(1 - 2 x)/(2 Sqrt[x - x^2])] == 0, x]

(*
==> x == 0 || x == 1
*)


I don't know a method that will find all non real valued points/areas in a general case.

• To answer your last question, just ask mma to do it for you. Mar 2, 2012 at 4:32
• @rcollyer Indeed, I forgot that Reduce allows domain specifications as expressions. Mar 2, 2012 at 6:52

You can use FunctionDomain to find out where the derivative does have a real value:

FunctionDomain[D[(1-2x)/(2 Sqrt[x-x^2]),x],x]


0 < x < 1

If you must have the region where the derivative does not have a real value, one method is:

Reduce[Not[0<x<1]]


x <= 0 || x >= 1