Function Or Not: Vertical Line Test

% Code for the left graph:
\documentclass{standalone}
\usepackage{pgfplots} % Plotting library

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xlabel = $x$,
        ylabel = $f(x)$,
        y = 1cm,
        x = 1cm,
        xmin = -5, xmax = 5, ymin = -2, ymax = 5,
        axis lines = middle,
        xlabel style = {anchor = west, xshift = 5pt},
        ylabel style = {anchor = south, yshift = 5pt}
    ]
    
    \addplot [blue, very thick, samples = 200] {x^2};
    
    % Add a bunch of colorful vertical lines. Notice how each vertical line intersects only ONCE with the blue curve:
    \pgfplotsinvokeforeach{0,...,8}{
        \addplot +[mark = none, very thick] coordinates {(2-#1*0.5, -2) (2-#1*0.5, 5)};
    }
    \end{axis}
\end{tikzpicture}

\end{document}
% Code for the right graph:
\documentclass{standalone}
\usepackage{pgfplots} % Plotting library
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xlabel = $x$,
        ylabel = $y$,
        y = 1cm,
        x = 1cm,
        xmin = -5, xmax = 5, ymin = -2, ymax = 5,
        axis lines = middle,
        xlabel style = {anchor = west, xshift = 5pt},
        ylabel style = {anchor = south, yshift = 5pt}
    ]
    
    \addplot [blue, very thick, samples = 200, name path global = Cube] {x^3};
    \addplot [blue, very thick, samples = 200, name path global = Log] {ln(x)};
    
    % Add a red vertical line at x = 1. Notice that this vertical line intersects TWICE with the blue curve: once at y = 0, and another time at y = 0.
    \addplot [mark = none, very thick, red, name path global = Line] coordinates {(1, -2) (1, 5)};
    
    % Mark intersections:
    \fill [name intersections = {of = Cube and Line, name = i, total = \t}, red, opacity = 1] 
    \foreach \s in {1,...,\t}{
        (i-\s) circle (3pt)
    };
        
    \fill [name intersections = {of = Log and Line, name = i, total = \t}, red, opacity = 1] 
    \foreach \s in {1,...,\t}{
        (i-\s) circle (3pt)
    };
    \end{axis}
\end{tikzpicture}

\end{document}