Gauge-natural parameterized variational problems, vakonomic field theories and relativistic hydrodynamics of a charged fluid
Enrico Bibbona
Variational principles for field theories where variations of fields are restricted along a parametrization are considered. In particular, gauge-natural parametrized variational problems are defined as those in which both the Lagrangian and the parametrization are gauge covariant and some further conditions is satisfied in order to formulate a N\"other theorem that links horizontal and gauge symmetries to the relative conservation laws (generalizing what Fern{\'a}ndez, Garc{\'{\i}}a and Rodrigo did in some recent papers). The case of vakonomic constraints in field theory is also studied within the framework of parametrized variational problems, defining and comparing two different concepts of criticality of a section, one arising directly from the vakonomic schema, the other making use of an adapted parametrization. The general theory is then applied to the case of hydrodynamics of a charged fluid coupled with its gravitational and electromagnetic field. A variational formulation including conserved currents and superpotentials is given that turns out to be computationally much easier than the standard one.
parametrized_variations.tex
\documentclass[11pt]{article}



%settings



\setlength{\topmargin}{-.5cm}

\setlength{\textwidth}{15cm}

\setlength{\oddsidemargin}{1cm}

\setlength{\evensidemargin}{1cm}

\setlength{\textheight}{22cm}



%packages



\usepackage[english]{babel}

\usepackage[latin1]{inputenc}

\usepackage{amsmath, amsfonts,amssymb}

\usepackage{amstext}

\usepackage{dcpic,pictex}

%\usepackage{amscd}



%\input{diagrams}
\usepackage[colorlinks, citecolor=blue, backref]{hyperref}
\usepackage[noblocks]{authblk}

%ambienti



\newtheorem{teorema}{\bf Theorem}

\newtheorem{proposizione}[teorema]{\bf Proposition}

\newtheorem{corollario}[teorema]{\bf Corollary}
\newtheorem{lemma}[teorema]{\bf Lemma}

\newtheorem{definizione}[teorema]{\bf Definition}

\newtheorem{osservazione}[teorema]{\bf Remark}

\newtheorem{esempio}[teorema]{\bf Example}



