% !TeX program = lualatex
% =====================================================================
%  analysis.tex
%  Analysis in one chapter: big operators with an index (sum, product),
%  limits — both the lim(...) operator and the arrow form written under
%  a long arrow — trigonometry with upright function names, derivatives
%  up to a differential equation and the heat equation, the vector
%  operators (grad, div, curl, Laplacian, directional derivative), the
%  whole integral family (primitive, definite, multiple, contour,
%  principal value, average, surface, volume), the Landau notations and
%  the integral transforms.
% =====================================================================
\documentclass[
  margins=8,
  font=Latin Modern Roman,
  size=12,
  linespread=1.4,
  lang=en,
  precision=4
]{scholatex}
\begin{document}

let title = <Red b 18pt c>
let h1    = <Navy b section>
let topic = <Navy b section ROMAN>
let study = <Navy b section ROMAN>
let step  = <Navy b subsection roman >
let p     = <tab>

<title>scholatex — analysis

% =====================================================================
<h1>Operators with an index
% =====================================================================

A big operator carries its index in (...); its body follows freely
and is set in display style so fractions stay full size.

<box line:Indigo fill:Lavender radius:3 title:{Sum and product}>{
	$sum(i=1, n) i = n(n+1)/2$ <3tab> $prod(k=1, n) k$
}

% =====================================================================
<h1>Limits
% =====================================================================

A limit's (...) holds the approach, written with ->; the target
sits under the word, as it should:

<box line:Indigo fill:Lavender radius:3>{
	$lim(x->0) f(x)$ <3tab> $lim(x->+inf) 1/x$
}

For the running phrase "$u_n$ tends to $l$" set under a long arrow, use
arrow(...): the condition is written underneath, and to or ->
read the same inside it.

<box line:Indigo fill:Lavender radius:3 title:{A sequence converging}>{
	$u_n arrow(n to +inf) l$ <3tab> $1/n arrow(n to +inf) 0$
}

% =====================================================================
<h1>Trigonometry
% =====================================================================

Function names — sin, cos, tan, ln, exp and
the rest — are set upright automatically, and a name glued to (...)
takes its argument as one atom, so fractions behave.

<box line:Crimson fill:MistyRose radius:3 title:{The fundamental identity}>{
	$sin(x)^2 + cos(x)^2 = 1$
}

<box line:Crimson fill:MistyRose radius:3 title:{Addition formula}>{
	$cos(a+b) = cos(a)cos(b) - sin(a)sin(b)$
}

<box line:Crimson fill:MistyRose radius:3>{
	$tan(x) = sin(x)/cos(x)$ <3tab> $lim(x->0) sin(x)/x = 1$
}

% =====================================================================
<h1>Derivatives and differential equations
% =====================================================================

A derivative is written as the fraction it is. The differential d is
set upright (ISO 80000-2), matching the d of the integrals — but only
when both sides of the fraction carry it, so a variable named d is left
alone (d/2 stays a plain fraction).

<box line:DarkOrange fill:OldLace radius:3 title:{Leibniz notation}>{
	$dy/dx$ <3tab> $(d^2 y)/(dx^2)$ <3tab> $d/dx (x^2) = 2x$
}

A first-order differential equation reads in one line:

<box line:DarkOrange fill:OldLace radius:3>{
	$dy/dx + y = 0$
}

Partial derivatives use partial ($partial$); parenthesise each side so
the fraction groups correctly. The heat equation, for instance:

<box line:DarkOrange fill:OldLace radius:3 title:{The heat equation}>{
	$(partial u)/(partial t) = (partial^2 u)/(partial x^2)$
}

% =====================================================================
<h1>Differential operators
% =====================================================================

The first-order vector operators read as named operators: $grad(f)$ the
gradient, $div(F)$ the divergence, $curl(F)$ the curl. The Laplacian is
written $lap(f)$; it prefixes its operand without function parentheses, so
$lap(f)$ stays bare, while a compound operand keeps its grouping, as in
$lap(x^2 + y^2)$.

