I have the following code to build the derivates of a given function:
\documentclass[tikz, border=.5cm]{standalone}
\usepackage{tkz-fct}
\usepackage{xfp}
\usetikzlibrary{spy}
\definecolor{vinho}{rgb}{0.0, 0.18, 0.39}
\definecolor{vermelho}{rgb}{0.93, 0.11, 0.14}
\begin{document}
\def\a{2}
\foreach \b in {2.5,2.45,...,2.3,2.2,2.1,2.09,...,2.01}{
\begin{tikzpicture}[scale=2,cap=round,declare function = {
f(\x) = .5(\x-1.5)(\x-1.5)+1;},
spy using outlines={circle,magnification=2, height=0.5cm,size=1.5cm, connect spies}]
\clip (-1.8,-0.8) rectangle (5,3.5);
\draw[-latex] (-0.5,0) -- (4,0) node[right]{$x$};
\draw[-latex] (0,-0.5) -- (0,3) node[above]{$y$};
\draw[vinho,thick,domain=1:3.5,samples=200] plot(\x,{f(\x)}) node[right]{$f$};
\draw[vermelho,thick,domain=-1:1.91,samples=200] plot({\a + \x(\b-\a)/(sqrt( (\b-\a)^2 + (f(\b)-f(\a))^2 ))},{f(\a) + \x(f(\b)-f(\a))/(sqrt( (\b-\a)^2 + (f(\b)-f(\a))^2 ))}) node[right]{$s$};
\draw[densely dotted] (0,{f(\b)}) -- (\b,{f(\b)}) -- (\b,0) node[below]{$x_0+h$};
\draw[densely dotted] (0,{f(\a)}) -- (\a,{f(\a)}) -- (\a,0) node[below=0.08cm]{$x_0$};
\draw[fill] (\a,{f(\a)}) node[above=0.3cm]{$P$} circle (1pt);
\draw[fill] (\b,{f(\b)}) node[above]{$Q$} circle (1pt);
\draw[decoration={brace, raise=10pt},decorate,vinho!50] (0,{f(\a)}) -- node[left=10pt] {$f(x_0+h)-f(x_0)$} (0,{f(\b)});
\draw[decoration={brace,mirror,raise=5pt},decorate,vinho!50] ({\a},-.250) -- node[below=6pt] {$h$} ({\b},-.250);
\spy on ({2\a},{2f(\a)}) in node at (0.7,0.7);
\end{tikzpicture}
}
\end{document}
For each \b in the looping, I build a different frame.
However, I would like to draw the spy:
\spy on ({2*\a},{2*f(\a)}) in node at (0.7,0.7);
only for b < 2.1. Tikz does not accept a condition when deals with non integer numbers.
How can I do this?

\fpeval{trunc(\b/2.1)} < 1maybe this condition is ok – polyn Nov 02 '21 at 20:47