### 5.46.2 Local extrema: extrema

Local extrema of a univariate or multivariate differentiable function under equality constraints can be obtained by using function extrema which takes four arguments :

- expr : differentiable expression
- constr (optional) : list of equality constraints
- vars : list of variables
- order_size=<positive integer> (optional) : upper bound for the order of derivatives examined in the process (defaults to 5)

Function returns sequence of two lists of points: local minima and maxima, respectively. Saddle and unclassified points are reported in the message area. Also, information about possible (non)strict extrema is printed out.

A single constraint/variable can be specified without list delimiters. A constraint may be specified as an equality or expression which is assumed to be equal to zero.

Number of constraints must be strictly less than number of variables. Additionally, denoting k -th constraint by gk(x1,x2,…,xn)=0 for k=1,2,…,m and letting g=(g1,g2,…,gm) , Jacobian matrix of g has to be full rank (i.e. equal to m ), since implicit differentiation is performed.

Variables may be specified with bounds, e.g. x=a..b, which is interpreted as x∈(a,b) . For semi-bounded variables one can use -infinity for a or +infinity for b . Also, parameter vars may be entered as e.g. [x1=a1,x2=a2,...,xn=an], in which case the critical point close to a=(a1,a2,…,an) is computed numerically, applying an iterative method with initial point a .

If order_size=<n> is specified as the fourth argument, derivatives up to order n are inspected to find critical points and classify them. For order_size=1 the function returns a single list containing all critical points found. The default is n=5 . If some critical points are left unclassified one might consider repeating the process with larger value of n , although the success is not guaranteed.

#### Examples

Input :

extrema(-2*cos(x)-cos(x)`^`2,x)

Output :

[0],[pi]

Input :

extrema(x/2-2*sin(x/2),x=-12..12)

Output :

[2*pi/3,-10*pi/3],[10*pi/3,-2*pi/3]

Input :

assume(a>=0);extrema(x`^`2+a*x,x)

Output :

[-a/2],[]

Input :

extrema(exp(x`^`2-2x)*ln(x)*ln(1-x),x=0.5)

Output :

[],[0.277769149124]

Input :

extrema(x`^`3-2x*y+3y`^`4,[x,y])

Output :

[[12`^`(1/5)/3,(12`^`(1/5))`^`2/6]],[]

Input :

assume(a>0);extrema(x/a`^`2+a*y`^`2,x+y=a,[x,y])

Output :

[[(2*a`^`4-1)/(2*a`^`3),1/(2*a`^`3)]],[]

Input :

extrema(x`^`2+y`^`2,x*y=1,[x=0..inf,y=0..inf])

Output :

[[1,1]],[]

Input :

extrema(x2`^`4-x1`^`4-x2`^`8+x1`^`10,[x1,x2])

Output :

[[6250`^`(1/6)/5,0],[-6250`^`(1/6)/5,0]],[]

Input :

extrema(x*y*z,x+y+z=1,[x,y,z],order_size=1)

Output :

[[1,0,0],[0,1,0],[0,0,1],[1/3,1/3,1/3]]