<box line:DarkOrange fill:OldLace radius:3 title:{The Laplacian as divergence of the gradient}>{
	$lap(f) = div(grad(f))$
}

The derivative of $f$ along a direction $u$ is $dirderiv(f, u)$, the gradient
indexed by the direction.

<box line:DarkOrange fill:OldLace radius:3 title:{Directional derivative}>{
	$dirderiv(f, u) = grad(f) cdot u$
}

% =====================================================================
<h1>Integrals: body and differential
% =====================================================================

An integral closes on a differential. Its head (...) names the
variable; everything up to the end of the formula is the integrand, and the
differential $dx$ is appended automatically.

<box line:DarkGreen fill:Honeydew radius:3 title:{Primitive and definite integral}>{
	$int(x) f(x)$ <3tab> $int(x=a, b) f(x)$
}

The head's variable is the differential, so a change of letter is just a
change in the head: $int(t=0, 1) t^2$. To keep a term outside the
integral, close the integrand in parentheses — these differ:

<box line:DarkGreen fill:Honeydew radius:3>{
	$(int(x=a, b) f(x)) + 1$ <3tab> $int(x=a, b) (f(x) + 1)$
}

% =====================================================================
<h1>Multiple integrals
% =====================================================================

Separate several domains with ; inside the head. The count of
domains chooses the single, double or triple integral sign; the
differentials come out in reverse order, the Fubini convention.

<box line:DarkGreen fill:Honeydew radius:3>{
	$int(x=a, b ; y=c, d) f(x,y)$

	$int(x=a, b ; y=c, d ; z=e, g) f(x,y,z)$
}

A single named domain is a region integral over that set, with the area
element giving the surface form: $int(D) f$.

% =====================================================================
<h1>Contour, principal value, average
% =====================================================================

Three named integral operators round out the family: a contour integral
$contourint(C) f(z)$, a Cauchy principal value $pvint(x=a, b) f(x)$, and
the average (normalised) integral $meanint(x=a, b) f(x)$.

<box line:DarkGreen fill:Honeydew radius:3 title:{The integral family}>{
	$contourint(C) f(z)$ <3tab> $pvint(x=a, b) f(x)$ <3tab> $meanint(x=a, b) f(x)$
}

% =====================================================================
<nextpage h1>Surface and volume integrals
% =====================================================================

The closed surface integral is $surfint(S)$ and the volume integral is
$volint(V)$, both built on the integral signs unicode-math provides
natively. A flux reads $flux(F, S)$.

<box line:DarkGreen fill:Honeydew radius:3 title:{The divergence theorem}>{
	$flux(F, S) = volint(V) div(F)$
}

% =====================================================================
<h1>Landau notation
% =====================================================================

The asymptotic comparisons are the explicit words $bigO(...)$ and
$litO(...)$, so the bare letters $o$ and $O$ stay free as variables.

<box line:Indigo fill:Lavender radius:3 title:{A first-order expansion}>{
	$exp(x) = 1 + x + litO(x)$ as $x to 0$

	$sum(k=1, n) k = n^2/2 + bigO(n)$
}

% =====================================================================
<h1>Integral transforms
% =====================================================================

The transforms name themselves: $laplace(f)$ and $fourier(f)$, with inverses
$ilaplace(f)$ and $ifourier(f)$.

<box line:Indigo fill:Lavender radius:3 title:{A transform pair}>{
	$laplace(f)$ on one side, $ilaplace(laplace(f)) = f$ on the other.
}

% ---------------------------------------------------------------------
<topic>Sign tables

<p>{ Computed from the function object: rows, zeros and signs are derived
from the factored expression, zeros exact. }

<fn f(x) = (x+2)(x-3)>
<signtab f>

