# pgfmath: comparison of a large number of number combinations

I have a function Zstart(n, l) that outputs a start number for certain combinations (n, l) (from which on the corresponding orbitals are filled).

Everything works, but question out of interest: Can this be implemented more easily (in pgfmath).

\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{
declare function={
Zstart(\n,\l)=(%
\n==1 && \l==0 ? 1% 1s
: (\n==2 && \l==0 ? 3% 2s
: (\n==3 && \l==0 ? 11% 3s
: (\n==4 && \l==0 ? 19% 4s
: (\n==5 && \l==0 ? 37% 5s
: (\n==6 && \l==0 ? 55% 6s
: (\n==7 && \l==0 ? 87% 7s
: (\n==8 && \l==0 ? 119% 8s
: (\n==2 && \l==1 ? 5% 2p
: (\n==3 && \l==1 ? 13% 3p
% ....
: -1))))))) ))% ....
);
},
}

Examples:

\foreach \n/\l  in {1/0, 4/0, 2/1, 55/66}{
Zstart(\n, \l) = \pgfmathprint{Zstart(\n, \l)} \\
}
\end{document}


As has been said already in previous versions of this question pgfmath and especially tikz(!!!) is completely the wrong tool here.

\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\begin{document}

\def\Zstart#1#2{%
\ifcase\numexpr#2\relax
\ifcase\numexpr#1\relax-1\or1\or3\or11\or19\or37\or55\or\87\or119\else-1\fi% l=0
\or
\ifcase\numexpr#1\relax-1\or-1\or5\or13\else-1\fi % l=1
\else
-1%
\fi}

Examples:

\foreach \n/\l  in {1/0, 4/0, 2/1, 55/66}{
Zstart(\n, \l) = \Zstart{\n}{\l} \par
}
\end{document}


If you do not use tikz then math library is overkilling. But if you already have loaded tikz for other reasons, you can probably use it like this.

\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}

\tikzmath{
% predefined values in array
let \zstart={{{-1,-1},{1,-1},{3,5},{11,13},{19,-1},{37,-1},{55,-1},{87,-1},{119,-1}}};
% function that checks the index validity and output the result
function Zstart(\n,\l) {
int \result;
if \n < 0 || \n > 8 || \l < 0 || \l > 1 then {
\result=-1;
} else {
\result=\zstart[\n][\l];
};
{\result};
};
}
\begin{document}

Examples:

\foreach \n/\l  in {1/0, 4/0, 2/1, 55/77}{
Zstart(\n, \l) = \tikzmath{Zstart(\n,\l);} \\
}
\end{document}