I would like to be able to "globally" declare a function for use in PGFplots. That is, I want to be able to declare a function a single time, and be able to use it without having to declare it on every single plot.
Here is an MWE for what I am doing now:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[declare function = {func(\x) = \x^2;}]
\begin{axis}
\addplot[domain=0:1] {func(x)};
\end{axis}
\end{tikzpicture}
\vspace{1em}
\begin{tikzpicture}[declare function = {func(\x) = \x^2;}]
\begin{axis}
\addplot[domain=0:1] {func(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Essentially the goal would be to have something like
declare global function = {func{\x} = \x^2;}
somewhere in the header and then be able to use func throughout. Is there any way to do this?
Note: I specifically want to do this in PGFplots so stuff in "raw" tikz is not going to be so helpful to me.

\x^2might not behave as you'd expect. For example when\xis-2then\x^2becomes-2^2which is-4. If you want to have a parabola, you would have to use(\x)^2instead. – Henri Menke May 11 '19 at 03:10