<p>{ A quotient: the pole comes out as a forbidden value; an even
multiplicity is known not to change sign. Objects rebind sequentially ---
the f, g and h of later sections shadow these without touching them. }

<fn g(x) = (x+1)/(x-2)>
<signtab g>

<fn h(x) = -2(x+1)^2 (x - 1/2)>
<signtab h>

<p>{ The block form remains the general one, for rows the affine engine
cannot derive: }

<signtab x:{0 | pi/2 | pi}>{
	cos(x) : + | 0 | -
}

% ---------------------------------------------------------------------
<topic>The number line

<p>{ Solved: the block takes the inequality and computes the set, endpoints
exact, open or closed as the inequality is strict or not: }

<numberline x:{-5, 5}>{
	abs(x - 1/2) >= 5/2
}

<numberline x:{-5, 5}>{
	(x+1)/(x-3) >= 0
}

<p>{ Declared, when the set is given rather than solved: }

<numberline x:{-5, 5} set:{[-2, 3) union (4, inf)} points:{-4}>

% ---------------------------------------------------------------------
<topic>Areas and integrals

<fn f(x) = -x^2/4 + 3>
<fn g(x) = x/2>

<p>{ The area under the curve of $f$ between 1 and 3: }

<plot f x:{-1, 4} y:{-1, 4} area:{1, 3}>

<p>{ The area between the curves of $f$ and $g$ on $[0, 3]$: }

<plot f x:{-1, 4} y:{-1, 4} between:g area:{0, 3}>

% ---------------------------------------------------------------------
<topic>Recurrent sequences: the cobweb

<fn h(x) = sqrt(2x+3)>

<p>{ The staircase of $u_(n+1) = h(u_n)$ from $u_0 = 0.2$, converging to
the fixed point $l = 3$: }

<plot h x:{0, 4} y:{0, 4} cobweb:{0.2, 10}>


% =====================================================================
%  Function studies --- the eight-step method (Müller), three rational
%  studies and one hyperbolic, each ending on the plotted graph.
% =====================================================================
% ====================================================================
<line>
<study title:{Polynomial: $f(x) = -x^4 + 2x^2 + 1$}>{
<p>An even quartic.
}

<fn f(x) = -x^4 + 2x^2 + 1
            x:{-inf | -1 | -1/sqrt(3) | 0 | 1/sqrt(3) | 1 | +inf}
            second:{- | - | + | + | - | -}
            deriv:{+ | + | + | - | - | -}
            var:{-inf / 2 \ 1 / 2 \ -inf}>

<step title:{Domain}>{
<p>$f$ is a polynomial: its domain is all of $R$.
}

<step title:{Parity}>{
<p>$f(-x) = -x^4 + 2x^2 + 1 = f(x)$, so $f$ is even; the graph is
symmetric about the $y$-axis.
}

<step title:{Sign}>{
<p>$f(0) = 1 > 0$ and $f$ tends to $-inf$ at both ends, so $f$ vanishes
at two symmetric points and is positive between them, negative outside.
}

<step title:{Vertical asymptotes}>{
<p>None: $f$ is defined and continuous on all of $R$.
}

<step title:{Affine asymptotes}>{
<p>None: a quartic grows faster than any line, the ratio of $f(x)$ to $x$ tends to $+- inf$. There is no affine asymptote.
}

<step title:{Growth and critical points}>{
<p>$f'(x) = -4x^3 + 4x = 4x(1 - x^2)$ vanishes at $-1$, $0$, $1$: two
maxima $f(-1) = f(1) = 2$ and a local minimum $f(0) = 1$.
}

<step title:{Convexity and inflection points}>{
<p>$f''(x) = -12x^2 + 4 = 4(1 - 3x^2)$ vanishes at $+- 1/sqrt(3)$:
$f$ is convex between them and concave outside, with two inflection
points. The table gathers $f''$, $f'$ and $f$.
}

<vartab f>