\newcommand{\Proposizione}[1]{

\addvspace{0.7cm}

\begin{proposizione}{\sf #1}\end{proposizione}}

\newcommand{\Osservazione}[1]{

\addvspace{0.7cm}

\begin{osservazione}{\sf #1}\end{osservazione}}

\newcommand{\Teorema}[1]{

\addvspace{0.7cm}

\begin
{teorema}{\sf #1}\end{teorema}}

\newcommand{\Corollario}[1]{

\addvspace{0.7cm}

\begin{corollario}{\sf #1}\end{corollario}}

\newcommand{\Lemma}[1]{

\addvspace{0.7cm}

\begin{lemma}{\sf #1}\end{lemma}}

\newcommand{\Definizione}[1]{

\addvspace{0.7cm}
\begin{definizione}{\sf #1}\end{definizione}



\addvspace{0.7cm}}

\newcommand{\DIM}[1]{{\bf Proof:} #1 \hspace{\fill}$\clubsuit$

\addvspace{0.7cm}}

\newcommand{\DEF}[1]{\Definizione{#1}}

\newcommand{\THEO}[1]{\Teorema{#1}}

\newcommand{\PROP}[1]{\Proposizione{#1}}
\newcommand{\COR}[1]{\Corollario{#1}}
\newcommand{\LEMMA}[1]{\Lemma{#1}}
\newcommand{\REMARK}[1]{\Osservazione{#1}}






\newcommand{\spl}[1]{\begin{equation}\begin{split}
#1
\end{split}\end{equation}}

\newcommand{\ali}[1]{\begin{align} #1
\end{align}}







%shortcuts

\def\id{{\mathchoice
     {\rm 1\kern-0.35em{}1}% Display Math Mode
     {\rm 1\kern-0.35em{}1}% Text Math Mode
     {\rm 1\kern-0.25em{}1}% Subscripts
     {\rm 1\kern-0.25em{}1}% ?
     }}


\def\im{\text{Im}}

\def\be{\begin{equation}}

\def\ee{\end{equation}}

\def\ba{\begin{array}}

\def\ea{\end{array}}

\providecommand{\norm}[1]{\lVert#1\rVert}

\providecommand{\abs}[1]{\lvert#1\rvert}








\providecommand{\Lie}{\pounds}

\def\<<{``}


\def\R{\mathbb{R}}


\def\N{\mathbb{N}}


\def\D{\partial}

\def\ex{\exists}


\def\fa{\forall}

\def\map{\longrightarrow}

\def\iff{\Longleftrightarrow}

\def\associa{\longmapsto}





\def\a{\`a
}

\def\ass{\`a}



\def\e{\`e }

\def\ess{\`e}

\def\o{\`o
}

\def\oss{\`o}

\def\ii{\`{\i}
}

\def\iss{\`{\i}}

\def\E{\`E
}

\def\ga{\gamma}

\def\al{\alpha}

\def\B{\beta}

\def\si{\sigma}

\def\Si{\Sigma}

\def\ve{\varepsilon}

\def\la{\lambda}

\def\de{\delta}

\def\vf{\chi}
\def\om{\omega}

\def\/{\, /\;
}






\begin{document}

\setlength{\parindent}{0in}

\author[a]{Enrico Bibbona}
\author[a,b]{Lorenzo Fatibene}
\author[a,b,c]{Mauro Francaviglia}
\affil[a]{Dipartimento di Matematica, Universit� degli Studi di Torino (Italy)}
\affil[b]{INFN, Sezione di Torino, Iniziativa Specifica NA12 (Italy)}
\affil[c]{ESG, Universit� della Calabria (Italy)}
\title{Gauge-natural parameterized variational problems, vakonomic field theories and relativistic hydrodynamics of a charged fluid}
\renewcommand\Authsep{, }
\maketitle

\begin{abstract}
Variational principles for field theories where variations of fields are restricted along a parametrization are considered.
In particular, gauge-natural parametrized variational problems are defined as those in which both the Lagrangian and the parametrization are gauge covariant and some further conditions is satisfied in order to formulate a N\"other theorem that links horizontal and gauge symmetries to the relative conservation laws (generalizing what Fern{\'a}ndez, Garc{\'{\i}}a and Rodrigo did in some recent papers).
The case of vakonomic constraints in field theory is also studied within the framework of parametrized variational problems, defining and comparing two different concepts of criticality of a section, one arising directly from the vakonomic schema, the other making use of an adapted parametrization.
The general theory is then applied to the case of hydrodynamics of a charged fluid coupled with its gravitational and electromagnetic field. A variational formulation including conserved currents and superpotentials is given that turns out to be computationally much easier than the standard one.
\end{abstract}


\section{Introduction}



In some recent literature an interest emerged about variational principles in which some specific requirement of physical or mathematical nature force us to restrict the variations of fields according to some a priori given rule.

\bigskip
As an example, let us mention Mechanics with non-integrable constraints on velocities. As it is well known there are at least two different procedures (so called vakonomic and non-holonomic) which lead to different equations of motion, it is now clear \cite{exp}, at least for affine constraints, that the more realistic trajectories are solutions of the non-holonomic one. However  the situation is less clear in more general cases (see \cite{marle} and references quoted therein), so that we do know very little about constraints in field theory (see \cite{deleon, krupkova}) and we cannot yet decide whether one procedure is better then the other for a reasonable extension out of Mechanics. In any case we shall not enter this question here, but just mention that both procedures can be implemented as variational problems with constrained variations (see \cite{garcia-vak}): they differ exactly in the choice of the rule to be imposed to admissible variations.

\bigskip
Another important case which was recently investigated is Euler-Poincar� reduction (see \cite{epred, reduction, lagred}) where a variational problem with constrained variations arises as a Lagrangian reduction of a free variational problem with symmetries.

\bigskip
A more classical example is presented in the well known book by Hawking and Ellis while introducing the equations of motion for relativistic hydrodynamics \cite{h-e}. There the constraint on variations comes from the physical requirement that variations preserve the continuity equation.

\bigskip
Motivated by all these examples, in this paper we first discuss the formal development of variational problems in which the variations are parametrized by sections of some vector bundle (Section \ref{2}).
This topic was already addressed in \cite{fgr} at least for natural constrained field theories arising from the vakonomic technique; we recover here, and sometimes generalize, some of the results of \cite{fgr} without asking that the parametrization necessarily arises from the vakonomic handling of a constraint, and we develop the case of gauge covariant field theories (much wider then the natural case) for which we develop a full N\"other theory  to link horizontal and gauge symmetries to the relative conservation laws (Section \ref{gau-na}). In Section \ref{vak} we specialize to the case of vakonomic constraints in field theories and define two different concepts of criticality for a section: one arising directly from the vakonomic paradigma, the other following from a compatible parametrization. We also show under what conditions the two concepts coincide.
In Section \ref{es}, finally, our results are applied to the case of relativistic hydrodynamics of a charged fluid.

\bigskip

An advantage of the framework we shall propose hereafter is to provide a unifying language able to deal with all variational problems with constrained variations, no matter whether they come from the vakonomic scheme, from the non-holonomic one, from a reduction problem or from any other physical or mathematical requirement. In our hope, therefore, this unified language can even allow a better comparison between different schemes.

\section{Variational calculus with parametrized variations}
\label{2}
Notation follows \cite{lo}, to which we refer the reader for further details.
Let $C\stackrel{\pi}{\map} M$ be the {\it configuration bundle} of a physical theory the sections $\Gamma(C)$ of which represent the fields (by an abuse of language we will often denote bundles with the same label as their total spaces).  


\DEF{A {\it Lagrangian} of order $k$ on the configuration bundle 
$C\stackrel{\pi}{\map}M$ ($m= \dim M$) is a fibered morphism
\[ L: J^k C \map \wedge^m \, T^\ast M.\]}



\DEF{
A {\it parametrization} of order $s$ and rank $l$
($s\geq l$ is required) of the set of constrained variations is a couple
$(E,\mathbb{P})$, where
$E$ is a vector bundle $E\stackrel{\pi_E}{\map} C$ while 
$\mathbb{P}$ is a fibered morphism (section)
\[\mathbb{P}:  J^s C \map (J^l E)^\ast\otimes_{J^lC} VC;\]
here $J$ denotes jet prolongation and $V$ is the vertical functor.
}
If $(x^\mu, y^a,\varepsilon^A)$ are local fibered coordinates on $E$ and $\{\D_a\}$ is the induced fiberwise natural basis of $VC$, a parametrization of order $1$ and rank $1$ associates to a section $y^a(x)$ of $C$ and a section $\varepsilon^A(x, y)$ of $E$ the section \[ \big[p^a_A \big(x^\nu, y^b(x), \D_\nu y^b(x) \big)\varepsilon^A(x,y(x)) + p^{a\phantom{A}\mu}_A (x^\nu, y^b(x), \D_\nu y^b(x) \big) d_\mu \varepsilon^A(x,y(x))\big]\, \D_a\] of $VC$.



\DEF{\label{xxx}Given a compact submanifold $D \subset M$ with suitably regular boundary $\D D$, an {\it
admissible variation} (for a Lagrangian with order $k$ and a parametrization of order $s$ and rank $l$) of a configuration $\si\in
\Gamma(C)$ on $D$ is a smooth $1$-parameter family of sections $\{\si_t\}_{t\in ]-1,1[}\subset
\Gamma (\pi ^{-1} D)$ such that
\begin{enumerate}
\item $\si_0 =\si|_D$
\item $\fa t \in ]-1,1[,\quad j^{k-1}\si_t|_{\D D}= j^{k-1}\si|_{\D D} $
\item \label{333}there exists a section $\ve\in\Gamma(E)$ such that $\frac{d}{d t} \si_t |_{t=0} =<\mathbb{P}\,|\,j^l \ve>\circ j^s \si $ and $j^{k+l-1}(\ve \circ \si)|_{\D D}=0$. 
\end{enumerate} }




\DEF{The set $\{C, L, \mathbb{P}\}$ where $C\stackrel{\pi}{\map}M$ is a 
configuration bundle, $L$ is a Lagrangian on $C$ and $\mathbb{P}$ is a 
parametrization of the set of constrained variations is called a \<<parametrized variational problem''.}

\DEF{We define {\it critical} for the parametrized variational problem $\{C, L, \mathbb{P}\}$ those sections of $C$ such that, for any compact domain $D \subset M$ and for any admissible variation $\{\si_t\}$ defined on $D$ one has 
\[\left.\frac{d}{d t } \int_D L \circ j^k
\si_t \right|_{t =0}=0.\]} 

Accordingly, if we use the trivial parametrization $\mathbb{P}: C\map VC^\ast\otimes_C VC$ that to any $p\in C$ associates the identity of $V_pC$ then the third condition becomes empty and we recover free variational calculus. 



For an ordinary variational problem with Lagrangian $L= \mathcal{L}\, ds$, criticality of a section of $C$ is equivalent in local fibered coordinates $(x^\mu, y^a)$ to the fact that for any compact $D\subset M$ and for any $V\in \Gamma(VC)$ such that $j^{k-1} (V\circ\si)|_{\D D}=0$ one has
\[ \int_D\left[\frac{\D \mathcal{L}}{\D y^i} V^i(x,y(x)) +
\frac{\D \mathcal{L}}{\D y^i_\mu}
d_\mu V^i (x,y(x))+
\cdots + \frac{\D \mathcal{L}}{\D y^i_{{\mu_1}\cdots{\mu_k}}}
d_{\mu_1} \cdots d_{\mu_k} V^i (x,y(x))\right]\, ds=0. \]

Explicit calculations (see \cite{lo}) show that the local coordinate expressions given above glue
together giving rise to the global expression
\begin{equation}\label{iiii} \fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\, \fa V\in VC\,
\text{  s. t. } j^{k-1} (V\circ \si )|_{\D 
D}=0,\quad\int_D<\de L\:|\:
j^k V>
\circ j^k \si =0 \end{equation} where $\de L$ is a global fibered (variational)
morphism
\begin{equation}
\label{deltaL}\de L: J^k C \map (J^k VC)^\ast \otimes_{J^k C} 
\Lambda^m T^\ast M.
\end{equation}

The rigorous definition and a short account on variational morphisms will be
given in Appendix \ref{morfismi}, where the reader can find some non-conventional definitions that we have generalized in order to embrace the case of parametrized variations.


\subsection{$\mathbb{P}$-first variation formula and $\mathbb{P}$-Euler-Lagrange equations}
\label{P}

To define criticality for parametrized variational problems with a $k^{th}$-order Lagrangian and a parametrization of rank $l$, we have to restrict variations to those $V\in VC$ in \eqref{iiii} with $j^{k-1} (V\circ \si )|_{\D 
D}=0$ that can be obtained through the parametrization from a section $\varepsilon$ of $E$ satisfying $j^{l+k-1} (\varepsilon \circ \si)|_{\D D}=0$.
Let us make t explicit on a first order Lagrangian and a parametrization with rank $1$ and order $1$: if  $(x^\mu, y^a, \varepsilon^A)$ are local fibered coordinates on $E$ and $ (p^a_A \varepsilon^A + p^{a\phantom{A}\mu}_A  d_\mu \varepsilon^A)\D_a$ is the local representation of $<\mathbb{P}\,|\,j^1 \varepsilon>\circ j^1 \si$, criticality holds if and only if for any compact $D\subset M$, for any section $\varepsilon$ with coordinate expression $\varepsilon^A(x,y)$ such that both $\varepsilon^A(x,y(x))=0$ and $d_\mu \varepsilon^A(x,y(x))=0$ for all $x\in \D D$, we have
\begin{equation} \int_D\left[\frac{\D \mathcal{L}}{\D y^a} (p^a_A \varepsilon^A + p^{a\phantom{A}\mu}_A  d_\mu \varepsilon^A) +
\frac{\D \mathcal{L}}{\D y^a_\mu}
d_\mu (p^a_A \varepsilon^A + p^{a\phantom{A}\nu}_A  d_\nu \varepsilon^A)\right]\, ds=0.\label{local} \end{equation}


To set up an intrinsic characterization of critical sections possibly given by a set of differential equations let us introduce the following procedure.

Let us take any parametrization $\mathbb{P}$ and think of 
it as a morphism


\[\mathbb{P}': J^s C \times J^l E \map  VC \]
linear in its second argument. Take its $k^{th}$-order (holonomic) 
jet prolongation (see Appendix \ref{morfismi}, Definition \ref{prol})
\[j^k\mathbb{P}': J^{s+k} C \times J^{l+k} E \map  J^kVC \]
and read it as a bundle morphism
\[j^k\mathbb{P}':  J^{s+k} C \map (J^{l+k} E)^\ast\otimes_{J^{s+k}C} J^kVC\]
(for simplicity we still denote it by $j^k\mathbb{P}'$, but the same abuse of notation cannot safely be adopted also for $\mathbb{P}$ and $\mathbb{P}'$ because the jet prolongations of the two objects give completely different results).

Let us consider the variational morphism $\de L: J^k C \map (J^k VC)^\ast
\otimes_{J^kC} \Lambda^m T^\ast M$ introduced in formula 
\eqref{deltaL} and
take its formal contraction (see Definition \ref{contr}) with $j^k\mathbb{P}'$. What we 
get is the
variational $E$-morphism

\[<\de L\,|\,j^k\mathbb{P}'>: J^{k+s} C \map (J^{l+k} E)^\ast
\otimes_{J^{l+k}C} \Lambda^m T^\ast M.\]


Criticality of a section $\si$ can now be recasted in the following global requirement 
\begin{gather*}\displaystyle\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\; \fa \varepsilon \in
\Gamma(E)\text{ s. t. }j^{l+k-1} (\varepsilon \circ \si)\big|_{\D D}=0 ,\\ \int_D \Big< <\de
L\,|\,j^k\mathbb{P}'>\,\Big|\, j^{l+k}\varepsilon\Big> \circ 
j^{k+s} \si =0\end{gather*}

This intrinsic procedure leads in the case of first order Lagrangians and first order first rank parameterizations to the local expression \eqref{local}.

Now we can try to turn this requirement into a set of differential equations. The first step is to search for a first variation formula for parametrized variational problems.


Thanks to Theorem \ref{splitting}, for any choice of a fibered connection 
$(\ga,\Gamma)$ on $E\map C\map M$ (see Definition \ref{formalcon} and \ref{fibercon}), there
exists a unique pair
$(\mathbb{E},
\mathbb{F})$ of variational morphisms
\[\begin{aligned}{}&\mathbb{E}(L, \mathbb{P}): J^{2k +l +s}C \map 
E^\ast\otimes_C
\Lambda^m T^\ast M\\
&\mathbb{F}(L, \mathbb{P},\ga): J^{2k +l +s-1}C \map
(J^{l+k-1}E)^\ast\otimes_{J^{l+k-1}C} \Lambda^m T^\ast M \end{aligned}\]
reduced with respect to $(\ga, \Gamma)$ (see Definition \ref{redu}) such that $\fa \varepsilon \in
\Gamma(E)$ one has
\begin{equation}\Big< <\de L\,|\,j^k\mathbb{P}'>\,\Big|\,
j^{l+k}\epsilon\Big>=  <\mathbb{E}\,|\,\varepsilon>+ \text{ Div}
<\mathbb{F}\,|\,j^{l+k-1}\varepsilon>.\label{pardeltaLL}\end{equation}
In the previous equation Div stands for the divergence of a variational morphism (Appendix \ref{morfismi}, Definition \ref{Div}) that coincides when computed on a section with the exterior differential of forms.
\DEF{We call {\it $\mathbb{P}$-Euler-Lagrange morphism} the variational
morphism $\mathbb{E}(L, S,\mathbb{P})$ and {\it $\mathbb{P}$-Poincar\'e -Cartan morphism} the variational morphism $\mathbb{F}(L, S, \mathbb{P}, \ga)$.}

\PROP{A section $\si$ of $C$ is critical for the parametrized variational problem $(C,L,\mathbb{P})$ (with $L$ of order $k$ and $\mathbb{P}$ of order $s$ and rank $l$)  if and only if $<\mathbb{E}\,|\,\varepsilon>\circ j^{2k +l +s}\si =0$.}
\DIM{We have 
\begin{gather*}\displaystyle\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\; \fa \varepsilon \in
\Gamma(E)\text{ s. t. }j^{l+k-1} (\varepsilon \circ \si)\big|_{\D D}=0 ,\; \int_D \Big< <\de
L\,|\,j^k\mathbb{P}'>\,\Big|\, j^{l+k}\varepsilon\Big> \circ 
j^{k+s} \si =0\\
\Updownarrow\\
\displaystyle\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\; \fa \varepsilon \in
\Gamma(E)\text{ s. t. }j^{l+k-1} (\varepsilon \circ \si)\big|_{\D D}=0 ,\\ \int_D <\mathbb{E}\,|\,\varepsilon> \circ j^{2k +l +s}\si+ \int_D d
\big(<\mathbb{F}\,|\,j^{l+k-1}\varepsilon> \circ 
j^{2k +l +s-1} \si\big) =0\\
\Updownarrow\\
\mathbb{E} \circ j^{2k +l +s}\si=0
\end{gather*}
The first equivalence is ensured by the first variation formula \eqref{pardeltaLL} and the Definition \ref{Div}, while
the last holds in force of the fact that $j^{l+k-1} (\varepsilon \circ \si)\big|_{\D D}=0$ and that $\varepsilon$ and $D$ are arbitrary.}




We stress that the number of derivatives of fields in $\mathbb{E}$ and  $\mathbb{F}$ is not sharp: in fact, due to the particular structure of the morphism $<\de L\,|\,j^k\mathbb{P}'>$, it is actually always lesser then the one expected from the naive issue.
Moreover, the morphism $\mathbb{E}(L, \mathbb{P})$ in the splitting \label{pardeltaL1} is truly
unique (i.e. independent on the connection used),  while
$\mathbb{F}(L, \mathbb{P}, \ga)$ is just one representative in the class of variational morphisms fitting into formula \eqref{pardeltaLL} chosen o that it is reduced with respect to the fibered
connection $(\ga,\Gamma)$; more precisely, the final expression of the morphism $\mathbb{F}(L, \mathbb{P}, \ga)$ depends at most on the spacetime connection $\ga$, while if $l+k\leq 2$ (the most common case) also $\mathbb{F}$ can be defined independently on any part of the fibered connection, so that the splitting algorithm can be performed in coordinates simply by integration by parts on the derivatives of the sections of $E$.


In the case $k=1$, $l=1$ and $s=1$, with the same coordinate representation as in formula \eqref{local}, the morphisms $\mathbb{E}$ and $\mathbb{F}$ are the following:
\begin{gather*}<\mathbb{E}\;|\; \varepsilon> \circ j^3\si = \left\{\left(\frac{\D L}{\D y^a} - d_\nu \frac{\D L}{\D
y^a_\nu}\right) p^a_A  - d_\mu \left[ \left(\frac{\D L}{\D y^a} - d_\nu
\frac{\D L}{\D y^a_\nu}\right){p^a_A}^\mu\right]\right\} \varepsilon^A\;  ds \\
<\mathbb{F}\;|\; j^1 \varepsilon> \circ j^2 \si = \left[ \left(\frac{\D L}{\D y^a} - d_\nu
\frac{\D L}{\D y^a_\nu}\right){p^a_A}^\mu
\varepsilon^A+\frac{\D L}{\D y^a_\mu} (p^a_A \ve^A +
{p^a_A}^\nu d_\nu \varepsilon^A)\right]\;ds\end{gather*}
and they can easily be obtained integrating by parts the integrand of equation \eqref{local}.





\subsection{Symmetries}

The second natural question arising in our investigations is whether the link between symmetries and conserved currents given in the standard N\"other theory is preserved if we vary configurations only along the parametrized variations.
First of all the definition of symmetry for a parametrized variational problem has to be changed with respect to the ordinary one in order to ensure the invariance of the parametrization as well as that of the Lagrangian. 
\DEF{Let $C\stackrel{\pi_C}{\map}M$ be a configuration bundle, $L$ a 
Lagrangian of order $k$ and $(E, \mathbb{P})$ a parametrization  of order $r$ and rank $l$ on the vector bundle $E\stackrel{\pi_E}{\map}C$.

Let $Z:E\map TE$ be a vector field on the bundle $E\map M$ such that $Y= T\pi_E Z$ is a vector field on $C$, while $X=T\pi_E Y$ is a vector field on $M$.


Calling $\Psi_{Z,s}^E$, $\Psi_{Y,s}^C$ and $\Psi_{Y,s}^{VC}$ the flows of fibered transformations generated by the vector fields $Z$ and $Y$ on the bundles $E$, $C$ and $VC$ respectively, we can drag any section $\varepsilon\in \Gamma(E)$ along $\Psi_{Z,s}^E$ getting the section $\varepsilon_s=(\Psi_{Z,s}^E)^\star \varepsilon$, any section $\si\in \Gamma(C)$ along $\Psi_{Y,s}^C$ getting $\si_s=(\Psi_{Y,s}^C)^\star \si$ and, for any section $V\in \Gamma(VC)$, we can also drag $V\circ \si$ along $\Psi_{Y,s}^{VC}$ getting $(\Psi_{Y,s}^{VC})^\star V\circ\si$.

The vector field $Z$ is an {\it infinitesimal Lagrangian symmetry} of the (parametrized) variational problem $\{C,L,\mathbb{P}\}$ if the following {\it covariance identity}
\begin{equation}<\de L\,|\,j^{k} \Lie_Y \si> = \text{Div} (i_X L) +\text{Div}
<\al\,|\,j^{k} Y> \label{covid}
\end{equation}
holds for some morphism $\al : J^{k+h}C \map 
(J^kTC)^\ast \otimes_{J^kC}
\Lambda^{m-1}T^\ast M$,
and moreover we have
\[ <\mathbb{P}\,|\,j^l \varepsilon_s> \circ j^r \si_s = (\Psi_{Y,s}^{VC})^\star (<\mathbb{P}\,|\,j^l \varepsilon> \circ j^r \si). \	\]
\label{simmetrie}}
The definition of infinitesimal symmetry has now been extended to variational problems with parametrized variations. Nevertheless in order to establish a correspondence between symmetries and conserved currents we need some more restrictive hypothesis.
Usually (in the case with free variations) one considers the covariance identity \eqref{covid} and simply splits $\de L$ in its Euler-Lagrange part plus the divergence of the Poincar�-Cartan part: being the first vanishing on shell, one gets the conserved current as the argument of the residual divergence. 
In our framework, on the contrary, field equations arise from the splitting of $<\de L\,|\,j^k\mathbb{P}'>$ so that we would need a rule to associate to any symmetry $Y$ and to any configuration $\si$ a section of the bundle of parameters that in turn is mapped by the parametrization into $\Lie_Y \si$. Without any further hypothesis such a section is not guaranteed to exist.
In thee next Section we will then state all the necessary assumptions which are needed to get a N\"other theorem in the case of gauge-natural symmetries of gauge-natural variational problems in the next section.



\section{Gauge-natural constrained theories}\label{gau-na}
Gauge-natural field theories have been shown to be the most general setting to
describe Lagrangian field theories with gauge symmetries, including gauge
theories, General Relativity in its different formulations, bosons, spinors and also supersymmetries (see \cite{lo-review, lo}).
In the book \cite{lo} it was also described in detail how to cope with
conservation laws linked to pure gauge (vertical) symmetries and 
how to implement
the conservation of energy and momentum as N\"other currents relative 
to an horizontal lift of space-time diffeomorphisms.
The goal of this Section is to extend the previously known results to the case of constrained
variational problems under suitable conditions. The original material on gauge-natural bundles can be found in \cite{eck}; a standard reference with many theoretical improvements is \cite{kolar}; a more applicative approach can be found in \cite{lo}, while a friendly introduction to the subject is also provided in Appendix \ref{GNmaterial}.

\subsection{Morphisms between gauge-natural bundles}

In this sub-Section we recall the fundamental definitions about morphisms between gauge-natural bundles, their push-forward along gauge transformations and their Lie derivatives. Gauge-natural morphisms are also defined.

For any principal automorphism $\Psi= (\phi, \psi)$ of the principal bundle $P\map M$ let us denote by $\mathfrak{B}(\Psi)= (\phi, \hat{\Psi}_\mathfrak{B})$ the gauge-natural lift of $\Psi$ to the gauge natural bundle $\mathfrak{B}(P)$.


\DEF{A bundle morphism between gauge-natural bundles $\mathbb{M}: 
\mathfrak{B}(P) \map
\mathfrak{D}(P)$ projecting onto the identity is said to be {\it 
gauge-natural} if
for any local principal automorphism $\Psi$ of $P$ the following diagram commutes
\nopagebreak
\[
\begindc{\commdiag}[2]
\obj(20,10)[Bd]{$\mathfrak{B}(P)$}
\obj(20,40)[Bu]{$\mathfrak{B}(P)$}
\obj(50,10)[Dd]{$\mathfrak{D}(P)$}
\obj(50,40)[Du]{$\mathfrak{D}(P)$}
\mor{Bu}{Du}{$\mathbb{M}$} 
\mor{Bd}{Dd}{$\mathbb{M}$} 
\mor{Bu}{Bd}{$\mathfrak{B}(\Psi)$} [\atright,\solidarrow]
\mor{Du}{Dd}{$\mathfrak{D}(\Psi)$} 
\enddc\]
}


\DEF{Let $\mathbb{M}: \mathfrak{B}(P) \map\mathfrak{D}(P)$ be a vertical (i.e. projecting onto the identity) morphism between gauge-natural bundles. We define its {\it push-forward} along the local principal automorphism $\Psi= (\phi, \psi)$ to be the unique vertical morphism 
$\Psi^\star\mathbb{M}: \mathfrak{B}(P) \map\mathfrak{D}(P)$ such that for all section $\si \in \Gamma(\mathfrak{B}(P))$ we have
\[\mathfrak{D}(\Psi)^\star(\mathbb{M}\circ \si) = \Psi^\star\mathbb{M} \circ \mathfrak{B}(\Psi)^\star \si.\]}

As a consequence we have the following explicit rule of calculation: 
\[\Psi^\star \mathbb{M}= \mathfrak{D}(\Psi)\circ \mathbb{M}\circ \mathfrak{B}(\Psi^{-1})  =\hat{\Psi}_\mathfrak{D}\circ \mathbb{M}\circ  \hat{\Psi}^{-1}_\mathfrak{B}.\]

\DEF{\label{LLIIEE}Let $\mathbb{M}: \mathfrak{B}(P) \map \mathfrak{D}(P)$ be a vertical morphism between gauge-natural bundles over the same base and $\Psi_s= (\phi_s, \psi_s)$ a $1$-parameter family of local principal automorphisms having $\Xi\in\Gamma(\text{IGA}(P))$ as generator. We define the {\it Lie derivative} of the morphism $\mathbb{M}$ along $\Xi$ to be the morphism $\Lie_\Xi \mathbb{M}: \mathfrak{B}(P) \map V\mathfrak{D}(P)$ that fulfills
\[\Lie_\Xi \mathbb{M} = - \left.\frac{d}{ds} \Psi_s^\star \mathbb{M}\right|_{s=0}. \]
}
From the definition it follows immediately that the expression of the Lie derivative of a morphism is linked to that of the Lie derivative of sections by means of the following rule: for all $\si\in \Gamma(\mathfrak{B}(P))$ 
\[ \Lie_\Xi \mathbb{M} \circ \si = \Lie_\Xi \, (\mathbb{M}\circ \si) - T\mathbb{M} \circ \Lie_\Xi  \si .\]

If we use coordinates $(x^\mu, y^a)$ on $\mathfrak{B}(P)$ and $(x^\mu, z^A)$ on $\mathfrak{D}(P)$, the local expression of $\mathbb{M}$ is $\mathbb{M}:(x^\mu, y^a) \associa (x^\mu, z^A(x^\mu, y^a))$.

Let us call $\hat{\Xi}_{\mathfrak{B}}$ and $\hat{\Xi}_{\mathfrak{D}}$ the gauge-natural lifts of an infinitesimal generator of principal automorphisms $\Xi$ respectively to $\mathfrak{B}(P)$ and $\mathfrak{D}(P)$, and let 
\[\hat{\Xi}_{\mathfrak{B}}= \Xi^\mu \frac{\D}{\D x^\mu} +\hat{\Xi}_{\mathfrak{B}}^a \frac{\D}{\D y^a}  \qquad\text{ and }\qquad \hat{\Xi}_{\mathfrak{D}}= \Xi^\mu \frac{\D}{\D x^\mu} +\hat{\Xi}_{\mathfrak{D}}^A \frac{\D}{\D z^A}\]
be their coordinate expressions.

The Lie derivative of $\mathbb{M}$ has thence local coordinate expression 
\[\Lie_\Xi \mathbb{M}= \left(\hat{\Xi}_{\mathfrak{D}}^A - \frac{\D z^A}{\D y^a}\hat{\Xi}_{\mathfrak{B}}^a \right) \frac{\D}{\D z^A}. \]

\REMARK{\label{LLIEE2}Let $\mathfrak{B}(P)$ and $\mathfrak{D}(P)$ be gauge-natural bundles of order $(r,s)$ and $(j,k)$ respectively. We can think at the Lie derivative as a fibered morphism
\[\Lie\mathbb{M}: \mathfrak{B}(P)\map \big(J^m \text{IGA}(P)\big)^\ast\otimes_{\mathfrak{D}(P)} V\mathfrak{D}(P)\]
with $m=\max\{r,j\}$ such that if $\Xi$ is vertical (i.e. a section of $\textstyle\frac{VP}{G}\hookrightarrow \text{IGA}(P)$), $\Lie_\Xi \mathbb{M}$ depends in fact on the derivatives of $\Xi$ only up to the order $f=\max\{s,k\}$.}

\PROP{A necessary and sufficient condition for a vertical morphism between
gauge-natural bundles $\mathbb{M}: \mathfrak{B}(P) \map \mathfrak{D}(P)$ to be gauge-natural is that for any $1$-parameter family of local automorphisms $\Psi_s$ of $P$ generated by $\Xi$, one has
\[ \Psi_s^\star \mathbb{M}= \mathbb{M}\qquad\text{or}\qquad \Lie_\Xi \mathbb{M} =0.\]
}
\PROP{Any global morphism $\mathbb{M}: \mathfrak{B}(P) \map \mathfrak{D}(P)$ has to be gauge-natural and any local gauge-natural morphism can be extended to a global one.}
\DIM{(Sketch) A trivialization of $P$ induces both a trivialization of $\mathfrak{B}(P)$ and $\mathfrak{D}(P)$ (see \cite{lo}) and gauge-naturality is exactly the same as invariance with respect to changes of trivializations of $P$. }

\subsection{Variationally gauge-natural morphisms}

In this sub-Section we present some technical properties that follow from requiring a local Lagrangian not exactly to be a gauge-natural morphism (that would imply globality) but to satisfy a slightly more relaxed condition that amounts to say that every gauge transformation has to be a Lagrangian symmetry according to definition \ref{simmetrie} if a gauge-natural parametrization is provided.

This generalization is needed in order to deal with the case presented as an example in Section \ref{esempio}.

The Theorems we shall develop here can be applied to ordinary variational calculus, but they have been introduced with the explicit aim of embracing the case of parametrized variations; their consequences will be analyzed in the next sub-Section. 


\DEF{\label{var_g_n}Let $\mathfrak{C}(P)\map M$ be a gauge-natural bundle and $F \map \mathfrak{C}(P)$ be a  vector bundle such that the composition $F \map \mathfrak{C}(P) \map M$ is a gauge natural bundle  on $M$ that we call $\mathfrak{F}(P)$.
A local variational morphism
\[\mathbb{M}: J^k \mathfrak{C}(P)  \map (J^h \mathfrak{F}(P))^\ast \otimes_{J^hC} \Lambda^{m-n}T^\ast(M)\]
is said to be {\it variationally gauge-natural} if for any $1$-parameter family of local automorphisms $\Psi_s$ of $P$ generated by $\Xi$ there exists a $1$-parameter family of variational morphisms $\{\al_s\}$
with
\[\al_s: J^{k-1} \mathfrak{C}(P)  \map (J^{h-1} \mathfrak{F}(P))^\ast {\otimes} \Lambda^{m-n-1}T^\ast(M)\]
such that, for every section $X\in \Gamma(\mathfrak{F}(P))$ one has
\[ \Psi_s^\star <\mathbb{M}\:|\:j^h X>= <\mathbb{M}\:|\:\Psi_s^\star j^h X> +  \text{ Div} <\al_s  \:|\: \Psi_s^\star j^{h-1} X>.\]}
 
\REMARK{In terms of Lie derivatives there are many possible equivalent infinitesimal formulations of the definition of variational gauge-naturality. Let us consider the morphism 
\[\mathbb{M}: J^k \mathfrak{C}(P)  \map (J^h \mathfrak{F}(P))^\ast \otimes_{J^hC} \Lambda^{m-n}T^\ast(M)\]
and let us think of it as a morphism
\[\mathbb{M}': J^k \mathfrak{C}(P) \times J^h \mathfrak{F}(P) \map \Lambda^{m-n}T^\ast(M)\]
linear in its second argument. Let us suppose that $\mathfrak{C}(P)$ is gauge-natural of order $(r,s)$ and $\mathfrak{C}(P)$ of order $(j,k)$ and that $m=\min \{r,j\}$, according to Remark \ref{LLIEE2}; then the Lie derivative of $\mathbb{M}'$ with respect to a gauge generator $\Xi$ is a morphism
\[\Lie_\Xi \mathbb{M}': J^k \mathfrak{C}(P) \times J^h \mathfrak{F}(P) \map  \big(J^{m}\text{IGA}(P)\big)^\ast\otimes_{M} V\Lambda^{m-n}T^\ast(M),\]
linear in the second argument, that can also be thought as
\[\Lie_\Xi \mathbb{M}': J^k \mathfrak{C}(P) \map (J^h \mathfrak{F}(P))^\ast \otimes \big(J^{m}\text{IGA}(P)\big)^\ast\otimes V\Lambda^{m-n}T^\ast(M)\]
where the tensor product is on the base $J^h \mathfrak{C}(P)$ (for simplicity we still denote it by $\Lie_\Xi \mathbb{M}'$).
Using the map $\pi_2$ introduced in Remark \ref{pi2}, we can say that variational gauge-naturality of $\mathbb{M}$ is equivalent to the existence of a morphism
$\al: J^{k-1} \mathfrak{C}(P) \map \big(J^h \mathfrak{F}(P)\big)^\ast \otimes  \big(J^{m}\text{IGA}(P)\big)^\ast\otimes V\Lambda^{m-n}T^\ast(M)$ such that

\[\pi_2 < \Lie_\Xi \mathbb{M}'\:|\: j^h X > =  \text{Div } \Big( \pi_2 \Big<<\al\;|\;j^{m-1}\Xi>  \:\Big|\: j^{h-1} X \Big>\Big), \]
and the link between $\al$ and the $1$-parameter family $\{\al_s\}$ of definition \ref{var_g_n} is 

\[- \frac{d}{ds} \left. \al_s  \right|_{s=0}=  <\al\;|\;j^{m-1}\Xi>.\]}


Concrete examples in local coordinates of how to check variational gauge-naturality of a Lagrangian morphism as well as that of an Euler-Lagrange morphism will be given in the proof of Proposition \ref{gndel}.
\bigskip

In our exposition, two technical lemmas precede the main basic properties of variationally gauge-natural morphisms and in particular of variationally gauge-natural Lagrangians in order to simplify their proofs. 
The first lemma is very well known, but we report it here just to display some coordinate expression which will be easily recognized later. To our knowledge the other statements have not yet been proved in the same generality.

\Lemma{\label{lemma1}If $L=\text{Div } \Lambda$ then for every $X\in\Gamma (VC)$ there exists a  morphism $\de \Lambda$ such that $<\de L \:|\: j^k X> = \text{Div} <\de \Lambda \:|\: j^{k-1} X>$. If $\Lambda$ is global, so is $\de \Lambda$.}

\DIM{Let $\Lambda $ be a local variational morphism
\[\Lambda: J^{k-1} C  \map (J^{k-1}VC)^\ast {\otimes}_{J^{k-1}C} \Lambda^{m-1}T^\ast(M)\]
where $M$ is the base of the configuration bundle $C$.
Let us use coordinates $(x^\mu, y^a_{\bar{\al}})$ on $J^k C$ ($\mu$ runs from $1$ to $\text{dim } M$, while $\bar{\al}$ is a multiindex of length $0\leq\abs{\bar{\al}}<k$) and let us express $\Lambda$ in coordinates as $\Lambda = \Lambda^\mu (x^\mu, y^a_{\bar{\al}})\, ds_\mu$ (with $0\leq\abs{\bar{\al}}<k$) while $L= d_\mu \Lambda^\mu (x^\mu, y^a_{\bar{\al}})\,ds$.

The coordinate expression for the morphism $<\de L\,|\, j^k X>$ is the following
\begin{equation} <\de L\,|\, j^k X> = \frac{\D d_\mu \Lambda^\mu}{\D y^a_{\bar{\nu}}}X^a_{\bar{\nu}} \; ds.\label{!}\end{equation}
where the multiindex $\bar{\nu}$ has length $0\leq\abs{\bar{\nu}}\leq k$.

We have
 
\[\frac{\D d_\mu \Lambda^\mu}{\D y^a_{\bar{\nu}}}= d_\mu \frac{\D \Lambda^\mu}{\D y^a_{\bar{\nu}}} + \de^{\bar{\al}+ \bar{1}_\mu}_{\bar{\nu}} \frac{\D \Lambda^\mu}{\D y^a_{\bar{\al}}}, \]
where the multi-index $\bar{\al}$ has length $\abs{\bar{\al}}= \abs{\bar{\nu}} - 1$ and by $\bar{1}_\mu$ we mean a multiindex with $1$ entry in position $\mu$ and zero elsewhere, while for $\abs{\bar{\nu}}=0$ there is no $\bar{\al}$ to fit into the formula so that one has to set $\de^{\bar{\al}+ \bar{1}_\mu}_{\bar{\nu}}=0$, while for $\abs{\bar{\nu}}=k$ we simply have 
\[d_\mu \frac{\D \Lambda^\mu}{\D y^a_{\bar{\nu}}}=0.\]



Substituting now into \eqref{!} we get

\[<\de L\,|\, j^k X> =  \left[ d_\mu \frac{\D \Lambda^\mu}{\D y^a_{\bar{\nu}}} + \de^{\bar{\al}+ \bar{1}_\mu}_{\bar{\nu}} \frac{\D \Lambda^\mu}{\D y^a_{\bar{\al}}} \right]X^a_{\bar{\nu}}\; ds =d_\mu \left(\frac{\D \Lambda^\mu}{\D y^a_{\bar{\al}}}X^a_{\bar{\al}}\right)\; ds.\]

We have found the local expression of the morphism $\de \Lambda$

\[ \de \Lambda = (\de \Lambda)^\mu \,  ds_\mu\qquad\text{ with }\qquad(\de \Lambda)^\mu =\frac{\D \Lambda^\mu}{\D y^a_{\bar{\al}}}X^a_{\bar{\al}}\]
 of which we wanted to prove the existence. It remains to straightforwardly check that if $\Lambda$ is global so is $\de \Lambda$; and that in this case the previous one is an invariant expression that does not depend on the chosen coordinates.} 


\Lemma{\label{lemma2}The gauge-natural lift $j^k\Hat{\Xi}_{V\mathfrak{C}}$ of an infinitesimal generator $\Xi\in \Gamma(\text{IGA}(P))$ of principal automorphisms of $P$ to the $k^{th}$-jet prolongation of the vertical bundle $V\mathfrak{C}(P)$ of a gauge-natural bundle $\mathfrak{C}(P)$ can be computed from the lift $j^k \Hat{\Xi}_\mathfrak{C}$ to the same jet prolongation of the base bundle $\mathfrak{C}(P)$ according to the following rule:
let $(x^\mu, y^a_{\bar{\nu}})$ be fibered coordinates on $J^k \mathfrak{C}(P)$ and $(x^\mu, y^b_{\bar{\nu}}, v^b_{\bar{\nu}})$ on $J^k V\mathfrak{C}(P)$ ($\bar{\nu}$ is a multi-index of length $0\leq \abs{\bar{\nu}}\leq k$). If
\[ j^k \Hat{\Xi}_\mathfrak{C}= \Xi^\mu \frac{\D}{\D x^\mu} + (j^k \hat{\Xi}_{\mathfrak{C}})^b_{\bar{\nu}} \frac{\D}{\D y^b_{\bar{\nu}}} \]
is the coordinate expression of $j^k \Hat{\Xi}_\mathfrak{C}$ then the coordinate expression of 
$j^k \Hat{\Xi}_{V\mathfrak{C}}$ is 
\[j^k \Hat{\Xi}_{V\mathfrak{C}}= \Xi^\mu \frac{\D}{\D x^\mu} +  (j^k \hat{\Xi}_{\mathfrak{C}})^b_{\bar{\nu}} \frac{\D}{\D y^b_{\bar{\nu}}} + {(j^k \Hat{\Xi}_{V\mathfrak{C}})}^b_{\bar{\nu}} \frac{\D}{\D v^b_{\bar{\nu}}} \]
with
\[ {(j^k \Hat{\Xi}_{V\mathfrak{C}})}^b_{\bar{\nu}} =  v^a_{\bar{\mu}}  \frac{\D}{\D y^a_{\bar{\mu}}} {(j^k \hat{\Xi}_\mathfrak{C})}^b_{\bar{\nu}} \] where $\bar{\mu}$ is a multi-index of length $0\leq \abs{\bar{\mu}}\leq k$.}


\DIM{If we have a gauge-natural bundle $\mathfrak{B}(P)$ with a system of local coordinates $(x^\mu, p^A)$, given the gauge-natural lift $\Hat{\Xi}_\mathfrak{B}$ of any infinitesimal generator $\Xi$ of principal automorphisms of $P$ with local coordinate representation
\[\Hat{\Xi}_\mathfrak{B}= \Xi^\mu \frac{\D}{\D x^\mu}+ \Hat{\Xi}_\mathfrak{B}^A \frac{\D}{\D p^A},\]
then the lift $\Hat{\Xi}_{V\mathfrak{B}}$ on the vertical bundle of $\mathfrak{B}$, where we use coordinates $(x^\mu, p^A, \varepsilon^A)$, has the following local representation 
\[\Hat{\Xi}_{V\mathfrak{B}}= \Xi^\mu \frac{\D}{\D x^\mu}+ \Hat{\Xi}_\mathfrak{B}^A \frac{\D}{\D p^A} + \varepsilon^B \frac{\D \Hat{\Xi}_\mathfrak{B}^A}{\D p^B} \frac{\D}{\D \varepsilon^A}.\]
Now plug in $\mathfrak{B}(P)= J^k \mathfrak{C}(P)$ and, thanks to the isomorphism $V (J^k \mathfrak{C}(P))\approx J^k (V \mathfrak{C}(P))$, one gets the thesis.}



\PROP{If $L$ is a variationally gauge-natural (local) variational morphism then the gauge-natural morphism $\de L$ introduced in formula \eqref{deltaL} is variationally gauge-natural, too.\label{gndel}}

\DIM{
Let us introduce a fibered coordinate system $(x^\mu, y^a)$ on the gauge-natural configuration bundle $\mathfrak{C}(P)$. On $J^k \mathfrak{C}(P)$ we can naturally induce the system of fibered coordinates $(x^\mu, y^a_{\bar{\nu}})$ where $\bar{\nu}$ is a multi-index of length $0\leq \abs{\bar{\nu}}\leq k$.

For a $k$-th order Lagrangian and for any section $X$ of the vertical bundle $V\mathfrak{C}(P)$ we have

\[<\de L\,|\, j^k X> = \frac{\D L}{\D y^a_{\bar{\nu}}}X^a_{\bar{\nu}}.\]

Let us adopt the same notation of the previous Lemma for the lifts of infinitesimal generators of automorphisms of $P$ to the configuration bundle and its vertical bundle.


Furthermore let $(r,s)$ be the order of $\mathfrak{C}$, so that the order of $J^k\mathfrak{C}$ is at most $(r+k,s+k)$.

The Lagrangian $L:J^k\mathfrak{C}\map \Lambda^m T^\ast M$ is variationally gauge-natural so that  a morphism
$\al: J^{k-1} \mathfrak{C}(P) \map  \big(J^{r+k-1}\text{IGA}(P)\big)^\ast\otimes V\Lambda^{m-n}T^\ast(M)$ exists such that

\[\pi_2  \Lie_\Xi \mathbb{M}' =  \text{Div } \Big( \pi_2 <\al\;|\;j^{m-1}\Xi> \Big)=\text{Div } \Lambda. \]
having called $\Lambda$ the morphism $\Lambda=\pi_2 <\al\;|\;j^{r+k-1}\Xi>$; let $\Lambda^\mu$ be its components with respect to the decomposition $\Lambda= \Lambda^\mu \,ds_\mu $.

We have in coordinates:
\[ \frac{\D L}{\D y^a_{\bar{\nu}}} d_{\bar{\nu}} \Lie_\Xi  y^a = d_\mu (L \Xi^\mu)  +  d_\mu \Lambda^\mu\]
which is equivalent to 

\begin{equation} - \frac{\D L}{\D x^\al} \Xi^\al - \frac{\D L}{\D y^a_{\bar{\nu}}} {(j^k \hat{\Xi}_\mathfrak{C})}^b_{\bar{\nu}} = L d_\mu \Xi^\mu  + d_\mu \Lambda^\mu \label{gnl}\end{equation}
Thanks to Lemma \ref{lemma2} we can notice that if the order of $\mathfrak{C}(P)$ is $(r,s)$ then the order of $V\mathfrak{C}(P)$ is $(r+1,s+1)$.

Gauge-naturality of $\de L: J^k \mathfrak{C}(P) \map (J^k V\mathfrak{C}(P))^\ast \otimes
\Lambda^m T^\ast M $ means that  there exists a morphism $\B: J^{k-1} \mathfrak{C}(P) \map  (J^{k-1} V\mathfrak{C})^\ast \otimes  \big(J^{r+k}\text{IGA}(P)\big)^\ast\otimes V\Lambda^{m-n}T^\ast(M)$ such that

\[\pi_2 < \Lie_\Xi \mathbb{M}'\:|\: j^k X > =  \text{Div } \Big( \pi_2 \Big<<\B\;|\;j^{r+k}\Xi>  \:\Big|\: j^{k-1} X \Big>\Big). \]  




Let us then compute $< \Lie_\Xi \mathbb{M}'\:|\: j^h X >$. We have (both multiindices $\bar{\nu}$ and $\bar{\mu}$ have length $0\leq \abs{\bar{\nu}}=\abs{\bar{\mu}}\leq k$).

\begin{gather*}\pi_2\,< \Lie_\Xi \mathbb{M}'\:|\: j^k X > =\left\{
 X^a_{\bar{\mu}} \frac{\D}{\D y^b_{\bar{\nu}}}\frac{\D L}{\D y^a_{\bar{\mu}}} d_{\bar{\nu}} \Lie_\Xi y^b - d_\al \left[\left( \frac{\D L}{\D y^b_{\bar{\nu}}} X^b_{\bar{\nu}} \right) \Xi^\al \right] + \frac{\D L}{\D y^b_{\bar{\nu}}} d_{\bar{\nu}} \Lie_\Xi  X^b \right\} \;ds=\\
=\left\{ - X^a_{\bar{\mu}} \left[ \frac{\D}{\D y^a_{\bar{\mu}}} \frac{\D L}{\D x^\al} \Xi^\al + \frac{\D}{\D y^a_{\bar{\mu}}}\frac{\D L}{\D y^b_{\bar{\nu}}} {(j^k \hat{\Xi}_\mathfrak{C})}^b_{\bar{\nu}}\right] - \frac{\D L}{\D y^b_{\bar{\nu}}} d_\al \left(  X^b_{\bar{\nu}}  \Xi^\al \right) + \frac{\D L}{\D y^b_{\bar{\nu}}} d_{\bar{\nu}} \Lie_\Xi X^b \right\} \;ds. \end{gather*}
Integrating by parts the first two addenda and applying \eqref{gnl} we get


\[\begin{aligned}
\pi_2\,< \Lie_\Xi \mathbb{M}'\:|\: j^k X > =&
\left\{ X^a_{\bar{\mu}}  \frac{\D}{\D y^a_{\bar{\mu}}}\left[ L d_\al \Xi^\al + d_\al \Lambda^\al \right] + \frac{\D L}{\D y^b_{\bar{\nu}}} X^a_{\bar{\mu}}  \frac{\D}{\D y^a_{\bar{\mu}}} {(j^k \hat{\Xi}_\mathfrak{C})}^b_{\bar{\nu}} +\right.\\
&\left.- \frac{\D L}{\D y^b_{\bar{\nu}}} X^b_{\bar{\nu}} d_\al \Xi^\al -  \frac{\D L}{\D y^b_{\bar{\nu}}} \Xi^\al d_\al X^b_{\bar{\nu}} +\frac{\D L}{\D y^b_{\bar{\nu}}}
d_{\bar{\nu}} \Lie_\Xi X^b\right\} \;ds=\\
=&\left\{\frac{\D L}{\D y^b_{\bar{\nu}}} X^a_{\bar{\mu}}  \frac{\D}{\D y^a_{\bar{\mu}}} {(j^k \hat{\Xi}_\mathfrak{C})}^b_{\bar{\nu}} - \frac{\D L}{\D y^b_{\bar{\nu}}}
{(j^k \Hat{\Xi}_{V\mathfrak{C}})}^b_{\bar{\nu}} + X^a_{\bar{\mu}}  \frac{\D}{\D y^a_{\bar{\mu}}}\left(d_\al \Lambda^\al \right) \right\} \;ds.
\end{aligned}\]
Thanks to Lemma \ref{lemma2} the first two addenda cancel, while thanks to Lemma \ref{lemma1} the argument of the derivative in the third addendum is the divergence of the morphism $\de \Lambda$ with local expression 
\[ <\de \Lambda\;|\;j^{k-1} X > = \left( X^a_{\bar{\mu}}  \frac{\D \Lambda^\al}{\D y^a_{\bar{\mu}}}  \right)\; ds_\al. \]
Thus we have
\[ \pi_2 \Big<<\B\;|\;j^{r+k}\Xi>  \:\Big|\: j^{k-1} X \Big>= <\de \Lambda\;|\;j^{k-1} X >\]
and $\de L$ is variationally gauge-natural.}

\THEO{\label{gnboundary}The volume part of a variationally gauge-natural (local) variational morphism is gauge-natural (and thence global).}
\DIM{Let $P\map M$ be a principal bundle, $\mathfrak{C}(P)$ a gauge-natural bundle and $\mathfrak{F}(P)$ a gauge-natural vector bundle. Let $\mathbb{M}$ be a gauge-natural morphism
\[\mathbb{M}: J^k\mathfrak{C}(P)\map (J^h\mathfrak{F}(P))^\ast \otimes_{J^h\mathfrak{C}} \Lambda^m T^\ast M\]
that for all $V\in \Gamma(\mathfrak{F}(P))$ splits into
\[
<\mathbb{M}\:|\:j^h V > = <\mathbb{V}\:|\: V > + \text{ Div}<\mathbb{B}
\:|\:j^{h-1} V >.\]
with
\[ \begin{aligned}
{}&\mathbb{V}\equiv \mathbb{V}(\mathbb{M})\: : J^{h+k} \mathfrak{C}(P)   \map
[\mathfrak{F}(P)]^\ast \otimes_{\mathfrak{C}}\Lambda^{m}T^\ast M\\ &\mathbb{B}\equiv
\mathbb{B}(\mathbb{M},\ga)\:  : J^{h+k-1} \mathfrak{C}(P)   \map (J^{h-1}
\mathfrak{F}(P))^\ast
\otimes_{J^{h-1}\mathfrak{C}}\Lambda^{m-1}T^\ast M.
\end{aligned}\]


For any $1$-parameter family of local automorphism $\Psi_s$ of $P$ and for all $V\in \Gamma(\mathfrak{F}(P))$ we have  
\[ \Psi_s^\star <\mathbb{M}\:|\:j^h V>   = \Psi_s^\star  <\mathbb{V}\:|\: V > + 
\Psi_s^\star \left[\rm{Div}<\mathbb{B}\:|\:j^{h-1} V > \right] \]

As it happens whenever we consider a natural bundle on $M$ as gauge-natural on any $P\map M$ the gauge-natural lift on $\Lambda^{m}T^\ast M$ of any gauge transformation coincides with the natural lift of the diffeomorphism onto which the gauge transformation projects, so that if $\Psi_s=(\phi_s, \psi_s)$ then  $\Lambda^m T^\ast(\Psi_s)= \Lambda^m T^\ast(\phi_s)$.
If computed on a section, the divergence coincides with the exterior differential of forms (see Definition \ref{Div}). Accordingly, as the push-forward along a diffeomorphism commutes with the exterior differential we have the following splitting

\[\Psi_s^\star <\mathbb{M}\:|\:j^h V>  = <\Psi_s^\star \mathbb{V}\:|\:\Psi_s^\star V > + \text{ Div} \left[ \Psi_s^\star <\mathbb{B}\:|\:j^{h-1} V > \right]. \]


By variational gauge-naturality of $\mathbb{M}$ we also have a $1$-parameter family of morphisms $\{\al_s\}$ such that
\begin{align*}
\Psi_s^\star <\mathbb{M}\:|\:j^h V> & = <\mathbb{M}\:|\: \Psi_s^\star j^h V> +  \text{ Div} <\al_s \:|\: \Psi_s^\star (j^{h-1} V)> \\
& = <\mathbb{V}\:|\: \Psi_s^\star  V > +
\text{ Div}<\mathbb{B}+\al_s \:|\:\Psi_s^\star ( j^{h-1}V) >.
\end{align*}


Thanks to the uniqueness of the volume part of the splitting of a variational morphism we can conclude
\[ \Psi_s^\star \mathbb{V} = \mathbb{V} \]
that ensures gauge-naturality of $\mathbb{V}$.}





\subsection{Gauge-natural variational calculus with parametrized variations}

\DEF{\label{problem}A gauge-natural variational problem with parametrized variations is defined by 
the set $(\mathfrak{C}(P),L, \mathfrak{F}, \mathbb{P}, \mathbb{J},\bar{\om})$ of the following objects:
\begin{enumerate}
\item a gauge-natural configuration bundle $\mathfrak{C}(P)\stackrel{\pi}{\map}M$ of order $(r,s)$
with  structure
$G$-bundle $P\stackrel{p}{\map}M$;
\item a variationally gauge-natural (local) Lagrangian morphism $L$ of order $k$;
\item a vector bundle $F\stackrel{\pi_F}{\map}\mathfrak{C}(P)$ such that the 
composite projection
$F\stackrel{\pi\circ\pi_F}{\map}M$ is a gauge-natural bundle $\mathfrak{F}(P)$ of order $(p,f)$ called {\it bundle of parameters};
\item a gauge-natural parameterizing morphism $\mathbb{P}:  J^1 \mathfrak{C}(P) \map (J^q \mathfrak{F}(P))^\ast\otimes_{J^q\mathfrak{C}(P)} V\mathfrak{C}(P)$ ($q\in\{0,1\}$);
\item a gauge-natural morphism $\mathbb{J}: J^{1} \mathfrak{C} \map (J^{r-q}\text{IGA}(P))^\ast \otimes_{J^1 \mathfrak{C}} \mathfrak{F}(P)$  such that we have $\big< \mathbb{P}\;|\; j^q <\mathbb{J}|j^{r-q} \Xi > \big>\circ \:j^1\si  = \Lie_\Xi \si $;
\item a morphism $\bar{\om} :J^{k}\mathfrak{C}(P) \map \mathcal{C}(M)\times_M 
\mathcal{C}(P)$ that
associates to any configuration a couple $(\gamma, \om)$ where $\gamma$ is a linear connection on $M$
and $\om$ is a principal connection on $P$.
\end{enumerate}}

Let us remark that the connection $\ga$ is needed to construct the $\mathbb{P}$-Poincar\'e -Cartan  morphism $\mathbb{F}(L, S, \mathbb{P}, \ga)$ only if $k+l>2$, otherwise this requirement can be dropped, while the connection $\om$ on $P$ will be needed in every case to distinguish horizontal and vertical gauge symmetries (as we will see in a while).  

\THEO{A gauge-natural variational problem with parametrized variations  $(\mathfrak{C}(P),L,\linebreak \mathfrak{F}, \mathbb{P}, \mathbb{J})$ leads to gauge-natural (global) Euler-Lagrange equations.}
\DIM{According to the splitting
\[\Big< <\de L\,|\,j^k \mathbb{P}'>\,\Big|\,
j^{l+k}\epsilon\Big>=  <\mathbb{E}\,|\,\epsilon>+ \text{ Div}
<\mathbb{F}\,|\,j^{l+k-1}\epsilon>,\]
the Euler-Lagrange equations of a gauge-natural variational problem with parametrized variations arise as the boundary part of a variationally gauge-natural variational morphism; in fact $\de L$ is variationally gauge-natural by Property \ref{gndel}, and so is $\mathbb{P}$ by hypothesis (hence also its jet prolongation). Their contraction is thence gauge-natural by definition.  
Thanks to Property \ref{gnboundary} we can conclude that the equations are gauge-natural.}

\bigskip

Let us now remark that according to the fact that the Lagrangian is variationally gauge-natural, every gauge-natural lift on $\mathfrak{C}(P)$ of an infinitesimal generator $\Xi\in\Gamma(\text{IGA}(P))$ of automorphisms of $P$ (or, in a more physical language, every gauge transformation) turns out to be a symmetry of our variational problem. With the help of the other requirements of Definition \ref{problem} we are able to associate to any of these gauge symmetries a gauge invariant \<<N\"other'' conserved current according to the the rule that follows.



\THEO{{\bf-N\"other theorem-} Let us consider a gauge natural variational problem with parametrized variations $(\mathfrak{C}(P),L, \mathfrak{F}, \mathbb{P}, \mathbb{J})$ (orders are as in Definition \ref{problem}) such that
\[\pi_2  \Lie_\Xi  L =  \text{Div } \Big( \pi_2 <\al\;|\;j^{r+k-1}\Xi> \Big)\]
 The unique fibered morphism (momentum  map)
\[\mathcal{E}: J^{2k+l+s-1}\mathfrak{C}(P)  \map J^{r-q-1}\text{IGA}(P)\otimes \Lambda^{n-1}T^\ast M\]
such that for all $\si \in \Gamma(\mathfrak{C}(P))$ and for all $\Xi\in\Gamma(\text{IGA}(P))$ one has 
\begin{multline*} <\mathcal{E}\;|\; j^{r-q-1} \Xi>\circ j^{2k+l+s-1}\si =\\= \Big(<\mathbb{F}\,|\,j^{l+k-1}\mathbb{J}\circ \Xi>- Tp\,\Xi \lrcorner L -  \pi_2 <\al\;|\;j^{r+k-1}\Xi>\Big)\circ j^{2k+l+s-1}\si \end{multline*}
associates to any couple $(\si, \Xi)$ formed by a section $\si\in \Gamma (\mathfrak{C}(P))$ and an infinitesimal generator of principal automorphisms $\Xi\in \Gamma(\text{IGA}(P))$ a current (i. e., a $(n-1)$-form) that is conserved (closed) on-shell.
Moreover the morphism $\mathcal{E}$ is gauge-natural (global).}

\DIM{By gauge-naturality of $L: J^k \mathfrak{C}\map \Lambda^m T^\ast M$ one can find a local morphism $\Lambda: J^{k-1} \mathfrak{C} \map V\Lambda^{m-1} T^\ast M$ such that
\[\pi_2  \Lie_\Xi L = \text{Div}\,( \pi_2 <\al\;|\;j^{r+k-1}\Xi> ).\]

\[\begin{aligned} \pi_2 \Lie_\Xi L &= <\de L \,| \,j^k \Lie_\Xi \si > -\text{ Div}\, (Tp\Xi \lrcorner L)  =\\
&= \Big< <\de L\,|\,j^k \mathbb{P}'>\,\Big|\,
j^{l+k}<\mathbb{J}\;|\; j^{r-q}\Xi>\Big> -\text{ Div}\, (Tp\Xi \lrcorner L)=\\
&=\Big<\mathbb{E}\,\Big|\,<\mathbb{J}\;|\; j^{r-q}\Xi>\Big>+ \text{ Div}\Big<\mathbb{F}\,\Big|\,j^{l+k-1}<\mathbb{J}\;|\; j^{r-q}\Xi>\Big>-\text{ Div}\, (Tp\Xi \lrcorner L). \end{aligned}\]
Thence
\begin{multline*}- \Big<\mathbb{E}\,\Big|\,<\mathbb{J}\;|\; j^{r-q}\Xi>\Big> =\\= \text{ Div} \Big<\mathbb{F}\,\Big|\,j^{l+k-1}<\mathbb{J}\;|\; j^{r-q}\Xi> \Big> -\text{ Div}\, (Tp\Xi \lrcorner L) - \text{Div}\, (\pi_2 <\al\;|\;j^{r+k-1}\Xi> )\end{multline*}
so
\begin{equation} - \Big<\mathbb{E}\,\Big|\,<\mathbb{J}\;|\; j^{r-q}\Xi>\Big> = \text{ Div} <\mathcal{E}\;|\; j^{r-q-1} \Xi>. \label{KKKJ}\end{equation}
While from the definition of $\mathcal{E}$ one can hardly argue how many derivatives of $\Xi$ will appear in its final expression (cancellations may arise!) from the latter  identity (that holds off-shell) we can say that $\Xi$ can enter with its derivatives up to the order $r-q-1$.
If $\si$ is a solution of the corresponding Euler-Lagrange equations then we have
\[d \left[\Big(\,\Big<\mathbb{F}\,\Big|\,j^{l+k-1}<\mathbb{J}\;|\; j^{r-q}\Xi>\Big>- Tp\Xi \lrcorner L - \pi_2 <\al\;|\;j^{r+k-1}\Xi> \Big)\circ\,j^{2k+l+s-1}\si\right]=0.\]
To prove gauge-naturality of $\mathcal{E}$ let us notice that identity \eqref{KKKJ} holds; thence, as the push-forward and the exterior differential of forms do commute, it is sufficient to prove gauge-naturality of the left hand side.
The morphism $\mathbb{E}$ is gauge-natural by Property \ref{gnboundary}, and it is contracted on $\mathbb{J}$ that is gauge-natural by hypothesis; thus the thesis follows.}


In the natural case we were able to construct N\"other currents related to diffeomorphisms, and their integrals on $(m-1)$-surfaces were linked to the energy-momentum of the system.
In the gauge-natural case we cannot any longer lift diffeomorphisms of $M$, but according to \cite{lo}, if on $P$ we have a connection gauge-naturally derived from fields, for any infinitesimal generator of principal automorphisms we can define the horizontal part with respect to this connection, and compute the conserved N\"other currents relative to it. This should be regarded as the density of energy momentum in a gauge-natural variational principle also in presence of a parametrization relative to a constraint.



\section{Constrained variational calculus and vakonomic field theories}
\label{vak}
Let us now apply the previously developed formalism to field theories with constraints within the vakonomic approach.
The non-holonomic technique can be studied within the same formalism too, but with a different characterization of admissible variations; this case will be considered in a forthcoming paper.

\subsection{Vak-criticality} \label{1}
The definitions we will use to implement the principle of constrained 
least action
are a generalization of the ones given by Arnold and others in 
\cite{arnold-vak}
in the case of Vakonomic Mechanics. We will abandon their line when they
introduce Lagrange multipliers to characterize critical sections.




\DEF{Let $C\stackrel{\pi}{\map} M$ be the configuration bundle. A {\it constraint} of order $p$ and codimension $r$ is a submanifold $S\subset J^p C$ of codimension $r$ that by
$\pi^p_{p-1}$ projects onto the whole $J^{p-1} C$.}



\DEF{A configuration $\si\in\Gamma(C)$ is said to be {\it admissible} 
with respect
to $S$ if its $p^{th}$-order jet prolongation lies in S. The space of admissible
configuration with respect to $S$ is
\[ \Gamma_S(C)= \{\si\in\Gamma(C)\/ \im (j^p\si) \in S  \}.\] }




\DEF{Given a compact submanifold $D\stackrel{cpt}{\subset} M$, a {\it vak-admissible variation} (at order $k$) of an admissible configuration $\si\in
\Gamma_S(C)$ is a smooth $1$-parameter family of sections $\{\si_\ve\}_{\ve\in ]-1,1[}\subset
\Gamma (\pi ^{-1} D)$ such that
\begin{enumerate}
\item $\si_0 =\si|_D$
\item $\fa \ve \in ]-1,1[,\quad j^{k-1}\si_\ve|_{\D D}= j^{k-1}\si|_{\D D} $
\item $\frac{d}{d \ve}j^p \si_\ve |_{\ve=0} \in J^p VC \cap TS$. \label{tre}
\end{enumerate} }



\DEF{The set $\{C, L, S\}$ where $C\stackrel{\pi}{\map}M$ is a 
configuration bundle, $L$ is a Lagrangian on $C$ and $S$ is a 
constraint is called a \<<constrained variational problem''.}

\DEF{We say that an admissible section $\si\in \Gamma_S(C)$ is {\it 
vakonomically critical} (or vak-critical) for the variational problem $\{C, L, S\}$ if
$\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M$ for any vak-admissible variation
$\{\si_\ve\}_{\ve\in ]-1,1[}\in
\Gamma (\pi ^{-1} D)$ we have
\[\left.\frac{d}{d \ve } \int_D L \circ j^k
\si_\ve \right|_{\ve =0}=0. \] }


An equivalent infinitesimal condition is that \[\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\, \fa V\in VC\,
\text{  s. t. } j^p V \in TS\text{ and }j^{k-1} V|_{\D 
D}=0,\quad\int_D<\de L\:|\:
j^k V>
\circ j^k \si =0 \] where $\de L$ is the fibered (variational)
morphism defined in \eqref{deltaL}.


\subsection{Parametrized variations and vakonomic criticality}
In order to turn the vak-criticality condition into a differential equation, the classical strategy (at least in Mechanics) is to introduce Lagrange multipliers (see \cite{arnold-vak}).
Here we try to profitably use a suitable parametrization of the set of constrained variations. This idea was first formally developed by Fernandez, Garcia and Rodrigo in the very interesting paper \cite{fgr}. 

\DEF{Let $C\stackrel{\pi}{\map}M$ be the configuration bundle.
A {\it parametrization}
\[\mathbb{P}_S:  J^s C \map (J^l E)^\ast\otimes_{J^sC} VC\]
of order $s$ and rank $l$
($s\geq l$ is required) of the set of constrained variations is said to be {\it vakonomically adapted} to the constraint $S\subset J^pC$ if for all $ \varepsilon\in\Gamma(E)$ and $\si\in \Gamma_S(C)$
the vertical vector field
$j^p (<\mathbb{P}\,|\,j^l \varepsilon>\circ j^s \si)\in TS$.
}

\DEF{A parametrization $\mathbb{P}_S:J^s C \map (J^l E)^\ast\otimes_{J^sC} VC$
vak-adapted to a constraint $S$ is said to be {\it faithful on $\si\in \Gamma_S(C)$ to $S$} if for all $V\in VC \text{ such 
that both } j^p (V \circ\si) \in
TS$ and $j^{k-1} (V \circ\si)|_{\D D}=0$ hold, there exist a section 
$\varepsilon\in\Gamma(E)$ such that $<\mathbb{P}\,|\,j^l
\varepsilon>\circ j^s \si = V$ and $j^{k-1+l} (\varepsilon\circ\si)|_{\D D}=0$}

The fundamental problem of the existence of a (possibly faithful) parametrization vakonomically adapted to a constraint $S$ has not yet been studied in general and will not be faced here. For the moment we
limit ourselves to consider a given specific parametrization as
a part of the variational problem, deferring the study of the general case to
further investigations. The same was done in all the previous papers 
on this topic (see e.g. \cite{fgr}).

\bigskip

Once we have a vak-adapted parametrization $\mathbb{P}_S$ we can study $\mathbb{P}_S$-criticality, constructing, as we have shown in Section \ref{P}, the relevant $\mathbb{P}_S$-Euler-Lagrange equations.

It is important to remark that even having defined the Lagrangian 
on the whole configuration bundle, the first variation formula arising from it does not
depend on the value of the Lagrangian outside the constraint. In fact 
if one has a
Lagrangian $ \hat{L}: J^k C \map \wedge^m \, T^\ast M$ such that
$\hat{L} = L +N$ with $N$ proportional to the equation of the constraint $S$, then on the constraint $S$ it automatically holds $<\de N \:|\: 
j^k V>\circ
j^k \si =0$ for all
$V\in VC\,
\text{  s.t. } j^p V \in TS$ and for all $\si \in \Gamma_S(C)$ therefore the
addendum $N$ does not contribute to the first variation formula, 
neither in the field
equation nor in the boundary part.

The link between vak-criticality and $\mathbb{P}_S$-criticality is given by the following Proposition.




\PROP{\label{mot}Let $\si\in \Gamma_S(C)$ be a vakonomically critical section 
for the constrained variational problem
$\{C, L, S\}$; then for any adapted parametrization $\mathbb{P}_S$ $\si$ is $\mathbb{P}_S$-critical.}
\DIM{We have
\begin{gather*}
\si\in \Gamma_S(C) \text{ is  critical}\\
\Updownarrow \\
\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\; \fa \text{ adm. var. }
\{\si_\ve\},\quad\left.\displaystyle\frac{d}{d \ve } \int_D L \circ
j^k
\si_\ve
\right|_{\ve =0}=0\\
\Updownarrow \\
\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\, \fa V\in VC\,
\text{  s. t. } j^p V \in TS\text{ and }j^{k-1}\si|_{\D D}=0,\quad\int_D<\de L\:|\:
j^k V>
\circ j^k \si =0\\
\phantom{(a)}\Downarrow \text{(a)}\\
\displaystyle\fa D\stackrel{\text{\tiny{cpt}}}{\subset}M,\; \fa \varepsilon \in
\Gamma(E)\text{ s. t. }j^{l+k-1}\varepsilon|_{\D D}=0 ,\quad\int_D \Big< <\de
L\,|\,j^k \mathbb{P}'>\,\Big|\, j^{l+k}\varepsilon\Big> \circ 
j^{k+s} \si =0\\
\Updownarrow \\
\mathbb{E}\circ j^{2k+l+s}\si=0.
\end{gather*}
Step (a) is not an equivalence because there can be admissible 
infinitesimal variations
vanishing at the boundary with their derivatives up to the desired 
order that do not come
from sections of the bundle of parameters that do vanish on the 
boundary. The last
equivalence holds in force of Stokes's theorem, the vanishing of
$j^{l+k-1}\varepsilon$ on the boundary and
the independence of the generators of $E$. }
\COR{Let $\si\in \Gamma_S(C)$ be an admissible $\mathbb{P}_S$-critical section for 
the constrained variational problem $\{C, L, S\}$ and let 
also $\mathbb{P}_S$ be
faithful to $S$ on $\si$; then $\si$ is vakonomically critical for the 
constrained variational
problem $\{C, L, S\}$.}


\section{Examples: }
\label{es}
To our knowledge, parametrized variational problems were first formally investigated by {Fer-n\'andez}, Garc\'ia and Rodrigo \cite{fgr} in relation with their application to Lagrangian reduction and in particular to Euler-Poincar\'e reduction \cite{epred, lagred, reduction}.
They were already implicitly used in the literature to deal with Vakonomic Mechanics \cite{arnold-vak, garcia-vak} and Relativistic Hydrodynamics \cite{h-e}.
What we want to present here is a gauge-natural example that also helps to clarify the distinction between a vak-critical section of a constrained variational problem and a $\mathbb{P}_S$-critical section, of which we study the equations of motions and the conserved N\"other currents. 

\subsection{A gauge-natural example: charged general relativistic fluids.}
\label{esempio}
A charged general relativistic fluid can be thought as a congruence 
of curves filling  a
causal domain $D\subseteq M$, each of them carrying some rest mass and 
charge, being source of gravity and of electromagnetic interaction.


Our kinematical description is inspired by \cite{h-e}, 
where the gravitational
field is represented by a Lorentzian metric with components $g_{\mu\nu}$, the 
electromagnetic potential by a
connection $A_\mu$ on a principal $U(1)$-bundle $P$ and the fluid 
degrees of freedom are represented by a nowhere vanishing $3$-form $J=J^\mu ds_\mu$ such that 
the unit  timelike vector
$u^\mu=J^\mu /\abs{J}$ is tangent to the flow lines and that 
the volume form
$\sqrt{\abs{g}}\rho=\abs{J}$ represents the matter density in D.
For what concerns the charge density we simply assume that at each spacetime 
point it is proportional  to
the matter density by an \<<elementary charge'' $q$.

An alternative (more common) approach to describe the fluid degrees of freedom (see \cite{taub, kijowski-art, brown}) is to associate to any space-time point $x^\mu$ three scalar fields $R^a(x^\mu)$ $(a=1,2,3)$ identifying the \<<abstract fluid particles''.   
We remark that using the tangent vector to flow lines as 
fluid variable, we loose the direct
kinematical identification between different points of the same flow line. In fact, having a
configuration $J^\mu (x)$, in order to know whether two points of spacetime are connected by the same flow line, we have to
solve the ODE that defines the integral curves of $u^\mu$ with 
initial condition in one of them.

In order to implement conservation of matter we only 
allow for closed $J$, so that for any
closed  $3$-surface $\Si$ in $D$ the flow of $J$ through $\Si$ is zero.
The bundle of configurations is thence
\[ \mathfrak{C}(P) = Lor(M) \times_M \mathcal{C}(P) \times_M \Lambda^3 T^\ast M\] 
that is gauge-natural having $P\map M$ with fiber $U(1)$ as structure bundle.
The field $J$, moreover, is subject to the constraint $S\subset j^1 \Lambda^3 T^\ast M$
represented by the equation $dJ=0$, or locally $d_\mu J^\mu=0$ (we also require $J$ to be time-like with respect to the unknown metric, but this just selects an open set in the configuration bundle, so that the condition is automatically preserved by any infinitesimal variation).


\bigskip

The dynamics of the system is governed by the Lagrangian

\begin{equation}
L = L_{H} + L_{EM}+  L_F + L_{int} \label{L1}\end{equation} with

\[\begin{aligned}
{}&L_H ( g_{\al\B}, \D_\la g_{\al\B}, \D_{\la\omega} g_{\al\B}) = \frac{\sqrt{\abs{g}}}{2\kappa}\: R \, ds\\
& L_{EM} (g_{\al\B}, A_\nu, \D_\si A_\nu) = -\frac{1}{4}\sqrt{\abs{g}}\: F^{\rho\si} F_{\rho\si}\, ds\\
& L_F (J^\mu, g_{\al\B}) = -\sqrt{\abs{g}}\: [\rho\;(1+ e (\rho))]\, ds\\
& L_{int} = q J^\mu A_\mu ds
\end{aligned}\]
where $R$ is the scalar curvature of the metric, $F_{\rho\si}$ are 
the curvature coefficients (field strength) of the connection $A$ (gauge potential) and $e (\rho)$ is a 
generic function of the scalar
$\rho= \sqrt{\frac{g_{\mu\nu}J^\mu J^\nu}{\abs{g}}}$, physically 
interpreted as the internal energy of the fluid.
It gives rise to the pressure $P= \rho^2 \frac{\D e}{\D \rho}$.

The gauge-natural bundle of parameters we introduce is then
\[ \mathfrak{F}(P)= (\pi_{\mathfrak{C}(P)})^\ast V Lor(M) \times_{\mathfrak{C}(P)} (\pi_{\mathfrak{C}(P)})^\ast V\mathcal{C(P)} 
\times_{\mathfrak{C}(P)} (\pi_{\mathfrak{C}(P)})^\ast TM\]
and the parametrization is such that for any section 
$\varepsilon=(\de g^{\mu\nu}, \de A_\mu,
X^\mu)
\in
\Gamma (E)$ and for any configuration $\si \in \Gamma (C)$ we have
\[<\mathbb{P}_S\,|\, j^1 \varepsilon>  = \big(\de g_{\mu\nu}(x^\si, 
g_{\al\B}), \de
A_\mu (x,A_\al),  \Lie_X J^\mu \big)  \]
where $\Lie_X J^\mu$ denotes the formal Lie derivative of $J$, i.e. 
$\Lie_X J^\mu = \nabla_\nu
J^\mu X^\nu - J^\nu \nabla_\nu X^\mu + J^\mu\nabla_\nu X^\nu$.
In this way we are freely varying the gravitational and 
electromagnetic degrees of freedom, while
variations of the fluid variables are taken to be tangent to the 
constraint $S$; in fact for every vector field $X$ and for every admissible configuration $J$ (i.e. such that $\D_\mu J^\mu=0$ holds) we have $\D_\mu \Lie_X J^\mu=0$.

Let us remark that this parametrization is trivially gauge-natural; in fact it partially coincides with the identity and partially with the Lie derivative.

\REMARK{
We want to spend some words to stress that our parametrization is adapted to the constraint $S$, but in general not faithful to it; nevertheless this is exactly what Physics requires.
Varying $J$ according to our prescription is equivalent to drag $J$ along a $1$-parameter family of diffeomorphisms generated by $X$ and this amounts to drag the integral curves of $u^\mu$  and to adjust the density $\rho$ to keep $J$ conserved (see \cite{h-e}).
If we consider a compact subset $D\subset M$ and find a tangent vector $X$ whose flow moves the integral curves of $u^\mu$ also on the boundary of $D$ ($X|_{\D D}\neq 0$) but leaves their tangent vectors fixed ($\Lie_X J^\mu|_{\D D}=0$, as it is possible in some cases), we have that it produces a family of deformed $J$ that are fixed on the boundary and that fulfill conservation of matter, but do not come from a vector field that vanishes on the boundary as it would be requested by faithfulness.
Nevertheless, this is exactly what we want to do from the physical viewpoint: when we think of the congruence of curves that represent our fluid and we imagine to vary them without moving the boundary we do not want to move particles, not only tangent vectors.
To support our choice to vary fields along our parametrization, we stress that also in the alternative approach of \<<abstract fluid particles'' variations leave unchanged the particle identification on the boundary.
Solutions of the Euler-Lagrange equations that we are going to find will thence be $\mathbb{P}_S$-critical sections of the parametrized constrained variational problem, without being necessarily vak-critical solutions of the variational problem with the constraint $S$ given by $dJ=0$.} 





The first variation formulae arising from the freely varied 
Lagrangians $L_{H}$ and
$L_{EM}$ are the well known

\begin{equation}\label{H}\big< \de L_{H}\,\big| j^2 <\mathbb{P}_S\,|\, j^1 \varepsilon>\big> = 
\frac{\sqrt{\abs{g}}}{2\kappa}
(R_{\mu\nu} -
\frac{1}{2}R g_{\mu\nu})\de g^{\mu\nu}\, ds + \nabla_\al \big< 
\mathbb{F}^\al_{(H)}\,\big|\, j^1
<\mathbb{P}_S\,|\, j^1 \varepsilon> \big>\end{equation} with
\[\big< \mathbb{F}^\al_{(H)}\,\big|\, j^1
<\mathbb{P}_S\,|\, j^1 \varepsilon> \big> =  \frac{\sqrt{\abs{g}}}{2\kappa}
(g^{\al\la}g_{\rho\si}-\de^\la_{(\rho} \de^\al_{\si)}) \nabla_\la \de 
g^{\rho\si}\,ds\]

where the covariant derivative is relative to the Levi-Civita connection and

\begin{equation}\begin{split}\label{EM}\big< \de L_{EM}\,\big| j^1 <\mathbb{P}_S\,|\, j^1 \varepsilon>\big> 
=& - \sqrt{\abs{g}} (\nabla_\mu
F^{\mu\nu}) \de A_\nu \, ds -   \sqrt{\abs{g}} \nabla_\mu (F^{\mu\nu} \de A_\nu)\,ds\\
&-\frac{\sqrt{\abs{g}}}{2}H^{(EM)}_{\mu\nu}\de g^{\mu\nu}\,ds\end{split}\end{equation} with
\[\sqrt{\abs{g}}\, H^{(EM)}_{\mu\nu}\,ds=-2\frac{\D L_{EM}}{\D g^{\mu\nu}}=  \sqrt{\abs{g}}\,
(F_{\mu\rho}F_{\nu\cdot}^{\phantom{\nu}\rho}-\frac{1}{4}
F_{\al\B}F^{\al\B}g_{\mu\nu})\, ds.\]
 From the parametrized variation of $L_{F}$, by taking into account the definitions
\[\mu = \rho\;(1+ e (\rho)) \hbox{\qquad and \qquad}
P = \rho^2 \frac{\D e}{\D \rho}\]
together with their consequences
\[ \rho \, \frac{\D \mu}{\D \rho} = \mu +P
\hbox{\qquad and \qquad} 
\rho \, \nabla_\nu \left( \frac{\D \mu}{\D \rho} \right) = \nabla_\nu P \]
we have
\[ \big< \de L_{F}\,\big|  <\mathbb{P}_S\,|\, j^1 \varepsilon>\big> = 
-\frac{\D \mu}{\D
\rho}\; u^\cdot_\mu \left( \nabla_\nu J^\mu X^\nu - J^\nu
\nabla_\nu X^\mu +J^\mu
\nabla_\nu X^\nu \right)\, ds.\]
Integrating by parts, we get the first variation formula

\begin{equation}\begin{aligned} \big< \de L_{F}\,\big|  <\mathbb{P}_S\,|\, j^1 
\varepsilon>\big>=&
-\sqrt{\abs{g}}\left[(u^\cdot_\mu u^\nu + \de^\nu_\mu)  \nabla_\nu P + ( 
\mu + P )\: u^\nu \nabla_\nu
u^\cdot_\mu \right] X^\mu \,ds+\\
&- \frac{\mu +P}{\rho} u^\cdot_\al  X^\al (\nabla_\mu J^\mu)+\sqrt{\abs{g}}\nabla_\nu \left[ (\mu + P) (\de_\mu^\nu + u^\cdot_\mu 
u^\nu) X^\mu \right]\, ds+\\
&-\frac{\sqrt{\abs{g}}}{2} H^{(F)}_{\mu\nu} \de g^{\mu\nu}\,ds \end{aligned}\label{F}\end{equation}
with
\[\sqrt{\abs{g}}\,H^{(F)}_{\mu\nu}\, ds = 2\frac{\D L_F}{\D g^{\mu\nu}}= \sqrt{\abs{g}}\,[P g_{\mu\nu} -(\mu + P) u^\cdot_\mu u^\cdot_\nu ]\, ds.\]

Let us compute the first variation formula for the interaction term 
$L_{(int)}$:

\begin{equation}\begin{aligned} \big< \de L_{int}\,\big|  <\mathbb{P}_S\,|\, j^1 
\varepsilon>\big>&=\frac{\D
L_{int}}{\D J^\mu} \Lie_{X} J^\mu  + \frac{\D
L_{int}}{\D A_\nu}
\de A_\nu =\\
&= q A_\mu (\nabla_\nu J^\mu X^\nu - J^\nu \nabla_\nu X^\mu
+J^\mu \nabla_\nu X^\nu)\, ds + q J^\nu \de A_\nu ds=\\
&= q J^\nu \de A_\nu + q J^\mu F_{\mu\nu} X^\nu \, ds+ q \nabla_\nu
(A_\mu J^\mu  X^\nu - A_\mu J^\nu  X^\mu )\,ds
\end{aligned}\label{inter}\end{equation}

The complete set of the equations of motion for the Lagrangian 
\eqref{L1} is thence the following
\[\left\{\begin{aligned}{}&\nabla_\mu J^\mu=0\qquad\quad\text{(constraint)}\\
&R_{\mu\nu} -  \frac{1}{2} R g_{\mu\nu} = \kappa (H_{\mu\nu}^{(EM)} + 
H_{\mu\nu}^{(F)})\\
&\sqrt{\abs{g}}\nabla_\mu F^{\mu\nu} = q J^\nu\\
&(u^\cdot_\mu u^\nu
+ \de^\nu_\mu)  \nabla_\nu P + ( \mu + P )\: u^\nu \nabla_\nu 
u^\cdot_\mu - J^\mu
F_{\mu\nu}=0.
\end{aligned}\right.\]



We are now going to prove that the Lagrangian \eqref{L1} is variationally gauge-natural when restricted to the prolongation of the constraint submanifold $S\subset J^1 \mathfrak{C}(P)$ identified by equation $\nabla_\mu J^\mu=0$.


If $(x^\mu, \theta)$ are coordinates on the structure bundle $P$, an infinitesimal generator of principal automorphisms of $P$ is a vector field $ Y = Y^\mu (x^\al) \D_\mu + y(x^\al) \frac{\D}{\D \theta} \in \Gamma(TP)$
projecting onto $X= T\pi Y = Y^\mu \D_\mu$.
The Lie derivative of a section $\si$ of the gauge-natural configuration bundle  $ Lor(M) \times \mathcal{C(P)}  \times
\Lambda^3 T^\ast M$ with respect to $Y$ is
\[\Lie_Y \si = (\Lie_X g_{\al\B}) \frac{\D}{\D g_{\al\B}}+ (\Lie_Y A_{\nu})\frac{\D}{\D A_{\nu}} +  (\Lie_X
J^\mu) \frac{\D}{\D J^\mu}\]

with coefficients
\[\begin{aligned}
{}&\Lie_X g_{\al\B}= \nabla_\al Y^\cdot_\B + \nabla_\B Y^\cdot_\al\\
{}&\Lie_Y A_{\si} = Y^\rho F_{\rho\si}+ \nabla_\si (y + A_\rho Y^\rho)\\
{}&\Lie_Y F_{\al\B} = Y^\rho \nabla_\rho F_{\al\B} + \nabla_\al Y^\rho
F_{\rho\B}  +\nabla_\B Y^\rho  F_{\al\rho}\\
{}&\Lie_X J^\mu = \nabla_\nu J^\mu Y^\nu - J^\nu \nabla_\nu Y^\mu + J^\mu
\nabla_\nu Y^\nu.
\end{aligned}\]
Thus the configuration bundle is gauge-natural with order $(1,1)$.


A gauge-natural morphism $\mathbb{J}: J^{1} \mathfrak{C} \map (J^{1}\text{IGA}(P))^\ast \otimes_{J^1 \mathfrak{C}} \mathfrak{F}(P)$  such that we have \begin{equation}\big< \mathbb{P}_S\;|\; j^1 <\mathbb{J}|j^1 Y > \big>\circ \:j^1\si  = \Lie_Y \si \label{J}\end{equation} can be defined  by $<\mathbb{J}|j^1 Y>\circ \:j^1\si  = (\Lie_X g_{\al\B}, \Lie_Y A_{\si}, X)$.

\bigskip

Let us now consider the Lie derivative of the morphism $L$ with respect to $Y$. We find:

\[\begin{aligned}
\pi_2\Lie_Y L=
& \frac{\D L}{\D g_{\al\B}} \Lie_X g_{\al\B} + \frac{\D L}{\D \D_\la g_{\al\B}} \D_\la \Lie_X g_{\al\B} + \frac{\D L}{\D \D_{\la\omega} g_{\al\B}} \D_{\la\omega} \Lie_X g_{\al\B}+\\
& + \frac{\D L}{\D A_{\nu}} \Lie_Y A_{\nu} + \frac{\D L}{\D \D_\si A_{\nu}} \D_\si \Lie_Y A_{\nu} + \frac{\D L}{\D J^{\mu}} \Lie_X J^{\mu} -d_\mu (L Y^\mu).
\end{aligned}\]

Analyzing this term by term we have that the identities $\Lie_Y L_H=0$, $\Lie_Y L_{EM}=0$ are well known to be satisfied (see \cite{lo}) and  they can be recasted using the first variation formulae \eqref{H} and \eqref{EM} together with the identity \eqref{J} into 

\begin{equation}\frac{\sqrt{\abs{g}}}{2\kappa}(R_{\mu\nu} -  \frac{1}{2} R g_{\mu\nu}) \Lie_Y g^{\mu\nu}= \nabla_\al \mathcal{E}^\al_H \label{covH}\end{equation}
with
\[\mathcal{E}^\al_H ds_\al= \frac{\sqrt{\abs{g}}}{2\kappa}\left[\left(
\frac{3}{2}R^\al_{\cdot\la} -R\de^\al_\la\right) Y^\la+ 
\left( g^{\B\gamma}\de^\al_\la - g^{\al(\ga}\;\de^{\B)}_\la \right) \nabla_{\B\ga} Y^\la\right] \,ds_\al \]

and into

\begin{equation}- \sqrt{\abs{g}} (\nabla_\mu
F^{\mu\nu}) \Lie_Y A_\nu -\frac{\sqrt{\abs{g}}}{2}H^{(EM)}_{\mu\nu}\Lie_X g^{\mu\nu} = \nabla_\al \mathcal{E}^\al_{EM} \label{covEM}\end{equation}

with
\[\mathcal{E}^\nu_{EM}\, ds_\nu=
 -\sqrt{\abs{g}}\, \left[ g^{\nu\si}\,H^{(EM)}_{\si\mu}\,Y^\mu +F^{\nu\mu} \nabla_\mu ( y + A_\rho Y^\rho)\right] ds_\nu.\]

For the Lagrangian $L_F$ a straightforward calculation enables us to verify that the identity $\Lie_Y L_F=0$ holds too, and that it can be split (thanks to the first variation formula \eqref{F} together with identity \eqref{J}) into the following:

\begin{equation}\begin{aligned} {}&-\sqrt{\abs{g}}\left[(u^\cdot_\mu u^\nu + \de^\nu_\mu)  \nabla_\nu P + ( 
\mu + P )\: u^\nu \nabla_\nu
u^\cdot_\mu \right] X^\mu+\\
&- \frac{\mu +P}{\rho} u^\cdot_\al  X^\al (\nabla_\mu J^\mu) -\frac{\sqrt{\abs{g}}}{2} H^{(F)}_{\mu\nu} \Lie_X g^{\mu\nu} = \nabla_\al \mathcal{E}^\al_{F} \end{aligned}\label{covF}\end{equation}
with
\[\mathcal{E}^\al_F \, ds_\al= -\sqrt{\abs{g}}\,(g^{\al\mu}\, H^{(F)}_{\mu\nu}\, Y^\nu)\,ds_\al. \]

What remains is just to show that the Lagrangian $L_{int}$ is variationally gauge-natural when restricted to the constraint submanifold. In fact we have
\[\begin{aligned}
\pi_2 \Lie_Y L_{int} & =\left[\frac{\D L_{int}}{\D J^\mu} \Lie_X J^\mu + \frac{\D L_{int}}{\D A_\nu}
\Lie_Y A_\nu - \nabla_\al ( Y^\al L_{int})\right] \,ds =\\
&= q\,\big[ A_\mu (\nabla_\nu J^\mu Y^\nu - J^\nu \nabla_\nu Y^\mu
+J^\mu \nabla_\nu Y^\nu) + J^\nu [Y^\rho F_{\rho\nu}+ \nabla_\nu (y + A_\rho Y^\rho)]+\\
&\phantom{=}- A_\nu J^\nu \nabla_\al Y^\al-  Y^\al J^\nu \nabla_\al  A_\nu
-Y^\al  A_\nu \nabla_\al  J^\nu \big] \,ds  =\\
&=q\,\left[ J^\nu \nabla_\nu y \right] \,ds  = q\,\left[\nabla_\nu ( y \, J^\nu) - y \nabla_\nu J^\nu\right] \,ds 
\end{aligned}\]


where the first addendum is a (local) divergence, while the second one vanishes on the constraint.
Thanks to the first variation \eqref{inter} together with identity \eqref{J}, the previous formula can be recasted into the identity 
\begin{equation} q J^\nu \Lie_Y A_\nu + q J^\mu F_{\mu\nu} X^\nu  = \nabla_\al \mathcal{E}^\al_{int} \label{covint}\end{equation}
with
\[\mathcal{E}^\al_{int} = -q (y +A_\mu Y^\mu)J^\al\]
Summing up identities \eqref{covH}, \eqref{covEM}, \eqref{covF} and \eqref{covint} we find that the sum of the left hand sides vanishes if composed with a $\mathbb{P}_S$-critical section, while the current
\[\mathcal{E}^\al \, ds_\al= (\mathcal{E}^\al_{H}+\mathcal{E}^\al_{EM}+\mathcal{E}^\al_{F}+\mathcal{E}^\al_{int}) \, ds_\al\]
is conserved.


\bigskip

If in particular we compute the current $\mathcal{E}^\al \, ds_\al$ relative to the horizontal part $Y_{(\text{hor})}= Y^\mu \D_\mu - A_\rho Y^\rho \frac{\D}{\D \theta}$ of an infinitesimal generator of automorphisms of $P$, what we get is
\[\mathcal{E}^\al_{(\text{hor})} \, ds_\al = \mathcal{E}_{H}^\al \, ds_\al - \sqrt{\abs{g}}\,[g^{\al\mu}\,( H^{(F)}_{\mu\nu} + H^{(F)}_{\mu\nu})\, Y^\nu]\,ds_\al. \]
and this is the conserved current related with the energy-momentum of the system.



Moreover, the N\"other current relative to the vertical part $Y_{(V)}= (y +A_\mu Y^\mu) \frac{\D}{\D \theta}$ is 
\[\mathcal{E}^\al_{(V)} = -\sqrt{\abs{g}}\, F^{\al\mu} \nabla_\mu ( y + A_\rho Y^\rho) - (y +A_\mu Y^\mu)\,q J^\al.\]

Integrating by part the covariant derivative of $(y +A_\mu Y^\mu)$ we can split this vertical current according to

\[\mathcal{E}^\al_{(V)} =(\sqrt{\abs{g}} \nabla_\mu F^{\al\mu} -q J^\al) (y +A_\mu Y^\mu) -\nabla_\mu \big[ \sqrt{\abs{g}}\, F^{\al\mu} ( y + A_\rho Y^\rho)\big] \]

where the first summand vanishes on-shell while the argument of the divergence is called the {\it superpotential} $\mathcal{U}=-\frac{1}{2}\sqrt{\abs{g}} F^{\al\mu} ( y + A_\rho Y^\rho)ds_{\al\mu}$ and it is a $2$-form that is closed even off-shell.
We stress that the interaction Lagrangian does not contribute to the electromagnetic superpotential.


\section*{Conclusions}

Motivated by many physical and mathematical examples, we have studied variational problems with parametrized variations. In particular, starting from the results of \cite{fgr} we have worked on a twofold generalization: by one side we studied parametrized variational problems, no matter from where the parametrization comes from, and we have recovered and ever generalized known results. In a second moment we also focused on the application to vakonomic constraints, for which we have defined and compared the two different concepts of vak-criticality and $\mathbb{P}$-criticality.
A detailed study of nonholonomic field theory could also be based on the same framework and it shall certainly be performed in the future developments. 
Hopefully our unified language will also help to understand how constraints on the derivatives of fields have to be handled in the case of field theories.

For what concerns the second direction of generalization, we have formulated a variational theory for gauge-natural parametrized field theories including conserved currents that provides, in the case of relativistic hydrodynamics of a charged fluid, a non-conventional procedure to define field equations, N\"other currents and superpotentials and that turns out to be computationally much easier then the standard one.
A last observation that deserves to be further investigated is that a $\mathbb{P}$-Euler Lagrange equations arising from the parametrized variational problems is usually not variational in the standard sense. Nevertheless we have a very efficient machinery to study symmetries and conservation laws. Do this apply to any known non-variational equations?


\section*{Acknowledgments}
One of us (E.B.) dedicates this paper to his newborn daughter Lucia. We thanks prof. Raffaele Vitolo and prof. Marco Ferraris for very helpful discussions and personal support. We are also grateful to prof. Jerry Marsden and prof. Tudor Ratiu for a course held at the GNFM-INdAM Ravello summer school 2004 where some ideas began to grew. We acknowledge support from GNFM-INdAM, from MIUR Prin 2005 on \<<{\it Leggi di conservazione e termodinamica in meccanica dei continui e in teorie di campo}'' and from INFN-Iniziativa specifica NA12.



\appendix \section{Variational morphisms and their splittings}
\label{morfismi}
In this Appendix we report the theory of variational morphisms.
The theory is modeled on
\cite{lo} and \cite{fibered}, where complete proofs are given. 
To adapt
them to the constrained case we have to modify a bit the definitions. In
particular, the modified definitions of formal connection and 
variational morphism
seem to appear here for the first time.


\subsection{Variational morphisms}


Variational morphisms are an abstract model of the integrands 
appearing in global variational calculus.
They were introduced (see \cite{vm} for a discussion and some bibliography on alternative approaches) to provide a general framework in which we can 
implement two specific algorithmic procedures based on integration by parts. The first one explicitly construct a
splitting of such integrands into a volume and a boundary covariant part that
generalizes the first variation formula; the second provides superpotentials from the N\"other currents.

 
\DEF{Let $C\stackrel{\pi}{\map}M$ be a configuration bundle over a
$m$ dimensional base and
$E\stackrel{\pi_E}{\map}C$ a vector bundle over $C$. Let $k\geq h$ and 
$n$ be natural
numbers (zero included).

A {\it variational $E$-morphism} is a vertical (projecting onto the identity) bundle morphism
\[ \mathbb{M}: J^k C  \map (J^h E)^\ast {\otimes}_{J^h C}
\pi^\ast \Lambda^{m-n}T^\ast(M). \]
The minimal $k$ is called the {\it
order} of
$\mathbb{M}$, $h$ is the {\it rank}, while $m-n$ is the {\it degree} and $n$
the {\it codegree}.}

\subsection{Operations with (variational) morphisms}

\DEF{Given a vertical fibered morphism $\mathbb{F}=(\text{id}, \Phi)$ between 
two bundles $B$
and
$D$ over the same base $M$ we call $s$-order jet prolongation (or 
$s$-order formal
derivative) of $\Phi$ the unique fibered morphism $j^s \mathbb{F}=(\text{id},
j^s \Phi)$ that makes commutative the following diagram

\[
\begindc{\commdiag}[2]
\obj(20,10)[MB]{$M$}
\obj(20,40)[B]{$B$}
\obj(20,70)[JB]{$J^s B$}
\obj(50,10)[MD]{$M$}
\obj(50,40)[D]{$D$}
\obj(50,70)[JD]{$J^s D$}
\mor{B}{MB}{$\pi$}
\mor{JB}{B}{${\pi}^s_1$}
\mor{D}{MD}{$\pi'$}[\atright,\solidarrow]
\mor{JD}{D}{${\pi'}^s_1$}[\atright,\solidarrow]
\mor(20,9)(50,9){}[\atright,\solidline]
\mor(20,11)(50,11){id}[\atleft,\solidline]
\mor{B}{D}{$\Phi$}
\mor{JB}{JD}{$j^s\Phi$}
\cmor((19,14)(15,28)(19,37)) \pup(14,33){$\si$}[\solidline]
\cmor((19,14)(9,40)(19,67)) \pup(4,40){$j^s\si$}[\solidline]
\cmor((51,14)(55,28)(51,37)) \pup(61,35){$\Phi\circ\si$}[\solidline]
\cmor((51,14)(68,35)(51,67)) \pup(74,55){$j^s(\Phi\circ\si)$}[\solidline]
\cmor((16,36)(17,36)(19,37)) \pup(1,1){}[\solidline]
\cmor((18,34)(18,35)(19,37)) \pup(1,1){}[\solidline]
\cmor((18,64)(18,65)(19,67)) \pup(1,1){}[\solidline]
\cmor((16,65)(17,65)(19,67)) \pup(1,1){}[\solidline]

\cmor((54,36)(53,36)(51,37)) \pup(1,1){}[\solidline]
\cmor((52,34)(52,35)(51,37)) \pup(1,1){}[\solidline]
\cmor((52,64)(52,65)(51,67)) \pup(1,1){}[\solidline]
\cmor((54,66)(53,66)(51,67)) \pup(1,1){}[\solidline]
\enddc\]\label{prol}}


When one prolongs a morphism projecting onto the identity from a jet bundle to another bundle, e.g. $\mathbb{F}: J^p B\map D$, one 
gets a morphism
$j^1 \mathbb{F}: J^1(J^p B)\map J^1 D$. The bundle $J^{p+1} B$ is naturally 
embedded in
$J^1(J^p B)$ by a canonical inclusion $i$. We are often more interested into the map
$j^1 \mathbb{F} \circ i$ rather then in the prolongation itself. We call $j^1 \mathbb{F} 
\circ i$ the first order
{\it holonomic prolongation} of $\mathbb{F}$. In the sequel, when we mention the
prolongation of a morphism starting from a jet bundle we will always mean the
holonomic one.


\REMARK{We warn the reader that by $j^k$ we denote three different concepts of prolongation: prolongation of a section, of a vertical morphism and of a vector field. They are strongly linked, though not identical concepts.
For a discussion of this link we refer the reader to \cite{lo}, but we just remark that every vector field $X$ on a bundle $B$ can be seen as a vertical morphism $X:B\map TB$, and if we compute the first jet prolongation of this morphism we get another morphism $j^h X: J^h B \map J^h TB$ that is not a vector field on $J^h B$ as it should be if thought as the prolongation of a vector field.

If $(x^\mu, y^i_{\bar{\nu}})$ are coordinates on $J^h B$ ($\bar{\nu}$ is a multiindex of length $0\leq\abs{\bar{\nu}}\leq h$), and $(x^\mu, y^i_{\bar{\nu}}, v^\mu_{\bar{\nu}}, v^a_{\bar{\nu}})$ coordinates on $J^1 TB$, the coordinate expression of the prolonged morphism $j^h X$ is $j^h X(x^\mu, y^i_{\bar{\nu}}) =(x^\mu, y^i_{\bar{\nu}},d_{\bar{\nu}}v^\mu,d_{\bar{\nu}}v^a)$.

Luckily enough, for all integers $h$, a global canonical map $r_h: J^h TB \map  TJ^h B $ can be defined (see \cite{modugno, sardanashvily}), whose coordinate expression is $r_h(x^\mu, y^i_{\bar{\nu}}, v^\mu_{\bar{\nu}}, v^a_{\bar{\nu}})= (x^\mu, y^i_{\bar{\nu}},v^\mu, d_{\bar{\nu}} v^i - \sum_{\bar{\al}}y^i_{\bar{\al} +\bar{1}_\mu} d_{\bar{\nu}-\bar{\al}}v^\mu)$ where $\bar{\al}$ is any possible multiindex of length $0\leq\abs{\bar{\al}}<\abs{\bar{\nu}}=h$ and  $\bar{1}_\mu$ is a multiindex with $1$ entry in position $\mu$ and zero elsewhere. The ordinary prolongation $j^h X$ of the vector field $X$ as a vector field on $J^h B$ can be recovered just by composing $r_h$ with the prolonged morphism $j^X$.}



\DEF{Let $B\map M$ be a bundle and $E$ a vector bundle over the same 
base, let $\mathbb{M}$ be a fibered morphism $\mathbb{M}:  B\map
(E)^\ast $ and $\mathbb{P}$ another bundle morphism
$\mathbb{P}:  B \map  E$.

We define {\it formal contraction} \label{contraction}of $\mathbb{M}$ on
$\mathbb{P}$ the unique variational morphism
\[<\mathbb{M}\:|\: \mathbb{P} >   : B \map M\times\mathbb{R} \]
such that
\[\fa \rho \in \Gamma (B),\:\:
<\mathbb{M}\:|\: \mathbb{P}> \circ \rho = <\mathbb{M}\circ \rho \:
| \:\mathbb{P}\circ\rho>\] where $<\,|\,>$ in the right-hand side is the usual
fiberwise contraction between a section of a vector bundle and a section of its
dual. \label{contr}}

\DEF{\label{Div}
Let $\mathbb{M}: J^k C \map \Lambda^{m-n}T^\ast(M) $ be a variational morphism. We define the {\it divergence} of $M$ to be the unique variational morphism
$\rm{Div}(\mathbb{M}) :  J^{k+1} C \map \Lambda^{m-n+1}T^\ast(M) $ such
that for any section $\si \in
\Gamma (C)$ the following holds
\[\rm{Div}(\mathbb{M}) \circ j^{k+1} \si := d(\mathbb{M}\circ j^k \si).\]}


\subsection{Formal connections and fibered connections}
The following definitions generalize the ones given in 
\cite{fibered} to the
settings of constrained variational calculus.
Let us consider a composite projection $E\stackrel{\pi_E}{\map} B\stackrel{\pi}{\map} M$ and the fibered morphism (section)

\[
\begindc{\commdiag}[2]
\obj(20,10)[M]{$M$}
\obj(20,40)[B]{$B$}
\obj(50,40)[E]{$E$}
\mor{B}{M}{} 
\put {$\pi$} at 46 50
\mor{B}{E}{$\mathbb{F}$} 
\mor{E}{M}{} [\atright,\solidarrow]
\put {\mbox{\footnotesize$\pi\circ\pi_E$}} at 68 64
\cmor((19,14)(15,28)(19,37)) \pup(12,26){$\si$}[\solidline]
\cmor((16,36)(17,36)(19,37)) \pup(1,1){}[\solidline]
\cmor((18,34)(18,35)(19,37)) \pup(1,1){}[\solidline]
\cmor((25,12)(42,20)(50,36)) \pup(52,21){$\mathbb{F}\circ\si$}[\solidarrow]
\enddc \]



with $E$ vector bundle on $B$.

Let $(x^\mu, y^i)$ be a coordinate system on $B$ 
and $(x^\mu, y^i,
v^A)$ on
$E$ (with respect to a fiberwise local basis $\{e_A\}$) a local 
representation of
$\mathbb{F}$ is $v^A(x^\mu,y^i) e_A$, while a local 
representation of its first jet
prolongation (as a fibered morphism) $j^1 \mathbb{F}$ is
$v^A(x^\mu,y^i) e_A + d_\mu v^A e_A^\mu$, where
$\{e_A^\mu\}$ is a base of the fiber of $J^1 E\map E$ and
$d_\mu v^A = \D_\mu v^A + \D_i v^A y^i_\mu$ is called the {\it formal 
derivative}
of $\mathbb{F}$.

The transformation rules  of the formal derivatives under a fibered change of
coordinates are not tensorial.

Consider a set
$\{\Gamma^A_{B \mu}(x^\mu,y^i, y^i_\mu)\}_{ 
A,B\in \{1, \cdots, \text{rank} E\},\; 
\mu\in\{1,\cdots , \dim M\} }$
of local coefficients that fit into the expression
\begin{equation}\nabla_\mu v^A =d_\mu v^A + \Gamma^A_{B \mu
}v^B\label{fcd}\end{equation} giving rise to an object at the left 
hand side of the
equalities that under a change of fibered coordinates	
\[\begin{array}{ccc}\left\{\begin{aligned}
{}&x^{\mu'}=x^{\mu'}(x^\mu)\\
&y^{i'}=y^{i'}(x^\mu, y^{i})\\
&y^{i'}_{\mu'}= (J^{-1})^\mu_{\mu'} d_\mu y^{i'}=(J^{-1})^\mu_{\mu'} 
(J^{i'}_\mu
+J^{i'}_i y^i_\mu) \\
&v^{A'}=M^{A'}_A (x^{\mu}, y^{i}) v^A 
\end{aligned}\right.&\qquad&\begin{aligned}
{}&J^{\mu'}_\mu=\frac{\D x^{\mu'}}{\D x^\mu}\\
&J^{i'}_\mu=\frac{\D y^{i'}}{\D x^\mu}, \quad J^{i'}_i=\frac{\D 
y^{i'}}{\D y^i}\\
&M^{A'}_A\in GL(\text{rank} E, \R)\end{aligned} \end{array}\]
transforms according to the rule
\begin{equation}\label{1A}\nabla_{\mu'} 
v^{A'}=(J^{-1})^\mu_{\mu'}\nabla_\mu v^A
M^{A'}_A\end{equation} that are nothing but
the transition functions of the vector bundle $E \otimes_B T^\ast M\map B$.

The resulting transformation law for the coefficients is
\begin{equation} \label{1B}\Gamma^{A'}_{B'{\mu'}} = 
J^\mu_{\mu'}(\Gamma^A_{B \mu}
M_A^{A'} M^B_{B'}  - d_\mu M^{A'}_A M_{B'}^B)\end{equation} It's easy 
to verify that
relations
\eqref{1B} form a cocycle over the manifold
$J^1B$, thus they define the transition functions of an affine bundle 
$FC(E)\map
J^1B$ modeled on the vector bundle $E^\ast \otimes_B E \otimes_B T^\ast M$.


\DEF{A {\it formal connection } on the composite fiber bundle $E\map B\map M$  is a global section of the affine 
bundle $FC(E)$.\label{formalcon}}
Let us consider the bundle $\mathbb{L}(E)\map B$ of linear frames of the vector bundle
$E\stackrel{\pi_E}{\map} B$. Let $r=\text{rank} E$.
$\mathbb{L}(E)$ is a principal $GL(r, \R)$ bundle and the free natural
right action $r: \mathbb{L}(E) \times GL(r, \R) \map \mathbb{L}(E)$ can be defined on it.

Let us call $\mathbb{L}_M(E)$ the bundle $\mathbb{L}(E)\map M$ obtained by the 
obvious composition
of projections. It is no longer principal, nevertheless the 
action $a$ induces
  on it a free right action $a_M$, that can be lifted to a right 
action $j^1 a_M $
on its fist jet extension $J^1 \mathbb{L}_M(E)$. The action $j^1 a_M 
$ is still free and
admits a quotient manifold $\frac{J^1 \mathbb{L}_M(E)}{GL(r, \R)}$ 
that has an affine
bundle structure over the base $J^1B$. The two affine bundles $FC(E)$ and
$\frac{J^1 \mathbb{L}_M(E)}{GL(r, \R)}$ are isomorphic and this can be proved directly by 
showing that they
share the same transition functions, providing a more
intrinsic characterization of the bundle of formal connections.

Consider now the bundle $J^1 E_{J^1B} \stackrel{j^1 \pi_E}{\map} J^1 B$; the
presence of a formal connection on $E$, allows us to define the
global vector bundle morphism $\nabla$ by the following commutative diagram

\[
\begindc{\commdiag}[2]
\obj(20,10)[JB]{$J^1B$}
\obj(20,40)[JE]{$J^1 E_{J^1B}$}
\obj(55,10)[B]{$B$}
\obj(55,40)[E]{$E \otimes_B T^\ast M$}
\mor{JE}{E}{$\nabla$} 
\mor{JB}{B}{${\pi_B}^1_0$} 
\mor{JE}{JB}{} 
\mor{E}{B}{}
\enddc\]

whose local coordinate expression is \eqref{fcd}.

\DEF{Let $\si$ be a section of $J^1 E_{J^1B}$. We call $\nabla 
\circ\si$ the
{\it formal covariant derivative} of $\si$. }


\DEF{A {\it fibered connection} on $E\stackrel{\pi_E}{\map}B$ is a 
couple $(\gamma,
\Gamma)$, where $\gamma$ is a linear connection on $M$ and $\Gamma$ 
is a formal
connection on $E$.\label{fibercon}}

Given a fibered connection on $E$ we can extend the morphism $\nabla$ to $J^1
(E_{J^1B} \otimes T^p_q(M))$ where $T^p_q(M)$ is the algebra of 
$p$-times covariant
and
$q$-times contravariant tensors on $M$ with the obvious tensorization 
procedure,
getting a fibered morphism

\[
\begindc{\commdiag}[2]
\obj(20,10)[JB]{$J^1B$}
\obj(20,40)[JE]{$J^1 (E_{J^1B}\otimes T^p_q(M))$}
\obj(75,10)[B]{$B$}
\obj(75,40)[E]{$E \otimes_B T^p_{q+1}(M)$}
\mor{JE}{E}{$\nabla$} 
\mor{JB}{B}{${\pi_B}^1_0$} 
\mor{JE}{JB}{} 
\mor{E}{B}{}
\enddc\]
that we denote by the same symbol $\nabla$.


\DEF{Let $\si$ be a section of $J^1 (E_{J^1B}\otimes T^p_q(M))$, let 
us call $\nabla
\circ\si$ the {\it formal covariant derivative} of $\si$. }

\DEF{The {\it formal covariant derivative} of a morphism 
$\mathbb{F}:B \map E$ is
the unique fibered morphism $\nabla \mathbb{F}: J^1 B \map E 
\otimes_B T^\ast M$ such
that
\[\fa \rho\in \Gamma (B), \nabla \mathbb{F} \circ j^1\rho = \nabla\circ
j^1 (\mathbb{F} \circ \rho).\]}

A formal connection on a composite fiber bundle $E\map B\map M$ can be constructed from a linear connection $A$ on the vector bundle $E\map B$ and the first jet prolongation $j^1 \si$ of a section of the bundle $B\map M$.
Let $(x^\mu, y^a, v^B)$ be a fibered coordinate system on $E$; the connection $A$ has the coordinate representation \[A= dx^\mu \otimes (\frac{\D}{\D x^\mu} - A^B_{D \mu} v^D \frac{\D}{\D v^B}) + dy^i \otimes (\frac{\D}{\D y^i} - A^B_{D i} v^D \frac{\D}{\D v^B}).\]

The coefficients $ \Gamma^B_{D \mu}= A^B_{D \mu} + A^B_{D i} y^i_\mu$ transform according to \eqref{1B} and thus they glue together into a global formal connection on $E\map B \map M$. 






\subsection{Local expression and reduction of a variational morphism with
respect to a fibered connection}
Fixed a fiberwise basis $\left\{e_A (x),e_A^{\la_1}(x),\cdots , e_A^{{\la_1} \cdots
{\la_h}}(x)\right\}_{ A\in
\{1, \cdots, p\},\;\; i \in \{1, \cdots, h\}, \;\; \la_i \in \{ 1, \cdots,  m
\} }$ of $J^h_x E$ and its dual
  $\left\{e^A
(x),e^A_{\la_1}(x),\cdots , e^A_{{\la_1} \cdots {\la_h}}(x)\right\}$ in $(J^1_x
E)^\ast$, the local expression of a variational morphism
$\mathbb{M}: J^k C   \map (J^h E)^\ast \otimes\Lambda^{m-n}T^\ast(M)$ is the
following

\begin{equation}
\mathbb{M} = \frac{1}{n!}\left( v^{{\mu_1}\cdots  {\mu_n}}_A e^A
+v^{{\mu_1}\cdots {\mu_n}{\la_1}}_A e^A_{\la_1}+ \cdots + v^{{\mu_1}\cdots
{\mu_n}{\la_1} \cdots {\la_h}}_A   e^A_{{\la_1} \cdots {\la_h}}\right)
\otimes ds_{{\mu_1}\cdots {\mu_n}},\label{local1}
\end{equation}

where the indices ${\mu_1}\cdots {\mu_n}$ are  skew-symmetric while the
${\la_1} \cdots {\la_h}$ (if any) are  symmetric and where the
coefficients are functions of the point  $j_x^k \rho \in J^k C$.

\bigskip

Given a fibered connection $(\gamma^\al_{\B\mu}, \Gamma^A_{B\mu} )$ 
we can change
basis on  $J_x^h E$ in a way that a holonomic section $j^h X\in 
\Gamma (J^h E)$ in
the new basis  (called {\it basis of symmetrized covariant derivatives}) has
components

\[\begin{aligned}
{}&\hat{v}^A = v^A (x)\\
&\hat{v}^A_{\la_1} = \nabla_{\la_1}  v^A (x)= d_{\la_1} v^A  +
\Gamma^A_{B{\la_1}} v^B\\ &\vdots\\
&\hat{v}^A_{{\la_1}\cdots {\la_h}} =  \nabla_{(\la_1} \cdots
\nabla_{{\la_n})} v^A (x).\end{aligned}\]



Accordingly, using the dual basis on $(J^h E)^\ast$ we
can define a new coordinate system $(x^\al,
\hat{v}_A^{{\mu_1}\cdots {\mu_n}},  \hat{v}_A^{{\mu_1}\cdots
{\mu_n}{\la_1}}, \hat{v}_A^{{\mu_1}\cdots {\mu_n}{\la_1}\cdots {\la_h}})$
on $(J^h E)^\ast \otimes_{J^hC}\Lambda^{m-n}T^\ast(M)$ such that the local 
expression of
$ \mathbb{M}$ is
\[
\mathbb{M} = \frac{1}{n!} \left( \hat{v}^{{\mu_1}\cdots {\mu_n}}_A
\hat{e}^A  + \hat{v}^{{\mu_1}\cdots {\mu_n}{\la_1}}_A
\hat{e}^A_{\la_1}+ \cdots +  \hat{v}^{{\mu_1}\cdots {\mu_n}{\la_1} \cdots
{\la_h}}_A  \hat{e}^A_{{\la_1} \cdots {\la_h}}\right) \otimes
ds_{{\mu_1}\cdots {\mu_n}}.
\]
We remark that in the previous expression,  as in formula \eqref{local1},
the coefficients  have to be meant as functions of the point $j_x^k
\rho \in J^k C$, and the indices ${\mu_1}\cdots {\mu_n}$ are
skew-symmetric while the ${\la_1}
\cdots {\la_h}$ (if any) are symmetric.

The explicit change of basis and coordinates in the case $h=1$ is
\[\begin{array}{ccc} \left\{\begin{aligned}{}&\hat{e}^A = e^A\\
&\hat{e}^A_\la = e^A_\la + \Gamma^{A}_{B\la} e^B\end{aligned}\right.&
\text{and} &\left\{\begin{aligned}{}&v_A= \hat{v}_A  + \hat{v}_B^\la
\Gamma^{B}_{A\la}\\ &v_A^\la = \hat{v}_A^\la\end{aligned}\right.\end{array}\]

The introduction of a fibered connection can  select a \<<preferred'' kind
of variational  morphism having nice properties when written in the
symmetrized covariant derivatives coordinate system.

\DEF{\label{redu}Let $ \mathbb{M}: J^k C  \map  (J^h E)^\ast
\otimes_{J^hC}\Lambda^{m-n}T^\ast(M)$ be a variational morphism and
$\mathbb{M}_l$ its term of rank $0\leq l \leq h$. The term $\mathbb{M}_l$
is said to be {\it reduced} with respect to the fibered connection
$(\gamma^\al_{\B\mu}, \Gamma^A_{B\mu} )$ if, written in the symmetrized
covariant derivatives coordinate system, it has the coefficients symmetric in
the first $n+1$ upper indices, i. e. if $\hat{v}^{[{\mu_1}\cdots
{\mu_n}{\la_1}] \cdots {\la_l}}_A=0$. The variational morphism
$\mathbb{M}$  is reduced if each one of its terms is reduced.}

Notice that the term of rank zero is always reduced  with respect to any
connection,  having always antisymmetric upper indices and that in the
case of Mechanics ($m=1$) all variational morphisms are reduced with
respect to any connection.

Now we are ready to state the most important results of the  theory, that
justify the name  \<<variational'' for the morphism we have introduced,
providing a sort of \<<first variation formula'' from any variational
morphism. The proofs of the next two Theorems can be found in 
\cite{lo}, but as a
consequence of the minor modifications we introduced here one has to
reinterpret the symbols according to the previous definitions.

\THEO{{\bf-\<<Splitting lemma''-}\label{splitting}
Let $\mathbb{M}: J^k C  \map (J^h E)^\ast
\otimes_{J^hC}\Lambda^{m }T^\ast M$  be a global variational morphism with
codegree $n=0$ and let $h$, $k$ $\in \N$ (zero included). Chosen a fibered
connection $(\ga, \Gamma)$ on $E$ there exist a unique pair $\mathbb{V},
\mathbb{B}$ of variational morphisms
\[\begin{aligned}
{}&\mathbb{V}\equiv \mathbb{V}(\mathbb{M})\: : J^{h+k} C   \map
E^\ast \otimes_C\Lambda^{m}T^\ast M\\ &\mathbb{B}\equiv
\mathbb{B}(\mathbb{M},\ga)\:  : J^{h+k-1} C   \map (J^{h-1}
E)^\ast
\otimes_{J^{h-1}C}\Lambda^{m-1}T^\ast M
\end{aligned}\]
reduced with respect to $(\ga, \Gamma)$ such that $\fa V \in \Gamma(E)$ the
following holds true
\begin{equation}
<\mathbb{M}\:|\:j^h V > = <\mathbb{V}\:|\: V > + \text{ Div}<\mathbb{B}
\:|\:j^{h-1} V >.\end{equation} The variational morphism $\mathbb{V}$ is
called the volume part of $\mathbb{M}$ and $\mathbb{B}$  its boundary
part.}

\THEO{{\bf-\<<Reduction lemma''-} Let $\mathbb{M}: J^k C   \map (J^h
E)^\ast \otimes_{J^h C}\Lambda^{m-n}T^\ast M$  be a global variational
morphism of codegree $n\geq 1$ and let $h$, $k$ $\in \N$ (zero included). 
Chosen a fibered
connection $(\ga, \Gamma)$ on $E$ there exist a unique pair $\mathbb{V},
\mathbb{B}$ of variational morphisms
\[\begin{aligned}
{}&\mathbb{V}\equiv \mathbb{V}(\mathbb{M})\: : J^{h+k} C   \map
(J^h E)^\ast
\otimes_{J^hC}\Lambda^{m-n}T^\ast M\\ &\mathbb{B}\equiv \mathbb{B}(\mathbb{M},\ga)\:
: J^{h+k-1} C  \map (J^{h-1}
E)^\ast \otimes_{J^{h-1}}
\Lambda^{m-n-1}T^\ast M
\end{aligned}\]
reduced with respect to $(\ga, \Gamma)$ such that $\fa V \in \Gamma(E)$ the
following holds true
\begin{equation}
<\mathbb{M}\:|\:j^h V > = <\mathbb{V}\:|\:j^h V > + \text{ Div} <\mathbb{B}\:|\:j^{h-1} V >.\end{equation} 
The variational
morphism $\mathbb{V}$ is called the volume part of $\mathbb{M}$ and
$\mathbb{B}$ its boundary part.
\label{reduction}}

Constructive proofs of these Theorems are given in \cite{lo} where we can find a collection of older results; they are carried on by induction on the rank of the
morphism. If the rank is $1$ then one just needs to integrate by parts and no fibered connection is needed. At any rank they provide an algorithm out of which we can perform explicitly the 
splitting or the reduction.


In both the Theorems the volume part is uniquely defined even if we do
not require it to be reduced, and finally it does not depend on the fibered 
connection.
The boundary parts, on the contrary, are defined modulo a divergenceless term, but the
condition of being reduced with respect to any specific fixed fibered connection 
determines them uniquely (if the rank is $1$ the boundary part is stiill unique and reduced with respect to any fibered connection).

Moreover it was proved \cite{kolarticolo} that the boundary parts depend 
in fact only
on the connection on the base, while the formal connection on $E$ 
reveals itself to be just an
intermediate object useful to explicitly construct the splitting, but 
in the end unessential.
\section{Gauge natural bundles}



\label{GNmaterial}


\DEF{Let $G$ be a Lie group. $\mathfrak{P}^n(G)$ will denote the category of principal $G$-bundles whose base manifold is $n$-dimensional and whose maps are G-bundle maps projecting onto local diffeomorphism between the two bases.}
\DEF{ A covariant functor $\mathfrak{B}$ from the category $\mathfrak{P}^n(G)$ to the category of bundles and bundle morphisms is a {\it gauge-natural functor} if
\begin{enumerate}
\item[a)] for all principal $G$-bundle $P\stackrel{p}{\map}M$, 
$\mathfrak{B}(P)$ is
a bundle with structure group $G$ having the same base $M$ as $P$;
\item[b)] any principal morphism $\Phi: P\map P'$ projecting onto 
$\phi: M\map M$
induces a fibered morphism $\mathfrak{B}(\Phi) : \mathfrak{B}(P) \map
\mathfrak{B}(P')$ also projecting over $\phi$;
\item[c)] for any open $U\subseteq M$ the inclusion
morphism $i: p^{-1}(U) \map P$ is mapped into the inclusion morphism 
$\mathfrak{B}(i):
\mathfrak{B}(p^{-1}(U)) \map\mathfrak{B}(P)$.
\end{enumerate}}

\DEF{A {\it gauge-natural bundle} $GN \stackrel{\ga}{\map} M$ having 
the principal
bundle $P\stackrel{p}{\map}M$ as {\it structure bundle} is the image of $P$ trough a gauge-natural
functor $\mathfrak{B}$.}
Examples of gauge-natural bundles are all natural  bundles (trivial 
case), the bundle of
principal connections $\mathcal{C}(P)$ on a principle bundle $P$, the bundle
$\text{IGA}(P)$ of its Infinitesimal Generators of principal Automorphisms, the  bundle of
spin frames and others (see \cite{lo}).

Notice that jet prolongations of a gauge-natural bundle are 
gauge-natural with the same structure
bundle, and that every composite fibration 
$Z\stackrel{\pi_Z}{\map}Y\stackrel{\pi_Y}{\map}X$
where $Y$ is a gauge-natural bundle with structure bundle $P$ and 
$\pi_Z$ is natural makes
$\pi_Y\circ\pi_Z$ a gauge-natural bundle with structure bundle $P$.

\bigskip

We want to stress that for our purposes, the most relevant property 
of a gauge-natural bundle $\mathfrak{B}(P)$ is the possibility of lifting local
principal automorphisms of the structure $G$-bundle $P$ to local fibered morphisms of $\mathfrak{B}(P)$. We will call \<<{\it gauge transformation}'' on $\mathfrak{B}(P)$ the gauge-natural lift of a local principal automorphism of $P$ and
\<<{\it gauge group}'' the structure group $G$.


The same, via the tangent map, can be done
for infinitesimal generators: an infinitesimal generator of principal automorphisms can be
lifted to a vector field on $\mathfrak{B}(P)$ that will be called its \<<{\it gauge-natural lift}''.



Let us consider a $1$-parameter family of infinitesimal generators of principal automorphisms $\{\Psi_s= (\phi_s, \psi_s)\}$.
It can be proved (see \cite{lo}) that any infinitesimal generator $\Xi\in \Gamma(TG)= \frac{d}{ds}\Psi_s|_{s=0}$ is a right invariant projectable vector field on $P$ and that we can explicitly construct the bundle $\text{IGA}(P)\map M$ whose sections are in one to one correspondence with the infinitesimal generators of such families and with right invariant sections of $TP$. 
Infinitesimal generators of vertical principal automorphisms $\{\Psi_s= (id, \psi_s)\}$ can be identified with sections of a subbundle $\textstyle\frac{VP}{G}\hookrightarrow \text{IGA}(P)$ that is associated to $P\stackrel{p}{\map}M$ by means of the adjoint action of the Lie algebra $\mathfrak{g}$ of the gauge group $G$.


By means of a trivialization of $P$ we can locally define a set $\{\rho_A\}_{A\in\{1\cdots \dim G\}}$ of right invariant vector fields on $P$ that at every point form a basis of $VP$.
Let $(x^\mu, y^a)$ be a fibered system of coordinates on $P$; every infinitesimal generator of principal automorphisms $\Xi$ can be locally written as a right invariant vector field 
\[\Xi (x^\mu, y^a)= \xi^\mu (x^\mu) \frac{\D}{\D x^\mu} + \xi^A (x^\mu)\rho_A(x^\mu, y^a)\]
on $P$.


\DEF{We say that a gauge-natural bundle $\mathfrak{B}(P)$  is of $(r,
s)$-order ($s\leq r$) if the gauge-natural lift is a morphism
\[ \mathbb{L}:\mathfrak{B}(P) \map (J^r \text{IGA(P)})^\ast \otimes_{\mathfrak{B}} T\mathfrak{B}(P) \]
such that if $\Xi$ is vertical (i.e. it is a section of $\textstyle\frac{VP}{G}\hookrightarrow \text{IGA}(P)$), the vector field $\hat{\Xi}_\mathfrak{B} = <\mathbb{L}\;|\; j^r\Xi>$ on $\mathfrak{B}(P)$ is vertical, too, and depends in fact on the derivatives of $\Xi$ only up to the order $s$.}



\DEF{
Let $\Psi= (\phi, \psi)$ be a local principal automorphism of $P$ and 
$\mathfrak{B}(\Psi)=(\phi, \hat{\Psi}_\mathfrak{B})$ be its gauge-natural lift to the gauge-natural bundle
$\mathfrak{B}(P)$. Let $\si$ be a section of $\mathfrak{B}(P)$; we define its {\it push-forward} along $\Psi$ to be the section $\Psi^\star \si = \hat{\psi}_\mathfrak{B} \circ \si \circ \phi^{-1}$.}


\DEF{Let $\Xi$ be the infinitesimal generator of the $1$-parameter family of local principal automorphisms $\{\Psi_s= (\phi_s, \psi_s)\}$; we define the {\it Lie derivative} of a section $\si$ of $\mathfrak{B}(P)$ along $\Xi$ to be the unique section of the pull back bundle $\Lie_\Xi \si\in \Gamma (\si^\star V\mathfrak{B}(P))$ such that
\[ \Lie_\Xi \si = - \frac{d}{ds} \Psi_s^\star \si. \]}
\REMARK{\label{dlm}We can easily prove that if $\hat{\Xi}_\mathfrak{B}$ is the gauge-natural lift of $\Xi$ on $\mathfrak{B}(P)$, and $\Xi$ is the projection of $\Xi$ on $M$, the Lie derivative of a section can be computed trough the following formula
\[\Lie_\Xi \si = T\si \circ \pi \Xi - \hat{\Xi}_\mathfrak{B}.\]
In coordinates, if $(x^\mu,y^i)$ are fibered coordinates on $\mathfrak{B}(P)$ while the lift can be written as $\hat{\Xi}_\mathfrak{B}= \xi^\mu \frac{\D}{x^\mu}+ \hat{\Xi}_\mathfrak{B}^i \frac{\D}{\D y^i}$ one has $\Lie_\Xi \si=\Lie_\Xi y^i \frac{\D}{\D y^i}$, with
\[ \Lie_\Xi y^i= d_\mu y^i(x)  \xi^\mu (x) - \hat{\Xi}_\mathfrak{B}^i(x, y(x)) \]

\bigskip

It also turns out that the Lie derivative operator on sections of the gauge-natural bundle $\mathfrak{B}(P)$ of order $(r,s)$ (where $r\geq s$) can be interpreted as a fibered morphism
\[ \mathbb{D}_\Lie : J^1 \mathfrak{B}(P) \map (J^r \text{IGA(P)})^\ast \otimes V\mathfrak{B}(P)\]
such that for all sections $\si\in\Gamma(\mathfrak{B}(P))$ and for all infinitesimal generator of principal automorphism $\Xi\in \Gamma (\text{IGA}(P))$ one has $< \mathbb{D}_\Lie \;|\; J^r \Xi> \circ\; j^1 \si = \Lie_\Xi \si$. }
Notice that if $\Xi$ is vertical (i.e. it is a section of $\textstyle\frac{VP}{G}\hookrightarrow \text{IGA}(P)$) then $\Lie_\Xi \si$ depends in fact on the derivatives of $\Xi$ only up to the order $s$. 

\REMARK{\label{pi2}When in differential geometry one computes the Lie derivative of a vector field on a manifold $M$ one gets another vector field and so happens for differential forms and tensors. According to our definition, on the contrary, the Lie derivative of a vector field is a section of the vertical bundle $VTM$. To reconcile this apparent contradiction we have to remark that whenever $\mathfrak{B}$ is a vector bundle with base $M$ then  its vertical $V\mathfrak{B}$ is isomorphic (see \cite{kolar}) to the fibered product $\mathfrak{B}\times_M \mathfrak{B}$ and one has a global vertical fibered morphism $\pi_2:V\mathfrak{B}\map \mathfrak{B}$ that realizes the projection onto the second fibered factor.
If $(x^\mu, y^a, v^a)$ is a local coordinate system on $V\mathfrak{B}$ then the map $\pi_2$ acts as follows:
$\pi_2:(x^\mu, y^a, v^a)\associa (x^\mu, v^a).$
If $\si$ is a section of a gauge-natural vector bundle then $\pi_2\Lie_\Xi \si$ would be what traditionally is meant as its Lie derivative, the coordinate computation being identical, but with a slightly different interpretation.
}

\bigskip

Let $P\stackrel{p}{\map}M$ be a principal bundle; let moreover $U\subset M$ 
be open, $(x^\mu, g^a)$ be a coordinate system on $p^{-1}(U)\subset P$ and $\{\rho_A   (x^\mu,
g^a)\}_{A=1\cdots
\dim G}$  a fiberwise right invariant basis of vertical vector 
fields. An infinitesimal
generator of principal automorphisms has the local form $\Xi(x^\mu, 
g^a)= \xi(x)^\mu \D_\mu
+\xi^A(x) \rho_A (x^\mu, g^a)$ (see \cite{lo}). Given a 
principal connection $\om
(x^\mu, g^a)= dx^\mu \otimes (\D_\mu -\om^A_\mu (x) \rho_A(x^\mu, 
g^a))$  we can also split $\Xi$ into a vertical and a horizontal part according to
\[\Xi= \xi^\mu (\D_\mu -\om^A_\mu \rho_A) \oplus (\om^A_\mu \xi^\mu  + 
\xi^A) \rho_A =
\Xi_{(H)}\oplus \Xi_{(V)}.\]

\bibliographystyle{plain}
\bibliography{bibliografia}
\end{document}

pictex.tex
% This is PiCTeX, Version 1.1   9/21/87
 
% CAVEAT: The PiCTeX manual often has a more lucid explanation
%   of any given topic than you will find in the internal documentation
%   of the macros.
 
% PiCTeX's commands can be classified into two groups: (1) public (or
%   external), and (2) private (or internal). The public macros are
%   discussed at length in the manual. The only discussion of the private
%   macros is the internal documentation. The private macros all have
%   names beginning with an exclamation point (!) of category code 11. 
%   Since in normal usage "!" has category code 12, these macros can't
%   be accessed or modified by the general user.
 
% The macros are organized into thematically related groups. For example,
%   the macros dealing with dots & dashes are all in the DASHPATTERN group.
%   The table below shows which macros are in which groups. The table
%   covers all public macros, and many (but not all) of PiCTeX's upper level
%   private macros. Following the table, the various groups are listed
%   in the order in which they appear in the table.
 
% *********************** TABLE OF GROUPS OF MACROS **********************
 
% HACKS:  Utility macros
%    \PiC
%    \PiCTeX
%    \placevalueinpts 
%    \!!loop 
%    \!cfor
%    \!copylist
%    \!ecfor
%    \!etfor
%    \!getnext
%    \!getnextvalueof
%    \!ifempty
%    \!ifnextchar
%    \!leftappend
%    \!listaddon 
%    \!loop
%    \!lop
%    \!mlap
%    \!not
%    \!removept
%    \!rightappend
%    \!tfor 
%    \!vmlap
%    \!wlet
 
% ALLOCATION:  Allocates registers
 
% AREAS: Deals with plot areas 
%    \axis
%    \grid 
%    \invisibleaxes
%    \normalgraphs 
%    \plotheading 
%    \setplotarea
%    \visibleaxes
 
% ARROWS:  Draws arrows
%    \arrow
%    \betweenarrows
 
% BARS:  Draws bars
%    \putbar 
%    \setbars
 
% BOXES:  Draws rectangles
%    \frame
%    \putrectangle 
%    \rectangle
%    \shaderectangleson
%    \shaderectanglesoff
 
% CURVES:  Upper level plot commands
%    \hshade 
%    \plot 
%    \sethistograms
%    \setlinear
%    \setquadratic
%    \vshade
 
% DASHPATTERNS:  Sets up dash patterns
%    \findlength 
%    \setdashes 
%    \setdashesnear
%    \setdashpattern
%    \setdots 
%    \setdotsnear 
%    \setsolid
%    \!dashingoff
%    \!dashingon
 
% DIVISION:  Does long division of dimension registers
%    \Divide 
%    \!divide
 
% ELLIPSES:  Draws ellipses and circles
%    \circulararc 
%    \ellipticalarc 
 
% RULES:  Draws rules, i.e., horizontal & vertical lines
%    \putrule 
%    \!putdashedhline
%    \!putdashedvline
%    \!puthline 
%    \!putsolidhline  
%    \!putsolidvline  
%    \!putvline
 
% LINEAR ARC:  Draws straight lines -- solid and dashed
%    \inboundscheckoff
%    \inboundscheckon
%    \!advancedashing 
%    \!drawlinearsegment
%    \!initinboundscheck
%    \!linearsolid
%    \!lineardashed
%    \!ljoin
%    \!plotifinbounds     
%    \!start 
 
% LOGTEN:  Log_10 function
%    \!logten
 
% PICTURES:  Basic setups for PiCtures; \put commands
%    \accountingoff
%    \accountingon
%    \beginpicture
%    \endpicture    
%    \endpicturesave 
%    \lines
%    \multiput
%    \put 
%    \setcoordinatemode
%    \setcoordinatesystem
%    \setdimensionmode
%    \stack 
%    \Lines
%    \Xdistance
%    \Ydistance
%    \!dimenput
%    \!ifcoordmode
%    \!ifdimenmode
%    \!setcoordmode
%    \!setdimenmode
%    \!setputobject
   
% PLOTTING:  Things to do with plotting
%    \dontsavelinesandcurves
%    \replot
%    \savelinesandcurves 
%    \setplotsymbol
%    \writesavefile 
%    \!plot
 
% PYTHAGORAS:  Euclidean distance function
%    \placehypotenuse 
%    \!Pythag
 
% QUADRATIC ARC:  Draws a quadratic arc
%    \!qjoin 
 
% ROTATIONS:  Handles rotations
%    \startrotation 
%    \stoprotation
%    \!rotateaboutpivot
%    \!rotateonly
 
% SHADING:  Handles shading
%    \setshadegrid 
%    \setshadesymbol
%    \!lshade
%    \!qshade
%    \!starthshade
%    \!startvshade  
 
% TICKS:  Draws ticks on graphs
%    \gridlines
%    \loggedticks
%    \nogridlines
%    \ticksin
%    \ticksout
%    \unloggesticks
 
% ***************** END OF TABLE OF GROUPS OF MACROS ********************


\catcode`!=11 %  ***** THIS MUST NEVER BE OMITTED
% *******************************
% *** HACKS  (Utility macros) ***
% *******************************
 
% ** User commands
% **   \PiC{P\kern-.12em\lower.5ex\hbox{I}\kern-.075emC}
% **   \PiCTeX{\PiC\kern-.11em\TeX}
% **   \placevalueinpts of <DIMENSION REGISTER> in {CONTROL SEQUENCE}
  
% ** Internal commands
% **   \!ifnextchar{CHARACTER}{TRUE ACTION}{FALSE ACTION}
% **   \!tfor NAME := LIST \do {BODY}
% **   \!etfor NAME:= LIST \do {BODY}
% **   \!cfor NAME := LIST \do {BODY}
% **   \!ecfor NAME:= LIST \do {BODY}
% **   \!ifempty{MACRO}{TRUE ACTION}{FALSE ACTION}
% **   \!getnext\\ITEMfrom\LIST
% **   \!getnextvalueof\DIMEN\from\LIST
% **   \!copylist\LISTMACRO_A\to\LISTMACRO_B
% **   \!wlet\CONTROL_SEQUENCE_A=\CONTROL_SEQUENCE_B
% **   \!listaddon ITEM LIST
% **   \!rightappendITEM\withCS\to\LISTMACRO
% **   \!leftappendITEM\withCS\to\LISTMACRO
% **   \!lop\LISTMACRO\to\ITEM
% **   \!loop ... repeat
% **   \!!loop ... repeat
% **   \!removept{DIMENSION REGISTER}{CONTROL SEQUENCE}
% **   \!mlap{...}  
% **   \!vmlap{...}
% **   \!not{TEK if-CONDITION}

% ** First, here are the the PiCTeX logo, and the syllable PiC:
\def\PiC{P\kern-.12em\lower.5ex\hbox{I}\kern-.075emC}
\def\PiCTeX{\PiC\kern-.11em\TeX}

% ** The following macro expands to parameter #2 or parameter #3 according to
% ** whether the next non-blank character following the macro is or is not #1. 
% ** Blanks following the macro are gobbled.
\def\!ifnextchar#1#2#3{%
  \let\!testchar=#1%
  \def\!first{#2}%
  \def\!second{#3}%
  \futurelet\!nextchar\!testnext}
\def\!testnext{%
  \ifx \!nextchar \!spacetoken 
    \let\!next=\!skipspacetestagain
  \else
    \ifx \!nextchar \!testchar
      \let\!next=\!first
    \else 
      \let\!next=\!second 
    \fi 
  \fi
  \!next}
\def\\{\!skipspacetestagain} 
  \expandafter\def\\ {\futurelet\!nextchar\!testnext} 
\def\\{\let\!spacetoken= } \\  %  ** set \spacetoken to a space token
 
 
% ** Borrow the "tfor" macro from Latex:
% **   \!tfor NAME := LIST \do {BODY}
% **   if, before expansion, LIST = T1 ... Tn,  where each  Ti  is a token
% **   or  {...},  then executes  BODY  n  times, with  NAME = Ti  on the
% **   i-th iteration.  Works for  n=0.
\def\!tfor#1:=#2\do#3{%
  \edef\!fortemp{#2}%
  \ifx\!fortemp\!empty 
    \else
    \!tforloop#2\!nil\!nil\!!#1{#3}%
  \fi}
\def\!tforloop#1#2\!!#3#4{%
  \def#3{#1}%
  \ifx #3\!nnil
    \let\!nextwhile=\!fornoop
  \else
    #4\relax
    \let\!nextwhile=\!tforloop
  \fi 
  \!nextwhile#2\!!#3{#4}}
 
 
% **   \!etfor NAME:= LIST\do {BODY}
% **   This is like \!cfor, but LIST is any balanced token list whose complete
% **     expansion has the form  T1 ... Tn
\def\!etfor#1:=#2\do#3{%
  \def\!!tfor{\!tfor#1:=}%
  \edef\!!!tfor{#2}%
  \expandafter\!!tfor\!!!tfor\do{#3}}
 
 
% **   modify the Latex \tfor (token-for) loop to a \cfor (comma-for) loop.
% **   \!cfor NAME := LIST \do {BODY}
% **     if, before expansion, LIST = a1,a2,...an, then executes  BODY n times,
% **     with  NAME = ai  on the i-th iteration.  Works for  n=0.
\def\!cfor#1:=#2\do#3{%
  \edef\!fortemp{#2}%
  \ifx\!fortemp\!empty 
  \else
    \!cforloop#2,\!nil,\!nil\!!#1{#3}%
  \fi}
\def\!cforloop#1,#2\!!#3#4{%
  \def#3{#1}%
  \ifx #3\!nnil
    \let\!nextwhile=\!fornoop 
  \else
    #4\relax
    \let\!nextwhile=\!cforloop
  \fi
  \!nextwhile#2\!!#3{#4}}
 
 
% **   \!ecfor NAME:= LIST\do {BODY}
% **   This is like \!cfor, but LIST is any balanced token list whose complete
% **     expansion has the form  a1,a2,...,an.
\def\!ecfor#1:=#2\do#3{%
  \def\!!cfor{\!cfor#1:=}%
  \edef\!!!cfor{#2}%
  \expandafter\!!cfor\!!!cfor\do{#3}}
 
 
\def\!empty{}
\def\!nnil{\!nil}
\def\!fornoop#1\!!#2#3{}
 
 
% **  \!ifempty{ARG}{TRUE ACTION}{FALSE ACTION}
\def\!ifempty#1#2#3{%
  \edef\!emptyarg{#1}%
  \ifx\!emptyarg\!empty
    #2%
  \else
    #3%
  \fi}
 
% **  \!getnext\\ITEMfrom\LIST
% **    \LIST has the form \\{item1}\\{item2}\\{item3}...\\{itemk}
% **    This routine sets \ITEM to item1, and cycles \LIST to
% **    \\{item2}\\{item3}...\\{itemk}\\{item1}
\def\!getnext#1\from#2{%
  \expandafter\!gnext#2\!#1#2}%
\def\!gnext\\#1#2\!#3#4{%
  \def#3{#1}%
  \def#4{#2\\{#1}}%
  \ignorespaces}
 
 
% ** \!getnextvalueof\DIMEN\from\LIST
% **   Similar to !getnext.  
% **   \LIST has the form \\{dimen1}\\{dimen2}\\{dimen3} ... 
% **   \DIMEN is a dimension register
% **   Works also for counts
%
\def\!getnextvalueof#1\from#2{%
  \expandafter\!gnextv#2\!#1#2}%
\def\!gnextv\\#1#2\!#3#4{%
  #3=#1%
  \def#4{#2\\{#1}}%
  \ignorespaces}
 
 
% ** \!copylist\LISTMACROA\to\LISTMACROB
% **   makes the replacement text of LISTMACRO B identical to that of
% **   list macro A.
\def\!copylist#1\to#2{%
  \expandafter\!!copylist#1\!#2}
\def\!!copylist#1\!#2{%
  \def#2{#1}\ignorespaces}
 
 
% **  \!wlet\CSA=\CSB
% **  lets control sequence \CSB = control sequence \CSA, and writes a
% **    message to that effect in the log file using plain TEK's \wlog
\def\!wlet#1=#2{%
  \let#1=#2 
  \wlog{\string#1=\string#2}}
 
% ** \!listaddon ITEM LIST
% ** LIST <-- LIST \\ ITEM
\def\!listaddon#1#2{%
  \expandafter\!!listaddon#2\!{#1}#2}
\def\!!listaddon#1\!#2#3{%
  \def#3{#1\\#2}}
 
% **  \!rightappendITEM\to\LISTMACRO
% **    \LISTMACRO --> \LISTMACRO\\{ITEM}
%\def\!rightappend#1\to#2{\expandafter\!!rightappend#2\!{#1}#2}
%\def\!!rightappend#1\!#2#3{\def#3{#1\\{#2}}}
 
 
% **  \!rightappendITEM\withCS\to\LISTMACRO
% **    \LISTMACRO --> \LISTMACRO||CS||{ITEM}
\def\!rightappend#1\withCS#2\to#3{\expandafter\!!rightappend#3\!#2{#1}#3}
\def\!!rightappend#1\!#2#3#4{\def#4{#1#2{#3}}}
 
 
% **  \!leftappendITEM\withCS\to\LISTMACRO
% **    \LISTMACRO --> CS||{ITEM}||\LISTMACRO
\def\!leftappend#1\withCS#2\to#3{\expandafter\!!leftappend#3\!#2{#1}#3}
\def\!!leftappend#1\!#2#3#4{\def#4{#2{#3}#1}}
 
 
% **  \!lop\LISTMACRO\to\ITEM
% **    \\{item1}\\{item2}\\{item3} ... --> \\{item2}\\{item3} ...
% **    item1 --> \ITEM
\def\!lop#1\to#2{\expandafter\!!lop#1\!#1#2}
\def\!!lop\\#1#2\!#3#4{\def#4{#1}\def#3{#2}}
 
 
% **  \!placeNUMBER\of\LISTMACRO\in\ITEM
% **    the NUMBERth item of \LISTMACRO --> replacement text of \ITEM
%\def\!place#1\of#2\in#3{\def#3{\outofrange}%
%{\count0=#1\def\\##1{\advance\count0-1 \ifnum\count0=0 \gdef#3{##1}\fi}#2}}
 
 
% **  Following code converts a commalist to a list macro, with all items 
% **    fully expanded.
%\!ecfor\item:=\commalist\do{\expandafter\!rightappend\item\to\list}
 
 
% ** \!loop ... repeat
% ** This is exactly like TEX's \loop ... repeat.  It can be used in nesting
% ** two loops, without puting the inner one inside a group.
\def\!loop#1\repeat{\def\!body{#1}\!iterate}
\def\!iterate{\!body\let\!next=\!iterate\else\let\!next=\relax\fi\!next}
 
% ** \!!loop ... repeat
% ** This is exactly like TEX's \loop ... repeat.  It can be used in nesting
% ** two loops, without puting the inner one inside a group.
\def\!!loop#1\repeat{\def\!!body{#1}\!!iterate}
\def\!!iterate{\!!body\let\!!next=\!!iterate\else\let\!!next=\relax\fi\!!next}
%  (\multiput uses \!!loop)
 
% ** \!removept{DIMENREG}{\CS}
% ** Defines the control sequence CS to be the value (in points) in the
% ** dimension register DIMENREG (but without the "pt" TEK usually adds)
% ** E.g., after  \dimen0=12.3pt \!removept\dimen0\A, \A expands to 12.3
\def\!removept#1#2{\edef#2{\expandafter\!!removePT\the#1}}
{\catcode`p=12 \catcode`t=12 \gdef\!!removePT#1pt{#1}}

% ** \pladevalueinpts of <DIMENSION REGISTER> in {CONTROL SEQUENCE}
\def\placevalueinpts of <#1> in #2 {%
  \!removept{#1}{#2}}
 
% ** \!mlap{...}  \!vmlap{...}
% ** Center  ...  in a box of width 0.
\def\!mlap#1{\hbox to 0pt{\hss#1\hss}}
\def\!vmlap#1{\vbox to 0pt{\vss#1\vss}}
 
% ** \!not{TEK if-CONDITION}
% ** By a TEK if-CONDITION is meant something like 
% **     \ifnum\N<0,   or   \ifdim\A>\B
% ** \!not produces an if-condition which is false if the original condition
% ** is true, and true if the original condition is false.
\def\!not#1{%
  #1\relax
    \!switchfalse
  \else
    \!switchtrue
  \fi
  \if!switch
  \ignorespaces}
 

% *******************
% *** ALLOCATIONS ***
% *******************

% This section allocates all the registers PiCTeX uses. Following
% each allocation is a string of the form  ....N.D...L......... ;
% the various letters show which sections of PiCTeX make explicit
% reference to that register, according to the following code:
 
%   H Hacks
%   A Areas
%   W arroWs
%   B Bars
%   X boXes
%   C Curves
%   D Dashpattterns
%   V diVision
%   E Ellipses
%   U rUles
%   L Linear arc
%   G loGten
%   P Pictures
%   O plOtting
%   Y pYthagoras
%   Q Quadratic arc
%   R Rotations
%   S Shading
%   T Ticks

% Turn off messages from TeX's allocation macros
\let\!!!wlog=\wlog              % "\wlog" is defined in plain TeX
\def\wlog#1{}    

\newdimen\headingtoplotskip     %.A.................
\newdimen\linethickness         %.A..X....U........T
\newdimen\longticklength        %.A................T
\newdimen\plotsymbolspacing     %......D...L....Q...
\newdimen\shortticklength       %.A................T
\newdimen\stackleading          %.A..........P......
\newdimen\tickstovaluesleading  %.A................T
\newdimen\totalarclength        %......D...L....Q...
\newdimen\valuestolabelleading  %.A.................

\newbox\!boxA                   %.AW...............T
\newbox\!boxB                   %..W................
\newbox\!picbox                 %............P......
\newbox\!plotsymbol             %..........L..O.....
\newbox\!putobject              %............PO...S.
\newbox\!shadesymbol            %.................S.

\newcount\!countA               %.A....D..UL....Q.ST
\newcount\!countB               %......D..U.....Q.ST
\newcount\!countC               %...............Q..T
\newcount\!countD               %...................
\newcount\!countE               %.............O....T
\newcount\!countF               %.............O....T
\newcount\!countG               %..................T
\newcount\!fiftypt              %.........U.........
\newcount\!intervalno           %..........L....Q...
\newcount\!npoints              %..........L........
\newcount\!nsegments            %.........U.........
\newcount\!ntemp                %............P......
\newcount\!parity               %.................S.
\newcount\!scalefactor          %..................T
\newcount\!tfs                  %.......V...........
\newcount\!tickcase             %..................T

\newdimen\!Xleft                %............P......
\newdimen\!Xright               %............P......
\newdimen\!Xsave                %.A................T
\newdimen\!Ybot                 %............P......
\newdimen\!Ysave                %.A................T
\newdimen\!Ytop                 %............P......
\newdimen\!angle                %........E..........
\newdimen\!arclength            %..W......UL....Q...
\newdimen\!areabloc             %.A........L........
\newdimen\!arealloc             %.A........L........
\newdimen\!arearloc             %.A........L........
\newdimen\!areatloc             %.A........L........
\newdimen\!bshrinkage           %.................S.
\newdimen\!checkbot             %..........L........
\newdimen\!checkleft            %..........L........
\newdimen\!checkright           %..........L........
\newdimen\!checktop             %..........L........
\newdimen\!dimenA               %.AW.X.DVEUL..OYQRST
\newdimen\!dimenB               %....X.DVEU...O.QRS.
\newdimen\!dimenC               %..W.X.DVEU......RS.
\newdimen\!dimenD               %..W.X.DVEU....Y.RS.
\newdimen\!dimenE               %..W........G..YQ.S.
\newdimen\!dimenF               %...........G..YQ.S.
\newdimen\!dimenG               %...........G..YQ.S.
\newdimen\!dimenH               %...........G..Y..S.
\newdimen\!dimenI               %...BX.........Y....
\newdimen\!distacross           %..........L....Q...
\newdimen\!downlength           %..........L........
\newdimen\!dp                   %.A..X.......P....S.
\newdimen\!dshade               %.................S.
\newdimen\!dxpos                %..W......U..P....S.
\newdimen\!dxprime              %...............Q...
\newdimen\!dypos                %..WB.....U..P......
\newdimen\!dyprime              %...............Q...
\newdimen\!ht                   %.A..X.......P....S.
\newdimen\!leaderlength         %......D..U.........
\newdimen\!lshrinkage           %.................S.
\newdimen\!midarclength         %...............Q...
\newdimen\!offset               %.A................T
\newdimen\!plotheadingoffset    %.A.................
\newdimen\!plotsymbolxshift     %..........L..O.....
\newdimen\!plotsymbolyshift     %..........L..O.....
\newdimen\!plotxorigin          %..........L..O.....
\newdimen\!plotyorigin          %..........L..O.....
\newdimen\!rootten              %...........G.......
\newdimen\!rshrinkage           %.................S.
\newdimen\!shadesymbolxshift    %.................S.
\newdimen\!shadesymbolyshift    %.................S.
\newdimen\!tenAa                %...........G.......
\newdimen\!tenAc                %...........G.......
\newdimen\!tenAe                %...........G.......
\newdimen\!tshrinkage           %.................S.
\newdimen\!uplength             %..........L........
\newdimen\!wd                   %....X.......P....S.
\newdimen\!wmax                 %...............Q...
\newdimen\!wmin                 %...............Q...
\newdimen\!xB                   %...............Q...
\newdimen\!xC                   %...............Q...
\newdimen\!xE                   %..W.....E.L....Q.S.
\newdimen\!xM                   %..W.....E......Q.S.
\newdimen\!xS                   %..W.....E.L....Q.S.
\newdimen\!xaxislength          %.A................T
\newdimen\!xdiff                %..........L........
\newdimen\!xleft                %............P......
\newdimen\!xloc                 %..WB.....U.......S.
\newdimen\!xorigin              %.A........L.P....S.
\newdimen\!xpivot               %................R..
\newdimen\!xpos                 %..........L.P..Q.ST
\newdimen\!xprime               %...............Q...
\newdimen\!xright               %............P......
\newdimen\!xshade               %.................S.
\newdimen\!xshift               %..W.........PO...S.
\newdimen\!xtemp                %............P......
\newdimen\!xunit                %.AWBX...EUL.P..QRS.
\newdimen\!xxE                  %........E..........
\newdimen\!xxM                  %........E..........
\newdimen\!xxS                  %........E..........
\newdimen\!xxloc                %..WB....EU.........
\newdimen\!yB                   %...............Q...
\newdimen\!yC                   %...............Q...
\newdimen\!yE                   %..W.....E.L....Q...
\newdimen\!yM                   %..W.....E......Q...
\newdimen\!yS                   %..W.....E.L....Q...
\newdimen\!yaxislength          %.A................T
\newdimen\!ybot                 %............P......
\newdimen\!ydiff                %..........L........
\newdimen\!yloc                 %..WB.....U.......S.
\newdimen\!yorigin              %.A........L.P....S.
\newdimen\!ypivot               %................R..
\newdimen\!ypos                 %..........L.P..Q.ST
\newdimen\!yprime               %...............Q...
\newdimen\!yshade               %.................S.
\newdimen\!yshift               %..W.........PO...S.
\newdimen\!ytemp                %............P......
\newdimen\!ytop                 %............P......
\newdimen\!yunit                %.AWBX...EUL.P..QRS.
\newdimen\!yyE                  %........E..........
\newdimen\!yyM                  %........E..........
\newdimen\!yyS                  %........E..........
\newdimen\!yyloc                %..WB....EU.........
\newdimen\!zpt                  %.AWBX.DVEULGP.YQ.ST

\newif\if!axisvisible           %.A.................
\newif\if!gridlinestoo          %..................T
\newif\if!keepPO                %...................
\newif\if!placeaxislabel        %.A.................
\newif\if!switch                %H..................
\newif\if!xswitch               %.A................T

\newtoks\!axisLaBeL             %.A.................
\newtoks\!keywordtoks           %.A.................

\newwrite\!replotfile           %.............O.....

\newhelp\!keywordhelp{The keyword mentioned in the error message in unknown. 
Replace NEW KEYWORD in the indicated response by the keyword that 
should have been specified.}    %.A.................

% The following commands assign alternate names to some of the 
% above registers.  "\!wlet"  is defined in  Hacks.
\!wlet\!!origin=\!xM                   %.A................T
\!wlet\!!unit=\!uplength               %.A................T
\!wlet\!Lresiduallength=\!dimenG       %.........U.........
\!wlet\!Rresiduallength=\!dimenF       %.........U.........
\!wlet\!axisLength=\!distacross        %.A................T
\!wlet\!axisend=\!ydiff                %.A................T
\!wlet\!axisstart=\!xdiff              %.A................T
\!wlet\!axisxlevel=\!arclength         %.A................T
\!wlet\!axisylevel=\!downlength        %.A................T
\!wlet\!beta=\!dimenE                  %...............Q...
\!wlet\!gamma=\!dimenF                 %...............Q...
\!wlet\!shadexorigin=\!plotxorigin     %.................S.
\!wlet\!shadeyorigin=\!plotyorigin     %.................S.
\!wlet\!ticklength=\!xS                %..................T
\!wlet\!ticklocation=\!xE              %..................T
\!wlet\!ticklocationincr=\!yE          %..................T
\!wlet\!tickwidth=\!yS                 %..................T
\!wlet\!totalleaderlength=\!dimenE     %.........U.........
\!wlet\!xone=\!xprime                  %....X..............
\!wlet\!xtwo=\!dxprime                 %....X..............
\!wlet\!ySsave=\!yM                    %...................
\!wlet\!ybB=\!yB                       %.................S.
\!wlet\!ybC=\!yC                       %.................S.
\!wlet\!ybE=\!yE                       %.................S.
\!wlet\!ybM=\!yM                       %.................S.
\!wlet\!ybS=\!yS                       %.................S.
\!wlet\!ybpos=\!yyloc                  %.................S.
\!wlet\!yone=\!yprime                  %....X..............
\!wlet\!ytB=\!xB                       %.................S.
\!wlet\!ytC=\!xC                       %.................S.
\!wlet\!ytE=\!downlength               %.................S.
\!wlet\!ytM=\!arclength                %.................S.
\!wlet\!ytS=\!distacross               %.................S.
\!wlet\!ytpos=\!xxloc                  %.................S.
\!wlet\!ytwo=\!dyprime                 %....X..............


% Initial values for registers
\!zpt=0pt                              % static
\!xunit=1pt
\!yunit=1pt
\!arearloc=\!xunit
\!areatloc=\!yunit
\!dshade=5pt
\!leaderlength=24in
\!tfs=256                              % static
\!wmax=5.3pt                           % static
\!wmin=2.7pt                           % static
\!xaxislength=\!xunit
\!xpivot=\!zpt
\!yaxislength=\!yunit 
\!ypivot=\!zpt
\plotsymbolspacing=.4pt
  \!dimenA=50pt \!fiftypt=\!dimenA     % static

\!rootten=3.162278pt                   % static
\!tenAa=8.690286pt                     % static  (A5)
\!tenAc=2.773839pt                     % static  (A3)
\!tenAe=2.543275pt                     % static  (A1)

% Initial values for control sequences
\def\!cosrotationangle{1}      %................R..
\def\!sinrotationangle{0}      %................R..
\def\!xpivotcoord{0}           %................R..
\def\!xref{0}                  %............P......
\def\!xshadesave{0}            %.................S.
\def\!ypivotcoord{0}           %................R..
\def\!yref{0}                  %............P......
\def\!yshadesave{0}            %.................S.
\def\!zero{0}                  %..................T

% Reset TeX to report allocations
\let\wlog=\!!!wlog
%  *************************************
%  ***  AREAS: Deals with plot areas ***
%  *************************************
%
%  ** User commands
%  **   \setplotarea x from LEFT XCOORD to RIGTH XCOORD, y from BOTTOM YCOORD
%  **      to TOP YCOORD
%  **   \axis BOTTOM-LEFT-TOP-RIGHT  [SHIFTEDTO xy=COORD] [VISIBLE-INVISIBLE]
%  **      [LABEL {label}] [TICKS] /
%  **   \visibleaxes
%  **   \invisibleaxes
%  **   \plotheading {HEADING}
%  **   \grid {# of columns} {# of rows}
%  **   \normalgraphs 
  
%  **  \normalgraphs
%  **    Sets defaults for graph setup. See Subsection 3.4 of manual.
\def\normalgraphs{%
  \longticklength=.4\baselineskip
  \shortticklength=.25\baselineskip
  \tickstovaluesleading=.25\baselineskip
  \valuestolabelleading=.8\baselineskip
  \linethickness=.4pt
  \stackleading=.17\baselineskip
  \headingtoplotskip=1.5\baselineskip
  \visibleaxes
  \ticksout
  \nogridlines
  \unloggedticks}
%
% **  \setplotarea x from LEFT XCOORD to RIGTH XCOORD, y from BOTTOM YCOORD
% **    to TOP YCOORD
% **  Reserves space in PICBOX for a rectangular box with the indicated
% **   coordinates.  Must be specified before calls to  \axis, 
% **   \grid, \plotheading.
% **  See Subsection 3.1 of the manual.
\def\setplotarea x from #1 to #2, y from #3 to #4 {%
  \!arealloc=\!M{#1}\!xunit \advance \!arealloc -\!xorigin
  \!areabloc=\!M{#3}\!yunit \advance \!areabloc -\!yorigin
  \!arearloc=\!M{#2}\!xunit \advance \!arearloc -\!xorigin
  \!areatloc=\!M{#4}\!yunit \advance \!areatloc -\!yorigin
  \!initinboundscheck
  \!xaxislength=\!arearloc  \advance\!xaxislength -\!arealloc
  \!yaxislength=\!areatloc  \advance\!yaxislength -\!areabloc
  \!plotheadingoffset=\!zpt
  \!dimenput {{\setbox0=\hbox{}\wd0=\!xaxislength\ht0=\!yaxislength\box0}}
     [bl] (\!arealloc,\!areabloc)}
%
% ** \visibleaxes, \invisibleaxes 
% ** Switches for setting visibility of subsequent axes.
% ** See Subsection 3.2 of the manual.
\def\visibleaxes{%
  \def\!axisvisibility{\!axisvisibletrue}}
\def\invisibleaxes{%
  \def\!axisvisibility{\!axisvisiblefalse}}
%
% ** The next few macros enable the user to fix up an erroneous keyword
% **   in the \axis command.
%  \newhelp is in ALLOCATIONS
%  \newhelp\!keywordhelp{The keyword mentioned in the error message in unknown. 
%  Replace NEW KEYWORD in the indicated response by the keyword that 
%  should have been specified.}

\def\!fixkeyword#1{%
  \errhelp=\!keywordhelp
  \errmessage{Unrecognized keyword `#1': \the\!keywordtoks{NEW KEYWORD}'}}

%  \newtoks\!keywordtoks    In ALLOCATIONS.
\!keywordtoks={enter `i\fixkeyword}

\def\fixkeyword#1{%
  \!nextkeyword#1 }

% ** \axis BOTTOM-LEFT-TOP-RIGHT  [SHIFTEDTO xy=COORD] [VISIBLE-INVISIBLE]
% **   [LABEL {label}] [TICKS] /
% ** Exactly one of the keywords BOTTOM, LEFT, TOP, RIGHT must be
% ** specified. Axis is drawn along the indicated edge of the current
% ** plot area, shifted if the SHIFTEDTO option is used, visible or
% ** invisible according the selected option, with an optional LABEL,
% ** and optional TICKS (see ticks.tex for the options avialabel with
% ** TICKS). The TICKS option must be the last one specified. The \axis
% ** MUST be terminated with a / followed by a space.
% ** See Subsection 3.2 of the manual for more information.

% ** The various options of the \axis command are processed by the
% ** \!nextkeyword macro defined below. For example, 
% ** `\!nextkeyword shiftedto ' expands to `\!axisshiftedto'.
\def\axis {%
  \def\!nextkeyword##1 {%
    \expandafter\ifx\csname !axis##1\endcsname \relax
      \def\!next{\!fixkeyword{##1}}%
    \else
      \def\!next{\csname !axis##1\endcsname}%
    \fi
    \!next}%
  \!offset=\!zpt
  \!axisvisibility
  \!placeaxislabelfalse
  \!nextkeyword}

% ** This and the various macros that follow handle the keyword
% ** specifications on the \axis command
% ** See Subsection 3.2 of the manual.
\def\!axisbottom{%
  \!axisylevel=\!areabloc
  \def\!tickxsign{0}%
  \def\!tickysign{-}%
  \def\!axissetup{\!axisxsetup}%
  \def\!axislabeltbrl{t}%
  \!nextkeyword}

\def\!axistop{%
  \!axisylevel=\!areatloc
  \def\!tickxsign{0}%
  \def\!tickysign{+}%
  \def\!axissetup{\!axisxsetup}%
  \def\!axislabeltbrl{b}%
  \!nextkeyword}

\def\!axisleft{%
  \!axisxlevel=\!arealloc
  \def\!tickxsign{-}%
  \def\!tickysign{0}%
  \def\!axissetup{\!axisysetup}%
  \def\!axislabeltbrl{r}%
  \!nextkeyword}

\def\!axisright{%
  \!axisxlevel=\!arearloc
  \def\!tickxsign{+}%
  \def\!tickysign{0}%
  \def\!axissetup{\!axisysetup}%
  \def\!axislabeltbrl{l}%
  \!nextkeyword}

\def\!axisshiftedto#1=#2 {%
  \if 0\!tickxsign
    \!axisylevel=\!M{#2}\!yunit
    \advance\!axisylevel -\!yorigin
  \else
    \!axisxlevel=\!M{#2}\!xunit
    \advance\!axisxlevel -\!xorigin
  \fi
  \!nextkeyword}

\def\!axisvisible{%
  \!axisvisibletrue  
  \!nextkeyword}

\def\!axisinvisible{%
  \!axisvisiblefalse
  \!nextkeyword}

\def\!axislabel#1 {%
  \!axisLaBeL={#1}%
  \!placeaxislabeltrue
  \!nextkeyword}

\expandafter\def\csname !axis/\endcsname{%
  \!axissetup % This could done already by "ticks"; if so, now \relax
  \if!placeaxislabel
    \!placeaxislabel
  \fi
  \if +\!tickysign %                 ** (A "top" axis)
    \!dimenA=\!axisylevel
    \advance\!dimenA \!offset %      ** dimA = top of the axis structure
    \advance\!dimenA -\!areatloc %   ** dimA = excess over the plot area
    \ifdim \!dimenA>\!plotheadingoffset
      \!plotheadingoffset=\!dimenA % ** Greatest excess over the plot area
    \fi
  \fi}

% ** \grid {c} {r} 
% ** Partitions the plot area into c columns and r rows; see Subsection 3.3
% ** of the manual.
% ** (Other grid patterns can be drawn with the TICKS option of the \axis 
% ** command.
\def\grid #1 #2 {%
  \!countA=#1\advance\!countA 1
  \axis bottom invisible ticks length <\!zpt> andacross quantity {\!countA} /
  \!countA=#2\advance\!countA 1
  \axis left   invisible ticks length <\!zpt> andacross quantity {\!countA} / }

% ** \plotheading{HEADING}
% ** Places HEADING centered above the top of the plotarea (and above
% ** any top axis ticks marks, tick labels, and axis label); see
% ** Subsection 3.3 of the manual.
\def\plotheading#1 {%
  \advance\!plotheadingoffset \headingtoplotskip
  \!dimenput {#1} [B] <.5\!xaxislength,\!plotheadingoffset>
    (\!arealloc,\!areatloc)}

% ** From here on, the routines are internal.
\def\!axisxsetup{%
  \!axisxlevel=\!arealloc
  \!axisstart=\!arealloc
  \!axisend=\!arearloc
  \!axisLength=\!xaxislength
  \!!origin=\!xorigin
  \!!unit=\!xunit
  \!xswitchtrue
  \if!axisvisible 
    \!makeaxis
  \fi}

\def\!axisysetup{%
  \!axisylevel=\!areabloc
  \!axisstart=\!areabloc
  \!axisend=\!areatloc
  \!axisLength=\!yaxislength
  \!!origin=\!yorigin
  \!!unit=\!yunit
  \!xswitchfalse
  \if!axisvisible
    \!makeaxis
  \fi}

\def\!makeaxis{%
  \setbox\!boxA=\hbox{% (Make a pseudo-y[x] tick for an x[y]-axis)
    \beginpicture
      \!setdimenmode
      \setcoordinatesystem point at {\!zpt} {\!zpt}   
      \putrule from {\!zpt} {\!zpt} to
        {\!tickysign\!tickysign\!axisLength} 
        {\!tickxsign\!tickxsign\!axisLength}
    \endpicturesave <\!Xsave,\!Ysave>}%
    \wd\!boxA=\!zpt
    \!placetick\!axisstart}

\def\!placeaxislabel{%
  \advance\!offset \valuestolabelleading
  \if!xswitch
    \!dimenput {\the\!axisLaBeL} [\!axislabeltbrl]
      <.5\!axisLength,\!tickysign\!offset> (\!axisxlevel,\!axisylevel)
    \advance\!offset \!dp  % ** advance offset by the "tallness"
    \advance\!offset \!ht  % ** of the label
  \else
    \!dimenput {\the\!axisLaBeL} [\!axislabeltbrl]
      <\!tickxsign\!offset,.5\!axisLength> (\!axisxlevel,\!axisylevel)
  \fi
  \!axisLaBeL={}}


% *******************************
% *** ARROWS  (Draws arrows)  ***
% *******************************
%
% ** User commands
% **  \arrow <ARROW HEAD LENGTH> [MID FRACTION, BASE FRACTION]
% **    [<XSHIFT,YSHIFT>] from XFROM YFROM to XTO YTO
% **  \betweenarrows {TEXT} [orientation & shift] from XFROM YFROM to XTO YTO

% ** \arrow <ARROW HEAD LENGTH> [MID FRACTION, BASE FRACTION]
% **    [<XSHIFT,YSHIFT>] from XFROM YFROM to XTO YTO
% ** Draws an arrow from (XFROM,YFROM) to (XTO,YTO).  The arrow head
% ** is constructed two quadratic arcs, which extend back a distance
% ** ARROW HEAD LENGTH (a dimension) on both sides of the arrow shaft.
% ** All the way back the arcs are a distance BASE FRACTION*ARROW HEAD
% ** LENGTH apart, while half-way back they are a distance MID FRACTION*
% ** ARROW HEAD LENGTH apart. <XSHIFT,YSHIFT> is optional, and has
% ** its usual interpreation. See Subsection 5.4 of the manual.

\def\arrow <#1> [#2,#3]{%
  \!ifnextchar<{\!arrow{#1}{#2}{#3}}{\!arrow{#1}{#2}{#3}<\!zpt,\!zpt> }}

\def\!arrow#1#2#3<#4,#5> from #6 #7 to #8 #9 {%
%
% ** convert to dimensions
  \!xloc=\!M{#8}\!xunit   
  \!yloc=\!M{#9}\!yunit
  \!dxpos=\!xloc  \!dimenA=\!M{#6}\!xunit  \advance \!dxpos -\!dimenA
  \!dypos=\!yloc  \!dimenA=\!M{#7}\!yunit  \advance \!dypos -\!dimenA
  \let\!MAH=\!M%                         ** save current c/d mode
  \!setdimenmode%                        ** go into dimension mode
%
  \!xshift=#4\relax  \!yshift=#5\relax%  ** pick up shift
  \!reverserotateonly\!xshift\!yshift%   ** back rotate shift
  \advance\!xshift\!xloc  \advance\!yshift\!yloc
%
% **  draw shaft of arrow
  \!xS=-\!dxpos  \advance\!xS\!xshift
  \!yS=-\!dypos  \advance\!yS\!yshift
  \!start (\!xS,\!yS)
  \!ljoin (\!xshift,\!yshift)
%
% ** find 32*cosine and 32*sine of angle of rotation
  \!Pythag\!dxpos\!dypos\!arclength
  \!divide\!dxpos\!arclength\!dxpos  
  \!dxpos=32\!dxpos  \!removept\!dxpos\!!cos
  \!divide\!dypos\!arclength\!dypos  
  \!dypos=32\!dypos  \!removept\!dypos\!!sin
% 
% ** construct arrowhead
  \!halfhead{#1}{#2}{#3}%                ** draw half of arrow head
  \!halfhead{#1}{-#2}{-#3}%              ** draw other half
%
  \let\!M=\!MAH%                         ** restore old c/d mode
  \ignorespaces}
%
% ** draw half of arrow head
  \def\!halfhead#1#2#3{%
    \!dimenC=-#1%                
    \divide \!dimenC 2 %                 ** half way back
    \!dimenD=#2\!dimenC%                 ** half the mid width
    \!rotate(\!dimenC,\!dimenD)by(\!!cos,\!!sin)to(\!xM,\!yM)
    \!dimenC=-#1%                        ** all the way back
    \!dimenD=#3\!dimenC
    \!dimenD=.5\!dimenD%                 ** half the full width
    \!rotate(\!dimenC,\!dimenD)by(\!!cos,\!!sin)to(\!xE,\!yE)
    \!start (\!xshift,\!yshift)
    \advance\!xM\!xshift  \advance\!yM\!yshift
    \advance\!xE\!xshift  \advance\!yE\!yshift
    \!qjoin (\!xM,\!yM) (\!xE,\!yE) 
    \ignorespaces}


% ** \betweenarrows {TEXT} [orientation & shift] from XFROM YFROM to XTO YTO
% **   Makes things like <--- text --->, using arrow heads from TeX's fonts.
% **   See Subsection 5.4 of the manual.
\def\betweenarrows #1#2 from #3 #4 to #5 #6 {%
  \!xloc=\!M{#3}\!xunit  \!xxloc=\!M{#5}\!xunit%   
  \!yloc=\!M{#4}\!yunit  \!yyloc=\!M{#6}\!yunit%           
  \!dxpos=\!xxloc  \advance\!dxpos by -\!xloc
  \!dypos=\!yyloc  \advance\!dypos by -\!yloc
  \advance\!xloc .5\!dxpos
  \advance\!yloc .5\!dypos
%
  \let\!MBA=\!M%           ** save current coord\dimen mode
  \!setdimenmode%          ** express locations in dimens
  \ifdim\!dypos=\!zpt
    \ifdim\!dxpos<\!zpt \!dxpos=-\!dxpos \fi
    \put {\!lrarrows{\!dxpos}{#1}}#2{} at {\!xloc} {\!yloc}
  \else
    \ifdim\!dxpos=\!zpt
      \ifdim\!dypos<\!zpt \!dypos=-\!zpt \fi
      \put {\!udarrows{\!dypos}{#1}}#2{} at {\!xloc} {\!yloc}
    \fi
  \fi
  \let\!M=\!MBA%           ** restore previous c/d mode
  \ignorespaces}

% ** Subroutine for left-right between arrows 
\def\!lrarrows#1#2{% #1=width, #2=text
  {\setbox\!boxA=\hbox{$\mkern-2mu\mathord-\mkern-2mu$}%
   \setbox\!boxB=\hbox{$\leftarrow$}\!dimenE=\ht\!boxB
   \setbox\!boxB=\hbox{}\ht\!boxB=2\!dimenE
   \hbox to #1{$\mathord\leftarrow\mkern-6mu
     \cleaders\copy\!boxA\hfil
     \mkern-6mu\mathord-$%
     \kern.4em $\vcenter{\box\!boxB}$$\vcenter{\hbox{#2}}$\kern.4em
     $\mathord-\mkern-6mu
     \cleaders\copy\!boxA\hfil
     \mkern-6mu\mathord\rightarrow$}}}

% ** Subroutine for up-down between arrows 
\def\!udarrows#1#2{% #1=width, #2=text
  {\setbox\!boxB=\hbox{#2}%
   \setbox\!boxA=\hbox to \wd\!boxB{\hss$\vert$\hss}%
   \!dimenE=\ht\!boxA \advance\!dimenE \dp\!boxA \divide\!dimenE 2
   \vbox to #1{\offinterlineskip
      \vskip .05556\!dimenE
      \hbox to \wd\!boxB{\hss$\mkern.4mu\uparrow$\hss}\vskip-\!dimenE
      \cleaders\copy\!boxA\vfil
      \vskip-\!dimenE\copy\!boxA
      \vskip\!dimenE\copy\!boxB\vskip.4em
      \copy\!boxA\vskip-\!dimenE
      \cleaders\copy\!boxA\vfil
      \vskip-\!dimenE \hbox to \wd\!boxB{\hss$\mkern.4mu\downarrow$\hss}
      \vskip .05556\!dimenE}}}


% ***************************
% *** BARS  (Draws bars)  ***
% ***************************
%
% ** User commands:
% ** \putbar [<XSHIFT,YSHIFT>] breadth <BREADTH> from XSTART YSTART
% **   to XEND YEND
% ** \setbars [<XSHIFT,YSHIFT>] breadth <BREADTH> baseline at XY = COORD
% **   [baselabels ([B_ORIENTATION_x,B_ORIENTATION_y] <B_XSHIFT,B_YSHIFT>)]
% **   [endlabels  ([E_ORIENTATION_x,E_ORIENTATION_y] <E_XSHIFT,E_YSHIFT>)]


% ** \putbar [<XSHIFT,YSHIFT>] breadth <BREADTH> from XSTART YSTART
% **   to XEND YEND
% ** Either XSTART=XEND or YSTART=YEND. Draws a rectangle between
% **   (XSTART,YSTART) & (XEND,YEND). The "depth" of the rectangle
% **   is determined by those two plot positions; its other
% **   dimension "breadth" is specified by the dimension BREADTH.
% ** See Subsection 4.2 of the manual.
\def\putbar#1breadth <#2> from #3 #4 to #5 #6 {%
  \!xloc=\!M{#3}\!xunit  \!xxloc=\!M{#5}\!xunit%   
  \!yloc=\!M{#4}\!yunit  \!yyloc=\!M{#6}\!yunit%           
  \!dypos=\!yyloc  \advance\!dypos by -\!yloc
  \!dimenI=#2  
% 
  \ifdim \!dimenI=\!zpt %            ** If 0 breadth
    \putrule#1from {#3} {#4} to {#5} {#6} % ** Then draw line
  \else %                            ** Else, put in a rectangle
    \let\!MBar=\!M%                  ** save current c/d mode
    \!setdimenmode %                 ** go into dimension mode
    \divide\!dimenI 2
    \ifdim \!dypos=\!zpt             
      \advance \!yloc -\!dimenI %    ** Equal y coordinates
      \advance \!yyloc \!dimenI
    \else
      \advance \!xloc -\!dimenI %    ** Equal x coordinates
      \advance \!xxloc \!dimenI
    \fi
    \putrectangle#1corners at {\!xloc} {\!yloc} and {\!xxloc} {\!yyloc}
    \let\!M=\!MBar %                 ** restore c/d mode
  \fi
  \ignorespaces}


% ** \setbars [<XSHIFT,YSHIFT>] breadth <BREADTH> baseline at XY = COORD
% **   [baselabels ([B_ORIENTATION_x,B_ORIENTATION_y] <B_XSHIFT,B_YSHIFT>)]
% **   [endlabels  ([E_ORIENTATION_x,E_ORIENTATION_y] <E_XSHIFT,E_YSHIFT>)]
% ** This command puts PiCTeX into the bar graph drawing mode described
% **   in Subsection 4.4 of the manual.
\def\setbars#1breadth <#2> baseline at #3 = #4 {%
  \edef\!barshift{#1}%
  \edef\!barbreadth{#2}%
  \edef\!barorientation{#3}%
  \edef\!barbaseline{#4}%
  \def\!bardobaselabel{\!bardoendlabel}%
  \def\!bardoendlabel{\!barfinish}%
  \let\!drawcurve=\!barcurve
  \!setbars}
\def\!setbars{%
  \futurelet\!nextchar\!!setbars}
\def\!!setbars{%
  \if b\!nextchar
    \def\!!!setbars{\!setbarsbget}%
  \else 
    \if e\!nextchar
      \def\!!!setbars{\!setbarseget}%
    \else
      \def\!!!setbars{\relax}%
    \fi
  \fi
  \!!!setbars}
\def\!setbarsbget baselabels (#1) {%
  \def\!barbaselabelorientation{#1}%
  \def\!bardobaselabel{\!!bardobaselabel}%
  \!setbars}
\def\!setbarseget endlabels (#1) {%
  \edef\!barendlabelorientation{#1}%
  \def\!bardoendlabel{\!!bardoendlabel}%
  \!setbars}

% ** \!barcurve
% ** Draws a bargraph with preset values of barshift, barbreadth,
% ** barorientation (x or y) and barbaseline (coordinate)
\def\!barcurve #1 #2 {%
  \if y\!barorientation
    \def\!basexarg{#1}%
    \def\!baseyarg{\!barbaseline}%
  \else
    \def\!basexarg{\!barbaseline}%
    \def\!baseyarg{#2}%
  \fi
  \expandafter\putbar\!barshift breadth <\!barbreadth> from {\!basexarg}
    {\!baseyarg} to {#1} {#2}
  \def\!endxarg{#1}%
  \def\!endyarg{#2}%
  \!bardobaselabel}

\def\!!bardobaselabel "#1" {%
  \put {#1}\!barbaselabelorientation{} at {\!basexarg} {\!baseyarg}
  \!bardoendlabel}
 
\def\!!bardoendlabel "#1" {%
  \put {#1}\!barendlabelorientation{} at {\!endxarg} {\!endyarg}
  \!barfinish}

\def\!barfinish{%
  \!ifnextchar/{\!finish}{\!barcurve}}
 

% ********************************
% *** BOXES (Draws rectangles) ***
% ********************************
%
% ** User commands:
% **   \putrectangle [<XSHIFT,YSHIFT>] corners at  XCOORD1 YCOORD1
% **     and  XCOORD2 YCOORD2 
% **   \shaderectangleson
% **   \shaderectanglesoff
% **   \frame [<SEPARATION>] {TEXT}
% **   \rectangle <WIDTH> <HEIGHT>
%
%
% **  \putrectangle [<XSHIFT,YSHIFT>] corners at XCOORD1 YCOORD1 
% **    and  XCOORD2 YCOORD2 
% **  Draws a rectangle with corners at (X1,Y1), (X2,Y1), (X1,Y2), (X2,Y2)
% **  Lines have thickness \linethickness, and overlap at the corners.
% **  The optional field  <XSHIFT,YSHIFT>  functions as with a \put command.
% **  See Subsection 4.2 of the manual.
\def\putrectangle{%
  \!ifnextchar<{\!putrectangle}{\!putrectangle<\!zpt,\!zpt> }}
\def\!putrectangle<#1,#2> corners at #3 #4 and #5 #6 {%
%
% ** get locations
  \!xone=\!M{#3}\!xunit  \!xtwo=\!M{#5}\!xunit%   
  \!yone=\!M{#4}\!yunit  \!ytwo=\!M{#6}\!yunit%           
  \ifdim \!xtwo<\!xone
    \!dimenI=\!xone  \!xone=\!xtwo  \!xtwo=\!dimenI
  \fi
  \ifdim \!ytwo<\!yone
    \!dimenI=\!yone  \!yone=\!ytwo  \!ytwo=\!dimenI
  \fi
  \!dimenI=#1\relax  \advance\!xone\!dimenI  \advance\!xtwo\!dimenI
  \!dimenI=#2\relax  \advance\!yone\!dimenI  \advance\!ytwo\!dimenI
  \let\!MRect=\!M%                  ** save current coord/dimen mode
  \!setdimenmode
%
% ** shade rectangle if appropriate
  \!shaderectangle
%
% ** draw horizontal edges
  \!dimenI=.5\linethickness
  \advance \!xone  -\!dimenI%       ** adjust x-location to overlap corners
  \advance \!xtwo   \!dimenI%       ** ditto
  \putrule from {\!xone} {\!yone} to {\!xtwo} {\!yone} 
  \putrule from {\!xone} {\!ytwo} to {\!xtwo} {\!ytwo} 
%
% ** draw vertical edges
  \advance \!xone   \!dimenI%       ** restore original x-values
  \advance \!xtwo  -\!dimenI% 
  \advance \!yone  -\!dimenI%       ** adjust y-location to overlap corners
  \advance \!ytwo   \!dimenI%       ** ditto
  \putrule from {\!xone} {\!yone} to {\!xone} {\!ytwo} 
  \putrule from {\!xtwo} {\!yone} to {\!xtwo} {\!ytwo} 
%
  \let\!M=\!MRect%                  ** restore coord/dimen mode
  \ignorespaces}
 
% ** \shaderectangleson 
% **   Subsequent rectangles will be shaded according to 
% **   the current shading pattern.  Affects \putrectangle, \putbar,
% **   \frame, \sethistograms, and \setbars. See Subsection 7.5 of the manual.
\def\shaderectangleson{%     
  \def\!shaderectangle{\!!shaderectangle}%
  \ignorespaces}
% ** \shaderectanglesoff 
% **    Suppresses  \shaderectangleson.  The default.
\def\shaderectanglesoff{%
  \def\!shaderectangle{}%
  \ignorespaces}

\shaderectanglesoff
 
% ** The following internal routine shades the current rectangle, when
% **   \!shaderectangle = \!!shaderectangle . 
\def\!!shaderectangle{%
  \!dimenA=\!xtwo  \advance \!dimenA -\!xone
  \!dimenB=\!ytwo  \advance \!dimenB -\!yone
  \ifdim \!dimenA<\!dimenB
    \!startvshade (\!xone,\!yone,\!ytwo)
    \!lshade      (\!xtwo,\!yone,\!ytwo)
  \else
    \!starthshade (\!yone,\!xone,\!xtwo)
    \!lshade      (\!ytwo,\!xone,\!xtwo)
  \fi
  \ignorespaces}
  
% ** \frame [<SEPARATION>] {TEXT}
% ** Draws a frame of thickness linethickness about the box enclosing
% **   TEXT; the frame is separated from the box by a distance of
% **   SEPARATION.  The result is an hbox with the same baseline as TEXT.
% **   If <SEPARATION> is omitted, you get the effect of <0pt>.
% ** See Subsection 4.2 of the manual.
\def\frame{%
  \!ifnextchar<{\!frame}{\!frame<\!zpt> }}
\long\def\!frame<#1> #2{%
  \beginpicture
    \setcoordinatesystem units <1pt,1pt> point at 0 0 
    \put {#2} [Bl] at 0 0 
    \!dimenA=#1\relax
    \!dimenB=\!wd \advance \!dimenB \!dimenA
    \!dimenC=\!ht \advance \!dimenC \!dimenA
    \!dimenD=\!dp \advance \!dimenD \!dimenA
    \let\!MFr=\!M
    \!setdimenmode
    \putrectangle corners at {-\!dimenA} {-\!dimenD} and {\!dimenB} {\!dimenC}
    \!setcoordmode
    \let\!M=\!MFr
  \endpicture
  \ignorespaces}
 
% ** \rectangle <WIDTH> <HEIGHT>
% ** Constructs a rectangle of width WIDTH and heigth HEIGHT. 
% ** See Subsection 4.2 of the manual.
\def\rectangle <#1> <#2> {%
  \setbox0=\hbox{}\wd0=#1\ht0=#2\frame {\box0}}


% *********************************************
% ***  CURVES  (Upper level \plot commands) ***
% *********************************************
%
% ** User commands
% **   \plot  DATA  /
% **   \plot  "FILE NAME"
% **   \setquadratic
% **   \setlinear
% **   \sethistograms
% **   \vshade  ...
% **   \hshade  ...

% \plot: multi-purpose command. Draws histograms, bar graphs, piecewise-linear
% or piecewise quadratic curves, depending on the setting of \!drawcurve.
% See Subsections 4.3-4.5, 5.1, 5.2 of the manual.
\def\plot{%
  \!ifnextchar"{\!plotfromfile}{\!drawcurve}}
\def\!plotfromfile"#1"{%
  \expandafter\!drawcurve \input #1 /}

% Command to set piecewise quadratic mode
% See Subsections 5.1, 7.3, and 7.4 of the manual.
\def\setquadratic{%
  \let\!drawcurve=\!qcurve
  \let\!!Shade=\!!qShade
  \let\!!!Shade=\!!!qShade}

% Command to set piecewise linear mode
% See Subsections 5.1, 7.3, and 7.4 of the manual.
\def\setlinear{%
  \let\!drawcurve=\!lcurve
  \let\!!Shade=\!!lShade
  \let\!!!Shade=\!!!lShade}

% Command to set histogram mode
% See Subsection 4.3 of the manual.
\def\sethistograms{%
  \let\!drawcurve=\!hcurve}

% Commands to cycle through list of coordinates in piecewise quadratic 
% interpolation mode
\def\!qcurve #1 #2 {%
  \!start (#1,#2)
  \!Qjoin}
\def\!Qjoin#1 #2 #3 #4 {%
  \!qjoin (#1,#2) (#3,#4)             % \!qjoin  is defined in QUADRATIC
  \!ifnextchar/{\!finish}{\!Qjoin}}

% Commands to cycle through list of coordinates in piecewise linear 
% interpolation mode
\def\!lcurve #1 #2 {%
  \!start (#1,#2)
  \!Ljoin}
\def\!Ljoin#1 #2 {%
  \!ljoin (#1,#2)                    % \!ljoin  is defined in LINEAR
  \!ifnextchar/{\!finish}{\!Ljoin}}

\def\!finish/{\ignorespaces}

% Command to cycle through list of coordinates in histogram mode
\def\!hcurve #1 #2 {%
  \edef\!hxS{#1}%
  \edef\!hyS{#2}%
  \!hjoin}
\def\!hjoin#1 #2 {%
  \putrectangle corners at {\!hxS} {\!hyS} and {#1} {#2}
  \edef\!hxS{#1}%
  \!ifnextchar/{\!finish}{\!hjoin}}


% \vshade: See Subsection 7.3 of the manual.
\def\vshade #1 #2 #3 {%
  \!startvshade (#1,#2,#3)
  \!Shadewhat}

% \hshade: See Subsection 7.4 of the manual.
\def\hshade #1 #2 #3 {%
  \!starthshade (#1,#2,#3)
  \!Shadewhat}

% Commands to cycle through coordinates and optional "edge effect"
% fields while shading.
\def\!Shadewhat{%
  \futurelet\!nextchar\!Shade}
\def\!Shade{%
  \if <\!nextchar
    \def\!nextShade{\!!Shade}%
  \else
    \if /\!nextchar
      \def\!nextShade{\!finish}%
    \else
      \def\!nextShade{\!!!Shade}%
    \fi
  \fi
  \!nextShade}
\def\!!lShade<#1> #2 #3 #4 {%
  \!lshade <#1> (#2,#3,#4)                 % \!lshade is defined in SHADING
  \!Shadewhat}
\def\!!!lShade#1 #2 #3 {%
  \!lshade (#1,#2,#3)
  \!Shadewhat} 
\def\!!qShade<#1> #2 #3 #4 #5 #6 #7 {%
  \!qshade <#1> (#2,#3,#4) (#5,#6,#7)      % \!qshade is defined in SHADING
  \!Shadewhat}
\def\!!!qShade#1 #2 #3 #4 #5 #6 {%
  \!qshade (#1,#2,#3) (#4,#5,#6)
  \!Shadewhat} 

% ** Set default interpolation mode
\setlinear


%  ********************************************
%  *** DASHPATTERNS (Sets up dash patterns) ***
%  ********************************************

%  **  User commands:
%  **    \setdashpattern <DIMEN1,DIMEN2,DIMEN3,...>
%  **    \setdots <INTRADOT_DISTANCE>
%  **    \setdotsnear <INTRADOT_DISTANCE> for <ARC LENGTH>
%  **    \setdashes <DASH/SKIP_DISTANCE>
%  **    \setdashesnear <DASH/SKIP_DISTANCE> for <ARC LENGTH>
%  **    \setsolid
%  **    \findlength {CURVE CMDS}
 
%  **  Internal commands:
%  **    \!dashingon
%  **    \!dashingoff
 
%  **  Dash patterns are specified by a balanced token list whose complete
%  **    expansion has the form: DIMEN1,DIMEN2,DIMEN3,DIMEN4,... ; this produces
%  **    an arc of length DIMEN1, a skip of length DIMEN2, an arc of length
%  **    DIMEN3, a skip of length DIMEN4, ... .  Any number of DIMEN values may
%  **    be given. The pattern is repeated as many times (perhaps fractional)
%  **    as necessary to draw the curve. 
%  **  A dash pattern remains in effect until it is overridden by a call to
%  **    \setdashpattern, or to \setdots, \setdotsnear ... , \setdashes, 
%  **    \setdashesnear ... , or \setsolid.
%  **  Solid lines are the default.
 
 
%  **  \def\setdashpattern <DIMEN1,DIMEN2,DIMEN3,...>
%  **  The following routine converts a balanced list of tokens whose
%  **  complete expansion has the form  DIMEN1,DIMEN2, ... , DIMENk  into 
%  **  three list macros that are used in drawing dashed rules and curves:
%  **    !Flist:   \!Rule{DIMEN1}\!Skip{DIMEN2}\!Rule{DIMEN3}\!Skip{DIMEN4} ...
%  **    !Blist:   ...\!Skip{DIMEN4}\!Rule{DIMEN3}\!Skip{DIMEN2}\!Rule{DIMEN1}
%  **    !UDlist:  \\{DIMEN1}\\{DIMEN2}\\{DIMEN3}\\{DIMEN4} ...;
%  **  calculates \!leaderlength := DIMEN1 + ... + DIMENk; and
%  **  sets the curve drawing routines to dash mode.
%  **  Those lists are used by the curve drawing routines.
%  **  Dimenj ... may be given as an explicit dimension (e.g., 5pt), or
%  **  as an expression involving a dimension register (e.g., -2.5\dimen0).
%  **  See Subsection 6.2 of the manual
\def\setdashpattern <#1>{%
  \def\!Flist{}\def\!Blist{}\def\!UDlist{}%
  \!countA=0
  \!ecfor\!item:=#1\do{%
    \!dimenA=\!item\relax
    \expandafter\!rightappend\the\!dimenA\withCS{\\}\to\!UDlist%
    \advance\!countA  1
    \ifodd\!countA
      \expandafter\!rightappend\the\!dimenA\withCS{\!Rule}\to\!Flist%
      \expandafter\!leftappend\the\!dimenA\withCS{\!Rule}\to\!Blist%
    \else 
      \expandafter\!rightappend\the\!dimenA\withCS{\!Skip}\to\!Flist%
      \expandafter\!leftappend\the\!dimenA\withCS{\!Skip}\to\!Blist%
    \fi}%
  \!leaderlength=\!zpt
  \def\!Rule##1{\advance\!leaderlength  ##1}%
  \def\!Skip##1{\advance\!leaderlength  ##1}%
  \!Flist%
  \ifdim\!leaderlength>\!zpt 
  \else
    \def\!Flist{\!Skip{24in}}\def\!Blist{\!Skip{24in}}\ignorespaces
    \def\!UDlist{\\{\!zpt}\\{24in}}\ignorespaces
    \!leaderlength=24in
  \fi
  \!dashingon}   
 
 
%  **  \!dashingon  -- puts the curve drawing routines into dash mode
%  **  \!dashingoff -- puts the curve drawing routines into solid mode
%  **  These are internal commands, invoked by \setdashpattern and \setsolid
\def\!dashingon{%
  \def\!advancedashing{\!!advancedashing}%
  \def\!drawlinearsegment{\!lineardashed}%
  \def\!puthline{\!putdashedhline}%
  \def\!putvline{\!putdashedvline}%
%  \def\!putsline{\!putdashedsline}%
  \ignorespaces}% 
\def\!dashingoff{%
  \def\!advancedashing{\relax}%
  \def\!drawlinearsegment{\!linearsolid}%
  \def\!puthline{\!putsolidhline}%
  \def\!putvline{\!putsolidvline}%
%  \def\!putsline{\!putsolidsline}%
  \ignorespaces}
 
 
%  **  \setdots <LENGTH>  --  sets up a dot/skip pattern where dot (actually
%  **    the current plotsymbol) is plunked down once for every LENGTH 
%  **    traveled along the curve.  LENGTH defaults to 5pt.
%  **    See Subsection 6.1 of the manual.
\def\setdots{%
  \!ifnextchar<{\!setdots}{\!setdots<5pt>}}
\def\!setdots<#1>{%
  \!dimenB=#1\advance\!dimenB -\plotsymbolspacing
  \ifdim\!dimenB<\!zpt
    \!dimenB=\!zpt
  \fi
\setdashpattern <\plotsymbolspacing,\!dimenB>}
 
% ** \setdotsnear <LENGTH> for <ARC LENGTH>
% ** sets up a dot pattern where the dots are approximately LENGTH apart,
% ** the total length of the pattern is ARC LENGTH, and the pattern
% ** begins and ends with a dot. See Subsection 6.3 of the manual.
\def\setdotsnear <#1> for <#2>{%
  \!dimenB=#2\relax  \advance\!dimenB -.05pt  
  \!dimenC=#1\relax  \!countA=\!dimenC 
  \!dimenD=\!dimenB  \advance\!dimenD .5\!dimenC  \!countB=\!dimenD
  \divide \!countB  \!countA
  \ifnum 1>\!countB 
    \!countB=1
  \fi
  \divide\!dimenB  \!countB
  \setdots <\!dimenB>}
 
%  **  \setdashes <LENGTH>  --  sets up a dash/skip pattern where the dash
%  **    and the skip are each of length LENGTH (the dash is formed by
%  **    plunking down the current plotsymbol over an arc of length LENGTH
%  **    and so may actually be longer than LENGTH.  LENGTH defaults to 5pt.
%  **    See Subsection 6.1 of the manual.
\def\setdashes{%
  \!ifnextchar<{\!setdashes}{\!setdashes<5pt>}}
\def\!setdashes<#1>{\setdashpattern <#1,#1>}
 
% ** \setdashesnear ...
% ** Like \setdotsnear; the pattern begins and ends with a dash.
% ** See Subsection 6.3 of the manual.
\def\setdashesnear <#1> for <#2>{%
  \!dimenB=#2\relax  
  \!dimenC=#1\relax  \!countA=\!dimenC 
  \!dimenD=\!dimenB  \advance\!dimenD .5\!dimenC  \!countB=\!dimenD
  \divide \!countB  \!countA
  \ifodd \!countB 
  \else 
    \advance \!countB  1
  \fi
  \divide\!dimenB  \!countB
  \setdashes <\!dimenB>}
 
%  **  \setsolid  --  puts the curve drawing routines in "solid line" mode,
%  **    the default mode.  See Subsection 6.1 of the manual.
\def\setsolid{%
  \def\!Flist{\!Rule{24in}}\def\!Blist{\!Rule{24in}}%  
  \def\!UDlist{\\{24in}\\{\!zpt}}%
  \!dashingoff}  
\setsolid

%  **  \findlength {CURVE CMDS}
%  **  PiCTeX executes the \start, \ljoin, and \qjoin cmds comprising
%  **  CURVE CMDS without plotting anything, but stashes the length
%  **  of the phantom curve away in \totalarclength.
%  **  See Subsection 6.3 of the manual.
\def\findlength#1{%
  \begingroup
    \setdashpattern <0pt, \maxdimen>
    \setplotsymbol ({})  
    \dontsavelinesandcurves
    #1%
  \endgroup
  \ignorespaces}


% *************************************************************
% *** DIVISION  (Does long division of dimension registers) ***
% *************************************************************
 
% ** User command:
% **   \Divide {DIVIDEND} by {DIVISOR} forming {RESULT}
  
% ** Internal command
% **   \!divide{DIVIDEND}{DIVISOR}{RESULT}
 
% **  \!divide DIVIDEND [by] DIVISOR [to get] ANSWER
% **  Divides the dimension DIVIDEND by the dimension DIVISOR, placing the 
% **  quotient in the dimension register ANSWER.  Values are understood to 
% **  be in points.  E.g.  12.5pt/1.4pt=8.92857pt.
% **  Quotient is accurate to 1/65536pt=2**[-16]pt
% **  |DIVISOR| should be < 2048pt (about 28 inches).
\def\!divide#1#2#3{%
  \!dimenB=#1%                      **  dimB  holds current remainder (r)
  \!dimenC=#2%                      **  dimC  holds divisor (d)
  \!dimenD=\!dimenB%                **  dimD  holds quotient q=r/d for this 
  \divide \!dimenD \!dimenC%        **    step, in units of scaled pts
  \!dimenA=\!dimenD%                **  dimA  eventually holds answer (a)
  \multiply\!dimenD \!dimenC%       **  r <-- r - dq
  \advance\!dimenB -\!dimenD%       **  First step complete. Have integer part
%                                   **  of a, and corresponding remainder.
  \!dimenD=\!dimenC%                **  Temporarily use dimD to hold |d|
    \ifdim\!dimenD<\!zpt \!dimenD=-\!dimenD 
  \fi
  \ifdim\!dimenD<64pt%              **  Branch on the magnitude of |d|
    \!divstep[\!tfs]\!divstep[\!tfs]%
  \else 
    \!!divide
  \fi
  #3=\!dimenA\ignorespaces}

% **  The following code handles divisors  d  with 
% **    (1)  .88in =  64pt <= d <  256pt =  3.54in
% **    (2) 3.54in = 256pt <= d < 2048pt = 28.34in
% **  Anything bigger than that may result in an overflow condition.
% **  For our purposes, we should never even see case (2).
\def\!!divide{%
  \ifdim\!dimenD<256pt
    \!divstep[64]\!divstep[32]\!divstep[32]%
  \else 
    \!divstep[8]\!divstep[8]\!divstep[8]\!divstep[8]\!divstep[8]%
    \!dimenA=2\!dimenA
  \fi}
 
 
% **  The following macro does the real long division work.
\def\!divstep[#1]{%                 **  #1 = "B"
  \!dimenB=#1\!dimenB%              **  r <-- B*r
  \!dimenD=\!dimenB%                **  dimD  holds quotient q=r/d for this 
    \divide \!dimenD by \!dimenC%   **    step, in units of scaled pts
  \!dimenA=#1\!dimenA%              **  a <-- B*a + q
    \advance\!dimenA by \!dimenD%
  \multiply\!dimenD by \!dimenC%    **  r <-- r - dq
    \advance\!dimenB by -\!dimenD}
 
% **  \Divide:  See Subsection 9.3 of the manual.
\def\Divide <#1> by <#2> forming <#3> {%
  \!divide{#1}{#2}{#3}}


% *********************************************
% *** ELLIPSES (Draws ellipses and circles) ***
% *********************************************
 
% ** User commands
% **   \ellipticalarc  axes ratio A:B  DEGREES degrees from XSTART YSTART 
% **      center at XCENTER YCENTER 
% **   \circulararc DEGREES degrees from XSTART YSTART 
% **      center at XCENTER YCENTER 
 
% ** Internal command
% **   \!sinandcos{32*ANGLE in radians}{32*SIN}{32*COS}
 
 
% **   \ellipticalarc  axes ratio A:B  DEGREES degrees from XSTART YSTART 
% **      center at XCENTER YCENTER 
% **    Draws a elliptical arc starting at the coordinate point (XSTART,YSTART).
% **    The center of the ellipse of which the arc is a segment is at 
% **      (XCENTER,YCENTER).
% **    The arc extends through an angle of DEGREES degrees (may be + or -).
% **    A:B is the ratio of the length of the xaxis to the length of
% **      the yaxis of the ellipse
% **    Sqrt{[(XSTART-XCENTER)/A]**2 + [(YSTART-YCENTER)/B]**2}
% **      must be < 512pt (about 7in).
% **    Doesn't modify the dimensions (ht, dp, wd) of the PiCture under
% **      construction.
 
% ** \circulararc  --  See Subsection 5.3 of the manual.
\def\circulararc{%
  \ellipticalarc axes ratio 1:1 }

% ** \ellipticalarc  --  See Subsection 5.3 of the manual.
\def\ellipticalarc axes ratio #1:#2 #3 degrees from #4 #5 center at #6 #7 {%
  \!angle=#3pt\relax%                    ** get angle
  \ifdim\!angle>\!zpt 
    \def\!sign{}%                        ** counterclockwise
  \else 
    \def\!sign{-}\!angle=-\!angle%       ** clockwise
  \fi
  \!xxloc=\!M{#6}\!xunit%                ** convert CENTER to dimension
  \!yyloc=\!M{#7}\!yunit     
  \!xxS=\!M{#4}\!xunit%                  ** get STARTing point on rim of ellipse
  \!yyS=\!M{#5}\!yunit
  \advance\!xxS -\!xxloc%                ** make center of ellipse (0,0)
  \advance\!yyS -\!yyloc
  \!divide\!xxS{#1pt}\!xxS %             ** scale point on ellipse to point on 
  \!divide\!yyS{#2pt}\!yyS %                 corresponding circle
%
  \let\!MC=\!M%                          ** save current c/d mode
  \!setdimenmode%                        ** go into dimension mode
%
  \!xS=#1\!xxS  \advance\!xS\!xxloc
  \!yS=#2\!yyS  \advance\!yS\!yyloc
  \!start (\!xS,\!yS)%
  \!loop\ifdim\!angle>14.9999pt%         ** draw in major portion of ellipse 
    \!rotate(\!xxS,\!yyS)by(\!cos,\!sign\!sin)to(\!xxM,\!yyM) 
    \!rotate(\!xxM,\!yyM)by(\!cos,\!sign\!sin)to(\!xxE,\!yyE)
    \!xM=#1\!xxM  \advance\!xM\!xxloc  \!yM=#2\!yyM  \advance\!yM\!yyloc
    \!xE=#1\!xxE  \advance\!xE\!xxloc  \!yE=#2\!yyE  \advance\!yE\!yyloc
    \!qjoin (\!xM,\!yM) (\!xE,\!yE)
    \!xxS=\!xxE  \!yyS=\!yyE 
    \advance \!angle -15pt
  \repeat
  \ifdim\!angle>\!zpt%                   ** complete remaining arc, if any
    \!angle=100.53096\!angle%            ** convert angle to radians, divide
    \divide \!angle 360 %                **   by 2, and multiply by 32
    \!sinandcos\!angle\!!sin\!!cos%      ** get 32*sin & 32*cos
    \!rotate(\!xxS,\!yyS)by(\!!cos,\!sign\!!sin)to(\!xxM,\!yyM) 
    \!rotate(\!xxM,\!yyM)by(\!!cos,\!sign\!!sin)to(\!xxE,\!yyE)
    \!xM=#1\!xxM  \advance\!xM\!xxloc  \!yM=#2\!yyM  \advance\!yM\!yyloc
    \!xE=#1\!xxE  \advance\!xE\!xxloc  \!yE=#2\!yyE  \advance\!yE\!yyloc
    \!qjoin (\!xM,\!yM) (\!xE,\!yE)
  \fi
%
  \let\!M=\!MC%                          ** restore c/d mode
  \ignorespaces}%                        **   if appropriate
 
 
%  ** \!rotate(XREG,YREG)by(32cos,32sin)to(XXREG,YYREG)
%  ** rotates (XREG,YREG) by angle with specfied scaled cos & sin to
%  ** (XXREG,YYREG).  Uses \!dimenA & \!dimenB as scratch registers.
\def\!rotate(#1,#2)by(#3,#4)to(#5,#6){% 
  \!dimenA=#3#1\advance \!dimenA -#4#2%   ** Rcos(x+t)=Rcosx*cost - Rsinx*sint
  \!dimenB=#3#2\advance \!dimenB  #4#1%   ** Rsin(x+t)=Rsinx*cost + Rcosx*sint
  \divide \!dimenA 32  \divide \!dimenB 32 
  #5=\!dimenA  #6=\!dimenB
  \ignorespaces}
\def\!sin{4.17684}%                       ** 32*sin(pi/24) (pi/24=7.5deg)
\def\!cos{31.72624}%                      ** 32*cos(pi/24)
 
 
%  ** \!sinandcos{32*ANGLE in radians}{\SINCS}{\COSCS}
%  **   Computes the 32*sine and 32*cosine of a small ANGLE expressed in 
%  **   radians/32 and puts these values in the replacement texts of 
%  **   \SINCS and \COSCS
\def\!sinandcos#1#2#3{%
 \!dimenD=#1%                **  angle is expressed in radians/32: 1pt = 1/32rad
 \!dimenA=\!dimenD%          **  dimA will eventually contain 32sin(angle)in pts
 \!dimenB=32pt%              **  dimB will eventually contain 32cos(angle)in pts
 \!removept\!dimenD\!value%  **  get value of 32*angle, without "pt"
 \!dimenC=\!dimenD%          **  holds 32*angle**i/i! in pts
 \!dimenC=\!value\!dimenC \divide\!dimenC by 64 %   ** now 32*angle**2/2
 \advance\!dimenB by -\!dimenC%                     ** 32-32*angle**2/2
 \!dimenC=\!value\!dimenC \divide\!dimenC by 96 %   ** now 32*angle**3/3!
 \advance\!dimenA by -\!dimenC%                     ** now 32*(angle-angle**3/6)
 \!dimenC=\!value\!dimenC \divide\!dimenC by 128 %  ** now 32*angle**4/4!
 \advance\!dimenB by \!dimenC%
 \!removept\!dimenA#2%                              ** set 32*sin(angle)
 \!removept\!dimenB#3%                              ** set 32*cos(angle)
 \ignorespaces}


% *****************************************************************
% ***  RULES  (Draws rules, i.e., horizontal & vertical lines)  ***
% *****************************************************************

% **  User command:
% **    \putrule [<XDIMEN,YDIMEN>] from  XCOORD1 YCOORD1 
% **      to  XCOORD2 YCOORD2 

% **  Internal commands:
% **    \!puthline [<XDIMEN,YDIMEN>]    (h = horizontal)
% **      Set by dashpat to either: \!putsolidhline  or \!putdashedhline
% **    \!putvline [<XDIMEN,YDIMEN>]    (v = vertical)
% **      Either:  \!putsolidvline  or  \!putdashedvline


% **  \putrule [<XDIMEN,YDIMEN>] from XCOORD1 YCOORD1
% **    to XCOORD2 YCOORD2
% **  Draws a rule -- dashed or solid depending on the current dash pattern --
% **    from (X1,Y1) to (X2,Y2).  Uses TEK's  \hrule & \vrule & \leaders  
% **    constructions to handle horizontal & vertical lines efficiently both
% **    in terms of execution time and space in the DVI file.  
% **  See Subsection 4.1 of the manual.
\def\putrule#1from #2 #3 to #4 #5 {%
  \!xloc=\!M{#2}\!xunit  \!xxloc=\!M{#4}\!xunit%   
  \!yloc=\!M{#3}\!yunit  \!yyloc=\!M{#5}\!yunit%           
  \!dxpos=\!xxloc  \advance\!dxpos by -\!xloc
  \!dypos=\!yyloc  \advance\!dypos by -\!yloc
%
  \ifdim\!dypos=\!zpt
    \def\!!Line{\!puthline{#1}}\ignorespaces
  \else
    \ifdim\!dxpos=\!zpt
      \def\!!Line{\!putvline{#1}}\ignorespaces
    \else 
       \def\!!Line{}
    \fi
  \fi
  \let\!ML=\!M%           ** save current coord\dimen mode
  \!setdimenmode%         ** express locations in dimens
  \!!Line%
  \let\!M=\!ML%           ** restore previous c/d mode
  \ignorespaces}
 
 
% **  \!putsolidhline [<XDIMEN,YDIMEN>]
% **  Place horizontal solid line
\def\!putsolidhline#1{%
  \ifdim\!dxpos>\!zpt 
    \put{\!hline\!dxpos}#1[l] at {\!xloc} {\!yloc}
  \else 
    \put{\!hline{-\!dxpos}}#1[l] at {\!xxloc} {\!yyloc}
  \fi
  \ignorespaces}
 
% **  \!putsolidvline [shifted <XDIMEN,YDIMEN>]
% **  Place vertical solid line
\def\!putsolidvline#1{%
  \ifdim\!dypos>\!zpt 
    \put{\!vline\!dypos}#1[b] at {\!xloc} {\!yloc}
  \else 
    \put{\!vline{-\!dypos}}#1[b] at {\!xxloc} {\!yyloc}
  \fi
  \ignorespaces}
 
\def\!hline#1{\hbox to #1{\leaders \hrule height\linethickness\hfill}}
\def\!vline#1{\vbox to #1{\leaders \vrule width\linethickness\vfill}}
 
 
% **  \!putdashedhline [<XDIMEN,YDIMEN>]
% **  Place dashed horizontal line
\def\!putdashedhline#1{%
  \ifdim\!dxpos>\!zpt 
    \!DLsetup\!Flist\!dxpos
    \put{\hbox to \!totalleaderlength{\!hleaders}\!hpartialpattern\!Rtrunc}
      #1[l] at {\!xloc} {\!yloc} 
  \else 
    \!DLsetup\!Blist{-\!dxpos}
    \put{\!hpartialpattern\!Ltrunc\hbox to \!totalleaderlength{\!hleaders}}
      #1[r] at {\!xloc} {\!yloc} 
  \fi
  \ignorespaces}
 
% **  \!putdashedhline [<XDIMEN,YDIMEN>]
% **  Place dashed vertical line
\def\!putdashedvline#1{%
  \!dypos=-\!dypos%            ** vertical leaders go from top to bottom
  \ifdim\!dypos>\!zpt 
    \!DLsetup\!Flist\!dypos 
    \put{\vbox{\vbox to \!totalleaderlength{\!vleaders}
      \!vpartialpattern\!Rtrunc}}#1[t] at {\!xloc} {\!yloc} 
  \else 
    \!DLsetup\!Blist{-\!dypos}
    \put{\vbox{\!vpartialpattern\!Ltrunc
      \vbox to \!totalleaderlength{\!vleaders}}}#1[b] at {\!xloc} {\!yloc} 
  \fi
  \ignorespaces}
 

% **  The rest of the macros in this section are subroutines used by 
% **  \!putdashedhline and \!putdashedvline.
\def\!DLsetup#1#2{%            ** Dashed-Line set up
  \let\!RSlist=#1%             ** set !Rule-Skip list
  \!countB=#2%                 ** convert rule length to integer (number of sps)
  \!countA=\!leaderlength%     ** ditto, leaderlength
  \divide\!countB by \!countA% ** number of complete leader units
  \!totalleaderlength=\!countB\!leaderlength
  \!Rresiduallength=#2%
  \advance \!Rresiduallength by -\!totalleaderlength%  \** excess length
  \!Lresiduallength=\!leaderlength
  \advance \!Lresiduallength by -\!Rresiduallength
  \ignorespaces}
 
\def\!hleaders{%
  \def\!Rule##1{\vrule height\linethickness width##1}%
  \def\!Skip##1{\hskip##1}%
  \leaders\hbox{\!RSlist}\hfill}
 
\def\!hpartialpattern#1{%
  \!dimenA=\!zpt \!dimenB=\!zpt 
  \def\!Rule##1{#1{##1}\vrule height\linethickness width\!dimenD}%
  \def\!Skip##1{#1{##1}\hskip\!dimenD}%
  \!RSlist}
 
\def\!vleaders{%
  \def\!Rule##1{\hrule width\linethickness height##1}%
  \def\!Skip##1{\vskip##1}%
  \leaders\vbox{\!RSlist}\vfill}
 
\def\!vpartialpattern#1{%
  \!dimenA=\!zpt \!dimenB=\!zpt 
  \def\!Rule##1{#1{##1}\hrule width\linethickness height\!dimenD}%
  \def\!Skip##1{#1{##1}\vskip\!dimenD}%
  \!RSlist}
 
\def\!Rtrunc#1{\!trunc{#1}>\!Rresiduallength}
\def\!Ltrunc#1{\!trunc{#1}<\!Lresiduallength}
 
\def\!trunc#1#2#3{%          
  \!dimenA=\!dimenB         
  \advance\!dimenB by #1%
  \!dimenD=\!dimenB  \ifdim\!dimenD#2#3\!dimenD=#3\fi
  \!dimenC=\!dimenA  \ifdim\!dimenC#2#3\!dimenC=#3\fi
  \advance \!dimenD by -\!dimenC}
 

%  ****************************************************************
%  ***  LINEAR ARC  (Draws straight lines -- solid and dashed)  ***
%  ****************************************************************
 
%  **  User commands
%  **    \inboundscheckoff
%  **    \inboundscheckon
   
%  **  Internal commands 
%  **    \!start (XCOORD,YCOORD)
%  **    \!ljoin (XCOORD,YCOORD)
%  **    \!drawlinearsegment  --  set by \dashpat to either
%  **      \!linearsolid  or  \!lineardashed
%  **    \!advancedashing     --  set by \dashpat to either
%  **       \relax  or  \!!advancedashing
%  **    \!plotifinbounds     --  set by \inboundscheck off/on to either
%  **       \!plot  or  \!!plotifinbounds
%  **    \!initinboundscheck  --  set by \inboundscheck off/on to either
%  **       \relax  or  \!!initinboundscheck
 
 
%  \plotsymbolspacing  ** distance between consecutive plot positions
%  \!xS                ** starting x
%  \!yS                ** starting y
%  \!xE                ** ending   x
%  \!yE                ** ending   y
%  \!xdiff             ** x_end - x_start
%  \!ydiff             ** y_end - y_start
%  \!distacross        ** how far along curve next point to be plotted is
%  \!arclength         ** approximate length of arc for current interval
%  \!downlength        ** remaining length for "pen" to be down    
%  \!uplength          ** length for "pen" to be down    
%  \!intervalno        ** counts segments to curve
%  \totalarclength     ** cumulative distance along curve
%  \!npoints           ** approximately  (arc length / plotsymbolspacing)
 
%  **  Calls -- \!Pythag, \!divide, \!plot
 
 
%  **  \!start (XCOORD,YCOORD)
%  **  Sets initial point for linearly (or quadratically) interpolated curve
\def\!start (#1,#2){%
  \!plotxorigin=\!xorigin  \advance \!plotxorigin by \!plotsymbolxshift
  \!plotyorigin=\!yorigin  \advance \!plotyorigin by \!plotsymbolyshift
  \!xS=\!M{#1}\!xunit \!yS=\!M{#2}\!yunit
  \!rotateaboutpivot\!xS\!yS
  \!copylist\!UDlist\to\!!UDlist% **\!UDlist has the form \\{dimen1}\\{dimen2}..
%                                 ** Routine will draw dashed line with pen
%                                 ** down for dimen1, up for dimen2, ...
  \!getnextvalueof\!downlength\from\!!UDlist
  \!distacross=\!zpt%             ** 1st point goes at start of curve
  \!intervalno=0 %                ** initialize interval counter
  \global\totalarclength=\!zpt%   ** initialize distance traveled along curve
  \ignorespaces}
 

%  **  \!ljoin (XCOORD,YCOORD) 
%  **  Draws a straight line starting at the last point specified
%  **    by the most recent \!start, \!ljoin, or \!qjoin, and
%  **    ending at (XCOORD,YCOORD).
\def\!ljoin (#1,#2){%
  \advance\!intervalno by 1
  \!xE=\!M{#1}\!xunit \!yE=\!M{#2}\!yunit
  \!rotateaboutpivot\!xE\!yE
  \!xdiff=\!xE \advance \!xdiff by -\!xS%**  xdiff = xE - xS
  \!ydiff=\!yE \advance \!ydiff by -\!yS%**  ydiff = yE - yS
  \!Pythag\!xdiff\!ydiff\!arclength%     **  arclength = sqrt(xdiff**2+ydiff**2) 
  \global\advance \totalarclength by \!arclength%
  \!drawlinearsegment%   ** set by dashpat to \!linearsolid or \!lineardashed
  \!xS=\!xE \!yS=\!yE%   ** shift ending points to starting points
  \ignorespaces}
 
 
% **  The following routine is used to draw a "solid" line between (xS,yS)
% **  and (xE,yE).  Points are spaced nearly every  \plotsymbolspacing length
% **  along the line.  
\def\!linearsolid{%
  \!npoints=\!arclength
  \!countA=\plotsymbolspacing
  \divide\!npoints by \!countA%      ** now #pts =. arclength/plotsymbolspacing
  \ifnum \!npoints<1 
    \!npoints=1 
  \fi
  \divide\!xdiff by \!npoints
  \divide\!ydiff by \!npoints
  \!xpos=\!xS \!ypos=\!yS
%
  \loop\ifnum\!npoints>-1
    \!plotifinbounds
    \advance \!xpos by \!xdiff
    \advance \!ypos by \!ydiff
    \advance \!npoints by -1
  \repeat
  \ignorespaces}
 
 
% ** The following routine is used to draw a dashed line between (xS,yS)
% ** and (xE,yE). The dash pattern continues from the previous segment.
\def\!lineardashed{%
% **
  \ifdim\!distacross>\!arclength
    \advance \!distacross by -\!arclength  %nothing to plot in this interval
%
  \else
%
    \loop\ifdim\!distacross<\!arclength
%     ** plot point, interpolating linearly in x and y
      \!divide\!distacross\!arclength\!dimenA%  ** dimA = across/arclength
      \!removept\!dimenA\!t%  ** \!t holds value in dimA, without the "pt"
      \!xpos=\!t\!xdiff \advance \!xpos by \!xS
      \!ypos=\!t\!ydiff \advance \!ypos by \!yS
      \!plotifinbounds
      \advance\!distacross by \plotsymbolspacing
      \!advancedashing
    \repeat  
%
    \advance \!distacross by -\!arclength%    ** prepare for next interval 
  \fi
  \ignorespaces}
 
 
\def\!!advancedashing{%
  \advance\!downlength by -\plotsymbolspacing
  \ifdim \!downlength>\!zpt
  \else
    \advance\!distacross by \!downlength
    \!getnextvalueof\!uplength\from\!!UDlist
    \advance\!distacross by \!uplength
    \!getnextvalueof\!downlength\from\!!UDlist
  \fi}
 
 
% ** \inboundscheckoff & \inboundscheckon: See Subsection 5.5 of the manual.
\def\inboundscheckoff{%
  \def\!plotifinbounds{\!plot(\!xpos,\!ypos)}%
  \def\!initinboundscheck{\relax}\ignorespaces}
\def\inboundscheckon{%
  \def\!plotifinbounds{\!!plotifinbounds}%
  \def\!initinboundscheck{\!!initinboundscheck}%
  \!initinboundscheck\ignorespaces} 
\inboundscheckoff
 
% ** The following code plots the current point only if it falls in the
% ** current plotarea.  It doesn't matter if the coordinate system has
% ** changed since the plotarea was set up.  However, shifts of the plot
% ** are ignored (how the plotsymbol stands relative to its plot position is
% ** unknown anyway).
\def\!!plotifinbounds{%
  \ifdim \!xpos<\!checkleft
  \else
    \ifdim \!xpos>\!checkright
    \else
      \ifdim \!ypos<\!checkbot
      \else
         \ifdim \!ypos>\!checktop
         \else
           \!plot(\!xpos,\!ypos)
         \fi 
      \fi
    \fi
  \fi}
 
 
\def\!!initinboundscheck{%
  \!checkleft=\!arealloc     \advance\!checkleft by \!xorigin
  \!checkright=\!arearloc    \advance\!checkright by \!xorigin
  \!checkbot=\!areabloc      \advance\!checkbot by \!yorigin
  \!checktop=\!areatloc      \advance\!checktop by \!yorigin}
 

% *********************************
% *** LOGTEN  (Log_10 function) ***
% *********************************
%
% ** \!logten{X}
% ** Calculates log_10 of X.  X and LOG10(X) are in fixed point notation.
% **  X must be positive; it may have an optional `+' sign; any number
% **  of digits may be specified for X.  The absolute error in LOG10(X) is
% **  less than .0001 (probably < .00006).  That's about as good as you
% **  hope for, since TEX only operates to 5 figures after the decimal
% **  point anyway.

%  \!rootten=3.162278pt       **** These are values are set in ALLOCATIONS
%  \!tenAe=2.543275pt  (=A5)
%  \!tenAc=2.773839pt  (=A3)
%  \!tenAa=8.690286pt  (=A1)

\def\!logten#1#2{%
  \expandafter\!!logten#1\!nil
  \!removept\!dimenF#2%
  \ignorespaces}

\def\!!logten#1#2\!nil{%
  \if -#1%
    \!dimenF=\!zpt
    \def\!next{\ignorespaces}%
  \else
    \if +#1%
      \def\!next{\!!logten#2\!nil}%
    \else
      \if .#1%
        \def\!next{\!!logten0.#2\!nil}%
      \else
        \def\!next{\!!!logten#1#2..\!nil}%
      \fi
    \fi
  \fi
  \!next}

\def\!!!logten#1#2.#3.#4\!nil{%
  \!dimenF=1pt %                 ** DimF holds log10 original argument
  \if 0#1%                      
    \!!logshift#3pt %            ** Argument < 1
  \else %                        ** Argument >= 1
    \!logshift#2/%               ** Shift decimal pt as many places
    \!dimenE=#1.#2#3pt %         **   as there are figures in #2
  \fi %                          ** Now dimE holds revised X want log10 of
  \ifdim \!dimenE<\!rootten%          ** Transform X to XX between sqrt(10) 
    \multiply \!dimenE 10 %           **   and 10*sqrt(10)
    \advance  \!dimenF -1pt
  \fi
  \!dimenG=\!dimenE%                  ** dimG <- (XX + 10)
    \advance\!dimenG 10pt
  \advance\!dimenE -10pt %            ** dimE <- (XX - 10)
  \multiply\!dimenE 10 %              ** dimE = 10*(XX-10)
  \!divide\!dimenE\!dimenG\!dimenE%   ** Now dimE=10t==10*(XX-10)/(XX+10)
  \!removept\!dimenE\!t%              ** !t=10t, with "pt" removed
  \!dimenG=\!t\!dimenE%               ** dimG=100t**2
  \!removept\!dimenG\!tt%             ** !tt=100t**2, with "pt" removed
  \!dimenH=\!tt\!tenAe%               ** dimH=10*a5*(10t)**2 /100
    \divide\!dimenH 100
  \advance\!dimenH \!tenAc%           ** ditto + 10*a3
  \!dimenH=\!tt\!dimenH%              ** ditto * (10t)**2 /100
    \divide\!dimenH 100   
  \advance\!dimenH \!tenAa%           ** ditto + 10*a1
  \!dimenH=\!t\!dimenH%               ** ditto * 10t / 100
    \divide\!dimenH 100 %             ** Now dimH = log10(XX) - 1
  \advance\!dimenF \!dimenH}%         ** dimF = log10(X)

\def\!logshift#1{%
  \if #1/%
    \def\!next{\ignorespaces}%
  \else
    \advance\!dimenF 1pt 
    \def\!next{\!logshift}%
  \fi 
  \!next}
 
 \def\!!logshift#1{%
   \advance\!dimenF -1pt
   \if 0#1%
     \def\!next{\!!logshift}%
   \else
     \if p#1%
       \!dimenF=1pt
       \def\!next{\!dimenE=1p}%
     \else
       \def\!next{\!dimenE=#1.}%
     \fi
   \fi
   \!next}


% ***********************************************************
% *** PICTURES (Basic setups for PiCtures; \put commands) ***
% ***********************************************************
 
% **  User Commands:
% **    \beginpicture
% **    \endpicture    
% **    \endpicturesave <XREG,YREG>
% **    \setcoordinatesystem units <XUNIT,YUNIT> point at XREF YREF
% **    \put {OBJECT} [ORIENTATION] <XSHIFT,YSHIFT> at XCOORD YCOORD
% **    \multiput {OJBECT} [ORIENTATION] <XSHIFT,YSHIFT>) at
% **      XCOORD YCOORD
% **      *NUMBER_OF_TIMES DXCOORD DYCOORD  /
% **    \accountingon
% **    \accountingoff
% **    \stack [ORIENTATION] <LEADING> {LIST OF ITEMS}
% **    \lines [ORIENTATION] {LINES}
% **    \Lines [ORIENTATION] {LINES}
% **    \setdimensionmode
% **    \setcoordinatemode
% **    \Xdistance
% **    \Ydistance
  
% **  Internal commands:
% **    \!setputobject{OBJECT}{[ORIENTATION]<XSHIFT,YSHIFT>}
% **    \!dimenput{OBJECT}[ORIENTATION]<XSHIFT,YSHIFT>(XDIMEN,YDIMEN)
% **    \!setdimenmode
% **    \!setcoordmode
% **    \!ifdimenmode
% **    \!ifcoordmode
  
 
% **  \beginpicture
% **  \endpicture
% **  \endpicturesave <XREG,YREG>
% **    \beginpicture ... \endpicture  creates an hbox.  Objects are
% **    placed in this box using the \put command and the like (see below).
% **    The location of an object is specified in terms of coordinate system(s)
% **    established by \setcoordinatesystem.  Each coordinate system (there
% **    might be just one) specifies the length of 1 horizontal unit, the length
% **    of 1 vertical unit, and the coordinates of a "reference point".  The
% **    reference points of various coordinate systems will be in the same
% **    physical location.  The macros keep track of the size of the objects
% **    and their locations. The resulting hbox is the smallest hbox which
% **    encloses all the objects, and whose TEK reference point is the point
% **    on the left edge of the box closest vertically to the PICTEX reference
% **    point. Using \endpicturesave, you can (globally) save the distance TEK's
% **    reference point is to the right (respectively, up from) PICTEX's 
% **    reference point in the dimension register \XREG (respectively \YREG). 
% **    You can then \put the picture OBJECT into a larger picture so that its
% **    reference point is at (XCOORD,YCOORD) with the command
% **      \put {picture OBJECT} [Bl] <\XREG, \YREG> at  XCOORD YCOORD 

% **  \beginpicture : See Subsection 1.1 of the manual.
\def\beginpicture{%
  \setbox\!picbox=\hbox\bgroup%
  \!xleft=\maxdimen  
  \!xright=-\maxdimen
  \!ybot=\maxdimen
  \!ytop=-\maxdimen}
 
% **  \endpicture : See Subsection 1.1 of the manual.
\def\endpicture{%
  \ifdim\!xleft=\maxdimen%  ** check if nothing was put in picbox
    \!xleft=\!zpt \!xright=\!zpt \!ybot=\!zpt \!ytop=\!zpt 
  \fi
  \global\!Xleft=\!xleft \global\!Xright=\!xright
  \global\!Ybot=\!ybot \global\!Ytop=\!ytop
  \egroup%
  \ht\!picbox=\!Ytop  \dp\!picbox=-\!Ybot
  \ifdim\!Ybot>\!zpt
  \else 
    \ifdim\!Ytop<\!zpt
      \!Ybot=\!Ytop
    \else
      \!Ybot=\!zpt
    \fi
  \fi
  \hbox{\kern-\!Xleft\lower\!Ybot\box\!picbox\kern\!Xright}}
 
% **  \endpicturesave : See Subsection 8.4 of the manual.
\def\endpicturesave <#1,#2>{%
  \endpicture \global #1=\!Xleft \global #2=\!Ybot \ignorespaces}
 
 
% **   \setcoordinatesystem units <XUNIT,YUNIT> 
% **     point at XREF YREF  
% **   Each of `units <XUNIT,YUNIT>' and `point at XREF YREF' 
% **     are optional.
% **   Unit lengths must be given in dimensions (e.g., <10pt,1in>).
% **     Default unit lengths are 1pt, 1pt, or previous unit lengths.
% **   Reference point is specified in current units (e.g., 3 5 ). 
% **     Default reference point is 0 0 , or previous reference point.
% **   Unit lengths and reference points obey TEX's scoping rules.
% **   See Subsection 1.2 of the manual.
\def\setcoordinatesystem{%
  \!ifnextchar{u}{\!getlengths }
    {\!getlengths units <\!xunit,\!yunit>}}
\def\!getlengths units <#1,#2>{%
  \!xunit=#1\relax
  \!yunit=#2\relax
  \!ifcoordmode 
    \let\!SCnext=\!SCccheckforRP
  \else
    \let\!SCnext=\!SCdcheckforRP
  \fi
  \!SCnext}
\def\!SCccheckforRP{%
  \!ifnextchar{p}{\!cgetreference }
    {\!cgetreference point at {\!xref} {\!yref} }}
\def\!cgetreference point at #1 #2 {%
  \edef\!xref{#1}\edef\!yref{#2}%
  \!xorigin=\!xref\!xunit  \!yorigin=\!yref\!yunit  
  \!initinboundscheck % ** See linear.tex
  \ignorespaces}
\def\!SCdcheckforRP{%
  \!ifnextchar{p}{\!dgetreference}%
    {\ignorespaces}}
\def\!dgetreference point at #1 #2 {%
  \!xorigin=#1\relax  \!yorigin=#2\relax
  \ignorespaces}

 
%  ** \put {OBJECT} [XY] <XDIMEN,YDIMEN> at (XCOORD,YCOORD)
%  **   `[XY]' and `<XDIMEN,YDIMEN>' are optional.
%  **   First OBJECT is placed in an hbox (the "objectbox") and then a
%  **     "reference point" is assigned to the objectbox as follows:
%  **     [1] first, the reference point is taken to be the center of the box;
%  **     [2] next, centering is overridden by the specifications
%  **           X=l -- reference point along the left edge of the objectbox
%  **           X=r -- reference point along the right edge of the objectbox
%  **           Y=b -- reference point along the bottom edge of the objectbox
%  **           Y=B -- reference point along the Baseline of the objectbox
%  **           Y=t -- reference point along the top edge of the objectbox;
%  **     [3] finally the reference point is shifted left by XDIMEN, down
%  **           by YDIMEN  (both default to 0pt).
%  **   The objectbox is placed within PICBOX with its reference point at  
%  **     (XCOORD,YCOORD). 
%  **   If OBJECT is a saved box, say  box0, you have to write
%  **     \put{\box0}...   or  \put{\copy0}...
%  **   The objectbox is void after the put.
%  **   See Subsection 2.1 of the manual.
\long\def\put#1#2 at #3 #4 {%
  \!setputobject{#1}{#2}%
  \!xpos=\!M{#3}\!xunit  \!ypos=\!M{#4}\!yunit  
  \!rotateaboutpivot\!xpos\!ypos%
  \advance\!xpos -\!xorigin  \advance\!xpos -\!xshift
  \advance\!ypos -\!yorigin  \advance\!ypos -\!yshift
  \kern\!xpos\raise\!ypos\box\!putobject\kern-\!xpos%
  \!doaccounting\ignorespaces}
 
%  **   \multiput etc.  Like  \put.  The objectbox is not voided until the
%  **     termininating /, and is placed repeatedly with:
%  **     XCOORD YCOORD -- the objectbox is put down with its reference point
%  **       at (XCOORD,YCOORD);
%  **     *N DXCOORD DYCOORD -- each of N times the current
%  **       (xcoord,ycoord) is incremented by (DXCOORD,DYCOORD), and the
%  **       objectbox is put down with its reference point at (xcoord,ycoord)
%  **       (This specification has to follow an XCOORD YCOORD pair)
%  **     See Subsection 2.2 of the manual.
\long\def\multiput #1#2 at {%
  \!setputobject{#1}{#2}%
  \!ifnextchar"{\!putfromfile}{\!multiput}}
\def\!putfromfile"#1"{%
  \expandafter\!multiput \input #1 /}
\def\!multiput{%
  \futurelet\!nextchar\!!multiput}
\def\!!multiput{%
  \if *\!nextchar
    \def\!nextput{\!alsoby}%
  \else
    \if /\!nextchar
      \def\!nextput{\!finishmultiput}%
    \else
      \def\!nextput{\!alsoat}%
    \fi
  \fi
  \!nextput}
\def\!finishmultiput/{%
  \setbox\!putobject=\hbox{}%
  \ignorespaces}
 
%  **   \!alsoat XCOORD YCOORD 
%  **     The objectbox is put down with reference point at XCOORD,YCOORD
\def\!alsoat#1 #2 {%
  \!xpos=\!M{#1}\!xunit  \!ypos=\!M{#2}\!yunit  
  \!rotateaboutpivot\!xpos\!ypos%
  \advance\!xpos -\!xorigin  \advance\!xpos -\!xshift
  \advance\!ypos -\!yorigin  \advance\!ypos -\!yshift
  \kern\!xpos\raise\!ypos\copy\!putobject\kern-\!xpos%
  \!doaccounting
  \!multiput}
 
% **   \!alsoby*N DXCOORD DYCOORD
% **     N times, the current (XCOORD,YCOORD) is advanced by (DXCOORD,DYCOORD),
% **     and the current (shifted, oriented) OBJECT is put down.
\def\!alsoby*#1 #2 #3 {%
  \!dxpos=\!M{#2}\!xunit \!dypos=\!M{#3}\!yunit 
  \!rotateonly\!dxpos\!dypos
  \!ntemp=#1%
  \!!loop\ifnum\!ntemp>0
    \advance\!xpos by \!dxpos  \advance\!ypos by \!dypos
    \kern\!xpos\raise\!ypos\copy\!putobject\kern-\!xpos%
    \advance\!ntemp by -1
  \repeat
  \!doaccounting 
  \!multiput}
 
% **  \accountingoff : Suspends PiCTeX's accounting of the aggregate
% **    size of the picture box.
% **  \accounting on : Reinstates accounting.
% **  See Subsection 8.2 of the manual.
\def\accountingon{\def\!doaccounting{\!!doaccounting}\ignorespaces}
\def\accountingoff{\def\!doaccounting{}\ignorespaces}
\accountingon
\def\!!doaccounting{%
  \!xtemp=\!xpos  
  \!ytemp=\!ypos
  \ifdim\!xtemp<\!xleft 
     \!xleft=\!xtemp 
  \fi
  \advance\!xtemp by  \!wd 
  \ifdim\!xright<\!xtemp 
    \!xright=\!xtemp
  \fi
  \advance\!ytemp by -\!dp
  \ifdim\!ytemp<\!ybot  
    \!ybot=\!ytemp
  \fi
  \advance\!ytemp by  \!dp
  \advance\!ytemp by  \!ht 
  \ifdim\!ytemp>\!ytop  
    \!ytop=\!ytemp  
  \fi}
 
\long\def\!setputobject#1#2{%
  \setbox\!putobject=\hbox{#1}%
  \!ht=\ht\!putobject  \!dp=\dp\!putobject  \!wd=\wd\!putobject
  \wd\!putobject=\!zpt
  \!xshift=.5\!wd   \!yshift=.5\!ht   \advance\!yshift by -.5\!dp
  \edef\!putorientation{#2}%
  \expandafter\!SPOreadA\!putorientation[]\!nil%
  \expandafter\!SPOreadB\!putorientation<\!zpt,\!zpt>\!nil\ignorespaces}
 
\def\!SPOreadA#1[#2]#3\!nil{\!etfor\!orientation:=#2\do\!SPOreviseshift}
 
\def\!SPOreadB#1<#2,#3>#4\!nil{\advance\!xshift by -#2\advance\!yshift by -#3}
 
\def\!SPOreviseshift{%
  \if l\!orientation 
    \!xshift=\!zpt
  \else 
    \if r\!orientation 
      \!xshift=\!wd
    \else 
      \if b\!orientation
        \!yshift=-\!dp
      \else 
        \if B\!orientation 
          \!yshift=\!zpt
        \else 
          \if t\!orientation 
            \!yshift=\!ht
          \fi 
        \fi
      \fi
    \fi
  \fi}
 
 
%  **  \!dimenput{OBJECT} <XDIMEN,YDIMEN> [XY] (XLOC,YLOC)
%  **    This is an internal put routine, similar to \put, except that
%  **    XLOC=distance right from reference point, YLOC=distance up from
%  **    reference point. XLOC and YLOC are dimensions, so this routine
%  **    is completely independent of the current coordinate system. 
%  **    This routine does NOT do ROTATIONS.
\long\def\!dimenput#1#2(#3,#4){%
  \!setputobject{#1}{#2}%
  \!xpos=#3\advance\!xpos by -\!xshift
  \!ypos=#4\advance\!ypos by -\!yshift
  \kern\!xpos\raise\!ypos\box\!putobject\kern-\!xpos%
  \!doaccounting\ignorespaces}
 
 
%  ** The following macros permit the picture drawing routines to be used 
%  ** either in the default "coordinate mode", or in "dimension mode".
%  **   In coordinate mode  \!M(1.5,\!xunit)    expands to  1.5\!xunit
%  **   In dimension  mode  \!M(1.5pt,\!xunit)  expands to  1.5pt
%  ** Dimension mode is useful in coding macros.
%  ** Any special purpose picture macro that sets dimension mode should 
%  ** reset coordinate mode before completion.
%  ** See Subsection 9.2 of the manual.
\def\!setdimenmode{%
  \let\!M=\!M!!\ignorespaces}
\def\!setcoordmode{%
  \let\!M=\!M!\ignorespaces}
\def\!ifcoordmode{%
  \ifx \!M \!M!}
\def\!ifdimenmode{%
  \ifx \!M \!M!!}
\def\!M!#1#2{#1#2} 
\def\!M!!#1#2{#1}
\!setcoordmode
\let\setdimensionmode=\!setdimenmode
\let\setcoordinatemode=\!setcoordmode

%  ** \Xdistance{XCOORD}, \Ydistance{YCOORD}  are the horizontal and
%  **   vertical distances from the origin (0,0) to the point
%  **   (XCOORD,YCOORD)  in the current coordinate system.
%  ** See Subsection 9.2 of the manual.
\def\Xdistance#1{%
  \!M{#1}\!xunit
  \ignorespaces}
\def\Ydistance#1{%
  \!M{#1}\!yunit
  \ignorespaces}

% ** The following macros -- \stack, \line, and \Lines -- are useful for
% **   annotating PiCtures. They can be used outside the \beginpicture ...
% **   \endpicture environment.

% ** \stack [POSITIONING] <LEADING> {VALUESLIST}
% ** Builds a vertical stack of the values in VALUESLIST. Values in
% ** VALUESLIST are separated by commas.  In the resulting stack, values are
% ** centered by default, and positioned flush left (right) if 
% ** POSITIONING = l (r).  Values are separated vertically by LEADING,
% ** which defaults to \stackleading.
% ** See Subsection 2.3 of the manual.
\def\stack{%
  \!ifnextchar[{\!stack}{\!stack[c]}}
\def\!stack[#1]{%
  \let\!lglue=\hfill \let\!rglue=\hfill
  \expandafter\let\csname !#1glue\endcsname=\relax
  \!ifnextchar<{\!!stack}{\!!stack<\stackleading>}}
\def\!!stack<#1>#2{%
  \vbox{\def\!valueslist{}\!ecfor\!value:=#2\do{%
    \expandafter\!rightappend\!value\withCS{\\}\to\!valueslist}%
    \!lop\!valueslist\to\!value
    \let\\=\cr\lineskiplimit=\maxdimen\lineskip=#1%
    \baselineskip=-1000pt\halign{\!lglue##\!rglue\cr \!value\!valueslist\cr}}%
  \ignorespaces}

% ** \lines [POSITIONING] {LINES}
% ** Builds a vertical array of the lines in LINES. Each line in LINES
% ** is terminated by a \cr.  In the resulting array, lines are
% ** centered by default, and positioned flush left (right) if 
% ** POSITIONING = l (r).  The lines in the array are subject to TeX's
% ** usual spacing rules: in particular the baselines are ordinarily an equal
% ** distance apart. The baseline of the array is the baseline of the
% ** the bottom line.
% ** See Subsection 2.3 of the manual.
\def\lines{%
  \!ifnextchar[{\!lines}{\!lines[c]}}
\def\!lines[#1]#2{%
  \let\!lglue=\hfill \let\!rglue=\hfill
  \expandafter\let\csname !#1glue\endcsname=\relax
  \vbox{\halign{\!lglue##\!rglue\cr #2\crcr}}%
  \ignorespaces}

% ** \Lines [POSITIONING] {LINES}
% ** Like \lines, but the baseline of the array is the baseline of the
% ** top line.  See Subsection 2.3 of the manual.
\def\Lines{%
  \!ifnextchar[{\!Lines}{\!Lines[c]}}
\def\!Lines[#1]#2{%
  \let\!lglue=\hfill \let\!rglue=\hfill
  \expandafter\let\csname !#1glue\endcsname=\relax
  \vtop{\halign{\!lglue##\!rglue\cr #2\crcr}}%
  \ignorespaces}


% *********************************************
% *** PLOTTING (Things to do with plotting) ***
% *********************************************
 
% **  User commands
% **    \setplotsymbol ({PLOTSYMBOL} [ORIENTATION] <XSHIFT,YSHIFT>)
% **    \savelinesandcurves on "FILE_NAME"
% **    \dontsavelinesandcurves
% **    \writesavefile {MESSAGE}
% **    \replot {FILE_NAME}
 
% **  Internal command
% **    \!plot(XDIMEN,YDIMEN)
 
% **  \setplotsymbol ({PLOTSYMBOL} [ ] < , >)
% **  Save PLOTSYMBOL away in an hbox for use with curve plotting routines
% **  See Subsection 5.2 of the manual.
\def\setplotsymbol(#1#2){%
  \!setputobject{#1}{#2}
  \setbox\!plotsymbol=\box\!putobject%
  \!plotsymbolxshift=\!xshift 
  \!plotsymbolyshift=\!yshift 
  \ignorespaces}
 
\setplotsymbol({\fiverm .})%       ** initialize plotsymbol
 
 
% **  \!plot is either \!!plot (when no lines and curves are being saved) or
% **                   \!!!plot (when   lines and curves are being saved)
 
% **  \!!plot(XDIMEN,YDIMEN)
% **  Places the current plotsymbol a horizontal distance=XDIMEN-xorigin 
% **    and a vertical distance=YDIMEN-yorigin from the current
% **    reference point.  
\def\!!plot(#1,#2){%
  \!dimenA=-\!plotxorigin \advance \!dimenA by #1%    ** over
  \!dimenB=-\!plotyorigin \advance \!dimenB by #2%    ** up
  \kern\!dimenA\raise\!dimenB\copy\!plotsymbol\kern-\!dimenA%
  \ignorespaces}
 
% **  \!!!plot(XDIMEN,YDIMEN)
% **  Like \!!plot, but also saves the plot location in units of 
% **    scaled point, on file `replotfile'
\def\!!!plot(#1,#2){%
  \!dimenA=-\!plotxorigin \advance \!dimenA by #1%    ** over
  \!dimenB=-\!plotyorigin \advance \!dimenB by #2%    ** up
  \kern\!dimenA\raise\!dimenB\copy\!plotsymbol\kern-\!dimenA%
  \!countE=\!dimenA
  \!countF=\!dimenB
  \immediate\write\!replotfile{\the\!countE,\the\!countF.}%
  \ignorespaces}


% ** \savelinesandcurves on "FILE_NAME"
% **   Switch to save locations used for plotting lines and curves
% **   (No advantage in saving locations for solid lines; however
% **   replotting curve locations speeds things up by a factor of about 4. 
% ** \dontsavelinesandcurves
% **   Terminates \savelinesandcurves. The default.
% ** See Subsection 5.6 of the manual.
\def\savelinesandcurves on "#1" {%
  \immediate\closeout\!replotfile
  \immediate\openout\!replotfile=#1%
  \let\!plot=\!!!plot}

\def\dontsavelinesandcurves {%
  \let\!plot=\!!plot}
\dontsavelinesandcurves

% ** \writesavefile {MESSAGE}
% ** The message is preceded by a "%", so that it won't interfere
% ** with replotting.
% ** See Subsection 5.6 of the manual.
{\catcode`\%=11\xdef\!Commentsignal{%}}
\def\writesavefile#1 {%
  \immediate\write\!replotfile{\!Commentsignal #1}%
  \ignorespaces}

% ** \replot "FILE_NAME"
% **   Replots the locations saved earlier under \savelinesandcurves
% **   on "FILE_NAME"
% ** See Subsection 5.6 of the manual.
\def\replot"#1" {%
  \expandafter\!replot\input #1 /}
\def\!replot#1,#2. {%
  \!dimenA=#1sp
  \kern\!dimenA\raise#2sp\copy\!plotsymbol\kern-\!dimenA
  \futurelet\!nextchar\!!replot}
\def\!!replot{%
  \if /\!nextchar 
    \def\!next{\!finish}%
  \else
    \def\!next{\!replot}%
  \fi
  \!next}
% **************************************************
% ***  PYTHAGORAS  (Euclidean distance function) ***
% **************************************************

% ** User command:
% **   \placehypotenuse for <dimension1> and <dimension2> in <register> 

% ** Internal command:
% **   \!Pythag{X}{Y}{Z}
% **     Input X,Y are dimensions, or dimension registers.
% **     Output Z == sqrt(X**2+Y**2) must be a dimension register.
% **     Assumes that |X|+|Y| < 2048pt (about 28in).
 
% ** Without loss of generality, suppose  x>0, y>0.  Put s = x+y,
% **   z = sqrt(x**2+y**2). Then  z = s*f,  where  f = sqrt(t**2 + (1-t)**2)
% **   = sqrt((1+tau**2)/2), where  t = x/s  and  tau = 2(t-1/2) .
 
% ** Uses the \!divide macro (which uses registers \!dimenA--\!dimenD.
% ** Uses the \!removept macro   (e.g., 123.45pt --> 123.45)
% ** Uses registers \!dimenE--\!dimenI.
\def\!Pythag#1#2#3{%
  \!dimenE=#1\relax                                     
  \ifdim\!dimenE<\!zpt 
    \!dimenE=-\!dimenE 
  \fi%                                            ** dimE = |x|
  \!dimenF=#2\relax
  \ifdim\!dimenF<\!zpt 
    \!dimenF=-\!dimenF 
  \fi%                                            ** dimF = |y|
  \advance \!dimenF by \!dimenE%                  ** dimF = s = |x|+|y|
  \ifdim\!dimenF=\!zpt 
    \!dimenG=\!zpt%                               ** dimG = z = sqrt(x**2+y**2)
  \else 
    \!divide{8\!dimenE}\!dimenF\!dimenE%          ** now dimE = 8t = (8|x|)/s
    \advance\!dimenE by -4pt%                     ** 8tau = (8t-4)*2
      \!dimenE=2\!dimenE%                         **   (tau = 2*t - 1)
    \!removept\!dimenE\!!t%                       ** 8tau, without "pt"
    \!dimenE=\!!t\!dimenE%                        ** (8tau)**2, in pts
    \advance\!dimenE by 64pt%                     ** u = [64 + (8tau)**2]/2
    \divide \!dimenE by 2%                        **   [u = (8f)**2]
    \!dimenH=7pt%                                 ** initial guess g at sqrt(u)
    \!!Pythag\!!Pythag\!!Pythag%                  ** 3 iterations give sqrt(u)
    \!removept\!dimenH\!!t%                       ** 8f=sqrt(u), without "pt"
    \!dimenG=\!!t\!dimenF%                        ** z = (8f)*s/8
    \divide\!dimenG by 8
  \fi
  #3=\!dimenG
  \ignorespaces}

\def\!!Pythag{%                                   ** Newton-Raphson for sqrt
  \!divide\!dimenE\!dimenH\!dimenI%               ** v = u/g
  \advance\!dimenH by \!dimenI%                   ** g <-- (g + u/g)/2
    \divide\!dimenH by 2}

% **  \placehypotenuse for <XI> and <ETA> in <ZETA>
% **  See Subsection 9.3 of the manual.
\def\placehypotenuse for <#1> and <#2> in <#3> {%
  \!Pythag{#1}{#2}{#3}}


% **********************************************
% *** QUADRATIC ARC  (Draws a quadratic arc) ***
% **********************************************
 
% **  Internal command
% **    \!qjoin (XCOORD1,YCOORD1) (XCOORD2,YCOORD2)
 
% **  \!qjoin (XCOORD1,YCOORD1) (XCOORD2,YCOORD2)
% **  Draws an arc starting at the (last) point specified by the most recent
% **  \!qjoin, or \!ljoin, or \!start  and passing through (X_1,Y_1), (X_2,Y_2).
% **  Uses quadratic interpolation in both  x  and  y:  
% **    x(t), 0 <= t <= 1, interpolates  x_0, x_1, x_2  at  t=0, .5, 1
% **    y(t), 0 <= t <= 1, interpolates  y_0, y_1, y_2  at  t=0, .5, 1
 
\def\!qjoin (#1,#2) (#3,#4){%
  \advance\!intervalno by 1
  \!ifcoordmode
    \edef\!xmidpt{#1}\edef\!ymidpt{#2}%
  \else
    \!dimenA=#1\relax \edef\!xmidpt{\the\!dimenA}%
    \!dimenA=#2\relax \edef\!xmidpt{\the\!dimenA}%
  \fi
  \!xM=\!M{#1}\!xunit  \!yM=\!M{#2}\!yunit   \!rotateaboutpivot\!xM\!yM
  \!xE=\!M{#3}\!xunit  \!yE=\!M{#4}\!yunit   \!rotateaboutpivot\!xE\!yE
%
% ** Find coefficients for x(t)=a_x + b_x*t + c_x*t**2
  \!dimenA=\!xM  \advance \!dimenA by -\!xS%   ** dimA = I = xM - xS
  \!dimenB=\!xE  \advance \!dimenB by -\!xM%   ** dimB = II = xE-xM
  \!xB=3\!dimenA \advance \!xB by -\!dimenB%   ** b=3I-II
  \!xC=2\!dimenB \advance \!xC by -2\!dimenA%  ** c=2(II-I)
%
% ** Find coefficients for y(t)=y_x + b_y*t + c_y*t**2
  \!dimenA=\!yM  \advance \!dimenA by -\!yS%   
  \!dimenB=\!yE  \advance \!dimenB by -\!yM%  
  \!yB=3\!dimenA \advance \!yB by -\!dimenB%  
  \!yC=2\!dimenB \advance \!yC by -2\!dimenA% 
%
% ** Use Simpson's rule to calculate arc length over [0,1/2]:
% **   arc length = 1/2[1/6 f(0) + 4/6 f(1/4) + 1/6 f(1/2)]
% ** with f(t) = sqrt(x'(t)**2 + y'(t)**2).
  \!xprime=\!xB  \!yprime=\!yB%          ** x'(t) = b + 2ct
  \!dxprime=.5\!xC  \!dyprime=.5\!yC%    ** dt=1/4 ==> dx'(t) = c/2
  \!getf \!midarclength=\!dimenA
  \!getf \advance \!midarclength by 4\!dimenA
  \!getf \advance \!midarclength by \!dimenA
  \divide \!midarclength by 12
%
% ** Get arc length over [0,1].
  \!arclength=\!dimenA
  \!getf \advance \!arclength by 4\!dimenA
  \!getf \advance \!arclength by \!dimenA
  \divide \!arclength by 12%             ** Now have arc length over [1/2,1]
  \advance \!arclength by \!midarclength
  \global\advance \totalarclength by \!arclength
%
%
% ** Check to see if there's anything to plot in this interval
  \ifdim\!distacross>\!arclength 
    \advance \!distacross by -\!arclength%   ** nothing 
%
  \else
    \!initinverseinterp%  ** initialize for inverse interpolation on arc length
    \loop\ifdim\!distacross<\!arclength%     ** loop over points on arc 
      \!inverseinterp%    ** find  t  such that arc length[0,t] = distacross,
%                         **   using inverse quadratic interpolation
%                         ** now evaluate x(t)=(c*t + b)*t + a
      \!xpos=\!t\!xC \advance\!xpos by \!xB
        \!xpos=\!t\!xpos \advance \!xpos by \!xS
%                                             ** evaluate y(t)
      \!ypos=\!t\!yC \advance\!ypos by \!yB
        \!ypos=\!t\!ypos \advance \!ypos by \!yS
      \!plotifinbounds%                       ** plot point if in bounds
      \advance\!distacross \plotsymbolspacing%** advance arc length for next pt
      \!advancedashing%                       ** see "linear"
    \repeat  
%
    \advance \!distacross by -\!arclength%    ** prepare for next interval 
  \fi
%
  \!xS=\!xE%              ** shift ending points to starting points
  \!yS=\!yE
  \ignorespaces}
 
 
% ** \!getf -- Calculates sqrt(x'(t)**2 + y'(t)**2) and advances
% **   x'(t) and y'(t)
\def\!getf{\!Pythag\!xprime\!yprime\!dimenA%
  \advance\!xprime by \!dxprime
  \advance\!yprime by \!dyprime}
 
 
% ** \!initinverseinterp -- initializes for inverse quadratic interpolation
% ** of arc length provided  1/3 < midarclength/arclength < 2/3; otherwise
% ** initializes for inverse linear interpolation.
\def\!initinverseinterp{%
  \ifdim\!arclength>\!zpt
    \!divide{8\!midarclength}\!arclength\!dimenE% ** dimE=8w=8r/s, where  r 
%                                               **  = midarclength, s=arclength
% **  Test for  w  out of range:  w<1/3  or w>2/3
    \ifdim\!dimenE<\!wmin \!setinverselinear
    \else 
      \ifdim\!dimenE>\!wmax \!setinverselinear
      \else%                                    ** w  in range: initialize
        \def\!inverseinterp{\!inversequad}\ignorespaces
%
% **     Calculate the coefficients  \!beta  and  \!gamma  of the quadratic
% **                    t = \!beta*v + \!gamma*v**2
% **     taking the values  t=0, 1/2, 1  at  v=0, w==r/s, 1  respectively:
% **        \!beta = (1/2 - w**2)/[w(1-w)] 
% **        \!gamma = 1 - beta.
%
         \!removept\!dimenE\!Ew%           **  8w, without "pt"
         \!dimenF=-\!Ew\!dimenE%           **  -(8w)**2
         \advance\!dimenF by 32pt%         **  32 - (8w)**2
         \!dimenG=8pt 
         \advance\!dimenG by -\!dimenE%    **  8 - 8w
         \!dimenG=\!Ew\!dimenG%            **  (8w)*(8-8w)
         \!divide\!dimenF\!dimenG\!beta%   **  beta = (32-(8w)**2)/(8w(8-8w))
%                                          **       = (1/2 - w**2)/(w(1-w))
         \!gamma=1pt
         \advance \!gamma by -\!beta%      **  gamma = 1-beta
      \fi%       ** end of the \ifdim\!dimenE>\!wmax
    \fi%         ** end of the \ifdim\!dimenE<\!wmin
  \fi%           ** end of the \ifdim\!arclength>\!zpt
  \ignorespaces}
 
 
% ** For 0 <= t <= 1, let AL(t) = arclength[0,t]/arclength[0,1]; note
% ** AL(0)=0, AL(1/2)=midarclength/arclength, AL(1)=1.  This routine
% ** calculates an approximation to AL^{-1}(distance across/arclength),
% ** using the assumption that AL^{-1} is quadratic.  Specifically, 
% ** it finds  t  such that
% **    AL^{-1}(v) =. t = v*(\!beta + \!gamma*v)
% ** where  \!beta  and  \!gamma  are set by \!initinv, and where
% ** v=distance across/arclength
\def\!inversequad{%
  \!divide\!distacross\!arclength\!dimenG%   ** dimG = v = distacross/arclength
  \!removept\!dimenG\!v%                     ** v, without "pt"
  \!dimenG=\!v\!gamma%                       ** gamma*v
  \advance\!dimenG by \!beta%                ** beta + gamma*v
  \!dimenG=\!v\!dimenG%                      ** t = v*(beta + gamma*v)
  \!removept\!dimenG\!t}%                    ** t, without "pt"
 
 
% ** When  w <= 1/3  or  w >= 2/3, the following routine writes (using
% ** plain TEK's \wlog command) a warning message on the user's log file,
% ** and initializes for inverse linear interpolation on arc length.
\def\!setinverselinear{%
  \def\!inverseinterp{\!inverselinear}%
  \divide\!dimenE by 8 \!removept\!dimenE\!t
  \!countC=\!intervalno \multiply \!countC 2
  \!countB=\!countC     \advance \!countB -1
  \!countA=\!countB     \advance \!countA -1
  \wlog{\the\!countB th point (\!xmidpt,\!ymidpt) being plotted 
    doesn't lie in the}%
  \wlog{ middle third of the arc between the \the\!countA th 
    and \the\!countC th points:}%
  \wlog{ [arc length \the\!countA\space to \the\!countB]/[arc length 
    \the \!countA\space to \the\!countC]=\!t.}%
  \ignorespaces}
 
% **  Inverse linear interpolation
\def\!inverselinear{% 
  \!divide\!distacross\!arclength\!dimenG
  \!removept\!dimenG\!t}


% **************************************
% **  ROTATIONS  (Handles rotations) ***
% **************************************
 
% ** User commands
% **   \startrotation [by COS_OF_ANGLE SIN_OF_ANGLE] [about XPIVOT YPIVOT]
% **   \stoprotation

% **   \startrotation [by COS_OF_ANGLE SIN_OF_ANGLE] [about XPIVOT YPIVOT]
% ** Future (XCOORD,YCOORD)'s will be rotated about (XPIVOT,YPIVOT) 
% ** by the angle with the give COS and SIN. Both fields are optional.
% ** [COS,SIN] defaults to previous value, or (1,0).
% ** (XPIVOT,YPIVOT) defaults to previous value, or (0,0)
% ** You can't change the coordinate system in the scope of a rotation.
% ** See Subsection 9.1 of the manual.
\def\startrotation{%
  \let\!rotateaboutpivot=\!!rotateaboutpivot
  \let\!rotateonly=\!!rotateonly
  \!ifnextchar{b}{\!getsincos }%
    {\!getsincos by {\!cosrotationangle} {\!sinrotationangle} }}
\def\!getsincos by #1 #2 {%
  \edef\!cosrotationangle{#1}%
  \edef\!sinrotationangle{#2}%
  \!ifcoordmode 
    \let\!ROnext=\!ccheckforpivot
  \else
    \let\!ROnext=\!dcheckforpivot
  \fi
  \!ROnext}
\def\!ccheckforpivot{%
  \!ifnextchar{a}{\!cgetpivot}%
    {\!cgetpivot about {\!xpivotcoord} {\!ypivotcoord} }}
\def\!cgetpivot about #1 #2 {%
  \edef\!xpivotcoord{#1}%
  \edef\!ypivotcoord{#2}%
  \!xpivot=#1\!xunit  \!ypivot=#2\!yunit
  \ignorespaces}
\def\!dcheckforpivot{%
  \!ifnextchar{a}{\!dgetpivot}{\ignorespaces}}
\def\!dgetpivot about #1 #2 {%
  \!xpivot=#1\relax  \!ypivot=#2\relax
  \ignorespaces}
  

% ** Following terminates rotation.
% ** See Subsection 9.1 of the manual.
\def\stoprotation{%
  \let\!rotateaboutpivot=\!!!rotateaboutpivot
  \let\!rotateonly=\!!!rotateonly
  \ignorespaces}
 
% ** !!rotateaboutpivot{XREG}{YREG}
% ** XREG <-- xpvt + cos(angle)*(XREG-xpvt) - sin(angle)*(YREG-ypvt)
% ** YREG <-- ypvt + cos(angle)*(YREG-ypvt) + sin(angle)*(XREG-xpvt)
% ** XREG,YREG are dimension registers. Can't be \!dimenA to \!dimenD
\def\!!rotateaboutpivot#1#2{%
  \!dimenA=#1\relax  \advance\!dimenA -\!xpivot
  \!dimenB=#2\relax  \advance\!dimenB -\!ypivot
  \!dimenC=\!cosrotationangle\!dimenA
    \advance \!dimenC -\!sinrotationangle\!dimenB
  \!dimenD=\!cosrotationangle\!dimenB
    \advance \!dimenD  \!sinrotationangle\!dimenA
  \advance\!dimenC \!xpivot  \advance\!dimenD \!ypivot
  #1=\!dimenC  #2=\!dimenD
  \ignorespaces}

% ** \!!rotateonly{XREG}{YREG}
% ** Like \!!rotateaboutpivot, but with a pivot of  (0,0)
\def\!!rotateonly#1#2{%
  \!dimenA=#1\relax  \!dimenB=#2\relax 
  \!dimenC=\!cosrotationangle\!dimenA
    \advance \!dimenC -\!rotsign\!sinrotationangle\!dimenB
  \!dimenD=\!cosrotationangle\!dimenB
    \advance \!dimenD  \!rotsign\!sinrotationangle\!dimenA
  #1=\!dimenC  #2=\!dimenD
  \ignorespaces}
\def\!rotsign{}
\def\!!!rotateaboutpivot#1#2{\relax}
\def\!!!rotateonly#1#2{\relax}
\stoprotation

\def\!reverserotateonly#1#2{%
  \def\!rotsign{-}%
  \!rotateonly{#1}{#2}%
  \def\!rotsign{}%
  \ignorespaces}


% **********************************
% *** SHADING  (Handles shading) ***
% **********************************

% **  User commands
% **    \setshadegrid [span <SPAN>] [point at XSHADE YSHADE] 
% **    \setshadesymbol [<LS, RS, BS, TS>] ({SHADESYMBOL}
% **      <XDIMEN,YDIMEN> [ORIENTATION])

% **  Internal commands:
% **    \!startvshade  (xS,ybS,ytS)
% **    \!starthshade  (yS,xlS,xrS)
% **    \!lshade [<LS,RS,BS,TS>]
% **       ** when shading vertically:
% **       [the region from (xS,ybS,ytS) to] (xE,ybE,ytE)
% **       ** when shading horizontally:
% **       [the region from (yS,xlS,xrS) to] (yE,xlE,xrE)
% **    \!qshade [<LS,RS,BS,TS>]
% **       ** when shading vertically:
% **       [the region from (xS,ybS,ytS) to] (xM,ybM,ytM)  (xE,ybE,ytE)
% **       ** when shading horizontally:
% **       [the region from (yS,xlS,xrS) to] (yM,xlM,xrM)  (yE,xlE,xrE)
% **    \!lattice{ANCHOR}{SPAN}{LOCATION}{INDEX}{LATTICE LOCATION}
% **    \!override{NOMINAL DIMEN}{REPLACEMENT DIMEN}{DIMEN}


% **  The shading routine can operate either in a "vertical mode" or a
% **  "horizontal mode".  In vertical mode, the region to be shaded is specified
% **  in the form
% **                 {(x,y): xl <= x <= xr  &  yb(x) <= y <= yt(x)}
% **  where  yb  and  yt  are functions of  x.  In horizontal mode, the region
% **  is specified in the form
% **                 {(x,y): yb <= y <= yt  &  xl(y) <= x <= xr(y)}.
% **  The functions  yb  and  yt  may be either both linear or both quadratic;
% **  similarly for  xl  and  xr.  A region with say, piecewise quadratic bottom
% **  and top boundaries, can be shaded by consecutive (vertical) \!qshades,
% **  proceeding from left to right.  Similarly, a region with piecewise     
% **  quadratic left and right boundaries can be shaded by consecutive
% **  (horizontal) \!qshades, proceeding from bottom to top.  More complex
% **  regions can be shaded by partitioning them into appropriate subregions,
% **  and shading those.
    
% **  Shading is accomplished by placing a user-selected shading symbol at
% **  those points of a regular grid which fall within the region to be
% **  shaded.  This region can be "shrunk" so that a largish shading symbol
% **  will not extend outside it.  Shrinking is accomplished by specifying
% **  shrinkages for the left, right, bottom, and top boundaries, in a manner
% **  discussed further below.

% **  \shades and \!joins MUST NOT be intermingled.  Finish drawing a curve
% **  before starting to shade a region, and finish shading a region before
% **  starting to draw a curve.


% **  \setshadegrid [span <SPAN>] [point at XSHADE YSHADE] 
% **  The shading symbol is placed down on the points of a grid centered
% **  at the coordinate point (XSHADE,YSHADE).  The grid points are of the
% **  form (j*SPAN,k*SPAN), with  j+k  even.  SPAN is specified
% **  as a dimension.
% **  (XSHADE,YSHADE) defaults to previous (XSHADE,YSHADE) (or (0,0) if none)
% **  SPAN defaults to previous span (or 5pt if none)
% **  See Subsection 7.2 of the manual.
\def\setshadegrid{%
  \!ifnextchar{s}{\!getspan }
    {\!getspan span <\!dshade>}}
\def\!getspan span <#1>{%
  \!dshade=#1\relax
  \!ifcoordmode 
    \let\!GRnext=\!GRccheckforAP
  \else
    \let\!GRnext=\!GRdcheckforAP
  \fi
  \!GRnext}
\def\!GRccheckforAP{%
  \!ifnextchar{p}{\!cgetanchor }
    {\!cgetanchor point at {\!xshadesave} {\!yshadesave} }}
\def\!cgetanchor point at #1 #2 {%
  \edef\!xshadesave{#1}\edef\!yshadesave{#2}%
  \!xshade=\!xshadesave\!xunit  \!yshade=\!yshadesave\!yunit
  \ignorespaces}
\def\!GRdcheckforAP{%
  \!ifnextchar{p}{\!dgetanchor}%
    {\ignorespaces}}
\def\!dgetanchor point at #1 #2 {%
  \!xshade=#1\relax  \!yshade=#2\relax
  \ignorespaces}

% **  \setshadesymbol  [<LS, RS, BS, TS>] ({SHADESYMBOL}
% **    <XDIMEN,YDIMEN> [ORIENTATION])
% **  Saves SHADESYMBOL away in an hbox for use with shading routines.
% **  A shade symbol will not be plotted if its plot position comes within
% **    distance LS of the left boundary,  RS of the right boundary,  TS of the
% **    top boundary,  BS of the bottom boundary.  These parameters have 
% **    default values that should work in most cases (see below).
% **    To override a default value, specify the replacement value
% **    in the appropriate subfield of the shrinkages field.
% **    0pt may be coded as  "z" (without the quotes).  To accept a
% **    default value, leave the field empty.  Thus
% **      [,z,,5pt]  sets  LS=default, RS=0pt, BS=default, TS=5pt .
% **    Skipping the shrinkages field accepts all the defaults.
% **  See Subsection 7.1 of the manual.
\def\setshadesymbol{%
  \!ifnextchar<{\!setshadesymbol}{\!setshadesymbol<,,,> }}

\def\!setshadesymbol <#1,#2,#3,#4> (#5#6){%
% **  set the shadesymbol
  \!setputobject{#5}{#6}%                        
  \setbox\!shadesymbol=\box\!putobject%
  \!shadesymbolxshift=\!xshift \!shadesymbolyshift=\!yshift
%
% **  set the shrinkages
  \!dimenA=\!xshift \advance\!dimenA \!smidge% ** default LS = xshift - smidge
  \!override\!dimenA{#1}\!lshrinkage%         
  \!dimenA=\!wd \advance \!dimenA -\!xshift%   ** default RS = width - xshift
    \advance\!dimenA \!smidge%                                  - smidge
    \!override\!dimenA{#2}\!rshrinkage
  \!dimenA=\!dp \advance \!dimenA \!yshift%    ** default BS = depth + yshift
    \advance\!dimenA \!smidge%                                  - smidge
    \!override\!dimenA{#3}\!bshrinkage
  \!dimenA=\!ht \advance \!dimenA -\!yshift%   ** default TS = height - yshift
    \advance\!dimenA \!smidge%                                  - smidge
    \!override\!dimenA{#4}\!tshrinkage
  \ignorespaces}
\def\!smidge{-.2pt}%

% ** \!override{NOMINAL DIMEN}{REPLACEMENT DIMEN}{DIMEN}
% ** Overrides the NOMINAL DIMEN by the REPLACEMENT DIMEN to produce DIMEN,
% ** according to the following rules:
% **   REPLACEMENT DIMEN empty: DIMEN <-- NOMINAL DIMEN
% **   REPLACEMENT DIMEN z:     DIMEN <-- 0pt
% **   otherwise:               DIMEN <-- REPLACEMENT DIMEN
% ** DIMEN must be a dimension register
\def\!override#1#2#3{%
  \edef\!!override{#2}% 
  \ifx \!!override\empty
    #3=#1\relax
  \else
    \if z\!!override
      #3=\!zpt
    \else
      \ifx \!!override\!blankz
        #3=\!zpt
      \else
        #3=#2\relax
      \fi
    \fi
  \fi
  \ignorespaces}
\def\!blankz{ z}

\setshadesymbol ({\fiverm .})%       ** initialize plotsymbol
%                                    ** \fivesy ^^B  is a small cross


% ** \!startvshade [at] (xS,ybS,ytS)
% ** Initiates vertical shading mode
\def\!startvshade#1(#2,#3,#4){%
  \let\!!xunit=\!xunit%
  \let\!!yunit=\!yunit%
  \let\!!xshade=\!xshade%
  \let\!!yshade=\!yshade%
  \def\!getshrinkages{\!vgetshrinkages}%
  \let\!setshadelocation=\!vsetshadelocation%
  \!xS=\!M{#2}\!!xunit
  \!ybS=\!M{#3}\!!yunit
  \!ytS=\!M{#4}\!!yunit
  \!shadexorigin=\!xorigin  \advance \!shadexorigin \!shadesymbolxshift
  \!shadeyorigin=\!yorigin  \advance \!shadeyorigin \!shadesymbolyshift
  \ignorespaces}
 
% ** \!starthshade [at] (yS,xlS,xrS)
% ** Initiates horizontal shading mode
\def\!starthshade#1(#2,#3,#4){%
  \let\!!xunit=\!yunit%
  \let\!!yunit=\!xunit%
  \let\!!xshade=\!yshade%
  \let\!!yshade=\!xshade%
  \def\!getshrinkages{\!hgetshrinkages}%
  \let\!setshadelocation=\!hsetshadelocation%
  \!xS=\!M{#2}\!!xunit
  \!ybS=\!M{#3}\!!yunit
  \!ytS=\!M{#4}\!!yunit
  \!shadexorigin=\!xorigin  \advance \!shadexorigin \!shadesymbolxshift
  \!shadeyorigin=\!yorigin  \advance \!shadeyorigin \!shadesymbolyshift
  \ignorespaces}


% **  \!lattice{ANCHOR}{SPAN}{LOCATION}{INDEX}{LATTICE LOCATION}
% **  Consider the lattice with points  ANCHOR + j*SPAN. This routine determines
% **  the index  k  of the smallest lattice point >= LOCATION, and sets
% **  LATTICE LOCATION = ANCHOR + k*SPAN.
% **  INDEX is assumed to be a count register, LATTICE LOCATION a dimen reg.
\def\!lattice#1#2#3#4#5{%
  \!dimenA=#1%                        ** dimA = ANCHOR
  \!dimenB=#2%                        ** dimB = SPAN  (assumed > 0pt)
  \!countB=\!dimenB%                  ** ctB  = SPAN, as a count
%
% ** Determine index of smallest lattice point >= LOCATION
  \!dimenC=#3%                        ** dimC = LOCATION
  \advance\!dimenC -\!dimenA%         ** now dimC = LOCATION-ANCHOR
  \!countA=\!dimenC%                  ** ctA = above, as a count
  \divide\!countA \!countB%           ** now ctA = desired index, if dimC <= 0
  \ifdim\!dimenC>\!zpt
    \!dimenD=\!countA\!dimenB%        ** (tentative k)*span
    \ifdim\!dimenD<\!dimenC%          ** if this is false, ctA = desired index
      \advance\!countA 1 %            ** if true, have to add 1
    \fi
  \fi
%
  \!dimenC=\!countA\!dimenB%          ** lattice location = anchor + ctA*span
    \advance\!dimenC \!dimenA
  #4=\!countA%                        ** the desired index
  #5=\!dimenC%                        ** corresponding lattice location
  \ignorespaces}


% ** \!qshade [with shrinkages] [[LS,RS,BS,TS]]
% ***** during vertical shading:
% **    [the region from (xS,ybS,ytS) to] (xM,ybM,ytM) [and] (xE,ybE,ytE)
% ** Shades the region {(x,y): xS <= x <= xE, yb(x) <= y <= yt(x)}, where 
% **   yb is the quadratic thru (xS,ybS) & (xM,ybM) & (xE,ybE)
% **   yt is the quadratic thru (xS,ytS) & (xM,ybM) & (xE,ytE)
% ** xS,ybS,ytS are either given by \!startvshade or carried over
% **   as the ending values of the immediately preceding \!qshade.
% ** For the interpretation of LS, RS, BS, & TS, see \setshadesymbol. The
% **   values set there can be overridden, for the course of this \!qshade
% **   only, in the same manner as overrides are specified for
% **   \setshadesymbol.
% ***** during horizontal shading:
% **    [the region from (yS,xlS,xrS) to] (yM,xlM,xrM) [and] (yE,xlE,xrE)
\def\!qshade#1(#2,#3,#4)#5(#6,#7,#8){%
  \!xM=\!M{#2}\!!xunit
  \!ybM=\!M{#3}\!!yunit
  \!ytM=\!M{#4}\!!yunit
  \!xE=\!M{#6}\!!xunit
  \!ybE=\!M{#7}\!!yunit
  \!ytE=\!M{#8}\!!yunit
  \!getcoeffs\!xS\!ybS\!xM\!ybM\!xE\!ybE\!ybB\!ybC%**Get coefficients B & C for
  \!getcoeffs\!xS\!ytS\!xM\!ytM\!xE\!ytE\!ytB\!ytC%**y=y0 + B(x-X0) + C(x-X0)**2
  \def\!getylimits{\!qgetylimits}%
  \!shade{#1}\ignorespaces}
 
% ** \!lshade ... (xE,ybE,ytE)
% ** This is like \!qshade, but the top and bottom boundaries are linear,
% ** rather than quadratic.
\def\!lshade#1(#2,#3,#4){%
  \!xE=\!M{#2}\!!xunit
  \!ybE=\!M{#3}\!!yunit
  \!ytE=\!M{#4}\!!yunit
  \!dimenE=\!xE  \advance \!dimenE -\!xS%   ** xE-xS
  \!dimenC=\!ytE \advance \!dimenC -\!ytS%  ** ytE-ytS
  \!divide\!dimenC\!dimenE\!ytB%            ** ytB = (ytE-ytS)/(xE-xS)
  \!dimenC=\!ybE \advance \!dimenC -\!ybS%  ** ybE-ybS
  \!divide\!dimenC\!dimenE\!ybB%            ** ybB = (ybE-ybS)/(xE-xS)
  \def\!getylimits{\!lgetylimits}%
  \!shade{#1}\ignorespaces}
 
% **  \!getcoeffs{X0}{Y0}{X1}{Y1}{X2}{Y2}{B}{C}
% **  Finds  B  and  C  such that the quadratic  y = Y0 + B(x-X0) + C(x-X0)**2
% **  passes through (X1,Y1) and (X2,Y2):  when X0=0=Y0, the formulas are:
% **                   B = S1 - X1*C,   C = (S2-S1)/X2
% **  with
% **                 S1 = Y1/X1,   S2 = (Y2-Y1)/(X2-X1).
\def\!getcoeffs#1#2#3#4#5#6#7#8{% 
  \!dimenC=#4\advance \!dimenC -#2%            ** dimC=Y1-Y0
  \!dimenE=#3\advance \!dimenE -#1%            ** dimE=X1-X0
  \!divide\!dimenC\!dimenE\!dimenF%            ** dimF=S1
  \!dimenC=#6\advance \!dimenC -#4%            ** dimC=Y2-Y1
  \!dimenH=#5\advance \!dimenH -#3%            ** dimH=X2-X1
  \!divide\!dimenC\!dimenH\!dimenG%            ** dimG=S2
  \advance\!dimenG -\!dimenF%                  ** dimG=S2-S1
  \advance \!dimenH \!dimenE%                  ** dimH=X2-X0
  \!divide\!dimenG\!dimenH#8%                  ** C=(S2-S1)/(X2-X0)
  \!removept#8\!t%                             ** C, without "pt"
  #7=-\!t\!dimenE%                             ** -C*(X1-X0)
  \advance #7\!dimenF%                         ** B=S1-C*(X1-X0)
  \ignorespaces}
 
 
\def\!shade#1{%
% ** Get LS,RS,BS,TS for this panel
  \!getshrinkages#1<,,,>\!nil% %       ** now effective LS=dimE, RS=dimF,
%                                      **   BS=dimG, TS=dimH
  \advance \!dimenE \!xS%              ** now dimE=xS+LS
  \!lattice\!!xshade\!dshade\!dimenE%  ** set parity=index of left-mst x-lattice
    \!parity\!xpos%                    **   point >= xS+LS, xpos=its location
  \!dimenF=-\!dimenF%                  ** set dimF=xE-RS
    \advance\!dimenF \!xE
%               
  \!loop\!not{\ifdim\!xpos>\!dimenF}%  ** loop over x-lattice points <= xE-RS
    \!shadecolumn%                 
    \advance\!xpos \!dshade%           ** move over to next column
    \advance\!parity 1%                ** increase index of x-point
  \repeat
%
  \!xS=\!xE%                           ** shift ending values to starting values
  \!ybS=\!ybE
  \!ytS=\!ytE
  \ignorespaces}
 
 
\def\!vgetshrinkages#1<#2,#3,#4,#5>#6\!nil{%
  \!override\!lshrinkage{#2}\!dimenE
  \!override\!rshrinkage{#3}\!dimenF
  \!override\!bshrinkage{#4}\!dimenG
  \!override\!tshrinkage{#5}\!dimenH
  \ignorespaces}
\def\!hgetshrinkages#1<#2,#3,#4,#5>#6\!nil{%
  \!override\!lshrinkage{#2}\!dimenG
  \!override\!rshrinkage{#3}\!dimenH
  \!override\!bshrinkage{#4}\!dimenE
  \!override\!tshrinkage{#5}\!dimenF
  \ignorespaces}
 
 
\def\!shadecolumn{%
  \!dxpos=\!xpos
  \advance\!dxpos -\!xS%            ** dx = x - xS
  \!removept\!dxpos\!dx%            ** ditto, without "pt"
  \!getylimits%                     ** get top and bottom y-values
  \advance\!ytpos -\!dimenH%        ** less TS
  \advance\!ybpos \!dimenG%         ** plus BS
  \!yloc=\!!yshade%                 ** get anchor point for this column
  \ifodd\!parity 
     \advance\!yloc \!dshade
  \fi
  \!lattice\!yloc{2\!dshade}\!ybpos%
    \!countA\!ypos%                 ** ypos=smallest y point for this column
  \!dimenA=-\!shadexorigin \advance \!dimenA \!xpos%      ** over
  \loop\!not{\ifdim\!ypos>\!ytpos}% ** loop over ypos <= yt(t)
    \!setshadelocation%             ** vmode: xloc=xpos, yloc=ypos 
%                                   ** hmode: xloc=ypos, yloc=xpos 
    \!rotateaboutpivot\!xloc\!yloc%
    \!dimenA=-\!shadexorigin \advance \!dimenA \!xloc%    ** over
    \!dimenB=-\!shadeyorigin \advance \!dimenB \!yloc%    ** up
    \kern\!dimenA \raise\!dimenB\copy\!shadesymbol \kern-\!dimenA
    \advance\!ypos 2\!dshade
  \repeat
  \ignorespaces}
 
\def\!qgetylimits{%
  \!dimenA=\!dx\!ytC              
  \advance\!dimenA \!ytB%         ** yt(t)=ytS + dx*(Bt + dx*Ct)
  \!ytpos=\!dx\!dimenA
  \advance\!ytpos \!ytS
  \!dimenA=\!dx\!ybC              
  \advance\!dimenA \!ybB%         ** yb(t)=ybS + dx*(Bb + dx*Cb)
  \!ybpos=\!dx\!dimenA
  \advance\!ybpos \!ybS}
 
\def\!lgetylimits{%
  \!ytpos=\!dx\!ytB%              ** yt(t)=ytS + dx*Bt
  \advance\!ytpos \!ytS
  \!ybpos=\!dx\!ybB%              ** yb(t)=ybS + dx*Bb
  \advance\!ybpos \!ybS}
 
\def\!vsetshadelocation{%         ** vmode: xloc=xpos, yloc=ypos 
  \!xloc=\!xpos
  \!yloc=\!ypos}
\def\!hsetshadelocation{%         ** hmode: xloc=ypos, yloc=xpos 
  \!xloc=\!ypos
  \!yloc=\!xpos}


% **************************************
% *** TICKS  (Draws ticks on graphs) ***
% **************************************

% ** User commands
% **   \ticksout
% **   \ticksin
% **   \gridlines
% **   \nogridlines
% **   \loggedticks
% **   \unloggesticks
% ** See Subsection 3.4 of the manual

% ** The following is an option of the \axis command
% **   ticks 
% **     [in] [out] 
% **     [long] [short] [length <LENGTH>] 
% **     [width <WIDTH>]
% **     [andacross] [butnotacross] 
% **     [logged] [unlogged] 
% **     [unlabeled] [numbered] [withvalues VALUE1 VALUE2 ... VALUEk / ]
% **     [quantity Q] [at LOC1 LOC2 ... LOCk / ] [from LOC1 to LOC2 by
% **       LOC_INCREMENT]
% ** See Subsection 3.2 of the manual for the rules.

% ** The various options of the  tick  field are processed by the
% ** \!nextkeyword  command defined below.
% ** For example, `\!nextkeyword short '  expands to  `\!ticksshort',
% ** while `\!nextkeyword withvalues' expands to `\!tickswithvalues'.

\def\!axisticks {%
  \def\!nextkeyword##1 {%
    \expandafter\ifx\csname !ticks##1\endcsname \relax
      \def\!next{\!fixkeyword{##1}}%
    \else
      \def\!next{\csname !ticks##1\endcsname}%
    \fi
    \!next}%
  \!axissetup
    \def\!axissetup{\relax}%
  \edef\!ticksinoutsign{\!ticksinoutSign}%
  \!ticklength=\longticklength
  \!tickwidth=\linethickness
  \!gridlinestatus
  \!setticktransform
  \!maketick
  \!tickcase=0
  \def\!LTlist{}%
  \!nextkeyword}

\def\ticksout{%
  \def\!ticksinoutSign{+}}
\def\ticksin{%
  \def\!ticksinoutSign{-}}
\ticksout

\def\gridlines{%
  \def\!gridlinestatus{\!gridlinestootrue}}
\def\nogridlines{%
  \def\!gridlinestatus{\!gridlinestoofalse}}
\nogridlines

\def\loggedticks{%
  \def\!setticktransform{\let\!ticktransform=\!logten}}
\def\unloggedticks{%
  \def\!setticktransform{\let\!ticktransform=\!donothing}}
\def\!donothing#1#2{\def#2{#1}}
\unloggedticks

% ** \!ticks/ : terminates read of tick options
\expandafter\def\csname !ticks/\endcsname{%
  \!not {\ifx \!LTlist\empty}
    \!placetickvalues
  \fi
  \def\!tickvalueslist{}%
  \def\!LTlist{}%
  \expandafter\csname !axis/\endcsname}

\def\!maketick{%
  \setbox\!boxA=\hbox{%
    \beginpicture
      \!setdimenmode
      \setcoordinatesystem point at {\!zpt} {\!zpt}   
      \linethickness=\!tickwidth
      \ifdim\!ticklength>\!zpt
        \putrule from {\!zpt} {\!zpt} to
          {\!ticksinoutsign\!tickxsign\!ticklength}
          {\!ticksinoutsign\!tickysign\!ticklength}
      \fi
      \if!gridlinestoo
        \putrule from {\!zpt} {\!zpt} to
          {-\!tickxsign\!xaxislength} {-\!tickysign\!yaxislength}
      \fi
    \endpicturesave <\!Xsave,\!Ysave>}%
    \wd\!boxA=\!zpt}
  
\def\!ticksin{%
  \def\!ticksinoutsign{-}%
  \!maketick
  \!nextkeyword}

\def\!ticksout{%
  \def\!ticksinoutsign{+}%
  \!maketick
  \!nextkeyword}

\def\!tickslength<#1> {%
  \!ticklength=#1\relax
  \!maketick
  \!nextkeyword}

\def\!tickslong{%
  \!tickslength<\longticklength> }

\def\!ticksshort{%
  \!tickslength<\shortticklength> }

\def\!tickswidth<#1> {%
  \!tickwidth=#1\relax
  \!maketick
  \!nextkeyword}

\def\!ticksandacross{%
  \!gridlinestootrue
  \!maketick
  \!nextkeyword}

\def\!ticksbutnotacross{%
  \!gridlinestoofalse
  \!maketick
  \!nextkeyword}

\def\!tickslogged{%
  \let\!ticktransform=\!logten
  \!nextkeyword}

\def\!ticksunlogged{%
  \let\!ticktransform=\!donothing
  \!nextkeyword}

\def\!ticksunlabeled{%
  \!tickcase=0
  \!nextkeyword}

\def\!ticksnumbered{%
  \!tickcase=1
  \!nextkeyword}

\def\!tickswithvalues#1/ {%
  \edef\!tickvalueslist{#1! /}%
  \!tickcase=2
  \!nextkeyword}

\def\!ticksquantity#1 {%
  \ifnum #1>1
    \!updatetickoffset
    \!countA=#1\relax
    \advance \!countA -1
    \!ticklocationincr=\!axisLength
      \divide \!ticklocationincr \!countA
    \!ticklocation=\!axisstart
    \loop \!not{\ifdim \!ticklocation>\!axisend}
      \!placetick\!ticklocation
      \ifcase\!tickcase
          \relax %  Case 0: no labels
        \or
          \relax %  Case 1: numbered -- not available here
        \or
          \expandafter\!gettickvaluefrom\!tickvalueslist
          \edef\!tickfield{{\the\!ticklocation}{\!value}}%
          \expandafter\!listaddon\expandafter{\!tickfield}\!LTlist%
      \fi
      \advance \!ticklocation \!ticklocationincr
    \repeat
  \fi
  \!nextkeyword}

\def\!ticksat#1 {%
  \!updatetickoffset
  \edef\!Loc{#1}%
  \if /\!Loc
    \def\next{\!nextkeyword}%
  \else
    \!ticksincommon
    \def\next{\!ticksat}%
  \fi
  \next}    
      
\def\!ticksfrom#1 to #2 by #3 {%
  \!updatetickoffset
  \edef\!arg{#3}%
  \expandafter\!separate\!arg\!nil
  \!scalefactor=1
  \expandafter\!countfigures\!arg/
  \edef\!arg{#1}%
  \!scaleup\!arg by\!scalefactor to\!countE
  \edef\!arg{#2}%
  \!scaleup\!arg by\!scalefactor to\!countF
  \edef\!arg{#3}%
  \!scaleup\!arg by\!scalefactor to\!countG
  \loop \!not{\ifnum\!countE>\!countF}
    \ifnum\!scalefactor=1
      \edef\!Loc{\the\!countE}%
    \else
      \!scaledown\!countE by\!scalefactor to\!Loc
    \fi
    \!ticksincommon
    \advance \!countE \!countG
  \repeat
  \!nextkeyword}

\def\!updatetickoffset{%
  \!dimenA=\!ticksinoutsign\!ticklength
  \ifdim \!dimenA>\!offset
    \!offset=\!dimenA
  \fi}

\def\!placetick#1{%
  \if!xswitch
    \!xpos=#1\relax
    \!ypos=\!axisylevel
  \else
    \!xpos=\!axisxlevel
    \!ypos=#1\relax
  \fi
  \advance\!xpos \!Xsave
  \advance\!ypos \!Ysave
  \kern\!xpos\raise\!ypos\copy\!boxA\kern-\!xpos
  \ignorespaces}

\def\!gettickvaluefrom#1 #2 /{%
  \edef\!value{#1}%
  \edef\!tickvalueslist{#2 /}%
  \ifx \!tickvalueslist\!endtickvaluelist
    \!tickcase=0
  \fi}
\def\!endtickvaluelist{! /}

\def\!ticksincommon{%
  \!ticktransform\!Loc\!t
  \!ticklocation=\!t\!!unit
  \advance\!ticklocation -\!!origin
  \!placetick\!ticklocation
  \ifcase\!tickcase
    \relax % Case 0: no labels
  \or %      Case 1: numbered
    \ifdim\!ticklocation<-\!!origin
      \edef\!Loc{$\!Loc$}%
    \fi
    \edef\!tickfield{{\the\!ticklocation}{\!Loc}}%
    \expandafter\!listaddon\expandafter{\!tickfield}\!LTlist%
  \or %      Case 2: labeled
    \expandafter\!gettickvaluefrom\!tickvalueslist
    \edef\!tickfield{{\the\!ticklocation}{\!value}}%
    \expandafter\!listaddon\expandafter{\!tickfield}\!LTlist%
  \fi}

\def\!separate#1\!nil{%
  \!ifnextchar{-}{\!!separate}{\!!!separate}#1\!nil}
\def\!!separate-#1\!nil{%
  \def\!sign{-}%
  \!!!!separate#1..\!nil}
\def\!!!separate#1\!nil{%
  \def\!sign{+}%
  \!!!!separate#1..\!nil}
\def\!!!!separate#1.#2.#3\!nil{%
  \def\!arg{#1}%
  \ifx\!arg\!empty
    \!countA=0
  \else
    \!countA=\!arg
  \fi
  \def\!arg{#2}%
  \ifx\!arg\!empty
    \!countB=0
  \else
    \!countB=\!arg
  \fi}
 
\def\!countfigures#1{%
  \if #1/%
    \def\!next{\ignorespaces}%
  \else
    \multiply\!scalefactor 10
    \def\!next{\!countfigures}%
  \fi
  \!next}

\def\!scaleup#1by#2to#3{%
  \expandafter\!separate#1\!nil
  \multiply\!countA #2\relax
  \advance\!countA \!countB
  \if -\!sign
    \!countA=-\!countA
  \fi
  #3=\!countA
  \ignorespaces}

\def\!scaledown#1by#2to#3{%
  \!countA=#1\relax%                          ** get original #
  \ifnum \!countA<0 %                         ** take abs value,
    \def\!sign{-}%                            **   remember sign
    \!countA=-\!countA
  \else
    \def\!sign{}%
  \fi
  \!countB=\!countA%                          ** copy |#|
  \divide\!countB #2\relax%                   ** integer part (|#|/sf)
  \!countC=\!countB%                          ** get sf * (|#|/sf)
    \multiply\!countC #2\relax
  \advance \!countA -\!countC%                ** ctA is now remainder
  \edef#3{\!sign\the\!countB.}%               ** +- integerpart.
  \!countC=\!countA %                         ** Tack on proper number
  \ifnum\!countC=0 %                          **   of zeros after .
    \!countC=1
  \fi
  \multiply\!countC 10
  \!loop \ifnum #2>\!countC
    \edef#3{#3\!zero}%
    \multiply\!countC 10
  \repeat
  \edef#3{#3\the\!countA}%                    ** Add on rest of remainder
  \ignorespaces}

\def\!placetickvalues{%
  \advance\!offset \tickstovaluesleading
  \if!xswitch
    \setbox\!boxA=\hbox{%
      \def\\##1##2{%
        \!dimenput {##2} [B] (##1,\!axisylevel)}%
      \beginpicture 
        \!LTlist
      \endpicturesave <\!Xsave,\!Ysave>}%
    \!dimenA=\!axisylevel
      \advance\!dimenA -\!Ysave
      \advance\!dimenA \!tickysign\!offset
      \if -\!tickysign
        \advance\!dimenA -\ht\!boxA
      \else
        \advance\!dimenA  \dp\!boxA
      \fi
    \advance\!offset \ht\!boxA 
      \advance\!offset \dp\!boxA
    \!dimenput {\box\!boxA} [Bl] <\!Xsave,\!Ysave> (\!zpt,\!dimenA)
  \else
    \setbox\!boxA=\hbox{%
      \def\\##1##2{%
        \!dimenput {##2} [r] (\!axisxlevel,##1)}%
      \beginpicture 
        \!LTlist
      \endpicturesave <\!Xsave,\!Ysave>}%
    \!dimenA=\!axisxlevel
      \advance\!dimenA -\!Xsave
      \advance\!dimenA \!tickxsign\!offset
      \if -\!tickxsign
        \advance\!dimenA -\wd\!boxA
      \fi
    \advance\!offset \wd\!boxA
    \!dimenput {\box\!boxA} [Bl] <\!Xsave,\!Ysave> (\!dimenA,\!zpt)
  \fi}


\normalgraphs
\catcode`!=12 %  *****  THIS MUST NEVER BE OMITTED

parametrized_variations.bbl
\def\cprime{$'$}
\begin{thebibliography}{10}

\bibitem{arnold-vak}
V.~I. Arnol{\cprime}d, V.~V. Kozlov, and A.~I. Ne{\u\i}shtadt.
\newblock {\em Dynamical systems. {III}}, volume~3 of {\em Encyclopaedia of
  Mathematical Sciences}.
\newblock Springer-Verlag, Berlin, 1988.
\newblock Translated from the Russian by A. Iacob.

\bibitem{epred}
M.~Castrill{\'o}n~L{\'o}pez, P.~L. Garc{\'{\i}}a, and T.~S. Ratiu.
\newblock Euler-{P}oincar\'e reduction on principal bundles.
\newblock {\em Lett. Math. Phys.}, 58(2):167--180, 2001.

\bibitem{reduction}
Marco Castrill{\'o}n~L{\'o}pez, Tudor~S. Ratiu, and Steve Shkoller.
\newblock Reduction in principal fiber bundles: covariant {E}uler-{P}oincar\'e
  equations.
\newblock {\em Proc. Amer. Math. Soc.}, 128(7):2155--2164, 2000.

\bibitem{eck}
David~J. Eck.
\newblock Gauge-natural bundles and generalized gauge theories.
\newblock {\em Mem. Amer. Math. Soc.}, 33(247):vi+48, 1981.

\bibitem{lo-review}
L.~Fatibene, M.~Ferraris, and M.~Francaviglia.
\newblock On the gauge natural structure of modern physics.
\newblock {\em Int. J. Geom. Methods Mod. Phys.}, 1(4):443--466, 2004.

\bibitem{vm}
L.~Fatibene, M.~Francaviglia, and M.~Raiteri.
\newblock Gauge natural field theories and applications to conservation laws.
\newblock In {\em Differential geometry and its applications (Opava, 2001)},
  volume~3 of {\em Math. Publ.}, pages 401--413. Silesian Univ. Opava, Opava,
  2001.

\bibitem{lo}
Lorenzo Fatibene and Mauro Francaviglia.
\newblock {\em Natural and gauge natural formalism for classical field
  theories}.
\newblock Kluwer Academic Publishers, Dordrecht, 2003.
\newblock A geometric perspective including spinors and gauge theories.

\bibitem{fgr}
A.~Fern{\'a}ndez, P.~L. Garc{\'{\i}}a, and C.~Rodrigo.
\newblock Stress-energy-momentum tensors for natural constrained variational
  problems.
\newblock {\em J. Geom. Phys.}, 49(1):1--20, 2004.

\bibitem{lagred}
Antonio Fern{\'a}ndez, Pedro~Luis Garc{\'{\i}}a, and C{\'e}sar Rodrigo.
\newblock Lagrangian reduction and constrained variational calculus.
\newblock In {\em Proceedings of the IX Fall Workshop on Geometry and Physics
  (Vilanova i la Geltr\'u, 2000)}, volume~3 of {\em Publ. R. Soc. Mat. Esp.},
  pages 53--64. R. Soc. Mat. Esp., Madrid, 2001.

\bibitem{fibered}
M.~Ferraris.
\newblock Fibered connections and global {P}oincar\'e-{C}artan forms in
  higher-order calculus of variations.
\newblock In {\em Proceedings of the conference on differential geometry and
  its applications, Part 2}, pages 61--91, Brno, 1984. Univ. J. E. Purkyn\v e.

\bibitem{garcia-vak}
P.~L. Garc{\'{\i}}a and C.~Rodrigo.
\newblock The momentum map in vakonomic mechanics.
\newblock In {\em Proceedings of the XII Fall Workshop on Geometry and
  Physics}, volume~7 of {\em Publ. R. Soc. Mat. Esp.}, pages 111--123. R. Soc.
  Mat. Esp., Madrid, 2004.

\bibitem{sardanashvily}
G.~Giachetta, L.~Mangiarotti, and G.~Sardanashvily.
\newblock {\em New {L}agrangian and {H}amiltonian methods in field theory}.
\newblock World Scientific Publishing Co. Inc., River Edge, NJ, 1997.

\bibitem{h-e}
S.~W. Hawking and G.~F.~R. Ellis.
\newblock {\em The large scale structure of space-time}.
\newblock Cambridge University Press, London, 1973.
\newblock Cambridge Monographs on Mathematical Physics, No. 1.

\bibitem{kijowski-art}
J.~Kijowski, D.~Pawlik, and W.~Tulczyjew.
\newblock A variational formulation of non-graviting and graviting
  hydrodynamics.
\newblock {\em Bull. Acad. Polon. Sci.}, XXVII:163--170, 1979.

\bibitem{kolarticolo}
Ivan Kol{\'a}{\v{r}}.
\newblock A geometrical version of the higher order {H}amilton formalism in
  fibred manifolds.
\newblock {\em J. Geom. Phys.}, 1(2):127--137, 1984.

\bibitem{kolar}
Ivan Kol{\'a}{\v{r}}, Peter~W. Michor, and Jan Slov{\'a}k.
\newblock {\em Natural operations in differential geometry}.
\newblock Springer-Verlag, Berlin, 1993.

\bibitem{krupkova}
Olga Krupkov{\'a} and Petr Voln{\'y}.
\newblock Euler-{L}agrange and {H}amilton equations for non-holonomic systems
  in field theory.
\newblock {\em J. Phys. A}, 38(40):8715--8745, 2005.

\bibitem{exp}
Andrew~D. Lewis and Richard~M. Murray.
\newblock Variational principles for constrained systems: theory and
  experiment.
\newblock {\em Internat. J. Non-Linear Mech.}, 30(6):793--815, 1995.

\bibitem{modugno}
L.~Mangiarotti and M.~Modugno.
\newblock Fibered spaces, jet spaces and connections for field theories.
\newblock In {\em Proceedings of the international meeting on geometry and
  physics (Florence, 1982)}, pages 135--165, Bologna, 1983. Pitagora.

\bibitem{marle}
Charles-Michel Marle.
\newblock Various approaches to conservative and nonconservative nonholonomic
  systems.
\newblock {\em Rep. Math. Phys.}, 42(1-2):211--229, 1998.
\newblock Pacific Institute of Mathematical Sciences Workshop on Nonholonomic
  Constraints in Dynamics (Calgary, AB, 1997).

\bibitem{brown}
E.~Soper.
\newblock {\em Classical field theory}.
\newblock John Wiley {\&} Sons, 1976.

\bibitem{taub}
A.~H. Taub.
\newblock General relativistic variational principle for perfect fluids.
\newblock {\em Physical Rev. (2)}, 94:1468--1470, 1954.

\bibitem{deleon}
J.~Vankerschaver, F.~Cantrijn, M.~de~Le{\'o}n, and D.~Mart{\'{\i}}n~de Diego.
\newblock Geometric aspects of nonholonomic field theories.
\newblock {\em Rep. Math. Phys.}, 56(3):387--411, 2005.

\end{thebibliography}
