\subsection*{Typing (domains)}

\begin{Mexin}
domtype(-10), domtype(2/3), domtype(0.1234), domtype(0.1 + 2*I), domtype(TRUE)
\end{Mexin}

\begin{Mexin}
testtype(-10, Dom::Rational), testtype(1/3, Dom::Rational)
\end{Mexin}

\begin{Mexin}
  Z:=Dom::Integer;
  Z::hasProp(Cat::Ring);
  Z::hasProp(Cat::Field)
\end{Mexin}

\begin{Mexin}
domtype([1,2,3]), domtype({1,2,3}), domtype("1,2,3"), domtype(a*x+b)
\end{Mexin}

\begin{Mexin}
A := matrix([[1, 2], [3, 4]]): B := matrix([[a, b], [c, d]]):
A, B, domtype(A)
\end{Mexin}
\begin{Mexin}
A + B, A*B, A*B - B*A, A^2 + B
\end{Mexin}

\begin{Mexin}
Z3 := Dom::IntegerMod(3):
n := Z3(2);
n^2
\end{Mexin}

\begin{Mexin}
p := 1+x;
p^2;
expand(p^2)
\end{Mexin}

\begin{Mexin}
Q  := Dom::Rational:
PQ := Dom::UnivariatePolynomial(x, Q):
\end{Mexin}
\begin{Mexin}
p := PQ(1+x);
p^2
\end{Mexin}

\begin{Mexin}
Z2 := Dom::IntegerMod(2):
PZ2 := Dom::UnivariatePolynomial(x, Z2):
\end{Mexin}
\begin{Mexin}
p  := PZ2(1+x);
p^2
\end{Mexin}

\begin{Mexin}
factor( PZ2(1+x^2) )
\end{Mexin}

\begin{Mexin}
factor( PQ(1+x^2) )
\end{Mexin}

\begin{Mexin}
PC := Dom::UnivariatePolynomial(x, Dom::Complex):
\end{Mexin}
\begin{Mexin}
factor( PC(1+x^2) )
\end{Mexin}

\begin{Mexin}
Q  := Dom::Rational:
Qx := Dom::Fraction(Dom::DistributedPolynomial([x], Q)):
F  := Dom::AlgebraicExtension(Qx, poly(z^2 - x, [z])):
P  := Dom::UnivariatePolynomial(u,F):
\end{Mexin}
\begin{Mexin}
f := P(u^2 - x^3);
factor(f)
\end{Mexin}

\subsection{Scope of local variables}

\begin{Mexin}
p := proc() begin x end_proc:
\end{Mexin}
\begin{Mexin}
x := 3: p();
x := 4: p()
\end{Mexin}
\begin{Mexin}
q :=
proc(x)
begin
    p();
end_proc:
\end{Mexin}
\begin{Mexin}
q(5);
\end{Mexin}

\begin{Mexin}
prog::check(p, 3);
\end{Mexin}

\begin{Mexin}
x := 4:
q :=
proc()
    local x, p;
begin
    x := 5;
    p := proc() begin x; end_proc;
    x := 6;
    p()
end_proc:
\end{Mexin}
\begin{Mexin}
q()
\end{Mexin}
\begin{Mexin}
p()
\end{Mexin}

\begin{Mexin}
makePower :=
proc(n: Type::NonNegInt)
    option escape;
begin
    proc(x) begin x^n end_proc;
end_proc:
f := makePower(3);
f(1), f(2), f(3), f(4)
\end{Mexin}

\begin{Mexin}
makeCounter :=
proc()
    option escape;
    local i;
begin
    i := 0;
    proc() begin i := i + 1 end_proc
end:
counter := makeCounter():
counter();
counter();
counter()
\end{Mexin}