<step title:{Graph}>{
<plot f samples:200 x:{-2, 2} y:{-3, 3}>
}

% ====================================================================
<study title:{Rational, horizontal asymptote: $g(x) = x^2/(x^2-2x+2)$}>{
<p>Denominator without real root.
}

<fn g(x) = x^2/(x^2 - 2x + 2)
            x:{-inf | 0 | 2 | +inf}
            deriv:{- | + | -}
            var:{1 \ 0 / 2 \ 1}>

<step title:{Domain}>{
<p>The discriminant of $x^2 - 2x + 2$ is $-4 < 0$, so the denominator
never vanishes: $g$ is defined on $R$.
}

<step title:{Parity}>{
<p>$g(-x) != g(x)$ and $g(-x) != -g(x)$: $g$ is neither even nor
odd.
}

<step title:{Sign}>{
<p>$g(x) = x^2 / (x^2 - 2x + 2)$ is a ratio of a square by a positive
quantity, so $g(x) >= 0$, vanishing only at $x = 0$.
}

<step title:{Vertical asymptotes}>{
<p>None: the denominator never vanishes.
}

<step title:{Horizontal asymptote}>{
<p>$g(x)$ tends to $1$ as $x$ tends to $+- inf$, so the line $y = 1$
is a horizontal asymptote on both sides.
}

<step title:{Growth and critical points}>{
<p>$g'(x) = 2x(2-x)/(x^2-2x+2)^2$ vanishes at $0$ and $2$: a minimum
$g(0) = 0$ and a maximum $g(2) = 2$.
}

<step title:{Convexity and inflection points}>{
<p>$g''$ vanishes at $1-sqrt(3)$, $1$ and $1+sqrt(3)$, giving three
inflection points. Its sign takes a table of its own; the variation
table below then carries only $g'$ and $g$.
}

<signtab x:{-inf | 1-sqrt(3) | 1 | 1+sqrt(3) | +inf}>{
	g''(x) : - | 0 | + | 0 | - | 0 | +
}

<vartab g>

<step title:{Graph}>{
<plot g samples:200 x:{-6, 6} y:{-1, 3}>
}

% ====================================================================
<study title:{Rational, vertical asymptote: $k(x) = (x^2+1)/(x-1)$}>{
<p>A pole at $x = 1$ and an affine asymptote.
}

<fn k(x) = (x^2+1)/(x-1)
            x:{-inf | 1-sqrt(2) | 1 | 1+sqrt(2) | +inf}
            second:{- | - || + | +}
            deriv:{+ | - || - | +}
            var:{-inf / 2-2sqrt(2) \ -inf || +inf \ 2+2sqrt(2) / +inf}>

<step title:{Domain}>{
<p>The denominator $x - 1$ vanishes at $x = 1$: the domain is
$]-inf, 1[$ union $]1, +inf[$.
}

<step title:{Parity}>{
<p>The domain is not centred at $0$, so $k$ is neither even nor odd.
}

<step title:{Sign}>{
<p>$x^2 + 1 > 0$ always, so $k(x)$ has the sign of $x - 1$: negative on
$]-inf, 1[$, positive on $]1, +inf[$.
}

<step title:{Vertical asymptote}>{
<p>At $x = 1$, $k(x)$ tends to $-inf$ on the left and $+inf$ on the
right: the line $x = 1$ is a vertical asymptote.
}

<step title:{Affine asymptote}>{
<p>Dividing gives $k(x) = x + 1 + 2/(x-1)$, so $k(x) - (x+1)$ tends to
$0$: the line $y = x + 1$ is an affine asymptote.
}

<step title:{Growth and critical points}>{
<p>$k'(x) = (x^2-2x-1)/(x-1)^2$ vanishes at $1 +- sqrt(2)$: a maximum
$k(1-sqrt(2)) = 2 - 2sqrt(2)$ and a minimum $k(1+sqrt(2)) = 2 + 2sqrt(2)$.
}

<step title:{Convexity}>{
<p>$k''(x) = 4/(x-1)^3$ never vanishes but changes sign at the pole:
$k$ is concave on $]-inf, 1[$ and convex on $]1, +inf[$, with no
inflection point. The table gathers $k''$, $k'$ and $k$.
}

<vartab k>

<step title:{Graph}>{
<plot k samples:200 x:{-4, 6} y:{-10, 12}>
}

% =====================================================================
%  Parametric and polar curves: <plot> with kind:.
% =====================================================================

<step title:{Parametric and polar curves}>{
<p>A curve that is not a function graph is the same plot with kind:. An
ellipse is parametric, a cardioid is polar; bounds may use pi.

let ell = <fn expr:{3cos(t), 2sin(t)}>
<plot ell kind:parametric t:{0, 2pi} x:{-4, 4} y:{-3, 3}>

let cardio = <fn expr:{1+cos(theta)}>
<plot cardio kind:polar theta:{0, 2pi}>
}

% =====================================================================
%  Transcendental functions and computed values: the shared numeric
%  library backs both #{...} and <plot>, and precision: rounds the
%  interpolated results for display.
% =====================================================================
<line>
<study title:{Hyperbolic: $f(x) = cosh(x)$, the catenary}>{
<p>The same eight-step method applies beyond rational functions. The
hyperbolic cosine $cosh(x) = (exp(x) + exp(-x))/2$ is the curve of a
hanging chain; the shared numeric library both draws it and computes its
values, and precision:4 on the class rounds every interpolated number.
}

<fn f(x) = cosh(x)
            x:{-inf | 0 | +inf}
            deriv:{- | +}
            var:{+inf \ 1 / +inf}>

<step title:{Domain}>{
<p>$exp$ is defined on all of $R$, hence so is $cosh$: the domain is
$R$, with no forbidden value.
}

<step title:{Parity}>{
<p>$f(-x) = (exp(-x) + exp(x))/2 = f(x)$: $cosh$ is even, the graph is
symmetric about the $y$-axis, and the study may be led on $[0, +inf[$.
}

<step title:{Sign}>{
<p>Both $exp(x) > 0$ and $exp(-x) > 0$, so $cosh(x) >= 1 > 0$ everywhere:
the curve stays above the $x$-axis, and even above the line $y = 1$.
}

<step title:{Asymptotic behaviour}>{
<p>As $x -> +inf$, $exp(-x) -> 0$, so $cosh(x) ~ exp(x)/2$: growth is
exponential and there is no asymptote. By parity the same holds as
$x -> -inf$ with $exp(-x)/2$.
}

<step title:{Growth and critical points}>{
<p>$f'(x) = sinh(x)$, which vanishes only at $0$ and has the sign of $x$:
$f$ decreases on $]-inf, 0]$, increases on $[0, +inf[$, with the global
minimum $f(0) = #{cosh(0)}$.
}

<step title:{Convexity}>{
<p>$f''(x) = cosh(x) >= 1 > 0$: $f$ is its own second derivative, convex
on all of $R$, with no inflection point.
}

<step title:{Variation table}>{
<vartab f>
}

<step title:{Graph}>{
<plot f x:{-2.5, 2.5} y:{0, 6}>
}

<step title:{A few values, rounded to four decimals}>{
<p>The same library that draws the curve computes its values. With
precision:4 set on the class, each interpolation is rounded for display:
$cosh(0) = #{cosh(0)}$, $cosh(1) = #{cosh(1)}$, and the identity
$cosh^2(1) - sinh^2(1) = #{cosh(1)^2 - sinh(1)^2}$ comes back to $1$.
The natural logarithm undoes the exponential: $ln(e) = #{ln(e)}$, while
$log(1000) = #{log(1000)}$ in base ten. A local override keeps more
figures where wanted: $pi approx #{round(pi, 8)}$.
}

\end{document}
