Maximizers for the {S}trichartz inequality
Damiano Foschi
We compute explicitly the best constants and, by solving some functional equations, we find all maximizers for homogeneous Strichartz estimates for the Schr\"odinger equation and for the wave equation in the cases when the Lebesgue exponent is an even integer.
maximizer-corrected.tex
%% maximizer-corrected.tex
\documentclass{amsart}

% need version 1.01 of PGF-TikZ package (Graphic System for TeX)
% which can be downloaded from  http://sourceforge.net/projects/pgf/
\usepackage{tikz}

\title{Maximizers for the {S}trichartz inequality}

\author[D.\ Foschi]%
{Damiano Foschi}

%%\address{Dipartimento di Matematica \\
%%  Universit\`a di Ferrara}
%%\email{damiano.foschi@unife.it}
%%\urladdr{http://utenti.unife.it/damiano.foschi/}

\date{June 9, 2006}

\keywords{%
  Strichartz estimates;
  Schr\"odinger equation;
  wave equation;
  functional equations.}%
\subjclass[2000]{Primary 35B45; Secondary 47D06, 39B05.}

%% macros
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\Abs}[1]{\bigl|#1\bigr|}
\newcommand{\norm}[1]{\left\|#1\right\|}
\newcommand{\Norm}[1]{\bigl\|#1\bigr\|}
\newcommand{\tonde}[1]{\left(#1\right)}
\newcommand{\Tonde}[1]{\bigl(#1\bigr)}
\newcommand{\TOnde}[1]{\Bigl(#1\Bigr)}
\newcommand{\TONde}[1]{\Biggl(#1\Biggr)}
\newcommand{\graffe}[1]{\left\{#1\right\}}
\newcommand{\Graffe}[1]{\bigl\{#1\bigr\}}
\newcommand{\ip}[1]{\langle #1 \rangle}
\newcommand{\pvector}[1]{\begin{pmatrix}#1\end{pmatrix}}
\newcommand{\ddirac}[1]{%
  \,\boldsymbol{\delta}\!\pvector{#1}\!}
\newcommand{\MU}{\boldsymbol{\mu}}
\newcommand{\chic}{\boldsymbol{\chi}}
\newcommand{\R}{\mathbb{R}}  % real numbers
\newcommand{\C}{\mathbb{C}}  % complex numbers
\newcommand{\Sp}{\mathbb{S}}  % unit sphere
\newcommand{\iC}{\mathrm{i}} % immaginary unit
\newcommand{\Eu}{\mathrm{e}} % euler's constant
\renewcommand{\Re}{{\mathfrak{Re}}}
\renewcommand{\Im}{{\mathfrak{Im}}}
\newcommand{\intersection}{\cap}
\newcommand{\union}{\cup} 
\newcommand{\mA}{{\mathcal A}}
\newcommand{\mC}{{\mathcal C}}
\newcommand{\mE}{{\mathcal E}}
\newcommand{\mG}{{\mathcal G}}
\newcommand{\mH}{{\mathcal H}}
\newcommand{\mL}{{\mathcal L}}
\newcommand{\mN}{{\mathcal N}}
\newcommand{\mP}{{\mathcal P}}
\newcommand{\de}{\partial}
\newcommand{\pder}[3][]{{\frac{\de^{#1} #2}{\de{#3}^{#1}}}}
\renewcommand{\d}{\,{\rm d}}
\newcommand{\1}[1]{\frac{1}{#1}}
\newcommand{\conv}{\ast}
\newcommand{\ovl}{\overline}
\newcommand{\changeto}{\rightsquigarrow}
\newcommand{\ut}{\widetilde{u}}
\newcommand{\Ft}{\widetilde{F}}
\newcommand{\Gt}{\widetilde{G}}
\newcommand{\fh}{\widehat{f}}
\newcommand{\fph}{\widehat{f_+}}
\newcommand{\fmh}{\widehat{f_-}}
\newcommand{\Ah}{\widehat{A}}
\newcommand{\bh}{\widehat{b}}
\newcommand{\Bh}{\widehat{B}}
\newcommand{\Ch}{\widehat{C}}
\newcommand{\ie}{{i.e.\ }}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{conjecture}[theorem]{Conjecture}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

%% macros for graphics
\setlength{\unitlength}{3947sp}%
\begingroup\makeatletter\ifx\SetFigFont\undefined%
\gdef\SetFigFont#1#2#3#4#5{%
  \reset@font\fontsize{#1}{#2pt}%
  \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
  \selectfont}%
\fi\endgroup%
%%

\begin{document}

\maketitle

\begin{center}
  Dipartimento di Matematica \\
  Universit\`a di Ferrara \\
  via Macchiavelli 34, I-44100 Ferrara - ITALY \\
  email: \verb|damiano.foschi@unife.it|
\end{center}

\begin{abstract}
  We compute explicitly the best constants
  and, by solving some functional equations,
  we find all maximizers for homogeneous Strichartz estimates
  for the Schr\"odinger equation and for the wave equation
  in the cases when the Lebesgue exponent is an even integer.
\end{abstract}

\section{%
  Introduction}
\label{sec:introduction}

Let $n$ be a positive integer and let $p = p(n) = 2 + 4/n$.
The Strichartz inequality
for the homogeneous Schr\"odinger equation
in $n$ spatial dimensions
states that there exists a constant $S > 0$ such that
\begin{equation} \label{eq:1}
  \norm{u}_{L^{p(n)}(\R^{1 + n})} \le S \norm{f}_{L^2(\R^n)},
\end{equation}
whenever $u(t, x)$ is the solution of the equation
\begin{equation} \label{eq:2}
  \iC \de_t u = \Delta u,
\end{equation}
with initial data $u(0, x) = f(x)$;
see~\cite{Str1977} for the original proof by Strichartz.
We denote by $S(n)$ the best constant for the estimate~\eqref{eq:1},
\begin{equation*}
  S(n) = \sup_{f \in L^2(\R^n)}
  \frac{\norm{\Eu^{-\iC t \Delta} f}_{L^{p(n)}(\R^{1 + n})}}
  {\norm{f}_{L^2(\R^n)}}.
\end{equation*}

If $n \ge 2$, we can also consider the Strichartz inequality
for the homogeneous wave equation
in $n$ spatial dimensions which
states that there exists a constant $W > 0$ such that
\begin{equation} \label{eq:3}
  \norm{u}_{L^{p(n - 1)}(\R^{1 + n})} \le
  W \Norm{(f, g)}_{\dot{H}^{\12}(\R^n)
    \times \dot{H}^{-\12}(\R^n)},
\end{equation}
whenever $u(t, x)$ is the solution of the equation
\begin{equation} \label{eq:4}
  \de_t^2 u = \Delta u,
\end{equation}
with initial data
\begin{equation} \label{eq:5}
  u(0, x) = f(x), \qquad \de_t u(0, x) = g(x).
\end{equation}
This also was proved in~\cite{Str1977}.
We denote by $W(n)$
the best constant for the estimate~\eqref{eq:3},
\begin{equation*}
  W(n) = \sup_{\substack{f \in \dot{H}^{\12}(\R^n) \\
      g \in \dot{H}^{-\12}(\R^n)}}
  \frac{\norm{\cos(t \sqrt{-\Delta}) f +
      \frac{\sin(t \sqrt{-\Delta})}{\sqrt{-\Delta}} g}_{%
      L^{p(n - 1)}(\R^{1 + n})}}
  {\norm{(f, g)}_{\dot{H}^{\12}(\R^n)
      \times \dot{H}^{-\12}(\R^n)}}.
\end{equation*}

Kunze~\cite{Kun2003} has recently proved
the existence of a maximizing function $f_* \in L^2(\R)$
for the estimate~\eqref{eq:1} in the special case $n = 1$ and $p = 6$,
which means that for the corresponding solution $u_*$,
\begin{equation*}
  \iC \de_t u_* = \de_x^2 u_*, \qquad u_*(0, x) = f_*(x),
\end{equation*}
we have the equality
$\norm{u_*}_{L^6(\R \times \R)} = S(1) \norm{f_*}_{L^2(\R)}$.
The proof in~\cite{Kun2003} is based on an elaborate application
of the concentration compactness principle
and does not provide an explicit expression for a maximizer.

Here, we present a more direct and elementary approach
which allows us to explicitly determine the families of maximizers
and compute the best constants
for the estimates~\eqref{eq:1} and~\eqref{eq:3}
when the exponent $p = p(n)$ is an even integer.
We show that the classes of maximizers are unique modulo
the natural geometric invariance properties of the equations.
Moreover, maximizers turn out to be smooth solutions
to some functional equations which can be solved explicitly.

\medskip
For the Schr\"odinger equation we have:

\begin{theorem}
  In the case $n = 1$ and $p = 6$, we have $S(1) = {12}^{-1/12}$;
  in the case $n = 2$ and $p = 4$, we have $S(2) = 2^{-1/2}$.
  In both cases an example of a maximizer $f_* \in L^2(\R^n)$
  for which we have
  \begin{equation} \label{eq:6}
    \norm{\Eu^{-\iC t \Delta} f_*}_{L^p(\R \times \R^n)} =
    S(n) \norm{f_*}_{L^2(\R^n)},
  \end{equation}
  is provided by the Gaussian function
  $f_*(x) = \exp\Tonde{-\abs{x}^2}$.
\end{theorem}

The geometric invariance properties of the equation~\eqref{eq:2}
suggest a way to completely characterize the class of all maximizers.

\begin{definition} \label{def:1}
  Let $\mG$ be the Lie group of transformations generated by:
  \begin{itemize}
  \item space-time translations:
    $u(t, x) \changeto u(t + t_0, x + x_0)$,
    with $t_0 \in \R$, $x_0 \in \R^n$;
  \item parabolic dilations:
    $u(t, x) \changeto u(\lambda^2 t, \lambda x)$,
    with $\lambda > 0$;
  \item change of scale:
    $u(t, x) \changeto \mu u(t, x)$, with $\mu > 0$;
  \item space rotations:
      $u(t, x) \changeto u(t, R x)$, 
      with $R \in SO(n)$;
  \item phase shifts:
      $u(t, x) \changeto \Eu^{\iC \theta} u(t, x)$, 
      with $\theta \in \R$;
  \item Galilean transformations:
    \begin{equation*}
      u(t, x) \changeto
      \exp\TOnde{\frac{\iC}4 \Tonde{\abs{v}^2 t + 2 v \cdot x}}
      u(t, x + t v),
    \end{equation*}
    with $v \in \R^n$.
  \end{itemize}
\end{definition}

If $u$ solves~\eqref{eq:2} and $g \in \mG$
then $v = g \cdot u$ is still a solution to~\eqref{eq:2}.
Moreover, the ratio $\norm{u}_{L^{p(n)}} / \norm{u(0)}_{L^2}$
is left unchanged by the action of $\mG$.

\begin{remark}
  We should mention that
  there exists another important (discrete) symmetry
  for the Schr\"odinger equation
  given by the \emph{pseudo-conformal inversion}:
  \begin{equation*}
    u(t, x) \changeto 
    t^{-n / 2} \Eu^{\iC \abs{x}^2 / (4 t)} u\TOnde{-\1t, \frac{x}{t}}.
  \end{equation*}
  Combining the inversion with translations and dilations,
  we obtain that the Schr\"odinger equation is invariant
  under the representation of $SL(2,\R)$ given by
  \begin{equation*}
    u(t, x) \changeto 
    (a + b t)^{-n / 2} \Eu^{\iC b \abs{x}^2 / (4 (a + b t))}
    u\TOnde{\frac{c + d t}{a + b t}, \frac{x}{a + b t}}, \qquad
    a d - b c = 1.
  \end{equation*}
  These transformations have many important applications.
  However, we do not really need them in the context of our analysis
  and for simplicity we are not including them
  in the list of generators of the group $\mG$.
\end{remark}

\begin{theorem}
  Let $(n, p) = (1, 6)$ or $(n, p) = (2, 4)$.
  Let $f_*(x) = \exp\Tonde{-\abs{x}^2}$ 
  and $u_*(t, x) = \Eu^{-\iC t \Delta} f_*(x)$
  be the corresponding solution
  to the Schr\"odinger equation~\eqref{eq:2}.
  Then the set of maximizers
  for which the equality~\eqref{eq:6} holds
  coincides with the set of initial data
  of solutions to~\eqref{eq:2} in the orbit of $u_*$
  under the action of the group $\mG$.
  In particular, all maximizers
  are given by $L^2$ functions of the form
  \begin{equation*}
    f_*(x) = \exp\Tonde{A \abs{x}^2 + b \cdot x + C},
  \end{equation*}
  with $A, C \in \C$, $b \in \C^n$ and $\Re(A) < 0$.
\end{theorem}

\medskip
For the wave equation we have:

\begin{theorem}
  In the case $n = 2$ and $p = 6$,
  we have $W(2) = (25 / 64 \pi)^{1/6}$;
  in the case $n = 3$ and $p = 4$,
  we have $W(3) = (3 / 16\pi)^{1/4}$.
  In both cases an example of a maximizer pair
  $(f_*, g_*) \in \dot{H}^{\12}(\R^n) \times \dot{H}^{-\12}(\R^n)$
  for which we have
  \begin{equation} \label{eq:7}
    \norm{\cos(t \sqrt{-\Delta}) f_* +
      \frac{\sin(t \sqrt{-\Delta})}{\sqrt{-\Delta}} g_*}_{%
      L^p(\R^{1 + n})} =
    W(n) \Norm{(f_*, g_*)}_{\dot{H}^{\12}(\R^n)
      \times \dot{H}^{-\12}(\R^n)}.
  \end{equation}
  is provided by the functions
  $f_*(x) = \Tonde{1 + \abs{x}^2}^{-(n-1)/2}$, $g_*(x) = 0$.
\end{theorem}

The geometric invariance properties of the equation~\eqref{eq:4}
suggest a way to completely characterize the class of all maximizers.

\begin{definition} \label{def:2}
  Let $\mL$ be the Lie group of transformations
  acting on \emph{solutions} of the wave equation
  and generated by:
  \begin{itemize}
  \item space-time translations:
    $u(t, x) \changeto u(t + t_0, x + x_0)$,
    with $t_0 \in \R$, $x_0 \in \R^n$;
  \item isotropic dilations:
    $u(t, x) \changeto u(\lambda t, \lambda x)$,
    with $\lambda > 0$;
  \item change of scale:
    $u(t, x) \changeto \mu u(t, x)$, with $\mu > 0$;
  \item space rotations:
      $u(t, x) \changeto u(t, R x)$, 
      with $R \in SO(n)$;
  \item phase shifts:
    $u(t, x) \changeto \Eu^{\iC \theta_+} u_+(t, x) + \Eu^{\iC \theta_-} u_-(t, x)$,
    with $\theta_+, \theta_- \in \R$
    (for the meaning of $u_+$ and $u_-$ see the next section);
  \item Lorentzian boosts:
    \begin{equation*}
      u(t, x_1, x') \changeto
       u\Tonde{\cosh(a) t + \sinh(a) x_1,
         \sinh(a) t + \cosh(a) x_1, x'},
    \end{equation*}
    with $a \in \R$.
  \end{itemize}
\end{definition}

If $u$ solves~\eqref{eq:4} and $g \in \mL$
then $v = g \cdot u$ is still a solution to~\eqref{eq:4}.
Moreover, the ratio $\norm{u}_{L^{p(n-1)}} /
\norm{(u(0), \de_t u(0))}_{\dot{H}^{\12} \times \dot{H}^{-\12}}$
is left unchanged by the action of $\mL$.

\begin{theorem}
  Let $(n, p) = (2, 6)$ or $(n, p) = (3, 4)$.
  We consider the initial data
  $f_*(x) = \Tonde{1 + \abs{x}^2}^{-(n-1)/2}$, $g_*(x) = 0$,
  and let $u_*$ be the corresponding solution
  to the wave equation~\eqref{eq:4}.
  Then the set of maximizers
  for which the equality~\eqref{eq:7} holds
  coincides with the set of initial data
  of solutions to~\eqref{eq:4} in the orbit of $u_*$
  under the action of the group $\mL$.
\end{theorem}

In order to understand how to construct maximizers,
we first present sharp proofs of the Strichartz estimates,
based on the space-time Fourier transform
in the spirit of Klainerman and Machedon's work
on bilinear estimates%
~\cite{KlaMac1996},~\cite{FosKla2000}.
We then optimize each step of the proof
by imposing conditions under which
all inequalities become equalities.
What we find are functional equations
for the Fourier transform of maximizers;
their solutions are given by particular exponential functions
with linear or quadratic exponents.

The key tool is the following well-known simple fact
about Cauchy-Schwarz's inequality for inner products.

\begin{lemma} \label{lem:0}
  Let $\ip{\cdot, \cdot}$ be a (complex) inner product on a vector
  space $V$ and let $u, v \in V$ be two non-zero vectors.
  Cauchy-Schwarz's inequality says that
  \begin{equation*}
    \abs{\ip{u, v}}^2 \le \ip{u, u} \ip{v, v};
  \end{equation*}
  moreover, equality holds if and only if $u = \alpha v$
  for some scalar $\alpha \in \C$.
\end{lemma}

\begin{remark}
  The uniqueness of maximizers modulo the transformation groups
  described in definitions~\ref{def:1} and~\ref{def:2}
  will be checked \emph{a posteriori},
  after we obtain explicit formulae for maximizers,
  and it is not used in the proof.
  While our proof relies heavily on the fact that $p$ is an even integer,
  the geometric characterization can be stated also in higher dimensions
  when $p$ is not an even integer.
  It would be interesting to prove our results
  without making use of the Fourier transform.
  For the moment, we formulate the following natural conjectures.
\end{remark}

\begin{conjecture}
  For any integer $n \ge 1$, let $p = 2 + 4/n$,
  let $f_*(x) = \exp\Tonde{-\abs{x}^2}$ 
  and $u_*(t, x) = \Eu^{-\iC t \Delta} f_*(x)$
  be the corresponding solution to the Schr\"odinger equation~\eqref{eq:2}.
  Then the set of maximizers for which the equality~\eqref{eq:6} holds
  coincides with the set of initial data
  of solutions to~\eqref{eq:2} in the orbit of $u_*$
  under the action of the group $\mG$.
\end{conjecture}

\begin{conjecture}
  For any integer $n \ge 2$,
  let $p = 2 + 4/(n-1)$ and
  let $f_*$ be the function on $\R^n$ whose Fourier transform
  is $\widehat{f_*}(\xi) = \abs{\xi}^{-1} \exp\tonde{-\abs{\xi}}$.
  Let $u_*$ be the solution to the wave equation~\eqref{eq:4}
  corresponding to the initial data
  $u_*(0) = f_*$, $\de_t u_*(0) = 0$.
  Then the set of maximizers for which the equality~\eqref{eq:7} holds
  coincides with the set of initial data
  of solutions to~\eqref{eq:4} in the orbit of $u_*$
  under the action of the group $\mL$.  
\end{conjecture}

\section{%
  Notation and preliminaries}
\label{sec:notation}

For $1 \le p < \infty$,
$L^p(\R^n)$ is the usual Lebesgue space with norm
\begin{equation*}
\norm{f}_{L^p(\R^n)} = \tonde{\int_{\R^n} \abs{f(x)}^p \d x}^{1/p}.
\end{equation*}
The homogeneous Sobolev spaces $\dot{H}^{\12}(\R^n)$ and $\dot{H}^{-\12}(\R^n)$
are defined by the norms
\begin{equation*}
  \norm{f}_{\dot{H}^{\12}(\R^n)} = \Norm{D^{\12} f}_{L^2(\R^n)}, \qquad
  \norm{f}_{\dot{H}^{-\12}(\R^n)} = \Norm{D^{-\12} f}_{L^2(\R^n)}, \qquad
\end{equation*}
where $D = \sqrt{-\Delta}$. 
In the context of the wave equation we set
\begin{equation*}
  \norm{(f, g)}_{\dot{H}^{\12}(\R^n) \times \dot{H}^{-\12}(\R^n)}
  = \tonde{\norm{f}_{\dot{H}^{\12}(\R^n)}^2
    + \norm{g}_{\dot{H}^{-\12}(\R^n)}^2}^{1/2}.
\end{equation*}

If $f(x)$ is an integrable function defined on $\R^n$,
we define its (spatial) Fourier transform by
\begin{equation*}
\fh(\xi) = \int_{\R^n} f(x) \Eu^{-\iC x \cdot \xi} \d x.
\end{equation*}
If $F(t,x)$ is an integrable function defined on $\R \times \R^n$,
we define its space-time Fourier transform by
\begin{equation*}
\Ft(\tau, \xi) =
  \int_{\R \times \R^n} F(t, x)
  \Eu^{-\iC \tonde{t \tau + x \cdot \xi}} \d t \d x.
\end{equation*}
These definitions extend in the usual way
to tempered distributions.
The Fourier transform acts like an isometry on $L^2$
and, with our definition for the Fourier transform,
Plancherel's theorem states that
\begin{equation*}
  \Norm{\fh}_{L^2(\R^n)} =
  (2 \pi)^{n/2} \norm{f}_{L^2(\R^n)}, \quad
  \Norm{\Ft}_{L^2(\R^{1 + n})} =
  (2 \pi)^{(1 + n)/2} \norm{f}_{L^2(\R^{1 + n})}.
\end{equation*}
We recall also that the Fourier transform of a pointwise product
(when it is defined)
is given by the convolution product
of the Fourier transform of each factor,
\begin{align*}
  \widehat{f g}(\xi) &=
  \1{(2 \pi)^n} \fh \conv \widehat{g} (\xi) = 
  \1{(2 \pi)^n} \int_{\R^n \times \R^n}
  \fh(\eta) \widehat{g}(\zeta)
  \ddirac{\xi - \eta - \zeta} \d\eta \d\zeta, \\
  \widetilde{F G}(\tau, \xi) &=
  \1{(2 \pi)^{n + 1}}
  \Ft \conv \Gt (\tau, \xi) = \\
  &= \1{(2 \pi)^{n + 1}}
  \int_{\R \times \R^n \times \R \times \R^n}
  \Ft(\lambda, \eta) \Gt(\mu, \zeta)
  \ddirac{\tau - \lambda - \mu \\ \xi - \eta - \zeta}
  \d\lambda \d\eta \d\mu \d\zeta.
\end{align*}
Here $\!\ddirac{\cdot}$ denotes Dirac's delta measure
concentrated in $0$,
$\int \!\ddirac{x} f(x) \d x = f(0)$.
We also denote the tensor product of two delta functions by
\begin{equation*}
  \ddirac{a \\ b} = \ddirac{a} \ddirac{b}.
\end{equation*}

\medskip
If $u(t, x)$ is the solution of the Schr\"odinger equation~\eqref{eq:2}
then its space-time Fourier transform is
\begin{equation*}
  \ut(\tau, \xi) =
  2 \pi \ddirac{\tau - \abs{\xi}^2} \fh(\xi),
\end{equation*}
where $f$ is the initial data at time $t=0$.
This shows that $\ut$ is a measure supported
on the paraboloid $\tau = \abs{\xi}^2$.
We notice,
in connection with the invariance of equation~\eqref{eq:2}
under Galilean transformations,
that the measure $\ddirac{\tau - \abs{\xi}^2}$
is invariant under the volume preserving affine change of variables
\begin{equation} \label{eq:8}
  (\tau, \xi) \changeto (\tau + 2 v \cdot \xi + \abs{v}^2, \xi + v),
\end{equation}
for any $v \in \R^n$.

\medskip
If $u(t, x)$ is the solution of the wave equation~\eqref{eq:4}
with initial data~\eqref{eq:5}, then
we can split it as $u = u_+ + u_-$, where
\begin{align*}
  u_+(t) &= \Eu^{\iC t D} D^{-\12} f_+, &
  f_+ &= \12 \tonde{D^{\12} f - \iC D^{-\12} g}, \\
  u_-(t) &= \Eu^{-\iC t D} D^{-\12} f_-, &
  f_- &= \12 \tonde{D^{\12} f + \iC D^{-\12} g}.
\end{align*}
We call $u_+$ a $(+)$-wave with data $f_+$
and $u_-$ a $(-)$-wave with data $f_-$.
Observe that, by parallelogram's law,
\begin{equation*}
  \norm{(f, g)}_{\dot{H}^{\12}(\R^n)
    \times \dot{H}^{-\12}(\R^n)}^2 = 
  2 \tonde{\norm{f_+}_{L^2(\R^n)}^2 + \norm{f_-}_{L^2(\R^n)}^2}.
\end{equation*}
The space-time Fourier transforms
of $u_+$ and $u_-$ are
\begin{equation*}
  \widetilde{u_+}(\tau, \xi) =
  2 \pi \abs{\xi}^{-\12}
  \ddirac{\tau - \abs{\xi}} \fph(\xi), \qquad
  \widetilde{u_-}(\tau, \xi) =
  2 \pi \abs{\xi}^{-\12}
  \ddirac{\tau + \abs{\xi}} \fmh(\xi).
\end{equation*}
Hence, $\widetilde{u_+}$ and $\widetilde{u_-}$
are measures supported on the null cones
$\tau = \abs{\xi}$ and $\tau = - \abs{\xi}$, respectively.
We notice also
that the measures $ \abs{\xi}^{-1} \ddirac{\tau \mp \abs{\xi}}$
are invariant under proper Lorentz transformations.
Indeed, we can write
\begin{equation*}
   \frac{\ddirac{\tau \mp \abs{\xi}}}{\abs{\xi}} = 
   2 \ddirac{\tau^2 - \abs{\xi}^2} \chic(\pm \tau > 0).
\end{equation*}

The invariance properties of these delta measures
on paraboloids and on null cones later
will help us in the computation of some convolution integrals.
Eventually we will need the following simple property of convolutions.

\begin{lemma} \label{lem:21}
  Let $A$ be a $n \times n$ invertible matrix and $b$ a vector in $\R^n$.
  Suppose $f$ is a function (or a distribution) on $\R^n$
  which is invariant under
  the linear affine change of variable $x \changeto A x + b$,
  in the sense that $f(x) = f(A x + b)$ for all $x \in \R^n$.
  Then, if the convolution $f \conv f$ is well defined,
  we have that
  \begin{equation*}
    f \conv f (x) = \1{\det A} f \conv f (A x + 2 b),
  \end{equation*}
  and, if the convolution $f \conv f \conv f$ is well defined,
  we have that
  \begin{equation*}
    f \conv f \conv f (x) = \1{(\det A)^2} f \conv f \conv f (A x + 3 b).
  \end{equation*}
\end{lemma}

For a complex number $z \in \C$,
we denote its real and imaginary parts by $\Re(z)$ and $\Im(z)$
and its complex conjugate by $\ovl{z}$.
Whenever they are mentioned,
$\log(z)$ and $\sqrt{z}$ are the branches
of the complex logarithm and of the complex square root
defined on $\C \setminus \R_-$
which extend analytically
the standard real logarithm and the standard square root
of positive real numbers.

For a vector $x = (x_1, x_2, \dots, x_n) \in \R^n$,
we adopt the prime notation to denote the vector
$x' = (x_2, \dots, x_n) \in \R^{n-1}$,
so that $x = (x_1, x')$.

If $E$ is a subset of $\R^n$
we denote its closure with respect to the usual topology
by $\ovl{E}$.

\section{%
  Schr\"odinger equation in dimension $n = 2$.}
\label{sec:case-n-2}

Consider the case $n = 2$, $p = 4$ for estimate~\eqref{eq:1}.
By Plancherel's theorem, 
$u \in L^4$ if and only if $\widetilde{u^2} \in L^2$ and
\begin{equation} \label{eq:9}
  \norm{u}_{L^4(\R^3)}^2 = \norm{u^2}_{L^2(\R^3)} = 
  (2 \pi)^{-3/2} \Norm{\widetilde{u^2}}_{L^2(\R^3)}.
\end{equation}
The Fourier transform of $u^2$ reduces to
\begin{equation} \label{eq:10}
  \widetilde{u^2}(\tau, \xi) = 
  \1{(2 \pi)^3} \ut \conv \ut (\tau, \xi) =
  \1{2 \pi} \int_{\R^2 \times \R^2}
  \fh(\eta) \fh(\zeta)
  \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\
    \xi - \eta - \zeta}
  \d\eta \d\zeta.
\end{equation}
When $\xi = \eta + \zeta$
and $\tau = \abs{\eta}^2 + \abs{\zeta}^2$,
by parallelogram's law we have
\begin{equation*}
  2 \tau =
  \abs{\eta + \zeta}^2 + \abs{\eta - \zeta}^2 \ge \abs{\xi}^2.
\end{equation*}
It follows that $\widetilde{u^2}$ is supported
in the closure of the region
\begin{equation*}
  \mP_2 = \graffe{(\tau, \xi) \in \R \times \R^2:
    2 \tau > \abs{\xi}^2}.
\end{equation*}
%
\begin{figure}
  \centering
  \begin{tikzpicture}[scale=2, >=latex]
    \fill[black!10]
    (-2, 2) parabola[bend at end] (0,0) parabola (2, 2) -- cycle;
    \draw[dashed]
    (-2, 2) parabola[bend at end] (0,0) parabola (2, 2);
    \draw[->, thin, dotted] (-2, 0) -- (2, 0) node[below] {$\xi$};
    \draw[->, thin, dotted] (0, -0.2) -- (0, 2) node[left] {$\tau$};
    \draw
    (-1.4, 1.96) parabola[bend at end] (0,0) parabola (1.4, 1.96);
    \draw[shift={(0.8,0.64)}]
    (-1.1, 1.21) parabola[bend at end] (0,0) parabola (1.1, 1.21);
    \draw[shift={(0.4,0.16)}]
    (-1.3, 1.69) parabola[bend at end] (0,0) parabola (1.3, 1.69);
    \fill[black!50, text=black]
    (0, 0) circle (1pt) node[below left] {$O$}
    (0.4, 0.16) node (a) {} circle (1pt)
    (0.8, 0.64) node (b) {} circle (1pt)
    (1.2, 0.80) node (c) {} circle (1pt);
    \path (0.6, 1.6) node {$2\tau \ge \abs{\xi}^2$};
    \draw[->]
    (2, 0.3) node[right] {$(\abs{\eta}^2, \eta)$}
    .. controls (1, 0) ..  (a);
    \draw[->]
    (2, 0.6) node[right] {$(\abs{\zeta}^2, \zeta)$}
    .. controls (1.2, 0.3) ..  (b);
    \draw[->]
    (2, 0.9) node[right] {$(\abs{\eta}^2 + \abs{\zeta}^2, \eta + \zeta)$}
    .. controls (1.4, 0.6) ..  (c);
  \end{tikzpicture}
  \caption{The region $\mP_2$}
  \label{fig:5}
\end{figure}
%
For each choice of $(\tau, \xi) \in \mP_2$,
we denote by $\ip{\cdot, \cdot}_{(\tau, \xi)}$
the $L^2$ inner product associated with the measure
\begin{equation} \label{eq:11}
  \MU_{(\tau, \xi)} =
  \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\ \xi - \eta - \zeta}
  \d\eta \d\zeta;
\end{equation}
and by $\norm{\cdot}_{(\tau, \xi)}$ the corresponding norm;
more precisely, we set
\begin{align*}
  & \ip{F, G}_{(\tau, \xi)} =
  \int_{\R^2 \times \R^2} F(\eta, \zeta) \ovl{G(\eta, \zeta)}
  \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\
    \xi - \eta - \zeta}
  \d\eta \d\zeta, \\
  & \norm{F}_{(\tau, \xi)} =
  \tonde{\int_{\R^2 \times \R^2} \abs{F(\eta, \zeta)}^2 
    \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\
      \xi - \eta - \zeta}
    \d\eta \d\zeta}^{1/2}.
\end{align*}

\begin{remark}
  The measure $\MU_{(\tau, \xi)}$ defined in~\eqref{eq:11}
  is the \emph{pull-back} of the Dirac's delta on $\R \times \R^2$
  by the function $\Phi_{(\tau, \xi)}: \R^2 \times \R^2 \to \R \times \R^2$
  given by
  \begin{equation*}
    \Phi_{(\tau, \xi)}(\eta, \zeta) =
    \Tonde{\tau - \abs{\eta}^2 - \abs{\zeta}^2, \xi - \eta - \zeta}.
  \end{equation*}
  This pull back is well defined as long as
  the differential of $\Phi_{(\tau, \xi)}$ is surjective
  in correspondence of the points where $\Phi_{(\tau, \xi)}$ vanishes
  (we refer to~\cite[Theorem 6.1.2 and Example 6.1.3]{Hor1990}
  for more details about pull-backs of distributions).
  A quick computation shows that the differential of $\Phi_{(\tau, \xi)}$
  is surjective at a point $(\eta, \zeta)$
  if and only if $\eta \ne \zeta$.
  On the other hand,
  if $\Phi_{(\tau, \xi)}(\eta, \eta) = 0$
  we must have
  \begin{equation*}
    2\tau = 2(\abs{\eta}^2 + \abs{\eta}^2) = \abs{\eta + \eta}^2 = \abs{\xi}^2.
  \end{equation*}  
  This tells us that $\MU_{(\tau, \xi)}$ is not well defined
  on the boundary of $\mP_2$, when $2 \tau = \abs{\xi}^2$.
  However, we can safely ignore the problems at this boundary
  and observe instead that
  for any locally integrable function $F(\eta, \zeta)$
  defined on $\R^2 \times \R^2$
  the integral $G(\tau, \xi) = \int F \d\MU_{(\tau, \xi)}$
  defines a locally integrable function on $\R \times \R^2$.
  Indeed, if $K$ is a compact set in $\R \times \R^2$, we have
  \begin{multline*}
    \iint_K \abs{G(\tau, \xi)} \d\tau \d\xi \le
    \iint_{(\tau, \xi) \in K} \iint \abs{F(\eta, \zeta)} 
    \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\ \xi - \eta - \zeta}
    \d\eta \d\zeta \d\tau \d\xi = \\
    = \iint_{(\abs{\eta}^2 + \abs{\zeta}^2, \eta + \zeta) \in K}
    \abs{F(\eta, \zeta)} \d\eta \d\zeta,
  \end{multline*}
  and the set 
  $\Graffe{(\eta, \zeta): (\abs{\eta}^2 + \abs{\zeta}^2, \eta + \zeta) \in K}$
  is a compact set in $\R^2 \times \R^2$.
\end{remark}

We can now write~\eqref{eq:10} as
\begin{equation*}
  \widetilde{u^2}(\tau, \xi) = \1{2 \pi}
  \ip{\fh \otimes \fh, 1 \otimes 1}_{(\tau, \xi)},
\end{equation*}
where the tensor product is defined by
$(f \otimes g) (\eta, \zeta) = f(\eta) g(\zeta)$.
By Cauchy-Schwarz's inequality we obtain that
\begin{equation} \label{eq:12}
  \Abs{\widetilde{u^2}(\tau, \xi)} \le \1{2 \pi}
  \Norm{\fh \otimes \fh}_{(\tau, \xi)}
  \Norm{1 \otimes 1}_{(\tau, \xi)}.
\end{equation}
Hence,
\begin{equation} \label{eq:13}
  \Norm{\widetilde{u^2}}_{L^2(\R^3)} \le \1{2 \pi}
  \TOnde{\sup_{(\tau, \xi) \in \mP_2}
    \Norm{1 \otimes 1}_{(\tau, \xi)}}
  \tonde{\int_{\mP_2}
    \Norm{\fh \otimes \fh}_{(\tau, \xi)}^2
    \d\tau \d\xi}^{1/2}.
\end{equation}
The next lemma shows that
not only $\Norm{1 \otimes 1}_{(\tau, \xi)}$ is uniformly bounded
with respect to $(\tau, \xi)$,
but that it is actually constant
on the support of $\widetilde{u^2}$.

\begin{lemma} \label{lem:1}
  For each $(\tau, \xi) \in \mP_2$ we have 
  $\norm{1 \otimes 1}_{(\tau, \xi)} = \sqrt{\pi/2}$.
\end{lemma}

\begin{proof}
  The quantity
  \begin{equation*}
    I(\tau, \xi) = \norm{1 \otimes 1}_{(\tau, \xi)}^2 =
    \int_{\R^2} \ddirac{\tau - \abs{\xi - \eta}^2 - \abs{\eta}^2} \d\eta
  \end{equation*}
  is just the convolution of the measure $\ddirac{\tau - \abs{\xi}^2}$
  with itself.
  The invariance of this measure
  with respect to the transformation~\eqref{eq:8}
  together with lemma~\ref{lem:21}
  imply that
  \begin{equation*}
    I(\tau, \xi) = I(\tau + 2 v \cdot \xi + \abs{v}^2, \xi + v),
  \end{equation*}
  for any $v \in \R^2$.
  If we take $v = -\xi/2$ we obtain that $I(\tau, \xi) = I(\tau^*, 0)$,
  where $\tau^* = \tau - \abs{\xi}^2/2$.
  Moreover, it is evident from its definition that,
  by homogeneity,
  $I$ is invariant under parabolic dilations,
  $I(\tau, \xi) = I(\lambda^2 \tau, \lambda \xi)$.
  Hence, when $\tau^* > 0$ we have
  \begin{multline*}
    I(\tau, \xi) = I(\tau^*, 0) = I(1, 0) = 
    \int_{\R^2} \ddirac{1 - 2\abs{\eta}^2} \d\eta = \\
    = 2 \pi \int_0^\infty \ddirac{1 - 2 r^2} r \d r =
    \pi \int_0^\infty \ddirac{1 - 2 s} \d s =
    \frac\pi2.
  \end{multline*}
\end{proof}

We also have
\begin{multline} \label{eq:14}
  \int_{\mP_2}
  \Norm{\fh \otimes \fh}_{(\tau, \xi)}^2
  \d\tau \d\xi = \\
  = \int_{\R^2 \times \R^2}
  \abs{\fh(\eta) \fh(\zeta)}^2
  \int_{\mP_2}
  \ddirac{\tau - \abs{\eta}^2 - \abs{\zeta}^2 \\
    \xi - \eta - \zeta}
  \d\tau \d\xi \d\eta \d\zeta = \\
  = \Norm{\fh \otimes \fh}_{L^2(\R^2 \times \R^2)}^2
  = \Norm{\fh}_{L^2(\R^2)}^4
  = (2 \pi)^4 \norm{f}_{L^2(\R^2)}^4.
\end{multline}
It follows from~\eqref{eq:9},~\eqref{eq:13},~\eqref{eq:14}
and lemma~\ref{lem:1} that
\begin{equation} \label{eq:15}
  \norm{u}_{L^4(\R^3)} \le \1{\sqrt{2}} \norm{f}_{L^2(\R^2)}.
\end{equation}
This proves that for $n = 2$
the best constant $S(2)$ in~\eqref{eq:1}
is no larger that $1/\sqrt{2}$.

\begin{remark}
  We observe that in the above computations
  the only place where we have used an inequality
  instead of an equality is in~\eqref{eq:13}
  as a consequence of the Cauchy-Schwarz inequality~\eqref{eq:12}.
  If we can find a function $f$
  for which we have equality in~\eqref{eq:12}
  for all $(\tau, \xi) \in \mP_2$
  then there will be equality also in~\eqref{eq:15}.
  This will show that $f$ is a maximizer for the estimate
  and that $S(2) = 1/\sqrt2$.
\end{remark}

We have equality in~\eqref{eq:13}
if there is equality in~\eqref{eq:12}
for almost all $(\tau, \xi) \in \mP_2$.
By lemma~\ref{lem:0}, this happens
if there exists a scalar function $F: \mP_2 \to \C$ such that
\begin{equation*}
  \Tonde{\fh \otimes \fh}(\eta, \zeta) =
  F(\tau, \xi) \tonde{1 \otimes 1}(\eta,\zeta),
\end{equation*}
for almost all $(\eta, \zeta)$
(with respect to the measure~\eqref{eq:11})
in the support of the measure~\eqref{eq:11}
and for almost all $(\tau, \xi)$ in $\mP_2$
(with respect to the Lebesgue measure on~$\R \times \R^2$).
This means that we are looking for functions $f$ and $F$ such that
\begin{equation} \label{eq:16}
  \fh(\eta) \fh(\zeta) =
  F\tonde{\abs{\eta}^2 + \abs{\zeta}^2, \eta + \zeta},
\end{equation}
for almost all $(\eta, \zeta) \in \R^2 \times \R^2$.
An example of such functions is given by the pair
$\fh(\xi) = \Eu^{-\abs{\xi}^2}$, $F(\tau, \xi) = \Eu^{-\tau}$.

If $f$ is a maximizer, $\fh$ must solve the equation~\eqref{eq:16}
and it follows from proposition~\ref{pro:3} that
\begin{equation} \label{eq:17}
  \fh(\xi) = \exp\Tonde{\Ah \abs{\xi}^2 + \bh \cdot \xi + \Ch},
  \qquad \xi \in \R^2,
\end{equation}
for some constants 
$\Ah \in \C$,
$\bh = \Tonde{\bh_1, \bh_2} \in \C^2$,
$\Ch \in \C$,
with $\Re(\Ah) < 0$ in order to have $f \in L^2(\R^2)$.
The inverse Fourier transform of~\eqref{eq:17}
is again a function of the same class
\begin{equation} \label{eq:18}
  f(x) = \exp\Tonde{A \abs{x}^2 + b \cdot x + C}, \qquad
  x \in \R^2,
\end{equation}
where the relations between
the parameters $A \in \C$, $b \in \C^2$, $C \in \C$
and the parameters $\Ah$, $\bh$, $\Ch$
are given by
\begin{equation*}
  A = \1{4\Ah}, \qquad
  b = -\frac{\iC \bh}{4 \Ah}, \qquad
  C = \Ch - \frac{\bh_1^2 + \bh_2^2}{4 \Ah} - \log(-4 \pi \Ah).
\end{equation*}

The class of initial data of the form~\eqref{eq:18}
is invariant under the action of the group~$\mG$
described in definition~\ref{def:1}.
The coefficients change according to the following rules:
  \begin{itemize}
  \item space-time translations:
    $(\Ah, \bh, \Ch) \changeto
    (\Ah + \iC t_0, \bh + \iC x_0, \Ch)$;
  \item parabolic dilations:
    $(\Ah, \bh, \Ch) \changeto
    (\Ah / \lambda^2, \bh / \lambda, \Ch - n \log\lambda)$;
  \item change of scale:
    $(\Ah, \bh, \Ch) \changeto (\Ah, \bh, \Ch + \log\mu)$;
  \item space rotations:
    $(\Ah, \bh, \Ch) \changeto (\Ah, R \bh, \Ch)$;
  \item phase shifts:
    $(\Ah, \bh, \Ch) \changeto (\Ah, \bh, \Ch + \iC \theta)$;
  \item Galilean transformations:
    \begin{equation*}
    (\Ah, \bh, \Ch) \changeto
    \TOnde{\Ah, \bh + A v,
      \Ch - \frac{\Ah}4 \abs{v}^2 - \frac{\bh}2 \cdot v}.
  \end{equation*}
\end{itemize}

Hence, after a translation and a phase shift
we can make all coefficients real;
by a Galilean transformation we can make $\bh = 0$;
then, by a parabolic dilation we can have $\Ah = -1/4$;
finally a change of scale gives $\Ch = \log(-\pi)$.
This would correspond to the case $A = -1$, $b = 0$, $C = 0$,
which is the function $f_*(x) = \Eu^{-\abs{x}^2}$.
Thus, we have proved that any maximizer is connected to $f_*$
by the action of $\mG$.

\section{%
  Schr\"odinger equation in dimension $n = 1$.}
\label{sec:case-n-1}

Consider the case $n = 1$, $p = 6$ for estimate~\eqref{eq:1}.
This is the case that was considered in \cite{Kun2003}.
By Plancherel's theorem,
$u \in L^6$ if and only if $\widetilde{u^3} \in L^2$ and
\begin{equation} \label{eq:19}
  \norm{u}_{L^6(\R^2)}^3 = \norm{u^3}_{L^2(\R^2)} = 
  (2 \pi)^{-1} \Norm{\widetilde{u^3}}_{L^2(\R^2)}.
\end{equation}
The Fourier transform of $u^3$ reduces to
\begin{multline} \label{eq:20}
  \widetilde{u^3}(\tau, \xi) = \1{(2 \pi)^4}
  \ut \conv \ut \conv \ut (\tau, \xi) = \\
  = \1{2 \pi} \int_{\R \times \R \times \R}
  \fh(\eta_1) \fh(\eta_2) \fh(\eta_3)
  \ddirac{\tau - \eta_1^2 - \eta_2^2 - \eta_3^2 \\
    \xi - \eta_1 - \eta_2 - \eta_3}
  \d\eta_1 \d\eta_2 \d\eta_3 = \\
  = \1{2 \pi} \int_{\R^3}
  \fh(\eta_1) \fh(\eta_2) \fh(\eta_3)
  \ddirac{\tau - \abs{\eta}^2 \\ \xi - (1, 1, 1) \cdot \eta}
  \d\eta,
\end{multline}
where now $\eta = \tonde{\eta_1, \eta_2, \eta_3}$.
When $\xi = (1, 1, 1) \cdot \eta$ and $\tau = \abs{\eta}^2$,
we have $3 \tau \ge \xi^2$.
It follows that $\widetilde{u^3}$ is supported
in the closure of the region
\begin{equation*}
  \mP_1 = \graffe{(\tau, \xi) \in \R \times \R: 3 \tau > \xi^2}.
\end{equation*}
For each choice of $(\tau, \xi) \in \mP_1$,
we denote by $\ip{\cdot, \cdot}_{(\tau, \xi)}$
the $L^2$ inner product associated with the measure
\begin{equation} \label{eq:21}
  \ddirac{\tau - \abs{\eta}^2 \\
    \xi - (1, 1, 1) \cdot \eta}
  \d\eta;
\end{equation}
and by $\norm{\cdot}_{(\tau, \xi)}$ the corresponding norm.
We can then write~\eqref{eq:20} as
\begin{equation*}
  \widetilde{u^3}(\tau, \xi) = \1{2 \pi}
  \ip{\fh \otimes \fh \otimes \fh,
    1 \otimes 1 \otimes 1}_{(\tau, \xi)},
\end{equation*}
where the tensor product is defined by
$(f \otimes g \otimes h) (\eta) = f(\eta_1) g(\eta_2) h(\eta_3)$.
By Cauchy-Schwarz's inequality we obtain that
\begin{equation} \label{eq:22}
  \Abs{\widetilde{u^3}(\tau, \xi)} \le \1{2 \pi}
  \Norm{\fh \otimes \fh \otimes \fh}_{(\tau, \xi)}
  \Norm{1 \otimes 1 \otimes 1}_{(\tau, \xi)}.
\end{equation}
Hence,
\begin{equation} \label{eq:23}
  \Norm{\widetilde{u^3}}_{L^2(\R^2)} \le \1{2 \pi}
  \TOnde{\sup_{(\tau, \xi) \in \mP_1}
    \Norm{1 \otimes 1 \otimes 1}_{(\tau, \xi)}}
  \tonde{\int_{\mP_1} \Norm{\fh \otimes \fh \otimes \fh}_{(\tau, \xi)}^2
    \d\tau \d\xi}^{1/2}.
\end{equation}
The next lemma shows that
not only $\Norm{1 \otimes 1 \otimes 1}_{(\tau, \xi)}$ is bounded,
but that it is actually constant
on the support of $\widetilde{u^3}$.

\begin{lemma} \label{lem:2}
  For each $(\tau, \xi) \in \mP_1$ we have 
  $\norm{1 \otimes 1 \otimes 1}_{(\tau, \xi)}
  = \sqrt{\pi / \sqrt3}$.
\end{lemma}

\begin{proof}
  The quantity
  \begin{equation*}
    I(\tau, \xi) = \norm{1 \otimes 1 \otimes 1}_{(\tau, \xi)}^2 =
    \int_{\R^3}
    \ddirac{\tau - \abs{\eta}^2 \\ \xi - (1, 1, 1) \cdot \eta}
    \d\eta
  \end{equation*}
  is just an iterated convolution of the measure $\ddirac{\tau - \xi^2}$
  with itself twice.
  {}From lemma~\ref{lem:21} and the invariance of this measure
  with respect to the transformation~\eqref{eq:8},
  it follows that $I(\tau, \xi) = I(\tau^*, 0)$
  where $\tau^* = \tau - \xi^2/3$.
  Moreover, by homogeneity $I$ is invariant under parabolic dilations,
  $I(\lambda^2 \tau, \lambda \xi) = I(\tau, \xi)$.
  Hence, when $\tau^* > 0$ we have
  \begin{multline*}
    I(\tau, \xi) = I(\tau^*, 0) = I(1, 0) = 
    \int_{\R^3} \ddirac{1 - \abs{\eta}^2 \\ -(1, 1, 1) \cdot \eta} \d\eta =
    \int_{\R^3}
    \ddirac{1 - \abs{\eta}^2 \\ \abs{(1, 1, 1)} \eta_1} \d\eta = \\
    = \1{\sqrt{3}} \int_{\R^2} \ddirac{1 - \abs{\zeta}^2} \d\zeta =
    \frac{2\pi}{\sqrt{3}} \int_0^\infty \ddirac{1 - r^2} r \d r = 
    \frac\pi{\sqrt{3}}.
  \end{multline*}
\end{proof}

We also have
\begin{multline} \label{eq:24}
  \int_{\mP_1} \Norm{\fh \otimes \fh \otimes \fh}_{(\tau, \xi)}^2
  \d\tau \d\xi = \\
  = \int_{\R^3}
  \abs{\fh(\eta_1) \fh(\eta_2) \fh(\eta_3)}^2
  \int_{\mP_1} \ddirac{\tau - \abs{\eta}^2 \\ \xi - (1, 1, 1) \cdot \eta}
  \d\tau \d\xi \d\eta = \\
  = \Norm{\fh \otimes \fh \otimes \fh}_{L^2(\R^3)}^2
  = \Norm{\fh}_{L^2(\R)}^6
  = (2 \pi)^3 \norm{f}_{L^2(\R)}^6.
\end{multline}
It follows from~\eqref{eq:19},~\eqref{eq:23},~\eqref{eq:24}
and lemma~\ref{lem:2} that
\begin{equation} \label{eq:25}
  \norm{u}_{L^6(\R^2)} \le {12}^{-1/12} \norm{f}_{L^2(\R)}.
\end{equation}
This proves that for $n=1$ the best constant $S(1)$ in~\eqref{eq:1}
is no larger that ${12}^{-1/12}$.

As before, we observe that
if we could find a function $f$
for which we have equality in~\eqref{eq:22}
for all $(\tau, \xi) \in \mP_1$
then we would have equality in~\eqref{eq:25}
and we would have found a maximizer for the estimate.
We have equality in the Cauchy-Schwarz inequality~\eqref{eq:22}
for (almost) all $(\tau, \xi) \in \mP_1$
if there exists a scalar function $F: \mP_1 \to \C$ such that
\begin{equation*}
  \Tonde{\fh \otimes \fh \otimes \fh}(\eta) =
  F(\tau, \xi) \tonde{1 \otimes 1 \otimes 1}(\eta),
\end{equation*}
for (almost) all $\eta$
in the support of the measure~\eqref{eq:21}.
This means that we are looking for functions $f$ and $F$ such that
\begin{equation} \label{eq:26}
  \fh(\eta_1) \fh(\eta_2) \fh(\eta_3) =
  F\Tonde{\eta_1^2 + \eta_2^2 + \eta_3^2, \eta_1 + \eta_2 + \eta_3},
\end{equation}
for (almost) all $\eta \in \R^3$.
Again, an example of such functions is given by the pair
$\fh(\xi) = \Eu^{-\xi^2}$, $F(\tau, \xi) = \Eu^{-\tau}$.

If $f$ is a maximizer, $\fh$ must solve the equation~\eqref{eq:26}
and it follows from proposition~\ref{pro:1} that
\begin{equation} \label{eq:27}
  \fh(\xi) = \exp\Tonde{\Ah \xi^2 + \Bh \xi + \Ch},
  \qquad \xi \in \R,
\end{equation}
for some complex constants $\Ah$, $\Bh$, $\Ch$,
with $\Re(\Ah) < 0$ in order to have $f \in L^2(\R)$.
The inverse Fourier transform of~\eqref{eq:27}
is again a function of the same class
\begin{equation} \label{eq:28}
  f(x) = \exp\Tonde{A x^2 + B x + C}, \qquad x \in \R,
\end{equation}
where the relations between
the parameters $A$, $B$, $C$ and the parameters $\Ah$, $\Bh$, $\Ch$
are given by
\begin{equation*}
  A = \1{4 \Ah}, \qquad
  B = -\frac{\iC \Bh}{4 \Ah}, \qquad
  C = \Ch - \frac{\Bh^2}{4 \Ah} - \12\log(-4 \pi \Ah).
\end{equation*}

As we have seen at the end of section~\ref{sec:case-n-2},
the class of initial data of the form~\eqref{eq:28}
is invariant under the action of the group~$\mG$
and any maximizer is connected to
the function $f_*(x) = \Eu^{-x^2}$
by the action of $\mG$.

\section{%
  Wave equation in dimension $n = 3$.}
\label{sec:case-w-n-3}

Consider the case $n = 3$, $p = 4$ for estimate~\eqref{eq:3}.
We have
\begin{equation} \label{eq:29}
  \widetilde{u_+ u_+}(\tau, \xi) =
  \1{(2 \pi)^2} \int_{\R^3 \times \R^3}
  \frac{\fph(\eta) \fph(\zeta)}
  {\abs{\eta}^{\12} \abs{\zeta}^{\12}}
  \ddirac{\tau - \abs{\eta} - \abs{\zeta} \\
    \xi - \eta - \zeta}
  \d\eta \d\zeta.
\end{equation}
In particular, it follows that
the term $\widetilde{u_+ u_+}$ is supported
in the closure of the region
\begin{equation*}
  \mC_{++} = \graffe{(\tau, \xi) \in \R \times \R^3: \tau > \abs{\xi}}.
\end{equation*}
Similarly, the term $\widetilde{u_+ u_-}$ is supported
in the closure of the region
\begin{equation*}
  \mC_{+-} =
  \graffe{(\tau, \xi) \in \R \times \R^3:
    \abs{\tau} < \abs{\xi}};
\end{equation*}
and the term $\widetilde{u_- u_-}$ is supported
in the closure of the region
\begin{equation*}
  \mC_{--} =
  \graffe{(\tau, \xi) \in \R \times \R^3: \tau < -\abs{\xi}}.
\end{equation*}

We remark that formulae like~\eqref{eq:29} are the starting point
for the bilinear estimates studied in~\cite{FosKla2000}.

We first prove the estimate for $u_+$.
By Plancherel's theorem we have
\begin{equation} \label{eq:30}
  \norm{u_+}_{L^4(\R^4)}^2 = \norm{u_+^2}_{L^2(\R^4)} = 
  (2 \pi)^{-2} \Norm{\widetilde{u_+^2}}_{L^2(\R^4)}.
\end{equation}
For each choice of $(\tau, \xi) \in \mC_{++}$,
we denote by $\ip{\cdot, \cdot}_{(\tau, \xi)}$
the $L^2$ inner product associated with the measure
\begin{equation} \label{eq:31}
  \MU_{(\tau, \xi)} =
  \ddirac{\tau - \abs{\eta} - \abs{\zeta} \\ \xi - \eta - \zeta}
  \d\eta \d\zeta
\end{equation}
and by $\norm{\cdot}_{(\tau, \xi)}$ the corresponding norm.

\begin{remark} \label{rem:7}
  The measure $\MU_{(\tau, \xi)}$ defined in~\eqref{eq:31}
  is the \emph{pull-back} of the Dirac's delta on $\R^{1 + 3}$
  by the function $\Phi_{(\tau, \xi)}:
  (\R^3 \setminus 0) \times (\R^3 \setminus 0) \to \R \times \R^3$
  given by
  \begin{equation*}
    \Phi_{(\tau, \xi)}(\eta, \zeta) =
    \Tonde{\tau - \abs{\eta} - \abs{\zeta}, \xi - \eta - \zeta}.
  \end{equation*}
  A quick computation shows that the differential of $\Phi_{(\tau, \xi)}$
  is surjective at a point~$(\eta, \zeta)$
  if and only if $\eta / \abs{\eta} \ne \zeta / \abs{\zeta}$.
  On the other hand,
  if $\eta / \abs{\eta} = \zeta / \abs{\zeta}$
  and~$\Phi_{(\tau, \xi)}(\eta, \zeta) = 0$
  we must have
  $\tau = \abs{\eta} + \abs{\zeta} = \abs{\eta + \zeta} = \abs{\xi}$.  
  This tells us that~$\MU_{(\tau, \xi)}$ is not well defined
  on the boundary of $\mC_{++}$, when $\tau = \abs{\xi}$.
  However, we can safely ignore the problems at this boundary
  and observe instead that
  for any locally integrable function $F(\eta, \zeta)$
  defined on $\R^3 \times \R^3$
  the integral $G(\tau, \xi) = \int F \d\MU_{(\tau, \xi)}$
  defines a locally integrable function on $\R \times \R^3$.
  Indeed, if $K$ is a compact set in $\R \times \R^3$, we have
  \begin{multline*}
    \iint_K \abs{G(\tau, \xi)} \d\tau \d\xi \le
    \iint_{(\tau, \xi) \in K} \iint \abs{F(\eta, \zeta)}
    \ddirac{\tau - \abs{\eta} - \abs{\zeta} \\ \xi - \eta - \zeta}
    \d\eta \d\zeta \d\tau \d\xi = \\
    = \iint_{(\abs{\eta} + \abs{\zeta}, \eta + \zeta) \in K}
    \abs{F(\eta, \zeta)} \d\eta \d\zeta,
  \end{multline*}
  and the set 
  $\Graffe{(\eta, \zeta): (\abs{\eta} + \abs{\zeta}, \eta + \zeta) \in K}$
  is a compact set in $\R^3 \times \R^3$.
\end{remark}

We can now write~\eqref{eq:29} as
\begin{equation} \label{eq:32}
  \widetilde{u_+^2}(\tau, \xi) = \1{(2 \pi)^2}
  \ip{\fph \otimes \fph,
    \abs{\cdot}^{-\12} \otimes \abs{\cdot}^{-\12}}_{(\tau, \xi)}.
\end{equation}
The quantity we want to compute this time is
$\norm{\abs{\cdot}^{-\12} \otimes
  \abs{\cdot}^{-\12}}_{(\tau, \xi)}$.

\begin{lemma} \label{lem:3}
  For each $(\tau, \xi) \in \mC_{++}$ we have 
  $\norm{\abs{\cdot}^{-\12} \otimes
    \abs{\cdot}^{-\12}}_{(\tau, \xi)} = (2 \pi)^{1/2}$.
\end{lemma}

\begin{proof}
  The quantity
  \begin{equation*}
    I(\tau, \xi) =
    \norm{\abs{\cdot}^{-\12} \otimes \abs{\cdot}^{-\12}}_{(\tau, \xi)}^2 =
    \int_{\R^3}
    \frac{\ddirac{\tau - \abs{\xi - \eta} - \abs{\eta}}}
    {\abs{\xi - \eta} \abs{\eta}} \d\eta
  \end{equation*}
  is just the convolution
  of the measure $\abs{\xi}^{-1} \ddirac{\tau - \abs{\xi}}$
  with itself.
  If $\tau > \abs{\xi}$, from the invariance of this measure
  with respect to proper Lorentz transformations
  and from the fact that it is always possible
  to find a proper Lorentz transformation which
  takes $(\tau, \xi)$ to the point $(\tau^*, 0)$
  where $\tau^* = (\tau^2 - \abs{\xi}^2)^{1/2}$,
  it follows that $I(\tau, \xi) = I(\tau^*, 0)$.
  Moreover, it is evident from its definition that
  by homogeneity~$I$ is invariant under isotropic dilations,
  $I(\lambda \tau, \lambda \xi) = I(\tau, \xi)$.
  Hence, when $\tau > \abs{\xi}$,
  \begin{equation*}
    I(\tau, \xi) = I(1, 0) = 
    \int_{\R^3} \frac{\ddirac{1 - 2 \abs{\xi}}}{\abs{\xi}^2} \d\xi =
    4 \pi \int_0^\infty \ddirac{1 - 2 r} \d r = 2 \pi.
  \end{equation*}
\end{proof}

Cauchy-Schwarz's inequality applied to~\eqref{eq:32}
together with lemma~\ref{lem:3} give
\begin{multline} \label{eq:33}
  \Norm{\widetilde{u_+^2}}_{L^2(\R^4)}^2 \le
  \1{(2 \pi)^3} \int_{\mC_{++}}
  \norm{\fph \otimes \fph}_{(\tau, \xi)}^2 \d\tau \d \xi = \\
  = \1{(2 \pi)^3}
  \norm{\fph \otimes \fph}_{L^2(\R^3 \times \R^3)}^2
  = \1{(2 \pi)^3} \norm{\fph}_{L^2(\R^3)}^4 =
  (2 \pi)^3 \norm{f_+}_{L^2(\R^3)}^4.
\end{multline}
Hence, combining~\eqref{eq:30} and~\eqref{eq:33} we obtain
\begin{equation} \label{eq:34}
  \Norm{u_+}_{L^4(\R^4)} \le (2 \pi)^{-1/4} \norm{f_+}_{L^2(\R^3)}.
\end{equation}
This time,
equality holds if there exist a function $F: \mC_{++} \to \C$
such that 
\begin{equation*}
  \Tonde{\fph \otimes \fph}(\eta, \zeta) =
  F(\tau, \xi) \abs{\eta}^{-\12} \abs{\zeta}^{-\12},
\end{equation*}
for all $(\eta, \zeta)$
in the support of the measure~\eqref{eq:31}.
This means that
\begin{equation*}
  \abs{\eta}^{\12} \fph(\eta) \abs{\zeta}^{\12} \fph (\zeta)
  = F\Tonde{\abs{\eta} + \abs{\zeta}, \eta + \zeta},
\end{equation*}
for almost all $\eta, \zeta \in \R^3$.
An example of such functions is given by the pair
\begin{equation*}
  \fph(\xi) = \abs{\xi}^{-\12} \Eu^{-\abs{\xi}}, \qquad
  F(\tau, \xi) = \Eu^{-\tau}.
\end{equation*}
It follows from proposition~\ref{pro:4} that
any maximizer for the estimate~\eqref{eq:34}
is a function whose Fourier transform has the form
\begin{equation} \label{eq:35}
  \fh(\xi) =
  \abs{\xi}^{-\12} \exp\TOnde{A \abs{\xi} + b \cdot \xi + C},
\end{equation}
with $A, C \in \C$, $b \in \C^3$, $\Im(C) \in [0, 2\pi[$
and $\abs{\Re(b)} < -\Re(A)$ (in order to have $f \in L^2(\R^3)$).
In the next lemma we compute an explicit expression
for homogeneous waves with data of the form~\eqref{eq:35}.

\begin{lemma} \label{lem:6}
  Let $u$ be the $(+)$-wave corresponding
  to an $L^2$ data of the form~\eqref{eq:35},
  \begin{equation} \label{eq:36}
    u(t, x) = \1{(2\pi)^3} \int_{\R^3}
    \exp\TOnde{(A + \iC t) \abs{\xi} + (b + \iC x) \cdot \xi + C}
    \frac{\d\xi}{\abs{\xi}}.
  \end{equation}
  Then we have the explicit formula
  \begin{multline} \label{eq:37}
    2 \pi^2 \Eu^{-\iC \Im(C)} u\Tonde{t - \Im(A), x - \Im(b)} = \\
    = \frac{\Eu^{\Re(C)}}
    {(\Re(A))^2 - \abs{\Re(b)}^2 + \abs{x}^2 - t^2 +
      2 \iC \tonde{\Re(A) t - \Re(b) \cdot x}}.
  \end{multline}
\end{lemma}

\begin{proof}
  The integral
  \begin{equation*}
    F(t, x) = \int_{\R^3} \exp\Tonde{t \abs{\xi} + x \cdot \xi}
    \frac{\d\xi}{\abs{\xi}}
  \end{equation*}
  is well defined for $t \in \C$ and $x \in \C^3$
  when $\Re(t) < -\abs{\Re(x)}$.
  For $t \in \R$ and $x \in \R^3$ with $t < -\abs{x}$,
  using polar coordinates,
  $r = \abs{\xi}$ and $u = (x/\abs{x}) \cdot (\xi/\abs{\xi})$,
  we find
  \begin{equation*}
    F(t, x) = 2 \pi \int_{-1}^1 \int_0^\infty
    \exp\Tonde{(t + \abs{x} u) r} r \d r \d u =
    \int_{-1}^1 \frac{2 \pi \d u}{\tonde{t + \abs{x} u}^2}
    = \frac{4 \pi}{t^2 - x_1^2 - x_2^2 - x_3^2}.
  \end{equation*}
  By analytic continuation this formula remains valid
  for complex $t$ and $x$ with $\Re(t) < -\abs{\Re(x)}$.
  Formula~\eqref{eq:37} follows from the identity  
  \begin{equation*}
    \Eu^{-\iC \Im(C)} u\Tonde{t - \Im(A), x - \Im(b)}
    = \frac{\Eu^{\Re(C)}}{(2 \pi)^3} 
    F\Tonde{\Re(A) + \iC t, \Re(b) + \iC x}.
  \end{equation*}
\end{proof}

\begin{remark} \label{rem:2}
  If $u$ is the $(+)$-wave corresponding
  to an $L^2$ data of the form~\eqref{eq:35},
  then the knowledge of $\abs{u(t, x)}$
  uniquely determines 
  the value of the coefficients $A$, $b$ and~$\Re(C)$.
  Indeed, by lemma~\ref{lem:6}
  the imaginary parts $\Im(A)$ and $\Im(b)$
  are determined by the fact
  that $\abs{u(t, x)}$ has a unique maximum 
  at the point \mbox{$t = -\Im(A)$}, \mbox{$x = -\Im(b)$},
  while the real parts $\Re(A) < 0$, $\Re(b)$ and $\Re(C)$
  are determined by the coefficients of the polynomial
  \begin{multline*}
    \Abs{u\tonde{t - \Im(A), x - \Im(b)}}^{-2} = \\
    = 4 \pi^4 \Eu^{-2 \Re(C)} \tonde{%
      \Tonde{(\Re(A))^2 - \abs{\Re(b)}^2 + \abs{x}^2 - t^2}^2 +
      4 \Tonde{\Re(A) t - \Re(b) \cdot x}^2}.
  \end{multline*}
\end{remark}

\medskip
We can repeat the above procedure for the term $u_-^2$
(the only difference is that~$\tau$ must be replaced by~$-\tau$):
\begin{equation} \label{eq:38}
  \Norm{u_-}_{L^4(\R^4)} \le (2 \pi)^{-1/4} \norm{f_-}_{L^2(\R^3)},
\end{equation}
with equality if and only if $f_-$ is of the form~\eqref{eq:35}.

\medskip
For the term $u_+ u_-$,
we observe that by H\"older's inequality we have
\begin{equation} \label{eq:39}
  \Norm{u_+ u_-}_{L^2(\R^4)} \le
  \Norm{u_+}_{L^4(\R^4)} \Norm{u_-}_{L^4(\R^4)} \le
  (2 \pi)^{-1/2} \norm{f_+}_{L^2(\R^3)} \norm{f_-}_{L^2(\R^3)}.
\end{equation}
The first inequality in~\eqref{eq:39} is an equality
if there is a constant $\mu \in \R$
such that $\abs{u_+(t, x)} = \mu \abs{u_-(t, x)}$
for (almost all) $(t, x) \in \R \times \R^3$.
The second inequality in~\eqref{eq:39} is an equality
if $f_+$ and $f_-$ are functions of the form~\eqref{eq:35}.

\medskip
Combining the $L^2$ orthogonality
of the terms $u_+^2$, $u_-^2$ and $u_+ u_-$
(due to the disjointness of the supports
of their Fourier transforms)
with~\eqref{eq:34},~\eqref{eq:38} and~\eqref{eq:39},
we obtain
\begin{multline} \label{eq:40}
  \norm{u}_{L^4}^4 = \norm{(u_+ + u_-)^2}_{L^2}^2 = 
  \norm{u_+}_{L^4}^4 + \norm{u_-}_{L^4}^4
  + 4\norm{u_+ u_-}_{L^2}^2 \le \\
  \le \1{2 \pi} \tonde{\norm{f_+}_{L^2}^4 + \norm{f_-}_{L^2}^4 +
    4 \norm{f_+}_{L^2(\R^3)}^2 \norm{f_-}_{L^2(\R^3)}^2} \le \\
  \le \frac{3}{4 \pi}
  \tonde{\norm{f_+}_{L^2}^2 + \norm{f_-}_{L^2}^2}^2 =
  \frac{3}{16 \pi}
  \norm{(f, g)}_{\dot{H}^{\12} \times \dot{H}^{-\12}}^4,
\end{multline}
where we have used the sharp inequality
\begin{equation*}
  X^2 + Y^2 + 4 X Y \le \frac32 (X + Y)^2, \qquad X,Y \ge 0,
\end{equation*}
for which equality holds if and only if $X = Y$.
This proves that for $n = 3$
the best constant $W(3)$ in~\eqref{eq:3}
is no larger that $(3/(16\pi))^{1/4}$.
The next proposition tells us that maximizers exist
and that the inequalities in~\eqref{eq:40} are sharp;
hence, $W(3) = (3/(16\pi))^{1/4}$.

\begin{proposition} \label{pro:6}
  We have $\norm{u}_{L^4} = (3/(16\pi))^{1/4}
  \norm{(f, g)}_{\dot{H}^{\12} \times \dot{H}^{-\12}}$
  if and only if
  \begin{equation} \label{eq:41}
    \fph(\xi) = \abs{\xi}^{-\12}
    \exp\TOnde{A \abs{\xi} + b \cdot \xi + C}, \qquad
    \fmh(\xi) = \abs{\xi}^{-\12}
    \exp\TOnde{\ovl{A} \abs{\xi} - \ovl{b} \cdot \xi + D},
  \end{equation}
  where $A, C, D \in \C$ and $b \in \C^3$
  with $\abs{\Re(b)} < -\Re(A)$ and $\Re(D) = \Re(C)$.
\end{proposition}

\begin{proof}
  By the above discussion, 
  we have equalities in~\eqref{eq:40} if and only if
  $f_+$, $f_-$ are both functions of the form~\eqref{eq:35}
  and $\abs{u_+(t, x)} = \abs{u_-(t, x)}$
  for all $(t, x) \in \R \times \R^3$.
  Observe that
  if $u_-$ is a $(-)$-wave with data $f_-$, where
  \begin{equation*}
    \fmh(\xi) = \abs{\xi}^{-\12}
    \exp\TOnde{A_- \abs{\xi} + b_- \cdot \xi + C_-},
  \end{equation*}
  then its complex conjugate $\ovl{u_-}$ is a $(+)$-wave with data
  \begin{equation*}
    \ovl{\fmh(-\xi)} = \abs{\xi}^{-\12} \exp\TOnde{%
      \ovl{A_-} \abs{\xi} - \ovl{b_-} \cdot \xi + \ovl{C_-}}.
  \end{equation*}
  By remark~\ref{rem:2}, 
  if two $(+)$-waves with initial data of the form~\eqref{eq:35}
  have the same absolute value at every point of the space-time
  then they must have the same coefficients $A$, $b$ and $\Re(C)$.
\end{proof}

A particular case of~\eqref{eq:41},
corresponding to $A = -1$, $b = 0$, $C = D = \log(2\pi^2)$,
is given by the initial data
\begin{equation} \label{eq:42}
   f_*(x) = \1{1 + \abs{x}^2}, \qquad
   g_*(x) = 0, \qquad x \in \R^3.
\end{equation}

The class of initial data of the form~\eqref{eq:41}
is invariant under the action of the group~$\mL$
described in definition~\ref{def:2}.
The coefficients change according to the following rules:
  \begin{itemize}
  \item space-time translations:
    $(A, b, C, D) \changeto (A + \iC t_0, b + \iC x_0, C, D)$;
  \item isotropic dilations:
    $(A, b, C, D) \changeto
    (A/\lambda, b/\lambda, C - n \log\lambda, D - n \log\lambda)$;
  \item change of scale:
    $(A, b, C, D) \changeto (A, b, C + \log\mu, D + \log\mu)$;
  \item space rotations:
    $(A, b, C, D) \changeto (A, R b, C, D)$;
  \item phase shifts:
    $(A, b, C, D) \changeto (A, b, C + \iC\theta_+, D + \iC\theta_-)$;
  \item Lorentzian boosts:
    \begin{equation*}
      \Tonde{A, (b_1, b'), C, D} \changeto
      \TOnde{A \cosh(a) - b_1 \sinh(a),
        \Tonde{-A \sinh(a) + b_1 \cosh(a), b'}, C, D}.
    \end{equation*}
  \end{itemize}
Hence, after a translation and a phase shift
we can make all coefficients real;
by a rotation we can make $b' = 0$
and by a Lorentzian boost we can make $b_1 = 0$;
then, by a isotropic dilation we can have $A = -1$;
finally a change of scale gives $C = D = \log(2\pi^2)$.
This would correspond to the functions
\begin{equation*}
  \fph(\xi) = \fmh(\xi) =
  -2 \pi^2 \abs{\xi}^{-\12} \exp\Tonde{-\abs{\xi}},
\end{equation*}
which are the Fourier transforms
of the $(+)$ and $(-)$ parts of the initial data~\eqref{eq:42}.
Thus, we have proved that
any maximizer is connected to $(f_*, g_*)$
by the action of~$\mL$.

\section{%
  Wave equation in dimension $n = 2$.}
\label{sec:case-w-n-2}

Consider the case $n = 2$, $p = 6$ for estimate~\eqref{eq:3}.
We decompose $u$ into its $(+)$ and $(-)$ parts
and treat the $L^6$ norm of $u$ as an $L^2$ norm of $u^3$.
By expanding the the products we find
\begin{align*}
  \norm{u}_{L^6}^6 =& \norm{(u_+ + u_-)^3}_{L^2}^2 =
  \norm{u_+^3 + 3 u_+^2 u_- + 3 u_+ u_-^2 + u_-^3}^2 = \\
  =& \norm{u_+^3}^2
  + \norm{u_-^3}^2
  + 9 \norm{u_+^2 u_-}^2
  + 9 \norm{u_+ u_-^2}^2 + \\
  &+ 6 \Re\ip{u_+^3, u_+^2 u_-}
  + 6 \Re\ip{u_+ u_-^2, u_-^3}
  + 18 \Re\ip{u_+^2 u_-, u_+ u_-^2} + \\
  &+ 6 \Re\ip{u_+^3, u_+ u_-^2}
  + 2 \Re\ip{u_+^3, u_-^3}
  + 6 \Re\ip{u_+^2 u_-, u_-^3},
\end{align*}
where here $\norm{\cdot}$ and $\ip{\cdot, \cdot}$ now stand for
the standard norm and inner product in~$L^2(\R \times \R^2)$.
We shall study one term at a time,
but first we compute some integrals which will be needed later.

\begin{lemma} \label{lem:7}
  For $(\tau, \xi) \in \R \times \R^2$ with $\tau > \abs{\xi}$, we define
  \begin{align*}
    I_2(\tau, \xi) &= \int_{(\R^2)^2}
    \ddirac{\tau - \abs{\eta_1} - \abs{\eta_2} \\
      \xi - \eta_1 - \eta_2}
    \frac{\d\eta_1 \d\eta_2}{\abs{\eta_1} \abs{\eta_2}}, \\
    I_3(\tau, \xi) &= \int_{(\R^2)^3}
    \ddirac{\tau - \abs{\eta_1} - \abs{\eta_2} - \abs{\eta_3} \\
      \xi - \eta_1 - \eta_2 - \eta_3}
    \frac{\d\eta_1 \d\eta_2 \d\eta_3}
    {\abs{\eta_1} \abs{\eta_2} \abs{\eta_3}}.
  \end{align*}
  Then we have $I_2(\tau, \xi) = 2 \pi / {\sqrt{\tau^2 - \abs{\xi}^2}}$
  and $I_3(\tau, \xi) = 4 \pi^2$.
\end{lemma}

\begin{proof}
  The fact that $I_2$ and $I_3$ are well defined
  locally integrable functions on $\R \times \R^2$
  follows from considerations similar to the ones made
  at the end of remark~\ref{rem:7}.
  Let us define $\mu$ to be the measure
  $\mu(\tau, \xi) = \abs{\xi}^{-1} \ddirac{\tau - \abs{\xi}}$;
  we have \mbox{$I_2 = \mu \conv \mu$} and $I_3 = \mu \conv \mu \conv \mu$.
  The measure $\mu$ is invariant under proper Lorentz transformations,
  and given $(\tau, \xi)$ such that $\tau > \abs{\xi}$,
  there exists always a proper Lorentz transformation which
  takes $(\tau, \xi)$ to the point $(\tau^*, 0)$
  where $\tau^* = \sqrt{\tau^2 - \abs{\xi}^2}$.
  By lemma~\ref{lem:21},
  it follows that $I_k(\tau, \xi) = I_k(\tau^*, 0)$, for $k = 2, 3$.
  The integral $I_2$ is homogeneous of degree $-1$
  while $I_3$ is homogeneous of degree $0$.
  Hence, for $\tau > \abs{\xi}$ we have
  \begin{equation*}
    I_2(\tau, \xi) = \frac{I_2(1, 0)}{\tau^*} = 
    \1{\tau^*}
    \int_{\R^2} \frac{\ddirac{1 - 2 \abs{\eta}}}{\abs{\eta}^2} \d\eta =
    \frac{2 \pi}{\tau^*} \int_0^\infty \frac{\ddirac{1 - 2 r}}{r} \d r =
    \frac{2 \pi}{\sqrt{\tau^2 - \abs{\xi}^2}}
  \end{equation*}
and
  \begin{multline*}
    I_3(\tau, \xi) = I_3(1, 0) =
    \int_{2 \abs{\eta} \le 1} I_2(1 - \abs{\eta}, -\eta) \frac{\d\eta}{\abs{\eta}} =
    \\ = \int_{2 \abs{\eta} < 1} \frac{2 \pi \d\eta}
    {\Tonde{(1 - \abs{\eta})^2 - \abs{\eta}^2}^{\12} \abs{\eta}}
    = 4 \pi^2 \int_0^{1/2} \frac{\d r}{\sqrt{1 - 2 r}} = 4 \pi^2.
  \end{multline*}
\end{proof}

Let us now begin the proof of the estimate
for the term $\norm{u_+^3}$.
The Fourier transform of $u_+^3$ is
\begin{equation} \label{eq:43}
  \widetilde{u_+^3}(\tau, \xi) =
  \1{(2 \pi)^3} \int_{(\R^2)^3}
  \frac{\fph(\eta_1) \fph(\eta_2) \fph(\eta_3)}
  {\abs{\eta_1}^{\12} \abs{\eta_2}^{\12} \abs{\eta_3}^{\12}}
  \ddirac{%
    \tau - \abs{\eta_1} - \abs{\eta_2} - \abs{\eta_3} \\
    \xi - \eta_1 - \eta_2 - \eta_3}
  \d\eta_1 \d\eta_2 \d\eta_3.
\end{equation}
The support of $\widetilde{u_+^3}$ is contained in the closure of the region
$\mC_{+++} = \graffe{(\tau, \xi): \tau > \abs{\xi}}$.
For each choice of $(\tau, \xi) \in \mC_{+++}$ ,
we denote by $\ip{\cdot, \cdot}_{(\tau, \xi)}$
the $L^2$ inner product associated with the measure
\begin{equation} \label{eq:44}
  \ddirac{\tau - \abs{\eta_1} - \abs{\eta_2} - \abs{\eta_3} \\
    \xi - \eta_1 - \eta_2 - \eta_3}
  \d\eta_1 \d\eta_2 \d\eta_3.
\end{equation}
We can then write
\begin{equation} \label{eq:45}
  \widetilde{u_+^3}(\tau, \xi) = \1{(2 \pi)^3}
  \ip{\fph \otimes \fph \otimes \fph, \abs{\cdot}^{-\12} \otimes
    \abs{\cdot}^{-\12} \otimes \abs{\cdot}^{-\12}}_{(\tau, \xi)},
\end{equation}

\begin{lemma} \label{lem:4}
  For each $(\tau, \xi) \in \mC_{+++}$ we have 
  $\norm{\abs{\cdot}^{-\12} \otimes \abs{\cdot}^{-\12}
    \otimes \abs{\cdot}^{-\12}}_{(\tau, \xi)} = 2 \pi$.
\end{lemma}

\begin{proof}
  The square of the norm we want to compute is the integral $I_3$
  of lemma~\ref{lem:7},
  \begin{equation*}
    \norm{\abs{\cdot}^{-\12} \otimes \abs{\cdot}^{-\12}
      \otimes \abs{\cdot}^{-\12}}_{(\tau, \xi)}^2 = 
    I_3(\tau, \xi) = 4 \pi^2.
  \end{equation*}
\end{proof}

Cauchy-Schwarz's inequality applied to~\eqref{eq:45}
and lemma~\ref{lem:4} give
\begin{multline} \label{eq:46}
  \Norm{u_+^3}^2 = \1{(2 \pi)^3} \Norm{\widetilde{u_+^3}}^2 \le
  \1{(2 \pi)^7} \int_{\R \times \R^2}
  \norm{\fph \otimes \fph \otimes \fph}_{(\tau, \xi)}^2
  \d\tau \d \xi = \\
  = \1{(2 \pi)^7} \norm{%
    \fph \otimes \fph \otimes \fph}_{L^2\tonde{(\R^2)^3}}^2
  = \1{(2 \pi)^7} \Norm{\fph}^6
  = \1{2 \pi} \norm{f_+}^6.
\end{multline}
This time,
equality holds if there exist a function $F: \mC_{+++} \to \C$
such that 
\begin{equation*}
  \Tonde{\fph \otimes \fph \otimes \fph}(\eta_1, \eta_2, \eta_3) =
  F(\tau, \xi)
  \abs{\eta_1}^{-\12} \abs{\eta_2}^{-\12} \abs{\eta_3}^{-\12},
\end{equation*}
for all $(\eta_1, \eta_2, \eta_3)$
in the support of the measure~\eqref{eq:44}.
This means that
\begin{equation*}
  \abs{\eta_1}^{\12} \fph(\eta_1)
  \abs{\eta_2}^{\12} \fph(\eta_2)
  \abs{\eta_3}^{\12} \fph(\eta_3)
  = F\Tonde{\abs{\eta_1} + \abs{\eta_2} + \abs{\eta_3},
    \eta_1 + \eta_2 + \eta_3},
\end{equation*}
for $\eta_1, \eta_2, \eta_3 \in \R^2$.
Examples of such functions are again
$\fph(\xi) = \abs{\xi}^{-\12} \Eu^{-\abs{\xi}}$,
$F(\tau, \xi) = \Eu^{-\tau}$.
More generally, 
by proposition~\ref{pro:5}
all maximizers for the estimate~\eqref{eq:46}
are given by the family
\begin{equation} \label{eq:47}
  \fh(\xi) =
  \abs{\xi}^{-\12} \exp\Tonde{A \abs{\xi} + b \cdot \xi + C},
\end{equation}
with $A, C \in \C$, $b \in \C^2$
and $\abs{\Re(b)} < -\Re(A)$ (in order to have an $L^2$ function).

\begin{lemma} \label{lem:11}
  Let $u$ be the $(+)$-wave corresponding
  to an $L^2$ function of the form~\eqref{eq:47},
  \begin{equation*}
    u(t, x) = \1{(2\pi)^2} \int_{\R^2}
    \exp\TOnde{(A + \iC t) \abs{\xi} + (b + \iC x) \cdot \xi + C}
    \frac{\d\xi}{\abs{\xi}}.
  \end{equation*}
  Then we have the explicit formula
  \begin{multline} \label{eq:48}
    2 \pi \Eu^{-\iC \Im(C)} u\Tonde{t - \Im(A), x - \Im(b)} = \\
    = \frac{\Eu^{\Re(C)}}
    {\sqrt{(\Re(A))^2 - \abs{\Re(b)}^2 + \abs{x}^2 - t^2 +
        2 \iC \tonde{\Re(A) t - \Re(b) \cdot x}}}.
  \end{multline}
\end{lemma}

\begin{proof}
  The integral
  \begin{equation*}
    F(t, x) = \int_{\R^2} \exp\Tonde{t \abs{\xi} + x \cdot \xi}
    \frac{\d\xi}{\abs{\xi}}
  \end{equation*}
  is well defined for $t \in \C$ and $x \in \C^2$
  when $\Re(t) < -\abs{\Re(x)}$.
  For $t \in \R$ and $x \in \R^2$ with $t < -\abs{x}$,
  using polar coordinate we find
  \begin{equation*}
    F(t, x) = \int_0^{2 \pi} \int_0^\infty
    \exp\Tonde{(t + \abs{x} \cos\theta) r} \d r \d\theta =
    \int_0^{2 \pi} \frac{\d\theta}{-t - \abs{x} \cos\theta}
    = \frac{2 \pi}{\sqrt{t^2-\abs{x}^2}}.
  \end{equation*}
  By analytic continuation this formula remains valid
  for complex $t$ and $x$ with $\Re(t) < -\abs{\Re(x)}$.
  Formula~\eqref{eq:48} follows from the identity  
  \begin{equation*}
    \Eu^{-\iC \Im(C)} u\Tonde{t - \Im(A), x - \Im(b)}
    = \frac{\Eu^{\Re(C)}}{(2 \pi)^2} 
    F\Tonde{\Re(A) + \iC t, \Re(b) + \iC x}.
  \end{equation*}
\end{proof}

\begin{remark} \label{rem:3}
  If $u$ is the $(+)$-wave corresponding
  to an $L^2$ function of the form~\eqref{eq:47},
  then the knowledge of $\abs{u(t, x)}$
  uniquely determines 
  the value of the coefficients~$A$,~$b$ and~$\Re(C)$.
  The proof of this fact is similar
  to the one outlined in remark~\ref{rem:2}.
\end{remark}

\medskip
Similarly, for the term $\norm{u_-^3}$ we have
\begin{equation*}
  \Norm{u_-^3}^2 \le \1{2 \pi} \norm{f_-}^6,
\end{equation*}
with equality when $f_-$ takes the form~\eqref{eq:47}.

\medskip
For the term $\norm{u_+^2 u_-}$,
we observe that by H\"older's inequality we have
\begin{equation} \label{eq:49}
  \Norm{u_+^2 u_-}^2 \le
  \Norm{u_+^3}^{\frac43} \Norm{u_-^3}^{\frac23} \le
  \1{2 \pi} \norm{f_+}^4 \norm{f_-}^2.
\end{equation}
The second inequality in~\eqref{eq:49} is an equality
if $f_+$ and $f_-$ are functions of the form~\eqref{eq:47}.
The first inequality in~\eqref{eq:49} is an equality
if there is a constant $\mu \ge 0$
such that $\abs{u_+(t, x)} = \mu \abs{u_-(t, x)}$
for (almost all) $(t, x) \in \R \times \R^2$.

\begin{lemma}
  Let $u_+$ be a $(+)$-wave and $u_-$ be a $(-)$-wave
  corresponding to initial data $f_+$ and $f_-$
  of the form~\eqref{eq:47}.
  If there exists $\mu \ge 0$ 
  such that $\abs{u_+(t, x)} = \mu \abs{u_-(t, x)}$
  for all $t$ and $x$,
  then
  \begin{equation} \label{eq:50}
    \fph(\xi) = \abs{\xi}^{-\12}
    \exp\Tonde{A \abs{\xi} + b \cdot \xi + C}, \qquad
    \fmh(\xi) = \abs{\xi}^{-\12}
    \exp\Tonde{\ovl{A} \abs{\xi} - \ovl{b} \cdot \xi + D},
  \end{equation}
  for some $A, C, D \in \C$ and $b \in \C^2$.
\end{lemma}
The proof of this lemma follows from the same argument
used in the proof of proposition~\ref{pro:6}.

\medskip
Similarly, for the term $\norm{u_+ u_-^2}$ we have
\begin{equation*}
  \Norm{u_+ u_-^2}^2 \le \1{2 \pi} \norm{f_+}^2 \norm{f_-}^4,
\end{equation*}
with equality if and only if
$f_+$ and $f_-$ are functions of the form~\eqref{eq:50}.

\medskip
Let us consider now the term $\Re\ip{u_+^3, u_+^2 u_-}$.
We have
\begin{equation*}
  \Re\ip{u_+^3, u_+^2 u_-} \le
  \abs{\ip{u_+^3, u_+^2 u_-}} \le
  \norm{u_+^3} \norm{u_+^2 u_-} \le
  \1{2 \pi} \norm{f_+}^5 \norm{f_-}.
\end{equation*}
Equality in the second and third inequalities here implies that
$f_+$ and $f_-$ are of the form~\eqref{eq:50},
while we must have $\Im(C) = \Im(D)$
to have equality in the first inequality.

\medskip
Similarly for the terms $\Re\ip{u_+ u_-^2, u_-^3}$
and $\Re\ip{u_+^2 u_-, u_+ u_-^2}$
we have
\begin{equation*}
  \abs{\Re\ip{u_+ u_-^2, u_-^3}} \le
  \1{2 \pi} \norm{f_+} \norm{f_-}^5, \qquad
  \abs{\Re\ip{u_+^2 u_-, u_+ u_-^2}} \le
  \1{2 \pi} \norm{f_+}^3 \norm{f_-}^3,
\end{equation*}
with equality when $f_+$ and $f_-$ are of the form~\eqref{eq:50}
with $\Im(C) = \Im(D)$.

\medskip
The terms $\Re\ip{u_+^3, u_+ u_-^2}$, $\Re\ip{u_+^3, u_-^3}$,
and $\Re\ip{u_+^2 u_-, u_-^3}$ are always zero.
Indeed, the Fourier transform of the cubic terms
$u_+^3$, $u_+^2 u_-$, $u_+ u_-^2$, $u_-^3$
are $L^2$ functions supported on the closures of the regions
\begin{align*}
  \mC_{+++} &=
  \graffe{(\tau, \xi) \in \R \times \R^2: \tau > \abs{\xi}}, \\
  \mC_{++-} &=
  \graffe{(\tau, \xi) \in \R \times \R^2: \tau > -\abs{\xi}}, \\
  \mC_{+--} &=
  \graffe{(\tau, \xi) \in \R \times \R^2: \tau > \abs{\xi}}, \\
  \mC_{---} &= 
  \graffe{(\tau, \xi) \in \R \times \R^2: \tau > -\abs{\xi}},
\end{align*}
respectively,
and the intersections
$\ovl{\mC_{+++}} \intersection \ovl{\mC_{+--}}$,
$\ovl{\mC_{+++}} \intersection \ovl{\mC_{---}}$,
$\ovl{\mC_{++-}} \intersection \ovl{\mC_{---}}$
are sets of measure zero.

\medskip
We put together all the estimates for each single term
and obtain
\begin{multline} \label{eq:51}
  2 \pi \norm{u}_{L^6}^6 \le
  \norm{f_+}^6 + \norm{f_-}^6
  + 9 \norm{f_+}^4 \norm{f_-}^2
  + 9 \norm{f_+}^2 \norm{f_-}^4 + \\
  + 6 \norm{f_+}^5 \norm{f_-}
  + 6 \norm{f_+} \norm{f_-}^5
  + 18 \norm{f_+}^3 \norm{f_-}^3.
\end{multline}

\begin{lemma} \label{lem:12}
  For $X \ge 0$ and $Y \ge 0$ we have
  the sharp polynomial inequality
  \begin{equation*}
    X^6 + Y^6 + 9 X^4 Y^2 + 9 X^2 Y^4 +
    6 X^5 Y + 6 X Y^5 + 18 X^3 Y^3 \le
    \frac{25}{4} \tonde{X^2 + Y^2}^3
  \end{equation*}
  with equality if and only if $X = Y$.
\end{lemma}

\begin{proof}
  By homogeneity we can assume that $Y = 1$.
  Let
  \begin{equation*}
    P(X) = X^6 + 1 + 9 X^4 + 9 X^2 + 6 X^5 + 6 X + 18 X^3, \qquad
    Q(X) = X^2 + 1.
  \end{equation*}
  We want to prove that $4 P(X) \le 25 Q(X)^3$ for $X \ge 0$,
  with equality if and only if $X = 1$.
  Since we have the identity
  \begin{equation*}
    4 P(X) = 4 Q(X)^3 + 24 \tonde{X Q(X)^2 + X^2 Q(X) + X^3},
  \end{equation*}
  our inequality is equivalent to
  \begin{equation*}
    24 \tonde{X Q(X)^2 + X^2 Q(X) + X^3} \le 21 Q(X)^3,
  \end{equation*}
  which reduces to
  \begin{equation*}
    8 \tonde{Z + Z^2 + Z^3} \le 7, \qquad 
    Z = \frac{X}{Q(X)} = \frac{X}{X^2+1} \in [0, 1/2].
  \end{equation*}
  On the interval $[0,1/2]$
  the polynomial $Z + Z^2 + Z^3$ is strictly increasing
  and takes its maximum value $7/8$ when $Z = 1/2$,
  which corresponds to $X = 1$.
\end{proof}

We apply lemma~\ref{lem:12} to~\eqref{eq:51} and finally obtain
\begin{equation} \label{eq:52}
  \norm{u}_{L^6} \le
  \tonde{\frac{25}{8 \pi}}^{\16}
  \tonde{\norm{f_+}_{L^2}^2 + \norm{f_-}^2}^{\12} = 
  \tonde{\frac{25}{64 \pi}}^{\16}
  \norm{(f, g)}_{\dot{H}^{\12}(\R^n) \times \dot{H}^{-\12}(\R^n)},
\end{equation}
which proves that $W(2) \ge (25 / (64 \pi))^{1/6}$.
The next proposition tells us that maximizers exist
and that all the inequalities are sharp;
hence, $W(2) = (25 / (64 \pi))^{1/6}$.

\begin{proposition}
  We have $\norm{u}_{L^6} = (25 / (64 \pi))^{1/6}
  \norm{(f, g)}_{\dot{H}^{\12} \times \dot{H}^{-\12}}$
  if and only if
  \begin{equation} \label{eq:53}
    \fph(\xi) = \abs{\xi}^{-\12}
    \exp\TOnde{A \abs{\xi} + b \cdot \xi + C}, \qquad
    \fmh(\xi) = \abs{\xi}^{-\12}
    \exp\TOnde{\ovl{A} \abs{\xi} - \ovl{b} \cdot \xi + C},
  \end{equation}
  where $A, C \in \C$ and $b \in \C^2$
  with $\abs{\Re(b)} < -\Re(A)$.  
\end{proposition}

\begin{proof}
  {}From the above discussion
  we have equalities in the estimates for each single cubic term
  if and only if $f_+$ and $f_-$ are of the form~\eqref{eq:50}
  with $\Im(C) = \Im(D)$.
  To have equality in~\eqref{eq:52} we also need 
  $\norm{f_+} = \norm{f_-}$
  which in this case implies $\Re(C) = \Re(D)$.
\end{proof}

A particular case of~\eqref{eq:53},
corresponding to $A = -1$, $b = 0$, $C = \log(2\pi)$,
is given by the initial data
\begin{equation} \label{eq:54}
   f_*(x) = \1{\sqrt{1 + \abs{x}^2}}, \qquad
   g_*(x) = 0, \qquad x \in \R^3.
\end{equation}

As we have seen at the end of section~\ref{sec:case-w-n-3},
the class of initial data of the form~\eqref{eq:53}
is invariant under the action of the group $\mL$
and any maximizer is connected to
the functions $(f_*, g_*)$
by the action of $\mL$.

\section{Functional equations}
\label{sec:functional-equations}

In this section we study the functional equations which
characterize the families of maximizers that
we have found in the previous sections.
They are:
\begin{align}
  \label{eq:55}
  & f(x) f(y) f(z) = F\Tonde{x^2 + y^2 + z^2, x + y + z} &
  & \text{for a.e. $(x, y, z) \in \R^3$}, \\
  \label{eq:56}
  & f(x) f(y) = F\Tonde{\abs{x}^2 + \abs{y}^2, x + y} &
  & \text{for a.e. $(x, y) \in \R^2 \times \R^2$}, \\
  \label{eq:57}
  & f(x) f(y) f(z) =
  F\Tonde{\abs{x} + \abs{y} + \abs{z}, x + y + z}, &
  & \text{for a.e. $(x, y, z) \in (\R^2)^3$}, \\
  \label{eq:58}
  & f(x) f(y) = F\Tonde{\abs{x} + \abs{y}, x + y}, &
  & \text{for a.e. $(x, y) \in \R^3 \times \R^3$},
\end{align}
where $f$ and $F$
are unknown complex valued measurable functions
and the identities are supposed to hold almost everywhere
with respect to the Lebesgue measure.
We are going to show that locally integrable solutions
to these equations are actually smooth functions;
this is a general principle which holds for a large class
of functional equation
(actually even assuming only measurability implies continuity,
see the work of A.\ J\'arai in \cite{Jar2003}),
but for the sake of completeness we include a direct proof
adapted to our equations.
Once the smoothness of $f$ and $F$ is established,
it is not difficult to solve the equation using 
geometric or differential methods.
It turns out that in all cases the function $F$
must be an exponential function of the form
\begin{equation*}
  F(t, x) = \exp\Tonde{A t + b \cdot x + C}.
\end{equation*}

A simpler model for the above functional equations
is provided by the exponential law, $f(x) f(y) = f(x + y)$,
which is one of the four basic Cauchy functional equations.
We refer the reader to~\cite{Acz1966} for a general introduction
to the subject of functional equations.
Here, we only require the following result
which is a simple exercise in real analysis.

\begin{lemma} \label{lem:10}
  Let $\Omega$ be an open subset of $\R^n$ 
  such that $x + y \in \Omega$ whenever $x, y \in \Omega$.
  Let $f: \Omega \to \C$ be a non-trivial locally integrable
  solution of the Cauchy functional equation
  \begin{equation} \label{eq:59}
    f(x) f(y) = f(x + y), \qquad
    \text{for a.e.\ $(x, y) \in \Omega \times \Omega$}.
  \end{equation}
  Then there exists a vector $b \in \C^n$ such that 
  $f(x) = \exp(b \cdot x)$ for a.e.\ $x \in \Omega$.
\end{lemma}

\begin{proof}
  Let $Q$ be cube contained in $\Omega$ such that
  $\int_Q f(y) \d y \ne 0$.
  If we integrate~\eqref{eq:59} with respect to $y \in Q$
  we obtain that $f(x)$ must coincide (almost everywhere)
  with the continuous function
  \begin{equation*}
    x \mapsto \frac{\int_Q f(x+y) \d y}{\int_Q f(y) \d y}.
  \end{equation*}
  If $f$ is continuous the above function is differentiable.
  Hence, we may assume that $f$ is differentiable.
  Fix $y_0 \in \Omega$ and let $b = (\nabla f(y_0))/f(y_0)$.
  If we differentiate~\eqref{eq:59} with respect to $y$
  and set $y = y_0$ we obtain the differential equation
  \begin{equation*}
    \nabla f(x + y_0) = f(x) \nabla f(y_0) =
    f(x) f(y_0) b = f(x + y_0) b,
  \end{equation*}
  whose non trivial solutions have the form
  $f(z) = \exp(b \cdot z + C)$ for some constant $C \in \C$.
  Substituting this expression for $f$ into~\eqref{eq:59},
  we obtain that $\exp(C)$ must be $1$.
\end{proof}

As was done in the lemma,
regularity properties of solutions to functional equations
can be obtained by (partial) integration of the equation.
The following lemmata,
although not expressed in their most general form,
are what we need to deduce continuity from local integrability
in our equations.

\begin{lemma} \label{lem:19}
  Let $A, B, \Omega$ be open subsets of $\R^n$.
  Let $f \in L^p_{\rm loc}(\Omega)$
  and let \mbox{$\varphi: A \times B \to \Omega$} be a smooth map such that
  \begin{equation} \label{eq:60}
    \det \abs{\pder{\varphi}{y}(x, y)} \ne 0, \qquad
    \text{for $(x, y) \in A \times B$}.
  \end{equation}
  Let $K$ be a compact subset of $B$.
  For each $x \in A$,
  let $g_x: B \to \Omega$ be the function $g_x(y) = f\tonde{\varphi(x, y)}$.
  Then the map $x \mapsto g_x$
  is a continuous application from $A$ to $L^p(K)$.
\end{lemma}

\begin{proof}
  The case of $f$ continuous is immediate.
  The general case follows by density.
  The condition on the partial Jacobian of $\varphi$
  is enough to apply, at least locally, 
  the change of variable $y \changeto z = \varphi(x, y)$
  in the integration over $K$.
  We leave the details to the reader.
\end{proof}

\begin{remark}
  Lemma~\ref{lem:19} does not hold if we remove condition~\eqref{eq:60}.
  For example, if $A = B = \Omega$ and $\varphi(x, y) = x$
  then we would have $g_x(y) = f(x)$
  and the map $x \mapsto \norm{g_x}_{L^p(K)} = \abs{K}^{1/p} \abs{f(x)}$
  may not be continuous.
\end{remark}

\begin{lemma} \label{lem:15}
  Let $A, B, \Omega$ be open subsets of $\R^n$.
  Let $f_j \in L^{p_j}_{\rm loc}(\Omega)$, $j = 1, 2, \dots, N$,
  with $\sum_j 1/p_j = 1$.
  Let $\varphi_1, \varphi_2, \dots, \varphi_N: A \times B \to \Omega$
  be smooth maps such that
  \begin{equation*}
    \det \abs{\pder{\varphi_j}{y}(x, y)} \ne 0, \qquad
    (x, y) \in A \times B, \quad
    j = 1, 2, \dots, N.
  \end{equation*}
  Let $\psi: A \times B \to \C$ be a continuous function.
  Let $K$ be a compact subset of $B$.
  Then the function
  \begin{equation*}
    F(x) = \int_K \prod_{j = 1}^N f_j\tonde{\varphi_j(x, y)} \psi(x,y) \d y,
    \qquad x \in A,
  \end{equation*}
  is continuous.
\end{lemma}

\begin{proof}
  The continuity of $F$ follows from the previous lemma
  and the continuity of the functional
  \begin{equation*}
    \tonde{x, g_1, g_2, \dots g_N} \mapsto
    \int_K \prod_j g_j(y) \psi(x,y) \d y
  \end{equation*}
  defined on $A \times \prod_j L^{p_j}_{\rm loc}(\Omega)$.
\end{proof}

\begin{proposition} \label{pro:2}
  Let $\Omega$ be an open subset of $\R^n \times \R^n$
  such that the section
  \mbox{$\Omega_x = \graffe{y \in \R^n: (x, y) \in \Omega}$}
  is dense in $\R^n$ for each $x \in \R^n$.
  Let $P, Q: \Omega \to \R^n$ be smooth maps such that
  \begin{equation} \label{eq:61}
    \det \abs{\pder{P}{y}(x, y)} \ne 0, \qquad
    \det \abs{\pder{Q}{y}(x, y)} \ne 0, \qquad
    \text{for $(x, y) \in \Omega$}.
  \end{equation}
  If $f: \R^n \to \C$ is a locally integrable solution
  of the functional equation
  \begin{equation} \label{eq:62}
    f(x) f(y) = f\Tonde{P(x, y)} f\Tonde{Q(x, y)}, \quad
    \text{for a.e. $(x, y) \in \Omega$},
  \end{equation}
  then $f$ is continuous.
\end{proposition}

\begin{proof}
  We may assume that $f$ is non trivial.
  Let $g(x) = \sqrt{\abs{f(x)}}$.
  When \mbox{$f \in L^1_{\rm loc}(\R^n)$} we have $g \in L^2_{\rm loc}(\R^n)$.
  Hence, by~\eqref{eq:61}, it follows that for every $x \in \R^n$
  the function $y \mapsto g(P(x, y)) g(Q(x, y))$
  is locally integrable on $\Omega$.
  Fix $x_0 \in \R^n$ and choose a compact domain $D$ in $\Omega_{x_0}$
  such that $\int_D f \ne 0$.

  We integrate the square root of the absolute value
  of equation~\eqref{eq:62}
  with respect to $y$ over the domain $D$ and obtain
  \begin{equation*}
    g(x) \int_D g(y) \d y = \int_D g\Tonde{P(x, y)} g\Tonde{Q(x, y)} \d y.
  \end{equation*}
  By lemma~\ref{lem:15},
  the right hand side is a continuous function of $x$
  for $x$ in a neighborhood of $x_0$.
  Since $\int_D g \ne 0$, we obtain that $g$ is continuous in $x_0$.
  This proves that $\abs{f}$ is a continuous function.
  In particular it follows that $f \in L^2_{\rm loc}$.
  We can bootstrap the argument:
  if we integrate~\eqref{eq:62}
  with respect to $y$ over the domain $D$, we obtain
  \begin{equation*}
    f(x) \int_D f(y) \d y = 
    \int_D f\Tonde{P(x, y)} f\Tonde{Q(x, y)} \d y,
  \end{equation*}
  from which it follows that $f$ is continuous.
\end{proof}

In the following subsections
we will study in detail each of our four functional equations.
In each case we will adopt the following strategy:
\begin{enumerate}
\item Local integrable solutions are continuous.
\item Nontrivial continuous solutions never vanish.
\item Continuous solutions which never vanish are of exponential form.
\end{enumerate}

\begin{remark} \label{rem:6}
  It is interesting to observe that
  there are functional equations 
  which formally look
  very similar to the ones we are considering,
  but
  for which each of the above three steps fail.
  Take for instance the functional equation
  \begin{equation*}
    f(x) f(y) = F\Tonde{x^2 + y^2, x + y} \text{ for a.e. $(x, y) \in \R^2$}.
  \end{equation*}
  In this case,
  given \emph{any} function $f$
  we can always construct a solution by setting
  \begin{equation*}
    F(s, t) =
    f\TOnde{\frac{t + \sqrt{2 s - t^2}}2}
    f\TOnde{\frac{t - \sqrt{2 s - t^2}}2}.
  \end{equation*}
  Even if the function $f$ is locally integrable,
  it does not need to be an exponential,
  it can vanish on any set and does not need to be continuous.
\end{remark}

\subsection{The equation~\eqref{eq:55}.}

As in section~\ref{sec:case-n-1}
we let $\mP_1 = \graffe{(s, t) \in \R \times \R: 3s > t^2}$.

\begin{lemma} \label{lem:9}
  Let $f: \R \to \C$ and $F: \ovl{\mP_1} \to \C$ be functions which 
  solve equation~\eqref{eq:55}.
  If $f$ is locally integrable then $f$ and $F$ are continuous functions.
\end{lemma}

\begin{proof}
  We first prove that
  $f$ locally integrable implies $F$ locally integrable.
  Indeed, 
  \begin{multline*}
    \iiint_{\abs{x}^2 + \abs{y}^2 + \abs{z}^2 \le R^2}
    \Abs{f(x) f(y) f(z)} \d x\d y\d z = 
    \int_{\substack{v \in \R^3 \\ \abs{v} \le R}}
    \Abs{F\Tonde{\abs{v}^2, v \cdot (1, 1, 1)}} \d v = \\
    = 2 \pi \int_0^R \int_{-1}^1
    \abs{F\Tonde{r^2, \sqrt3 r u}} r^2 \d u\d r =
    \frac{\pi}{\sqrt3} \iint_{\frac{t^2}3 \le s \le R^2}
    \abs{F(s,t)} \d s \d t,
  \end{multline*}
  for any $R > 0$.
  Moreover, using the change of variables
  \begin{equation*}
    (y, z) \changeto (s, t) = \Phi(y, z) = (y^2 + z^2, y + z)
  \end{equation*}
  from the region $\graffe{y > z}$ to $\graffe{s > t^2/2}$,
  with $\d s\d t = 2(y-z) \d y\d z$,
  we have
  \begin{multline*}
    f(x) \int_\Omega f(y) f(z) (y-z) \d y \d z
    = \int_\Omega F\tonde{x^2 + y^2 + z^2, x + y + z}
    (y-z) \d y \d z = \\
    = \12 \int_{\Phi(\Omega)} F\tonde{x^2 + s, x + t} \d s \d t.
  \end{multline*}
  for any bounded domain $\Omega \subseteq \graffe{y > z}$.
  The local integrability of $F$ implies that the function
  $x \mapsto \int_{\Phi(\Omega)} F(x^2 + s, x + t) \d s\d t$
  is continuous.
  We choose $\Omega$ so that
  the integral $\int_\Omega f(y) f(z) (y-z) \d y \d z$ is not zero
  and it follows that $f(x)$ is continuous.

  The continuity of $F$ comes easily from the equation 
  and the continuity of $f$, since we have
  \begin{equation*}
    F(s, t) = f(0)
    f\TOnde{\frac{t + \sqrt{2 s - t^2}}2}
    f\TOnde{\frac{t - \sqrt{2 s - t^2}}2}.
  \end{equation*}
\end{proof}

\begin{remark} \label{rem:1}
  We can write~\eqref{eq:55} as
  \begin{equation*}
    \tonde{f \otimes f \otimes f} (v) = F(s, t), \qquad
    v \in \R^3, \qquad
    s = \abs{v}^2, \qquad
    t = v \cdot (1, 1, 1),
  \end{equation*}
  which shows that the tensor product $f \otimes f \otimes f$,
  as a function on $\R^3$,
  is constant along any circle $\Gamma(s, t)$
  obtained as the intersection
  between the sphere of radius~$\sqrt{s}$ centered at the origin
  and the plane orthogonal to the vector $(1, 1, 1)$
  passing through the point $(t/3, t/3, t/3)$.
\end{remark}

\begin{lemma} \label{lem:8}
  If $f$ and $F$ are continuous functions which 
  solve equation~\eqref{eq:55}
  and $f$ vanishes at one point
  then $f$ and $F$ vanish everywhere.
\end{lemma}

\begin{proof}
  By continuity it is enough to prove that
  the set of all points where $f$ vanishes is open.
  Suppose $f$ vanishes at a point $x_*$.
  If $f$ is not identically zero then
  there exists some open set $A$ in $\R$
  on which $f$ never vanishes.
  Let $y_*$ and $z_*$ be two distinct points in $A$.
  Consider the map
  \begin{equation*}
    (y, z) \mapsto (s, t) = (x_*^2 + y^2 + z^2, x_* + y + z).
  \end{equation*}
  Its Jacobian determinant at the point $(y_*, z_*)$
  is $2 \abs{y_* - z_*} \ne 0$.
  Hence, the map
  is invertible from a neighborhood $U \subset A \times A$ of $(y_*, z_*)$
  to a neighborhood $V$
  of $(s_*, t_*) = (x_*^2 + y_*^2 + z_*^2, x_* + y_* + z_*)$.
  It follows that,
  for each $x$ sufficiently close to $x_*$ so that
  $(x^2 + y_*^2 + z_*^2, x + y_* + z_*)$ lies in $V$,
  there exists a pair $(y, z) \in U$ such that
  \begin{equation*}
    (x^2 + y_*^2 + z_*^2, x + y_* + z_*) = (x_*^2 + y^2 + z^2, x_* + y + z).
  \end{equation*}
  Using the functional equation~\eqref{eq:55} we obtain
  \begin{equation*}
    f(x) f(y_*) f(z_*) = f(x_*) f(y) f(z) = 0,
  \end{equation*}
  and we know that $f(y_*) f(z_*) \ne 0$.
  Hence, $f(x)$ vanishes for $x$ in a neighborhood of~$x_*$.
\end{proof}

\begin{proposition} \label{pro:1}
  If $f: \R \to \C$ and $F: \ovl{\mP_1} \to \C$ 
  are non-trivial locally integrable functions
  which satisfy the functional equation~\eqref{eq:55}
  for all $x, y, z \in \R$,
  then there exists complex constants $A$, $B$, $C$
  such that 
  \begin{equation*}
    f(x) = \exp\Tonde{A x^2 + B x + C}, \qquad
    F(t, x) = \exp\tonde{A t +  B x + 3C},
  \end{equation*}
  for (almost) all $(t, x) \in \mP_1$.
\end{proposition}

\begin{proof}
  By lemma~\ref{lem:9},
  we may assume that $f$ and $F$ are continuous.
  By lemma~\ref{lem:8},
  we may assume that $f$ and $F$ never vanishes.
  We define
  \begin{align*}
    & g(x) = \frac{f(x)}{f(-x)}, &
    & G(s, t) = \frac{F(s, t)}{F(s, -t)}, &
    & h(x) = f(x) f(-x), &
    & H(s, t) = F(s, t) F(s, -t).
  \end{align*}

  The function $g$ corresponds to the \emph{odd} component of $f$,
  $g(x) g(-x) = 1$, $g(0) = 1$,
  and satisfies the same equation
  \begin{equation*}
    g(x) g(y) g(z) = G\tonde{x^2 + y^2 + z^2, x + y + z}, \qquad
    x, y, z \in \R.
  \end{equation*}
  In particular,
  \begin{equation*}
    G(2s, 0) = g\tonde{\sqrt{s}} g\tonde{-\sqrt{s}} g(0) = 1,
  \end{equation*}
  for all $s \ge 0$.
  It follows that
  \begin{equation*}
    g(x) g(y) = g(x + y) g(-x-y) g(x) g(y) = 
    g(x + y) G\tonde{(x+y)^2 + x^2 + y^2, 0} = g(x + y).
  \end{equation*}
  By lemma~\ref{lem:10},
  $g$ must be an exponential function of the form
  $g(x) = \exp(2 B x)$ for some complex constant $B$.

  The function $h$ corresponds to the \emph{even} component of $f$,
  $h(x) = h(-x)$ and satisfies the equation
  \begin{equation*}
    h(x) h(y) h(z) =
    H\tonde{x^2 + y^2 + z^2, x \pm y \pm z}, \qquad
    x, y, z \in \R,
  \end{equation*}
  for any combination of signs.
  By the same argument used in remark~\ref{rem:1},
  we have that $h \otimes h \otimes h$
  is constant along circles obtained by
  intersecting spheres centered at the origin
  with planes perpendicular
  to the four vectors $(1, \pm 1, \pm 1)$.
  It follows that $h \otimes h \otimes h$ must be constant
  on any sphere centered at the origin.
  In fact, any two points at the same distance from the origin
  can be connected by a finite sequence
  of arcs of the above circles.
  This means that there exists
  a function $\varphi: \R_+ \to \C$ such that
  \begin{equation*}
    \frac{h(x) h(y) h(z)}{h(0)^3} =
    \varphi\tonde{x^2 + y^2 + z^2}, \qquad
    x, y, z \in \R.
  \end{equation*}
  In particular, for $s \ge 0$ and $t \ge 0$, we have
  \begin{equation*}
    \varphi(s) \varphi(t) = 
    \frac{h\tonde{\sqrt{s}} h(0)^2}{h(0)^3} \cdot  
    \frac{h\tonde{\sqrt{t}} h(0)^2}{h(0)^3} =
    \frac{h\tonde{\sqrt{s}} h\tonde{\sqrt{t}} h(0)}{h(0)^3} =
    \varphi(s+t).
  \end{equation*}
  By lemma~\ref{lem:10},
  $\varphi$ must be an exponential function of the form
  $\varphi(s) = \exp(2 A s)$ for some complex constant $A$.
  Hence, $h(x) = h(0) \exp\tonde{2 A x^2}$.

  We conclude the proof of the lemma by observing that
  \begin{equation*}
    f(x)^2 = g(x) h(x) = \exp(2 B x) h(0) \exp\tonde{A x^2} =
    \exp\tonde{2 A x^2 + 2 B x + 2 C},
  \end{equation*}
  where $C$ is a complex constant such that $f(0) = \Eu^C$.
\end{proof}

\subsection{The equation~\eqref{eq:56}.}

If we integrate equation~\eqref{eq:56}
with respect to $y$ on a domain of $\R^2$,
we cannot apply directly the regularity results of lemma~\ref{lem:15},
because the domain of $F$ is a region in $\R^3$
and the image of the application
\mbox{$y \mapsto \Tonde{\abs{x}^2 + \abs{y}^2, x + y}$}
is a set of measure zero in $\R^3$.
To overcome this difficulty
we exploit the geometric invariance properties of the equation.

\begin{remark} \label{rem:4}
  Let $I: \R^2 \to \R^2$ be the identity on $\R^2$ 
  and let $H: \R^2 \to \R^2$, $H(x_1, x_2) = (-x_2, x_1)$,
  be a counterclockwise rotation by $\pi/2$ of the plane.
  Given two points $x$ and $y$ in $\R^2$
  the functions
  \begin{align*}
    P(x, y) &= \frac{x + y}{2} + H\TOnde{\frac{x - y}{2}} =
    \frac{I+H}{2} x + \frac{I-H}{2} y, \\
    Q(x, y) &= \frac{x + y}{2} - H\TOnde{\frac{x - y}{2}} =
    \frac{I-H}{2} x + \frac{I+H}{2} y,
  \end{align*}
  determine two other points $p = P(x, y)$ and $q = Q(x, y)$
  so that $x, y$ and $p, q$ are the opposite vertices of a square
  (see figure~\ref{fig:1}) and we have
  \begin{equation} \label{eq:63}
    p + q = x + y, \qquad
    \abs{p}^2 + \abs{q}^2 = \abs{x}^2 + \abs{y}^2.
  \end{equation}
  Moreover, the linear map $(x, y) \mapsto (p, q)$
  is an isometry on $\R^2 \times \R^2$.
  By property~\eqref{eq:63},
  it follows that the equation~\eqref{eq:56}
  implies the equation
  \begin{equation} \label{eq:64}
    f(x) f(y) = f\Tonde{P(x, y)} f\Tonde{Q(x, y)}, \qquad
    \text{for a.e. $(x, y) \in \R^2 \times \R^2$}.
  \end{equation}
  Observe also that $\de P / \de y = (I - H) / 2$
  and $\de Q / \de y = (I + H) / 2$ are non singular matrices.
\end{remark}

\begin{figure}
  \centering
  \begin{tikzpicture}[scale=0.8, >=latex]
    \begin{scope}
      \draw[->, thick]
      (0, 0) node[below] {$O$} -- (2, 1) node[right] {$x$};
      \draw[->, thick]
      (0, 0) -- (-1, 2) node[above] {$Hx$};
      \draw[->, dashed]
      (0, 0) +(40:2cm) arc (40:100:2cm);
    \end{scope}
    \begin{scope}[xshift=5.5cm, rotate=30]
      \draw[dashed]
      (0, 0) circle (2cm)
      (0, -2) node[below] {$x$} -- (0, 2) node[above] {$y$}
      (-2, 0) node[left] {$P(x,y)$} -- (2, 0) node[right] {$Q(x,y)$};
      \draw[thick]
      (0, -2) -- (2, 0) -- (0, 2) -- (-2, 0) -- cycle;
    \end{scope}
    \begin{scope}[xshift=11cm, rotate=-20]
      \draw[dashed]
      (-1, -2) -- (1, 2)
      (-1, 2) -- (1, -2);
      \draw[thick]
      (-1, -2) node[left] {$a$} -- (1, -2) node[below] {$b$}
      -- (1, 2) node[right] {$c$} -- (-1, 2) node[above] {$d$} -- cycle;
    \end{scope}
  \end{tikzpicture}
  \caption{The functions $H$ (left) and $P, Q$ (center)
    described in remark~\ref{rem:4}
    and a rectangle (right) used in remark~\ref{rem:5}}
  \label{fig:1}
\end{figure}

As in section~\ref{sec:case-n-2}
we let $\mP_2 = \graffe{(s, v) \in \R \times \R^2: 2s > \abs{v}^2}$.

\begin{lemma} \label{lem:13}
  Let $f:\R^2 \to \C$ and $F: \ovl{\mP_2} \to \C$
  be solutions of equation~\eqref{eq:56}.
  If $f$ is locally integrable
  then $f$ and $F$ are continuous functions.
\end{lemma}

\begin{proof}
  By remark~\ref{rem:4},
  the lemma becomes a corollary of proposition~\ref{pro:2}.
\end{proof}

\begin{lemma} \label{lem:5}
  If $f$ is a continuous solution of equation~\eqref{eq:64}
  and $f$ vanishes at one point then $f$ vanishes everywhere.
\end{lemma}

\begin{proof}
  Let $y \in \R^2$.
  If $f$ vanishes at the point $x_0$,
  using equation~\eqref{eq:64} we must have that
  $f$ vanishes at the point $x_1$,
  where $x_1$ is either $P(x_0, y)$ or $Q(x_0, y)$,
  and $\abs{x_1 - y} = (1/\sqrt2) \abs{x_0 - y}$.
  By iterating this argument,
  we can construct a sequence of points $x_n$
  such that $f(x_n) = 0$ and $\lim_n x_n = y$.
  By continuity it follows that~$f(y) = 0$.
\end{proof}

\begin{remark} \label{rem:5}
  It follows from equation~\eqref{eq:56}
  that $f$ solves the rectangular functional equation
  \begin{equation*}
    f(a) f(c) = f(b) f(d),
  \end{equation*}
  whenever the points $a, c$ and $b, d$
  are the opposite vertices of a rectangle (see figure~\ref{fig:1}).
  Indeed, when $a - b = d - c$ and $a - b \perp c - b$,
  we have
  \begin{equation*}
    0 = (a - b) \cdot (c - b) =
    a \cdot c - (a + c) \cdot b + \abs{b}^2 = 
    a \cdot c - (b + d) \cdot b + \abs{b}^2 = 
    a \cdot c - d \cdot b.
  \end{equation*}
  Hence, $a \cdot c = b \cdot d$ and
  $\abs{a}^2 + \abs{c}^2 = \abs{a + c}^2 - 2 a \cdot c = 
  \abs{b + d}^2 - 2 b \cdot d = \abs{b}^2 + \abs{d}^2$.
\end{remark}

\begin{proposition} \label{pro:3}
  If $f: \R^2 \to \C$ and $F: \ovl{\mP_2} \to \C$ 
  are nontrivial locally integrable functions
  which satisfy the functional equation~\eqref{eq:56}
  then there exists constants
  \mbox{$A \in \C$}, \mbox{$b \in \C^2$}, $C \in \C$
  such that 
  \begin{equation*}
    f(x) = \exp\Tonde{A \abs{x}^2 + b \cdot x + C}, \qquad
    F(t, x) = \exp\Tonde{A t +  b \cdot x + 2C},
  \end{equation*}
  for (almost) all $(t, x) \in \mP_2$.
\end{proposition}

In the proof of the proposition we follow a geometric construction
which is an adaptation of the one for odd orthogonally additive mappings
found in~\cite{Rat1985}.

\begin{proof}
  By lemma~\ref{lem:13},
  we may assume that $f$ and $F$ are continuous.
  By lemma~\ref{lem:5},
  we may assume that $f$ and $F$ never vanishes.
  We define
  \begin{align*}
    & g(x) = \frac{f(x)}{f(-x)}, &
    & G(t, z) = \frac{F(t, z)}{F(t, -z)}, &
    & h(x) = f(x) f(-x), &
    & H(t, z) = F(t, z) F(t, -z).
  \end{align*}
  The function $g$ corresponds to the \emph{odd} component of $f$,
  $g(x) g(-x) = 1$ and $g(0) = 1$.
  By remark~\ref{rem:5} we know
  it satisfies the rectangular equation $g(a) g(c) = g(b) g(d)$,
  whenever the points $a, c$ and $b, d$
  are the opposite vertices of a rectangle.
  Given two vectors $x$ and $y$ in $\R^2$
  it is always possible to find a third vector $z$ such that
  $z \perp x + y$ and $x + z \perp y - z$.
  Let $p$ and $-p$ be the components of $x$ and $y$ perpendicular to~$x + y$.
  \begin{figure}
    \centering
    \begin{tikzpicture}[scale=0.18, >=latex]
      \begin{scope}
        \draw[dotted]
        (-13, 0) -- (13, 0);
        \draw[->, thick] (0, 0) -- (7, 9);
        \draw[->, thick] (0, 0) -- (-7, 16);
        \draw[->, thick] (0, 0) -- (0, 25);
        \draw[dashed]
        (7, 9) -- (0, 25) -- (-7, 16);
        \draw
        (0, 0) node[below] {$O$} --
        (12, 9) node[right] {$x{+}z$} --
        (12, 0) node[below right] {$p{+}z$} --
        (7, 0) node[below] {$p$} --
        (7, 9) node[left] {$x$} --
        (12, 9) --
        (0, 25) node[above] {$x{+}y$} --
        (-12, 16) node[left] {$y{-}z$} --
        (-12, 0) node[below] {$-p{-}z$} --
        (-7, 0) node[below] {$-p$} --
        (-7, 16) node[right] {$y$} --
        (-12, 16) -- cycle;
      \end{scope}
      \begin{scope}[shift={(30, 2)}]
        \draw (-10,0) node[below] {$-q$} rectangle (0, 15) node[above] {$p$}
        rectangle (10, 0) node[below] {$q$};
        \draw[->, thick] (0, 0) node[below] {$O$}
        -- (-10, 15) node[above] {$-y$};
        \draw[->, thick] (0, 0) -- (10, 15) node[above] {$y$};
      \end{scope}
    \end{tikzpicture}
    \caption{Constructions for the function $g$ (left)
      and the function $h$ (right)
      in the proof of proposition~\ref{pro:3}}
    \label{fig:2}
  \end{figure}
  Consider the three rectangles formed by
  $(0, x+z, x+y, y-z)$, $(x, x+z, p+z, p)$ and $(y, y-z, -p-z, -p)$
  (see figure~\ref{fig:2});
  using the rectangular equation we have
  \begin{align*}
    g(x+y) g(0) &= g(x+z) g(y-z), \\
    g(x) g(p+z) &= g(x+z) g(p), \\
    g(y) g(-p-z) &= g(y-z) g(-p);
  \end{align*}
  and using the parity properties of $g$ we obtain
  \begin{multline*}
    g(x+y) = g(x+y) g(0) = g(x+z) g(y-z) = g(x+z) g(p) g(y-z) g(-p) = \\
    = g(x) g(p+z) g(y) g(-p-z) = g(x) g(y).
  \end{multline*}
  By lemma~\ref{lem:10},
  $g$ must be an exponential function of the form
  $g(x) = \exp(2 b \cdot x)$ for some complex vector $b \in \C^2$.

  The function $h$ corresponds to the \emph{even} component of $f$,
  $h(x) = h(-x)$, and satisfies the rectangular equation
  $h(a) h(c) = h(b) h(d)$,
  whenever the points $a, c$ and $b, d$
  are the opposite vertices of a rectangle.
  Given two points $x$ and $y$ with $\abs{x} = \abs{y}$,
  let $p = (x+y)/2$, $q = (x-y)/2$ and consider the rectangles
  $(0, p, x, q)$, $(0, p, y, -q)$ (see figure~\ref{fig:2});
  by the rectangular equation and the parity of $h$ we have
  \begin{equation*}
    h(x) h(0) = h(p) h(q) = h(p) h(-q) = h(y) h(0).
  \end{equation*}
  Hence, $\abs{x} = \abs{y}$ implies $h(x) = h(y)$.
  This means that $h$ is spherically symmetric
  and there exists a function $\varphi: \R_+ \to \C$ such that
  $h(x) = h(0) \varphi\Tonde{\abs{x}^2}$, for $x \in \R^2$.
  Given $s \ge 0$ and $t \ge 0$,
  let $x$ and $y$ be two points in $\R^2$
  such that $\abs{x}^2 = s$, $\abs{y}^2 = t$ and $x \perp y$;
  by the Pythagorean theorem we have $\abs{x+y}^2 = s + t$.
  It follows that
  \begin{equation*}
    \varphi(s) \varphi(t) = \frac{h(x) h(y)}{h(0)^2} =
    \frac{h(x + y) h(0)}{h(0)^2} = \varphi(s+t).
  \end{equation*}
  By lemma~\ref{lem:10},
  $\varphi$ must be an exponential function of the form
  $\varphi(s) = \exp(2 A s)$ for some complex constant $A$.
  Hence, $h(x) = h(0) \exp\Tonde{2 A \abs{x}^2}$.

  We conclude the proof of the lemma by observing that
  \begin{equation*}
    f(x)^2 = g(x) h(x) = \exp(2 b \cdot x) h(0) \exp\Tonde{A \abs{x}^2} =
    \exp\tonde{2 A x^2 + 2 b \cdot x + 2 C},
  \end{equation*}
  where $C$ is a complex constant such that $f(0) = \Eu^C$.
\end{proof}

\subsection{The equation~\eqref{eq:57}.}

As in section~\ref{sec:case-w-n-2}
we let $\mC_{+++} = \graffe{(t, v) \in \R \times \R^2: t > \abs{v}}$.

\begin{lemma} \label{lem:14}
  Let $f: \R^2 \to \C$ and $F: \ovl{\mC_{+++}} \to \C$
  be functions which solve equation~\eqref{eq:57}.
  If $f$ is locally integrable then $f$ and $F$ are continuous functions.
\end{lemma}

\begin{proof}
  Suppose first that $f \in L^p_{\rm loc}(\R^2)$ for some $p > 2$.
  Using the results of lemma~\ref{lem:7} we can see that 
  $F \in L^1_{\rm loc}(\mC_{+++})$; indeed,
  \begin{multline*}
    \int_{\abs{v}^2 \le t \le R} \abs{F(t, v)} \d v\d t = 
    \1{8 \pi^2} \int_{\abs{v}^2 \le t \le R} \abs{F(t, v)} I_3(t, v) \d v\d t = \\
    = \1{8 \pi^2} \int_{t \le R}
    \frac{\Abs{F\Tonde{\abs{x} + \abs{y} + \abs{z}, x + y + z}}}
    {\abs{x} \abs{y} \abs{z}}
    \ddirac{t - \abs{x} - \abs{y} - \abs{z} \\ v - x - y - z}
    \d x \d y \d z \d v \d t = \\
    = \1{8 \pi^2} \int_{\abs{x} + \abs{y} + \abs{z} \le R}
    \frac{\abs{f(x) f(y) f(z)}}{\abs{x} \abs{y} \abs{z}}
    \d x \d y \d z  \le \1{8 \pi^2}
    \TOnde{\int_{\abs{x} \le R} \frac{\abs{f(x)}}{\abs{x}} \d x}^3 \le \\
    \le C \tonde{R^{1 - 2/p}}^3 \norm{f}_{L^p(B(0, R))}^3.
  \end{multline*}
  We choose now a bounded domain $\Omega \subseteq \R^2 \times \R^2$
  such that the integral
  \begin{equation*}
    C_\Omega = \int_\Omega \frac{f(y) f(z)}
    {\abs{y} \abs{z} I_2\tonde{\abs{y} + \abs{z}, y + z}} \d y \d z
  \end{equation*}
  is finite and not zero
  (here $I_2$ is the function defined in lemma~\ref{lem:7}).
  This is possible when $f$ is not trivial,
  since $f(x)/\abs{x}$ is locally integrable and $1/I_2$ is bounded
  on compact subsets of $\mC_{+++}$.
  We divide both sides of the equation~\eqref{eq:57} by 
  the quantity $\abs{y} \abs{z} I_2\tonde{\abs{y} + \abs{z}, y + z}$
  and integrate with respect to $(y, z) \in \Omega$; we obtain
  \begin{equation} \label{eq:65}
    f(x) C_\Omega =
    \int_D F\tonde{\abs{x} + t, x + v} \varphi_\Omega(t, v) \d v \d t,
  \end{equation}
  for almost every $x \in \R^2$,
  where 
  \begin{equation*}
    \varphi_\Omega(t, v) = \1{I_2(t, v)}
      \int_\Omega \ddirac{t - \abs{y} - \abs{z} \\ v - y - z}
      \frac{\d y\d z}{\abs{y} \abs{z}} \le 1
  \end{equation*}
  is a bounded continuous function
  and the region $D$ is its support.
  The continuity of $f$ now follows from 
  the continuity of the right hand side in~\eqref{eq:65}
  by lemma~\ref{lem:15}.

  Suppose now that $f \in L^1_{\rm loc}(\R^2)$,
  then for $p > 2$ the functions $g = \abs{f}^{1/p} \in L^p_{\rm loc}(\R^2)$,
  $G = \abs{F}^{1/p}$ also solve equation~\eqref{eq:57}
  and it follows from the previous argument that $g$ is continuous.
  Hence, $\abs{f}$ is also continuous
  and so we have that $f \in L^p_{\rm loc}(\R^2)$ for any $p$.

  The continuity of $F$ comes easily from the equation 
  and the continuity of $f$:
  if~$t \ge r \ge 0$ and $\omega$ is a unit vector, we have
  \begin{equation*}
    F(t, r \omega) = f(0)
    f\TOnde{\frac{r + t}{2} \omega}
    f\TOnde{\frac{r - t}{2} \omega}.
  \end{equation*}
\end{proof}

\begin{lemma} \label{lem:16}
  If $f$ and $F$ are continuous functions which 
  solve equation~\eqref{eq:57}
  and~$f$ vanishes at one point
  then $f$ and $F$ vanish everywhere.
\end{lemma}

\begin{proof}
  Equation~\eqref{eq:57} implies that
  \begin{equation} \label{eq:66}
    f\tonde{\frac{x}3}^3 = F\tonde{\abs{x}, x} = f(x) f(0)^2.
  \end{equation}
  Suppose $f(x_0) = 0$ then $f(x_1) = 0$ for $x_1 = x_0 / 3$.
  By iterating this argument, $x_{k+1} = x_k/3$,
  we can construct a sequence of points $x_n$
  such that $f(x_n) = 0$ and $\lim_n x_n = 0$.
  By continuity it follows that $f(0) = 0$
  and by~\eqref{eq:66} $f$ must vanishes everywhere.
\end{proof}

\begin{lemma} \label{lem:17}
  Let $n \ge 1$.
  Let $\mN = \graffe{(t, x) \in \R \times \R^n: t = \abs{x}}$
  be the cone of future null vectors
  and $\mC = \graffe{(t, x) \in \R \times \R^n: t > \abs{x}}$
  the cone of future time-like vectors.
  Observe that $\mN + \mN = \ovl{\mC} = \mN \union \mC$.
  If $F: \mN \union \mC \to \C$ is a continuous solution
  of the conditional functional equation 
  \begin{equation} \label{eq:67}
    U, V \in \mN \implies F(U) F(V) = F(U + V)
  \end{equation}
  then $F$ is also a solution of the unconditional functional equation
  \begin{equation*}
    F(X) F(Y) = F(X + Y), \qquad \forall X, Y \in \mC.
  \end{equation*}
\end{lemma}

\begin{figure}
  \centering
  \begin{tikzpicture}[scale=0.2, >=latex]
    \draw[dotted, thin]
    (-12, 12) -- (1, -1) 
    (-1, -1) -- (12, 12);
    \draw[dashed, thin]
    (-11, 11) -- (-1, 20) -- (10, 10)
    (-8, 8) -- (-4, 12) -- (4, 4)
    (-3, 3) -- (3, 9) -- (6, 6)
    (-4, 12) -- (-1, 20) -- (3, 9);
    \draw[->, semithick]
    (0, 0) node[below] {$O$} -- (10, 10) node[below right] {$(a{+}c) U$};
    \draw[->, semithick] (0, 0) -- (6, 6) node[below right] {$a U$};
    \draw[->, semithick] (0, 0) -- (4, 4) node[below right] {$c U$};
    \draw[->, semithick] (0, 0) -- (-11, 11) node[below left] {$(b{+}d) V$};
    \draw[->, semithick] (0, 0) -- (-8, 8) node[below left] {$d V$};
    \draw[->, semithick] (0, 0) -- (-3, 3) node[below left] {$b V$};
    \draw[->, thick] (0, 0) -- (3, 9) node[above right] {$X$};
    \draw[->, thick] (0, 0) -- (-4, 12) node[above left] {$Y$};
    \draw[->, thick] (0, 0) -- (-1, 20) node[above] {$X{+}Y$};
  \end{tikzpicture}
  \caption{Construction for the proof of lemma~\ref{lem:17}.}
  \label{fig:3}
\end{figure}

\begin{proof}
  Let $X$ and $Y$ be two vectors in $\mN \union \mC$
  which are not both in $\mN$.
  Let $\Pi$ be a two dimensional plane through the origin
  which contains $X$ and $Y$;
  the intersection of the plane $\Pi$ with the cone $\mN$ 
  is the union of two null directed half lines,
  \begin{equation*}
    \Pi \intersection \mN = (\R_+ U) \union (\R_+ V),
  \end{equation*}
  where $U$ and $V$ are two linearly independent vectors in $\mN$.
  We write $X$ and $Y$ as linear combinations of $U$ and $V$,
  \begin{equation*}
    X = a U + b V, \qquad
    Y = c U + d V,
  \end{equation*}
  for some non negative coefficients $a, b, c, d$.
  Then, using equation~\eqref{eq:67},
  \begin{multline*}
    F(X + Y) = F\Tonde{(aU + bV) + (cU +dV)} =
    F\Tonde{(a+c) U + (b+d) V} = \\
    = F\Tonde{(a+c) U} F\Tonde{(b+d) V} =
    \Tonde{F(aU) F(cU)} \Tonde{F(bV) F(dV)} = \\
    = \Tonde{F(aU) F(bV)} \Tonde{F(cU) F(dV)} = 
    F(aU + bV) F(cU + dV) = F(X) F(Y).
  \end{multline*}
\end{proof}

\begin{proposition} \label{pro:5}
  If $f: \R^2 \to \C$ and $F: \ovl{\mC_{+++}} \to \C$ 
  are non trivial locally integrable functions
  which satisfy the functional equation~\eqref{eq:57}
  then there exists constants $A \in \C$, $b \in \C^2$, $C \in \C$
  such that 
  \begin{equation*}
    f(x) = \exp\Tonde{A \abs{x} + b \cdot x + C}, \qquad
    F(t, x) = \exp\tonde{A t +  b \cdot x + 3C},
  \end{equation*}
  for (almost) all $(t, x) \in \mC_{+++}$.
\end{proposition}

\begin{proof}
  By lemma~\ref{lem:14},
  we may assume that $f$ and $F$ are continuous.
  By lemma~\ref{lem:16},
  we may assume that $f$ and $F$ never vanishes.
  Setting $y = 0$ and $z = 0$ in~\eqref{eq:57} we obtain
  $F\tonde{\abs{x}, x} = f(x) f(0)^2$.
  We define $G(t, x) = F(t, x) / F(0, 0)$;
  then
  \begin{equation*}
    G\Tonde{\abs{x}, x} = \frac{F\Tonde{\abs{x}, x}}{F(0, 0)} = 
    \frac{f(x)}{f(0)}, \qquad x \in \R^2.
  \end{equation*}
  We also have
  \begin{equation*}
    G\Tonde{\abs{x}, x} G\Tonde{\abs{y}, y} =
    \frac{f(x) f(y) f(0)}{f(0)^3} =
    \frac{F\Tonde{\abs{x} + \abs{y}, x + y}}{F(0, 0)} =
    G\Tonde{\abs{x} + \abs{y}, x + y}.
  \end{equation*}
  We can apply first lemma~\ref{lem:17} and then lemma~\ref{lem:10}
  to the function $G$ and obtain that $G(t, x) = \exp\tonde{A t + b \cdot x}$
  for some constants $A \in \C$ and $b \in C^2$.
  The result then follows by choosing $C$ so that $F(0, 0) = \exp(3C)$.
\end{proof}

\subsection{The equation~\eqref{eq:58}.}

\begin{lemma} \label{lem:18}
  It is possible to construct an open set $\Omega \subset \R^3 \times \R^3$,
  whose sections \mbox{$\Omega_x = \graffe{y: (x, y) \in \Omega}$}
  are dense in $\R^3$ for every $x \in \R^3$,
  and a pair of smooth maps $P, Q: \Omega \to \R^3$
  such that, for every $(x, y) \in \Omega$,
  \begin{gather}
    \label{eq:69}
    \abs{P(x, y)} + \abs{Q(x, y)} = \abs{x} + \abs{y}, \\
    \label{eq:70}
    P(x, y) + Q(x, y) = x + y, \\
    \notag
    \det\abs{\pder{P}{y}(x, y)} \ne 0, \qquad
    \det\abs{\pder{Q}{y}(x, y)} \ne 0.
  \end{gather}
\end{lemma}

\begin{figure}
  \centering
  \begin{tikzpicture}[scale=0.7, >=latex]
    \draw[thin, dotted]
    (-4, -0.4) -- (11, 1.1)
    (-5.094, -3.069) -- (6.946, 4.185)
    (1, 4) node[left] {$\mu$} -- (11.5, 0.5)
    (-3, 1) node[left] {$\lambda$} -- (9, -3);
    \draw
    (6, -2) -- (10, 1)
    (4, 3) -- (0, 0) -- (-4.631, -2.790) -- (-0.631, 0.210) --
    (4, 3) -- (10.631, 0.790) -- (6.631, -2.210) -- (-0.631, 0.210);
    \draw[thick, black!75, parametric, smooth]
    plot[domain=0:6.283, id=Exy]
    function{5+5.634*cos(t)-0.259*sin(t), 0.5+0.563*cos(t)+2.597*sin(t)}
    plot[domain=-1.3:2.2, id=Hpx] function{%
      -2.315+1.857*cosh(t)+0.833*sinh(t), -1.385+1.119*cosh(t)-1.383*sinh(t)}
    plot[domain=-1:1.6, id=Hqx] function{%
      3.315+2.684*cosh(t)+0.648*sinh(t), -1.105-0.894*cosh(t)+1.945*sinh(t)};
    \draw
    (8.1, 2.9) node[above] {$\mE(x,y)$}
    (-0.4, 2) node[left] {$\mH(x,p)$}
    (6.2, -4) node[left] {$\mH(x,q)$};
    \fill[black!50, text=black]
    (0, 0) circle (2pt) node[below] {$O$}
    (4, 3) circle (2pt) node[above] {$x$}
    (6, -2) circle (2pt) node[above] {$y$}
    (10, 1) circle (2pt) node[above] {$x{+}y$}
    (-0.631, 0.210) circle (2pt) node[left] {$p$}
    (10.631, 0.790) circle (2pt) node[below right] {$q$}
    (-4.631, -2.790) circle (2pt) node[left] {$p{-}x$}
    (6.631, -2.210) circle (2pt) node[below] {$q{-}x$};    
  \end{tikzpicture}
  \caption{Constructions of the functions $P$, $Q$ and their inverses
    as described in lemma~\ref{lem:18}.}
  \label{fig:4}
\end{figure}

\begin{proof}
  The set $\Omega = \graffe{(x, y) \in \R^3 \times \R^3: x \times y \ne 0}$
  of linearly independent pair of vectors
  clearly has sections $\Omega_x$ dense in $\R^3$ for every $x$.
  Given $(x, y) \in \Omega$, the ellipsoid of revolution
  \begin{equation*}
    \mE(x, y) =
    \graffe{u \in \R^3: \abs{u} + \abs{x + y - u} = \abs{x} + \abs{y}},
  \end{equation*}
  with foci at $0$ and $x + y$ and which contains the points $x$ and $y$,
  is non degenerate and any line passing through one of the foci
  intersects the ellipsoid in exactly two points.
  In particular, the line $\lambda$ passing through $y$ and $0$
  intersects $\mE(x, y)$ in $y$ and in another point $p$;
  similarly, the line $\mu$ passing through $x$ and $x + y$
  intersects $\mE(x, y)$ in $x$ and in another point $q$.
  By symmetry we have $p + q = x + y$
  and from the definition of $\mE$ it follows that
  \begin{equation*}
    \abs{p} + \abs{q} = \abs{p} + \abs{x + y - p} = \abs{x} + \abs{y}.
  \end{equation*}
  It is evident from the geometric construction
  that the correspondence \mbox{$(x, y) \mapsto (p, q)$} is a smooth map
  as long as the vectors $x$ and $y$ remain linearly independent;
  moreover, when $x$ and $y$ are linearly independent
  we also have that
  $(x, p)$ and $(x, q)$ are pairs of linearly independent vectors.
  Setting $P(x, y) = p$ and $Q(x, y) = q$,
  we obtain two smooth maps $P, Q: \Omega \to \R^3$
  which satisfy~\eqref{eq:69} and~\eqref{eq:70}.

  To verify that, for fixed $x \in \R^3$,
  the maps $y \mapsto P(x, y)$ and $y \mapsto Q(x, y)$
  are locally invertible
  we provide a smooth geometric construction of their inverses.

  Given a pair of points $(x, p) \in \Omega$,
  we define $\mH(x, p)$ to be the branch of the hyperboloid
  with foci at $0$ and $p - x$ passing through the point $p$,
  \begin{equation*}
    \mH(x, p) =
    \graffe{u \in \R^3: \abs{u} - \abs{p - x - u} = \abs{p} - \abs{x}}
  \end{equation*}
  and we notice that it is non-degenerate
  since $p$ does not belong to the line passing through $0$ and $p - x$.
  The line passing through $p$ and $0$
  intersects $\mH(x, p)$ in $p$ and in another point $y_*$.
  The map $(x, p) \mapsto y_*$ 
  is smooth as long as $x$ and $p$ remain linearly independent.
  We claim that $P(x, y_*) = p$; indeed,
  $p$ belongs to the line passing through $y_*$ and $0$
  and from the definition of $\mH(x, p)$ it follows that
  \begin{equation*}
    \abs{p} + \abs{p - x - y_*} = \abs{x} + \abs{y_*},
  \end{equation*}
  which means that $p \in \mE(x, y_*)$.

  Similarly, given a pair of points $(x, q) \in \Omega$,
  we consider $\mH(x, q)$,
  the branch of the hyperboloid
  with foci at $0$ and $q - x$ passing through the point $q$.
  The line passing through $q - x$ and $0$
  intersects $\mH(x, q)$ in one point $y_{**}$,
  the vertex of the hyperboloid.
  The map $(x, q) \mapsto y_{**}$ 
  is smooth as long as $x$ and $q$ remain linearly independent
  and it easy to check that $Q(x, y_{**}) = q$.
  Indeed,
  since $q - x$ belongs to the line passing through $y_{**}$ and $0$,
  by a translation we have that
  $q$ belongs to the line passing through $x + y_{**}$ and $x$,
  moreover from the definition of $\mH(x, q)$ it follows that
  \begin{equation*}
    \abs{q} + \abs{q - x - y_{**}} = \abs{x} + \abs{y_{**}},
  \end{equation*}
  which means that $q \in \mE(x, y_{**})$.
\end{proof}

\begin{remark}
  Explicit formulae for the functions $P$ and $Q$
  constructed in the previous lemma are given by
  \begin{equation*}
    P(x, y) = \TOnde{\frac{x \cdot y - \abs{x} \abs{y}}
      {x \cdot y + \abs{x} \abs{y} + 2 \abs{y}^2}} y, \qquad
    Q(x, y) = x + y - P(x, y).
  \end{equation*}
\end{remark}

As in section~\ref{sec:case-w-n-3}
we let $\mC_{++} = \graffe{(t, v) \in \R \times \R^3: t > \abs{v}^2}$.

\begin{lemma} \label{lem:20}
  Let $f: \R^3 \to \C$ and $F: \ovl{\mC_{++}} \to \C$
  be functions which solve equation~\eqref{eq:58}.
  If $f$ is locally integrable then $f$ and $F$ are continuous functions.
\end{lemma}

\begin{proof}
  Let $P$ and $Q$ be the functions constructed in lemma~\ref{lem:18}.
  If $f$ and $F$ are solutions to~\eqref{eq:58}
  it follows that
  \begin{equation*}
    f(x) f(y) = f\Tonde{P(x, y)} f\Tonde{Q(x, y)}, \quad
   \text{for a.e. $(x, y) \in \R^3 \times \R^3$},
  \end{equation*}
  and the lemma then becomes a corollary of proposition~\ref{pro:2}.
\end{proof}

Once the continuity of locally integrable solutions to~\eqref{eq:58}
is established, one then proceeds in the same manner as in the
previous subsection and obtains the following result.

\begin{proposition} \label{pro:4}
  If $f: \R^3 \to \C$ and $F: \ovl{\mC_{++}} \to \C$ 
  are non trivial locally integrable functions
  which satisfy the functional equation
  \begin{equation*}
    f(x) f(y) = F\Tonde{\abs{x} + \abs{y}, x + y},
  \end{equation*}
  for all $x, y \in \R^3$,
  then there exists constants $A \in \C$, $b \in \C^3$, $C \in \C$
  such that 
  \begin{equation*}
    f(x) = \exp\Tonde{A \abs{x} + b \cdot x + C}, \qquad
    F(t, x) = \exp\tonde{A t +  b \cdot x + 2 C},
  \end{equation*}
  for (almost) all $(t, x) \in \mC_{++}$.
\end{proposition}

\section*{%
  Acknowledgement}

I am grateful to S.\ Klainerman
for interesting discussions and for suggesting the proof of lemma~\ref{lem:17};
to A.\ J\'arai 
for comments on regularity properties of solutions to functional equations;
and to the anonymous referee
for suggesting a simpler way of computing
the integrals of lemma~\ref{lem:3} and lemma~\ref{lem:7}
based on Lorentz invariance,
for pointing out a flaw in the first version of the proof of lemma~\ref{lem:8},
and for suggesting the example described in remark~\ref{rem:6}.

\bibliographystyle{amsplain}
\begin{thebibliography}{9}

\bibitem{Acz1966}
  J{\'a}nos Acz{\'e}l,
  \emph{Lectures on functional equations and their applications},
  Mathematics in Science and Engineering, Vol. 19,
  Academic Press, New York, 1966.
  
\bibitem{FosKla2000}
  Damiano Foschi and Sergiu Klainerman,
  \emph{Bilinear space-time estimates
    for homogeneous wave equations},
  Ann. Sci. \'Ecole Norm. Sup. (4) \textbf{33} (2000),
  no.~2, 211--274.

\bibitem{Hor1990}
  Lars H{\"o}rmander,
  \emph{The analysis of linear partial differential operators {I}.
    Distribution theory and Fourier analysis}, 2nd ed.,
  Springer Study Edition,
  Springer-Verlag, Berlin, 1990.

\bibitem{Jar2003}
  Antal J{\'a}rai,
  \emph{Measurability implies continuity 
    for solutions of functional equations---even with few variables},
  Aequationes Math. \textbf{65} (2003), no.~3, 236--266.
  
\bibitem{KlaMac1996}
  Sergiu Klainerman and Matei Machedon,
  \emph{Remark on {S}trichartz-type inequalities},
  Internat. Math. Res. Notices (1996), no.~5, 201--220.
  
\bibitem{Kun2003}
  Markus Kunze,
  \emph{On the existence of a maximizer
    for the {S}trichartz inequality},
  Comm. Math. Phys. \textbf{243} (2003), 137--162.
  
\bibitem{Rat1985}
  J{\"u}rg R{\"a}tz,
  \emph{On orthogonally additive mappings},
  Aequationes Math. \textbf{28} (1985), no.~1-2, 35--49.
  
\bibitem{Str1977}
  Robert S. Strichartz,
  \emph{Restrictions of {F}ourier transforms to quadratic surfaces
    and decay of solutions of wave equations},
  Duke Math. J. \textbf{44} (1977), no.~3, 705--714.
  
\end{thebibliography}
\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 

pgfbaseimage.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfbaseimage.code.tex,v 1.2 2005/07/06 15:58:57 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.




% Declare an image
%
% #1 = optional argument: width, height, page specification
% #2 = name of the image for later use
% #4 = filename without extension, automatic extensions are .pdf,
%      .jpg, and .png for PDF and .ps, .eps, .epsi for postscript.
%
% Description:
%
% This command declares an image file for later use. Even if the image
% is used several times in the document, in PDF it will only be stored
% once. 
%
% Example:
%
% \pgfdeclareimage[width=2cm,page=2]{myimage}{imagefilename}

\def\pgfdeclareimage{\@ifnextchar[{\pgf@declareimage}{\pgf@declareimage[]}}
\def\pgf@declareimage[#1]#2#3{%
  \setkeys{pgfimage}{height=,width=,page=,interpolate=false,mask=}% defaults
  \setkeys{pgfimage}{#1}%
  % Try to find the file
  \gdef\pgf@filename{}%
  % If page= parameter is not empty, try that file first:
  \ifx\pgf@imagepage\@empty%
  \else%
  \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3.page\pgf@imagepage}%
  \fi%
  \ifx\pgf@filename\@empty%
    \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}%
  \else%
    \setkeys{pgfimage}{page=}% make page empty     
  \fi%
  \ifx\pgf@filename\@empty%
    \PackageWarning{pgf}%
    {File "#3" not found when defining image "#2".\MessageBreak
      Tried all extensions in "\pgfsys@imagesuffixlist"}%
    \pgf@declaredraftimage{#2}%
  \else%
    \ifpgf@draftmode%
      \pgf@declaredraftimage{#2}%
    \else%
      \pgfsys@defineimage%
    \fi%
  \fi%
  \expandafter\global\expandafter\let\csname pgf@image@#2!\endcsname=\pgf@image%
}

\define@key{pgfimage}{width}{\edef\pgf@imagewidth{#1}}
\define@key{pgfimage}{height}{\edef\pgf@imageheight{#1}}
\define@key{pgfimage}{page}{\edef\pgf@imagepage{#1}}
\define@key{pgfimage}{interpolate}[true]{\edef\pgf@imageinterpolate{/Interpolate #1}}
\define@key{pgfimage}{mask}{%
  \edef\pgf@imagemask{#1}%
  \ifx\pgf@imagemask\@empty%
  \else%
    \@ifundefined{pgf@mask@#1}%
    {\PackageError{pgf}{Undefined mask "#1".}{}%
      \edef\pgf@imagemask{}}%
    {\edef\pgf@imagemask{\csname pgf@mask@#1\endcsname}%
      \ifx\pgf@imagemask\@empty%
      \else
      \edef\pgf@imagemask{/SMask \pgf@imagemask\space 0 R}%
      \fi}%
    \fi}

\def\pgf@findfile#1:#2+#3{%
  \IfFileExists{#3.#1}%
  {\xdef\pgf@filename{#3.#1}}%
  {\def\pgf@mightbeempty{#2}%
    \ifx\pgf@mightbeempty\@empty\else%
    \pgf@findfile#2+{#3}%
    \fi}}

\def\pgf@declaredraftimage#1{%
  \ifx\pgf@imagewidth\@empty%
    \PackageWarning{pgf}{Missing width for image "#1" in draft mode.\MessageBreak  Using 1cm instead}%
    \edef\pgf@imagewidth{1cm}%
  \fi%
  \ifx\pgf@imageheight\@empty%
    \PackageWarning{pgf}{Missing height for image "#1" in draft mode.\MessageBreak Using 1cm instead}%
    \edef\pgf@imageheight{1cm}%
  \fi%  
  \ifx\pgf@imagepage\@empty\else\edef\pgf@imagepagetext{ page \pgf@imagepage}\fi%
  \edef\pgf@image{%
    \hbox to \pgf@imagewidth{%
      \vrule\kern-0.4pt%
      \vbox to \pgf@imageheight{%
        \hrule\vfil%
        \hbox to \pgf@imagewidth{\hskip-10cm\hfil\noexpand\tiny#1\pgf@imagepage\hfil\hskip-10cm}%
        \vfil\hrule}%
      \kern-0.4pt\vrule}%
  }%
}



% Declare a soft mask
%
% #1 = optional argument: matte specification. default matte is
%      white. 
% #2 = name of the mask for later use
% #3 = filename without extension, automatic extensions are .pdf,
%      .jpg, and .png for PDF. Postscript is not supported.
%
% Description:
%
% This command declares a soft mask for later masking an image. The
% declared mask should be used together with an image of exactly the
% same height/width if matte is defined. Matte should be the
% preblended background color (see pdf spec for details).
%
% Example:
%
% \pgfdeclaremask[matte=white]{maskname}{maskfilename}
% \pgfdeclareimage[mask=maskname]{image}{imagefilename}

\def\pgfdeclaremask{\@ifnextchar[\pgf@declaremask{\pgf@declaremask[]}}
\def\pgf@declaremask[#1]#2#3{%
  \setkeys{pgfmask}{matte={1 1 1}}% defaults
  \setkeys{pgfmask}{#1}%
  \def\pgf@mask{}%
  % Try to find the file
  \gdef\pgf@filename{}%
  \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}%
  \ifx\pgf@filename\@empty%
    \PackageWarning{pgf}%
    {File "#3" not found when defining mask "#2".\MessageBreak
      Tried all extensions in "\pgfsys@imagesuffixlist"}%
  \else%
    \pgfsys@definemask%
  \fi%
  \expandafter\global\expandafter\let\csname pgf@mask@#2\endcsname=\pgf@mask%
}

\define@key{pgfmask}{matte}{\edef\pgf@maskmatte{#1}}




% Create an alias name for an image
%
% #1 = name of the alias
% #2 = name of the original
%
% Example:
%
% \pgfdeclareimage{image}{1cm}{1cm}{filename
% \pgfaliasimage{alias}{image}
% \pgfuseimage{alias}

\def\pgfaliasimage#1#2{%
  \expandafter\global\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@image@#2!\endcsname%
  \expandafter\global\expandafter\let\csname pgf@image@#1!\endcsname=\pgf@temp%
  }

  
% Use an image
%
% #1 = name of a previously declared image
%
% Example:
%
% \pgfputat{\pgforigin}{\pgfbox[left,base]{\pgfuseimage{myimage}}}

\def\pgfuseimage#1{%
  \def\pgf@imagename{pgf@image@#1}%
  \pgf@tryextensions{\pgf@imagename}{\pgfalternateextension}%
  \expandafter\@ifundefined\expandafter{\pgf@imagename}%
  {\PackageError{pgf}{Undefined image "#1"}{}}%
  {{\leavevmode\csname\pgf@imagename\endcsname}}}

\def\pgf@tryextensions#1#2{%
  \edef\pgf@args{[#2!]}\expandafter\pgf@@tryextensions\pgf@args{#1}}
\def\pgf@@tryextensions[#1!#2]#3{%
  \expandafter\@ifundefined\expandafter{#3.#1!#2}%
  {\def\pgf@temp{#2}%
    \ifx\pgf@temp\@empty%
    \edef#3{#3!}%
    \else%
    \pgf@@tryextensions[#2]{#3}%
    \fi}%
  {\edef#3{#3.#1!#2}}}


% Alternate image
%
% Description:
%
% When an image is used, pgf first attempts to use the image with the
% alternate extension added. If this fails, the original image is
% used. If the alternate extension contains ``!'', then the text up to
% the ! is successively removed and the remainder is tried as an
% alternate extension.
%
% Example:
%
% \def\pgfalternateextension{20!white}

\def\pgfalternateextension{}



% Directly insert an image
%
% #1 = optional argument: width, height, page specification
% #2 = file name
%
% Description:
%
% Directly inserts an image without declaration. You can, however,
% still access this image using the name pgflastimage. By using
% pgfaliasimage, you can also save this image for later.
%
% Example:
%
% \pgfimage[height=2cm]{filename}

\def\pgfimage{\@ifnextchar[\pgf@imagecom{\pgf@imagecom[]}}
\def\pgf@imagecom[#1]#2{%
  \pgfdeclareimage[#1]{pgflastimage}{#2}%
  \pgfuseimage{pgflastimage}}



\endinput

pgfbaselayers.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfbaselayers.code.tex,v 1.2 2005/10/24 15:14:48 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


% Creates a new pgf layer
%
% #1 = layer name
%
% Declares a new layer for pgf.
%
% Example:
%
% \pgfdeclarelayer{background}

\def\pgfdeclarelayer#1{%
  \expandafter\pgf@newbox\csname pgf@layerbox@#1\endcsname%
  \expandafter\pgf@newbox\csname pgf@layerboxsaved@#1\endcsname%
}
\let\pgf@newbox=\newbox % avoid plain TeX outer problem

% Sets the layers that compose the picture
%
% #1 = List of layers
%
% Description:
%
% Sets the list of layers that make up the picture. The layers will be
% put on top of each other in the order given. 
%
% Example:
%
% \pgfsetlayers{background,main}

\def\pgfsetlayers#1{\edef\pgf@layerlist{#1}}
\pgfsetlayers{main}



% Adds code to a layer
%
% #1 = layer name
%
% Note:
%
% You cannot anything to the ``main'' layer using this command.
%
% Example:
%
% \begin{pgfonlayer}{background}
%   \fill[red] (0,0) -- (1,1);
% \end{pgfonlayer}

\def\pgfonlayer#1{%
  \expandafter\global\expandafter%
  \setbox\csname pgf@layerbox@#1\endcsname=\hbox to 0pt%
    \bgroup%
      \expandafter\box\csname pgf@layerbox@#1\endcsname%
      \begingroup%
}
\def\endpgfonlayer{%
      \endgroup%
      \hss
    \egroup%
}




% Hooks into the scoping:

\def\pgf@insertlayers{%
  \expandafter\pgf@dolayer\pgf@layerlist,,\relax%
}
\def\pgf@maintext{main}%
\def\pgf@dolayer#1,#2,\relax{%
  \def\pgf@test{#1}%
  \ifx\pgf@test\pgf@maintext%
    \box\pgf@layerbox@main%
  \else%
    \pgfsys@beginscope%
      \expandafter\box\csname pgf@layerbox@#1\endcsname%
    \pgfsys@endscope%
  \fi%
  \def\pgf@test{#2}%
  \ifx\pgf@test\@empty%
  \else%
    \pgf@dolayer#2,\relax%
  \fi%
}

\def\pgf@savelayers{%
  \expandafter\pgf@dosavelayer\pgf@layerlist,,\relax%
}
\def\pgf@dosavelayer#1,#2,\relax{%
  \def\pgf@test{#1}%
  \ifx\pgf@test\pgf@maintext%
  \else%
    \setbox\csname pgf@layerboxsaved@#1\endcsname=\box\csname pgf@layerbox@#1\endcsname%
  \fi%
  \def\pgf@test{#2}%
  \ifx\pgf@test\@empty%
  \else%
    \pgf@dosavelayer#2,\relax%
  \fi%
}

\def\pgf@restorelayers{%
  \expandafter\pgf@dorestorelayer\pgf@layerlist,,\relax%
}
\def\pgf@dorestorelayer#1,#2,\relax{%
  \def\pgf@test{#1}%
  \ifx\pgf@test\pgf@maintext%
  \else%
    \global\setbox\csname pgf@layerbox@#1\endcsname=\box\csname pgf@layerboxsaved@#1\endcsname%
  \fi%
  \def\pgf@test{#2}%
  \ifx\pgf@test\@empty%
  \else%
    \pgf@dorestorelayer#2,\relax%
  \fi%
}

\endinput

pgfbaseplot.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfbaseplot.code.tex,v 1.2 2005/07/06 15:58:57 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



% PGF's plotting interface works as follows:
%
% In order to plot something, two things need to be done. First, you
% need to provide the coordinates (obviously) of the points that
% should be plotted. The coordinates are given via a long stream of
% commands. These commands are \pgfplotstreamstart, which is
% given exactly once at the beginning, \pgfplotstreampoint, of which there
% are numerous in the middle, \pgfplotstreamspecial, of which there may be
% numerous in the middle, and \pgfplotstreamend, which must be given
% at the end. Between these commands arbitrary other commands may be
% given. Here is an example:
%
% ...
% \pgfplotstreamstart
% \pgfplotstreampoint{\pgfpointxy{0}{0}}
% \pgfplotstreampoint{\pgfpointxy{1}{1}}
% \pgfplotstreampoint{\pgfpointxy{2}{4}}
% \relax
% \pgfplotstreampoint{\pgfpointxy{3}{9}}
% \pgfplotstreamspecial{some handler-dependent special stuff}
% \pgfplotstreamend
%
% By themselves, the \pgfplotstreamxxxx commands do not do anything by
% default. Rather, the ``use'' such a stream, you must first install a
% stream handler. For example, the ``lineto'' handler will simply
% translate every \pgfplotstreampoint into a \pgfpathlineto.
%
% Example:
%
% \pgfpathmoveto{\pgfpointorigin}
%
% \pgfplothandlerlineto
% \pgfplotstreamstart
% \pgfplotstreampoint{\pgfpointxy{0}{0}}
% \pgfplotstreampoint{\pgfpointxy{1}{1}}
% \pgfplotstreampoint{\pgfpointxy{2}{4}}
% \relax
% \pgfplotstreampoint{\pgfpointxy{3}{9}}
% \pgfplotstreamend


% The stream commands actually call their ``internal'' versions, which
% are set by the handlers:
\def\pgfplotstreamstart{\pgf@plotstreamstart}
\def\pgfplotstreampoint#1{\gdef\pgfplotlastpoint{#1}\pgf@plotstreampoint{#1}}
\def\pgfplotstreamspecial{\pgf@plotstreamspecial}
\def\pgfplotstreamend{\pgf@plotstreamend}




% Sets the action taken for the first point of a plot to a lineto.
%
% Description:
%
% For certain handlers it makes sense either the start a plot by
% moving to the first point of the plot or to do a lineto to that
% first point. Using this command this action can be set to a lineto. 
%
% Example:
%
% \pgfsetlinetofirstplotpoint

\def\pgfsetlinetofirstplotpoint{\let\pgf@plot@first@action=\pgfpathlineto}


% Sets the action taken for the first point of a plot to a moveto.
%
% Example:
%
% \pgfsetmovetofirstplotpoint

\def\pgfsetmovetofirstplotpoint{\let\pgf@plot@first@action=\pgfpathmoveto}

\let\pgf@plot@first@action=\pgfpathmoveto



%
% Handlers
%


% This handler converts each plot stream command into a lineto
% command, except for the first, which is converted to the action that
% has previously been specified using \pgfsetlinetofirstplotpoint or
% \pgfsetmovetofirstplotpoint. 
%
% Example:
%
% \pgfplothandlerlineto
% \pgfplotxyfile{mytable}

\def\pgfplothandlerlineto{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@line@handler%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}

\def\pgf@plot@line@handler#1{%
  \pgf@plot@first@action{#1}%
  \global\let\pgf@plotstreampoint=\pgfpathlineto%
}



% More handlers are defined in pgflibraryplothandlers





% This handler discards the plot.
%
% Example:
%
% \pgfplothandlerdiscard
% \pgfplotxyfile{mytable}

\def\pgfplothandlerdiscard{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\@gobble%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}




% This handler records each plot stream command to a macro. This is
% useful if plot commands are difficult to generate and need to be
% ``recylced'' later on.
%
% Example:
%
% \pgfplothandlerrecord{\myplot}
% \pgfplotxyfile{mytable}  % stored in \myplot now
% \pgfplothandlerline
% \myplot
% \pgftransformxshift{1cm}
% \myplot

\def\pgfplothandlerrecord#1{%
  \def\pgf@plot@recordto{#1}%
  \gdef#1{\pgfplotstreamstart}%
  \def\pgf@plotstreamstart{%
    \gdef\pgf@plotstreampoint####1{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreampoint{####1}}}%
    \gdef\pgf@plotstreamspecial####1{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamspecial{####1}}}%
    \gdef\pgf@plotstreamend{\expandafter\gdef\expandafter#1\expandafter{#1\pgfplotstreamend}}%
  }%
}



% Read a plot stream from a file and plot it.
%
% #1 = file from which to read things
%
% File format:
%
% Each line of the file should begin with two numbers separated by a
% space. Such a line with number #1 and #2 is converted to a
% \pgfplotstreampoint{\pgfpointxy{#1}{#2}}. Extra characters following
% on the line are ignored.
%
% Lines starting with ``%'' and ``#'' are ignored.
%
% Example:
%
% \pgfplotxyfile{tableformgnuplot.dat}

\def\pgfplotxyfile#1{%
  \begingroup%
    \pgfplotstreamstart%
    \openin1=#1
    \ifeof1
      \PackageWarning{pgf}{Plot data file `#1' not found.}
     \else
      \catcode`\#=14
      \pgf@readxyfile%
    \fi
    \pgfplotstreamend%    
  \endgroup%
}

\def\pgf@partext{\par}
\def\pgf@readxyfile{%
  \read1 to \pgf@temp%
  \let\par=\@@par%
  \edef\pgf@temp{\pgf@temp}%
  \ifx\pgf@temp\@empty%
  \else\ifx\pgf@temp\pgf@partext%
  \else%
    \expandafter\pgf@parsexyline\pgf@temp\pgf@stop%
  \fi\fi%
  \ifeof1\else\expandafter\pgf@readxyfile\fi%
}

\def\pgf@parsexyline#1 #2 #3\pgf@stop{%
  \pgfplotstreampoint{\pgfpointxy{#1}{#2}}%
}





% Read a plot stream from a file and plot it.
%
% #1 = file from which to read things
%
% File format:
%
% Like xy, except that each line contains three numbers, which are
% converted to xyz coordiantes.
%
% Example:
%
% \pgfplotxyfile{tableformgnuplot.dat}

\def\pgfplotxyzfile#1{%
  \begingroup%
    \pgfplotstreamstart%
    \openin1=#1
    \ifeof1
      \PackageWarning{pgf}{Plot data file `#1' not found.}
    \else
      \catcode`\#=14
      \pgf@readxyzfile%
    \fi
    \pgfplotstreamend%    
  \endgroup%
}

\def\pgf@readxyzfile{%
  \read1 to \pgf@temp%
  \ifx\pgf@temp\@empty%
  \else\ifx\pgf@temp\pgf@partext%
  \else%
    \expandafter\pgf@parsexyzline\pgf@temp\pgf@stop%
  \fi\fi%
  \ifeof1\else\expandafter\pgf@readxyzfile\fi%
}

\def\pgf@parsexyzline#1 #2 #3 #4\pgf@stop{%
  \pgfplotstreampoint{\pgfpointxyz{#1}{#2}{#3}}%
}




% Render a function using gnuplot.
%
% #1 = filename prefix for .gnuplot and .table files (optional,
%      default is \jobname)
% #2 = gnuplot function text
%
% Description:
%
% This command will write a file called #1.gnuplot that sets up
% some gnuplot commands to write output to a file called
% #1.table. Then it calls gnuplot (using the \write18 mechanism)
% to execute the file. Then it reads #2.table using \pgfplotxyfile.
%
% Example:
%
% \pgfplothandlerlineto
% \pgfplotgnuplot[\jobname]{plot [x=0:5] x*sin(x)}

{
  \catcode`\%=12
  \catcode`\"=12
  \xdef\pgf@gnuplot@head#1{set terminal table; set output "#1.table"; set format "%.5f"}
}

\newwrite\pgf@plotwrite
\newif\ifpgf@resample@plot

\def\pgfplotgnuplot{\@ifnextchar[{\pgf@plotgnuplot}{\pgf@plotgnuplot[\jobname]}}%}
\def\pgf@plotgnuplot[#1]#2{%
  \pgf@resample@plottrue%
  % Check, whether it is up-to-date
  \openin\@inputcheck=#1.gnuplot
  \ifeof\@inputcheck%
  \else%
    \read\@inputcheck to\pgf@temp% ignored
    \read\@inputcheck to\pgf@plot@line%
    \edef\pgf@plot@code{#2\space}%
    \ifx\pgf@plot@code\pgf@plot@line%
      \openin\@inputcheck=#1.table
      \ifeof\@inputcheck%
      \else%
        \pgf@resample@plotfalse%
      \fi%
    \fi%
  \fi
  \ifpgf@resample@plot%  
    \immediate\openout\pgf@plotwrite=#1.gnuplot
    \immediate\write\pgf@plotwrite{\pgf@gnuplot@head{#1}}%
    \immediate\write\pgf@plotwrite{#2}%
    \immediate\closeout\pgf@plotwrite%
    \immediate\write18{gnuplot #1.gnuplot}
  \fi%
  \pgfplotxyfile{#1.table}
}




\endinput

pgfbaseshapes.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfbaseshapes.code.tex,v 1.9 2005/10/13 10:12:31 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



\newbox\pgfnodeparttextbox


% Creates a node
%
% #1 = shape type
% #2 = anchor
% #3 = name for later reference
% #4 = path usage command
%
% Description:
%
% This command draws a shape that has previously been defined using
% \pgfdeclareshape. The shape is shifted such that the anchor is at
% the origin. In order to transform the whole shape, you should setup
% pgf's transformation matrix prior to calling this command.
%
% When this command is called, the shape-specific TeX boxes of the
% node must be have been setup correctly.
%
% Example:
%
% \pgftransformshift{\pgfpoint{1cm}{1cm}}
% \pgfmultipartnode{rectangle}{center}{Hello}{hellonode}{\pgfusepath{stroke}}

\def\pgfmultipartnode#1#2#3#4{%
  \@ifundefined{pgf@sh@s@#1}%
  {\PackageError{pgf}{Unknown shape ``#1''}{}}%
  {%
    {%
      \let\pgf@sh@savedpoints=\@empty%
      \csname pgf@sh@s@#1\endcsname%
      \pgf@sh@savedpoints%
      \pgftransformshift{%
        \pgf@sh@reanchor{#1}{#2}%
        \pgf@x=-\pgf@x%
        \pgf@y=-\pgf@y%
      }%
      % Save the saved points and the transformation matrix
      \edef\pgf@test{#3}%
      \ifx\pgf@test\@empty%
      \else%
        \expandafter\xdef\csname pgf@sh@ns@#3\endcsname{#1}%
        \edef\pgf@sh@@temp{\noexpand\gdef\expandafter\noexpand\csname pgf@sh@np@#3\endcsname}%
        \expandafter\pgf@sh@@temp\expandafter{\pgf@sh@savedpoints}%
        \pgfgettransform\pgf@temp
        \expandafter\xdef\csname pgf@sh@nt@#3\endcsname{\pgf@temp}%
      \fi%
      \@ifundefined{pgf@sh@bbg@#1}{}
      {{\pgfscope\csname pgf@sh@bbg@#1\endcsname\endpgfscope}}%
      \@ifundefined{pgf@sh@bg@#1}{}%
      {\csname pgf@sh@bg@#1\endcsname#4}%
      \@ifundefined{pgf@sh@fbg@#1}{}
      {{\pgfscope\csname pgf@sh@fbg@#1\endcsname\endpgfscope}}%
      {%
        \expandafter\@for\expandafter\pgf@shape@com\expandafter:\expandafter=\csname pgf@sh@boxes@#1\endcsname\do{%
          {%
            \pgftransformshift{\pgf@sh@reanchor{#1}{\pgf@shape@com}}%
            \expandafter\pgfqboxsynced\expandafter{\csname pgfnodepart\pgf@shape@com box\endcsname}%
          }%
        }%
      }%
      \@ifundefined{pgf@sh@bfg@#1}{}%
      {{\pgfscope\csname pgf@sh@bfg@#1\endcsname\endpgfscope}}%
      \@ifundefined{pgf@sh@fg@#1}{}%
      {\csname pgf@sh@fg@#1\endcsname#4}%
      \@ifundefined{pgf@sh@ffg@#1}{}%
      {{\pgfscope\csname pgf@sh@ffg@#1\endcsname\endpgfscope}}%
    }%
  }%
}


% Creates a node
%
% #1 = shape type
% #2 = anchor
% #3 = normal TeX text
% #4 = name for later reference
% #5 = path usage command
%
% Description:
%
% This command draws a shape that has previously been defined using
% \pgfdeclareshape. The shape is shifted such that the anchor is at
% the origin. In order to transform the whole shape, you should setup
% pgf's transformation matrix prior to calling this command.
%
% Example:
%
% \pgftransformshift{\pgfpoint{1cm}{1cm}}
% \pgfnode{rectangle}{center}{Hello}{hellonode}{\pgfusepath{stroke}}

\def\pgfnode#1#2#3#4#5{%
  {%
    \setbox\pgfnodeparttextbox=\hbox%
    {%
      \pgfinterruptpicture%
        {#3}%
      \endpgfinterruptpicture%
    }%
    \pgfmultipartnode{#1}{#2}{#4}{#5}%
  }
}  

\def\pgf@sh@resavedanchor#1#2{%
  \pgf@process{#2}%
  \edef\pgf@sh@marshal{%
    \noexpand\g@addto@macro\noexpand\pgf@sh@savedpoints{%
      \noexpand\def\noexpand#1{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
    }}%
  \pgf@sh@marshal%
}


\def\pgf@sh@resaveddimen#1#2{%
  {#2\global\pgf@x=\pgf@x}%
  \edef\pgf@sh@marshal{%
    \noexpand\g@addto@macro\noexpand\pgf@sh@savedpoints{%
      \noexpand\def\noexpand#1{\the\pgf@x}%
    }}%
  \pgf@sh@marshal%
}

% Invoke an anchor
\def\pgf@sh@reanchor#1#2{%
  \@ifundefined{pgf@anchor@#1@#2}%
  {%
    \setcounter{pgf@counta}{#2}%
    \csname pgf@anchor@#1@border\endcsname{\pgfpointpolar{\c@pgf@counta}{1pt}}%
  }%
  {\csname pgf@anchor@#1@#2\endcsname}%
}



% Retrieves an anchor of a shape
%
% #1 = name
% #2 = anchor or a number (corresponding to a degree)
%
% Description:
%
% This command yields a point at the anchor of the given named shape.
%
% Example:
%
% \pgfshape{rectangle}{center}{Hello}{hellonode}{\pgfusepath[stroke]}
% \pgfpathmoveto{\pgfpointanchor{hellonode}{center}}

\def\pgfpointanchor#1#2{%
  % Ok, check whether #1 is known!
  \@ifundefined{pgf@sh@ns@#1}
  {\PackageError{pgf}{No shape named #1 is known}{}%
    \pgfpointorigin}%
  {%
    \pgf@process{%
      % install special coordinates
      \csname pgf@sh@np@#1\endcsname
      \pgf@sh@reanchor{\csname pgf@sh@ns@#1\endcsname}{#2}%
      {%
        \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
        \pgf@pos@transform{\pgf@x}{\pgf@y}%
        \global\pgf@x=\pgf@x%
        \global\pgf@y=\pgf@y%
      }%
      % Undo current transformation
      \pgftransforminvert%
      \pgf@pos@transform{\pgf@x}{\pgf@y}%
    }%
  }%
}



% Retrieves a border point of a shape
%
% #1 = name
% #2 = another point
%
% Description:
%
% This command yields a point on the border of the shape that is on a
% straight line from the center to the point #2.
%
% Example:
%
% \pgfshape{rectangle}{center}{Hello}{hellonode}{\pgfusepath[stroke]}
% \pgfpathmoveto{\pgfpointshapeborder{hellonode}{\pgfpoint{2cm}{1cm}}
% \pgfpathlineto{\pgfpoint{2cm}{1cm}}
% \pgfusepath{stroke}

\def\pgfpointshapeborder#1#2{%
  % Ok, check whether #1 is known!
  \@ifundefined{pgf@sh@ns@#1}
  {\PackageError{pgf}{No shape named #1 is known}{}%
    \pgfpointorigin}%
  {%
    \pgf@process{%
      % install special coordinates
      \csname pgf@sh@np@#1\endcsname%
      {%
        \pgf@process{\pgfpointtransformed{#2}}%
        \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
        \pgftransforminvert%
        \pgf@pos@transform{\pgf@x}{\pgf@y}%
        \pgf@xa=\pgf@x%
        \pgf@ya=\pgf@y%
        \pgf@process{\csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @center\endcsname}%
        \advance\pgf@xa by-\pgf@x%
        \advance\pgf@ya by-\pgf@y%
        \csname pgf@anchor@\csname pgf@sh@ns@#1\endcsname @border\endcsname{\pgfpoint{\pgf@xa}{\pgf@ya}}%
        \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
        \pgf@pos@transform{\pgf@x}{\pgf@y}%
        \global\pgf@x=\pgf@x%
        \global\pgf@y=\pgf@y%
      }%
      % Undo current transformation
      \pgftransforminvert%
      \pgf@pos@transform{\pgf@x}{\pgf@y}%
    }%
  }%
}



% Declares a shape type
%
% #1 = shape type
% #2 = shape specification
%
% Description:
%
% This command declares a new shape type. The shape specification
% should contain the following commands:
%
% - \savedanchor
%   This command takes two arguments: a name and some code. The point
%   specified by the code (the \pgf@x and \pgf@y values resulting from
%   executing the code, to be precise), will be stored under the given
%   name. Whenever, later on, an anchor is invoked these stored points
%   will be available. The \saveddimen works like \savedanchor, only a
%   single dimension is stored (taken from \pgf@x).
%   When a savedanchor is calculated, the height/width/depth of the
%   boxes mentioned in \nodeparts can be used.
%
% - \anchor
%   Specifies an anchor. This command takes two arguments: an anchor
%   name and some code for computing the anchor. When the anchor
%   computation starts, all shape points and shape dimension will be
%   setup.
%
% - \anchorborder
%   This command should compute a point on the border of the
%   shape. When the code is called, \pgf@x and \pgf@y will have been
%   preinitialised with a direction.
%
% - \behindbackgroundpath
%   Some things to be draw behind everything.
%
% - \backgroundpath
%   A path that is drawn behind the main box. How this path is used
%   depends on how \pgfshape is called.
%
% - \beforebackgroundpath
%   Some things to be draw before the background path, but behind the
%   main box.
%
% - \behindforegroundpath
%   Some things to be draw on top of the main box.
%
% - \foregroundpath
%   A path that is drawn on top of all of the above. How this path is
%   used depends on how \pgfshape is called.
%
% - \beforeforegroundpath
%   Some things to be draw before everything.
%
% - \nodeparts
%   List of node parts that make up the shape. For each entry XYZ in
%   the list there must be a box named \pgfnodepartXYZbox (possibly
%   ``redirected'' to some different box using \let). Each such box
%   will be placed at the anchor XYZ.
%   By default, \nodeparts is just {text}. Thus, there will be one
%   node part box named \pgfnodeparttextbox and this node will be
%   placed at the anchor text. 
%   
%
% Example:
%
% See the definition of rectangle, below.

\long\def\pgfdeclareshape#1#2{%
  {
    \def\shape@name{#1}
    \let\savedanchor=\pgf@sh@savedanchor
    \let\saveddimen=\pgf@sh@saveddimen
    \let\anchor=\pgf@sh@anchor
    \let\anchorborder=\pgf@sh@anchorborder
    \let\behindbackgroundpath=\pgf@sh@behindbgpath
    \let\backgroundpath=\pgf@sh@bgpath
    \let\beforebackgroundpath=\pgf@sh@beforebgpath
    \let\behindforegroundpath=\pgf@sh@behindfgpath
    \let\foregroundpath=\pgf@sh@fgpath
    \let\beforeforegroundpath=\pgf@sh@beforefgpath
    \let\nodeparts=\pgf@sh@boxes
    \let\inheritsavedanchors=\pgf@sh@inheritsavedanchors
    \let\inheritanchor=\pgf@sh@inheritanchor
    \let\inheritanchorborder=\pgf@sh@inheritanchorborder
    \let\inheritbehindbackgroundpath=\pgf@sh@inheritbehindbgpath
    \let\inheritbackgroundpath=\pgf@sh@inheritbgpath
    \let\inheritbeforebackgroundpath=\pgf@sh@inheritbeforebgpath
    \let\inheritbehindforegroundpath=\pgf@sh@inheritbehindfgpath
    \let\inheritforegroundpath=\pgf@sh@inheritfgpath
    \let\inheritbeforeforegroundpath=\pgf@sh@inheritbeforefgpath
    \let\inheritnodeparts=\pgf@sh@inheritboxes
    \anchorborder{\csname pgf@anchor@#1@center\endcsname}%
    \anchor{text}{\pgfpointorigin}%
    \nodeparts{text}%
    \expandafter\global\expandafter\let\csname pgf@sh@s@\shape@name\endcsname=\@empty%
    #2
  }
}

\def\pgf@sh@savedanchor#1#2{%
  \expandafter\g@addto@macro\csname pgf@sh@s@\shape@name\endcsname{\pgf@sh@resavedanchor{#1}{#2}}}
\def\pgf@sh@saveddimen#1#2{%
  \expandafter\g@addto@macro\csname pgf@sh@s@\shape@name\endcsname{\pgf@sh@resaveddimen{#1}{#2}}}
\def\pgf@sh@anchor#1#2{\expandafter\gdef\csname pgf@anchor@\shape@name @#1\endcsname{#2}}
\def\pgf@sh@anchorborder#1{\expandafter\gdef\csname pgf@anchor@\shape@name @border\endcsname##1{\pgf@process{##1}#1}}
\long\def\pgf@sh@behindbgpath#1{\expandafter\gdef\csname pgf@sh@bbg@\shape@name\endcsname{#1}}
\long\def\pgf@sh@bgpath#1{\expandafter\gdef\csname pgf@sh@bg@\shape@name\endcsname{#1}}
\long\def\pgf@sh@beforebgpath#1{\expandafter\gdef\csname pgf@sh@fbg@\shape@name\endcsname{#1}}
\long\def\pgf@sh@behindfgpath#1{\expandafter\gdef\csname pgf@sh@bfg@\shape@name\endcsname{#1}}
\long\def\pgf@sh@fgpath#1{\expandafter\gdef\csname pgf@sh@fg@\shape@name\endcsname{#1}}
\long\def\pgf@sh@beforefgpath#1{\expandafter\gdef\csname pgf@sg@ffg@\shape@name\endcsname{#1}}
\def\pgf@sh@boxes#1{\expandafter\gdef\csname pgf@sh@boxes@\shape@name\endcsname{#1}}

\def\pgf@sh@inheritsavedanchors[from=#1]{%
  \expandafter\g@addto@macro\csname pgf@sh@s@\shape@name\endcsname{\csname pgf@sh@s@#1\endcsname}}
\def\pgf@sh@inheritanchor[from=#1]#2{%
  \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
    pgf@anchor@\shape@name @#2\endcsname=\expandafter\noexpand\csname
    pgf@anchor@#1@#2\endcsname}%
  \pgf@marshal%
}
\def\pgf@sh@inheritanchorborder[from=#1]{%
  \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
    pgf@anchor@\shape@name @border\endcsname=\expandafter\noexpand\csname
    pgf@anchor@#1@border\endcsname}%
  \pgf@marshal%
}
\def\pgf@sh@inheritor#1#2{%
  \edef\pgf@marshal{\global\let\expandafter\noexpand\csname
    pgf@sh@#1@\shape@name\endcsname=\expandafter\noexpand\csname
    pgf@sh@#1@#2\endcsname}%
  \pgf@marshal%
}
\def\pgf@sh@inheritbehindbgpath[from=#1]{\pgf@sh@inheritor{bbg}{#1}}
\def\pgf@sh@inheritbgpath[from=#1]{\pgf@sh@inheritor{bg}{#1}}
\def\pgf@sh@inheritbeforebgpath[from=#1]{\pgf@sh@inheritor{fbg}{#1}}
\def\pgf@sh@inheritbehindfgpath[from=#1]{\pgf@sh@inheritor{bfg}{#1}}
\def\pgf@sh@inheritfgpath[from=#1]{\pgf@sh@inheritor{fg}{#1}}
\def\pgf@sh@inheritbeforefgpath[from=#1]{\pgf@sh@inheritor{ffg}{#1}}
\def\pgf@sh@inheritboxes[from=#1]{\pgf@sh@inheritor{boxes}{#1}}



% 
% Coordinate. This shape is special: It is only used to reference a
% point for later usage. Nothing is drawn, all anchors are identical
% to the center. 
%

\pgfdeclareshape{coordinate}
{
  \savedanchor\centerpoint{%
    % x
    \pgf@x=.5\wd\pgfnodeparttextbox%
    % y
    \pgf@y=.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by -.5\dp\pgfnodeparttextbox%
  }
  
  \anchor{center}{\centerpoint}
  \anchor{north}{\centerpoint}
  \anchor{north west}{\centerpoint}
  \anchor{north east}{\centerpoint}
  \anchor{center}{\centerpoint}
  \anchor{west}{\centerpoint}
  \anchor{east}{\centerpoint}
  \anchor{mid}{\centerpoint}
  \anchor{mid west}{\centerpoint}
  \anchor{mid east}{\centerpoint}
  \anchor{base}{\centerpoint}
  \anchor{base west}{\centerpoint}
  \anchor{base east}{\centerpoint}
  \anchor{south}{\centerpoint}
  \anchor{south west}{\centerpoint}
  \anchor{south east}{\centerpoint}
  \anchorborder{\centerpoint}

  \nodeparts{}% no text
}


% Set the recommended inner x separation
%
% #1 = size
%
% Example:
%
% \pgfsetshapeinnerxsep{2pt}

\def\pgfsetshapeinnerxsep#1{\def\pgfshapeinnerxsep{#1}}
\pgfsetshapeinnerxsep{.3333em}


% Set the recommended inner y separation
%
% #1 = size
%
% Example:
%
% \pgfsetshapeinnerxsep{2pt}

\def\pgfsetshapeinnerysep#1{\def\pgfshapeinnerysep{#1}}
\pgfsetshapeinnerysep{.3333em}


% Set the recommended outer x separation
%
% #1 = size
%
% Example:
%
% \pgfsetshapeouterxsep{2pt}

\def\pgfsetshapeouterxsep#1{\def\pgfshapeouterxsep{#1}}
\pgfsetshapeouterxsep{.5\pgflinewidth}


% Set the recommended outer y separation
%
% #1 = size
%
% Example:
%
% \pgfsetshapeouterxsep{2pt}

\def\pgfsetshapeouterysep#1{\def\pgfshapeouterysep{#1}}
\pgfsetshapeouterysep{.5\pgflinewidth}


% Set the recommended minimum width
%
% #1 = size
%
% Example:
%
% \pgfsetshapeminwidth{1cm}

\def\pgfsetshapeminwidth#1{\def\pgfshapeminwidth{#1}}
\pgfsetshapeminwidth{1pt}


% Set the recommended minimum height
%
% #1 = size
%
% Example:
%
% \pgfsetshapeminheight{1cm}

\def\pgfsetshapeminheight#1{\def\pgfshapeminheight{#1}}
\pgfsetshapeminheight{1pt}


% 
% Rectangle
%

\pgfdeclareshape{rectangle}
{
  \savedanchor\northeast{%
    % Calculate x
    %
    % First, is width < minimum width?
    \pgf@x=\the\wd\pgfnodeparttextbox%
    \setlength\pgf@xc{\pgfshapeinnerxsep}%
    \advance\pgf@x by 2\pgf@xc%
    \setlength\pgf@xb{\pgfshapeminwidth}%
    \ifdim\pgf@x<\pgf@xb%
      % yes, too small. Enlarge...
      \pgf@x=\pgf@xb%
    \fi%
    % Now, calculate right border: .5\wd\pgfnodeparttextbox + .5 \pgf@x + outer sep
    \pgf@x=.5\pgf@x%
    \advance\pgf@x by.5\wd\pgfnodeparttextbox%
    \setlength\pgf@xa{\pgfshapeouterxsep}%
    \advance\pgf@x by\pgf@xa%
    % Calculate y
    %
    % First, is height+depth < minimum height?
    \pgf@y=\ht\pgfnodeparttextbox%
    \advance\pgf@y by\dp\pgfnodeparttextbox%
    \setlength\pgf@yc{\pgfshapeinnerysep}%
    \advance\pgf@y by 2\pgf@yc%
    \setlength\pgf@yb{\pgfshapeminheight}%
    \ifdim\pgf@y<\pgf@yb%
      % yes, too small. Enlarge...
      \pgf@y=\pgf@yb%
    \fi%
    % Now, calculate upper border: .5\ht-.5\dp + .5 \pgf@y + outer sep
    \pgf@y=.5\pgf@y%
    \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
    \advance\pgf@y by.5\ht\pgfnodeparttextbox%
    \setlength\pgf@ya{\pgfshapeouterysep}%
    \advance\pgf@y by\pgf@ya%
  }
    
  \savedanchor\southwest{%
      % Calculate x
      %
      % First, is width < minimum width?
      \pgf@x=\wd\pgfnodeparttextbox%
      \setlength\pgf@xc{\pgfshapeinnerxsep}%
      \advance\pgf@x by 2\pgf@xc%
      \setlength\pgf@xb{\pgfshapeminwidth}%
      \ifdim\pgf@x<\pgf@xb%
        % yes, too small. Enlarge...
        \pgf@x=\pgf@xb%
      \fi%
      % Now, calculate left border: .5\wd\pgfnodeparttextbox - .5 \pgf@x - outer sep
      \pgf@x=-.5\pgf@x%
      \advance\pgf@x by.5\wd\pgfnodeparttextbox%
      \setlength\pgf@xa{\pgfshapeouterxsep}%
      \advance\pgf@x by-\pgf@xa%
      % Calculate y
      %
      % First, is height+depth < minimum height?
      \pgf@y=\ht\pgfnodeparttextbox%
      \advance\pgf@y by\dp\pgfnodeparttextbox%
      \setlength\pgf@yc{\pgfshapeinnerysep}%
      \advance\pgf@y by 2\pgf@yc%
      \setlength\pgf@yb{\pgfshapeminheight}%
      \ifdim\pgf@y<\pgf@yb%
        % yes, too small. Enlarge...
        \pgf@y=\pgf@yb%
      \fi%
       % Now, calculate upper border: .5\ht-.5\dp - .5 \pgf@y - outer sep
      \pgf@y=-.5\pgf@y%
      \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
      \advance\pgf@y by.5\ht\pgfnodeparttextbox%
      \setlength\pgf@ya{\pgfshapeouterysep}%
      \advance\pgf@y by-\pgf@ya%
  }

  %
  % Anchors
  % 
  \anchor{center}{
    \pgf@process{\northeast}%
    \pgf@xa=.5\pgf@x%
    \pgf@ya=.5\pgf@y%
    \pgf@process{\southwest}%
    \pgf@x=.5\pgf@x%
    \pgf@y=.5\pgf@y%
    \advance\pgf@x by \pgf@xa%
    \advance\pgf@y by \pgf@ya%
  }
  \anchor{mid}{\pgf@anchor@rectangle@center\setlength\pgf@y{.5ex}}
  \anchor{base}{\pgf@anchor@rectangle@center\pgf@y=0pt}
  \anchor{north}{
    \pgf@process{\southwest}%
    \pgf@xa=.5\pgf@x%
    \pgf@process{\northeast}%
    \pgf@x=.5\pgf@x%
    \advance\pgf@x by \pgf@xa%
  }
  \anchor{south}{
    \pgf@process{\northeast}%
    \pgf@xa=.5\pgf@x%
    \pgf@process{\southwest}%
    \pgf@x=.5\pgf@x%
    \advance\pgf@x by \pgf@xa%
  }
  \anchor{west}{
    \pgf@process{\northeast}%
    \pgf@ya=.5\pgf@y%
    \pgf@process{\southwest}%
    \pgf@y=.5\pgf@y%
    \advance\pgf@y by \pgf@ya%
  }
  \anchor{mid west}{\southwest\setlength\pgf@y{.5ex}}
  \anchor{base west}{\southwest\pgf@y=0pt}
  \anchor{north west}{
    \southwest
    \pgf@xa=\pgf@x
    \northeast
    \pgf@x=\pgf@xa}
  \anchor{south west}{\southwest}
  \anchor{east}{%
    \pgf@process{\southwest}%
    \pgf@ya=.5\pgf@y%
    \pgf@process{\northeast}%
    \pgf@y=.5\pgf@y%
    \advance\pgf@y by \pgf@ya%
  }
  \anchor{mid east}{\northeast\setlength\pgf@y{.5ex}}
  \anchor{base east}{\northeast\pgf@y=0pt}
  \anchor{north east}{\northeast}
  \anchor{south east}{
    \northeast
    \pgf@xa=\pgf@x
    \southwest
    \pgf@x=\pgf@xa
  }
  \anchorborder{%
    \pgf@xb=\pgf@x% xb/yb is target
    \pgf@yb=\pgf@y%
    \southwest%
    \pgf@xa=\pgf@x% xa/ya is se
    \pgf@ya=\pgf@y%
    \northeast%
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \pgf@xc=.5\pgf@x% x/y is half width/height
    \pgf@yc=.5\pgf@y%
    \advance\pgf@xa by\pgf@xc% xa/ya becomes center
    \advance\pgf@ya by\pgf@yc%
    \edef\pgf@marshal{%
      \noexpand\pgfpointborderrectangle
      {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}
      {\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
    }%
    \pgf@process{\pgf@marshal}%
    \advance\pgf@x by\pgf@xa%
    \advance\pgf@y by\pgf@ya%
  }

  %
  % Background path
  %
  \backgroundpath{
    \pgfpathrectanglecorners
    {\pgfpointadd{\southwest}{\pgfpoint{\pgfshapeouterxsep}{\pgfshapeouterysep}}}
    {\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfshapeouterxsep}{\pgfshapeouterysep}}}}
  }
}



% Special  current bounding box  rectangle:
\expandafter\def\csname pgf@sh@ns@current bounding box\endcsname{rectangle}
\expandafter\def\csname pgf@sh@np@current bounding box\endcsname{%
  \def\southwest{\pgfpoint{\pgf@picminx}{\pgf@picminy}}%
  \def\northeast{\pgfpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
}
\expandafter\def\csname pgf@sh@nt@current bounding box\endcsname{{1}{0}{0}{1}{0pt}{0pt}}



%
% Circle
%

\pgfdeclareshape{circle}
%
% Draws a circle around the text
%
{
  \savedanchor\centerpoint{%
    \pgf@x=.5\wd\pgfnodeparttextbox%
    \pgf@y=.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
  }
    
  \saveddimen\radius{%
    % 
    % Caculate ``height radius''
    % 
    \pgf@ya=.5\ht\pgfnodeparttextbox%
    \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
    \setlength\pgf@yb{\pgfshapeinnerysep}%
    \advance\pgf@ya by\pgf@yb%
    % 
    % Caculate ``width radius''
    % 
    \pgf@xa=.5\wd\pgfnodeparttextbox%
    \setlength\pgf@xb{\pgfshapeinnerxsep}%
    \advance\pgf@xa by\pgf@xb%
    % 
    % Calculate length of radius vector:
    % 
    \pgf@process{\pgfpointnormalised{\pgfpoint{\pgf@xa}{\pgf@ya}}}%
    \ifdim\pgf@x>\pgf@y%
        \c@pgf@counta=\pgf@x%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@xa=16\pgf@xa\relax%
          \divide\pgf@xa by\c@pgf@counta%
          \pgf@xa=16\pgf@xa\relax%
        \fi%
      \else%
        \c@pgf@counta=\pgf@y%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@ya=16\pgf@ya\relax%
          \divide\pgf@ya by\c@pgf@counta%
          \pgf@xa=16\pgf@ya\relax%
        \fi%
    \fi%
    \pgf@x=\pgf@xa%
    % 
    % If necessary, adjust radius so that the size requirements are
    % met: 
    % 
    \setlength{\pgf@xb}{\pgfshapeminwidth}%  
    \setlength{\pgf@yb}{\pgfshapeminheight}%  
    \ifdim\pgf@x<.5\pgf@xb%
        \pgf@x=.5\pgf@xb%
    \fi%
    \ifdim\pgf@x<.5\pgf@yb%
        \pgf@x=.5\pgf@yb%
    \fi%
    % 
    % Now, add larger of outer sepearations.
    % 
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgf@x by\pgf@yb%
    \else%
      \advance\pgf@x by\pgf@xb%
    \fi%
  }

  %
  % Anchors
  % 
  \anchor{center}{\centerpoint}
  \anchor{mid}{\centerpoint\setlength\pgf@y{.5ex}}
  \anchor{base}{\centerpoint\pgf@y=0pt}
  \anchor{north}{\centerpoint\advance\pgf@y by\radius}
  \anchor{south}{\centerpoint\advance\pgf@y by-\radius}
  \anchor{west}{\centerpoint\advance\pgf@x by-\radius}
  \anchor{east}{\centerpoint\advance\pgf@x by\radius}
  \anchor{mid west}{\centerpoint\advance\pgf@x by-\radius\setlength\pgf@y{.5ex}}
  \anchor{mid east}{\centerpoint\advance\pgf@x by\radius\setlength\pgf@y{.5ex}}
  \anchor{base west}{\centerpoint\advance\pgf@x by-\radius\pgf@y=0pt}
  \anchor{base east}{\centerpoint\advance\pgf@x by\radius\pgf@y=0pt}
  \anchor{north west}{
    \centerpoint
    \pgf@xa=\radius
    \advance\pgf@x by-0.707107\pgf@xa
    \advance\pgf@y by0.707107\pgf@xa
  }
  \anchor{south west}{
    \centerpoint
    \pgf@xa=\radius
    \advance\pgf@x by-0.707107\pgf@xa
    \advance\pgf@y by-0.707107\pgf@xa
  }
  \anchor{north east}{
    \centerpoint
    \pgf@xa=\radius
    \advance\pgf@x by0.707107\pgf@xa
    \advance\pgf@y by0.707107\pgf@xa
  }
  \anchor{south east}{
    \centerpoint
    \pgf@xa=\radius
    \advance\pgf@x by0.707107\pgf@xa
    \advance\pgf@y by-0.707107\pgf@xa
  }
  \anchorborder{
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \edef\pgf@marshal{%
      \noexpand\pgfpointborderellipse
      {\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}
      {\noexpand\pgfpoint{\radius}{\radius}}%
    }%
    \pgf@marshal%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \centerpoint%
    \advance\pgf@x by\pgf@xa%
    \advance\pgf@y by\pgf@ya%
  }

  %
  % Background path
  %
  \backgroundpath{
    \@tempdima=\radius%
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\@tempdima by-\pgf@yb%
    \else%
      \advance\@tempdima by-\pgf@xb%
    \fi%
    \pgfpathcircle{\centerpoint}{\@tempdima}%
  }
}





\endinput

pgfbasesnakes.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfbasesnakes.code.tex,v 1.6 2005/10/25 08:18:14 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\newdimen\pgfsnakeremainingdistance
\newdimen\pgfsnakecompleteddistance


% Creates a new pgf snake
%
% #1 = snake name
% #1 = initial state
% #3 = states of the snake
%
%
% This command declares a new snake for later use. The second
% parameter specifies the states of the snake, see also the
% description of pgfpathsnake.
%
% Inside the code of #3 the command \state may be used. This command
% will only be defined while #3 is executed.
%
% Example:
%
% \pgfdeclaresnake{zig zag}{one zig zag}
% {
%   \state{one zig zag}[width=10pt]
%   {
%     \pgfpathlineto{\pgfpoint{2.5pt}{2.5pt}}
%     \pgfpathlineto{\pgfpoint{7.5pt}{-2.5pt}}
%     \pgfpathlineto{\pgfpoint{10pt}{0pt}}
%   }
%   \state{final}
%   {
%     \pgfpathlineto{\pgfpoint{\pgfsnakeremainingdistance}{0pt}}
%   }
% }

\long\def\pgfdeclaresnake#1#2#3{%
  \def\pgf@snake@name{#1}%
  \@namedef{pgf@snake@@#1@initial}{#2}%
  \let\pgf@orig@state=\state%
  \let\state=\pgf@snake@state
  #3
  \let\state=\pgf@orig@state%
}


% Sets the additional transformation applied to every segment of a snake
%
% #1 = transformation
%
% Example:
%
% \pgfsetsnakesegmenttransformation{\pgftransformyshift{5pt}}

\def\pgfsetsnakesegmenttransformation#1{\def\pgf@snakeadditionaltransform{#1}}
\pgfsetsnakesegmenttransformation{}


% Declares a new state
%
% #1 = state name
% #2 = options
% #3 = path element
%
% Description:
%
% When a snake is drawn and the current state is #1, the following
% happens. First, the options are executed, which will possible change
% the state. If that does not happen, the path element is added to the
% path and the coordinate system is translated by the path element's
% width (which is specified using the width option).
%
% Example:
%
% \state{initial}[width=10pt]
% {
%   \pgfpathlineto{\pgfpoint{2.5pt}{2.5pt}}
%   \pgfpathlineto{\pgfpoint{7.5pt}{-2.5pt}}
%   \pgfpathlineto{\pgfpoint{10pt}{0pt}}
% }

\def\pgf@snake@state#1{\@ifnextchar[{\pgf@@snake@start#1}{\pgf@@snake@start#1[]}}%}
\def\pgf@@snake@start#1[#2]#3{%
  \@namedef{pgf@snake@@\pgf@snake@name @#1@options}{#2}%
  \@namedef{pgf@snake@@\pgf@snake@name @#1@code}{#3}%
}



% Use multiple snakes
%
% #1 = list of snake names/length pairs
% #2 = point to which the snake leads
%
% This operation uses the snakes in parameter #1 to get to the point
% #4. The parameter #1 should contain pairs consisting of a snake name
% and a length for which this snake should be used. When the length is
% computed, the dimensions \pgfsnakeremainingdistance and
% \pgfsnakecompleteddistance will have been set to the length of the
% total distance to #2 that has already been covered/that still needs
% to be covered.
%
% Example:
%
% \pgfpathsnakesto{{lineto}{1cm},{zig zag}{\pgfsnakeremainingdistance}}{\pgfpoint{2cm}{3cm}}

\def\pgfpathsnakesto#1#2{%
  \begingroup%
    % compute target vector
    \pgfpointtransformed{#2}%
    \advance\pgf@x by-\pgf@path@lastx%
    \advance\pgf@y by-\pgf@path@lasty%
    % Ok, now normalize the vector...
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\pgfpointnormalised{}}%
    % ok, now computer length (arghh...)
    % In theory that's easy: divide the larger of the values x or y by
    % the normalizes x or y. Well...
    %
    % First, make xa and ya positive:
    \ifdim\pgf@xa<0pt%
      \pgf@xa=-\pgf@xa%
    \fi%
    \ifdim\pgf@ya<0pt%
      \pgf@ya=-\pgf@ya%
    \fi%
    % Now do division:
    \ifdim\pgf@xa>\pgf@ya%
      \c@pgf@counta=\pgf@x%
      \ifnum\c@pgf@counta=0\relax%
      \else%
        \divide\c@pgf@counta by 255\relax%
        \pgf@xa=16\pgf@xa\relax%
        \divide\pgf@xa by\c@pgf@counta%
        \pgf@xa=16\pgf@xa\relax%
      \fi%
    \else%
      \c@pgf@counta=\pgf@y%
      \ifnum\c@pgf@counta=0\relax%
      \else%
        \divide\c@pgf@counta by 255\relax%
        \pgf@ya=16\pgf@ya\relax%
        \divide\pgf@ya by\c@pgf@counta%
        \pgf@xa=16\pgf@ya\relax%
      \fi%
    \fi%
    % Make positive:
    \ifdim\pgf@xa<0pt%
      \pgf@xa=-\pgf@xa%
    \fi%
    % Ok, now we draw things...
    \edef\pgf@list{#1}%
    \pgfsnakeremainingdistance=\pgf@xa%
    \pgfsnakecompleteddistance=0pt%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \@for\pgf@temp:=\pgf@list\do{%
      \ifx\pgf@temp\@empty%
      \else%
        \expandafter\pgf@snake@invoke\pgf@temp%
      \fi%
    }%
  \endgroup%
}

\def\pgf@snake@invoke#1#2{%
  \setlength\pgf@xa{#2}%
  {%
    \edef\pgf@marshal{\noexpand\pgfpathsnakealongvector{#1}{\the\pgf@xa}{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}}%
    \pgf@marshal%
  }%
  \advance\pgfsnakecompleteddistance by\pgf@xa%
  \advance\pgfsnakeremainingdistance by-\pgf@xa%
}

% Use a snake
%
% #1 = snake name
% #2 = point to which the snake leads
%
% This operation mainly computes \pgfpathsnakealongvector for a vector
% appropriately choosen. See \pgfpathsnakealongvector for details.
%
% Example:
%
% \pgfpathsnaketo{zig zag}{\pgfpoint{2cm}{3cm}}

\def\pgfpathsnaketo#1#2{\pgfpathsnakesto{{#1}{\pgfsnakeremainingdistance}}{#2}}



% Use a snake
%
% #1 = snake name
% #2 = length of the snake
% #3 = vector along which the snake grows, should have unit length.
%
% This command draws a snake (more precisely, it adds a snake to the
% path). This works as follows:
%
% First, the coordinate system is transformed such that the vector #3
% points to the right.
%
% Next, the state `initial' of the snake is entered. Unless the
% options of this state cause it to switch to another state, the path
% element is added to the path. Then, the coordinate system is
% translated by the width of the path element as specified in the
% width option of the path element. The dimensions
% \pgfsnakeremainingdistance and \pgfsnakecompleteddistance are
% updated. 
%
% The process ends when the state `final' is entered. The code of the
% final state is executed and the process stops.
%
% Example:
%
% \pgfpathsnakealongvector{zig zag}{100pt}{\pgfpolar{30}{1pt}}

\def\pgfpathsnakealongvector#1#2#3{%
  \@ifundefined{pgf@snake@@#1@initial}{\PackageError{pgf}{Undefined snake ``#1''}{}}
  { 
  \begingroup% keep things local
    \pgftransformreset%
    \pgf@pt@x=\pgf@path@lastx% evil trickery to transform to the last point
    \pgf@pt@y=\pgf@path@lasty%
    \pgf@process{#3}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@xb=-\pgf@y%
    \pgf@yb=\pgf@x%
    \pgftransformcm
      {\pgf@sys@tonumber{\pgf@xa}}{\pgf@sys@tonumber{\pgf@ya}}
      {\pgf@sys@tonumber{\pgf@xb}}{\pgf@sys@tonumber{\pgf@yb}}
      {\pgfpointorigin}%
    % Now, setup the automaton
    \expandafter\let\expandafter\pgf@snake@current@state\expandafter=\csname pgf@snake@@#1@initial\endcsname%
    \def\pgf@snake@name{#1}%  
    \pgfsnakecompleteddistance=0pt%  
    \setlength\pgfsnakeremainingdistance{#2}%
    \pgf@snake@run%
    % Last step:
    {%
      \pgftransformxshift{\pgfsnakecompleteddistance}%
      \pgf@snakeadditionaltransform%
      \csname pgf@snake@@#1@final@code\endcsname%
    }%
  \endgroup%
  }%
}

\def\pgf@final@text{final}

\def\pgf@snake@run{%
  \let\pgf@snake@next=\pgf@snake@do@state%
  \ifx\pgf@snake@current@state\pgf@final@text%
    \let\pgf@snake@next=\relax%
  \fi%
  \pgf@snake@next%  
}

\def\pgf@snake@do@state{%
  \let\pgf@snake@next=\relax%
  \let\pgf@snake@next@state=\pgf@snake@current@state%
  % execute options
  \def\pgf@marshal{\setkeys{pgfsnake}}%
  \expandafter\expandafter\expandafter\pgf@marshal
  \expandafter\expandafter\expandafter{\csname pgf@snake@@\pgf@snake@name @\pgf@snake@current@state @options\endcsname}%
  \ifx\pgf@snake@next\relax%
    \let\pgf@snake@next=\pgf@snake@do@code%
  \fi%
  \pgf@snake@next%
}

\def\pgf@snake@do@code{%
  % Ok, execute code:
  {%
    \pgftransformxshift{\pgfsnakecompleteddistance}%
    \pgf@snakeadditionaltransform%
    \csname pgf@snake@@\pgf@snake@name @\pgf@snake@current@state @code\endcsname%
  }%
  % next, do transformation and update
  \setlength{\pgf@xa}{\pgf@snake@width}%
  \advance\pgfsnakeremainingdistance by-\pgf@xa%
  \advance\pgfsnakecompleteddistance by\pgf@xa%
  % Next iteration:
  \let\pgf@snake@current@state=\pgf@snake@next@state%
  \pgf@snake@run%
}

\define@key{pgfsnake}{width}{%
  \def\pgf@snake@width{#1}%
  \pgf@snake@switch@if#1 to final\pgf@stop%
}
\define@key{pgfsnake}{switch if less than}{%
  \pgf@snake@switch@if#1\pgf@stop%
}
\define@key{pgfsnake}{next state}{%
  \def\pgf@snake@next@state{#1}%
}

\def\pgf@snake@switch@if#1to #2\pgf@stop{%
  \ifx\pgf@snake@next\relax%
    \setlength\pgf@x{#1}%
    \ifdim\pgfsnakeremainingdistance<\pgf@x%
      \def\pgf@snake@current@state{#2}%
      \let\pgf@snake@next=\pgf@snake@run%
    \fi%
  \fi%
}



% lineto snake
%
% This snake simply adds a straight line. This snake is mainly useful
% in conjunction with other snakes.

\pgfdeclaresnake{lineto}{final}
{
  \state{final}
  { \pgfpathlineto{\pgfpoint{\pgfsnakeremainingdistance}{0pt}} }
}



% moveto snake
%
% This snake simply jumps to the end. This snake, too, is mainly
% useful in conjunction with other snakes.

\pgfdeclaresnake{moveto}{final}
{
  \state{final}
  { \pgfpathmoveto{\pgfpoint{\pgfsnakeremainingdistance}{0pt}} }
}



\endinput

pgfcore.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcore.code.tex,v 1.3 2005/10/25 08:18:14 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

\newif\ifpgf@draftmode

\input pgfcoremath.code.tex
\input pgfcorepoints.code.tex
\input pgfcorepathconstruct.code.tex
\input pgfcorepathusage.code.tex
\input pgfcorescopes.code.tex
\input pgfcoregraphicstate.code.tex
\input pgfcoretransformations.code.tex
\input pgfcorequick.code.tex
\input pgfcoreobjects.code.tex
\input pgfcorepathprocessing.code.tex
\input pgfcorearrows.code.tex
\input pgfcoreshade.code.tex

\endinput

pgfcorearrows.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorearrows.code.tex,v 1.2 2005/07/10 20:11:23 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



% Sets the end arrow
%
% #1 = An arrow name
%
% Example:
%
% \pgfsetarrowsend{stealth}

\def\pgfsetarrowsend#1{\pgf@arrowset{end}{#1}}
\def\pgf@arrowset#1#2{%
  \@ifundefined{pgf@arrow@code@#2}
  {\PackageError{pgf}{Arrow #1 type ``#2'' unknown}{}}
  {%
    \edef\pgf@arrow@temp{#2}%
    \ifx\pgf@arrow@temp\@empty% ah. clear!
      \expandafter\let\csname pgf@#1arrow\endcsname=\@empty%
      \expandafter\let\csname pgf@shorten@#1\endcsname=\@empty%
    \else%
      %\pgf@arrow@prepare{#2}%
      \expandafter\def\csname pgf@#1arrow\endcsname{\pgf@arrow@call{#2}}%
      \expandafter\edef\csname pgf@shorten@#1\endcsname{\expandafter\noexpand\csname pgf@arrow@right@#2\endcsname}%
    \fi%
  }%
}


% Sets the start arrow
%
% #1 = An arrow name
%
% Example:
%
% \pgfsetarrowsstart{stealth}

\def\pgfsetarrowsstart#1{\pgf@arrowset{start}{\csname pgf@arrows@invert#1\endcsname}}

\def\pgf@arrows@invname#1#2{\expandafter\def\csname pgf@arrows@invert#1\endcsname{#2}}
\pgf@arrows@invname{}{}




% Sets arrows
%
% #1 = An arrow specification of the form ``left''-``right''. The last
%      and right should be arrow types that have been defined using
%      the \pgfarrowsdef command
%
% Example:
%
% \pgfsetarrows{-to}

\def\pgfsetarrows#1{\pgf@arrows#1\pgf@stop}
\def\pgf@arrows#1-#2\pgf@stop{%
  \pgfsetarrowsstart{#1}
  \pgfsetarrowsend{#2}
}

\def\pgf@arrows@checked#1#2#3{%
  \@ifundefined{pgf@arrow@code@#2}%
  {%
    \PackageError{pgf}{Arrow end type ``#2'' unknown}{}}%
  {%
    \@ifundefined{pgf@arrow@code@\csname pgf@arrows@invert#1\endcsname}
    {\PackageError{pgf}{Arrow start type ``#1'' unknown}{}}%
    {#3}%
  }%
}

\def\pgf@arrows@check@already#1#2#3{%
  \@ifundefined{pgf@arrow@code@#2}
  {#3}%
  {\PackageError{pgf}{Arrow end type ``#2'' already defined}{}}%
}


% Called when an arrow needs to be rendered

\def\pgf@arrow@call#1{%
  \expandafter\ifx\csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname\relax%
    \pgfsysprotocol@getcurrentprotocol\pgf@arrow@temp%
    {%
      \pgfinterruptpath%
        \let\pgfusepath=\pgf@nousepath@here%
        \pgf@relevantforpicturesizefalse%
        \pgftransformreset%
        \pgfsysprotocol@setcurrentprotocol\@empty%
        \pgfsysprotocol@bufferedtrue%
        \pgfsys@beginscope%
        \csname pgf@arrow@code@#1\endcsname%
        \pgfsys@endscope%
        \pgfsysprotocol@getcurrentprotocol\pgf@@arrow@temp%
        \global\let\pgf@@arrow@temp=\pgf@@arrow@temp%
      \endpgfinterruptpath%
      \expandafter\xdef\csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname{%
        \noexpand\pgfsys@invoke{\pgf@@arrow@temp}}%
    }%
    \pgfsysprotocol@setcurrentprotocol\pgf@arrow@temp%
  \fi%
  \csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname%
} 

\def\pgf@arrow@code@{} % dummy

\def\pgf@nousepath@here#1{%
  \PackageError{pgf}{The definition of an arrow may not use \string\pgfusepath}{}
}



% Define an arrow type.
%
% #1 = name or mnemonic for arrow when used at the start (examples: ``to'' or ``<'')
% #2 = name or mnemonic for arrow when used at the end (examples: ``to'' or ``>'')
% #3 = code to setup the left and right extend of the arrow. To set
%      the left extend, call \pgfarrowsleftextend, for the right \pgfarrowsrightextend.
% #4 = protocolable code
%
% Description:
%
% When you define an arrow using this command, you must give two
% names. The first is used for the arrow when it is ``at the start'',
% the other when it is at the end. For example, a simple arrow might
% have the names ``<'' and ``>'', though these particular names are
% not used by pgf and left for the user.
%
% The code should be ``protocolable'' code. This means that it uses
% only pretty simple commands. 
%
% The arrow code will be protocolled once for each line width at which
% the arrow is used. Thus, the code can (and often should) depend on
% the line width.
%
% The arrow should ``point right'' in the coordinate system. The end
% of the line at which the arrow should be drawn will be at the origin
% of the coordinate system. The coordinate system will be scaled and
% rotated appropriately before the arrow is drawn.
%
% The right extend of the arrow should be set to how much the arrow
% ``protrudes over the right''. Prior to drawing the arrow, the line
% will be shortened by this amount so that the arrow tip will exactly
% touch the original right end of the unshortened line.
%
% The left extend specifies the leftmost point of the arrow. This is
% important only if you use the swapping command, when this end is
% used to compute the shortening. 
%
% The definition of an arrow should normally take care of the fact
% that the line cap of the main line may be a butt cap, a round cap or
% a rect cap. In all cases, the arrow should ``cover'' the cap
% completely or not at all.
%
% Example:
%
% \pgfarrowsdeclare{stealth}{stealth}
% {
%   \pgfarrowsleftextend{-6\pgflinewidth}
%   \pgfarrowsrightextend{2\pgflinewidth}
% {
%   \pgfpathmoveto{\pgfpoint{2\pgflinewidth}{0pt}}
%   \pgfpathlineto{\pgfpoint{-6\pgflinewidth}{4\pgflinewidth}}
%   \pgfpathlineto{\pgfpoint{-3\pgflinewidth}{0pt}}
%   \pgfpathlineto{\pgfpoint{-6\pgflinewidth}{-4\pgflinewidth}}
%   \pgfusepathqfill
% }

\def\pgfarrowsdeclare#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}
  {%
    \expandafter\def\csname pgf@arrow@code@#2\endcsname{#4}%
    \expandafter\def\csname pgf@arrow@left@#2\endcsname{#3\advance\pgf@x by-\pgf@xa}%
    \expandafter\def\csname pgf@arrow@right@#2\endcsname{#3\advance\pgf@x by\pgf@xb}%
    \pgf@arrows@invname{#1}{#2}%
  }%
}

\def\pgfarrowsleftextend#1{\setlength\pgf@xa{#1}}
\def\pgfarrowsrightextend#1{\setlength\pgf@xb{#1}}

\def\pgf@arrows@repeat#1#2{%
  \edef\pgf@arrows@marshal{\noexpand\let\expandafter\noexpand\csname#2\endcsname=\expandafter\noexpand\csname#1\endcsname}%
  \pgf@arrows@marshal}



% Declare a new arrow type to be the same as another one.
%
% #1 = name of new start
% #2 = name or new end
% #3 = name or old start
% #4 = name or old end
%
% Example:
%
% \pgfarrowsdeclarealias{<}{>}{to}{to}

\def\pgfarrowsdeclarealias#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}
  {%
    \pgf@arrows@checked{#3}{#4}%
    {%
      \pgf@arrows@repeat{pgf@arrow@code@#4}{pgf@arrow@code@#2}%
      \pgf@arrows@repeat{pgf@arrow@left@#4}{pgf@arrow@left@#2}%
      \pgf@arrows@repeat{pgf@arrow@right@#4}{pgf@arrow@right@#2}%
      \pgf@arrows@invname{#1}{#2}%
    }%
  }%
}




% Creates a new arrows by ``swapping'' an existing arrow.
%
% #1 = name of new start
% #2 = name of new end
% #3 = name of old start
% #4 = name of old end
%
% Example:
%
% \pgfarrowsdeclarealias{]}{[}{[}{]}

\def\pgfarrowsdeclarereversed#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}%
  {%
    \pgf@arrows@checked{#3}{#4}%
    {%
      \expandafter\def\csname pgf@arrow@code@#2\endcsname{%
        \pgflowlevel{\pgftransformxscale{-1}}%
        \csname pgf@arrow@code@#4\endcsname}%
      \pgf@arrows@repeat{pgf@arrow@right@#4}{pgf@arrow@left@#2}%
      \pgf@arrows@repeat{pgf@arrow@left@#4}{pgf@arrow@right@#2}%
      \pgf@arrows@invname{#1}{#2}%
    }%
  }%
}



% Creates new arrows by combining two existing arrows.
%
% #1 = optional additional space
% #2 = name of new start
% #3 = name of new end
% #4 = name of second (innermost) start
% #5 = name of second end
% #6 = name of first (outermost) start
% #7 = name of first end
%
% In the star form, the line will end at the innermost arrows,
% otherwise the line will end at the outermost arrows.
%
% Example:
%
% \pgfarrowsdeclarecombine*{|<}{>|}{|}{|}{<}{>}
% \pgfarrowsdeclarecombine{<<}{>>}{<}{>}{<}{>}

\def\pgfarrowsdeclarecombine{\@ifnextchar*{\pgfarrowsdeclarecombine@star}{\pgf@@arrowsdeclarecombine}}

\def\pgf@@arrowsdeclarecombine{\@ifnextchar[{\pgf@arrowsdeclarecombine}{\pgf@arrowsdeclarecombine[0pt]}}
\def\pgf@arrowsdeclarecombine[#1]#2#3#4#5#6#7{%
  \pgf@arrows@check@already{#2}{#3}%
  {%
    \pgf@arrows@checked{#4}{#5}%
    {%
      \pgf@arrows@checked{#6}{#7}%
      {%
        \expandafter\edef\csname pgf@arrow@code@#3\endcsname{%
          \noexpand\pgfscope%
          {\expandafter\noexpand\csname pgf@arrow@code@#7\endcsname}%
          \noexpand\endpgfscope%
          {%
            \noexpand\setlength\pgf@x{#1}%
            \noexpand\pgf@process{\expandafter\noexpand\csname pgf@arrow@left@#7\endcsname}%
            \noexpand\pgf@process{\expandafter\noexpand\csname pgf@arrow@right@#5\endcsname}%
            \pgf@x=-\pgf@x%
            \noexpand\pgflowlevel{\noexpand\pgftransformxshift{\pgf@x}}%
            \expandafter\noexpand\csname pgf@arrow@code@#5\endcsname}%
          }%
        \pgf@arrows@repeat{pgf@arrow@right@#7}{pgf@arrow@right@#3}%
        \expandafter\def\csname pgf@arrow@left@#3\endcsname{%
          \pgf@process{%
            \setlength\pgf@y{#1}%
            \advance\pgf@x by\pgf@y%
            \pgf@process{\csname pgf@arrow@left@#7\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#5\endcsname}%
            \pgf@process{\csname pgf@arrow@left@#5\endcsname}%
          }%
        }%
        \pgf@arrows@invname{#2}{#3}%
      }%
    }%
  }%
}

\def\pgfarrowsdeclarecombine@star*{\@ifnextchar[{\pgf@arrowsdeclarecombine@star}{\pgf@arrowsdeclarecombine@star[0pt]}}
\def\pgf@arrowsdeclarecombine@star[#1]#2#3#4#5#6#7{%
  \pgf@arrows@check@already{#2}{#3}%
  {%
    \pgf@arrows@checked{#4}{#5}%
    {%
      \pgf@arrows@checked{#6}{#7}%
      {%
        \expandafter\edef\csname pgf@arrow@code@#3\endcsname{%
          \noexpand\pgfscope%
            {%
              \noexpand\setlength\pgf@x{#1}%
              \pgf@process{\expandafter\noexpand\csname pgf@arrow@left@#7\endcsname}%
              \pgf@process{\expandafter\noexpand\csname pgf@arrow@right@#5\endcsname}%
              \noexpand\pgflowlevel{\noexpand\pgftransformxshift{\pgf@x}}%
            }%
            {\expandafter\noexpand\csname pgf@arrow@code@#7\endcsname}%
          \noexpand\endpgfscope%
          \expandafter\noexpand\csname pgf@arrow@code@#5\endcsname%
        }%
        \pgf@arrows@repeat{pgf@arrow@left@#7}{pgf@arrow@left@#3}%
        \expandafter\def\csname pgf@arrow@right@#3\endcsname{%
          \pgf@process{%
            \setlength\pgf@y{#1}%
            \advance\pgf@x by\pgf@y%
            \pgf@process{\csname pgf@arrow@left@#7\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#5\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#7\endcsname}%
          }%
        }%
        \pgf@arrows@invname{#2}{#3}%
      }%
    }%
  }%
}



% Creates new arrows by doubling/tripling existing arrows.
%
% #1 = optional additional space in multiples of line width
% #2 = name of new start
% #3 = name of new end
% #4 = name of old start
% #5 = name of old end
%
% Example:
%
% \pgfarrowsdeclaredouble{<<}{>>}{<}{>}

\def\pgfarrowsdeclaredouble{\@ifnextchar[{\pgf@arrowsdeclaredouble}{\pgf@arrowsdeclaredouble[0pt]}}
\def\pgf@arrowsdeclaredouble[#1]#2#3#4#5{\pgfarrowsdeclarecombine[#1]{#2}{#3}{#4}{#5}{#4}{#5}}
\def\pgfarrowsdeclaretriple{\@ifnextchar[{\pgf@arrowsdeclaretriple}{\pgf@arrowsdeclaretriple[0pt]}}
\def\pgf@arrowsdeclaretriple[#1]#2#3#4#5{%
  \pgfarrowsdeclarecombine[#1]{pgf@trip@#2}{pgf@trip@#3}{#4}{#5}{#4}{#5}%
  \pgfarrowsdeclarecombine[#1]{#2}{#3}{pgf@trip@#2}{pgf@trip@#3}{#4}{#5}%
}


% A stealth-fighter-like pointed arrow
%
% Example:
%
% \pgfsetarrows{-stealth}

\pgfarrowsdeclare{stealth}{stealth}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfarrowsleftextend{-3\@tempdima}
  \pgfarrowsrightextend{5\@tempdima}
}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfpathmoveto{\pgfpoint{5\@tempdima}{0pt}}
  \pgfpathlineto{\pgfpoint{-3\@tempdima}{4\@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{-3\@tempdima}{-4\@tempdima}}
  \pgfusepathqfill
}

\pgfarrowsdeclarereversed{stealth reversed}{stealth reversed}{stealth}{stealth}


% An arrow similar to the $\to$ arrow
%
% Example:
%
% \pgfsetarrow{-to}

\pgfarrowsdeclare{to}{to}
{
  \@tempdima=-0.84pt%
  \advance\@tempdima by-1.3\pgflinewidth%
  \@tempdimb=0.21pt%
  \advance\@tempdimb by.625\pgflinewidth%
  \pgfarrowsleftextend{\@tempdima}
  \pgfarrowsrightextend{\@tempdimb}
}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{0.8\pgflinewidth}
  \pgfsetdash{}{0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfpoint{-3\@tempdima}{4\@tempdima}}
  \pgfpathcurveto
  {\pgfpoint{-2.75\@tempdima}{2.5\@tempdima}}
  {\pgfpoint{0pt}{0.25\@tempdima}}
  {\pgfpoint{0.75\@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfpoint{0pt}{-0.25\@tempdima}}
  {\pgfpoint{-2.75\@tempdima}{-2.5\@tempdima}}
  {\pgfpoint{-3\@tempdima}{-4\@tempdima}}
  \pgfusepathqstroke
}

\pgfarrowsdeclare{to reversed}{to reversed}
{
  \@tempdima=-0.21pt%
  \advance\@tempdima by-0.475\pgflinewidth%
  \@tempdimb=0.98pt%
  \advance\@tempdimb by1.45\pgflinewidth%
  \pgfarrowsleftextend{\@tempdima}
  \pgfarrowsrightextend{\@tempdimb}
}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{0.8\pgflinewidth}
  \pgfsetdash{}{0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfpoint{3.5\@tempdima}{4\@tempdima}}
  \pgfpathcurveto
  {\pgfpoint{3.25\@tempdima}{2.5\@tempdima}}
  {\pgfpoint{0.5\@tempdima}{0.25\@tempdima}}
  {\pgfpoint{-0.25\@tempdima}{0\@tempdima}}
  \pgfpathcurveto
  {\pgfpoint{0.5\@tempdima}{-0.25\@tempdima}}
  {\pgfpoint{3.25\@tempdima}{-2.5\@tempdima}}
  {\pgfpoint{3.5\@tempdima}{-4\@tempdima}}
  \pgfusepathqstroke
}



% LaTeX's orginal arrow type
%
% Example:
%
% \pgfsetarrows{-latex}

\pgfarrowsdeclare{latex}{latex}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfarrowsleftextend{-1\@tempdima}
  \pgfarrowsrightextend{9\@tempdima}
}
{
  \@tempdima=0.28pt%
  \advance\@tempdima by.3\pgflinewidth%
  \pgfpathmoveto{\pgfpoint{9\@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfpoint{6.3333\@tempdima}{.5\@tempdima}}
  {\pgfpoint{2\@tempdima}{2\@tempdima}}
  {\pgfpoint{-1\@tempdima}{3.75\@tempdima}}
  \pgfpathlineto{\pgfpoint{-1\@tempdima}{-3.75\@tempdima}}
  \pgfpathcurveto
  {\pgfpoint{2\@tempdima}{-2\@tempdima}}
  {\pgfpoint{6.3333\@tempdima}{-.5\@tempdima}}
  {\pgfpoint{9\@tempdima}{0pt}}
  \pgfusepathqfill
}
\pgfarrowsdeclarereversed{latex reversed}{latex reversed}{latex}{latex}



% A bar shaped arrow
%
% Example:
%
% \pgfsetarrows{-|}

\pgfarrowsdeclare{|}{|}
{
  \pgfarrowsleftextend{-0.25\pgflinewidth}
  \pgfarrowsrightextend{.75\pgflinewidth}
}
{
  \@tempdima=2pt%
  \advance\@tempdima by1.5\pgflinewidth%
  \pgfsetdash{}{0pt}
  \pgfsetrectcap
  \pgfpathmoveto{\pgfpoint{0.25\pgflinewidth}{-\@tempdima}}
  \pgfpathlineto{\pgfpoint{0.25\pgflinewidth}{\@tempdima}}
  \pgfusepathqstroke
}



\endinput

pgfcoregraphicstate.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex,v 1.3 2005/09/21 00:05:34 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

% Globals

\newdimen\pgflinewidth


% Set the line width to #1.
% 
% #1 = new line width.
% 
% Example:
%
% \pgfsetlinewidth{3pt}

\def\pgfsetlinewidth#1{%
  \setlength\pgflinewidth{#1}%
  \global\pgflinewidth=\pgflinewidth%
  \pgfsys@setlinewidth{\the\pgflinewidth}%
  \ignorespaces}


% Set the miter limit to #1.
% 
% #1 = new miter limit factor.
% 
% Example:
%
% \pgfsetmiterlimit{3}

\def\pgfsetmiterlimit#1{%
  \pgfsys@setmiterlimit{#1}%
  \ignorespaces}


% Set the dash pattern to #1 with phase #2/
% 
% #1 = a row of numbers of length of ``on'' and ``off'' points.
% #2 = a phase
% 
% Example:
%
% \pgfsetdash{}          {0pt} % solid line
% \pgfsetdash{{.1cm}}    {0pt} % long dashes
% \pgfsetdash{{1pt}{1ex}}{0pt} % dotted

\def\pgfsetdash#1#2{%
  \def\pgf@temp{}%
  \def\pgf@next{\pgf@strip}%
  \pgf@strip#1{pgf@stop}%
  \setlength\pgf@x{#2}%
  \pgfsys@setdash{\pgf@temp}{\the\pgf@x}%
  \ignorespaces}

\def\pgf@strip#1{%
  \def\pgf@@temp{#1}%
  \ifx\pgf@@temp\pgf@stop%
    \let\pgf@next=\relax%
  \else%
    \setlength\pgf@x{#1}%
    \ifx\pgf@temp\@empty%
      \edef\pgf@temp{\the\pgf@x}%
    \else%
      \edef\pgf@temp{\pgf@temp,\the\pgf@x}%
    \fi%
  \fi\pgf@next}

\def\pgf@stop{pgf@stop}


% Set color of strokes. This will overrule the normal color.
% 
% Example:
%
% \pgfsetstrokecolor{red}

\def\pgfsetstrokecolor#1{%
  \colorlet{pgf@tempcolor}{#1}%
  \@ifundefined{applycolormixins}{}{\applycolormixins{pgf@tempcolor}}%
  \expandafter\expandafter\expandafter\pgf@setstrokecolor\csname\string\color@pgf@tempcolor\endcsname%
}
\def\pgf@setstrokecolor#1#2#3#4#5{%
  \expandafter\ifx\csname pgfsys@color@#4@stroke\endcsname\relax%
    \PackageError{pgfbase}{Unsupported color model `#4'. Sorry}{}%
  \else%
    \edef\pgf@colmarshal{\expandafter\noexpand\csname pgfsys@color@#4@stroke\endcsname}%
    \pgf@uncomma#5,,%
    \pgf@colmarshal%
  \fi}

\def\pgf@uncomma#1,{%
  \def\pgf@coltest{#1}%
  \ifx\pgf@coltest\@empty%
    \let\pgf@colnext=\relax%
  \else%
    \expandafter\def\expandafter\pgf@colmarshal\expandafter{\pgf@colmarshal{#1}}%
    \let\pgf@colnext=\pgf@uncomma%
  \fi%
  \pgf@colnext%  
}


% Set color of fills. This will overrule the normal color.
% 
% Example:
%
% \pgfsetfillcolor{gray}

\def\pgfsetfillcolor#1{%
  \colorlet{pgf@tempcolor}{#1}%
  \@ifundefined{applycolormixins}{}{\applycolormixins{pgf@tempcolor}}%
  \expandafter\expandafter\expandafter\pgf@setfillcolor\csname\string\color@pgf@tempcolor\endcsname%
}
\def\pgf@setfillcolor#1#2#3#4#5{%
  \expandafter\ifx\csname pgfsys@color@#4@fill\endcsname\relax%
    \PackageError{pgfbase}{Unsupported color model `#4'. Sorry}{}%
  \else%
    \edef\pgf@colmarshal{\expandafter\noexpand\csname pgfsys@color@#4@fill\endcsname}%
    \pgf@uncomma#5,,%
    \pgf@colmarshal%
  \fi}



% Sets both the stroke and fill color.
% 
% Example:
%
% \pgfsetcolor{blue}

\def\pgfsetcolor#1{%
  \colorlet{pgf@tempcolor}{#1}%
  \@ifundefined{applycolormixins}{}{\applycolormixins{pgf@tempcolor}}%
  \expandafter\expandafter\expandafter\pgf@setcolor\csname\string\color@pgf@tempcolor\endcsname%
}
\def\pgf@setcolor#1#2#3#4#5{%
  \expandafter\ifx\csname pgfsys@color@#4\endcsname\relax%
    \PackageError{pgfbase}{Unsupported color model `#4'. Sorry}{}%
  \else%
    \edef\pgf@colmarshal{\expandafter\noexpand\csname pgfsys@color@#4\endcsname}%
    \pgf@uncomma#5,,%
    \pgf@colmarshal%
  \fi}

% Code for ensuring the stroke/fill colors are correctly reset.
\def\XC@bcolor{\pgfsys@color@reset}

% Set a butt line cap.
% 
% Example:
%
% \pgfsetbuttcap

\def\pgfsetbuttcap{\pgfsys@buttcap\ignorespaces}


% Set a round line cap.
% 
% Example:
%
% \pgfsetroundcap

\def\pgfsetroundcap{\pgfsys@roundcap\ignorespaces}


% Set a rectangular line cap.
% 
% Example:
%
% \pgfsetrectcap

\def\pgfsetrectcap{\pgfsys@rectcap\ignorespaces}


% Set a miter line join.
% 
% Example:
%
% \pgfsetmiterjoin

\def\pgfsetmiterjoin{\pgfsys@miterjoin\ignorespaces}


% Set a bevel line join.
% 
% Example:
%
% \pgfsetbeveljoin

\def\pgfsetbeveljoin{\pgfsys@beveljoin\ignorespaces}


% Set a round line join.
% 
% Example:
%
% \pgfsetroundjoin

\def\pgfsetroundjoin{\pgfsys@roundjoin\ignorespaces}


% Sets the even-odd rule for filling and clipping.
% 
% Example:
%
% \pgfseteorule

\def\pgfseteorule{\pgfsys@eoruletrue\ignorespaces}


% Sets the non-zero winding number rule for filling and clipping.
% 
% Example:
%
% \pgfsetnonzerorule

\def\pgfsetnonzerorule{\pgfsys@eorulefalse\ignorespaces}


% Sets the opacity of stroking operations.
% 
% #1 = opacity, where 1 means fully opaque and 0 means fully
% transparent. 
%
% Example:
%
% \pgfsetstrokeopacity{0.5}

\def\pgfsetstrokeopacity#1{%
  \edef\pgf@temp{{#1}}%
  \expandafter\pgfsys@stroke@opacity\pgf@temp}


% Sets the opacity of stroking operations.
% 
% #1 = opacity, where 1 means fully opaque and 0 means fully
% transparent. 
%
% Example:
%
% \pgfsetfillopacity{0.5}

\def\pgfsetfillopacity#1{%
  \edef\pgf@temp{{#1}}%
  \expandafter\pgfsys@fill@opacity\pgf@temp}



\endinput

pgfcoremath.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoremath.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


% Mathematical stuff


% Internal registers
\newcounter{pgf@counta}
\newcounter{pgf@countb}
\newcounter{pgf@countc}
\newcounter{pgf@countd}

% Internal setting function
\def\pgf@setmath#1#2{\edef\pgf@temp{#2pt}\csname pgf@#1\endcsname=\pgf@temp}


% Calculate sin of a degree
%
% #1 = degree
%
% x  = sin of #1
%
% Example:
%
% \pgfsin{30}

\def\pgfsin#1{%
  \pgf@setcounter{pgf@counta}{#1}\relax%
  \c@pgf@countb=90%
  \advance\c@pgf@countb by-\c@pgf@counta%
  \ifnum\c@pgf@countb>179%
  \advance\c@pgf@countb by-360%
  \else%
  \ifnum\c@pgf@countb<-179%
  \advance\c@pgf@countb by360%
  \fi\fi%
  \ifnum\c@pgf@countb<0\relax%
  \c@pgf@countb=-\c@pgf@countb%
  \fi%
  \pgf@setmath{x}{\csname pgf@cos\the\c@pgf@countb\endcsname}}


% Calculate cos of a degree
%
% #1 = degree
%
% x  = cos of #1
%
% Example:
%
% \pgfcos{30}

\def\pgfcos#1{%
  \pgf@setcounter{pgf@counta}{#1}%
  \ifnum\c@pgf@counta>179%
  \advance\c@pgf@counta by-360%
  \else%
  \ifnum\c@pgf@counta<-179%
  \advance\c@pgf@counta by360%
  \fi\fi%
  \ifnum\c@pgf@counta<0\relax%
  \c@pgf@counta=-\c@pgf@counta%
  \fi%
  \pgf@setmath{x}{\csname pgf@cos\the\c@pgf@counta\endcsname}}



% Calculate sin and cos of a degree
%
% #1 = degree
%
% x  = cos of #1
% y  = sin of #1
%
% Example:
%
% \pgfcos{30}

\def\pgfsincos#1{%
  \pgf@setcounter{pgf@counta}{#1}%
  \ifnum\c@pgf@counta>179%
  \advance\c@pgf@counta by-360%
  \else%
  \ifnum\c@pgf@counta<-179%
  \advance\c@pgf@counta by360%
  \fi\fi\relax%
  \c@pgf@countb=\c@pgf@counta\relax%
  \ifnum\c@pgf@counta<0\relax%
  \c@pgf@counta=-\c@pgf@counta%
  \fi\relax%
  \pgf@setmath{y}{\csname pgf@cos\the\c@pgf@counta\endcsname}%
  \c@pgf@counta=90%
  \advance\c@pgf@counta by-\c@pgf@countb\relax%
  \ifnum\c@pgf@counta>179%
  \advance\c@pgf@counta by-360%
  \else%
  \ifnum\c@pgf@counta<-179%
  \advance\c@pgf@counta by360%
  \fi\fi\relax%
  \ifnum\c@pgf@counta<0\relax%
  \c@pgf@counta=-\c@pgf@counta%
  \fi\relax%
  \pgf@setmath{x}{\csname pgf@cos\the\c@pgf@counta\endcsname}}


% Internal tables

\def\pgf@def#1#2#3{\expandafter\def\csname pgf@#1#2\endcsname{#3}}
\pgf@def{cos}{0}{1}           \pgf@def{cos}{1}{0.999848}
\pgf@def{cos}{2}{0.999391}    \pgf@def{cos}{3}{0.99863}
\pgf@def{cos}{4}{0.997564}    \pgf@def{cos}{5}{0.996195}
\pgf@def{cos}{6}{0.994522}    \pgf@def{cos}{7}{0.992546}
\pgf@def{cos}{8}{0.990268}    \pgf@def{cos}{9}{0.987688}
\pgf@def{cos}{10}{0.984808}   \pgf@def{cos}{11}{0.981627}
\pgf@def{cos}{12}{0.978148}   \pgf@def{cos}{13}{0.97437}
\pgf@def{cos}{14}{0.970296}   \pgf@def{cos}{15}{0.965926}
\pgf@def{cos}{16}{0.961262}   \pgf@def{cos}{17}{0.956305}
\pgf@def{cos}{18}{0.951057}   \pgf@def{cos}{19}{0.945519}
\pgf@def{cos}{20}{0.939693}   \pgf@def{cos}{21}{0.93358}
\pgf@def{cos}{22}{0.927184}   \pgf@def{cos}{23}{0.920505}
\pgf@def{cos}{24}{0.913545}   \pgf@def{cos}{25}{0.906308}
\pgf@def{cos}{26}{0.898794}   \pgf@def{cos}{27}{0.891007}
\pgf@def{cos}{28}{0.882948}   \pgf@def{cos}{29}{0.87462}
\pgf@def{cos}{30}{0.866025}   \pgf@def{cos}{31}{0.857167}
\pgf@def{cos}{32}{0.848048}   \pgf@def{cos}{33}{0.838671}
\pgf@def{cos}{34}{0.829038}   \pgf@def{cos}{35}{0.819152}
\pgf@def{cos}{36}{0.809017}   \pgf@def{cos}{37}{0.798636}
\pgf@def{cos}{38}{0.788011}   \pgf@def{cos}{39}{0.777146}
\pgf@def{cos}{40}{0.766044}   \pgf@def{cos}{41}{0.75471}
\pgf@def{cos}{42}{0.743145}   \pgf@def{cos}{43}{0.731354}
\pgf@def{cos}{44}{0.71934}    \pgf@def{cos}{45}{0.707107}
\pgf@def{cos}{46}{0.694658}   \pgf@def{cos}{47}{0.681998}
\pgf@def{cos}{48}{0.669131}   \pgf@def{cos}{49}{0.656059}
\pgf@def{cos}{50}{0.642788}   \pgf@def{cos}{51}{0.62932}
\pgf@def{cos}{52}{0.615661}   \pgf@def{cos}{53}{0.601815}
\pgf@def{cos}{54}{0.587785}   \pgf@def{cos}{55}{0.573576}
\pgf@def{cos}{56}{0.559193}   \pgf@def{cos}{57}{0.544639}
\pgf@def{cos}{58}{0.529919}   \pgf@def{cos}{59}{0.515038}
\pgf@def{cos}{60}{0.5}        \pgf@def{cos}{61}{0.48481}
\pgf@def{cos}{62}{0.469472}   \pgf@def{cos}{63}{0.45399}
\pgf@def{cos}{64}{0.438371}   \pgf@def{cos}{65}{0.422618}
\pgf@def{cos}{66}{0.406737}   \pgf@def{cos}{67}{0.390731}
\pgf@def{cos}{68}{0.374607}   \pgf@def{cos}{69}{0.358368}
\pgf@def{cos}{70}{0.34202}    \pgf@def{cos}{71}{0.325568}
\pgf@def{cos}{72}{0.309017}   \pgf@def{cos}{73}{0.292372}
\pgf@def{cos}{74}{0.275637}   \pgf@def{cos}{75}{0.258819}
\pgf@def{cos}{76}{0.241922}   \pgf@def{cos}{77}{0.224951}
\pgf@def{cos}{78}{0.207912}   \pgf@def{cos}{79}{0.190809}
\pgf@def{cos}{80}{0.173648}   \pgf@def{cos}{81}{0.156434}
\pgf@def{cos}{82}{0.139173}   \pgf@def{cos}{83}{0.121869}
\pgf@def{cos}{84}{0.104528}   \pgf@def{cos}{85}{0.0871557}
\pgf@def{cos}{86}{0.0697565}  \pgf@def{cos}{87}{0.052336}
\pgf@def{cos}{88}{0.0348995}  \pgf@def{cos}{89}{0.0174524}
\pgf@def{cos}{90}{0}          \pgf@def{cos}{91}{-0.0174524}
\pgf@def{cos}{92}{-0.0348995} \pgf@def{cos}{93}{-0.052336}
\pgf@def{cos}{94}{-0.0697565} \pgf@def{cos}{95}{-0.0871557}
\pgf@def{cos}{96}{-0.104528}  \pgf@def{cos}{97}{-0.121869}
\pgf@def{cos}{98}{-0.139173}  \pgf@def{cos}{99}{-0.156434}
\pgf@def{cos}{100}{-0.173648} \pgf@def{cos}{101}{-0.190809}
\pgf@def{cos}{102}{-0.207912} \pgf@def{cos}{103}{-0.224951}
\pgf@def{cos}{104}{-0.241922} \pgf@def{cos}{105}{-0.258819}
\pgf@def{cos}{106}{-0.275637} \pgf@def{cos}{107}{-0.292372}
\pgf@def{cos}{108}{-0.309017} \pgf@def{cos}{109}{-0.325568}
\pgf@def{cos}{110}{-0.34202}  \pgf@def{cos}{111}{-0.358368}
\pgf@def{cos}{112}{-0.374607} \pgf@def{cos}{113}{-0.390731}
\pgf@def{cos}{114}{-0.406737} \pgf@def{cos}{115}{-0.422618}
\pgf@def{cos}{116}{-0.438371} \pgf@def{cos}{117}{-0.45399}
\pgf@def{cos}{118}{-0.469472} \pgf@def{cos}{119}{-0.48481}
\pgf@def{cos}{120}{-0.5}      \pgf@def{cos}{121}{-0.515038}
\pgf@def{cos}{122}{-0.529919} \pgf@def{cos}{123}{-0.544639}
\pgf@def{cos}{124}{-0.559193} \pgf@def{cos}{125}{-0.573576}
\pgf@def{cos}{126}{-0.587785} \pgf@def{cos}{127}{-0.601815}
\pgf@def{cos}{128}{-0.615661} \pgf@def{cos}{129}{-0.62932}
\pgf@def{cos}{130}{-0.642788} \pgf@def{cos}{131}{-0.656059}
\pgf@def{cos}{132}{-0.669131} \pgf@def{cos}{133}{-0.681998}
\pgf@def{cos}{134}{-0.694658} \pgf@def{cos}{135}{-0.707107}
\pgf@def{cos}{136}{-0.71934}  \pgf@def{cos}{137}{-0.731354}
\pgf@def{cos}{138}{-0.743145} \pgf@def{cos}{139}{-0.75471}
\pgf@def{cos}{140}{-0.766044} \pgf@def{cos}{141}{-0.777146}
\pgf@def{cos}{142}{-0.788011} \pgf@def{cos}{143}{-0.798636}
\pgf@def{cos}{144}{-0.809017} \pgf@def{cos}{145}{-0.819152}
\pgf@def{cos}{146}{-0.829038} \pgf@def{cos}{147}{-0.838671}
\pgf@def{cos}{148}{-0.848048} \pgf@def{cos}{149}{-0.857167}
\pgf@def{cos}{150}{-0.866025} \pgf@def{cos}{151}{-0.87462}
\pgf@def{cos}{152}{-0.882948} \pgf@def{cos}{153}{-0.891007}
\pgf@def{cos}{154}{-0.898794} \pgf@def{cos}{155}{-0.906308}
\pgf@def{cos}{156}{-0.913545} \pgf@def{cos}{157}{-0.920505}
\pgf@def{cos}{158}{-0.927184} \pgf@def{cos}{159}{-0.93358}
\pgf@def{cos}{160}{-0.939693} \pgf@def{cos}{161}{-0.945519}
\pgf@def{cos}{162}{-0.951057} \pgf@def{cos}{163}{-0.956305}
\pgf@def{cos}{164}{-0.961262} \pgf@def{cos}{165}{-0.965926}
\pgf@def{cos}{166}{-0.970296} \pgf@def{cos}{167}{-0.97437}
\pgf@def{cos}{168}{-0.978148} \pgf@def{cos}{169}{-0.981627}
\pgf@def{cos}{170}{-0.984808} \pgf@def{cos}{171}{-0.987688}
\pgf@def{cos}{172}{-0.990268} \pgf@def{cos}{173}{-0.992546}
\pgf@def{cos}{174}{-0.994522} \pgf@def{cos}{175}{-0.996195}
\pgf@def{cos}{176}{-0.997564} \pgf@def{cos}{177}{-0.99863}
\pgf@def{cos}{178}{-0.999391} \pgf@def{cos}{179}{-0.999848}
\pgf@def{cos}{180}{-1}



\pgf@def{cosfrac}{0}{1}
\pgf@def{cosfrac}{1}{0.99995}    \pgf@def{cosfrac}{2}{0.9998}
\pgf@def{cosfrac}{3}{0.99955}    \pgf@def{cosfrac}{4}{0.999201}
\pgf@def{cosfrac}{5}{0.998752}   \pgf@def{cosfrac}{6}{0.998205}
\pgf@def{cosfrac}{7}{0.997559}   \pgf@def{cosfrac}{8}{0.996815}
\pgf@def{cosfrac}{9}{0.995974}   \pgf@def{cosfrac}{10}{0.995037}
\pgf@def{cosfrac}{11}{0.994004}  \pgf@def{cosfrac}{12}{0.992877}
\pgf@def{cosfrac}{13}{0.991656}  \pgf@def{cosfrac}{14}{0.990342}
\pgf@def{cosfrac}{15}{0.988936}  \pgf@def{cosfrac}{16}{0.987441}
\pgf@def{cosfrac}{17}{0.985856}  \pgf@def{cosfrac}{18}{0.984183}
\pgf@def{cosfrac}{19}{0.982424}  \pgf@def{cosfrac}{20}{0.980581}
\pgf@def{cosfrac}{21}{0.978653}  \pgf@def{cosfrac}{22}{0.976644}
\pgf@def{cosfrac}{23}{0.974555}  \pgf@def{cosfrac}{24}{0.972387}
\pgf@def{cosfrac}{25}{0.970143}  \pgf@def{cosfrac}{26}{0.967823}
\pgf@def{cosfrac}{27}{0.965429}  \pgf@def{cosfrac}{28}{0.962964}
\pgf@def{cosfrac}{29}{0.960429}  \pgf@def{cosfrac}{30}{0.957826}
\pgf@def{cosfrac}{31}{0.955157}  \pgf@def{cosfrac}{32}{0.952424}
\pgf@def{cosfrac}{33}{0.949629}  \pgf@def{cosfrac}{34}{0.946773}
\pgf@def{cosfrac}{35}{0.943858}  \pgf@def{cosfrac}{36}{0.940887}
\pgf@def{cosfrac}{37}{0.937862}  \pgf@def{cosfrac}{38}{0.934784}
\pgf@def{cosfrac}{39}{0.931655}  \pgf@def{cosfrac}{40}{0.928477}
\pgf@def{cosfrac}{41}{0.925252}  \pgf@def{cosfrac}{42}{0.921982}
\pgf@def{cosfrac}{43}{0.918669}  \pgf@def{cosfrac}{44}{0.915315}
\pgf@def{cosfrac}{45}{0.911922}  \pgf@def{cosfrac}{46}{0.90849}
\pgf@def{cosfrac}{47}{0.905024}  \pgf@def{cosfrac}{48}{0.901523}
\pgf@def{cosfrac}{49}{0.89799}   \pgf@def{cosfrac}{50}{0.894427}
\pgf@def{cosfrac}{51}{0.890835}  \pgf@def{cosfrac}{52}{0.887217}
\pgf@def{cosfrac}{53}{0.883573}  \pgf@def{cosfrac}{54}{0.879905}
\pgf@def{cosfrac}{55}{0.876216}  \pgf@def{cosfrac}{56}{0.872506}
\pgf@def{cosfrac}{57}{0.868777}  \pgf@def{cosfrac}{58}{0.865031}
\pgf@def{cosfrac}{59}{0.861269}  \pgf@def{cosfrac}{60}{0.857493}
\pgf@def{cosfrac}{61}{0.853704}  \pgf@def{cosfrac}{62}{0.849903}
\pgf@def{cosfrac}{63}{0.846092}  \pgf@def{cosfrac}{64}{0.842271}
\pgf@def{cosfrac}{65}{0.838444}  \pgf@def{cosfrac}{66}{0.834609}
\pgf@def{cosfrac}{67}{0.83077}   \pgf@def{cosfrac}{68}{0.826927}
\pgf@def{cosfrac}{69}{0.82308}   \pgf@def{cosfrac}{70}{0.819232}
\pgf@def{cosfrac}{71}{0.815383}  \pgf@def{cosfrac}{72}{0.811534}
\pgf@def{cosfrac}{73}{0.807687}  \pgf@def{cosfrac}{74}{0.803842}
\pgf@def{cosfrac}{75}{0.8}       \pgf@def{cosfrac}{76}{0.796162}
\pgf@def{cosfrac}{77}{0.792329}  \pgf@def{cosfrac}{78}{0.788502}
\pgf@def{cosfrac}{79}{0.784682}  \pgf@def{cosfrac}{80}{0.780869}
\pgf@def{cosfrac}{81}{0.777064}  \pgf@def{cosfrac}{82}{0.773268}
\pgf@def{cosfrac}{83}{0.769481}  \pgf@def{cosfrac}{84}{0.765705}
\pgf@def{cosfrac}{85}{0.761939}  \pgf@def{cosfrac}{86}{0.758185}
\pgf@def{cosfrac}{87}{0.754443}  \pgf@def{cosfrac}{88}{0.750714}
\pgf@def{cosfrac}{89}{0.746997}  \pgf@def{cosfrac}{90}{0.743294}
\pgf@def{cosfrac}{91}{0.739605}  \pgf@def{cosfrac}{92}{0.735931}
\pgf@def{cosfrac}{93}{0.732272}  \pgf@def{cosfrac}{94}{0.728628}
\pgf@def{cosfrac}{95}{0.724999}  \pgf@def{cosfrac}{96}{0.721387}
\pgf@def{cosfrac}{97}{0.717792}  \pgf@def{cosfrac}{98}{0.714213}
\pgf@def{cosfrac}{99}{0.710651}  \pgf@def{cosfrac}{100}{0.707107}



\endinput

pgfcoreobjects.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoreobjects.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


% Object reuse


% Define a pgf object for reuse. Such objects will be stored
% efficiently internally.
%
% #1 = name for later reuse
% #2 = lower left corner point of bounding box
% #3 = upper right left corner point of bounding box
% #4 = pure pgf code (nothing too fancy!)
%
% Description:
% 
% Used to define reusable objects. The object must be composed of
% basic pgf graphic primitives. Nothing fancy can be used. The
% created object will be stored as an xform object in pdf or as a
% postscript procedure in postscript.
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfpathqmoveto{0pt}{0pt}
%  \pgfpathqmoveto{10pt}{0pt}
%  \pgfpathqmoveto{10pt}{10pt}
%  \pgfpathqmoveto{0pt}{10pt}
%  \pgfpathclose
%  \pgfusepath{stroke}}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgfuseobject{myrect}
% \end{pgfpicture}

\def\pgfdefobject#1#2#3#4{%
  \pgfinterruptpath%
    \pgf@relevantforpicturesizefalse%
    \pgfsys@defobject{#1}{#2}{#3}{#4}%
  \endpgfinterruptpath%
  \ignorespaces%
}


% Use an object that was previously defined using pgfdefobject
%
% #1 = name of previously defined object
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfqmoveto{0}{0}
%  \pgfqmoveto{10}{0}
%  \pgfqmoveto{10}{10}
%  \pgfqmoveto{0}{10}
%  \pgfclosestroke}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgfuseobject{myrect}
% \end{pgfpicture}

\def\pgfuseobject#1{\pgfsys@beginscope\pgfsys@useobject{#1}{}\pgfsys@endscope}


% Use an object that was previously defined using pgfdefobject, but
% magnify the object by the current x and y register values
%
% #1 = name of previously defined object
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfqmoveto{0}{0}
%  \pgfqmoveto{10}{0}
%  \pgfqmoveto{10}{10}
%  \pgfqmoveto{0}{10}
%  \pgfclosestroke}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgf@x=2pt% Scale by factor two in x-direction
%   \pgf@y=2pt% Scale by factor two in y-direction
%   \pgfuseobjectmagnify{myrect}
% \end{pgfpicture}

\def\pgfuseobjectmagnify#1{%
  \pgfsys@beginscope%
  \pgfsys@useobject{#1}{\pgfsys@transformxyscale{\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}}%
  \pgfsys@endscope%
}


\endinput

pgfcorepathconstruct.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex,v 1.1 2005/10/25 08:18:14 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

\newdimen\pgf@path@lastx
\newdimen\pgf@path@lasty



% Replace corners by arcs.
%
% #1 = in-size of arc
% #2 = out-size of arc
% 
% Description:
% 
% This command influences path construction command like
% \pgfpathlineto or \pgfpatharc. It will cause the corners at the end
% of these commands to be replaced by little arcs. If the
% corner is a 90 degrees corner and if #1=#2, a quarter-circle of
% radius #1 is put in place of the corner. If #1 and #2 are different,
% the quarter circle will instead by a quarter ellipse. If the angle
% is different from 90 degrees, a deformed quarter circle will
% result, which may or may not be desirable. For a ``perfect'' arc you
% must use the \pgfpatharc command. 
% 
% 
% Example: One rounded corner.
%
% \pgfpathmoveto{\pgfpointxy{0}{0}}
% \pgfsetcornersarced{4pt}{4pt}
% \pgfpathlineto{\pgfpointxy{0}{1}}
% \pgfpathlineto{\pgfpointxy{1}{1}}
% \pgfstroke
%
% Example: A rounded rectangle
%
% \pgfsetcornersarced{4pt}{4pt}
% \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
% \pgfstroke
%
% Example: A rounded triangles
%
% \pgfsetcornersarced{4pt}{4pt}
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathlineto{\pgfpoint{1cm}{0cm}}
% \pgfpathlineto{\pgfpoint{1cm}{1cm}}
% \pgfpathclose
% \pgfstroke

\newif\ifpgf@arccorners

\def\pgfsetcornersarced#1{%
  \pgf@process{#1}%
  \edef\pgf@corner@arc{{\the\pgf@x}{\the\pgf@y}}%
  \pgf@arccornerstrue%
  \ifdim\pgf@x=0pt%
    \ifdim\pgf@y=0pt\relax%
      \pgf@arccornersfalse%
    \fi%
  \fi%
}

\def\pgf@roundcornerifneeded{%
  \ifpgf@arccorners\expandafter\pgfsyssoftpath@specialround\pgf@corner@arc\fi%
}


% Move current point to #1.
%
% #1 = new current point
% 
% Example:
%
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpathlineto{\pgfxy(0,1)}
% \pgfstroke

\def\pgfpathmoveto#1{%
  \pgfpointtransformed{#1}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgfsyssoftpath@moveto{\the\pgf@x}{\the\pgf@y}%
  \global\pgf@path@lastx=\pgf@x%
  \global\pgf@path@lasty=\pgf@y%
}

\def\pgf@protocolsizes#1#2{%
  \ifpgf@relevantforpicturesize%
    \ifdim#1<\pgf@picminx\global\pgf@picminx#1\fi%
    \ifdim#1>\pgf@picmaxx\global\pgf@picmaxx#1\fi%
    \ifdim#2<\pgf@picminy\global\pgf@picminy#2\fi%
    \ifdim#2>\pgf@picmaxy\global\pgf@picmaxy#2\fi%
  \fi%
  \ifdim#1<\pgf@pathminx\global\pgf@pathminx#1\fi%
  \ifdim#1>\pgf@pathmaxx\global\pgf@pathmaxx#1\fi%
  \ifdim#2<\pgf@pathminy\global\pgf@pathminy#2\fi%
  \ifdim#2>\pgf@pathmaxy\global\pgf@pathmaxy#2\fi%
}


\def\pgf@resetpathsizes{%
  \global\pgf@pathmaxx=-16000pt\relax%
  \global\pgf@pathminx=16000pt\relax%
  \global\pgf@pathmaxy=-16000pt\relax%
  \global\pgf@pathminy=16000pt\relax%
}

\def\pgf@getpathsizes#1{%
  \edef#1{{\the\pgf@pathmaxx}{\the\pgf@pathminx}{\the\pgf@pathmaxy}{\the\pgf@pathminy}}%
}
\def\pgf@setpathsizes#1{%
  \expandafter\pgf@@setpathsizes#1%
}
\def\pgf@@setpathsizes#1#2#3#4{%
  \global\pgf@pathmaxx=#1\relax%
  \global\pgf@pathminx=#2\relax%
  \global\pgf@pathmaxy=#3\relax%
  \global\pgf@pathminy=#4\relax%
}





% Append a line from the current point to #1 to the current path.
%
% #1 = end of line
% 
% Example:
%
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpathlineto{\pgfxy(0,1)}
% \pgfstroke

\def\pgfpathlineto#1{%
  \pgfpointtransformed{#1}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@roundcornerifneeded%
  \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%
  \global\pgf@path@lastx=\pgf@x%
  \global\pgf@path@lasty=\pgf@y%
}



% Close the current path.
%
% Example:
%
% % Draws two triangles
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpathlineto{\pgfxy(0,1)}
% \pgfpathlineto{\pgfxy(1,0)}
% \pgfclosepath
% \pgfpathmoveto{\pgfxy(2,0)}
% \pgfpathlineto{\pgfxy(2,1)}
% \pgfpathlineto{\pgfxy(3,0)}
% \pgfpathclose
% \pgfstroke

\def\pgfpathclose{%
  \pgf@roundcornerifneeded%
  \pgfsyssoftpath@closepath%
}


% Append a bezier spline from the current point to #3 with control
% points #1 and #2 to the current path.
%
% #1 = first control point
% #2 = second control point
% #3 = end point
% 
% Example:
%
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpathcurveto{\pgfxy(0,1)}{\pgfxy(1,1)}{\pgfxy(1,2)}
% \pgfstroke

\def\pgfpathcurveto#1#2#3{%
  \pgfpointtransformed{#3}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgfpointtransformed{#2}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgfpointtransformed{#1}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@roundcornerifneeded%
  \pgfsyssoftpath@curveto{\the\pgf@x}{\the\pgf@y}{\the\pgf@xa}{\the\pgf@ya}{\the\pgf@xb}{\the\pgf@yb}%
  \global\pgf@path@lastx=\pgf@xb%
  \global\pgf@path@lasty=\pgf@yb%
}

% Append an arc to the current point, where the current point is at
% angle #1 and the end is at angle #2. If #2 > #1, the arc is drawn
% counter-clockwise, otherwise it is clockwise.
%
% #1 = angle of first point
% #2 = angle of second point
% #3 = radius or x-radius/y-radius
% 
% Example:
%
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpatharc{0}{90}{2cm}
% \pgfstroke

\def\pgfpatharc#1#2#3{%
  \pgf@setcounter{pgf@countc}{#1}%
  \pgf@setcounter{pgf@countd}{#2}%
  \ifnum\c@pgf@countc>360\relax%
    \advance\c@pgf@countc by-360\relax%
  \fi%
  \ifnum\c@pgf@countc<-360\relax%
    \advance\c@pgf@countc by360\relax%
  \fi%
  \ifnum\c@pgf@countd>360\relax%
    \advance\c@pgf@countd by-360\relax%
  \fi%
  \ifnum\c@pgf@countd<-360\relax%
    \advance\c@pgf@countd by360\relax%
  \fi%
  \loop%
    \@tempcnta=\c@pgf@countc\relax%
    \advance\@tempcnta by-\c@pgf@countd\relax%
    \ifnum\@tempcnta<0\relax%
      \@tempcnta=-\@tempcnta\relax%
    \fi%
  \ifnum\@tempcnta>90\relax%
    \ifnum\c@pgf@countd>\c@pgf@countc\relax%
      \@tempcnta=\c@pgf@countc\relax%
      \advance\@tempcnta by 90\relax%
      \expandafter\pgf@arc\expandafter{\expandafter\c@pgf@countc\expandafter}\expandafter{\the\@tempcnta}{#3}%
      \advance\c@pgf@countc by 90\relax%
    \else
      \@tempcnta=\c@pgf@countc\relax%
      \advance\@tempcnta by -90\relax%
      \expandafter\pgf@arc\expandafter{\expandafter\c@pgf@countc\expandafter}\expandafter{\the\@tempcnta}{#3}%
      \advance\c@pgf@countc by -90\relax%
    \fi%
  \repeat%
  \pgf@roundcornerifneeded%
  \pgf@arc{\c@pgf@countc}{\c@pgf@countd}{#3}%
}

\def\pgf@arc#1#2#3{%
  \in@/{#3}%
  \ifin@%
    \pgf@@arc{#1}{#2}#3\@@%
  \else
    \pgf@@arc{#1}{#2}#3/#3\@@%
  \fi%
}

\def\pgf@@arc#1#2#3/#4\@@{%
  \setlength{\@tempdima}{#3}%
  \setlength{\@tempdimb}{#4}%
  \@tempcnta=#1\relax%
  \@tempcntb=#2\relax%
  \advance\@tempcntb by-\@tempcnta\relax%
  \ifnum\@tempcntb<0\relax%
    \@tempcntb=-\@tempcntb\relax%
  \fi%
  \ifnum\@tempcntb>85\relax% hackery to correct the control points
    \@tempdima=0.0555\@tempdima\relax%
    \@tempdimb=0.0555\@tempdimb\relax%
  \else%
    \ifnum\@tempcntb>75\relax%  
      \@tempdima=0.055\@tempdima\relax%
      \@tempdimb=0.055\@tempdimb\relax%
    \else%
      \ifnum\@tempcntb>60\relax%  
        \@tempdima=0.0545\@tempdima\relax%
        \@tempdimb=0.0545\@tempdimb\relax%
      \else%
        \@tempdima=0.054\@tempdima\relax%
        \@tempdimb=0.054\@tempdimb\relax%
      \fi%
    \fi%
  \fi
  \@tempdima=\@tempcntb\@tempdima\relax%
  \divide\@tempdima by 9\relax%
  \@tempdimb=\@tempcntb\@tempdimb\relax%
  \divide\@tempdimb by 9\relax%
  %.. controls +(\@tempcnta+90:\@tempdima) and +(\@tempcntb-90:\@tempdima) .. +(-(#1:#3)+(#2:#3))%
  % store first support vector in xa/ya:
  \@tempcnta=#1\relax%
  \ifnum#2>#1\relax%
    \advance\@tempcnta by 90\relax%
  \else%
    \advance\@tempcnta by -90\relax%
  \fi%
  \pgfpointtransformed{\pgfpointpolar{\@tempcnta}{\@tempdima/\@tempdimb}}%
  \advance\pgf@x by-\pgf@pt@x%
  \advance\pgf@y by-\pgf@pt@y%
  \pgf@xa=\pgf@path@lastx%
  \pgf@ya=\pgf@path@lasty%
  \advance\pgf@xa by \pgf@x%
  \advance\pgf@ya by \pgf@y%
  % store target in xb/yb:
  \@tempcnta=#1\relax%
  \pgfpointtransformed{\pgfpointpolar{\@tempcnta}{#3/#4}}%
  \pgf@xb=\pgf@path@lastx%
  \pgf@yb=\pgf@path@lasty%
  \advance\pgf@xb by -\pgf@x%
  \advance\pgf@yb by -\pgf@y%
  \@tempcnta=#2\relax%
  \pgfpointtransformed{\pgfpointpolar{\@tempcnta}{#3/#4}}%
  \advance\pgf@xb by \pgf@x%
  \advance\pgf@yb by \pgf@y%
  % store second support xc/yc:
  \@tempcnta=#2\relax%
  \ifnum#2>#1\relax%
    \advance\@tempcnta by -90\relax%
  \else%
    \advance\@tempcnta by 90\relax%
  \fi%
  \pgfpointtransformed{\pgfpointpolar{\@tempcnta}{\@tempdima/\@tempdimb}}%
  \advance\pgf@x by-\pgf@pt@x%
  \advance\pgf@y by-\pgf@pt@y%
  \pgf@xc=\pgf@xb\relax%
  \pgf@yc=\pgf@yb\relax%
  \advance \pgf@xc by \pgf@x\relax%
  \advance \pgf@yc by \pgf@y\relax%
  \pgfsyssoftpath@curveto{\the\pgf@xa}{\the\pgf@ya}{\the\pgf@xc}{\the\pgf@yc}{\the\pgf@xb}{\the\pgf@yb}%
  \global\pgf@path@lastx=\pgf@xb%
  \global\pgf@path@lasty=\pgf@yb%
  \pgf@protocolsizes{\pgf@xa}{\pgf@ya}%
  \pgf@protocolsizes{\pgf@xb}{\pgf@yb}%
  \pgf@protocolsizes{\pgf@xc}{\pgf@yc}%
}

% Append  an ellipse to the current path.
%
% #1 = center
% #2 = first axis
% #3 = second axis
%  
% Example:
%
% % Add a circle of radius 3cm around the origin
% \pgfpathellipse{\pgforigin}{\pgfxy(2,0)}{\pgfxy(0,1)}
%
% % Draw a non-filled circle of radius 1cm around the point (1,1)
% \pgfpathellipse{\pgfxy(1,1)}{\pgfxy(1,1)}{\pgfxy(-2,2)}
% \pgfstroke

\def\pgfpathellipse#1#2#3{%
  \pgfpointtransformed{#1}% store center in xc/yc
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \pgfpointtransformed{#2}%
  \pgf@xa=\pgf@x% store first axis in xa/ya
  \pgf@ya=\pgf@y%
  \advance\pgf@xa by-\pgf@pt@x%
  \advance\pgf@ya by-\pgf@pt@y%
  \pgfpointtransformed{#3}%
  \pgf@xb=\pgf@x% store second axis in xb/yb
  \pgf@yb=\pgf@y%
  \advance\pgf@xb by-\pgf@pt@x%
  \advance\pgf@yb by-\pgf@pt@y%
  {%
    \advance\pgf@xa by\pgf@xc%
    \advance\pgf@ya by\pgf@yc%
    \pgfsyssoftpath@moveto{\the\pgf@xa}{\the\pgf@ya}%
    \pgf@protocolsizes{\pgf@xa}{\pgf@ya}%
  }%
  \pgf@x=0.555\pgf@xb% first arc
  \pgf@y=0.555\pgf@yb%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya%
  \advance\pgf@x by\pgf@xc%
  \advance\pgf@y by\pgf@yc%
  \edef\pgf@temp{{\the\pgf@x}{\the\pgf@y}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@x=0.555\pgf@xa%
  \pgf@y=0.555\pgf@ya%
  \advance\pgf@x by\pgf@xb%
  \advance\pgf@y by\pgf@yb%
  {%
    \advance\pgf@x by\pgf@xc%
    \advance\pgf@y by\pgf@yc%
    \advance\pgf@xb by\pgf@xc%
    \advance\pgf@yb by\pgf@yc%    
    \expandafter\pgfsyssoftpath@curveto\pgf@temp{\the\pgf@x}{\the\pgf@y}{\the\pgf@xb}{\the\pgf@yb}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@xb}{\pgf@yb}%
  }%
  \pgf@xa=-\pgf@xa% flip first axis
  \pgf@ya=-\pgf@ya%
  \pgf@x=0.555\pgf@xa% second arc
  \pgf@y=0.555\pgf@ya%
  \advance\pgf@x by\pgf@xb%
  \advance\pgf@y by\pgf@yb%
  \advance\pgf@x by\pgf@xc%
  \advance\pgf@y by\pgf@yc%
  \edef\pgf@temp{{\the\pgf@x}{\the\pgf@y}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@x=0.555\pgf@xb%
  \pgf@y=0.555\pgf@yb%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya%
  {%
    \advance\pgf@x by\pgf@xc%
    \advance\pgf@y by\pgf@yc%
    \advance\pgf@xa by\pgf@xc%
    \advance\pgf@ya by\pgf@yc%    
    \expandafter\pgfsyssoftpath@curveto\pgf@temp{\the\pgf@x}{\the\pgf@y}{\the\pgf@xa}{\the\pgf@ya}%  
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@xa}{\pgf@ya}%
  }%
  \pgf@xb=-\pgf@xb% flip second axis
  \pgf@yb=-\pgf@yb%
  \pgf@x=0.555\pgf@xb% third arc
  \pgf@y=0.555\pgf@yb%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya%
  \advance\pgf@x by\pgf@xc%
  \advance\pgf@y by\pgf@yc%
  \edef\pgf@temp{{\the\pgf@x}{\the\pgf@y}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@x=0.555\pgf@xa%
  \pgf@y=0.555\pgf@ya%
  \advance\pgf@x by\pgf@xb%
  \advance\pgf@y by\pgf@yb%
  {%
    \advance\pgf@x by\pgf@xc%
    \advance\pgf@y by\pgf@yc%
    \advance\pgf@xb by\pgf@xc%
    \advance\pgf@yb by\pgf@yc%    
    \expandafter\pgfsyssoftpath@curveto\pgf@temp{\the\pgf@x}{\the\pgf@y}{\the\pgf@xb}{\the\pgf@yb}%  
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@xb}{\pgf@yb}%
  }%
  \pgf@xa=-\pgf@xa% flip first axis once more
  \pgf@ya=-\pgf@ya%
  \pgf@x=0.555\pgf@xa% fourth arc
  \pgf@y=0.555\pgf@ya%
  \advance\pgf@x by\pgf@xb%
  \advance\pgf@y by\pgf@yb%
  \advance\pgf@x by\pgf@xc%
  \advance\pgf@y by\pgf@yc%
  \edef\pgf@temp{{\the\pgf@x}{\the\pgf@y}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@x=0.555\pgf@xb%
  \pgf@y=0.555\pgf@yb%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya%
  {%
    \advance\pgf@x by\pgf@xc%
    \advance\pgf@y by\pgf@yc%
    \advance\pgf@xa by\pgf@xc%
    \advance\pgf@ya by\pgf@yc%    
    \expandafter\pgfsyssoftpath@curveto\pgf@temp{\the\pgf@x}{\the\pgf@y}{\the\pgf@xa}{\the\pgf@ya}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@xa}{\pgf@ya}%
  }%
  \pgfsyssoftpath@closepath%
  \pgfsyssoftpath@moveto{\the\pgf@xc}{\the\pgf@yc}%
}



% Append a circle to the current path
%
% #1 = center
% #2 = radius
%  
% Example:
%
% % Append a circle of radius 3cm around the the point (1,1)
% \pgfpathcircle{\pgxy(1,1)}{3cm}

\def\pgfpathcircle#1#2{\pgfpathellipse{#1}{\pgfpoint{#2}{0pt}}{\pgfpoint{0pt}{#2}}}



% Append a rectangle to the current path
%
% #1 = lower left corner point of rectangle
% #2 = width and height vector
%  
% Example:
%
% % A rectangle with corners (2,2) and (3,3)
% \pgfpathrectangle{\pgfpointxy{2}{2}}{\pgfpointxy{1}{1}}

\def\pgfpathrectangle{%
  \let\pgfrect@next=\pgf@specialrect%
  \ifpgf@pt@identity%
    \ifpgf@arccorners%
    \else%
      \let\pgfrect@next=\pgf@normalrect%
    \fi%
  \fi%
  \pgfrect@next%
}

\def\pgf@normalrect#1#2{%
  \pgf@process{#2}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgfpointtransformed{#1}%
  \pgfsyssoftpath@rect{\the\pgf@x}{\the\pgf@y}{\the\pgf@xa}{\the\pgf@ya}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \advance\pgf@x by\pgf@xa\relax%
  \advance\pgf@y by\pgf@ya\relax%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
}

\def\pgf@specialrect#1#2{%
  \pgf@process{#2}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#1}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \advance\pgf@xa by\pgf@xb%
  \advance\pgf@ya by\pgf@yb%
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}%
  \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}%
  \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}%
  \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}%
  \pgfpathclose%
  \pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@xb}}%
}

% Append a rectangle to the current path
%
% #1 = one corner of the rectangle
% #2 = opposite corner of the rectangle
%  
% Example:
%
% % A rectangle with corners (2,2) and (3,3)
% \pgfpathrectanglecorners{\pgfpointxy{2}{2}}{\pgfpointxy{3}{3}}

\def\pgfpathrectanglecorners#1#2{%
  \pgf@process{#2}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \pgf@process{#1}%
  \advance\pgf@xc by-\pgf@x%
  \advance\pgf@yc by-\pgf@y%
  \pgfpathrectangle{#1}{\pgfpoint{\pgf@xc}{\pgf@yc}}%
}


% Append a grid to the current path.
%
% #1 = lower left point of grid
% #2 = upper right point of grid
%  
% Options: 
%  
% stepx = x-step dimension (default 1cm)
% stepy = y-step dimension (default 1cm)
% step  = dimesion vector
%  
% Example:
%
% \pgfsetlinewidth{0.8pt}
% \pgfgrid{\pgfxy(0,0)}{\pgfxy(3,2)}
% \pgfsetlinewidth{0.4pt}
% \pgfgrid[stepx=1cm,stepy=1cm]{\pgfxy(0,0)}{\pgfxy(3,2)}

\define@key{pgfbase}{stepx}{\setlength{\pgf@x}{#1}\relax}
\define@key{pgfbase}{stepy}{\setlength{\pgf@y}{#1}\relax}
\define@key{pgfbase}{step}{\pgf@process{#1}}

\def\pgfpathgrid{\@ifnextchar[{\pgf@pathgrid}{\pgf@pathgrid[]}}
\def\pgf@pathgrid[#1]#2#3{%
  \setkeys{pgfbase}{stepx=1cm,stepy=1cm}%
  \setkeys{pgfbase}{#1}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \pgf@process{#3}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@process{#2}%
  \pgf@xa=\pgf@x\relax%
  \pgf@ya=\pgf@y\relax%
  {%
    % compute bounding box
    % first corner
    \pgf@x=\pgf@xb%
    \pgf@y=\pgf@yb%
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    % second corner
    \pgf@x=\pgf@xb%
    \pgf@y=\pgf@ya%
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    % third corner
    \pgf@x=\pgf@xa%
    \pgf@y=\pgf@yb%
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    % fourth corner
    \pgf@x=\pgf@xa%
    \pgf@y=\pgf@ya%
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  }%
  \c@pgf@counta=\pgf@y\relax%
  \c@pgf@countb=\pgf@yc\relax%
  \divide\c@pgf@counta by\c@pgf@countb\relax%
  \pgf@y=\c@pgf@counta\pgf@yc\relax%
  \ifdim\pgf@y<\pgf@ya%
    \advance\pgf@y by\pgf@yc%
  \fi%
  \loop% horizontal lines
    {%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@pos@transform{\pgf@xa}{\pgf@ya}
      \pgfsyssoftpath@moveto{\the\pgf@xa}{\the\pgf@ya}%
      \pgf@xa=\pgf@xb%
      \pgf@ya=\pgf@y%
      \pgf@pos@transform{\pgf@xa}{\pgf@ya}
      \pgfsyssoftpath@lineto{\the\pgf@xa}{\the\pgf@ya}%
    }%
    \advance\pgf@y by\pgf@yc%
  \ifdim\pgf@y<\pgf@yb%
  \repeat%
  \advance\pgf@y by-0.01pt\relax%
  \ifdim\pgf@y<\pgf@yb%
    {%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@pos@transform{\pgf@xa}{\pgf@ya}
      \pgfsyssoftpath@moveto{\the\pgf@xa}{\the\pgf@ya}%
      \pgf@xa=\pgf@xb%
      \pgf@ya=\pgf@y%
      \pgf@pos@transform{\pgf@xa}{\pgf@ya}
      \pgfsyssoftpath@lineto{\the\pgf@xa}{\the\pgf@ya}%
    }%
  \fi%
  \c@pgf@counta=\pgf@x\relax%
  \c@pgf@countb=\pgf@xc\relax%
  \divide\c@pgf@counta by\c@pgf@countb\relax%
  \pgf@x=\c@pgf@counta\pgf@xc\relax%
  \ifdim\pgf@x<\pgf@xa%
    \advance\pgf@x by\pgf@xc%
  \fi%
  \loop% vertical lines
    {%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@ya%
      \pgf@pos@transform{\pgf@xc}{\pgf@yc}
      \pgfsyssoftpath@moveto{\the\pgf@xc}{\the\pgf@yc}%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@yb%
      \pgf@pos@transform{\pgf@xc}{\pgf@yc}
      \pgfsyssoftpath@lineto{\the\pgf@xc}{\the\pgf@yc}%
    }%
    \advance\pgf@x by\pgf@xc%
  \ifdim\pgf@x<\pgf@xb%
  \repeat%
  \advance\pgf@x by-0.01pt\relax%
  \ifdim\pgf@x<\pgf@xb%
    {%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@ya%
      \pgf@pos@transform{\pgf@xc}{\pgf@yc}
      \pgfsyssoftpath@moveto{\the\pgf@xc}{\the\pgf@yc}%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@yb%
      \pgf@pos@transform{\pgf@xc}{\pgf@yc}
      \pgfsyssoftpath@lineto{\the\pgf@xc}{\the\pgf@yc}%
    }%
  \fi%
}



% Append two half-parabolas to the path
%
% #1 = bend (relative to current point)
% #2 = end point (relative to bend point)
%  
% Description:
%  
% This command appends a half-parabola that starts at the current point
% and has its bend at #1+current point. Then, a second parabola is
% appended that starts at #1+current point, where it also has its
% minimum/maximum, and ends at #1+current point+#2, which becomes the
% new current point. 
%  
% By setting #2 = (0,0) you draw only a half parabola that goes from the
% current point to the bend; by setting #1 = (0,0)
% you draw a half parabola that going to current point + #2 and has its
% bend at the current point. 
%  
% Examples:
%
% % Half-parabola going ``up and right''
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathparabola{\pgfpointorigin}{\pgfpoint{2cm}{4cm}}
%
% % Half-parabola going ``down and right''
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathparabola{\pgfpoint{-2cm}{4cm}}}{\pgfpointorigin}
%
% % Full parabola
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathparabola{\pgfpoint{-2cm}{4cm}}{\pgfpoint{2cm}{4cm}}

\def\pgfpathparabola#1#2{%
  {%
    \pgf@process{#2}% untransformed
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@process{#1}% untransformed
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \@tempswatrue%
    \ifdim\pgf@xb=0pt\relax%
      \ifdim\pgf@yb=0pt\relax%
        \@tempswafalse%
      \fi%
    \fi%  
    {%
      \if@tempswa%
        \pgf@arccornersfalse
      \else%
      \fi%
      \@tempswatrue%
      \ifdim\pgf@xc=0pt\relax%
        \ifdim\pgf@yc=0pt\relax%
          \@tempswafalse%
        \fi%
      \fi%
      \if@tempswa  
      {%
        \pgf@pt@x=\pgf@path@lastx%
        \pgf@pt@y=\pgf@path@lasty%
        \pgfpathcurveto%
          {\pgfpoint{.1125\pgf@xc}{.225\pgf@yc}}% found by trial and error
          {\pgfpoint{.5\pgf@xc}{\pgf@yc}}% found by trial and error
          {\pgfpoint{\pgf@xc}{\pgf@yc}}%
      }%
      \fi%
    }%
    \if@tempswa%
      \pgf@xc=\pgf@xb%
      \pgf@yc=\pgf@yb%
      {%
        \pgf@pt@x=\pgf@path@lastx%
        \pgf@pt@y=\pgf@path@lasty%
        \pgfpathcurveto%
          {\pgfpoint{.5\pgf@xc}{0\pgf@yc}}% found by trial and error
          {\pgfpoint{.8875\pgf@xc}{.775\pgf@yc}}% found by trial and error
          {\pgfpoint{\pgf@xc}{\pgf@yc}}%
      }%
    \fi%
  }%  
}  




% Append a sine curve between 0 and \pi/2 to the path.
%
% #1 = vector, describing the width and height of the curve
%  
% Description:
%  
% This command appends a sine curve in the interval 0 and \pi/2 to the
% current path. The sine curve ends at currentpoint+#1.
%  
% Examples:
%
% % One complete sine in the interval [0,\pi]
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathsine{\pgfpoint{1.57cm}{1cm}}
% \pgfpathcosine{\pgfpoint{3.141cm}{0cm}}

\def\pgfpathsine#1{%
  {%
    \pgf@process{#1}% untransformed
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@pt@x=\pgf@path@lastx% evil trickery to transform to the last point
    \pgf@pt@y=\pgf@path@lasty%
    \pgfpathcurveto%
      {\pgfpoint{.31830988618\pgf@xc}{.5\pgf@yc}}% found by trial and error
      {\pgfpoint{.63502822294\pgf@xc}{\pgf@yc}}% found by trial and error
      {\pgfpoint{\pgf@xc}{\pgf@yc}}%
  }%  
}  

% Append a cosine curve between 0 and \pi/2 to the path.
%
% #1 = vector, describing the width and height of the curve
%  
% Examples:
%
% % One complete sine in the interval [0,\pi]
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathsine{\pgfpoint{1.57cm}{1cm}}
% \pgfpathcosine{\pgfpoint{3.141cm}{0cm}}

\def\pgfpathcosine#1{%
  {%
    \pgf@process{#1}% untransformed
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@pt@x=\pgf@path@lastx% evil trickery to transform to the last point
    \pgf@pt@y=\pgf@path@lasty%
    \pgfpathcurveto%
      {\pgfpoint{.36497177706\pgf@xc}{0pt}}% found by trial and error
      {\pgfpoint{.68169011382\pgf@xc}{.5\pgf@yc}}% found by trial and error
      {\pgfpoint{\pgf@xc}{\pgf@yc}}%
  }%  
}  


\endinput

pgfcorepathprocessing.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorepathprocessing.code.tex,v 1.2 2005/10/03 15:52:27 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



% Cleanup path
%
% #1 = a macro name that stores a path
%
% Description:
%
% This command will remove superfluous parts from a path. Movetos with
% a moveto following are removed.
%
% Example:
%
% \pgfsyssoftpath@moveto{0}{0}
% \pgfsyssoftpath@moveto{10}{10}
% \pgfsyssoftpath@lineto{0}{0}
% \pgfsyssoftpath@getcurrentpath\mypath
% \pgfprocesspathcleanup\mypath

\def\pgfprocesspathcleanup#1{%
  {%
    \let\pgf@newpath=\@empty%
    \expandafter\pgf@cleanupprocessor#1\pgf@stop%
  }%
  \let#1=\pgf@newpath%
}

\def\pgf@cleanupprocessor#1{%
  \ifx#1\pgf@stop%
    \let\next=\@gobble% ok, done
  \else%
    \ifx#1\pgfsyssoftpath@movetotoken%
      \let\next=\pgf@cleanupmoveto%
    \else%
      \let\next=\pgf@cleanupredo%
    \fi%
  \fi%
  \next#1%
}

\def\pgf@cleanupredo#1#2#3{%
  \g@addto@macro\pgf@newpath{#1{#2}{#3}}%
  \pgf@cleanupprocessor%
}

\def\pgf@cleanupmoveto#1#2#3#4{%
  \ifx#4\pgfsyssoftpath@movetotoken%
    % Ok, skip
  \else%
    \g@addto@macro\pgf@newpath{#1{#2}{#3}}%
  \fi%
  \pgf@cleanupprocessor#4%
}



% Extract start and end vectors of a path
%
% #1 = a macro that stores a path
%
% Description:
%
% This command will extract the first and second coordinate on the
% path as well as the last and second-last. These coordinates will be
% put in the pgfpoint-macros \pgfpointfirstonpath,
% \pgfpointsecondonpath, \pgfpointsecondlastonpath, and
% \pgfpointlastonpath. If the path is empty, these macros are set to
% \pgfpointorigin. 
%
% Example:
%
% \pgfsyssoftpath@moveto{0}{0}
% \pgfsyssoftpath@lineto{10}{10}
% \pgfsyssoftpath@curveto{20}{20}{30}{30}{40}{40}
% \pgfsyssoftpath@getcurrentpath\mypath
% \pgfprocesspathextractpoints\mypath
% 
% % \pgfpointfirstonpath is now \pgfpoint{0}{0}
% % \pgfpointsecondonpath is now \pgfpoint{10bp}{10bp}
% % \pgfpointsecondlastonpath is now \pgfpoint{30bp}{30bp}
% % \pgfpointlastonpath is now \pgfpoint{40bp}{40bp}

\def\pgfprocesspathextractpoints#1{%
  \ifx#1\@empty%
    \let\pgfpointfirstonpath=\pgfpointorigin%
    \let\pgfpointsecondonpath=\pgfpointorigin%
    \let\pgfpointsecondlastonpath=\pgfpointorigin%
    \let\pgfpointlastonpath=\pgfpointorigin%
  \else%
    \expandafter\pgf@extractprocessorfirst#1\pgf@stop%
  \fi%
}

\def\pgf@extractprocessorfirst#1#2#3#4{%
  \def\pgfpointfirstonpath{\pgfpoint{#2}{#3}}%
  \ifx#4\pgf@stop%
    % pretty short path...
    \let\pgfpointsecondonpath=\pgfpointfirstonpath%
    \let\pgfpointsecondlastonpath=\pgfpointfirstonpath%
    \let\pgfpointlastonpath=\pgfpointfirstonpath%
    \let\next=\@gobble%
  \else
    \let\next=\pgf@extractprocessorsecond%
  \fi%
  \next#4%
}

\def\pgf@extractprocessorsecond#1{%
  \ifx#1\pgfsyssoftpath@movetotoken%
    % Reset things...
    \let\pgf@next=\pgf@extractprocessorfirst%
  \else%
    \let\pgf@next=\pgf@@extractprocessorsecond%
  \fi%
  \pgf@next#1%
}
\def\pgf@@extractprocessorsecond#1#2#3#4{%
  \def\pgfpointsecondonpath{\pgfpoint{#2}{#3}}%
  \let\pgfpointsecondlastonpath=\pgfpointfirstonpath%
  \let\pgfpointlastonpath=\pgfpointsecondonpath%
  \ifx#4\pgf@stop%
    % short path...
    \let\next=\@gobble%
  \else
    \let\next=\pgf@extractprocessorother%
  \fi%
  \next#4%
}

\def\pgf@extractprocessorother#1{%
  \ifx#1\pgfsyssoftpath@movetotoken%
    % Reset things...
    \let\pgf@next=\pgf@extractprocessorfirst%
  \else%
    \let\pgf@next=\pgf@@extractprocessorother%
  \fi%
  \pgf@next#1%
}
\def\pgf@@extractprocessorother#1#2#3#4{%
  \let\pgfpointsecondlastonpath=\pgfpointlastonpath%
  \def\pgfpointlastonpath{\pgfpoint{#2}{#3}}%
  \ifx#4\pgf@stop%
    % end!
    \let\next=\@gobble%
  \fi%
  \next#4%
}



% Check for closepath and rectangles
%
% #1 = a macro that stores a path
% #2 = command to be executed when a closepath or a rectangle is encountered
%
% Example:
%
% \pgfsyssoftpath@moveto{0}{0}
% \pgfsyssoftpath@lineto{10}{10}
% \pgfsyssoftpath@curveto{20}{20}{30}{30}{40}{40}
% \pgfsyssoftpath@getcurrentpath\mypath
% \pgfprocesscheckclosed{\mypath}{\pgf@drawarrowsfalse}

\def\pgfprocesscheckclosed#1#2{%
  {%
    \global\let\pgf@proc@todo=\relax%
    \let\pgfsyssoftpath@movetotoken=\@gobbletwo%
    \let\pgfsyssoftpath@linetotoken=\@gobbletwo%
    \let\pgfsyssoftpath@curvetosupportatoken=\@gobbletwo%
    \let\pgfsyssoftpath@curvetosupportbtoken=\@gobbletwo%
    \let\pgfsyssoftpath@curvetotoken=\@gobbletwo%
    \def\pgfsyssoftpath@rectcornertoken{\gdef\pgf@proc@todo{#2}\@gobbletwo}%
    \def\pgfsyssoftpath@rectsizetoken{\gdef\pgf@proc@todo{#2}\@gobbletwo}%
    \def\pgfsyssoftpath@closepathtoken{\gdef\pgf@proc@todo{#2}\@gobbletwo}%
    #1%
  }%
  \pgf@proc@todo%
}

  
% Resolve specialround
%
% #1 = a macro that stores a path
% #2 = a macro that stores the new path
%
% Description:
%
% Resolves all specialround tokens. When such a token is encountered,
% the objective is to replace the next corner by a rounded corner. 
%

\def\pgfprocessround#1#2{%
  % first, check whether #1 contains \pgfsyssoftpath@specialroundtoken.
  % if not, do quick assignment!
  \expandafter\pgf@processroundcheck\expandafter#1\expandafter#2#1\pgfsyssoftpath@specialroundtoken\pgf@stop%
}

\def\pgf@processroundcheck#1#2#3\pgfsyssoftpath@specialroundtoken#4\pgf@stop{%
  \def\pgf@test{#4}%
  \ifx\pgf@test\@empty%
    % ok, nothing to be done!
    \let#2=#1%
  \else%
    % very well...
    \pgf@@processround#1#2%
  \fi%
}


\def\pgf@@processround#1#2{%  
  \let\pgfprocess@newpath\@empty%
  \let\pgfprocess@moveto\@empty%
  \let\pgfprocess@firstto\@empty%
  \let\pgfprocess@segment\@empty%
  \pgf@xa=0pt%
  \pgf@ya=0pt%
  \expandafter\pgfprocess@round#1\pgf@stop{0pt}{0pt}%
  \expandafter\g@addto@macro\expandafter\pgfprocess@newpath\expandafter{\pgfprocess@moveto}%
  \expandafter\g@addto@macro\expandafter\pgfprocess@newpath\expandafter{\pgfprocess@segment}%
  \let#2=\pgfprocess@newpath%
}

\def\pgfprocess@round#1#2#3{%
  \ifx#1\pgf@stop%
    \let\next=\relax%
  \else%
    \ifx#1\pgfsyssoftpath@specialroundtoken%
      \def\pgfprocess@savex{#2}%
      \def\pgfprocess@savey{#3}%
      \let\next=\pgfprocess@specialround%
      \ifdim#2=0pt%
        \ifdim#3=0pt%
          \let\next=\pgfprocess@round% skip!
        \fi%
      \fi%
    \else%
      \ifx\pgfprocess@firstto\@empty%
        \def\pgfprocess@firstto{{#2}{#3}}%
      \fi%
      \pgf@xa=#2%
      \pgf@ya=#3%
      \ifx#1\pgfsyssoftpath@movetotoken%
        % ok, move old segment to newpath
        \expandafter\g@addto@macro\expandafter\pgfprocess@newpath\expandafter{\pgfprocess@moveto}%
        \expandafter\g@addto@macro\expandafter\pgfprocess@newpath\expandafter{\pgfprocess@segment}%
        \def\pgfprocess@moveto{#1{#2}{#3}}%
        \let\pgfprocess@firstto=\@empty%
        \let\pgfprocess@segment=\@empty%
      \else%
        \g@addto@macro\pgfprocess@segment{#1{#2}{#3}}%
      \fi%
      \let\next=\pgfprocess@round%
    \fi%
  \fi%
  \next%  
}

\def\pgfprocess@specialround#1#2#3{%
  \ifx\pgfprocess@firstto\@empty%
    \def\pgfprocess@firstto{{#2}{#3}}%
  \fi%
  \let\next=\pgfprocess@round% default: do nothing
  \ifx#1\pgfsyssoftpath@linetotoken%
    % Ok, round a lineto
    \let\next=\pgfprocess@specialroundcope%
  \else%
    \ifx#1\pgfsyssoftpath@curvetosupportatoken%
      % Ok, round a curveto. 
      \let\next=\pgfprocess@specialroundcurveto%
    \else%
      \ifx#1\pgfsyssoftpath@closepathtoken%
        % Ok, round a closepath (this is tricky...)
        \let\next=\pgfprocess@specialroundclose%
      \fi%
    \fi%
  \fi%
  \next#1{#2}{#3}%
}%

\def\pgfprocess@specialroundcope#1#2#3#4#5#6{%
  \let\next=\pgfprocess@round% do nothing by default
  \let\pgfprocess@continueafterrounding=\pgfprocess@round%
  \ifx#4\pgfsyssoftpath@linetotoken%
    % ok, let's get kicking...
    \pgf@xc=#5%
    \pgf@yc=#6%
    \let\next=\pgfprocess@@specialround%
  \else%
    \ifx#4\pgfsyssoftpath@curvetosupportatoken%  
      \pgf@xc=#5%
      \pgf@yc=#6%
      \let\next=\pgfprocess@@specialround%
    \else%
      \ifx#4\pgfsyssoftpath@closepathtoken%  
        \pgf@xc=#5%
        \pgf@yc=#6%
        \let\next=\pgfprocess@@specialround%
      \else
        \ifx#4\pgfsyssoftpath@specialroundtoken%  
          \let\next=\pgfprocess@@findrightcoordinates%
        \fi%
      \fi%
    \fi%
  \fi%
  \next#1{#2}{#3}#4{#5}{#6}%
}

\def\pgfprocess@@findrightcoordinates#1#2#3#4#5#6#7#8#9{%
  \pgf@xc=#8%
  \pgf@yc=#9%
  \pgfprocess@@specialround#1{#2}{#3}#4{#5}{#6}#7{#8}{#9}%
}

\def\pgfprocess@@specialround#1#2#3{%
  \g@addto@macro\pgfprocess@segment{#1}%
  % calculate start coordinate of the curve
  \pgf@xb=#2%
  \pgf@yb=#3%
  %
  \edef\pgf@marshal%
  {\noexpand\pgfpointlineatdistance{\pgfprocess@savex}%
    {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}%
    {\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}}%
  \pgf@process{\pgf@marshal}%
  \pgf@xa=\pgf@x% save start point of added curve
  \pgf@ya=\pgf@y%
  \edef\pgfprocess@addition{{\the\pgf@x}{\the\pgf@y}}%
  \expandafter\g@addto@macro\expandafter\pgfprocess@segment\expandafter{\pgfprocess@addition}%
  %
  % now add curve
  %
  \edef\pgf@marshal%
  {\noexpand\pgfpointlineatdistance{\pgfprocess@savey}%
    {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}%
    {\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}}%
  \pgf@process{\pgf@marshal}%
  \pgf@xc=\pgf@x% save end point of added curve
  \pgf@yc=\pgf@y%
  % calculate first support:
  {%
    \pgf@x=\pgf@xb%
    \pgf@y=\pgf@yb%
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \advance\pgf@xa by 0.555\pgf@x%
    \advance\pgf@ya by 0.555\pgf@y%
    \edef\pgfprocess@addition{\noexpand\pgfsyssoftpath@curvetosupportatoken{\the\pgf@xa}{\the\pgf@ya}}%
    \expandafter\g@addto@macro\expandafter\pgfprocess@segment\expandafter{\pgfprocess@addition}%
  }%
  % calculate second support:
  {%
    \pgf@x=\pgf@xb%
    \pgf@y=\pgf@yb%
    \advance\pgf@x by-\pgf@xc%
    \advance\pgf@y by-\pgf@yc%
    \advance\pgf@xc by 0.555\pgf@x%
    \advance\pgf@yc by 0.555\pgf@y%
    \edef\pgfprocess@addition{\noexpand\pgfsyssoftpath@curvetosupportbtoken{\the\pgf@xc}{\the\pgf@yc}}%
    \expandafter\g@addto@macro\expandafter\pgfprocess@segment\expandafter{\pgfprocess@addition}%
  }%
  % add end:
  \edef\pgfprocess@addition{\noexpand\pgfsyssoftpath@curvetotoken{\the\pgf@xc}{\the\pgf@yc}}%
  \expandafter\g@addto@macro\expandafter\pgfprocess@segment\expandafter{\pgfprocess@addition}%
  %
  % continue!
  %
  \pgf@xa=#2%
  \pgf@ya=#3%
  \pgfprocess@continueafterrounding%
}

\def\pgfprocess@specialroundcurveto#1#2#3#4#5#6{%
  \g@addto@macro\pgfprocess@segment{#1{#2}{#3}#4{#5}{#6}}% supports
  \pgf@xa=#5%
  \pgf@ya=#6%
  \pgfprocess@specialroundcope}

\def\pgfprocess@specialroundclose{%
  \let\next=\pgfprocess@round%
  \ifx\pgfprocess@moveto\@empty%
  \else%
    \ifx\pgfprocess@firstto\@empty%
    \else%
      \expandafter\pgfprocess@@specialclosetarget\pgfprocess@firstto%
      \let\pgfprocess@continueafterrounding=\pgfprocess@cleanupafterclose%
      \edef\next{%
        \noexpand\pgfprocess@@specialround%
        \expandafter\expandafter\expandafter\noexpand\expandafter\pgfprocess@@specialclosemoveto\pgfprocess@moveto%
      }%
    \fi%
  \fi%  
  \next%
}

\def\pgfprocess@@specialclosetarget#1#2{%
  \pgf@xc=#1%
  \pgf@yc=#2%
}

\def\pgfprocess@@specialclosemoveto#1#2#3{%
  \pgfsyssoftpath@linetotoken{#2}{#3}%
}


\def\pgfprocess@cleanupafterclose#1#2#3{%
  \edef\pgfprocess@moveto{\noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xc}{\the\pgf@yc}}%
  \edef\pgf@marshal{\noexpand\pgfprocess@round\noexpand\pgfsyssoftpath@closepathtoken{\the\pgf@xc}{\the\pgf@yc}}%
  \pgf@marshal%  
}


% Replace start and end coordinates of a path
%
% #1 = new start coordinate
% #2 = new end coordinate
%
% Description:
%
% This command will replace the first and last coordinates on a path
% by the given coordinates.
%
% Example:
%
% \pgfsyssoftpath@moveto{0}{0}
% \pgfsyssoftpath@lineto{10}{10}
% \pgfsyssoftpath@curveto{20}{20}{30}{10}{40}{0}
% \pgfsyssoftpath@getcurrentpath\mypath
% \pgfsetlinewidth{2pt}
% \pgfusepath{stroke}
% \pgfprocesspathextractpoints{\mypath}
% \pgfprocesspathreplacestartandend{\mypath}
%   {\pgfpointlineatdistance{2pt}{\pgfpointfirstonpath}{\pgfpointsecondonpath}}%
%   {\pgfpointlineatdistance{2pt}{\pgfpointlastonpath}{\pgfpointsecondlastonpath}}%
% \pgfsyssoftpath@setcurrentpath\mypath
% \pgfsetlinewidth{1pt}
% \color{red}
% \pgfusepath{stroke}

\def\pgfprocesspathreplacestartandend#1#2#3{%
  {%
    \let\pgf@newpath=\@empty%
    \let\pgf@prepath=\@empty%
    \ifx#1\@empty%
    \else%
      \pgf@process{#3}%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@process{#2}%
      \expandafter\pgf@replaceprocessfirst#1\pgf@stop%
    \fi%
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\pgf@newpath
    \expandafter\expandafter\expandafter{\expandafter\pgf@prepath\pgf@newpath}%
    \global\let#1=\pgf@newpath%
  }%
}

\def\pgf@replaceprocessfirst#1#2#3#4{%
  \def\pgf@temppath{#1{#2}{#3}}%
  \edef\pgf@newpath{\noexpand#1{\the\pgf@x}{\the\pgf@y}}%
  \ifx#4\pgf@stop%
    \let\next=\@gobble%
  \else%
    \let\next=\pgf@replaceprocessother%
  \fi%
  \next#4%
}

\def\pgf@replaceprocessother#1{%
  \ifx#1\pgfsyssoftpath@movetotoken%
    % Arggghh! Must reset everything!
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\pgf@prepath
    \expandafter\expandafter\expandafter{\expandafter\pgf@prepath\pgf@temppath}%
    % Redo first.
    \let\pgf@next=\pgf@replaceprocessfirst%
  \else%
    \let\pgf@next=\pgf@@replaceprocessother%
  \fi%
  \pgf@next#1%
}
\def\pgf@@replaceprocessother#1#2#3#4{%
  \ifx#4\pgf@stop%
    \edef\pgf@newpathaddition{{\noexpand#1{\the\pgf@xa}{\the\pgf@ya}}}%
    \expandafter\g@addto@macro\expandafter\pgf@newpath\pgf@newpathaddition%
    \let\next=\@gobble%
  \else%
    \g@addto@macro\pgf@temppath{#1{#2}{#3}}%
    \g@addto@macro\pgf@newpath{#1{#2}{#3}}%
    \let\next=\pgf@replaceprocessother%
  \fi%
  \next#4%
}  

\endinput

pgfcorepathusage.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorepathusage.code.tex,v 1.2 2005/07/17 22:34:19 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


% Stroke/fill/clip/etc. the current path. Depending on the options,
% the current path will be stroked/filled/clipped/etc. If no options
% are given, the path is stroked. If multiple options are given, all
% of them are performed (in a sensible order).
%
% #1 = action(s) to be applied to the current path. Valid actions are: 
%      stroke -  strokes the path. If no options are given, this is the
%                default. 
%      draw -    same as stroke.
%      fill -    fills the path.
%      clip -    clip the path.
%      discard - Discards the path. Same effect as having an empty
%                options list.
%
% Example:
%
% % Draws an edge.
% \pgfpathmoveto{\pgfxy(0,0)}
% \pgfpathlineto{\pgfxy(0,1)}
% \pgfpathlineto{\pgfxy(1,0)}
% \pgfusepath{stroke}

\define@key{pgfup}{stroke}[]{\def\pgf@up@stroke{stroke}}
\define@key{pgfup}{draw}[]{\def\pgf@up@stroke{stroke}}
\define@key{pgfup}{fill}[]{\def\pgf@up@fill{fill}}
\define@key{pgfup}{clip}[]{\def\pgf@up@clip{clip}}
\define@key{pgfup}{discard}[]{}
\define@key{pgfup}{use as bounding box}[]{\def\pgf@up@bb{\pgf@relevantforpicturesizefalse}}

\def\pgfusepath#1{%
  \let\pgf@up@stroke\@empty%
  \let\pgf@up@fill\@empty%
  \let\pgf@up@clip\@empty%
  \let\pgf@up@discard\@empty%
  \let\pgf@up@bb\@empty%
  \setkeys{pgfup}{#1}%
  \expandafter\def\expandafter\pgf@up@action\expandafter{\csname pgfsys@\pgf@up@fill\pgf@up@stroke\endcsname}%
  \ifx\pgf@up@stroke\@empty%
    \ifx\pgf@up@fill\@empty%
      \ifx\pgf@up@clip\@empty%
        \let\pgf@up@action=\@empty%
        \pgfsyssoftpath@setcurrentpath\@empty%
      \else%
        % only clipping  
        \let\pgf@up@action=\pgfsys@discardpath%
      \fi%
    \fi%
  \fi%  
  \pgfprocessround{\pgfsyssoftpath@currentpath}{\pgfsyssoftpath@currentpath}% change the current path
  %
  % Check whether the path is stroked. If so, add half the path width
  % to the bounding box.
  %
  \ifpgf@relevantforpicturesize%
    \ifx\pgf@up@stroke\@empty%
    \else%
      \pgf@x=\pgf@pathminx\advance\pgf@x by-.5\pgflinewidth%
      \ifdim\pgf@x<\pgf@picminx\global\pgf@picminx\pgf@x\fi%
      \pgf@y=\pgf@pathminy\advance\pgf@y by-.5\pgflinewidth%
      \ifdim\pgf@y<\pgf@picminy\global\pgf@picminy\pgf@y\fi%
      \pgf@x=\pgf@pathmaxx\advance\pgf@x by.5\pgflinewidth%
      \ifdim\pgf@x>\pgf@picmaxx\global\pgf@picmaxx\pgf@x\fi%
      \pgf@y=\pgf@pathmaxy\advance\pgf@y by.5\pgflinewidth%
      \ifdim\pgf@y>\pgf@picmaxy\global\pgf@picmaxy\pgf@y\fi%
    \fi%
  \fi%
  %
  \ifx\pgf@up@clip\@empty%
    \ifx\pgf@up@stroke\@empty%
      \pgfsyssoftpath@invokecurrentpath%
      \pgfsyssoftpath@getcurrentpath\pgf@last@used@path%
      \pgf@up@action%
    \else%
      \pgf@check@for@arrows%
      \ifpgf@drawarrows%
        \pgf@shorten@path@as@needed%
        \pgfsyssoftpath@invokecurrentpath%
        \pgfsyssoftpath@getcurrentpath\pgf@last@used@path%
        \pgf@up@action%
        \pgfsyssoftpath@setcurrentpath\@empty%
        \pgf@add@arrows@as@needed%
      \else%
        \pgfsyssoftpath@invokecurrentpath%
        \pgfsyssoftpath@getcurrentpath\pgf@last@used@path%
        \pgf@up@action%
      \fi%
    \fi%
  \else%
    \pgfsyssoftpath@invokecurrentpath%
    \pgfsyssoftpath@getcurrentpath\pgf@last@used@path%
    \pgfsys@clipnext%
    \pgf@up@action%
    \pgf@relevantforpicturesizefalse%
  \fi%
  \pgf@up@bb%
  \pgfsyssoftpath@setcurrentpath\@empty%
  \pgf@resetpathsizes%
  \ignorespaces%
}


% Shorten start/end of paths by a certain amount.
%
% #1 = amount by which paths should be shortened.
%
% Example:
%
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathlineto{\pgfpoint{10pt}{0pt}
%
% % The following has the same effect:
% \pgfsetshortenstart{1pt}
% \pgfpathmoveto{\pgfpointorigin}
% \pgfpathlineto{\pgfpoint{11pt}{0pt}

\def\pgfsetshortenstart#1{\setlength\pgf@shorten@start@additional{#1}}
\def\pgfsetshortenend#1{\setlength\pgf@shorten@end@additional{#1}}

\newif\ifpgf@drawarrows

\def\pgf@check@for@arrows{%
  \pgf@drawarrowsfalse%
  \ifx\pgf@startarrow\@empty\else\pgf@drawarrowstrue\fi%
  \ifx\pgf@endarrow\@empty\else\pgf@drawarrowstrue\fi%
  \ifdim\pgf@shorten@end@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
  \ifdim\pgf@shorten@start@additional=0pt\relax\else\pgf@drawarrowstrue\fi%
  \ifpgf@drawarrows%
    \pgfsyssoftpath@getcurrentpath\pgf@arrowpath%
    \ifx\pgf@arrowpath\@empty%
      \pgf@drawarrowsfalse%
    \else%
      \pgfprocesscheckclosed{\pgf@arrowpath}{\pgf@drawarrowsfalse}%
    \fi%
  \fi%
}

\newdimen\pgf@shorten@end@additional
\newdimen\pgf@shorten@start@additional

\let\pgf@shorten@end=\@empty
\let\pgf@shorten@start=\@empty

\def\pgf@shorten@path@as@needed{%
  \pgfprocesspathextractpoints{\pgf@arrowpath}%
  \let\pgf@arrow@next=\pgf@shorten@now%
  \ifx\pgf@shorten@start\@empty%
    \ifx\pgf@shorten@end\@empty%
      \ifdim\pgf@shorten@end@additional=0pt\relax%
        \ifdim\pgf@shorten@start@additional=0pt\relax%
          \let\pgf@arrow@next=\relax%
        \fi%
      \fi%
    \fi%
  \fi%
  \pgf@arrow@next%
}

\def\pgf@shorten@now{%
  {%
    \pgf@x=0pt%
    \pgf@shorten@start%
    \advance\pgf@x by\pgf@shorten@start@additional%
    \pgf@xc=\pgf@x%
    \pgf@process{\pgfpointlineatdistance{\pgf@xc}{\pgfpointfirstonpath}{\pgfpointsecondonpath}}%
    \global\pgf@x=\pgf@x%
    \global\pgf@y=\pgf@y%
  }%
  \edef\pgfpointfirstonpath{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  {%
    \pgf@x=0pt%
    \pgf@shorten@end%
    \advance\pgf@x by\pgf@shorten@end@additional%
    \pgf@xc=\pgf@x%
    \pgf@process{\pgfpointlineatdistance{\pgf@xc}{\pgfpointlastonpath}{\pgfpointsecondlastonpath}}%
    \global\pgf@x=\pgf@x%
    \global\pgf@y=\pgf@y%
  }%
  \edef\pgfpointlastonpath{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  \pgfprocesspathreplacestartandend{\pgf@arrowpath}{\pgfpointfirstonpath}{\pgfpointlastonpath}%
  \pgfsyssoftpath@setcurrentpath\pgf@arrowpath%
}

\def\pgf@add@arrows@as@needed{%
  \ifx\pgf@startarrow\@empty%
  \else%
    \pgflowlevelobj%
      {\pgftransformarrow{\pgfpointsecondonpath}{\pgfpointfirstonpath}}
      {\pgf@startarrow}%
  \fi%
  \ifx\pgf@endarrow\@empty%
  \else%
    \pgflowlevelobj%
      {\pgftransformarrow{\pgfpointsecondlastonpath}{\pgfpointlastonpath}}
      {\pgf@endarrow}%
  \fi%      
}

\let\pgf@startarrow=\@empty
\let\pgf@endarrow=\@empty

\endinput

pgfcorepoints.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorepoints.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

\newdimen\pgf@picminx
\newdimen\pgf@picmaxx
\newdimen\pgf@picminy
\newdimen\pgf@picmaxy

\newdimen\pgf@pathminx
\newdimen\pgf@pathmaxx
\newdimen\pgf@pathminy
\newdimen\pgf@pathmaxy

\newif\ifpgf@relevantforpicturesize

\def\pgf@process#1{{#1\global\pgf@x=\pgf@x\global\pgf@y=\pgf@y}}

\newdimen\pgf@tempdim
\def\pgf@setlength#1#2{% these will be used only when \nullfont is active
  \begingroup% keep font setting local
    \pgf@selectfontorig% restore font
    \pgf@setlengthorig\pgf@tempdim{#2}% calculate dimension (possibly using calc)
    \global\pgf@tempdim\pgf@tempdim% make dimension global
  \endgroup%
  #1=\pgf@tempdim\relax}
\def\pgf@addtolength#1#2{%
  \begingroup% keep font setting local
    \pgf@selectfontorig% restore font
    \pgf@tempdim#1\relax%
    \pgf@addtolengthorig\pgf@tempdim{#2}% calculate dimension (possibly using calc)
    \global\pgf@tempdim\pgf@tempdim% make dimension global
  \endgroup%
  #1=\pgf@tempdim\relax}
\newcounter{pgf@tempcount}
\def\pgf@setcounter#1#2{%
  \setcounter{pgf@tempcount}{#2}% makes change global!
  \csname c@#1\endcsname=\c@pgf@tempcount\relax}
\def\pgf@selectfont{\pgf@selectfontorig\nullfont}



% Return a point
%  
% #1 = x-coordinate of the point 
% #2 = y-coordinate of the point 
%  
% x = #1
% y = #2
%
% Example:
%
% \pgfpathmoveto{\pgfpoint{2pt}{3cm}}

\def\pgfpoint#1#2{%
  \setlength\pgf@x{#1}%
  \setlength\pgf@y{#2}\ignorespaces}

% Return the origin.
%  
% x = 0
% y = 0
%
% Example:
%
% \pgfpathmoveto{\pgfpointorigin}

\def\pgfpointorigin{\pgfpoint{0pt}{0pt}\ignorespaces}



% Return a transformed point
%  
% #1 = a point
%
% Description:
%
% This command applies pgf's current transformation matrix to the
% given point. Normally, this is done automatically by commands like
% lineto or moveto, but sometimes you may wish to access a transformed
% point yourself. For example, this command is useful for a low level
% coordinate system shift:
%
% Example:
%
% \begin{pgflowleveltransformshiftscope}{\pgfpointtransformed{\pgfpointorigin}}
%   \pgfbox[center,center]{Hi!}
% \end{pgflowleveltransformshiftscope}

\def\pgfpointtransformed#1{%
  \pgf@process{%
    #1%
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
  }%
}


% Return the difference vector of two points.
%  
% #1 = start of vector  
% #2 = end of vector  
%  
% x = x-component of difference 
% y = y-component of difference 
%
% Example:
%
% \pgfpathmoveto{\pgfpointdiff{\pgfpointxy{1}{1}}{\pgfpointxy{2}{3}}}

\def\pgfpointdiff#1#2{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#2}%
  \advance\pgf@x by-\pgf@xa\relax%
  \advance\pgf@y by-\pgf@ya\relax\ignorespaces}

% Add two vectors. 
%  
% #1 = first vector  
% #2 = second vector  
%  
% x = x-component of addition
% y = y-component of addition
%
% Example:
%
% \pgfpathmoveto{\pgfpointadd{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}}

\def\pgfpointadd#1#2{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#2}%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya}



% Multiply a vector by a factor.
%  
% #1 = factor  
% #2 = vector  
%
% Example:
%
% \pgfpointscale{2}{\pgfpointxy{0}{1}}

\def\pgfpointscale#1#2{%
  \pgf@process{#2}%
  \pgf@x=#1\pgf@x%
  \pgf@y=#1\pgf@y%
}


% The intersection of two lines
%  
% #1 = point on first line
% #2 = another point on first line
% #3 = point on second line
% #4 = another point on second line
%
% Returns the intersection of the two lines. If there is no
% intersection or if the points #1 and #2 or the points #3 and #4 are
% identical, the behaviour is not specified.
%
% Example:
%
% \pgfpointintersectionoflines{\pgfpointxy{0}{1}}{\pgfpointxy{1}{0}}{\pgfpointxy{2}{2}}{\pgfpointxy{3}{4}}

\def\pgfpointintersectionoflines#1#2#3#4{%
  {
    % 
    % Compute orthogonal vector to #1--#2
    % 
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{#1}%
    \advance\pgf@xa by-\pgf@x%
    \advance\pgf@ya by-\pgf@y%
    \pgf@ya=-\pgf@ya%
    % Normalise a bit
    \c@pgf@counta=\pgf@xa%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@ya%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xa by\c@pgf@counta\relax%
      \divide\pgf@ya by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
    \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@ya,\pgf@xa)
    % 
    % 
    % Compute orthogonal vector to #3--#4
    % 
    \pgf@process{#4}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@process{#3}%
    \advance\pgf@xb by-\pgf@x%
    \advance\pgf@yb by-\pgf@y%
    \pgf@yb=-\pgf@yb%
    % Normalise a bit
    \c@pgf@counta=\pgf@xb%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@yb%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xb by\c@pgf@counta\relax%
      \divide\pgf@yb by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
    \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@yb,\pgf@xb)
    % 
    % Setup transformation matrx (this is just to use the matrix
    % inversion)
    % 
    \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
    \pgftransforminvert%
    \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
  }%
}


% Returns point on a line from #2 to #3 at time #1.
%  
% #1 = a time, where 0 is the start and 1 is the end
% #2 = start point
% #3 = end point 
%  
% x = x-component of #1*start + (1-#1)*end
% y = y-component of #1*start + (1-#1)*end 
%
% Example:
%
% % Middle of (1,1) and (2,3)
% \pgfpathmoveto{\pgfpointlineattime{0.5}{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}}

\def\pgfpointlineattime#1#2#3{%
  \pgf@process{#3}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#2}%
  \advance\pgf@xa by-\pgf@x\relax%
  \advance\pgf@ya by-\pgf@y\relax%
  \advance\pgf@x by #1\pgf@xa\relax%
  \advance\pgf@y by #1\pgf@ya\relax%  
  \ignorespaces}


% Move point #2 #1 many units in the direction of #3.
%  
% #1 = a distance
% #2 = start point
% #3 = end point 
%  
% x = x-component of start + #1*(normalise(end-start))
% y = y-component of start + #1*(normalise(end-start))
%
% Example:
%
%
% \pgfpathmoveto{\pgfpointlineatdistance{2pt}{\pgfpointxy{0}{1}}{\pgfpointxy{2}{3}}}
% \pgfpathlineto{\pgfpointlineatdistance{3pt}{\pgfpointxy{2}{3}}{\pgfpointxy{0}{1}}}

\def\pgfpointlineatdistance#1#2#3{%
  \pgf@process{#2}%
  \pgf@xb=\pgf@x\relax% xb/yb = start point
  \pgf@yb=\pgf@y\relax%
  \pgf@process{#3}%
  \advance\pgf@x by-\pgf@xb\relax%
  \advance\pgf@y by-\pgf@yb\relax%
  \pgf@process{\pgfpointnormalised{}}% x/y = normalised vector
  \setlength\pgf@xa{#1}%
  \pgf@ya=\pgf@xa\relax%
  \pgf@xa=\pgf@sys@tonumber{\pgf@x}\pgf@xa%
  \pgf@ya=\pgf@sys@tonumber{\pgf@y}\pgf@ya%
  \pgf@x=\pgf@xb\relax%
  \pgf@y=\pgf@yb\relax%
  \advance\pgf@x by\pgf@xa\relax%
  \advance\pgf@y by\pgf@ya\relax%
  \ignorespaces}


% Returns point on a curve from #2 to #5 with controls #3 and #4 at time #1.
%  
% #1 = a time
% #2 = start point
% #3 = first control point
% #4 = second control point
% #5 = end point 
%  
% x = x-component of place on the curve at time t
% y = y-component of place on the curve at time t
%
% Additionally, (\pgf@xa,\pgf@ya) and (\pgf@xb,\pgf@yb) will be on a
% tangent to the point on the curve (this can be useful for computing
% a label rotation).
%
% Example:
%
% % Middle of (1,1) and (2,3)
% \pgfpathmoveto{\pgfpointcurveattime{0.5}{\pgfpointxy{0}{1}}{\pgfpointxy{1}{1}}{\pgfpointxy{1}{1}}{\pgfpointxy{2}{3}}}

\def\pgfpointcurveattime#1#2#3#4#5{%
  \def\pgf@time@s{#1}%
  \pgf@x=#1pt%
  \pgf@x=-\pgf@x%
  \advance\pgf@x by 1pt%
  \edef\pgf@time@t{\pgf@sys@tonumber{\pgf@x}}%
  \pgf@process{#5}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \pgf@process{#4}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@process{#3}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#2}%
  % First iteration:
  \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
  \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
  \pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb%
  \pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb%
  \pgf@xb=\pgf@time@t\pgf@xb\advance\pgf@xb by\pgf@time@s\pgf@xc%
  \pgf@yb=\pgf@time@t\pgf@yb\advance\pgf@yb by\pgf@time@s\pgf@yc%
  % Second iteration:
  \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
  \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
  \pgf@xa=\pgf@time@t\pgf@xa\advance\pgf@xa by\pgf@time@s\pgf@xb%
  \pgf@ya=\pgf@time@t\pgf@ya\advance\pgf@ya by\pgf@time@s\pgf@yb%
  % Save x/y
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  % Third iteration:
  \pgf@x=\pgf@time@t\pgf@x\advance\pgf@x by\pgf@time@s\pgf@xa%
  \pgf@y=\pgf@time@t\pgf@y\advance\pgf@y by\pgf@time@s\pgf@ya%
}






% Internal registers
\newdimen\pgf@xx
\newdimen\pgf@xy
\newdimen\pgf@yx
\newdimen\pgf@yy
\newdimen\pgf@zx
\newdimen\pgf@zy



% Store a value in polar-coordinates
%
% #1 = a degree
% #2 = a radius
%
% x = #2 * cos(#1)
% y = #2 * sin(#2)
% 
% Example:
%
% % Create a slanted rectangle
%
% \pgfpathmoveto{\pgfpointpolar{30}{1cm}}

\def\pgfpointpolar#1#2{%
  \pgfsincos{#1}%
  \in@/{#2}%
  \ifin@%
    \pgf@polar@#2\@@%
  \else%
    \pgf@polar@#2/#2\@@%
  \fi%  
  \pgf@xa=\pgf@sys@tonumber{\pgf@x}\pgf@xa%
  \pgf@ya=\pgf@sys@tonumber{\pgf@y}\pgf@ya%
  \pgf@y=\pgf@xa\relax%
  \pgf@x=\pgf@ya\ignorespaces}

\def\pgf@polar@#1/#2\@@{%
  \setlength{\pgf@xa}{#2}%
  \setlength{\pgf@ya}{#1}%  
}



% Store the vector #1 * x-vec + #2 * y-vec
%
% #1 = a factor for the x-vector
% #2 = a factor fot the y-vector
%
% x = x-component of result vector
% y = y-component of result vector
%
% Description:
% 
% This command can be used to create a new coordinate system
% without using the rotate/translate/scale commands. This
% may be useful, if you do not want arrows and line width to
% be scaled/transformed together with the coordinate system.
% 
% Example:
%
% % Create a slanted rectangle
%
% \pgfsetxvec{\pgfpoint{1cm}{1cm}}
% \pgfsetyvec{\pgfpoint{0cm}{1cm}}
% 
% \pgfpathmoveto{\pgfpointxy{0}{0}}
% \pgfpathlineto{\pgfpointxy{1}{0}}
% \pgfpathlineto{\pgfpointxy{1}{1}}
% \pgfpathlineto{\pgfpointxy{0}{1}}
% \pgfclosestroke

\def\pgfpointxy#1#2{\pgf@x=#1\pgf@xx%
  \advance\pgf@x by #2\pgf@yx%
  \pgf@y=#1\pgf@xy%
  \advance\pgf@y by #2\pgf@yy}


% Store the vector #1 * x-vec + #2 * y-vec + #3 * z-vec
%
% #1 = a factor for the x-vector
% #2 = a factor fot the y-vector
% #3 = a factor fot the z-vector
%
% x = x-component of result vector
% y = y-component of result vector
%
%
% Description:
% 
% This command allows you to use a 3d coordinate system.
% 
%
% Example:
%
% % Draw a cubus
% 
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{0}{0}{1}}
% \pgfline{\pgfpointxyz{0}{1}{0}}{\pgfpointxyz{0}{1}{1}}
% \pgfline{\pgfpointxyz{1}{0}{0}}{\pgfpointxyz{1}{0}{1}}
% \pgfline{\pgfpointxyz{1}{1}{0}}{\pgfpointxyz{1}{1}{1}}
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{0}{1}{0}}
% \pgfline{\pgfpointxyz{0}{0}{1}}{\pgfpointxyz{0}{1}{1}}
% \pgfline{\pgfpointxyz{1}{0}{0}}{\pgfpointxyz{1}{1}{0}}
% \pgfline{\pgfpointxyz{1}{0}{1}}{\pgfpointxyz{1}{1}{1}}
% \pgfline{\pgfpointxyz{0}{0}{0}}{\pgfpointxyz{1}{0}{0}}
% \pgfline{\pgfpointxyz{0}{0}{1}}{\pgfpointxyz{1}{0}{1}}
% \pgfline{\pgfpointxyz{0}{1}{0}}{\pgfpointxyz{1}{1}{0}}
% \pgfline{\pgfpointxyz{0}{1}{1}}{\pgfpointxyz{1}{1}{1}}

\def\pgfpointxyz#1#2#3{%
  \pgf@x=#1\pgf@xx%
  \advance\pgf@x by #2\pgf@yx%
  \advance\pgf@x by #3\pgf@zx%
  \pgf@y=#1\pgf@xy%
  \advance\pgf@y by #2\pgf@yy%
  \advance\pgf@y by #3\pgf@zy}




% Set the x-vector
%
% #1 = a point the is the new x-vector
%
% Example:
%
% \pgfsetxvec{\pgfpoint{1cm}{0cm}}

\def\pgfsetxvec#1{%
  \pgf@process{#1}%
  \pgf@xx=\pgf@x%
  \pgf@xy=\pgf@y%
  \ignorespaces}


% Set the y-vector
%
% #1 = a point the is the new y-vector
%
% Example:
%
% \pgfsetyvec{\pgfpoint{0cm}{1cm}}

\def\pgfsetyvec#1{%
  \pgf@process{#1}%
  \pgf@yx=\pgf@x%
  \pgf@yy=\pgf@y%
  \ignorespaces}


% Set the z-vector
%
% #1 = a point the is the new z-vector
%
% Example:
%
% \pgfsetzvec{\pgfpoint{-0.385cm}{-0.385cm}}

\def\pgfsetzvec#1{%
  \pgf@process{#1}%
  \pgf@zx=\pgf@x%
  \pgf@zy=\pgf@y%
  \ignorespaces}



% Default values
\pgfsetxvec{\pgfpoint{1cm}{0cm}}
\pgfsetyvec{\pgfpoint{0cm}{1cm}}
\pgfsetzvec{\pgfpoint{-0.385cm}{-0.385cm}}




% Normalise a point.
%
% #1 = point with coordinates (a,b)
%
% x  = a/\sqrt(a*a+b*b)
% y  = b/\sqrt(a*a+b*b)
%
% Example:
%
% \pgfpointnormalised{\pgfpointxy{2}{1}}

\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \ifdim\pgf@x<0pt\relax% move into first quadrant
    \pgf@x=-\pgf@x%
  \fi%
  \ifdim\pgf@y<0pt\relax%
    \pgf@y=-\pgf@y%
  \fi%
  \ifdim\pgf@x>\pgf@y% x > y
    % make point small
    \c@pgf@counta=\pgf@x%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta=0\relax%
      \c@pgf@counta=1\relax%
    \fi%
    \divide\pgf@x by\c@pgf@counta%
    \divide\pgf@y by\c@pgf@counta%
    \divide\pgf@xa by\c@pgf@counta%
    \divide\pgf@ya by\c@pgf@counta%
    % ok.
    \pgf@x=.125\pgf@x%
    \pgf@y=.125\pgf@y%
    \c@pgf@counta=\pgf@x%
    \c@pgf@countb=\pgf@y%
    \multiply\c@pgf@countb by 100%
    \ifnum\c@pgf@counta<64\relax%
      \pgf@x=1pt\relax%
      \pgf@y=0pt\relax%
    \else%
      \divide\c@pgf@countb by \c@pgf@counta%
      \pgf@setmath{x}{\csname pgf@cosfrac\the\c@pgf@countb\endcsname}%
      \pgf@xc=8192pt%
      \divide\pgf@xc by\c@pgf@counta%
      \pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@ya%
      \pgf@y=\pgf@sys@tonumber{\pgf@x}\pgf@y%
    \fi%
    \ifdim\pgf@xa<0pt%
      \pgf@x=-\pgf@x%
    \fi%
  \else% x <= y
    % make point small
    \c@pgf@counta=\pgf@y%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta=0\relax%
      \c@pgf@counta=1\relax%
    \fi%
    \divide\pgf@x by\c@pgf@counta%
    \divide\pgf@y by\c@pgf@counta%
    \divide\pgf@xa by\c@pgf@counta%
    \divide\pgf@ya by\c@pgf@counta%
    % ok.
    \pgf@x=.125\pgf@x%
    \pgf@y=.125\pgf@y%
    \c@pgf@counta=\pgf@y%
    \c@pgf@countb=\pgf@x%
    \multiply\c@pgf@countb by 100%
    \ifnum\c@pgf@counta<64\relax%
      \pgf@y=1pt\relax%
      \pgf@x=0pt\relax%
    \else%
      \divide\c@pgf@countb by \c@pgf@counta%
      \pgf@setmath{y}{\csname pgf@cosfrac\the\c@pgf@countb\endcsname}%
      \pgf@xc=8192pt%
      \divide\pgf@xc by\c@pgf@counta%
      \pgf@x=\pgf@sys@tonumber{\pgf@xc}\pgf@xa%
      \pgf@x=\pgf@sys@tonumber{\pgf@y}\pgf@x%
    \fi%
    \ifdim\pgf@ya<0pt%
      \pgf@y=-\pgf@y%
    \fi%
  \fi\ignorespaces}





% A point on a rectangle in a certain direction.
%
% #1 = a point pointing in some direction (length should be about 1pt,
%      but need not be exact)
% #2 = upper right corner of a rectangle centered at the origin
%
% Returns the intersection of a line starting at the origin going in
% the given direction and the rectangle's border.
%
% Example:
%
% \pgfpointborderrectangle{\pgfpointnormalised{\pgfpointxy{2}{1}}
%   {\pgfpoint{1cm}{2cm}}

\def\pgfpointborderrectangle#1#2{%
  \pgf@process{#2}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@process{#1}%
  % Ok, let's find out about the direction:
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \ifnum\pgf@xa<0\relax% move into first quadrant
    \pgf@x=-\pgf@x%
  \fi%
  \ifnum\pgf@ya<0\relax%
    \pgf@y=-\pgf@y%
  \fi%
  \pgf@xc=.125\pgf@x%
  \pgf@yc=.125\pgf@y%
  \c@pgf@counta=\pgf@xc%
  \c@pgf@countb=\pgf@yc%
  \ifnum\c@pgf@countb<\c@pgf@counta%
    \ifnum\c@pgf@counta<255\relax%
      \pgf@y=\pgf@yb\relax%
      \pgf@x=0pt\relax%
    \else%
      \pgf@xc=8192pt%
      \divide\pgf@xc by\c@pgf@counta% \pgf@xc = 1/\pgf@x
      \pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y%
      \pgf@y=\pgf@sys@tonumber{\pgf@xb}\pgf@y%
      \ifnum\pgf@y<\pgf@yb%
        \pgf@x=\pgf@xb%
      \else% rats, calculate intersection on upper side
        \ifnum\c@pgf@countb<255\relax%
          \pgf@x=\pgf@xb\relax%
          \pgf@y=0pt\relax%
        \else%
          \pgf@yc=8192pt%
          \divide\pgf@yc by\c@pgf@countb% \pgf@xc = 1/\pgf@x
          \pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x%
          \pgf@x=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
          \pgf@y=\pgf@yb%
        \fi%
      \fi%  
    \fi%
  \else%
    \ifnum\c@pgf@countb<255\relax%
      \pgf@x=\pgf@xb\relax%
      \pgf@y=0pt\relax%
    \else%
      \pgf@yc=8192pt%
      \divide\pgf@yc by\c@pgf@countb% \pgf@xc = 1/\pgf@x
      \pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x%
      \pgf@x=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
      \ifnum\pgf@x<\pgf@xb%
        \pgf@y=\pgf@yb%
      \else%
        \ifnum\c@pgf@counta<255\relax%
          \pgf@y=\pgf@yb\relax%
          \pgf@x=0pt\relax%
        \else%
          \pgf@xc=8192pt%
          \divide\pgf@xc by\c@pgf@counta% \pgf@xc = 1/\pgf@x
          \pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y%
          \pgf@y=\pgf@sys@tonumber{\pgf@xb}\pgf@y%
          \pgf@x=\pgf@xb%
        \fi%
      \fi%  
    \fi%
  \fi%  
  \ifnum\pgf@xa<0\relax\pgf@x=-\pgf@x\fi%
  \ifnum\pgf@ya<0\relax\pgf@y=-\pgf@y\fi%    
}




% An approximation to a point on an ellipse in a certain
% direction. Will be exact only if the ellipse is a circle. 
%
% #1 = a point pointing in some direction
% #2 = upper right corner of a bounding box for the ellipse
%
% Returns the intersection of a line starting at the origin going in
% the given direction and the ellipses border.
%
% Example:
%
% \pgfpointborderellipse{\pgfpointnormalised{\pgfpointxy{2}{1}}
%   {\pgfpoint{1cm}{2cm}}

\def\pgfpointborderellipse#1#2{%
  \pgf@process{#2}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \ifdim\pgf@xa=\pgf@ya% circle. that's easy!
    \pgf@process{\pgfpointnormalised{#1}}%
    \pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x%
    \pgf@y=\pgf@sys@tonumber{\pgf@xa}\pgf@y%
  \else%
    \ifdim\pgf@xa<\pgf@ya%
      % Ok, first, let's compute x/y:
      \c@pgf@countb=\pgf@ya%
      \divide\c@pgf@countb by65536\relax%
      \divide\pgf@x by\c@pgf@countb%
      \divide\pgf@y by\c@pgf@countb%
      \pgf@xc=\pgf@x%
      \pgf@yc=8192pt%
      \pgf@y=.125\pgf@y%
      \c@pgf@countb=\pgf@y%
      \divide\pgf@yc by\c@pgf@countb%
      \pgf@process{#1}%
      \pgf@y=\pgf@sys@tonumber{\pgf@yc}\pgf@y%
      \pgf@y=\pgf@sys@tonumber{\pgf@xc}\pgf@y%
      \pgf@process{\pgfpointnormalised{}}%
      \pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x%
      \pgf@y=\pgf@sys@tonumber{\pgf@ya}\pgf@y%
    \else%
      % Ok, now let's compute y/x:
      \c@pgf@countb=\pgf@xa%
      \divide\c@pgf@countb by65536\relax%
      \divide\pgf@x by\c@pgf@countb%
      \divide\pgf@y by\c@pgf@countb%
      \pgf@yc=\pgf@y%
      \pgf@xc=8192pt%
      \pgf@x=.125\pgf@x%
      \c@pgf@countb=\pgf@x%
      \divide\pgf@xc by\c@pgf@countb%
      \pgf@process{#1}%
      \pgf@x=\pgf@sys@tonumber{\pgf@yc}\pgf@x%
      \pgf@x=\pgf@sys@tonumber{\pgf@xc}\pgf@x%
      \pgf@process{\pgfpointnormalised{}}%
      \pgf@x=\pgf@sys@tonumber{\pgf@xa}\pgf@x%
      \pgf@y=\pgf@sys@tonumber{\pgf@ya}\pgf@y%
    \fi%  
  \fi%
}





% Extract the x-coordinate of a point to a dimensions
%  
% #1 = a TeX dimension
% #2 = a point
%
% Example:
%
% \newdimen\mydim
% \pgfextractx{\mydim}{\pgfpoint{2cm}{4pt}}
% % \mydim is now 2cm

\def\pgfextractx#1#2{%
  \pgf@process{#2}%
  #1=1.00374\pgf@x\relax}


% Extract the y-coordinate of a point to a dimensions
%  
% #1 = a TeX dimension
% #2 = a point
%
% Example:
%
% \newdimen\mydim
% \pgfextracty{\mydim}{\pgfpoint{2cm}{4pt}}
% % \mydim is now 4pt

\def\pgfextracty#1#2{%
  \pgf@process{#2}%
  #1=1.00374\pgf@y\relax}


\endinput

pgfcorequick.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorequick.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


% Quick version of basic drawing commands. Most high-level commands
% are not available if these commands are used.

% Move current point to (#1,#2).
%
% #1 = x dimension of new current point
% #2 = y dimension of new current point
% 
% Example:
%
% \pgfpathqmoveto{0pt}{0pt}
% \pgfpathqlineto{1pt}{1pt}
% \pgfpathqcurveto{2pt}{1pt}{2pt}{2pt}{3pt}{2pt}
% \pgfqstroke

\def\pgfpathqmoveto#1#2{\pgfsyssoftpath@moveto{#1}{#2}}


% Append a line to (#1,#2) to the current path.
%
% #1 = x dimension of target
% #2 = y dimension of target
% 
% Example:
%
% \pgfpathqmoveto{0pt}{0pt}
% \pgfpathqlineto{1pt}{1pt}
% \pgfpathqcurveto{2pt}{1pt}{2pt}{2pt}{3pt}{2pt}
% \pgfqstroke

\def\pgfpathqlineto#1#2{\pgfsyssoftpath@lineto{#1}{#2}}


% Append a bezier spline to the current path.
%
% #1 = x dimension of first support point
% #2 = y dimension of first support point
% #3 = x dimension of second support point
% #4 = y dimension of second support point
% #5 = x dimension of target point
% #6 = y dimension of target point
% 
% Example:
%
% \pgfpathqmoveto{0pt}{0pt}
% \pgfpathqlineto{1pt}{1pt}
% \pgfpathqcurveto{2pt}{1pt}{2pt}{2pt}{3pt}{2pt}
% \pgfqstroke

\def\pgfpathqcurveto#1#2#3#4#5#6{\pgfsyssoftpath@curveto{#1}{#2}{#3}{#4}{#5}{#6}}




% Append a circle of the given radius around the origin.
%
% #1 = radius
% 
% Example:
%
% \pgfpathqcircle{10pt}
% is quicker than
% \pgfpathcircle{\pgforigin}{10pt}

\def\pgfpathqcircle#1{%
  {%
    \pgf@x=#1%
    \pgf@y=0.555\pgf@x%
    \pgfsyssoftpath@moveto{\the\pgf@x}{0pt}%
    \pgfsyssoftpath@curveto{\the\pgf@x}{\the\pgf@y}{\the\pgf@y}{\the\pgf@x}{0pt}{\the\pgf@x}%
    \pgfsyssoftpath@curveto{-\the\pgf@y}{\the\pgf@x}{-\the\pgf@x}{\the\pgf@y}{-\the\pgf@x}{0pt}%
    \pgfsyssoftpath@curveto{-\the\pgf@x}{-\the\pgf@y}{-\the\pgf@y}{-\the\pgf@x}{0pt}{-\the\pgf@x}%
    \pgfsyssoftpath@curveto{\the\pgf@y}{-\the\pgf@x}{\the\pgf@x}{-\the\pgf@y}{\the\pgf@x}{0pt}%
    \pgfsyssoftpath@closepath%
  }%
}



% Stroke current path. No hooks called.
% 
% Example:
%
% \pgfpathqmoveto{0cm}{0cm}
% \pgfpathqlineto{1cm}{1cm}
% \pgfpathqcurveto{2cm}{1cm}{2cm}{2cm}{3cm}{2cm}
% \pgfqstroke

\def\pgfusepathqstroke{%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfsys@stroke%
  \pgf@resetpathsizes%
}


% Quickly fill current path.

\def\pgfusepathqfill{%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfsys@fill%
  \pgf@resetpathsizes%
}


% Quickly fill and stroke current path.

\def\pgfusepathqfillstroke{%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfsys@fillstroke%
  \pgf@resetpathsizes%
}

% Quickly clip current path.

\def\pgfusepathqclip{%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfsys@clipnext%
  \pgfsys@discardpath%
  \pgf@resetpathsizes%
}


\endinput

pgfcorescopes.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorescopes.code.tex,v 1.12 2005/11/15 17:46:37 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

% Globals

\newbox\pgfpic
\newbox\pgf@hbox

\newbox\pgf@layerbox@main


% Scopes


% Pgf scope environment. All changes of the graphic state are local to
% the scope.
%  
% Example:
%
% \begin{pgfscope}
%    \pgfsetlinewidth{3pt}
%    \pgfline{\pgfxy(0,0)}{\pgfxy(3,3)}
% \end{pgfscope}

\def\pgfscope{%
  \pgfsyssoftpath@setcurrentpath\@empty%
  \pgfsys@beginscope%
    \pgf@resetpathsizes%
    \edef\pgfscope@linewidth{\the\pgflinewidth}%
    \begingroup}
\def\endpgfscope{%
    \endgroup%
    \global\pgflinewidth=\pgfscope@linewidth%
  \pgfsys@endscope}




% Quickly insert a box can contain normal TeX text at the origin.
% 
% #1 = box of width/height and depth 0pt
% 
% Example:
%
% \pgfqbox{\mybox}

\def\pgfqbox#1{%
  \pgfsys@hbox#1%
} 


% Insert a box that can contain normal TeX text at the origin, but
% with the current coordinate transformation matrix synced with the
% low-level transformation matrix.
% 
% #1 = box of width/height and depth 0pt
%
% In essence, this command does the same as if you first said
% \pgflowlevelsynccm and then \pgfqbox. However, pgf will use a
% ``TeX-translation'' for the translation part of the transformation
% cm. This will ensure that hyperlinks ``survive'' at least
% translations. 
% 
% Example:
%
% \pgfqboxsynced{\mybox}

\def\pgfqboxsynced#1{%
  \pgfsys@hboxsynced#1%
}


% Puts some text in a box and inserts it with the current
% transformations applied.
% 
% #1 = List of optional positioning. Possible values are ``left'', ``right'',
%      ``top'', ``bottom'' and ``base''.
% #2 = TeX text. May contain verbatims.
% 
% Example:
%
% \pgftransformshift{\pgfpoint{1cm}{0cm}}
% \pgftext{Hello World!}

\def\pgftext{\@ifnextchar[\pgf@text{\pgf@text[]}}%
\def\pgf@text[#1]{%
  \def\pgf@text@options{#1}%
  \pgf@maketext\pgf@after@text}
\def\pgf@after@text{%
  {
  \def\pgf@text@hshift{center}%
  \def\pgf@text@vshift{center}%
  \def\pgf@marshal{\setkeys{pgfbox}}%
  \expandafter\pgf@marshal\expandafter{\pgf@text@options}%
  \csname pgf@halign\pgf@text@hshift\endcsname%
  \csname pgf@valign\pgf@text@vshift\endcsname%
  % Protocol sizes:
  \pgf@process{\pgfpointtransformed{\pgfpoint{0pt}{\dp\pgf@hbox}}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@process{\pgfpointtransformed{\pgfpoint{\wd\pgf@hbox}{\dp\pgf@hbox}}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@process{\pgfpointtransformed{\pgfpoint{0pt}{\ht\pgf@hbox}}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgf@process{\pgfpointtransformed{\pgfpoint{\wd\pgf@hbox}{\ht\pgf@hbox}}}%
  \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  \pgfqboxsynced{\pgf@hbox}%
  }%
}

\define@key{pgfbox}{left}[]{\def\pgf@text@hshift{left}}
\define@key{pgfbox}{center}[]{}
\define@key{pgfbox}{right}[]{\def\pgf@text@hshift{right}}
\define@key{pgfbox}{top}[]{\def\pgf@text@vshift{top}}
\define@key{pgfbox}{bottom}[]{\def\pgf@text@vshift{bottom}}
\define@key{pgfbox}{base}[]{\def\pgf@text@vshift{base}}
\define@key{pgfbox}{at}{\pgftransformshift{#1}}
\define@key{pgfbox}{x}{\pgftransformxshift{#1}}
\define@key{pgfbox}{y}{\pgftransformyshift{#1}}
\define@key{pgfbox}{rotate}{\pgftransformrotate{#1}}

\def\pgf@halignleft{}% do nothing
\def\pgf@haligncenter{\pgftransformxshift{-.5\wd\pgf@hbox}}
\def\pgf@halignright{\pgftransformxshift{-\wd\pgf@hbox}}%
\def\pgf@valignbase{}% do nothing
\def\pgf@valignbottom{\pgftransformyshift{\dp\pgf@hbox}}%
\def\pgf@valigncenter{\pgftransformyshift{.5\dp\pgf@hbox}\pgftransformyshift{-.5\ht\pgf@hbox}}%
\def\pgf@valigntop{\pgftransformyshift{-\ht\pgf@hbox}}%


% Internal function for creating a hbox.
\def\pgf@maketext#1{%
  \def\pgf@@maketextafter{#1}%
  \setbox\pgf@hbox=\hbox\bgroup%
    \pgfinterruptpicture%
      \bgroup%
        \aftergroup\pgf@collectresetcolor%
        \let\next=%
}
\def\pgf@collectresetcolor{%
  \@ifnextchar\reset@color%
  {\reset@color\afterassignment\pgf@collectresetcolor\let\pgf@temp=}%
  {\pgf@textdone}%
}
\def\pgf@textdone{%
    \endpgfinterruptpicture%
  \egroup%
  \pgf@@maketextafter%  
}

\long\def\pgf@makehbox#1{%
  \setbox\pgf@hbox=\hbox{{%
    \pgfinterruptpicture%
      #1%
    \endpgfinterruptpicture%
    }}}
 



% Picture environment
%
% Example:
%
% \begin{pgfpicture}
%   \pgfsetendarrow{\pgfarrowto}
%   \pgfpathmoveto{\pgfpointxy{-0.9}{0.2}}
%   \pgfpathlineto{\pgfpointxy{0.9}{0.4}}
%   \pgfusepath{stroke}
% \end{pgfpicture}

\newif\ifpgfpicture

\def\pgfpicture{%
  \begingroup%
  \pgfpicturetrue%
  \pgf@picmaxx=-16000pt\relax%
  \pgf@picminx=16000pt\relax%
  \pgf@picmaxy=-16000pt\relax%
  \pgf@picminy=16000pt\relax%
  \pgf@relevantforpicturesizetrue%
  \pgf@resetpathsizes%
  \@ifnextchar\bgroup\pgf@oldpicture\pgf@picture}
\def\pgf@oldpicture#1#2#3#4{%
  \setlength\pgf@picminx{#1}%
  \setlength\pgf@picminy{#2}%
  \setlength\pgf@picmaxx{#3}%
  \setlength\pgf@picmaxy{#4}%
  \pgf@relevantforpicturesizefalse%
  \pgf@picture}

\def\pgf@picture{%
  \setbox\pgfpic\hbox to0pt\bgroup%
    \begingroup%
    \pgfsys@beginpicture%
      \pgfsys@beginscope%
        \begingroup%
        \color{.}%
        \pgfsetlinewidth{0.4pt}%
        \pgftransformreset%
        \pgfsyssoftpath@setcurrentpath\@empty%
        \begingroup%
          \let\pgf@setlengthorig=\setlength%
          \let\pgf@addtolengthorig=\addtolength%
          \let\pgf@selectfontorig=\selectfont%
          \let\setlength=\pgf@setlength%
          \let\addtolength=\pgf@addtolength%
          \let\selectfont=\pgf@selectfont%
          \nullfont\spaceskip\z@\xspaceskip\z@%
          \setbox\pgf@layerbox@main\hbox to0pt\bgroup%
            \begingroup%
  }
\def\endpgfpicture{%
              % Shift baseline outside:
              \global\let\pgf@shift@baseline=\pgf@baseline%
            \endgroup%
            \hss%
          \egroup%
          \pgf@insertlayers%
        \endgroup%    
        \pgfsys@discardpath%
        \endgroup%
      \pgfsys@endscope%
    \pgfsys@endpicture%
    \endgroup%
    \hss
  \egroup%
  % ok, now let's position the box
  \ifdim\pgf@picmaxx=-16000pt\relax%
    % empty picture. make size 0.  
    \pgf@picmaxx=0pt\relax%
    \pgf@picminx=0pt\relax%
    \pgf@picmaxy=0pt\relax%
    \pgf@picminy=0pt\relax%
  \fi%
  \pgfsys@typesetpicturebox\pgfpic%
  \endgroup%
}

\def\pgf@insertlayers{%
  \box\pgf@layerbox@main%
}


% Sets the baseline
%
% #1 = baseline
%
% Sets the baseline of the picture. Default is the lower border, which
% is the same as \pgf@picminy
%
% Example:
%
% \pgfsetbaseline{1cm+2pt}

\def\pgfsetbaseline#1{\def\pgf@baseline{#1}}
\pgfsetbaseline{\pgf@picminy}





% Interrupt path
%
% Description:
%
% The environment can be used to insert some drawing commands while
% constructing a path. The drawing commands inside the environment
% will not interfere with the path being constructed ``outside.''
% However, you must ward against graphic state changes using a scope. 
%
% Example: Draw two parallel lines
%
% \pgfmoveto{\pgfpoint{0cm}{0cm}}
% \begin{pgfinterruptpath}
%   \pgfmoveto{\pgfpoint{1cm}{0cm}}
%   \pgfmoveto{\pgfpoint{1cm}{1cm}}
%   \pgfusepath{stroke}
% \end{pgfinterruptpath}
% \pgflineto{\pgfpoint{0cm}{1cm}}
% \pgfusepath{stroke}

\def\pgfinterruptpath
{%
  \begingroup%
  % save all sorts of things...
  \edef\pgf@interrupt@savex{\the\pgf@path@lastx}%
  \edef\pgf@interrupt@savey{\the\pgf@path@lasty}%
  \pgf@getpathsizes\pgf@interrupt@pathsizes%
  \pgfsyssoftpath@getcurrentpath\pgf@interrupt@path%
  \pgfsyssoftpath@setcurrentpath\@empty%
  \edef\pgfscope@linewidth{\the\pgflinewidth}%
  \let\pgf@interrupt@lastmoveto=\pgfsyssoftpath@lastmoveto%
  \begingroup%
}
\def\endpgfinterruptpath
{%
  \endgroup%
  \global\pgflinewidth=\pgfscope@linewidth%
  \pgfsyssoftpath@setcurrentpath\pgf@interrupt@path%
  \pgf@setpathsizes\pgf@interrupt@pathsizes%
  \global\pgf@path@lastx=\pgf@interrupt@savex%
  \global\pgf@path@lasty=\pgf@interrupt@savey%
  \global\let\pgfsyssoftpath@lastmoveto=\pgf@interrupt@lastmoveto%
  \endgroup%
}




% Interrupts a picture
%
% Description:
%
% This environment interrupts a picture and temporarily returns to
% normal TeX mode. All sorts of things are saved and restored by this
% environment.
%
% WARNING: Using this environment in conjuction with low level
% transformations can *strongly* upset the typesetting. Typically, the
% contents of this environment should have size/height/depth 0pt in
% the end.
%
% WARNING: This environment should only be used inside typesetting a
% box and this box must in turn be inserted using \pgfqbox.
%
% Example: Draw two parallel lines
%
% \pgfmoveto{\pgfpoint{0cm}{0cm}}
% \setbox\mybox=\hbox{
%    \begin{pgfinterruptpicture}
%      This is normal text.
%      \begin{pgfpicture} % a subpicture
%        \pgfmoveto{\pgfpoint{1cm}{0cm}}
%        \pgfmoveto{\pgfpoint{1cm}{1cm}}
%        \pgfusepath{stroke}
%      \end{pgfpicture}
%      More text.
%    \end{pgfinterruptpicture}
%  }
% \ht\mybox=0pt
% \wd\mybox=0pt
% \dp\mybox=0pt
% \pgfqbox{\mybox}%
% \pgfpathlineto{\pgfpoint{0cm}{1cm}}
% \pgfusepath{stroke}

\def\pgfinterruptpicture
{%
  \begingroup%
  \edef\pgf@interrupt@savemaxx{\the\pgf@picmaxx}%
  \edef\pgf@interrupt@saveminx{\the\pgf@picminx}%
  \edef\pgf@interrupt@savemaxy{\the\pgf@picmaxy}%
  \edef\pgf@interrupt@saveminy{\the\pgf@picminy}%
  \pgftransformreset%
  \pgfinterruptpath%
  \ifx\pgf@setlengthorig\@undefined%
  \else%
    \let\setlength\pgf@setlengthorig%
    \let\addtolength\pgf@addtolengthorig%
    \let\selectfont\pgf@selectfontorig%
  \fi%
  \selectfont%
  \pgfpicturefalse%
  \pgf@savelayers%
}
\def\endpgfinterruptpicture
{%
  \pgf@restorelayers%
  \endpgfinterruptpath%
  \global\pgf@picmaxx=\pgf@interrupt@savemaxx%
  \global\pgf@picmaxy=\pgf@interrupt@savemaxy%
  \global\pgf@picminx=\pgf@interrupt@saveminx%
  \global\pgf@picminy=\pgf@interrupt@saveminy%
  \endgroup%
}

\let\pgf@savelayers=\relax
\let\pgf@restorelayers=\relax


\endinput

pgfcoreshade.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoreshade.code.tex,v 1.3 2005/07/17 22:34:19 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


%
% Parsing functions
%
\newdimen\pgf@max
\newcount\pgf@sys@shading@range@num
\def\pgf@parsefunc#1{%
  \edef\temp{{#1}}%
  \expandafter\pgf@convertrgbstring\temp%
  \edef\temp{{\pgf@rgbconv}}%
  \expandafter\pgf@@parsefunc\temp}
\def\pgf@@parsefunc#1{%
  \let\pgf@bounds=\@empty%
  \let\pgf@funcs=\@empty%
  \let\pgf@psfuncs=\@empty%
  \let\pgf@encode=\@empty%
  \let\pgf@sys@shading@ranges=\@empty%
  \pgf@sys@shading@range@num=0\relax%
  \pgf@parsefirst[#1; ]%
  \pgf@parselastdom[#1; ]%
  \pgf@parsemid[#1; ]%
  \ifx\pgf@bounds\@empty%
    \edef\pgf@pdfparseddomain{0 1}%
    \edef\pgf@pdfparsedfunction{\pgf@singlefunc\space}%
  \else%
    \edef\pgf@pdfparseddomain{\pgf@doma\space\pgf@domb}%
    \edef\pgf@pdfparsedfunction{%
      << /FunctionType 3 /Domain [\pgf@doma\space\pgf@domb] /Functions
      [\pgf@funcs\space] /Bounds [\pgf@bounds] /Encode [0 1 \pgf@encode]
      >> }%
  \fi%
  \xdef\pgf@psfuncs{\pgf@psfuncs}%
  }
\def\pgf@parsefirst[rgb(#1)=(#2,#3,#4)#5]{%
  \setlength\pgf@x{#1}%
  \edef\pgf@sys@shading@start@pos{\the\pgf@x}%
  \pgf@sys@bp@correct\pgf@x%
  \edef\pgf@doma{\pgf@sys@tonumber{\pgf@x}}%
  \edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}%
  \pgf@getrgbtuplewithmixin{#2}{#3}{#4}%
  \edef\pgf@sys@shading@start@rgb{\pgf@sys@rgb}%
  \let\pgf@sys@prevcolor=\pgf@sys@shading@start@rgb%
  \let\pgf@sys@prevpos=\pgf@sys@shading@start@pos%
  \edef\pgf@prevcolor{\pgf@rgb}%
  \edef\pgf@firstcolor{\pgf@rgb}}
\def\pgf@parselastdom[rgb(#1)=(#2,#3,#4); {%
  \@ifnextchar]{%
    \setlength\pgf@x{#1}%
    \edef\pgf@sys@shading@end@pos{\the\pgf@x}%
    \pgf@max=\pgf@x\relax%
    \pgf@sys@bp@correct\pgf@x%
    \edef\pgf@domb{\pgf@sys@tonumber{\pgf@x}}%
    \pgf@getrgbtuplewithmixin{#2}{#3}{#4}%
    \edef\pgf@sys@shading@end@rgb{\pgf@sys@rgb}%
    \@gobble}{\pgf@parselastdom[}}
\def\pgf@parsemid[rgb(#1)=(#2,#3,#4); {\pgf@parserest[}
\def\pgf@parserest[rgb(#1)=(#2,#3,#4); {%
  \advance\pgf@sys@shading@range@num by1\relax%
  \@ifnextchar]{%
    \pgf@getrgbtuplewithmixin{#2}{#3}{#4}%
    \edef\pgf@singlefunc{\space%
      << /FunctionType 2 /Domain [0 1] /C0
      [\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }%
    \edef\pgf@funcs{\pgf@funcs\space%
      << /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0
      [\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }%
    \edef\pgf@psfuncs{\pgf@prevx\space \pgf@rgb\space \pgf@prevcolor\space pgfshade \pgf@psfuncs}%
    \setlength\pgf@x{#1}%
    \edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@rgb}}}%
    \edef\pgf@sys@prevpos{\the\pgf@x}%
    \let\pgf@sys@prevcolor=\pgf@sys@rgb%
    \@gobble}{%
    \setlength\pgf@x{#1}%
    \pgf@getrgbtuplewithmixin{#2}{#3}{#4}%
    \edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@rgb}}}%
    \edef\pgf@sys@prevpos{\the\pgf@x}%
    \let\pgf@sys@prevcolor=\pgf@sys@rgb%
    \edef\pgf@psfuncs{\pgf@prevx\space \pgf@rgb\space \pgf@prevcolor\space pgfshade \pgf@psfuncs}%
    \pgf@sys@bp@correct\pgf@x%
    \edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}%
    \edef\pgf@bounds{\pgf@bounds\space\pgf@sys@tonumber{\pgf@x}}%
    \edef\pgf@encode{\pgf@encode\space0 1}%
    \edef\pgf@singlefunc{\space%
      << /FunctionType 2 /Domain [0 1] /C0
      [\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% 
    \edef\pgf@funcs{\pgf@funcs\space%
      << /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0
      [\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% 
    \edef\pgf@prevcolor{\pgf@rgb}%
    \pgf@parserest[}}

\def\pgf@getrgbtuplewithmixin#1#2#3{%
  \definecolor{pgfshadetemp}{rgb}{#1,#2,#3}%
  \@ifundefined{applycolormixins}{}{\applycolormixins{pgfshadetemp}}%
  \extractcolorspec{pgfshadetemp}{\pgf@tempcolor}%
  \expandafter\convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}%
  \expandafter\pgf@getrgb@@\pgf@rgbcolor!}
\def\pgf@getrgb@@#1,#2,#3!{%
  \def\pgf@rgb{#1 #2 #3}%
  \def\pgf@sys@rgb{{#1}{#2}{#3}}%
}


\def\pgf@convertrgbstring#1{%
  \def\pgf@rgbconv{}%
  \pgf@converttorgb#1]%
  }
\def\pgf@converttorgb{%
  \@ifnextchar]{\@gobble}%done!
  {%
    \@ifnextchar;{\pgf@grabsemicolor}%
    {%
      \@ifnextchar r{\pgf@grabrgb}%
      {%
        \@ifnextchar g{\pgf@grabgray}%
        {%
          \@ifnextchar c{\pgf@grabcolor}%
          {\PackageError{pgfshade}{Illformed shading
              specification}{}\pgf@converttorgb}%
        }%
      }%
    }%
  }%
}
\def\pgf@grabsemicolor;{%
  \edef\pgf@rgbconv{\pgf@rgbconv; }\pgf@converttorgb}
\def\pgf@grabrgb rgb(#1)=(#2,#3,#4){%
  \edef\pgf@rgbconv{\pgf@rgbconv rgb(#1)=(#2,#3,#4)}\pgf@converttorgb}
\def\pgf@grabgray gray(#1)=(#2){%
  \edef\pgf@rgbconv{\pgf@rgbconv rgb(#1)=(#2,#2,#2)}\pgf@converttorgb}
\def\pgf@grabcolor color(#1)=(#2){%
  \colorlet{pgf@tempcol}{#2}%
  \extractcolorspec{pgf@tempcol}{\pgf@tempcolor}%
  \expandafter\convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}%
  \expandafter\pgf@convgetrgb@\expandafter{\pgf@rgbcolor}{#1}%
}
\def\pgf@convgetrgb@#1#2{%
  \edef\pgf@rgbconv{\pgf@rgbconv rgb(#2)=(#1)}\pgf@converttorgb}




% Declares a horizontal shading for later use. The shading is a
% horizontal bar that changes its color.
%
% #1 = name of the shading for later use
% #2 = height of the shading
% #3 = color specification in the following format: A list of colors
%      that the bar should have at certain points. If the bar should
%      be red at 1cm, this is specified as
%      "rgb(1cm)=(1,0,0)". Multiple specifications are separated by a
%      semicolon and a space. At least two specifications must be
%      given. The specified positions must be given in increasing
%      order. 
%
% Example:
%
% \pgfdeclarehorizontalshading{redtogreentoblue}{1cm}{%
%   rgb(0cm)=(1,0,0); % red
%   rgb(1cm)=(0,1,0); % green
%   rgb(2cm)=(0,0,1)}
%
% \begin{document}
%   The following bar is 2cm long: \pgfuseshading{redtogreentoblue}.
% \end{document}

\def\pgfdeclarehorizontalshading{\@ifnextchar[\pgf@declarehorizontalshading{\pgf@declarehorizontalshading[]}}%
\def\pgf@declarehorizontalshading[#1]#2#3#4{%
  \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
  \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\@empty%
    \pgfsys@horishading{#2}{#3}{#4}%
  \else%
    \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@horishading}%
    \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
    \expandafter\let\csname @pgfshading#2!\endcsname=\@empty%
  \fi}


% Declares a vertical shading for later use. 
%
% #1 = name of the shading for later use
% #2 = height of the shading
% #3 = color specification 
%
% Example:
%
% \pgfdeclareverticalshading{redtogreentoblue}{1cm}{%
%   rgb(0cm)=(1,0,0); % red
%   rgb(1cm)=(0,1,0); % green
%   rgb(2cm)=(0,0,1)}
%
% \begin{document}
%   The following bar is 2cm high: \pgfuseshading{redtogreentoblue}.
% \end{document}

\def\pgfdeclareverticalshading{\@ifnextchar[\pgf@declareverticalshading{\pgf@declareverticalshading[]}}%
\def\pgf@declareverticalshading[#1]#2#3#4{%
  \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
  \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\@empty%
    \pgfsys@vertshading{#2}{#3}{#4}%
  \else%
    \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@vertshading}%
    \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
    \expandafter\let\csname @pgfshading#2!\endcsname=\@empty%
  \fi}


% Declares a radial shading for later use. 
%
% #1 = name of the shading for later use
% #2 = center of inner circle
% #3 = color specification 
%
% Description:
%
% A radial shading creates a smooth color transition between two
% circles. The center of the inner circle is at the give position. Its
% radius is the start of the color specification. The
% center of the outer circle is at the center of the whole shading,
% whose radius is the end of the color specification. For example,
% suppose the color specification is "rgb(1cm)=(1,1,1); rgb(2cm)=(0,0,0)".  
% Then the shading would be 4cm times 4cm large. The inner circle would
% have diameter 1cm and the outer circle would have diameter 2cm. The
% outer circle would be centered in the middle of the shading, whereas
% the outer circle would be centered at the given position.
%
% Example:
%
% \pgfdeclareradialshading{redtogreentoblue}{\pgfpoint{2cm}{2cm}}{%
%   rgb(10pt)=(1,0,0); % red
%   rgb(2cm)=(0,1,0); % green
%   rgb(3cm)=(0,0,1)}
%
% \begin{document}
%   The following ball has diameter 3cm: \pgfuseshading{redtogreentoblue}.
% \end{document}

\def\pgfdeclareradialshading{\@ifnextchar[\pgf@declareradialshading{\pgf@declareradialshading[]}}%
\def\pgf@declareradialshading[#1]#2#3#4{%
  \expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}%
  \expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\@empty%
    \pgfsys@radialshading{#2}{#3}{#4}%
  \else%
    \expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@radialshading}%
    \expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}%
    \expandafter\let\csname @pgfshading#2!\endcsname=\@empty%
  \fi}
  

% Inserts a box into the text that contains a previously defined
% shading. 
%
% #1 = Name of a shading
%
% Example:
%
% \pgfuseshading{redtogreentoblue}

\def\pgfuseshading#1{%
  \edef\pgf@shadingname{@pgfshading#1}%
  \pgf@tryextensions{\pgf@shadingname}{\pgfalternateextension}%
  \expandafter\@ifundefined\expandafter{\pgf@shadingname}%
  {\PackageError{pgfshade}{Undefined shading "#1"}{}}%
  {%
    {%
      \globalcolorsfalse%
      \def\pgf@shade@adds{}%
      \@ifundefined{pgf@deps\pgf@shadingname}%
      {}%
      {%
        \edef\@list{\csname pgf@deps\pgf@shadingname\endcsname}%
        \@for\@temp:=\@list\do{%
          {%
            \@ifundefined{applycolormixins}{}{\applycolormixins{\@temp}}%
            \extractcolorspec{\@temp}{\pgf@tempcolor}%
            \expandafter\convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}%
            \xdef\pgf@shade@adds{\pgf@shade@adds,\pgf@rgbcolor}%
          }%
        }%
      }%
      \expandafter\pgf@strip@shadename\pgf@shadingname!!%
      \@ifundefined{@pgfshading\pgf@basename\pgf@shade@adds!}%
      {%
        {%
          \expandafter\def\expandafter\@temp\expandafter{\csname pgf@func\pgf@shadingname\endcsname}%
          \edef\@args{{\pgf@basename\pgf@shade@adds}}%
          \expandafter\expandafter\expandafter\def%
          \expandafter\expandafter\expandafter\@@args%
          \expandafter\expandafter\expandafter{\csname pgf@args\pgf@shadingname\endcsname}%
          \expandafter\expandafter\expandafter\@temp\expandafter\@args\@@args%
          %
        }%
      }%
      {}%
      \pgf@invokeshading{\csname @pgfshading\pgf@basename\pgf@shade@adds!\endcsname}%
    }%
  }%
}

\def\pgf@strip@shadename @pgfshading#1!!!{\def\pgf@basename{#1}}

\def\pgf@invokeshading#1{%
  \ifpgfpicture%
    \pgfsys@shadinginsidepgfpicture{#1}%
  \else%
    \pgfsys@shadingoutsidepgfpicture{#1}%  
  \fi%
}


% Create an alias name for a shading
%
% #1 = name of the alias
% #2 = name of the original
%
% Example:
%
% \pgfaliasshading{shading!25}{shadingshaded}

\def\pgfaliasshading#1#2{%
  \expandafter\let\expandafter\pgf@temp\expandafter=\csname @pgfshading#2!\endcsname%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgf@temp%
  \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@deps@pgfshading#2!\endcsname%
  \expandafter\let\csname pgf@deps@pgfshading#1!\endcsname=\pgf@temp%
  \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@func@pgfshading#2!\endcsname%
  \expandafter\let\csname pgf@func@pgfshading#1!\endcsname=\pgf@temp%
  \expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@args@pgfshading#2!\endcsname%
  \expandafter\let\csname pgf@args@pgfshading#1!\endcsname=\pgf@temp%
}




% Shades the current path, but does not discard it.
%
% #1 - a shading (see below)
% #2 - an angle
%
% Description:
%
% \pgfshadepath  ``tries'' to fill the
% current path with a shading. The shading's original size should
% completely cover the area between (0,0) and (100bp,100bp). The
% shading will be rotated by #2 and then rescaled so that it
% completely covers the path. Then the path will be used (locally) for
% clipping and the shading is drawn.
%
% After all this, the path can still be used for the normal
% stroking/clipping operations.
%
% The shading is rotated around its middle. If no rotation occurs, the
% lower left corner of the path will lie on (25bp, 25bp), the upper
% right corner on (75bp, 75bp).
%
% Example:
%
% \pgfdeclareverticalshading{myshading}{100bp}{color(0pt)=(red); color(100bp)=(green)}
%
% \pgfpathmoveto{\pgforigin}
% \pgfpathlineto{\pgfxy(1,0)}
% \pgfpathlineto{\pgfxy(1,1)}
% \pgfshadepath{myshading}{0}
% \pgfusepath{stroke}

\def\pgfshadepath#1#2{%
  \ifdim\pgf@pathminx=16000pt%
    \PackageWarning{pgfshade}{No path specified that can be filled}%
  \else%
    \begingroup%  
      \pgfsys@beginscope%
        % Calculate center:
        \pgf@xb=.5\pgf@pathmaxx%
        \advance\pgf@xb by.5\pgf@pathminx%
        \pgf@yb=.5\pgf@pathmaxy%
        \advance\pgf@yb by.5\pgf@pathminy%
        % Calculate scaling:
        \pgf@xc=\pgf@pathmaxx%
        \advance\pgf@xc by-\pgf@pathminx%
        \pgf@yc=\pgf@pathmaxy%
        \advance\pgf@yc by-\pgf@pathminy%
        \pgf@xc=.02\pgf@xc%
        \pgf@yc=.02\pgf@yc%
        \pgfsyssoftpath@invokecurrentpath%
        \pgfsys@clipnext%
        \pgfsys@discardpath%
        % Compute new transformation matrix:
        \pgf@process{\pgfsincos{#2}}%
        \pgf@xa=-\pgf@x%
        \pgfsys@transformcm{1}{0}{0}{1}{\pgf@xb}{\pgf@yb}%
        \pgfsys@transformcm%
        {\pgf@sys@tonumber{\pgf@xc}}{0}%
        {0}{\pgf@sys@tonumber{\pgf@yc}}{0pt}{0pt}%
        \pgfsys@transformcm%
        {\pgf@sys@tonumber{\pgf@y}}{\pgf@sys@tonumber{\pgf@x}}%
        {\pgf@sys@tonumber{\pgf@xa}}{\pgf@sys@tonumber{\pgf@y}}{0pt}{0pt}%
        \pgfuseshading{#1}%
      \pgfsys@endscope%
    \endgroup%
  \fi%
}

\endinput

pgfcoretransformations.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoretransformations.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



% Position transformations

\newdimen\pgf@pt@x
\newdimen\pgf@pt@y

\newdimen\pgf@pt@temp

\newif\ifpgf@pt@identity
\pgf@pt@identitytrue

\def\pgf@pt@aa{1.0} \def\pgf@pt@ab{0.0}
\def\pgf@pt@ba{0.0} \def\pgf@pt@bb{1.0}



% Store the current transformation matrix in a macro.
%
% #1 = macro name
%
% Example:
%
% \pgfgettransform\mytransform

\def\pgfgettransform#1{%
  \edef#1{{\pgf@pt@aa}{\pgf@pt@ab}{\pgf@pt@ba}{\pgf@pt@bb}{\the\pgf@pt@x}{\the\pgf@pt@y}}
}


% Restore the current transformation matrix from a macro.
%
% #1 = macro name, previously used with \pgfgettransform
%
% Example:
%
% \pgfsettransform\mytransform

\def\pgfsettransform#1{%
  \edef\pgf@temp{#1}%
  \expandafter\pgf@settransform\pgf@temp%
}
\def\pgf@settransform#1#2#3#4#5#6{%
  \def\pgf@pt@aa{#1}%
  \def\pgf@pt@ab{#2}%
  \def\pgf@pt@ba{#3}%
  \def\pgf@pt@bb{#4}%
  \pgf@pt@x=#5%
  \pgf@pt@y=#6%
  \edef\pgf@idtest{#1,#2,#3,#4}%
  \ifx\pgf@idtest\pgf@idmatrixtext%
    \pgf@pt@identitytrue%
  \else%
    \pgf@pt@identityfalse%
  \fi%
}

\def\pgf@idmatrixtext{1.0,0.0,0.0,1.0}


% Transformation command
%
% #1 = x dimension
% #2 = y dimension
%
% Description:
%
% Applies the pgfs transformation matrix to the point (#1,#2). The
% result is once more stored in the point.
%
%
% Example:
%
% \pgf@pos@transform{\pgf@x}{\pgf@y}

\def\pgf@pos@transform#1#2{%
  \ifpgf@pt@identity%
  \else%
    \pgf@pt@temp=#1%
    #1=\pgf@pt@aa#1%
    \advance#1 by\pgf@pt@ba#2%
    #2=\pgf@pt@bb#2%
    \advance#2 by\pgf@pt@ab\pgf@pt@temp%
  \fi%
  \advance#1 by\pgf@pt@x%
  \advance#2 by\pgf@pt@y%
}


% Invert the current transformation matrix
%
% Description:
%
% This command replaces the current transformation matrix by its
% inverse. The inversion is not very exact if the matrix is nearly
% singular. 
%
% Example:
%
% \pgftransforminvert

\def\pgftransforminvert{%
  % First, invert the shift. That's easy
  \pgf@pt@x=-\pgf@pt@x
  \pgf@pt@y=-\pgf@pt@y
  \ifpgf@pt@identity%
  \else%
    % Sigh. Have to calculate the inverse of the matrix.
    % Start with determinant
    % Matrix = (aa ab
    %           ba bb)
    {%
      \@tempdima=\pgf@pt@aa pt%
      \@tempdima=\pgf@pt@bb\@tempdima% aa * bb
      \@tempdimb=\pgf@pt@ba pt%
      \@tempdimb=\pgf@pt@ab\@tempdimb% ba * ab
      \advance\@tempdima by -\@tempdimb% aa*bb - ba*ab
      % Invert
      \@tempdima=.125\@tempdima%
      \c@pgf@counta=\@tempdima\relax% 8192*determinant
      \@tempdima=8192pt%
      \divide\@tempdima by\c@pgf@counta%
      \pgf@x=\pgf@pt@bb\@tempdima% bb/(det A)
      \xdef\pgf@new@pt@aa{\pgf@sys@tonumber{\pgf@x}}%
      \pgf@x=\pgf@pt@aa\@tempdima% aa/(det A)
      \xdef\pgf@new@pt@bb{\pgf@sys@tonumber{\pgf@x}}%
      \@tempdima=-\@tempdima%
      \pgf@x=\pgf@pt@ba\@tempdima% -ba/(det A)
      \xdef\pgf@new@pt@ba{\pgf@sys@tonumber{\pgf@x}}%
      \pgf@x=\pgf@pt@ab\@tempdima% -ab/(det A)
      \xdef\pgf@new@pt@ab{\pgf@sys@tonumber{\pgf@x}}%
    }%
    \expandafter\def\expandafter\pgf@pt@aa\expandafter{\pgf@new@pt@aa}%
    \expandafter\def\expandafter\pgf@pt@ab\expandafter{\pgf@new@pt@ab}%
    \expandafter\def\expandafter\pgf@pt@ba\expandafter{\pgf@new@pt@ba}%
    \expandafter\def\expandafter\pgf@pt@bb\expandafter{\pgf@new@pt@bb}%
    \pgf@pt@temp=\pgf@pt@x%
    \pgf@pt@x=\pgf@pt@aa\pgf@pt@x%
    \advance\pgf@pt@x by\pgf@pt@ba\pgf@pt@y%
    \pgf@pt@y=\pgf@pt@bb\pgf@pt@y%
    \advance\pgf@pt@y by\pgf@pt@ab\pgf@pt@temp%
  \fi%
}




% PGF-Level concatenation of the transformation matrix with a given
% matrix. 
%
% #1 - #5 = a concatenation matrix (see pdf spec). Entry #5 is a
%           translation point.
%
% Description:
%
% All coordinates given to subsequent path construction commands will
% be transformed additionally by the given transformation matrix. If
% the command is followed by a 6th argument, the transformation is
% only applied to this argument.
%
%
% Example:
%
% \pgftransformcm{1}{0}{0}{1}{\pgfpoint{100pt}{0pt}} % 100pt to the right.
%
% \pgftransformcm{2}{0}{0}{2}{\pgfpointorigin} % double in in size
% \pgfpathmoveto{\pgfpoint{0cm}{0cm}}
% \pgfpathlineto{\pgflineto{1cm}{1cm}} % actually 2cm/2cm

\def\pgftransformcm#1#2#3#4#5{%
  \edef\pgf@marshal{\noexpand\pgf@transformcm{#1}{#2}{#3}{#4}}%
  \pgf@marshal{#5}%
}
\def\pgf@transformcm#1#2#3#4#5{%
  {%
    \pgf@process{#5}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    %
    \pgf@x=#1pt%
    \pgf@y=#2pt%
    %
    \pgf@xa=\pgf@pt@aa\pgf@x%
    \advance\pgf@xa by \pgf@pt@ba\pgf@y%
    %
    \pgf@ya=\pgf@pt@ab\pgf@x%
    \advance\pgf@ya by \pgf@pt@bb\pgf@y%
    %
    \pgf@x=#3pt%
    \pgf@y=#4pt%
    %
    \pgf@xb=\pgf@pt@aa\pgf@x%
    \advance\pgf@xb by \pgf@pt@ba\pgf@y%
    %
    \pgf@yb=\pgf@pt@ab\pgf@x%
    \advance\pgf@yb by \pgf@pt@bb\pgf@y%
    %
    \pgf@x=\pgf@pt@aa\pgf@xc%
    \advance\pgf@x by\pgf@pt@ba\pgf@yc%
    \advance\pgf@x by\pgf@pt@x%
    %
    \pgf@y=\pgf@pt@ab\pgf@xc%
    \advance\pgf@y by\pgf@pt@bb\pgf@yc%
    \advance\pgf@y by\pgf@pt@y%
    %
    \global\pgf@x=\pgf@x%
    \global\pgf@y=\pgf@y%
    \xdef\pgf@tempaa{\pgf@sys@tonumber{\pgf@xa}}%
    \xdef\pgf@tempab{\pgf@sys@tonumber{\pgf@ya}}%
    \xdef\pgf@tempba{\pgf@sys@tonumber{\pgf@xb}}%
    \xdef\pgf@tempbb{\pgf@sys@tonumber{\pgf@yb}}%
  }%
  \pgf@pt@x=\pgf@x%
  \pgf@pt@y=\pgf@y%
  \let\pgf@pt@aa=\pgf@tempaa%
  \let\pgf@pt@ba=\pgf@tempba%
  \let\pgf@pt@ab=\pgf@tempab%
  \let\pgf@pt@bb=\pgf@tempbb%
  \def\pgf@trans@idtest{#1,#2,#3,#4}%
  \ifx\pgf@trans@idtest\pgf@trans@idtext%
  \else%
    \pgf@pt@identityfalse%
  \fi%
}
\def\pgf@trans@idtext{1.0,0,0,1.0}






% Undo all transformations
%
% Example:
%
% \pgftansformreset

\def\pgftransformreset{%
  \pgf@pt@x=0pt%
  \pgf@pt@y=0pt%
  \def\pgf@pt@aa{1.0}%
  \def\pgf@pt@ba{0.0}%
  \def\pgf@pt@ab{0.0}%
  \def\pgf@pt@bb{1.0}%
  \pgf@pt@identitytrue%
}


% Undo all slanting/rotation, but not translations
%
% Example:
%
% \pgftansformreset

\def\pgftransformresetnontranslations{%
  \def\pgf@pt@aa{1.0}%
  \def\pgf@pt@ba{0.0}%
  \def\pgf@pt@ab{0.0}%
  \def\pgf@pt@bb{1.0}%
  \pgf@pt@identitytrue%
}




% Shifting command and environment
%
% #1 = vector by which all subsequent points should be moved.
%
% Example:
%
% \pgftansformshift{\pgfpoint{1cm}{1cm}}

\def\pgftransformshift#1{\pgftransformcm{1.0}{0}{0}{1.0}{#1}}
\def\pgftransformxshift#1{\pgftransformcm{1.0}{0}{0}{1.0}{\pgfpoint{#1}{0pt}}}
\def\pgftransformyshift#1{\pgftransformcm{1.0}{0}{0}{1.0}{\pgfpoint{0pt}{#1}}}




% Scaling commands
%
% #1 = scaling for all subsequent points.
%
% Example:
%
% \pgftransformscale{2}
% \pgftransformxscale{2}
% \pgftransformyscale{2}

\def\pgftransformscale#1{\pgftransformcm{#1}{0}{0}{#1}{\pgfpointorigin}}
\def\pgftransformxscale#1{\pgftransformcm{#1}{0}{0}{1.0}{\pgfpointorigin}}
\def\pgftransformyscale#1{\pgftransformcm{1.0}{0}{0}{#1}{\pgfpointorigin}}



% Slanting commands
%
% #1 = slanting in x-direction. 1 means 45 degrees.
%
% Example:
%
% \pgftransformxslant{2}
% \pgftransformyslant{2}

\def\pgftransformxslant#1{\pgftransformcm{1.0}{0}{#1}{1.0}{\pgfpointorigin}}
\def\pgftransformyslant#1{\pgftransformcm{1.0}{#1}{0}{1.0}{\pgfpointorigin}}



% Rotation commands
%
% #1 = degrees for the rotation
%
% Example:
%
% \pgftransformrotate{30}

\def\pgftransformrotate#1{%
  \pgfsincos{#1}%
  \pgf@xa=-\pgf@x%
  \pgftransformcm%
  {\pgf@sys@tonumber{\pgf@y}}{\pgf@sys@tonumber{\pgf@x}}%
  {\pgf@sys@tonumber{\pgf@xa}}{\pgf@sys@tonumber{\pgf@y}}{\pgfpointorigin}%
}



% The following two if's have the following effect:
%
% \ifpgfslopedattime decides whether the coordinate system of an
% xxxattime transformation command should be rotated such that text
% drawn on the line should be tangent to the line
%
% \ifpgfresetnontranslationattime decides whether the coordinate
% system of an xxxattime transformation command should be reset
% (concerning the non-translations) before a possible rotation is
% applied. This is useful, for example, if the main coordinate system
% is scaled by, say, a factor of 2 and you do not want that to apply
% to the text, but you do want the rotation to applyu.

\newif\ifpgfslopedattime
\newif\ifpgfresetnontranslationattime


% Transform to the coordinate system of a point on a line
%
% #1 = a time fraction of line where to put the label, where 0 means start,
%      1 means end, and for example 0.5 means the middle.
% #2 = start of line
% #3 = end of line
%
% Example:
%
% {
%   \pgftransformlineattime{.5}{\pgfxy(0,0)}{\pgfxy(3,2)}
%   \pgftext{Hi!}
% }
%
% {
%   \pgftransformlineattime{.75}{\pgfxy(0,0)}{\pgfxy(3,2)}
%   \pgftransformresetnontranslations
%   \pgftext{Hi!}
% }
%
\def\pgftransformlineattime#1#2#3{%
  \pgftransformshift{\pgfpointlineattime{#1}{#2}{#3}}%
  \ifpgfresetnontranslationattime%
    \pgftransformresetnontranslations%
  \fi%
  \ifpgfslopedattime%
    \pgf@process{#2}%
    \pgf@xa=\pgf@x% xb/yb = start point
    \pgf@ya=\pgf@y%
    \pgf@process{#3}%
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \ifdim\pgf@x<0pt%
      \pgf@x=-\pgf@x%
      \pgf@y=-\pgf@y%
    \fi%
    \pgfpointnormalised{}% x/y = normalised vector
    \pgf@ya=-\pgf@y%
    \pgftransformcm%
    {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
    {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
  \fi%
}




% Transform to the coordinate system of a point on a curve
%
% #1 = a time fraction of line where to put the label, where 0 means start,
%      1 means end, and for example 0.5 means the middle.
% #2 = start of line
% #3 = first control
% #4 = second control
% #5 = end of line
%
% Example:
%
% {
%   \pgftransformlabel{.5}{\pgfxy(0,0)}{\pgfxy(3,2)}
%   \pgftext{Hi!}
% }
%
% {
%   \pgftransformlabel{.75}{\pgfxy(0,0)}{\pgfxy(3,2)}
%   \pgftransformresetnontranslations
%   \pgftext{Hi!}
% }
%
\def\pgftransformcurveattime#1#2#3#4#5{%
  \pgfpointcurveattime{#1}{#2}{#3}{#4}{#5}%
  \pgftransformshift{\pgfpoint{\pgf@x}{\pgf@y}}%
  \ifpgfresetnontranslationattime%
    \pgftransformresetnontranslations%
  \fi%
  \ifpgfslopedattime%
    \pgf@x=\pgf@xb%
    \pgf@y=\pgf@yb%
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \ifdim\pgf@x<0pt%
      \pgf@x=-\pgf@x%
      \pgf@y=-\pgf@y%
    \fi%
    \pgfpointnormalised{}% x/y = normalised vector
    \pgf@ya=-\pgf@y%
    \pgftransformcm%
    {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
    {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
  \fi%
}





% Transform to the coordinate system of an arrow at the end of the
% line going from point #1 to point #2 with the correct rotation.
%
% #1 = a start point an (invisible) line
% #2 = an end point an (invisible) line
%
% Example:
%
% \pgftransformarrow{\pgfpointorigin}{\pgfpoint{1cm}{0cm}}

\def\pgftransformarrow#1#2{%
  \pgftransformshift{#2}%
  \pgf@process{#2}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#1}%
  \advance\pgf@xa by-\pgf@x%
  \advance\pgf@ya by-\pgf@y%
  \pgf@x=\pgf@xa%
  \pgf@y=\pgf@ya%
  \pgfpointnormalised{}%
  \pgf@ya=-\pgf@y%
  \pgftransformcm%
  {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
  {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpoint{0pt}{0pt}}%
}



% Low-level transformations

% Causes the current high-level transformation command to be applied
% to the low-level.
%
% Description:
%
% All subsequent drawing will be transformed additionally by the
% current high-level transformation. Thus, the high-level
% transformation becomes the low-level transformation. The high-level
% transformation is reset at this point.

\def\pgflowlevelsynccm{%
  \pgfsys@transformcm%
  {\pgf@pt@aa}{\pgf@pt@ab}%
  {\pgf@pt@ba}{\pgf@pt@bb}%
  {\pgf@pt@x}{\pgf@pt@y}%
  \pgftransformreset%
  \pgf@relevantforpicturesizefalse%
}  



% Causes a transformation command to be applied to the ``lowlevel''
% transformation matrix. 
%
% #1 - a high-level transformation command
%
% Description:
%
% All subsequent drawing will be transformed additionally by the given
% transformation matrix. Note that PGF will no longer be able to
% ``keep track'' of the coordinates. Also, transformations are applied
% to *everything*, including line thickness and line endings. Most
% often, this is not desirable.
%
% Example:
%
% \pgflowlevel{\pgftransformcm{1}{0}{0}{1}{\pgfpoint{100pt}{0pt}}} % 100bp to the right.
%
% \begin{pgflowlevelscope}{\pgftransformcm{2}{0}{0}{2}{\pgfpointorigin}} % double in in size
%  \pgfmoveto{\pgfpoint{0cm}{0cm}}
%  \pgflineto{\pgflineto{1cm}{1cm}} % actually 2cm/2cm
% \end{pgflowlevelscope}

\def\pgflowlevel#1{%
  {%
    \pgftransformreset%
    #1%
    \pgflowlevelsynccm%
  }%
  \pgf@relevantforpicturesizefalse%
}

\def\pgflowlevelscope#1{\pgfscope\pgflowlevel{#1}}
\def\endpgflowlevelscope{\endpgfscope}

\long\def\pgflowlevelobj#1#2{\pgfscope{\pgflowlevel{#1}#2}\endpgfscope}




\endinput

pgffor.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/utilities/pgffor.code.tex,v 1.2 2005/07/06 15:58:58 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



\newdimen\pgffor@iter
\newdimen\pgffor@skip
\newif\ifpgffor@continue

\let\pgffor@beginhook=\@empty
\let\pgffor@endhook=\@empty
\let\pgffor@afterhook=\@empty

\def\foreach#1in#2{%
  \def\pgffor@var{#1}%
  \def\pgffor@values{#2, \pgffor@stop,}%
  \let\pgffor@body\@empty%
  \global\pgffor@continuetrue%
  \pgffor@collectbody}

\def\pgffor@collectbody{%
  \@ifnextchar\foreach{\pgffor@collectforeach}{%
    \@ifnextchar\bgroup{\pgffor@collectargument}{\pgffor@collectsemicolon}}%
}

\def\pgffor@collectforeach\foreach#1in#2{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body\foreach#1in{#2}}%
  \pgffor@collectbody%
}

\long\def\pgffor@collectargument#1{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body{#1}}%
  \pgffor@iterate%
}


\def\pgffor@collectsemicolon{%
  \let\pgffor@next=\pgffor@collectnormalsemicolon%
  \ifnum\the\catcode`\;=\active\relax%
    \let\pgffor@next=\pgffor@collectactivesemicolon%
  \fi%
  \pgffor@next%
}

\def\pgffor@collectnormalsemicolon#1;{%
  \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body#1;}%
  \pgffor@iterate%
}

{
  \catcode`\;=\active
  
  \gdef\pgffor@collectactivesemicolon#1;{%
    \expandafter\long\expandafter\def\expandafter\pgffor@body\expandafter{\pgffor@body#1;}%
    \pgffor@iterate%
  }
}

\def\pgffor@iterate{%
  \let\pgffor@last\@empty%
  \let\pgffor@prevlast\@empty%
  \expandafter\pgffor@scan\pgffor@values}

\def\pgffor@stop{\pgffor@stop}%
\def\pgffor@dots{...}%

\def\pgffor@scan{\@ifnextchar({\pgffor@scanround}{\pgffor@scanone}}
\def\pgffor@scanround(#1)#2,{\def\pgffor@value{(#1)}\pgffor@scanned}
\def\pgffor@scanone#1,{\def\pgffor@value{#1}\pgffor@scanned}

\def\pgffor@scanned{%
  \ifx\pgffor@value\pgffor@stop%
    \let\pgffor@next=\pgffor@after% done!
  \else%
    \ifx\pgffor@value\pgffor@dots%
      \let\pgffor@next=\pgffor@handledots%
    \else%
      \let\pgffor@next=\pgffor@handlevalue%
    \fi%
    \ifpgffor@continue%
    \else%
      \let\pgffor@next=\pgffor@scan% done!
    \fi%
  \fi%
  \pgffor@next}

\def\pgffor@after{%
  \global\pgffor@continuetrue%
  \pgffor@afterhook}

\def\pgffor@handlevalue{%
  \let\pgffor@prevlast\pgffor@last%
  \let\pgffor@last\pgffor@value%
  \pgffor@invokebody%
  \pgffor@scan%
}

\def\pgffor@invokebody{%
  \begingroup%
    \expandafter\in@\expandafter/\expandafter{\pgffor@var}%
    \ifin@%
      \expandafter\def\expandafter\pgffor@valuerest\expandafter{\pgffor@value//\relax}%
      \expandafter\pgffor@multiassign\pgffor@var/\pgffor@stop/\pgffor@stop/\relax%
    \else%
      \expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@value}%
    \fi%
    \expandafter\pgffor@beginhook\pgffor@body\pgffor@endhook%
  \endgroup%
}


\def\pgffor@multiassign#1/#2/\relax{%
  \def\pgffor@currentvar{#1}%
  \def\pgffor@rest{#2}%
  \ifx\pgffor@currentvar\pgffor@stop%
    \let\pgffor@next=\relax%
  \else%
    \let\pgffor@next=\pgffor@multiassignrest%
  \fi%
  \pgffor@next%
}

\def\pgffor@multiassignrest{\expandafter\pgffor@multiassignfinal\pgffor@valuerest}
\def\pgffor@multiassignfinal#1/#2/\relax{%
  \def\pgffor@test{#2}%
  \ifx\pgffor@test\@empty%
    \def\pgffor@valuerest{#1//\relax}% repeat
  \else%
    \def\pgffor@valuerest{#2/\relax}%
  \fi%
  \expandafter\def\pgffor@currentvar{#1}%
  \expandafter\pgffor@multiassign\pgffor@rest/\relax%
}
  



\def\pgffor@handledots{%
  \ifx\pgffor@last\@empty%
    \PackageError{pgffor}{``...'' not allowed without prior value}{}%
  \fi%
  \pgffor@dotsscanend%
}
\def\pgffor@dotsscanend#1,{%
  \def\pgffor@dotsend{#1}%
  % calculate skip%
  \ifx\pgffor@prevlast\@empty%
    \ifdim\pgffor@dotsend pt>\pgffor@last pt%
      \pgffor@skip=1pt%
    \else%
      \pgffor@skip=-1pt%
    \fi%
  \else%
    \pgffor@skip=\pgffor@last pt%
    \pgffor@iter=\pgffor@prevlast pt%
    \advance\pgffor@skip by-\pgffor@iter%
  \fi%
  \pgffor@iter=\pgffor@last pt%
  % do loop
  \pgffor@loop%
}

\def\pgffor@loop{%
  \advance\pgffor@iter by\pgffor@skip%
  \let\pgffor@next=\pgffor@doloop%
  \ifdim\pgffor@skip<0pt%
    \ifdim\pgffor@iter<\pgffor@dotsend pt%
      \let\pgffor@next=\pgffor@endloop%
    \fi%
  \else%
    \ifdim\pgffor@iter>\pgffor@dotsend pt%
      \let\pgffor@next=\pgffor@endloop%
    \fi%
  \fi%
  \ifpgffor@continue%
  \else%
    \let\pgffor@next=\pgffor@endloop% done!
  \fi%
  \pgffor@next%
}

\def\pgffor@endloop{%
  \pgffor@scan%
}

{\catcode`\p=12\catcode`\t=12\gdef\Pgffor@geT#1pt{#1}}

\def\pgffor@doloop{%
  \begingroup%
    \edef\pgffor@temp{\expandafter\Pgffor@geT\the\pgffor@iter}%
    \edef\pgffor@incheck{{.0/}{\pgffor@temp/}}%
    \expandafter\in@\pgffor@incheck%
    \ifin@%
      \expandafter\pgffor@strip\pgffor@temp%
    \fi%
    \expandafter\in@\expandafter/\expandafter{\pgffor@var}%
    \ifin@%
      \expandafter\def\expandafter\pgffor@valuerest\expandafter{\pgffor@temp//\relax}%
      \expandafter\pgffor@multiassign\pgffor@var/\pgffor@stop/\pgffor@stop/\relax%
    \else%
      \expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@temp}%
    \fi%
    \expandafter\pgffor@beginhook\pgffor@body\pgffor@endhook%
  \endgroup%
  \pgffor@loop%  
}

\def\pgffor@strip#1.0{\def\pgffor@temp{#1}}


\def\breakforeach{\global\pgffor@continuefalse}
  
\endinput

pgflibraryplothandlers.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/libraries/pgflibraryplothandlers.code.tex,v 1.3 2005/07/06 15:58:57 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\newif\ifpgf@plot@started


% This handler converts each plot stream command into a curveto
% command, except for the first, which is converted to the previously
% specified action.
%
% Example:
%
% \pgfpathmoveto{\pgfpointorigin}
% \pgfsetlinetofirstplotpoint
% \pgfplothandlercurveto
% \pgfplotxyfile{mytable}

\def\pgfplothandlercurveto{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@curveto@handler@initial%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\pgf@plot@curveto@handler@finish%
    \global\pgf@plot@startedfalse%
  }%
}

\def\pgf@plot@curveto@handler@initial#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@plot@first@action{\pgfpoint{\pgf@xa}{\pgf@ya}}%
  \xdef\pgf@plot@curveto@first{\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}%
  \global\let\pgf@plot@curveto@first@support=\pgf@plot@curveto@first%
  \global\let\pgf@plotstreampoint=\pgf@plot@curveto@handler@second%
}

\def\pgf@plot@curveto@handler@second#1{%
  \pgf@process{#1}%
  \xdef\pgf@plot@curveto@second{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  \global\let\pgf@plotstreampoint=\pgf@plot@curveto@handler@third%
  \global\pgf@plot@startedtrue%
}

\def\pgf@plot@curveto@handler@third#1{%
  \pgf@process{#1}%
  \xdef\pgf@plot@curveto@current{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  % compute difference vector:
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{\pgf@plot@curveto@first}
  \advance\pgf@xa by-\pgf@x%
  \advance\pgf@ya by-\pgf@y%
  % compute support directions:
  \pgf@xa=\pgf@plottension\pgf@xa%
  \pgf@ya=\pgf@plottension\pgf@ya%
  % first marshal:
  \pgf@process{\pgf@plot@curveto@second}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \advance\pgf@xb by-\pgf@xa%
  \advance\pgf@yb by-\pgf@ya%
  \advance\pgf@xc by\pgf@xa%
  \advance\pgf@yc by\pgf@ya%
  \edef\pgf@marshal{\noexpand\pgfpathcurveto{\noexpand\pgf@plot@curveto@first@support}%
    {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgf@plot@curveto@second}}%
  {\pgf@marshal}%
  % Prepare next:
  \global\let\pgf@plot@curveto@first=\pgf@plot@curveto@second%
  \global\let\pgf@plot@curveto@second=\pgf@plot@curveto@current%
  \xdef\pgf@plot@curveto@first@support{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
}

\def\pgf@plot@curveto@handler@finish{%
  \ifpgf@plot@started%
    \pgfpathcurveto{\pgf@plot@curveto@first@support}{\pgf@plot@curveto@second}{\pgf@plot@curveto@second}%
  \fi%
}


% This commands sets the tension for smoothing of plots.
%
% #1 = tension of curves. A value of 1 will yield a circle when the
%      control points are at quarters of a circle. A smaller value
%      will result in a tighter curve. Default is 0.5. 
%
% Example:
%
% \pgfsetplottension{0.2}

\def\pgfsetplottension#1{%
  \pgf@x=#1pt\relax%
  \pgf@x=0.2775\pgf@x\relax%
  \edef\pgf@plottension{\pgf@sys@tonumber\pgf@x}}
\pgfsetplottension{0.5}


% This handler converts the plot stream command into a curveto
% command that is closed using a closepath.
%
% Example:
%
% \pgfpathmoveto{\pgfpointorigin}
% \pgfplothandlerclosedcurve
% \pgfplotxyfile{mytable}

\def\pgfplothandlerclosedcurve{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@closedcurve@handler@initial%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\pgf@plot@closedcurve@handler@finish%
  }%
}

\def\pgf@plot@closedcurve@handler@initial#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \xdef\pgf@plot@closedcurve@initial{\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}%
  \global\let\pgf@plotstreampoint=\pgf@plot@closedcurve@handler@second%
  \global\pgf@plot@startedfalse%
}

\def\pgf@plot@closedcurve@handler@second#1{%
  \pgf@process{#1}%
  \xdef\pgf@plot@closedcurve@after@initial{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  {\pgfpathmoveto{}}%
  \global\let\pgf@plotstreampoint=\pgf@plot@closedcurve@handler@third%
}

\def\pgf@plot@closedcurve@handler@third#1{%
  \global\pgf@plot@startedtrue%
  \pgf@process{#1}%
  \xdef\pgf@plot@closedcurve@current{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  % compute difference vector:
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{\pgf@plot@closedcurve@initial}
  \advance\pgf@xa by-\pgf@x%
  \advance\pgf@ya by-\pgf@y%
  % compute support directions:
  \pgf@xa=\pgf@plottension\pgf@xa%
  \pgf@ya=\pgf@plottension\pgf@ya%
  % first marshal:
  \pgf@process{\pgf@plot@closedcurve@after@initial}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \advance\pgf@xb by-\pgf@xa%
  \advance\pgf@yb by-\pgf@ya%
  \advance\pgf@xc by\pgf@xa%
  \advance\pgf@yc by\pgf@ya%
  \global\let\pgf@plot@closedcurve@first=\pgf@plot@closedcurve@after@initial%
  \global\let\pgf@plot@closedcurve@second=\pgf@plot@closedcurve@current%
  \xdef\pgf@plot@closedcurve@after@initial@presupport{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}%
  \xdef\pgf@plot@closedcurve@first@support{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
  \global\let\pgf@plotstreampoint=\pgf@plot@closedcurve@handler@fourth%
}

\def\pgf@plot@closedcurve@handler@fourth#1{%
  \pgf@process{#1}%
  \xdef\pgf@plot@closedcurve@current{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  % compute difference vector:
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{\pgf@plot@closedcurve@first}
  \advance\pgf@xa by-\pgf@x%
  \advance\pgf@ya by-\pgf@y%
  % compute support directions:
  \pgf@xa=\pgf@plottension\pgf@xa%
  \pgf@ya=\pgf@plottension\pgf@ya%
  % first marshal:
  \pgf@process{\pgf@plot@closedcurve@second}%
  \pgf@xb=\pgf@x%
  \pgf@yb=\pgf@y%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \advance\pgf@xb by-\pgf@xa%
  \advance\pgf@yb by-\pgf@ya%
  \advance\pgf@xc by\pgf@xa%
  \advance\pgf@yc by\pgf@ya%
  \edef\pgf@marshal{\noexpand\pgfpathcurveto{\noexpand\pgf@plot@closedcurve@first@support}%
    {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgf@plot@closedcurve@second}}%
  {\pgf@marshal}%
  % Prepare next:
  \global\let\pgf@plot@closedcurve@first=\pgf@plot@closedcurve@second%
  \global\let\pgf@plot@closedcurve@second=\pgf@plot@closedcurve@current%
  \xdef\pgf@plot@closedcurve@first@support{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
}

\def\pgf@plot@closedcurve@handler@finish{%
  \ifpgf@plot@started
    %
    % first, draw line from 2nd last to last:
    %
    \pgf@process{\pgf@plot@closedcurve@initial}%
    % compute difference vector:
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\pgf@plot@closedcurve@first}%
    \advance\pgf@xa by-\pgf@x%
    \advance\pgf@ya by-\pgf@y%
    % compute support directions:
    \pgf@xa=\pgf@plottension\pgf@xa%
    \pgf@ya=\pgf@plottension\pgf@ya%
    % first marshal:
    \pgf@process{\pgf@plot@closedcurve@second}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \advance\pgf@xb by-\pgf@xa%
    \advance\pgf@yb by-\pgf@ya%
    \advance\pgf@xc by\pgf@xa%
    \advance\pgf@yc by\pgf@ya%
    \edef\pgf@marshal{\noexpand\pgfpathcurveto{\noexpand\pgf@plot@closedcurve@first@support}%
      {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgf@plot@closedcurve@second}}%
    {\pgf@marshal}%
    \xdef\pgf@plot@closedcurve@first@support{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
    %
    % second, draw line from last point to start:
    %
    \pgf@process{\pgf@plot@closedcurve@after@initial}%
    % compute difference vector:
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\pgf@plot@closedcurve@second}%
    \advance\pgf@xa by-\pgf@x%
    \advance\pgf@ya by-\pgf@y%
    % compute support directions:
    \pgf@xa=\pgf@plottension\pgf@xa%
    \pgf@ya=\pgf@plottension\pgf@ya%
    % first marshal:
    \pgf@process{\pgf@plot@closedcurve@initial}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \advance\pgf@xb by-\pgf@xa%
    \advance\pgf@yb by-\pgf@ya%
    \advance\pgf@xc by\pgf@xa%
    \advance\pgf@yc by\pgf@ya%
    \edef\pgf@marshal{\noexpand\pgfpathcurveto{\noexpand\pgf@plot@closedcurve@first@support}%
      {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgf@plot@closedcurve@initial}}%
    {\pgf@marshal}%
    %
    % third, draw line from first to second point:
    %
    \edef\pgf@marshal{\noexpand\pgfpathcurveto{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
      {\noexpand\pgf@plot@closedcurve@after@initial@presupport}{\noexpand\pgf@plot@closedcurve@after@initial}}%
    {\pgf@marshal}%
    \pgfpathclose%
  \fi%
}





% This handler converts each point in a stream into a line from the
% $y$-axis to the given points coordinate, resulting in a
% ``comb.'' 
%
% Example:
%
% \pgfplothandlerxcomb
% \pgfplotxyfile{mytable}

\def\pgfplothandlerxcomb{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@xcomb@handler%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}

\def\pgf@plot@xcomb@handler#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgfpathmoveto{\pgfpoint{0pt}{\pgf@ya}}%
  \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}%
}


% This handler converts each point in a stream into a line from the
% $x$-axis straight up to the given points coordinate, resulting in a
% ``comb.'' 
%
% Example:
%
% \pgfplothandlerycomb
% \pgfplotxyfile{mytable}

\def\pgfplothandlerycomb{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@ycomb@handler%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}

\def\pgf@plot@ycomb@handler#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{0pt}}%
  \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}%
}






% This handler converts each point in a stream into a line from the
% origin to the point's coordinate, resulting in a ``star''.
%
% Example:
%
% \pgfplothandlerpolarcomb
% \pgfplotxyfile{mytable}

\def\pgfplothandlerpolarcomb{%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@polarcomb@handler%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}

\def\pgf@plot@polarcomb@handler#1{%
  \pgf@process{#1}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgfpathmoveto{\pgfpointorigin}%
  \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}%
}




% This handler draws a given mark at each point. 
%
% #1 = some code to be executed at each point (with the coordinate
%      system translated to that point).
%      Typically, this code will be \pgfuseplotmark{whatever}.
%
% Example:
%
% \pgfplothandlermark{\pgfuseplotmark{*}}
% \pgfplotxyfile{mytable}

\def\pgfplothandlermark#1{%
  \def\pgf@plot@mark{#1}%
  \def\pgf@plotstreamstart{%
    \global\let\pgf@plotstreampoint=\pgf@plot@mark@handler%
    \global\let\pgf@plotstreamspecial=\@gobble%
    \global\let\pgf@plotstreamend=\relax%
  }%
}

\def\pgf@plot@mark@handler#1{%
  {\pgftransformshift{#1}\pgf@plot@mark}%
}


% Define a new plot mark for use with \pgfplotmark.
%
% #1 = a plot mark mnemonic
% #2 = code for drawing the mark
%
% Example:
%
% \pgfdeclareplotmark{*}{\pgfpathcircle{\pgfpointorigin}{2pt}\pgfusepathqfill}

\def\pgfdeclareplotmark#1#2{\expandafter\def\csname pgf@plot@mark@#1\endcsname{#2}}


% Set the size of plot marks. For circles, this will be the radius,
% for other shapes it should be about half the width/height.
%
% Example:
%
% \pgfsetplotmarksize{1pt}

\def\pgfsetplotmarksize#1{\setlength\pgfplotmarksize{#1}}

\newdimen\pgfplotmarksize
\pgfplotmarksize=2pt


% Insert a plot mark's code at the origin.
%
% #1 = plot mark mnemonic
%
% Example:
%
% \pgfuseplotmark{*}

\def\pgfuseplotmark#1{\csname pgf@plot@mark@#1\endcsname}


% A stroke-filled circle mark

\pgfdeclareplotmark{*}
{%
  \pgfpathcircle{\pgfpointorigin}{\pgfplotmarksize}
  \pgfusepathqfillstroke
}


% A plus-sign like mark

\pgfdeclareplotmark{+}
{%
  \pgfpathmoveto{\pgfpoint{-\pgfplotmarksize}{0pt}}
  \pgfpathlineto{\pgfpoint{\pgfplotmarksize}{0pt}}
  \pgfpathmoveto{\pgfpoint{0pt}{\pgfplotmarksize}}
  \pgfpathlineto{\pgfpoint{0pt}{-\pgfplotmarksize}}
  \pgfusepathqstroke
}


% An x-shaped mark

\pgfdeclareplotmark{x}
{%
  \pgfpathmoveto{\pgfpoint{-.70710678\pgfplotmarksize}{-.70710678\pgfplotmarksize}}
  \pgfpathlineto{\pgfpoint{.70710678\pgfplotmarksize}{.70710678\pgfplotmarksize}}
  \pgfpathmoveto{\pgfpoint{-.70710678\pgfplotmarksize}{.70710678\pgfplotmarksize}}
  \pgfpathlineto{\pgfpoint{.70710678\pgfplotmarksize}{-.70710678\pgfplotmarksize}}
  \pgfusepathqstroke
}

% See pgflibraryplotmarks for more plot marks






\endinput

pgfrcs.code.tex
% Copyright 2005 by Till Tantau <tantau@users.sourceforge.net>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

% The purpose of this file is to define the command
% \ProvidesPackageRCS, which should be followed by an RCS id
% string. This command will also be available in plain TeX, where it
% prints out a message to the log.


\def\pgfversion{1.01}


\ifx\pgfrcsloaded\undefined
\def\pgfrcsloaded{}

\edef\pgfrcsatcode{\the\catcode`\@}
\catcode`\@=11

\def\@empty{}

% Get date and version from RCS Ids
\def\pgf@parseid $#1: #2.#3,v #4 #5/#6/#7 #8${%
  \pgf@parsercsfile$#2/$
  \def\pgf@rcssuffix{#3}
  \def\pgf@rcsrevision{#4}
  \def\pgf@rcsdate{#5/#6/#7}
}
\def\pgf@parsercsfile$#1/#2${
  \def\pgf@temp{#2}
  \ifx\pgf@temp\@empty
    \def\pgf@rcsfile{#1}
  \else
    \pgf@parsercsfile$#2$
  \fi}

\def\ProvidesFileRCS $#1${
  \pgf@parseid $#1$
  \ProvidesFile{\pgf@rcsfile.\pgf@rcssuffix}[\pgf@rcsdate\space (rcs-revision \pgf@rcsrevision)]
}

\def\ProvidesPackageRCS{%
  \def\pgf@rcsadditional{}%
  \afterassignment\pgfrcs@checkforoptional\let\next=}

\def\pgfrcs@checkforoptional{%
  \ifx\next[%
    \let\next=\pgfrcs@getoptional%
  \else
    \let\next=\pgfrcs@package%
  \fi%
  \next}%}

\def\pgfrcs@getoptional#1] ${%
  \def\pgf@rcsadditional{#1}%
  \pgfrcs@package%
}

\def\pgfrcs@package#1${
  \pgf@parseid $#1$
  \ProvidesPackage{\pgf@rcsfile}[\pgf@rcsdate\space\pgf@rcsadditional\space(rcs-revision \pgf@rcsrevision)]
}

\def\ProvidesClassRCS $#1$ [#2]{%
  \pgf@parseid $#1$
  \ProvidesClass{\pgf@rcsfile}[\pgf@rcsdate\space#2\space (rcs-revision \pgf@rcsrevision)]
}

\ifx\ProvidesPackage\@undefined
  % plain tex
  \def\ProvidesPackage#1[#2]{\wlog{Loading package #1 version #2.}}
\fi

\ifx\ProvidesFile\@undefined
  % plain tex
  \def\ProvidesFile#1[#2]{\wlog{Loading file #1 version #2.}}
\fi

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/utilities/pgfrcs.code.tex,v 1.8 2005/11/14 17:37:52 tantau Exp $

\catcode`\@=\pgfrcsatcode

\fi


pgfsys.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys.code.tex,v 1.9 2005/10/18 18:03:38 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.




%
% The following conversion functions are used to convert from TeX
% dimensions to postscript/pdf points.
% 
{\catcode`\p=12\catcode`\t=12\gdef\Pgf@geT#1pt{#1}}

\def\pgf@sys@tonumber#1{\expandafter\Pgf@geT\the#1}

\def\pgf@sys@bp@correct#1{#1=0.99627#1}

\def\pgf@sys@bp#1{%
  {%
    \pgf@x=#1\relax%
    \pgf@x=0.99627\pgf@x%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x\space}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\pgfsysprotocol@currentprotocol\temp}%
    \xdef\pgfsysprotocol@currentprotocol{\the\toks@}%
  }%
}
\def\pgf@sys@pt#1{%
  {%
    \pgf@x=#1\relax%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x\space}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\pgfsysprotocol@currentprotocol\temp}%
    \xdef\pgfsysprotocol@currentprotocol{\the\toks@}%
  }%
}

% internal dimensions that are always present when pgsys is loaded.
\newdimen\pgf@x
\newdimen\pgf@y
\newdimen\pgf@xa
\newdimen\pgf@ya
\newdimen\pgf@xb
\newdimen\pgf@yb
\newdimen\pgf@xc
\newdimen\pgf@yc


% The following \if decides, whether even-odd filling and clipping is
% to be used or normal the non-zero winding number rule. See the
% pdf-documentation for details on what these rules are.

\newif\ifpgfsys@eorule



% In the following dummy definitions of the pgf system commands are
% given. The individual drivers must overwrite these definitions,
% preferably all of them. If some system command is used that has not
% been overwritten, the command fails with a warning.
%
% In some cases, some pgf system commands are just shorthands for a
% series of more complicated commands. In this case, a default
% implementation is given in this file, but a driver may choose to
% overwrite this default implementation with a more effecient
% version. For example, a closestroke is the same as a closepath
% followed by a stroking, but in pdf there is a special shorthand for
% this. So, the pdf driver overwrites \pgfsys@closestroke, while the
% postscript driver does not.
%
% The commands for which default implementations are available are
% given at the end.

\def\pgf@sys@fail#1{%
  \expandafter\ifx\csname pgf@sys@fail@#1\endcsname\@empty%
  \else%
    \expandafter\global\expandafter\let\csname pgf@sys@fail@#1\endcsname=\@empty%
    \PackageWarning{pgf}{%
      Your graphic driver \pgfsysdriver\space does not supported #1. This warning is given only once}%
  \fi%
}



\def\pgfsys@invoke{\pgf@sys@fail{invoking specials}}
% This command is used whenever some literal text needs to be inserted
% into the resulting .pdf, .ps, or .dvi file. Note that most
% \pgfsys@xxxx commands will not directly call this command, but,
% rather, use the protocolling mechanism to record their literal
% text. It is then left to the discretion of the protocolling
% mechansim to insert the literal text at some appropriate, later
% time. 
%
% This command should only be called when \pgfsys@beginpicture has
% been called previously and when the picture has not been suspended
% using \pgfsys@beginhbox.


\def\pgfsys@outerinvoke{\pgfsys@invoke}
% This command can be used to insert protocolled graphic commands
% outside any picture. This is extremely dangerous, but sometimes
% useful. By default, this command does the same as inside pictures. 



%
%
% Path construction commands
%
%

\def\pgfsys@moveto#1#2{\pgf@sys@fail{path constructions}}
% This command is used to start a path at a specific point (#1bp,#2bp)
% or to move the current point of the current path to (#1bp,#2bp)
% without drawing anything upon stroking (the current path is
% `interrupted'). 
%
% Here (and in the following) the coordinates are in TeX's big points
% (bp), unless the coordinate system has been scaled. A big point is
% 1/72 inches. Note that TeX's point pt is 1/72.27 inches.
%
% Example:
%
% \pgfsys@moveto{10}{10}
% \pgfsys@lineto{0}{0}
% \pgfsys@stroke
%
% This will draw a line from (10bp,10bp) to the origin of the picture.

\def\pgfsys@lineto#1#2{\pgf@sys@fail{path constructions}}
% Continue the current path to (#1bp,#2bp) with a line.

\def\pgfsys@curveto#1#2#3#4#5#6{\pgf@sys@fail{path constructions}}
% Continue the current path with a bezier curver to (#5bp,#6bp). The
% control points of the curve are at (#1bp,#2bp) and (#3bp,#4bp).

\def\pgfsys@rect#1#2#3#4{\pgf@sys@fail{path constructions}}
% Append a rectangle to the current path whose lower left corner is at
% (#1bp,#2bp) and whose width/height is given by (#3bp,#4bp).
%
% This command can be `mapped back' to moveto and lineto commands, but
% it is included since pdf has a special, quick version of this command.

\def\pgfsys@closepath{\pgf@sys@fail{path constructions}}
% Close the current path. This results in joining the current point of
% the path with the point specified by the last moveto
% operation. Typically, this is preferable over using lineto to the
% last point specified by a moveto, since the line starting at this
% point and the line ending at this point will be smoothly joined by
% closepath. 
%
% Example:
%
% \pgfsys@moveto{0}{0}
% \pgfsys@lineto{10}{10}
% \pgfsys@lineto{0}{10}
% \pgfsys@closepath
% \pgfsys@stroke
%
% versus
%
% \pgfsys@moveto{0}{0}
% \pgfsys@lineto{10}{10}
% \pgfsys@lineto{0}{10}
% \pgfsys@lineto{0}{0}
% \pgfsys@stroke
% 
% The difference between the above will be that in the second triangle
% the corner at the origin will be wrong; it will just be the overlay
% of two lines going in different directions, not a sharp pointed
% corner.






%
%
% Stroking and filling commands
%
%

\def\pgfsys@stroke{\pgf@sys@fail{path usage}}
% Stroke the current path (as if it were drawn with a pen). A number
% of so-called graphic state parameters influence this, which can be
% set in different ways:
%
% - linewidth
%   The `thickness' of the line. A width of 0 is the thinnest width
%   renderable on the device. On a high-resolution printer this may
%   become invisible and should be avoided. A good choice is 0.4pt,
%   which is the default.
%
% - stroke color
%   This special color is used for stroking. If it is not set, the
%   current color is used.
%
% - cap
%   The cap describes how the endings of lines a drawn. A round cap
%   adds a little half circle to these endings. A butt cap ends the
%   lines exactly at the end (or start) point without anything
%   added. A rectangular cap ends the lines like the butt cap, but the
%   lines protrude over the endpoint by the line thickness. (See also
%   the pdf or postscript manual). If the path has been closed, no cap
%   is drawn.
%
% - join
%   This describes how a bend (a join) in a path is rendered. A round
%   join draws bends using small arcs. A bevel join just draws the two
%   lines and then fills the join minimally so that it becomes
%   convex. A miter join extends the lines so that they form a single
%   sharp corner, but only up to a certain miter limit. (See the pdf
%   or postscript manual once more).
%
% - dash
%   The line may be dashed according to a dashing pattern.
%
% - clipping area
%   If a clipping area is established, only those parts of the path
%   that are inside the clipping area will be drawn.
%
% In addition to stroking a path, the path may also be used for
% clipping after it has been stroked. This will happen if the
% \pgfsys@clipnext is used prior to this command, see there for
% details.

\def\pgfsys@fill{\pgf@sys@fail{path usage}}
% This command fills the area surrounded by the current path. If the
% path has not yet been closed, it is closed prior to filling. The
% path itself is not stroked. For self-intersecting paths or paths
% consisting of multiple parts, the nonzero winding number rule is
% used to determine whether a point is inside or outside the
% path, except if \ifpgfsys@eorule holds -- in which case the even-odd
% rule should be used. (See the pdf or postscript manual for details.) 
%
% The following graphic state parameters influence the filling:
%
% - fill color
%   If the fill color is not especially set, the current color is
%   used. 
%
% - clipping area
%   If a clipping area is established, only those parts of the filling
%   area that are inside the clipping area will be drawn.
%
% In addition to filling the path, the path will also be used for
% clipping if \pgfsys@clipnext is used prior to this command.

\def\pgfsys@fillstroke{\pgf@sys@fail{path usage}}
% First, the path is filled, then the path is stroked. If the fill and
% stroke colors are the same (or if they are not specified and the
% current color is used), this yields almost the same as a
% \pgfsys@fill. However, due to the line thickness of the stroked
% path, the fillstroked area will be slightly larger.
%
% In addition to stroking and filling the path, the path will also be
% used for clipping if \pgfsys@clipnext is used prior to this command.

\def\pgfsys@clipnext{\pgf@sys@fail{path usage}}
% This command should be issued after a path has been constructed, but
% before it has been stroked and/or filled or discarded. When the
% command is used, the next stroking/filling/discarding command will
% first be executed normally. Then, afterwards, the just-used path
% will be used for subsequent clipping. If there has already been a
% clipping region, this region is intersected with the new clipping
% path (the clipping cannot get bigger). The nonzero winding number
% rule is used to determine whether a point is inside or outside the
% clipping area or the even-odd rule, depending on whether
% \ifpgfsys@eorule holds.

\def\pgfsys@discardpath{\pgf@sys@fail{path usage}}
% Normally, this command should `throw away' the current path.
% However, after \pgfsys@clipnext has been called, the current path
% should subsequently be used for clipping. See \pgfsys@clipnext for
% details. 





%
%
% Stroking options
%
%
\def\pgfsys@setlinewidth#1{\pgf@sys@fail{setting the line width}}
% Sets the width of lines, when stroked, to #1bp.

\def\pgfsys@buttcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a butt cap. See \pgfsys@stroke.

\def\pgfsys@roundcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a round cap. See \pgfsys@stroke.

\def\pgfsys@rectcap{\pgf@sys@fail{setting the line cap}}
% Sets the cap to a rectangular cap. See \pgfsys@stroke.

\def\pgfsys@miterjoin{\pgf@sys@fail{setting the line join}}
% Sets the join to a miter join. See \pgfsys@stroke.

\def\pgfsys@setmiterlimit#1{\pgf@sys@fail{setting the line cap}}
% Sets the miter limit of lines to #1. See the pdf or postscript
% documentation.

\def\pgfsys@roundjoin{\pgf@sys@fail{setting the line cap}}
% Sets the join to a round join. See \pgfsys@stroke.

\def\pgfsys@beveljoin{\pgf@sys@fail{setting the line cap}}
% Sets the join to a bevel join. See \pgfsys@stroke.

\def\pgfsys@setdash#1#2{\pgf@sys@fail{setting the dashing pattern}}
% Sets the dashing patter. #1 should be a list of lengths given in big
% points (bp) separated by spaces. #2 should be a single value given
% in bp.
%
% The list of values in #1 is used to determine the lengths of the
% `on' phases of the dashing and of the `off' phases. For example, if
% #1 is `3 4', then the dashing pattern is `3bp on followed by 4bp
% off, followed by 3bp on, followed by 4bp off, and so on'. A pattern
% of `.5 4 3 1.5' means `.5bp on, 4bp off, 3bp on, 1.5bp off, .5bp on,
% ...'. If the number of entries is odd, the last one is used twice,
% so `3' means `3bp on, 3bp off, 3bp on, 3bp off,...'. An empty list
% means `always on'.
%
% The second argument determines the `phase' of the pattern. For
% example, for a pattern of `3 4' and a phase of `1', the pattern
% would start: `2bp on, 4bp off, 3bp on, 4bp off, 3bp on, 4bp off...'.




%
%
% Opacity stuff
%
%

\def\pgfsys@stroke@opacity#1{\pgf@sys@fail{opacity}}
% Sets the opacity of stroking operations. 1 means fully opaque, 0
% means fully transparent.

\def\pgfsys@fill@opacity#1{\pgf@sys@fail{opacity}}
% Sets the opacity of filling operations. 1 means fully opaque, 0
% means fully transparent.




%
%
% Color stuff
%
%

\def\pgfsys@color@rgb@stroke#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given rgb tuple
% (numbers between 0 and 1). 
%
% Example: Make stroked text dark red: \pgfsys@color@rgb@stroke{0.5}{0}{0}
%
% The special stroking color is only used if the stroking color has
% been set since the last \color command. Thus, each \color command
% should reset both the stroking and filling colors.

\def\pgfsys@color@rgb@fill#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given rgb tuple
% (numbers between 0 and 1). This color may be different from the
% stroking color.

\def\pgfsys@color@rgb#1#2#3{\pgfsys@color@rgb@stroke{#1}{#2}{#3}\pgfsys@color@rgb@fill{#1}{#2}{#3}}
% Sets the color used for filling and stroking operations. This is a
% ``low-level'' version of the \color command. It is currently only
% used by the plain tex version to support colors.

\def\pgfsys@color@cmyk@stroke#1#2#3#4{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given cymk tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmyk@fill#1#2#3#4{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given cymk tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmyk#1#2#3#4{\pgfsys@color@cmyk@stroke{#1}{#2}{#3}{#4}\pgfsys@color@cmyk@fill{#1}{#2}{#3}{#4}}
% Sets the color used for filling and stroking operations.

\def\pgfsys@color@cmy@stroke#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given cym tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmy@fill#1#2#3{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given cym tuple
% (numbers between 0 and 1). 

\def\pgfsys@color@cmy#1#2#3{\pgfsys@color@cmy@stroke{#1}{#2}{#3}\pgfsys@color@cmy@fill{#1}{#2}{#3}}
% Sets the color used for filling and stroking operations.

\def\pgfsys@color@gray@stroke#1{\pgf@sys@fail{color}}
% Sets the color used for stroking operations to the given gray level 
% (number between 0 and 1). 

\def\pgfsys@color@gray@fill#1{\pgf@sys@fail{color}}
% Sets the color used for filling operations to the given gray level 
% (number between 0 and 1). 

\def\pgfsys@color@gray#1{\pgfsys@color@gray@stroke{#1}\pgfsys@color@gray@fill{#1}}
% Sets the color used for filling and stroking operations.

\newif\ifpgfsys@color@reset@inorder
% This if decides whether the color resetting of the
% \pgfsys@color@reset command may assume that all color commands are
% given ``in order.'' This means that this command will not be called,
% say, at the beginning of a box that is later inserted at a point
% where a fill color was actively set. This may allow the command to
% produce more compact code when it ``knows'' that no special fill or
% stroke color has been set.
\pgfsys@color@reset@inordertrue


\def\pgfsys@color@reset{}
% This command will be called when the \color command is used. It
% should purge any internal settings of stroking and filling
% color. After this call, till the next use of a command like
% \pgfsys@color@rgb@fill, the current color installed by the \color
% command should be used.

\def\pgfsys@color@unstacked#1{}
% This slightly obscure command causes the color stack to be
% tricked. When called, this command should set the current color to
% #1 without causing any change in the color stack. 



%
%
% Coordinate system transformations
%
%

\def\pgfsys@transformcm#1#2#3#4#5#6{\pgf@sys@fail{transformations}}
% Perform a concatenation of the low-level current transformation
% matrix with the matrix given by the values #1 to #6. The
% transformation matrix is a transformation on a homogeneous
% 2D-coordinate system. See the pdf or postscript manual for details. 




%
%
% Graphic state saving and restoring.
%
%

\def\pgfsys@beginscope{\pgf@sys@fail{scoping}}
% Saves the current graphic state on a graphic state stack. All
% changes to the graphic state parameters mentioned for \pgfsys@stroke
% and \pgfsys@fill will be local to the current graphic state and will
% the old values will be restored after endscope is used.
%
% WARNING: pdf and postscript differ with respect to the question of
% whether the current path is part of the graphic state or not. For
% this reason, you should never use this command unless the path is
% currently empty. For example, it might be a good idea to use
% discardpath prior to calling this command. 

\def\pgfsys@endscope{\pgf@sys@fail{scoping}}
% Restores the last saved graphic state.




%
%
% Special commands
%
%

\def\pgfsys@imagesuffixlist{}
% A list of suffixes, separated by `:', that will be tried when
% searching for an image.



%
%
% Special commands
%
%


\def\pgfsys@definemask{\pgf@sys@fail{masking}}
% This command declares a mask for usage with images. It works similar
% to \pgfsys@defineimage: Certain macros are set when the command is
% called. The result should be to set the macro \pgf@mask to a pdf
% object count that can subsequently be used as a soft mask. The
% following macros will be set when this command is invoked:
%
% - \pgf@filename
%   File name of the mask to be defined.
%
% - \pgf@maskmatte
%   The so-called matte of the mask (see the pdf documentation for
%   details). The matte is a color specification consisting of 1, 3 or
%   4 numbers between 0 and 1. The number of numbers depends on the
%   number of color channels in the image (not in the mask!). It will
%   be assumed that the image has been preblended with this color.




%
%
% Shading commands
%
%

\def\pgfsys@horishading#1#2#3{\pgf@sys@fail{shadings}}
% Declares a horizontal shading for later use. The effect of this
% command should be the definition of a macro called `@pgfshading#1!'
% (or \csname @pdfshading#1!\endcsname, to be precise). When invoked,
% this new macro should insert a shading at the current position.
%
% #1 is the name of the shading, which is also used in the output
% macro name. #2 is the height of the shading and must be given as a
% TeX dimension like `2cm' or `10pt'. #3 is a shading color
% specification as specified in the pgfuserguide. The shading
% specification implicitly fixes the width of the shading. 
%
% When `@pgfshading#1!' is invoked, it should insert a box of height
% #2 and the width implicit in the shading declaration.

\def\pgfsys@vertshading#1#2#3{\pgf@sys@fail{shadings}}
% Like horishading, only for vertical shadings. This time, the height
% of the shading is implicit in #3 and the width is given as #2.

\def\pgfsys@radialshading#1#2#3{\pgf@sys@fail{shadings}}
% Declares a radial shading. Like the previous macros, this command
% should setup the macro `@pgfshading#1!', which upon invocation
% should insert a radial shading whose size is implicit in #3. 
%
% The parameter #2 is a pgf point specification if the starting point
% of the shading. See the pgfuserguide for details.

\def\pgfsys@shadingoutsidepgfpicture#1{%
  #1%
}
% This command gets the definition of a shading (@pgfshadingxxxx!) as
% an argument and should insert this shading into the normal text.
%
% This command has a default implementation.


\def\pgfsys@shadinginsidepgfpicture#1{%
  \pgf@makehbox{#1}%
  \setbox\pgf@hbox=\hbox{\hskip-.5\wd\pgf@hbox\lower.5\ht\pgf@hbox\hbox{\box\pgf@hbox}}%
  \pgfqbox{\pgf@hbox}%
}
% This command works like \pgfsys@shadingoutsidepgfpicture, only it is
% called when a shading should be inserted inside a picture. This
% command should insert the shading centered on the origin (which will
% typically have been low-level translated somewhere else.)
%
% This command has a default implementation.





%
%
% Commands having a default implementation. These commands only need
% not be implemented by drivers if this results in a better
% preformance. 
%
%


\def\pgfsys@closestroke{\pgfsys@closepath\pgfsys@stroke}
% This command should have the same effect as first closing the path
% and then stroking it.


\def\pgfsys@transformshift#1#2{\pgfsys@transformcm{1}{0}{0}{1}{#1}{#2}}
% This command will change the origin of the low-level coordinate
% system to (#1bp,#2bp).

\def\pgfsys@transformxyscale#1#2{\pgfsys@transformcm{#1}{0}{0}{#2}{0bp}{0bp}}
% This command will scale the low-level coordinate system (and
% everything that is drawn) by a factor of #1 in x-directed and #2 in
% y-direction. Note that this applies to everything, including
% lines. So a scaled line will have a different width and may even
% have a different width when going along the x-axis and when going
% along the y-axis, if the scaling is different in these directions.

\def\pgfsys@hbox#1{%
  \pgfsys@beginscope%
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \box#1%
  \pgfsys@endscope%
}
% Called to insert a TeX hbox into a pgfpicture. 

\def\pgfsys@hboxsynced#1{%
  {\pgfsys@beginscope\pgflowlevelsynccm\pgfsys@hbox#1\pgfsys@endscope}%
}
% Called to insert a TeX hbox into a pgfpicture, but with the current
% coordiante transformation matrix synced with the canvas
% transformation matrix. 
%
% In essence, this command does the same as if you first said
% \pgflowlevelsynccm and then \pgfsys@hbox. However, a driver may
% choose to use a ``TeX-translation'' for the translation part of the
% transformation cm. This will ensure that hyperlinks ``survive'' at
% least translations. 

\def\pgfsys@beginpicture{}
% Called at the beginning of a pgfpicture. Used to setup things.

\def\pgfsys@endpicture{}
% Called at the end of a pgfpicture. 

\def\pgfsys@typesetpicturebox#1{%
  \setlength\pgf@x{\pgf@shift@baseline}%
  \advance\pgf@x by-\pgf@picminy\relax%
  \advance\pgf@picmaxy by-\pgf@picminy\relax% maxy is now the height
  \advance\pgf@picmaxx by-\pgf@picminx\relax% maxx is now the width
  \setbox#1=\hbox{\hskip-\pgf@picminx\lower\pgf@picminy\box#1}%
  \ht#1=\pgf@picmaxy%
  \wd#1=\pgf@picmaxx%
  \dp#1=0pt%
  \leavevmode\raise-\pgf@x\box#1%
}
% Called after a picture has been typeset in box #1. This
% command should insert the box into the normal TeX code. The box #1
% will still be a ``raw'' box that contains only the \special's. The
% job of this command is to resize and shift this box according to the
% baseline shift and the size of the box.
%
% This command has a default implementation.

\def\pgfsys@beginpurepicture{\pgfsys@beginpicture}
% This version of the beginpicture command can be used for pictures
% that are guaranteed not to contain any hboxes. In this case, a
% driver might provide a more compact version of the command.

\def\pgfsys@endpurepicture{\pgfsys@endpicture}
% Called at the end of a ``pure'' pgfpicture.

\def\pgfsys@defineimage{%
  \ifx\pgf@imagewidth\@empty\else\edef\pgf@imagewidth{width=\pgf@imagewidth,}\fi%
  \ifx\pgf@imageheight\@empty\else\edef\pgf@imageheight{height=\pgf@imageheight,}\fi%
  \ifx\pgf@imagepage\@empty\else\edef\pgf@imagepage{page=\pgf@imagepage,}\fi%
  \edef\pgf@image{\noexpand\includegraphics[\pgf@imageheight\pgf@imagewidth]{\pgf@filename}}%
}
% Called, when an image should be defined. 
%
% This command does not take any parameters. Instead, certain macros
% will be preinstalled with appropriate values when this command is
% invoked. These are:
%
% - \pgf@filename
%   File name of the image to be defined.
%
% - \pgf@imagewidth
%   Will be set to the desired (scaled) width of the image.
%
% - \pgf@imageheight
%   Will be set to the desired (scaled) height of the image.
%
%   If this macro and also the height macro are empty, the image
%   should have its `natural' size.
%
%   If exactly only of them is specified, the undefined value the
%   image is scaled so that the aspect ratio is kept.
%
%   If both are set, the image is scaled in both directions
%   independently, possibly changing the aspect ratio.
%
%
% The following macros presumable mostly make sense for drivers that
% can handle pdf: 
%
% - \pgf@imagepage
%   The desired page number to be extracted from a multi-page
%   `image'. 
%
% - \pgf@imagemask
%   If set, it will be set to `/SMask x 0 R', where x is the pdf
%   object number of a soft mask to be applied to the image.
%
% - \pgf@imageinterpolate
%   If set, it will be set to `/Interpolate true' or  `/Interpolate
%   false', indicating whether the image should be interpolated in
%   pdf. 
%
%
% The command should now setup the macro \pgf@image such that calling
% this macro will result in typesetting the image. Thus, \pgf@image is
% the `return value' of the command.


\def\pgfsys@defobject#1#2#3#4{%
  \pgfsysprotocol@getcurrentprotocol\pgfsys@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\@empty%
    \pgfsysprotocol@bufferedtrue%
    #4%
    \pgfsysprotocol@getcurrentprotocol\pgfsys@@temp%
    \expandafter\global\expandafter\let\csname #1\endcsname=\pgfsys@@temp%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfsys@temp%
}
% Declares an object for later use. The idea is that the object can be
% precached in some way and then be rendered more quickly when used
% several times. For example, an arrow head might be defined and
% prerendered in this way.
%
% The parameter #1 is the name for later use. #2 and #3 are pgf points
% specifying a bounding box for the object. #4 is the code for the
% object. The code may only contain protocollable code.


\def\pgfsys@useobject#1#2{%
  \pgfsysprotocol@getcurrentprotocol\pgfsys@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\@empty%
    \pgfsysprotocol@bufferedfalse%
    #2%
    \expandafter\pgfsysprotocol@setcurrentprotocol\csname #1\endcsname%
    \pgfsysprotocol@invokecurrentprotocol%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfsys@temp%
}
% Renders a previously declared object. The first parameter is the
% name of the the object. The second parameter is extra code that
% should be executed right *before* the object is rendered. Typically,
% this will be some transformation code. 


\def\pgfsys@begininvisible{\pgfsys@transformcm{1}{0}{0}{1}{2000bp}{2000bp}}
% Between this command and the closing endinvisible, all output should
% be suppressed. Nothing should be drawn at all, which includes all
% paths, images and shadings.

\def\pgfsys@endinvisible{\pgfsys@transformcm{1}{0}{0}{1}{-2000bp}{-2000bp}}
% Ends the invisibilty section, unless invisibility blocks have been
% nested. In this case, only the `last' one restores visibility.




% Discern the driver:
\input pgf.cfg

\PackageInfo{pgfsys}{Driver file for pgf: \pgfsysdriver}
\InputIfFileExists{\pgfsysdriver}{}{%
  \PackageError{pgfsys}{Driver file ``\pgfsysdriver'' not found.}{}}

\endinput

pgfsysprotocol.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsysprotocol.code.tex,v 1.1.1.1 2005/06/29 12:14:04 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.





% This package provides the pgf system protcol layer. Protocolling is
% used to record a bunch of graphic operations so that they can be
% reused quickly at a later point.
%
% Basically, all ``recordable'' \pgfsys@xxxx commands call
% \pgfsysprotocol@protocol for their protocolable literal
% specials. The literal text will either be stored in the current
% protocol. At a later point (actually, normally this happens
% immediately afterwards), the accumulated protocolled text is invoked
% using pgfsys@invokeprotocol.



\let\pgfsysprotocol@currentprotocol=\@empty
\newif\ifpgfsysprotocol@buffered


% Add to the protocol buffered
\def\pgfsysprotocol@literalbuffered#1{%
  \edef\pgfsysprotocol@temp{{#1\space}}%
  \expandafter\g@addto@macro\expandafter\pgfsysprotocol@currentprotocol\pgfsysprotocol@temp%
}

% Add to the protocol
\def\pgfsysprotocol@literal#1{%
  \pgfsysprotocol@literalbuffered{#1}%
  \ifpgfsysprotocol@buffered%
  \else%
    \pgfsysprotocol@flushcurrentprotocol%
  \fi%
}

% Getting and setting the current protocol
\def\pgfsysprotocol@getcurrentprotocol#1{%
  \let#1=\pgfsysprotocol@currentprotocol%
}

\def\pgfsysprotocol@setcurrentprotocol#1{%
  \global\let\pgfsysprotocol@currentprotocol=#1%
}


% Invoking the current protocol
\def\pgfsysprotocol@invokecurrentprotocol{%
  \ifx\pgfsysprotocol@currentprotocol\@empty%
  \else%
    \expandafter\pgfsys@invoke\expandafter{\pgfsysprotocol@currentprotocol}%
  \fi%
}

\def\pgfsysprotocol@flushcurrentprotocol{%
  \pgfsysprotocol@invokecurrentprotocol%
  \pgfsysprotocol@setcurrentprotocol\@empty%
}


\endinput

pgfsyssoftpath.code.tex
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsyssoftpath.code.tex,v 1.1.1.1 2005/06/29 12:14:05 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.



% This package provides the pgf system path abstraction layer. This
% layer is used to construct paths first ``abstractly.'' These
% abstract paths can still be modified, before they are ``made
% concrete.'' 
%
% An abstract path consists of a sequence of basic building blocks,
% each of which is a tuple consisting of two numbers (specifying a
% coordinate) and a token. Possible tokens are:
%
% 1. moveto
% 2. lineto
% 3. rectcorner
% 4. rectsize
% 5. curvetosupporta
% 6. curvetosupportb
% 7. curveto
% 8. closepath
% 9. specialround
%
% A curveto must always be preceeded by a curvetosupporta and a
% curvetosupportb. A non-empty path must always begin with a
% moveto. The coordinates of a closepath are non-specified, currently, 
% but they might be set to the coordinate of the path segment start,
% in the future.



\let\pgfsyssoftpath@currentpath=\@empty
% The current path

\def\pgfsyssoftpath@lastmoveto{{0pt}{0pt}}

% Add a moveto element to the current path
\def\pgfsyssoftpath@moveto#1#2{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@movetotoken{#1}{#2}%
  }}%
  \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
  \xdef\pgfsyssoftpath@lastmoveto{{#1}{#2}}%
}

% Add a lineto element to the current path
\def\pgfsyssoftpath@lineto#1#2{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@linetotoken{#1}{#2}%
  }}%
 \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
}

% Add curveto elements to the current path
\def\pgfsyssoftpath@curveto#1#2#3#4#5#6{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@curvetosupportatoken{#1}{#2}%
    \noexpand\pgfsyssoftpath@curvetosupportbtoken{#3}{#4}%
    \noexpand\pgfsyssoftpath@curvetotoken{#5}{#6}%
  }}%
 \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
}

% Add rectanlge elements to the current path
\def\pgfsyssoftpath@rect#1#2#3#4{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@rectcornertoken{#1}{#2}%
    \noexpand\pgfsyssoftpath@rectsizetoken{#3}{#4}%
  }}%
 \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
}

% Add closepath element to the current path
\def\pgfsyssoftpath@closepath{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@closepathtoken\pgfsyssoftpath@lastmoveto%
  }}%
  \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
}

% Add special element to the current path
\def\pgfsyssoftpath@specialround#1#2{%
  \edef\pgfsyssoftpath@temp{{%
    \noexpand\pgfsyssoftpath@specialroundtoken{#1}{#2}%
  }}%
 \expandafter\g@addto@macro\expandafter\pgfsyssoftpath@currentpath\pgfsyssoftpath@temp%
}


% Getting and setting the current path
\def\pgfsyssoftpath@getcurrentpath#1{%
  \let#1=\pgfsyssoftpath@currentpath%
}

\def\pgfsyssoftpath@setcurrentpath#1{%
  \global\let\pgfsyssoftpath@currentpath=#1%
}


% Invoking the current path
\def\pgfsyssoftpath@invokecurrentpath{%
  \pgfsyssoftpath@currentpath%
}

\def\pgfsyssoftpath@flushcurrentpath{%
  \pgfsyssoftpath@invokecurrentpath%
  \pgfsyssoftpath@setcurrentpath\@empty%
}

% Marshallers
\def\pgfsyssoftpath@movetotoken#1#2{\pgfsys@moveto{#1}{#2}}
\def\pgfsyssoftpath@linetotoken#1#2{\pgfsys@lineto{#1}{#2}}
\def\pgfsyssoftpath@rectcornertoken#1#2#3#4#5{\pgfsys@rect{#1}{#2}{#4}{#5}} % #3 = \pgfsyssoftpath@rectsizetoken
\def\pgfsyssoftpath@curvetosupportatoken#1#2#3#4#5#6#7#8{\pgfsys@curveto{#1}{#2}{#4}{#5}{#7}{#8}}
\def\pgfsyssoftpath@closepathtoken#1#2{\pgfsys@closepath}
\let\pgfsyssoftpath@specialroundtoken=\@gobbletwo


\endinput

%%% Local Variables: 
%%% mode: latex
%%% End: 

tikz.code.tex
\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/frontendlayer/tikz.code.tex,v 1.35 2005/11/09 15:49:25 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\newdimen\tikz@lastx
\newdimen\tikz@lasty
\newdimen\tikz@lastxsaved
\newdimen\tikz@lastysaved

\newdimen\tikzleveldistance
\newdimen\tikzsiblingdistance

\newbox\tikz@figbox
\newbox\tikz@tempbox

\newcount\tikztreelevel
\newcount\tikznumberofchildren
\newcount\tikznumberofcurrentchild

\newcount\tikz@fig@count

\newif\iftikz@node@is@a@label
\newif\iftikz@snaked

\let\tikz@options=\@empty
\let\tikz@transform=\relax
\def\tikz@addoption#1{\expandafter\def\expandafter\tikz@options\expandafter{\tikz@options#1}}
\def\tikz@addmode#1{\expandafter\def\expandafter\tikz@mode\expandafter{\tikz@mode#1}}
\def\tikz@addtransform#1{%
  \ifx\tikz@transform\relax%
    #1%
  \else%
    \expandafter\def\expandafter\tikz@transform\expandafter{\tikz@transform#1}%
  \fi%
}



% Baseline options
\define@key{tikz}{baseline}[0pt]{\pgfsetbaseline{#1}}%

% Draw options
\define@key{tikz}{line width}{\tikz@semiaddlinewidth{#1}}%

\def\tikz@semiaddlinewidth#1{\tikz@addoption{\pgfsetlinewidth{#1}}\setlength\pgflinewidth{#1}}

\define@key{tikz}{cap}{\tikz@addoption{\csname pgfset#1cap\endcsname}}
\define@key{tikz}{join}{\tikz@addoption{\csname pgfset#1join\endcsname}}
\define@key{tikz}{miter limit}{\tikz@addoption{\pgfsetmiterlimit{#1}}}

\define@key{tikz}{dash pattern}{% syntax: on 2pt off 3pt on 4pt ...
  \def\tikz@temp{#1}%
  \ifx\tikz@temp\@empty%
    \def\tikz@dashpattern{}%
    \tikz@addoption{\pgfsetdash{}{0pt}}%
  \else%
    \def\tikz@dashpattern{}%
    \expandafter\tikz@scandashon\@gobble#1o\@nil%
    \edef\tikz@temp{{\tikz@dashpattern}{\noexpand\tikz@dashphase}}%
    \expandafter\tikz@addoption\expandafter{\expandafter\pgfsetdash\tikz@temp}%
  \fi}
\define@key{tikz}{dash phase}{%
  \def\tikz@dashphase{#1}%
  \edef\tikz@temp{{\tikz@dashpattern}{\noexpand\tikz@dashphase}}%
  \expandafter\tikz@addoption\expandafter{\expandafter\pgfsetdash\tikz@temp}%
}%
\def\tikz@dashphase{0pt}

\def\tikz@scandashon n#1o{%
  \expandafter\def\expandafter\tikz@dashpattern\expandafter{\tikz@dashpattern{#1}}%
  \@ifnextchar\@nil{\@gobble}{\tikz@scandashoff}}
\def\tikz@scandashoff ff#1o{%
  \expandafter\def\expandafter\tikz@dashpattern\expandafter{\tikz@dashpattern{#1}}%
  \@ifnextchar\@nil{\@gobble}{\tikz@scandashon}}

\define@key{tikz}{draw opacity}{\tikz@addoption{\pgfsetstrokeopacity{#1}}}

% Double draw options
\define@key{tikz}{double}[]{%
  \def\tikz@temp{#1}%
  \ifx\tikz@temp\@empty%
  \else%
    \def\tikz@double@color{#1}%
  \fi%
  \tikz@addmode{\tikz@mode@doubletrue}}
\define@key{tikz}{double distance}{%
  \setlength{\pgf@x}{#1}%
  \edef\tikz@double@width@distance{\the\pgf@x}%
  \tikz@addmode{\tikz@mode@doubletrue}}

\def\tikz@double@width@distance{0.6pt}
\def\tikz@double@color{white}

% Fill options

\define@key{tikz}{even odd rule}[]{\tikz@addoption{\pgfseteorule}}
\define@key{tikz}{nonzero rule}[]{\tikz@addoption{\pgfsetnonzerorule}}

\define@key{tikz}{fill opacity}{\tikz@addoption{\pgfsetfillopacity{#1}}}


% Joined fill/draw options

\define@key{tikz}{opacity}{\tikz@addoption{\pgfsetstrokeopacity{#1}\pgfsetfillopacity{#1}}}


% Main color options
\define@key{tikz}{color}{%
  \tikz@addoption{%
    \ifx\tikz@fillcolor\@empty%
      \ifx\tikz@strokecolor\@empty%
      \else%
        \pgfsys@color@reset@inorderfalse%
        \let\tikz@strokecolor\@empty%
        \let\tikz@fillcolor\@empty%
      \fi%
    \else%
      \pgfsys@color@reset@inorderfalse%
      \let\tikz@strokecolor\@empty%
      \let\tikz@fillcolor\@empty%
    \fi%
    \colorlet{tikz@color}{#1}%
    \color{tikz@color}%
    \pgfsys@color@reset@inordertrue%
  }%
  \def\tikz@textcolor{#1}}


% Rounding options
\define@key{tikz}{rounded corners}[4pt]{\pgfsetcornersarced{\pgfpoint{#1}{#1}}}
\define@key{tikz}{sharp corners}[]{\pgfsetcornersarced{\pgfpointorigin}}



% Coordinate options
\define@key{tikz}{x}{\tikz@handle@vec{\pgfsetxvec}{\tikz@handle@x}#1\relax}
\define@key{tikz}{y}{\tikz@handle@vec{\pgfsetyvec}{\tikz@handle@y}#1\relax}
\define@key{tikz}{z}{\tikz@handle@vec{\pgfsetzvec}{\tikz@handle@z}#1\relax}

\def\tikz@handle@vec#1#2{\@ifnextchar({\tikz@handle@coordinate#1}{\tikz@handle@single#2}}
\def\tikz@handle@coordinate#1{\tikz@scan@one@point#1}
\def\tikz@handle@single#1#2\relax{#1{#2}}
\def\tikz@handle@x#1{\pgfsetxvec{\pgfpoint{#1}{0pt}}}
\def\tikz@handle@y#1{\pgfsetyvec{\pgfpoint{0pt}{#1}}}
\def\tikz@handle@z#1{\pgfsetzvec{\pgfpoint{#1}{#1}}}


% Transformation options
\define@key{tikz}{scale}{\tikz@addtransform{\pgftransformscale{#1}}}
\define@key{tikz}{xscale}{\tikz@addtransform{\pgftransformxscale{#1}}}
\define@key{tikz}{xslant}{\tikz@addtransform{\pgftransformxslant{#1}}}
\define@key{tikz}{yscale}{\tikz@addtransform{\pgftransformyscale{#1}}}
\define@key{tikz}{yslant}{\tikz@addtransform{\pgftransformyslant{#1}}}
\define@key{tikz}{rotate}{\tikz@addtransform{\pgftransformrotate{#1}}}
\define@key{tikz}{rotate around}{\tikz@addtransform{\tikz@rotatearound{#1}}}
\def\tikz@rotatearound#1{%
  \edef\tikz@temp{#1}% get rid of active stuff
  \expandafter\tikz@rotateparseA\tikz@temp%
}%
\def\tikz@rotateparseA#1:{%
  \def\tikz@temp@rot{#1}%
  \tikz@scan@one@point\tikz@rotateparseB%
}
\def\tikz@rotateparseB#1{%
  \pgf@process{#1}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \pgftransformshift{\pgfpoint{\pgf@xc}{\pgf@yc}}%
  \pgftransformrotate{\tikz@temp@rot}%
  \pgftransformshift{\pgfpoint{-\pgf@xc}{-\pgf@yc}}%
}

\define@key{tikz}{shift}{\tikz@addtransform{\tikz@scan@one@point\pgftransformshift#1\relax}}
\define@key{tikz}{xshift}{\tikz@addtransform{\pgftransformxshift{#1}}}
\define@key{tikz}{yshift}{\tikz@addtransform{\pgftransformyshift{#1}}}
\define@key{tikz}{cm}{\tikz@addtransform{\tikz@parse@cm#1\relax}}
\define@key{tikz}{reset cm}{\tikz@addtransform{\pgftransformreset}}

\def\tikz@parse@cm#1,#2,#3,#4,{%
  \def\tikz@p@cm{{#1}{#2}{#3}{#4}}%
  \tikz@scan@one@point\tikz@parse@cmA}
\def\tikz@parse@cmA#1{%
  \expandafter\pgftransformcm\tikz@p@cm{#1}%
}



% Grid options
\define@key{tikz}{xstep}{\def\tikz@grid@x{#1}}
\define@key{tikz}{ystep}{\def\tikz@grid@y{#1}}
\define@key{tikz}{step}{\def\tikz@grid@x{#1}\def\tikz@grid@y{#1}}

\def\tikz@grid@x{1cm}
\def\tikz@grid@y{1cm}


% Path usage options
\newif\iftikz@mode@double
\newif\iftikz@mode@fill
\newif\iftikz@mode@draw
\newif\iftikz@mode@clip
\newif\iftikz@mode@boundary
\newif\iftikz@mode@shade
\let\tikz@mode=\@empty

\def\tikz@nonetext{none}

\define@key{tikz}{path only}[]{\let\tikz@mode=\@empty}
\define@key{tikz}{shade}[]{\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{fill}[]{%
  \def\tikz@temp{#1}%
  \ifx\tikz@temp\tikz@nonetext%
    \tikz@addmode{\tikz@mode@fillfalse}%
  \else%
    \ifx\tikz@temp\@empty%
    \else%
      \tikz@addoption{\pgfsetfillcolor{#1}}%
      \def\tikz@fillcolor{#1}%
    \fi%
    \tikz@addmode{\tikz@mode@filltrue}%
  \fi%
}
\define@key{tikz}{draw}[]{%
  \def\tikz@temp{#1}%
  \ifx\tikz@temp\tikz@nonetext%
    \tikz@addmode{\tikz@mode@drawfalse}%
  \else%
    \ifx\tikz@temp\@empty%
    \else%
      \tikz@addoption{\pgfsetstrokecolor{#1}}%
      \def\tikz@strokecolor{#1}%
    \fi%
    \tikz@addmode{\tikz@mode@drawtrue}%
  \fi%
}
\define@key{tikz}{clip}[]{\tikz@addmode{\tikz@mode@cliptrue}}
\define@key{tikz}{use as bounding box}[]{\tikz@addmode{\tikz@mode@boundarytrue}}

\define@key{tikz}{save path}{\tikz@addmode{\pgfsyssoftpath@getcurrentpath#1\global\let#1=#1}}

\let\tikz@fillcolor=\@empty
\let\tikz@strokecolor=\@empty


% Shading options
\define@key{tikz}{shading}{\def\tikz@shading{#1}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{shading angle}{\def\tikz@shade@angle{#1}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{top color}{%
  \colorlet{tikz@axis@top}{#1}%
  \colorlet{tikz@axis@middle}{tikz@axis@top!50!tikz@axis@bottom}%
  \def\tikz@shading{axis}\def\tikz@shade@angle{0}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{bottom color}{%
  \colorlet{tikz@axis@bottom}{#1}%
  \colorlet{tikz@axis@middle}{tikz@axis@top!50!tikz@axis@bottom}%
  \def\tikz@shading{axis}\def\tikz@shade@angle{0}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{middle color}{%
  \colorlet{tikz@axis@middle}{#1}%
  \def\tikz@shading{axis}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{left color}{%
  \colorlet{tikz@axis@top}{#1}%
  \colorlet{tikz@axis@middle}{tikz@axis@top!50!tikz@axis@bottom}%
  \def\tikz@shading{axis}\def\tikz@shade@angle{90}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{right color}{%
  \colorlet{tikz@axis@bottom}{#1}%
  \colorlet{tikz@axis@middle}{tikz@axis@top!50!tikz@axis@bottom}%
  \def\tikz@shading{axis}\def\tikz@shade@angle{90}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{ball color}{\colorlet{tikz@ball}{#1}\def\tikz@shading{ball}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{inner color}{\colorlet{tikz@radial@inner}{#1}\def\tikz@shading{radial}\tikz@addmode{\tikz@mode@shadetrue}}
\define@key{tikz}{outer color}{\colorlet{tikz@radial@outer}{#1}\def\tikz@shading{radial}\tikz@addmode{\tikz@mode@shadetrue}}

\def\tikz@shading{axis}
\def\tikz@shade@angle{0}

\pgfdeclareverticalshading[tikz@axis@top,tikz@axis@middle,tikz@axis@bottom]{axis}{100bp}{%
  color(0bp)=(tikz@axis@bottom);
  color(25bp)=(tikz@axis@bottom);
  color(50bp)=(tikz@axis@middle);
  color(75bp)=(tikz@axis@top);
  color(100bp)=(tikz@axis@top)}

\colorlet{tikz@axis@top}{gray}
\colorlet{tikz@axis@middle}{gray!50!white}
\colorlet{tikz@axis@bottom}{white}

\pgfdeclareradialshading[tikz@ball]{ball}{\pgfpoint{-10bp}{10bp}}{%
 color(0bp)=(tikz@ball!15!white);
 color(9bp)=(tikz@ball!75!white);
 color(18bp)=(tikz@ball!70!black);
 color(25bp)=(tikz@ball!50!black);
 color(50bp)=(black)}

\colorlet{tikz@ball}{blue}

\pgfdeclareradialshading[tikz@radial@inner,tikz@radial@outer]{radial}{\pgfpointorigin}{%
 color(0bp)=(tikz@radial@inner);
 color(25bp)=(tikz@radial@outer);
 color(50bp)=(tikz@radial@outer)}

\colorlet{tikz@radial@inner}{gray}
\colorlet{tikz@radial@outer}{white}





% General shape options
\define@key{tikz}{name}{\edef\tikz@fig@name{#1}}

\define@key{tikz}{shape}{\edef\tikz@shape{#1}}

\define@key{tikz}{inner sep}{\def\pgfshapeinnerxsep{#1}\def\pgfshapeinnerysep{#1}}
\define@key{tikz}{inner xsep}{\def\pgfshapeinnerxsep{#1}}
\define@key{tikz}{inner ysep}{\def\pgfshapeinnerysep{#1}}

\define@key{tikz}{outer sep}{\def\pgfshapeouterxsep{#1}\def\pgfshapeouterysep{#1}}
\define@key{tikz}{outer xsep}{\def\pgfshapeouterxsep{#1}}
\define@key{tikz}{outer ysep}{\def\pgfshapeouterysep{#1}}

\define@key{tikz}{minimum width}{\def\pgfshapeminwidth{#1}}
\define@key{tikz}{minimum height}{\def\pgfshapeminheight{#1}}
\define@key{tikz}{minimum size}{\def\pgfshapeminwidth{#1}\def\pgfshapeminheight{#1}}

\define@key{tikz}{anchor}{\def\tikz@anchor{#1}}

\define@key{tikz}{left}[]{\def\tikz@anchor{east}\tikz@possibly@transform{x}{-}{#1}}
\define@key{tikz}{right}[]{\def\tikz@anchor{west}\tikz@possibly@transform{x}{}{#1}}
\define@key{tikz}{above}[]{\def\tikz@anchor{south}\tikz@possibly@transform{y}{}{#1}}
\define@key{tikz}{below}[]{\def\tikz@anchor{north}\tikz@possibly@transform{y}{-}{#1}}
\define@key{tikz}{above left}[]%
  {\def\tikz@anchor{south east}%
    \tikz@possibly@transform{x}{-}{#1}\tikz@possibly@transform{y}{}{#1}}
\define@key{tikz}{above right}[]%
  {\def\tikz@anchor{south west}%
    \tikz@possibly@transform{x}{}{#1}\tikz@possibly@transform{y}{}{#1}}
\define@key{tikz}{below left}[]%
  {\def\tikz@anchor{north east}%
    \tikz@possibly@transform{x}{-}{#1}\tikz@possibly@transform{y}{-}{#1}}
\define@key{tikz}{below right}[]%
  {\def\tikz@anchor{north west}%
    \tikz@possibly@transform{x}{}{#1}\tikz@possibly@transform{y}{-}{#1}}

\define@key{tikz}{transform shape}[true]{%
  \csname tikz@fullytransformed#1\endcsname%
  \iftikz@fullytransformed%
    \pgfresetnontranslationattimefalse%
  \else%
    \pgfresetnontranslationattimetrue%
  \fi%
}

\newif\iftikz@fullytransformed
\pgfresetnontranslationattimetrue%

\def\tikz@anchor{center}%
\def\tikz@shape{rectangle}%

\def\tikz@possibly@transform#1#2#3{%
  \def\tikz@test{#3}%
  \ifx\tikz@test\@empty%
  \else%
    \setlength{\pgf@x}{#3}%
    \pgf@x=#2\pgf@x\relax%
    \edef\tikz@marshal{\noexpand\tikz@addtransform{%
        \expandafter\noexpand\csname  pgftransform#1shift\endcsname{\the\pgf@x}}}% 
    \tikz@marshal%
  \fi%
}


% Line/curve label placement options
\define@key{tikz}{sloped}[true]{\csname pgfslopedattime#1\endcsname}

\define@key{tikz}{pos}{\edef\tikz@time{#1}}

\def\tikz@time{.5}



% Text options
\define@key{tikz}{text}{\def\tikz@textcolor{#1}}
\define@key{tikz}{font}{\def\tikz@textfont{#1}}
\define@key{tikz}{text opacity}{\def\tikz@textopacity{#1}}
\define@key{tikz}{text width}{\def\tikz@text@width{#1}}
\define@key{tikz}{text ragged}[]%
{\def\tikz@text@action{\raggedright\rightskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}}
\define@key{tikz}{text badly ragged}[]{\def\tikz@text@action{\raggedright\relax}}
\define@key{tikz}{text ragged left}[]%
{\def\tikz@text@action{\raggedleft\leftskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}}
\define@key{tikz}{text badly ragged left}[]{\def\tikz@text@action{\raggedleft\relax}}
\define@key{tikz}{text justified}[]{\def\tikz@text@action{\leftskip\z@\rightskip\z@\relax}}
\define@key{tikz}{text centered}[]{\def\tikz@text@action{%
  \leftskip\z@ plus2em%
  \rightskip\z@ plus2em%
  \spaceskip.3333em \xspaceskip.5em%
  \parfillskip=0pt%
  \let\\=\@centercr% for latex
  \relax}}
\define@key{tikz}{text badly centered}[]%
{\def\tikz@text@action{%
  \let\\=\@centercr% for latex
  \parfillskip=0pt%
  \rightskip\@flushglue%
  \leftskip\@flushglue\relax}}

\let\tikz@text@width=\@empty
\let\tikz@textcolor=\@empty
\let\tikz@textfont=\@empty
\let\tikz@textopacity=\@empty

\def\tikz@text@action{\raggedright\rightskip\z@ plus2em \spaceskip.3333em \xspaceskip.5em\relax}





% Arrow options
\define@key{tikz}{arrows}{\tikz@processarrows{#1}}

\define@key{tikz}{>}{%
  \tikz@set@pointed{\csname pgf@arrows@invert#1\endcsname}{#1}%
  \expandafter\tikz@processarrows\expandafter{\tikz@current@arrows}%
}

\define@key{tikz}{shorten <}{\pgfsetshortenstart{#1}}
\define@key{tikz}{shorten >}{\pgfsetshortenend{#1}}

\def\tikz@set@pointed#1#2{%
  \@ifundefined{pgf@arrow@code@tikze@>@#2}
  {%
    \pgfarrowsdeclarealias{tikzs@<@#2}{tikze@>@#2}{#1}{#2}%
    \pgfarrowsdeclarereversed{tikzs@>@#2}{tikze@<@#2}{#1}{#2}%
    \pgfarrowsdeclarecombine*{tikz@|<@#2}{tikz@>|@#2}{#1}{#2}{|}{|}%
    \pgfarrowsdeclaredouble[\pgflinewidth]{tikzs@<<@#2}{tikze@>>@#2}{#1}{#2}%
    \pgfarrowsdeclarereversed{tikzs@>>@#2}{tikze@<<@#2}{tikzs@<<@#2}{tikze@>>@#2}%
  }{}%
  \@namedef{tikz@special@arrow@start<}{tikzs@<@#2}%
  \@namedef{tikz@special@arrow@end>}{tikze@>@#2}%
  \@namedef{tikz@special@arrow@start>}{tikzs@>@#2}%
  \@namedef{tikz@special@arrow@end<}{tikze@<@#2}%
  \@namedef{tikz@special@arrow@start|<}{tikz@|<@#2}%
  \@namedef{tikz@special@arrow@end>|}{tikz@>|@#2}%
  \@namedef{tikz@special@arrow@start<<}{tikzs@<<@#2}%
  \@namedef{tikz@special@arrow@end>>}{tikze@>>@#2}%
  \@namedef{tikz@special@arrow@start>>}{tikzs@<<@#2}%
  \@namedef{tikz@special@arrow@end<<}{tikze@>>@#2}%
}

\def\tikz@processarrows#1{%
  \def\tikz@current@arrows{#1}%
  \def\tikz@temp{#1}%
  \ifx\tikz@temp\@empty%
  \else%
    \tikz@@processarrows#1\@nil
  \fi%
}
\def\tikz@@processarrows#1-#2\@nil{%
  \expandafter\ifx\csname tikz@special@arrow@start#1\endcsname\relax%
    \pgfsetarrowsstart{#1}
  \else%
    \pgfsetarrowsstart{\csname tikz@special@arrow@start#1\endcsname}%
  \fi%
  \expandafter\ifx\csname tikz@special@arrow@end#2\endcsname\relax%
    \pgfsetarrowsend{#2}
  \else%
    \pgfsetarrowsend{\csname tikz@special@arrow@end#2\endcsname}%
  \fi%
}

\tikz@set@pointed{\pgf@arrows@invertto}{to}
\def\tikz@current@arrows{-}

% Parabola options
\define@key{tikz}{bend}{\tikz@scan@one@point\tikz@set@parabola@bend#1\relax}%
\define@key{tikz}{bend pos}{\def\tikz@parabola@bend@factor{#1}}
\define@key{tikz}{parabola height}{%
  \def\tikz@parabola@bend@factor{.5}%
  \def\tikz@parabola@bend{\pgfpointadd{\pgfpoint{0pt}{#1}}{\tikz@last@position@saved}}}

\def\tikz@parabola@bend{\tikz@last@position@saved}
\def\tikz@parabola@bend@factor{0}

\def\tikz@set@parabola@bend#1{\def\tikz@parabola@bend{#1}}

% Axis options
\define@key{tikz}{domain}{\def\tikz@plot@domain{#1}}
\define@key{tikz}{range}{\def\tikz@plot@range{#1}}

% Plot options
\define@key{tikz}{smooth}[]{\let\tikz@plot@handler=\pgfplothandlercurveto}
\define@key{tikz}{smooth cycle}[]{\let\tikz@plot@handler=\pgfplothandlerclosedcurve}
\define@key{tikz}{sharp plot}[]{\let\tikz@plot@handler\pgfplothandlerlineto}

\define@key{tikz}{tension}{\pgfsetplottension{#1}}

\define@key{tikz}{xcomb}[]{\let\tikz@plot@handler=\pgfplothandlerxcomb}
\define@key{tikz}{ycomb}[]{\let\tikz@plot@handler=\pgfplothandlerycomb}
\define@key{tikz}{polar comb}[]{\let\tikz@plot@handler=\pgfplothandlerpolarcomb}

\define@key{tikz}{raw gnuplot}[true]{\csname tikz@plot@raw@gnuplot#1\endcsname}
\define@key{tikz}{prefix}{\def\tikz@plot@prefix{#1}}
\define@key{tikz}{id}{\def\tikz@plot@id{#1}}

\define@key{tikz}{samples}{\def\tikz@plot@sampels{#1}}
\define@key{tikz}{parametric}[true]{\csname tikz@plot@parametric#1\endcsname}

\define@key{tikz}{only marks}[]{\let\tikz@plot@handler\pgfplothandlerdiscard}

\define@key{tikz}{mark}{\def\tikz@plot@mark{#1}}
\define@key{tikz}{mark options}{\def\tikz@plot@mark@options{#1}}
\define@key{tikz}{mark size}{\pgfsetplotmarksize{#1}}

\let\tikz@plot@mark@options=\@empty

\let\tikz@plot@handler=\pgfplothandlerlineto
\let\tikz@plot@mark=\@empty

\def\tikz@plot@sampels{25}
\def\tikz@plot@domain{-5:5}

\def\tikz@plot@prefix{\jobname.}
\def\tikz@plot@id{pgf-plot}

\newif\iftikz@plot@parametric
\newif\iftikz@plot@raw@gnuplot


% Tree options
\define@key{tikz}{edge from parent path}{\def\tikz@edge@to@parent@path{#1}}

\define@key{tikz}{parent anchor}{\def\tikzparentanchor{.#1}\ifx\tikzparentanchor\tikz@border@text\let\tikzparentanchor\@empty\fi}
\define@key{tikz}{child anchor}{\def\tikzchildanchor{.#1}\ifx\tikzchildanchor\tikz@border@text\let\tikzchildanchor\@empty\fi}

\define@key{tikz}{level distance}{\setlength\tikzleveldistance{#1}}
\define@key{tikz}{sibling distance}{\setlength\tikzsiblingdistance{#1}}

\define@key{tikz}{growth function}{\let\tikz@grow=#1}
\define@key{tikz}{grow}{\tikz@set@growth{#1}\edef\tikz@special@level{\the\tikztreelevel}}%
\define@key{tikz}{grow'}{\tikz@set@growth{#1}\tikz@swap@growth\edef\tikz@special@level{\the\tikztreelevel}}%


\def\tikz@special@level{-1}% never

\def\tikz@swap@growth{%
  % Swap left and right
  \let\tikz@temp=\tikz@angle@grow@right%
  \let\tikz@angle@grow@right=\tikz@angle@grow@left%
  \let\tikz@angle@grow@left=\tikz@temp%
}%

\def\tikz@set@growth#1{%
  \let\tikz@grow=\tikz@grow@direction%
  \expandafter\ifx\csname tikz@grow@direction@#1\endcsname\relax%
    \c@pgf@counta=#1\relax%
  \else%
    \c@pgf@counta=\csname tikz@grow@direction@#1\endcsname%
  \fi%
  \edef\tikz@angle@grow{\the\c@pgf@counta}%
  \advance\c@pgf@counta by-90\relax%
  \edef\tikz@angle@grow@left{\the\c@pgf@counta}%
  \advance\c@pgf@counta by180\relax%
  \edef\tikz@angle@grow@right{\the\c@pgf@counta}%
}

\def\tikz@border@text{.border}
\let\tikzparentanchor=\@empty
\let\tikzchildanchor=\@empty
\def\tikz@edge@to@parent@path{(\tikzparentnode\tikzparentanchor) -- (\tikzchildnode\tikzchildanchor)}

\tikzleveldistance=15mm
\tikzsiblingdistance=15mm

\def\tikz@grow@direction@down{-90}
\def\tikz@grow@direction@up{90}
\def\tikz@grow@direction@left{180}
\def\tikz@grow@direction@right{0}

\def\tikz@grow@direction@south{-90}
\def\tikz@grow@direction@north{90}
\def\tikz@grow@direction@west{180}
\def\tikz@grow@direction@east{0}

\expandafter\def\csname tikz@grow@direction@north east\endcsname{45}
\expandafter\def\csname tikz@grow@direction@north west\endcsname{135}
\expandafter\def\csname tikz@grow@direction@south east\endcsname{-45}
\expandafter\def\csname tikz@grow@direction@south west\endcsname{-135}

\def\tikz@grow@direction{%
  \pgftransformshift{\pgfpointpolar{\tikz@angle@grow}{\tikzleveldistance}}%
  \ifnum\tikztreelevel=\tikz@special@level%
  \else%
    \pgf@xc=.5\tikzsiblingdistance%
    \c@pgf@counta=\tikznumberofchildren%
    \advance\c@pgf@counta by1\relax%
    \@tempdima=\c@pgf@counta\pgf@xc%
    \pgftransformshift{\pgfpointpolar{\tikz@angle@grow@left}{\@tempdima}}%
    \pgftransformshift{\pgfpointpolar{\tikz@angle@grow@right}{\tikznumberofcurrentchild\tikzsiblingdistance}}%
  \fi%
}

\setkeys{tikz}{grow=down}




% Snake options
\define@key{tikz}{snake}[]{%
  \def\tikz@@snake{#1}%
  \ifx\tikz@@snake\@empty%
    \tikz@snakedtrue%
  \else%
    \ifx\tikz@@snake\tikz@nonetext%
      \tikz@snakedfalse%
    \else%
      \tikz@snakedtrue%
      \let\tikz@snake=\tikz@@snake%
    \fi%
  \fi}

\define@key{tikz}{segment amplitude}{\setlength{\pgfsnakesegmentamplitude}{#1}}
\define@key{tikz}{segment length}{\setlength{\pgfsnakesegmentlength}{#1}}
\define@key{tikz}{segment angle}{\def\pgfsnakesegmentangle{#1}}
\define@key{tikz}{segment aspect}{\def\pgfsnakesegmentaspect{#1}}

\define@key{tikz}{segment object length}{\def\pgfsnakesegmentobjectlength{#1}}

\define@key{tikz}{raise snake}{\def\pgf@snake@raise{\pgftransformyshift{#1}}}
\define@key{tikz}{mirror snake}[true]{%
  \csname if#1\endcsname
    \def\pgf@snake@mirror{\pgftransformyscale{-1}}%
  \else%
    \let\pgf@snake@mirror=\@empty%
  \fi
}

\define@key{tikz}{gap before snake}{\def\tikz@presnake{{moveto}{#1}}}
\define@key{tikz}{line before snake}{\def\tikz@presnake{{lineto}{#1}}}

\define@key{tikz}{gap after snake}{\def\tikz@postsnake{{moveto}{#1}}\def\tikz@mainsnakelength{\pgfsnakeremainingdistance-#1}}
\define@key{tikz}{line after snake}{\def\tikz@postsnake{{lineto}{#1}}\def\tikz@mainsnakelength{\pgfsnakeremainingdistance-#1}}

\define@key{tikz}{gap around snake}{%
  \def\tikz@presnake{{moveto}{#1}}%
  \def\tikz@postsnake{{moveto}{#1}}%
  \def\tikz@mainsnakelength{\pgfsnakeremainingdistance-#1}%
}
\define@key{tikz}{line around snake}{%
  \def\tikz@presnake{{lineto}{#1}}%
  \def\tikz@postsnake{{lineto}{#1}}%
  \def\tikz@mainsnakelength{\pgfsnakeremainingdistance-#1}%
}
\let\pgf@snake@mirror=\@empty
\let\pgf@snake@raise=\@empty

\pgfsetsnakesegmenttransformation{\pgf@snake@mirror\pgf@snake@raise}

\def\tikz@snake{zigzag}

\let\tikz@presnake=\@empty
\let\tikz@postsnake=\@empty
\def\tikz@mainsnakelength{\pgfsnakeremainingdistance}



% Execute option

\define@key{tikz}{execute at begin picture}{\expandafter\def\expandafter\tikz@atbegin@picture\expandafter{\tikz@atbegin@picture#1}}
\define@key{tikz}{execute at end picture}{\expandafter\def\expandafter\tikz@atend@picture\expandafter{\tikz@atend@picture#1}}
\define@key{tikz}{execute at begin scope}{\expandafter\def\expandafter\tikz@atbegin@scope\expandafter{\tikz@atbegin@scope#1}}
\define@key{tikz}{execute at end scope}{\expandafter\def\expandafter\tikz@atend@scope\expandafter{\tikz@atend@scope#1}}

\let\tikz@atbegin@picture=\@empty
\let\tikz@atend@picture=\@empty
\let\tikz@atbegin@scope=\@empty
\let\tikz@atend@scope=\@empty




% Styles
\define@key{tikz}{set style}{\tikzstyle#1}

% Handled in a special way.
\def\tikzstyle#1=#2[#3]{% #2 is dummy
  \in@+{#1}%
  \ifin@%
    \tikz@style#1{#3}%
  \else%
    \expandafter\def\csname tikz@st@#1\endcsname{#3}%
  \fi}
\def\tikz@style#1+#2{%
  \edef\tikz@marshal{\def\expandafter\noexpand\csname tikz@st@#1\endcsname}%
  \expandafter\expandafter\expandafter\tikz@marshal\expandafter\expandafter\expandafter{\csname tikz@st@#1\endcsname,#2}}

\def\iftikzstyleempty#1#2#3{%
  \expandafter\ifx\csname tikz@st@#1\endcsname\@empty%
    \let\pgf@next=\@firstoftwo%
  \else%
    \expandafter\ifx\csname tikz@st@#1\endcsname\relax%
      \let\pgf@next=\@firstoftwo%
    \else
      \let\pgf@next=\@secondoftwo%
    \fi%
  \fi%
  \pgf@next{#2}{#3}}



%
%
% Predefined styles
%
%

\tikzstyle{help lines}=              [color=gray,line width=0.2pt]

\tikzstyle{every picture}=           []
\tikzstyle{every path}=              []
\tikzstyle{every scope}=             []
\tikzstyle{every plot}=              []
\tikzstyle{every node}=              []
\tikzstyle{every child}=             []
\tikzstyle{every child node}=        []

\tikzstyle{ultra thin}=              [line width=0.1pt]
\tikzstyle{very thin}=               [line width=0.2pt]
\tikzstyle{thin}=                    [line width=0.4pt]
\tikzstyle{semithick}=               [line width=0.6pt]
\tikzstyle{thick}=                   [line width=0.8pt]
\tikzstyle{very thick}=              [line width=1.2pt]
\tikzstyle{ultra thick}=             [line width=1.6pt]

\tikzstyle{solid}=                   [dash pattern=]
\tikzstyle{dotted}=                  [dash pattern=on \pgflinewidth off 2pt]
\tikzstyle{densely dotted}=          [dash pattern=on \pgflinewidth off 1pt]
\tikzstyle{loosely dotted}=          [dash pattern=on \pgflinewidth off 4pt]
\tikzstyle{dashed}=                  [dash pattern=on 3pt off 3pt]
\tikzstyle{densely dashed}=          [dash pattern=on 3pt off 2pt]
\tikzstyle{loosely dashed}=          [dash pattern=on 3pt off 6pt]

\tikzstyle{transparent}=             [opacity=0]
\tikzstyle{ultra nearly transparent}=[opacity=0.05]
\tikzstyle{very nearly transparent}= [opacity=0.1]
\tikzstyle{nearly transparent}=      [opacity=0.25]
\tikzstyle{semitransparent}=         [opacity=0.5]
\tikzstyle{nearly opaque}=           [opacity=0.75]
\tikzstyle{very nearly opaque}=      [opacity=0.9]
\tikzstyle{ultra nearly opaque}=     [opacity=0.95]
\tikzstyle{opaque}=                  [opacity=1]

\tikzstyle{at start}=                [pos=0]
\tikzstyle{very near start}=         [pos=0.125]
\tikzstyle{near start}=              [pos=0.25]
\tikzstyle{midway}=                  [pos=0.5]
\tikzstyle{near end}=                [pos=0.75]
\tikzstyle{very near end}=           [pos=0.875]
\tikzstyle{at end}=                  [pos=1]

\tikzstyle{bend at start}=           [bend pos=0,bend={+(0,0)}]
\tikzstyle{bend at end}=             [bend pos=1,bend={+(0,0)}]

\tikzstyle{edge from parent}=        [draw]

\tikzstyle{snake triangles 45}=      [snake=triangles,segment object length=2.41421356\pgfsnakesegmentamplitude]
\tikzstyle{snake triangles 60}=      [snake=triangles,segment object length=1.73205081\pgfsnakesegmentamplitude]
\tikzstyle{snake triangles 90}=      [snake=triangles,segment object length=\pgfsnakesegmentamplitude]


%
% Setting keys
%

\let\tikz@late@keys=\@empty%

\def\tikz@set@one@key#1{%
  \setkeys*{tikz}{#1}%
  \ifx\XKV@rm\@empty%
    % fine
  \else%
    \expandafter\in@\expandafter!\expandafter{\XKV@rm}%
    \ifin@%
      % this is a color!
      \expandafter\tikz@addoption\expandafter{\expandafter\color\expandafter{\XKV@rm}}%
      \edef\tikz@textcolor{\XKV@rm}%
    \else%
      \expandafter\ifx\csname\string\color@\XKV@rm\endcsname\relax%
        % Ok, second chance: This might be an arrow specification:
        \expandafter\in@\expandafter-\expandafter{\XKV@rm}
        \ifin@%
          % Ah, an arrow spec!
          \expandafter\tikz@processarrows\expandafter{\XKV@rm}%
        \else%
          % Ok, third chance: A shape!
          \expandafter\ifx\csname pgf@sh@s@\XKV@rm\endcsname\relax%
            \PackageError{tikz}{I do not know what to do with the option ``\XKV@rm''}{}
          \else%
            \edef\tikz@shape{\XKV@rm}%
          \fi%
        \fi%
      \else%
        \expandafter\tikz@addoption\expandafter{\expandafter\color\expandafter{\XKV@rm}}%
        \edef\tikz@textcolor{\XKV@rm}%
      \fi%
    \fi%
  \fi%  
}

\def\tikz@setkeys#1{\tikz@@setkeys#1,\pgf@stop}

\def\tikz@@setkeys#1,#2\pgf@stop{%
  \def\tikz@key@test{#1}%
  \def\tikz@key@rest{#2}%
  \ifx\tikz@key@test\@empty%
  \else%
    \@ifnextchar s{\tikz@parse@key}{\tikz@parse@key}#1==\pgf@stop%
  \fi%
  \ifx\tikz@key@rest\@empty%
  \else%
    \expandafter\expandafter\expandafter\tikz@@setkeys\expandafter\tikz@key@rest\expandafter\pgf@stop%
  \fi%
}

\def\tikz@style@text{style}

\def\tikz@parse@key#1=#2=#3\pgf@stop{
  \def\tikz@key@test{#1}%
  \ifx\tikz@key@test\tikz@style@text%
    % Ok, style!
    \@ifundefined{tikz@st@#2}%
    {\PackageError{tikz}{Unknown style ``#2}''{}}
    {%
      \expandafter\let\expandafter\tikz@temp\expandafter=\csname tikz@st@#2\endcsname%
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\tikz@key@rest
      \expandafter\expandafter\expandafter{\expandafter\tikz@temp\expandafter,\tikz@key@rest}%
    }%
  \else%
    \expandafter\ifx\csname tikz@st@#1\endcsname\relax%
      % Ok, normal!
      \def\tikz@test{#3}%
      \ifx\tikz@test\@empty%
        \tikz@set@one@key{#1}%
      \else%
        \tikz@set@one@key{#1={#2}}%
      \fi%
    \else%
      % Ok, style!
      \expandafter\let\expandafter\tikz@temp\expandafter=\csname tikz@st@#1\endcsname%
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\tikz@key@rest
      \expandafter\expandafter\expandafter{\expandafter\tikz@temp\expandafter,\tikz@key@rest}%
    \fi%
  \fi%  
}

\def\tikz@every@style#1{%
  \expandafter\ifx\csname tikz@st@#1\endcsname\relax%
  \else%
    \expandafter\expandafter\expandafter\tikz@setkeys
    \expandafter\expandafter\expandafter{\csname tikz@st@#1\endcsname}%
  \fi%
}





%
% Main TikZ Environment
%

\def\tikzpicture{\@ifnextchar[\tikz@picture{\tikz@picture[]}}%}
\def\tikz@picture[#1]{%
  \pgfpicture%
  \let\tikz@atbegin@picture=\@empty%
  \let\tikz@atend@picture=\@empty%
  \tikz@installcommands\scope[style=every picture,#1]%
  \tikz@atbegin@picture%
}
\def\endtikzpicture{%
    \tikz@atend@picture%
    \global\let\pgf@shift@baseline=\pgf@baseline%
    \endscope%
    \let\pgf@baseline=\pgf@shift@baseline%
  \endpgfpicture}

  

% Inlined picture
%
% #1 - some code to be put in a tikzpicture environment.
%
% If the command is not followed by braces, everything up to the next
% semicolon is used as argument.
%
% Example:
%
% The rectangle \tikz{\draw (0,0) rectangle (1em,1ex)} has width 1em and
% height 1ex.

\def\tikz{\@ifnextchar[{\tikz@opt}{\tikz@opt[]}}
\def\tikz@opt[#1]{\@ifnextchar\bgroup{\tikz@[#1]}{\tikz@@[#1]}}
\def\tikz@[#1]#2{\tikzpicture[#1]#2\endtikzpicture}
\def\tikz@@{%
  \let\tikz@next=\tikz@collectnormalsemicolon%
  \ifnum\the\catcode`\;=\active\relax%
    \let\tikz@next=\tikz@collectactivesemicolon%
  \fi%
  \tikz@next}
\def\tikz@collectnormalsemicolon[#1]#2;{\tikzpicture[#1]#2;\endtikzpicture}
{
  \catcode`\;=\active
  \gdef\tikz@collectactivesemicolon[#1]#2;{\tikzpicture[#1]#2;\endtikzpicture}
}



%
% Environment for scoping graphic state settings
%
\def\tikz@scope@env{\@ifnextchar[\tikz@@scope@env{\tikz@@scope@env[]}}
\def\tikz@@scope@env[#1]{%
  \pgfscope%
  \begingroup%
  \let\tikz@atbegin@scope=\@empty%
  \let\tikz@atend@scope=\@empty%
  \let\tikz@options=\@empty%
  \let\tikz@mode=\@empty%
  \tikz@every@style{every scope}%
  \tikz@setkeys{#1}%
  \tikz@options%
  \tikz@atbegin@scope%
}
\def\endtikz@scope@env{%
  \tikz@atend@scope%
  \endgroup%
  \endpgfscope%
}


%
% Install the abbreviated commands
%
\def\tikz@installcommands{%
  \ifnum\the\catcode`\;=\active\relax\expandafter\let\expandafter\tikz@origsemi\expandafter=\tikz@activesemicolon\fi%
  \ifnum\the\catcode`\:=\active\relax\expandafter\let\expandafter\tikz@origcolon\expandafter=\tikz@activecolon\fi%
  \ifnum\the\catcode`\|=\active\relax\expandafter\let\expandafter\tikz@origbar\expandafter=\tikz@activebar\fi%
  \let\tikz@origscope=\scope%
  \let\tikz@origendscope=\endscope%
  \let\tikz@origpath=\path%
  \let\tikz@origagainpath=\againpath%
  \let\tikz@origdraw=\draw%
  \let\tikz@origfill=\fill%
  \let\tikz@origfilldraw=\filldraw%
  \let\tikz@origshade=\shade%
  \let\tikz@origshadedraw=\shadedraw%
  \let\tikz@origclip=\clip%
  \let\tikz@origuseasboundingbox=\useasboundingbox%
  \let\tikz@orignode=\node%
  \let\tikz@orignode=\coordiante%
  %
  \tikz@deactivatthings%
  %
  \let\scope=\tikz@scope@env%
  \let\endscope=\endtikz@scope@env%
  \let\path=\tikz@command@path%
  \let\againpath=\tikz@command@againpath%
  %
  \def\draw{\path[draw]}
  \def\fill{\path[fill]}
  \def\filldraw{\path[fill,draw]}
  \def\shade{\path[shade]}
  \def\shadedraw{\path[shade,draw]}
  \def\clip{\path[clip]}
  \def\useasboundingbox{\path[use as bounding box]}
  \def\node{\path node}
  \def\coordinate{\path coordinate}
}

\def\tikz@uninstallcommands{%
  \ifnum\the\catcode`\;=\active\relax\expandafter\let\tikz@activesemicolon=\tikz@origsemi\fi%
  \ifnum\the\catcode`\:=\active\relax\expandafter\let\tikz@activecolon=\tikz@origcolon\fi%
  \ifnum\the\catcode`\|=\active\relax\expandafter\let\tikz@activebar=\tikz@origbar\fi%
  \let\scope=\tikz@origscope%
  \let\endscope=\tikz@origendscope%
  \let\path=\tikz@origpath%
  \let\againpath=\tikz@origagainpath%
  \let\draw=\tikz@origdraw%
  \let\fill=\tikz@origfill%
  \let\filldraw=\tikz@origfilldraw%
  \let\shade=\tikz@origshade%
  \let\shadedraw=\tikz@origshadedraw%
  \let\clip=\tikz@origclip%
  \let\useasboundingbox=\tikz@origuseasboundingbox%
  \let\node=\tikz@orignode%
}


{
  \catcode`\;=12
  \gdef\tikz@nonactivesemicolon{;}
  \catcode`\:=12
  \gdef\tikz@nonactivecolon{:}
  \catcode`\|=12
  \gdef\tikz@nonactivebar{|}
  \catcode`\;=\active
  \catcode`\:=\active
  \catcode`\|=\active
  \catcode`\"=\active
  \gdef\tikz@activesemicolon{;}%
  \gdef\tikz@activecolon{:}%
  \gdef\tikz@activebar{|}%
  \gdef\tikz@activequotes{"}%
  \gdef\tikz@deactivatthings{%
    \def;{\tikz@nonactivesemicolon}
    \def:{\tikz@nonactivecolon}
    \def|{\tikz@nonactivebar}
  }
}





% Constructs a path and draws/fills them according to the current
% settings.  

\def\tikz@command@path{%
  \@ifnextchar[{\tikz@check@earg}%]
  {\@ifnextchar<{\tikz@doopt}{\tikz@@command@path}}}
\def\tikz@check@earg[#1]{%
  \@ifnextchar<{\tikz@swap@args[#1]}{\tikz@@command@path[#1]}}
\def\tikz@swap@args[#1]<#2>{\tikz@command@path<#2>[#1]}

\def\tikz@doopt{%
  \let\tikz@next=\tikz@eargnormalsemicolon%
  \ifnum\the\catcode`\;=\active\relax%
    \let\tikz@next=\tikz@eargactivesemicolon%
  \fi%
  \tikz@next}
\long\def\tikz@eargnormalsemicolon<#1>#2;{\only<#1>{\tikz@@command@path#2;}}
{
  \catcode`\;=\active
  \long\global\def\tikz@eargactivesemicolon<#1>#2;{\only<#1>{\tikz@@command@path#2;}}
}

\def\tikz@@command@path{%
  \edef\tikzscope@linewidth{\the\pgflinewidth}%
  \begingroup%
    \let\tikz@options=\@empty%
    \let\tikz@mode=\@empty%
    \let\tikz@moveto@waiting=\relax%
    \let\tikz@timer=\relax%
    \let\tikz@collected@onpath=\@empty%
    \tikz@snakedfalse%
    \tikz@node@is@a@labelfalse%
    \tikz@expandcount=1000\relax%
    \tikz@lastx=0pt%
    \tikz@lasty=0pt%
    \tikz@lastxsaved=0pt%
    \tikz@lastysaved=0pt%
    \tikz@every@style{every path}%
    \tikz@scan@next@command%
}
\def\tikz@scan@next@command{%
  \ifx\tikz@collected@onpath\@empty%
  \else%
    \tikz@invoke@collected@onpath%
  \fi%
  \afterassignment\tikz@handle\let\@let@token=%
}
\newcount\tikz@expandcount

% Central dispatcher for commands
\def\tikz@handle{%
  \let\@next=\tikz@expand%
    \ifx\@let@token(%)
      \let\@next=\tikz@movetoabs%
    \else%
      \ifx\@let@token+%
        \let\@next=\tikz@movetorel%
      \else%
        \ifx\@let@token-%
          \let\@next=\tikz@lineto%
        \else%
          \ifx\@let@token.%
            \let\@next=\tikz@dot%
          \else%
            \ifx\@let@token r%
              \let\@next=\tikz@rect%
            \else%
              \ifx\@let@token a%
                \let\@next=\tikz@arcA%
              \else%
                \ifx\@let@token[%]
                  \let\@next=\tikz@parse@options%
                \else%
                  \ifx\@let@token n%
                    \let\@next=\tikz@fig%
                  \else%
                    \ifx\@let@token\bgroup%
                      \let\@next=\tikz@beginscope%
                    \else%
                      \ifx\@let@token\egroup%
                        \let\@next=\tikz@endscope%
                      \else%
                        \ifx\@let@token;%
                          \let\@next=\tikz@finish%
                        \else%
                          \ifx\@let@token c%
                            \let\@next=\tikz@cchar%
                          \else%
                            \ifx\@let@token e%
                              \let\@next=\tikz@e@char%
                            \else%
                              \ifx\@let@token g%
                                \let\@next=\tikz@grid%
                              \else%
                                \ifx\@let@token s%
                                   \let\@next=\tikz@sine%
                                \else%
                                  \ifx\@let@token |%
                                     \let\@next=\tikz@vh@lineto%
                                  \else%
                                    \ifx\@let@token p%
                                      \let\@next=\tikz@pchar%
                                      \pgfsetmovetofirstplotpoint%
                                    \else%
                                      \ifx\@let@token\pgfextra%
                                        \let\@next=\tikz@extra%
                                      \else%
                                        \ifx\@let@token\foreach%
                                          \let\@next=\tikz@foreach%
                                        \else%
                                          \ifx\@let@token\pgf@stop%
                                            \let\@next=\relax%
                                          \else%
                                            \ifx\@let@token\par%
                                              \let\@next=\tikz@scan@next@command%
                                            \fi%      
                                          \fi%      
                                        \fi%      
                                      \fi%      
                                    \fi%  
                                  \fi%  
                                \fi%
                              \fi%
                            \fi%
                          \fi%
                        \fi%
                      \fi%  
                    \fi%  
                  \fi%  
                \fi%  
              \fi%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi%
  \@next%
}

\def\tikz@pchar{\@ifnextchar l{\tikz@plot}{\tikz@parabola}}
\def\tikz@cchar{%
  \@ifnextchar i{\tikz@circle}%
  {\@ifnextchar h{\tikz@children}{\tikz@cochar}}}%
\def\tikz@cochar o{%
  \@ifnextchar o{\tikz@coordinate}{\tikz@cosine}}
\def\tikz@e@char{%
  \@ifnextchar l{\tikz@ellipse}{\tikz@edgetoparent}}


\def\tikz@finish{%
  \tikz@mode@fillfalse%
  \tikz@mode@drawfalse%
  \tikz@mode@doublefalse%
  \tikz@mode@clipfalse%
  \tikz@mode@boundaryfalse%
  \edef\tikz@pathextend{%
    {\noexpand\pgfpoint{\the\pgf@pathminx}{\the\pgf@pathminy}}%
    {\noexpand\pgfpoint{\the\pgf@pathmaxx}{\the\pgf@pathmaxy}}%
  }%
  \tikz@mode% installs the mode settings
  % Rendering pipeline:  
  % 
  % Step 1: Setup options
  % 
  \ifx\tikz@options\@empty%
  \else%
    \pgfsys@beginscope%
      \begingroup%
      \tikz@options%
  \fi%
  % 
  % Step 2: Do a fill if shade follows.
  %
  \iftikz@mode@fill%
    \iftikz@mode@shade%
      \pgfprocessround{\pgfsyssoftpath@currentpath}{\pgfsyssoftpath@currentpath}% change the current path
      \pgfsyssoftpath@invokecurrentpath%
      \pgfsys@fill%
      \tikz@mode@fillfalse% no more filling...
    \fi%
  \fi%
  % 
  % Step 3: Do a shade if necessary.
  %
  \iftikz@mode@shade%
    \pgfprocessround{\pgfsyssoftpath@currentpath}{\pgfsyssoftpath@currentpath}% change the current path
    \pgfshadepath{\tikz@shading}{\tikz@shade@angle}%
    \tikz@mode@shadefalse% no more shading...
  \fi%
  % 
  % Step 4: Double stroke, if necessary
  %
  \iftikz@mode@draw%
    \iftikz@mode@double%
      % Change line width
      \begingroup%
        \pgfsys@beginscope%
          \pgf@x=2\pgflinewidth%
          \advance\pgf@x by\tikz@double@width@distance%
          \pgflinewidth=\pgf@x%
          \pgfsetlinewidth{\the\pgflinewidth}%
    \fi%
  \fi%
  % 
  % Step 5: Do stroke/fill/clip as needed
  %
  \edef\tikz@temp{\noexpand\pgfusepath{%
    \iftikz@mode@fill fill,\fi%
    \iftikz@mode@draw draw,\fi%
    \iftikz@mode@clip clip,\fi%
    }}%
  \tikz@temp%
  \tikz@mode@fillfalse% no more filling
  % 
  % Step 6: Double stroke, if necessary
  %
  \iftikz@mode@draw%
    \iftikz@mode@double%
          \pgfsyssoftpath@setcurrentpath\pgf@last@used@path% reinstall
          \pgf@x=\tikz@double@width@distance%
          \pgfsetlinewidth{\the\pgf@x}%
          \pgfsetstrokecolor{\tikz@double@color}%
          \pgfsyssoftpath@flushcurrentpath%
          \pgfsys@stroke%
        \pgfsys@endscope%
        \pgf@add@arrows@as@needed
      \endgroup%
    \fi%
  \fi%
  \tikz@mode@drawfalse% no more stroking
  % 
  % Step 7: Add labels and nodes
  %
  \copy\tikz@figbox%
  \setbox\tikz@figbox=\box\voidb@x%
  %
  % Step 8: Close option brace
  %
  \ifx\tikz@options\@empty%
  \else%
      \endgroup%
    \pgfsys@endscope%
    \iftikz@mode@clip%
      \PackageError{tikz}{Extra options not allowed for clipping path command.}{}%
    \fi%
  \fi%
  \iftikz@mode@clip%
    \aftergroup\pgf@relevantforpicturesizefalse%
  \fi%
  \iftikz@mode@boundary%
    \aftergroup\pgf@relevantforpicturesizefalse%
  \fi%
  \endgroup%
  \global\pgflinewidth=\tikzscope@linewidth%
}




\def\tikz@skip#1{\tikz@scan@next@command#1}
\def\tikz@expand{%
  \advance\tikz@expandcount by -1%
  \ifnum\tikz@expandcount<0\relax%
    \PackageError{tikz}{Giving up on this path}{}%
    \let\@next=\tikz@finish%
  \else%
    \let\@next=\tikz@@expand
  \fi%
  \@next}

\def\tikz@@expand{%
  \expandafter\tikz@scan@next@command\@let@token}



% Syntax for scopes: 
% {scoped path commands}

\def\tikz@beginscope{\begingroup\tikz@scan@next@command}
\def\tikz@endscope{%
  \global\setbox\tikz@tempbox=\copy\tikz@figbox%
  \endgroup%
  \setbox\tikz@figbox=\box\tikz@tempbox%
  \tikz@scan@next@command}


% Syntax for pgfextra: 
% \pgfextra {normal tex text}

\long\def\tikz@extra#1{#1\tikz@scan@next@command}
\def\pgfextra{pgfextra}


% Syntax for \foreach: 
% \foreach \var in {list} {path text}
%
% Example:
%
% \draw (0,0) \foreach \x in {1,2,3} {-- (\x,0) circle (1cm)} -- (5,5);

\def\tikz@foreach{%
  \def\pgffor@beginhook{\setbox\tikz@figbox=\box\tikz@tempbox\expandafter\tikz@scan@next@command\@firstofone}%
  \def\pgffor@endhook{\pgfextra{\global\setbox\tikz@tempbox=\copy\tikz@figbox\@gobble}}%
  \def\pgffor@afterhook{\setbox\tikz@figbox=\box\tikz@tempbox\tikz@scan@next@command}%
  \global\setbox\tikz@tempbox=\copy\tikz@figbox%
  \foreach}

% Syntax for againpath: 
% \againpath \somepathname

\def\tikz@command@againpath#1{%
  \pgfextra{%
    \pgfsyssoftpath@getcurrentpath\tikz@temp%
    \expandafter\g@addto@macro\expandafter\tikz@temp\expandafter{#1}%
    \pgfsyssoftpath@setcurrentpath\tikz@temp%
  }
}




%
% When this if is set, a just-scanned point is a shape and its border
% position still needs to be determined, depending on subsequent
% commands. 
%

\newif\iftikz@shapeborder


% Syntax for moveto: 
% <point>
\def\tikz@movetoabs{\tikz@moveto(}
\def\tikz@movetorel{\tikz@moveto+}
\def\tikz@moveto{%
  \tikz@scan@one@point{\tikz@@moveto}}
\def\tikz@@moveto#1{%
  \tikz@make@last@position{#1}%
  \iftikz@shapeborder%
    % ok, the moveto will have to wait. flag that we have a moveto in
    % wainting:
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%
  \else%
    \pgfpathmoveto{\tikz@last@position}%
    \let\tikz@moveto@waiting=\relax%
  \fi%
  \tikz@scan@next@command%
}

\let\tikz@moveto@waiting=\relax % normally, nothing is waiting...

\def\tikz@flush@moveto{%
  \ifx\tikz@moveto@waiting\relax%
  \else%
    \pgfpathmoveto{\tikz@last@position}%
  \fi%
  \let\tikz@moveto@waiting=\relax%
}


\def\tikz@flush@moveto@toward#1#2#3{%
  % #1 = a point towards which the last moveto should be corrected
  % #2 = a dimension to which the corrected x-coordinate should be stored
  % #3 = a dimension for the corrected y-coordinate
  \ifx\tikz@moveto@waiting\relax%
    % do nothing
  \else%
    \pgf@process{\pgfpointshapeborder{\tikz@moveto@waiting}{#1}}%
    #2=\pgf@x%
    #3=\pgf@y%
    \edef\tikz@timer@start{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
    \pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}%
  \fi%
  \let\tikz@moveto@waiting=\relax%
}


%
% Collecting labels on the path 
%

\def\tikz@collect@coordinate@onpath#1coordinate{%
  \@ifnextchar[{\tikz@@collect@coordinate@opt#1}{\tikz@@collect@coordinate@opt#1[]}}%}
\def\tikz@@collect@coordinate@opt#1[#2]{%
  \@ifnextchar({\tikz@@collect@coordinate#1[#2]}{%
  \tikz@collect@label@onpath#1node[shape=coordinate,#2]{}}}%}
\def\tikz@@collect@coordinate#1[#2](#3){%
  \tikz@collect@label@onpath#1node[shape=coordinate,#2](#3){}}

\def\tikz@collect@label@onpath#1node{%
  \expandafter\def\expandafter\tikz@collected@onpath\expandafter{\tikz@collected@onpath node}%
  \tikz@collect@label@scan#1}

\def\tikz@collect@label@scan#1{%  
  \@ifnextchar({\tikz@collect@paran#1}%
  {\@ifnextchar[{\tikz@collect@options#1}%
    {\@ifnextchar\bgroup{\tikz@collect@arg#1}%
      {#1}}}%
}%}}

\def\tikz@collect@paran#1(#2){%
  \expandafter\def\expandafter\tikz@collected@onpath\expandafter{\tikz@collected@onpath(#2)}%
  \tikz@collect@label@scan#1%
}
\def\tikz@collect@options#1[#2]{%
  \expandafter\def\expandafter\tikz@collected@onpath\expandafter{\tikz@collected@onpath[#2]}%
  \tikz@collect@label@scan#1%
}
\def\tikz@collect@arg#1#2{%
  \expandafter\def\expandafter\tikz@collected@onpath\expandafter{\tikz@collected@onpath{#2}}%
  #1%
}


\def\tikz@invoke@collected@onpath{%
  \tikz@node@is@a@labeltrue%
  \let\tikz@temp=\tikz@collected@onpath%
  \let\tikz@collected@onpath=\@empty%
  \expandafter\tikz@scan@next@command\tikz@temp\pgf@stop%
  \tikz@node@is@a@labelfalse%
}




% Syntax for lineto: 
% -- <point>

\def\tikz@lineto{%
  \@ifnextchar |%
  {\expandafter\tikz@hv@lineto\@gobble}%
  {\expandafter\@ifnextchar\tikz@activebar{\expandafter\tikz@hv@lineto\@gobble}%
    {\expandafter\tikz@lineto@mid\@gobble}}}
\def\tikz@lineto@mid{%
  \@ifnextchar n{\tikz@collect@label@onpath\tikz@lineto@mid}%
  {%
    \@ifnextchar c{\tikz@close}{%
      \@ifnextchar p{\pgfsetlinetofirstplotpoint\expandafter\tikz@plot\@gobble}%
        {\tikz@scan@one@point{\tikz@@lineto}}}}}
\def\tikz@@lineto#1{%
  % Record the starting point for later labels on the path:
  \edef\tikz@timer@start{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}
  \iftikz@shapeborder%
    % ok, target is a shape. recalculate end
    \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\tikz@last@position}}%
    \tikz@make@last@position{\pgfpoint{\pgf@x}{\pgf@y}}%
    \tikz@flush@moveto@toward{\tikz@last@position}\pgf@x\pgf@y%
    \tikz@path@lineto{\tikz@last@position}%
    \edef\tikz@timer@end{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
    \tikz@make@last@position{#1}%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%    
  \else%
    % target is a reasonable point...
    % Record the starting point for later labels on the path:
    \tikz@make@last@position{#1}%
    \tikz@flush@moveto@toward{\tikz@last@position}\pgf@x\pgf@y%
    \tikz@path@lineto{\tikz@last@position}%
    \edef\tikz@timer@end{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi%
  \let\tikz@timer=\tikz@timer@line%
  \tikz@scan@next@command%
}

% snake or lineto?
\def\tikz@path@lineto#1{%
  \iftikz@snaked%
    \pgfpathsnakesto{\tikz@presnake,{\tikz@snake}{\tikz@mainsnakelength},\tikz@postsnake}{#1}%
  \else%
    \pgfpathlineto{#1}%
  \fi%
}

% snake or lineto?
\def\tikz@path@close#1{%
  \iftikz@snaked%
    \pgfpathsnakesto{\tikz@presnake,{\tikz@snake}{\tikz@mainsnakelength},\tikz@postsnake}{#1}%
    \pgfpathclose%
  \else%
    \pgfpathclose%
  \fi%
}


% Syntax for lineto horizontal/vertical: 
% -| <point>

\def\tikz@hv@lineto{%
  \@ifnextchar n
  {\tikz@collect@label@onpath\tikz@hv@lineto}
  {\@ifnextchar c{\tikz@collect@coordinate@onpath\tikz@hv@lineto}%
    {\tikz@scan@one@point{\tikz@@hv@lineto}}}}
\def\tikz@@hv@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \pgf@yc=\tikz@lasty%
  \tikz@make@last@position{#1}%
  \tikz@flush@moveto@toward{\pgfpoint{\tikz@lastx}{\pgf@yc}}\pgf@x\pgf@yc%
  \iftikz@shapeborder%
    % ok, target is a shape. have to work now:
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfpoint{\tikz@lastx}{\pgf@yc}}}%
      \tikz@make@last@position{\pgfpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfpoint{\tikz@lastx}{\pgf@yc}}%
      \tikz@path@lineto{\tikz@last@position}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@end=\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%    
  \else%
    \tikz@path@lineto{\pgfpoint{\tikz@lastx}{\pgf@yc}}%
    \tikz@path@lineto{\tikz@last@position}%
    \edef\tikz@timer@end{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
  \fi%
  \let\tikz@timer=\tikz@timer@hvline%
  \tikz@scan@next@command%
}

% Syntax for lineto vertical/horizontal: 
% |- <point>

\def\tikz@vh@lineto-{\tikz@vh@lineto@next}
\def\tikz@vh@lineto@next{%
  \@ifnextchar n
  {\tikz@collect@label@onpath\tikz@vh@lineto@next}
  {\@ifnextchar c{\tikz@collect@coordinate@onpath\tikz@vh@lineto@next}%
    {\tikz@scan@one@point\tikz@@vh@lineto}}}
\def\tikz@@vh@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \pgf@xc=\tikz@lastx%
  \tikz@make@last@position{#1}%
  \tikz@flush@moveto@toward{\pgfpoint{\pgf@xc}{\tikz@lasty}}\pgf@xc\pgf@y%
  \iftikz@shapeborder%
    % ok, target is a shape. have to work now:
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfpoint{\pgf@xc}{\tikz@lasty}}}%
      \tikz@make@last@position{\pgfpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfpoint{\pgf@xc}{\tikz@lasty}}%
      \tikz@path@lineto{\tikz@last@position}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@end=\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%    
  \else%
    \tikz@path@lineto{\pgfpoint{\pgf@xc}{\tikz@lasty}}%
    \tikz@path@lineto{\tikz@last@position}%
    \edef\tikz@timer@end{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi%
  \let\tikz@timer=\tikz@timer@vhline%
  \tikz@scan@next@command%
}

% Syntax for cycle: 
% -- cycle
\def\tikz@close c{%
  \@ifnextchar o{\tikz@collect@coordinate@onpath\tikz@lineto@mid c}% oops, a coordinate
  {\tikz@@close c}}%
\def\tikz@@close cycle{%
  \tikz@flush@moveto%
  \tikz@path@close{\expandafter\pgfpoint\pgfsyssoftpath@lastmoveto}%
  \def\pgfstrokehook{}%
  \let\tikz@timer=\@undefined%
  \tikz@scan@next@command%
}


% Syntax for options: 
% [options]
\def\tikz@parse@options#1]{%
  \tikz@setkeys{#1}%
  \tikz@scan@next@command%
}



% Syntax for edge from parent: 
% edge from parent [options]
\def\tikz@edgetoparent dge from parent{\@ifnextchar[\tikz@@edgetoparent{\tikz@@edgetoparent[]}}%}
\def\tikz@@edgetoparent[#1]{%
  \let\tikz@edge@to@parent@needed=\@empty%
  \tikz@node@is@a@labeltrue%
  \tikz@scan@next@command [style=edge from parent,#1] \tikz@edge@to@parent@path%
}


% Syntax for bezier curves
% .. controls(point) and (point) .. (target)
% .. controls(point) .. (target) 
% .. (target) % currently not supported

\def\tikz@dot.{\tikz@@dot}%
\def\tikz@@dot{%
  \@ifnextchar n%
  {\tikz@collect@label@onpath\tikz@@dot}%
  {\@ifnextchar c{\tikz@curveto@double}{\tikz@curveto@auto}}}

\def\tikz@curveto@double co{%
  \@ifnextchar o{\tikz@collect@coordinate@onpath\tikz@@dot co}
  {\tikz@cureveto@@double}}
\def\tikz@cureveto@@double ntrols#1{%
  \tikz@scan@one@point\tikz@curveA#1%
}
\def\tikz@curveA#1{%
  \edef\tikz@timer@start{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  {%
    \tikz@make@last@position{#1}%
    \xdef\tikz@curve@first{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  }%
  \@ifnextchar a
  {\tikz@curveBand}%
  {\let\tikz@curve@second\tikz@curve@first\tikz@curveCdots}%
}
\def\tikz@curveBand and{%
  \tikz@scan@one@point\tikz@curveB%
}
\def\tikz@curveB#1{%
  \def\tikz@curve@second{#1}%
  \tikz@curveCdots}
\def\tikz@curveCdots{%
  \afterassignment\tikz@curveCdot\let\@next=}
\def\tikz@curveCdot.{%
  \ifx\@next.%
  \else%
    \PackageError{tikz}{Dot expected}{}%
  \fi%
  \tikz@updatecurrenttrue%
  \tikz@curveCcheck%
}
\def\tikz@curveCcheck{%
  \@ifnextchar n%
  {\tikz@collect@label@onpath\tikz@curveCcheck}
  {\@ifnextchar c{\tikz@collect@coordinate@onpath\tikz@curveCcheck}
    {\tikz@scan@one@point\tikz@curveC}}%
}
\def\tikz@curveC#1{%
  \tikz@make@last@position{#1}%
  \edef\tikz@curve@third{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  {%
    \tikz@lastxsaved=\tikz@lastx%
    \tikz@lastysaved=\tikz@lasty%
    \tikz@make@last@position{\tikz@curve@second}%
    \xdef\tikz@curve@second{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  }%
  %
  % Start recalculating things in case start and end are shapes.
  %
  % First, the start:
  \ifx\tikz@moveto@waiting\relax%
  \else%
    \pgf@process{\pgfpointshapeborder{\tikz@moveto@waiting}{\tikz@curve@first}}%
    \edef\tikz@timer@start{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
    \pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}%
  \fi%
  \let\tikz@timer@cont@one=\tikz@curve@first%
  \let\tikz@timer@cont@two=\tikz@curve@second%    
  % Second, the end:
  \iftikz@shapeborder%
    % ok, target is a shape. recalculate third
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\tikz@curve@second}}%
      \tikz@make@last@position{\pgfpoint{\pgf@x}{\pgf@y}}%
      \edef\tikz@curve@third{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
      \pgfpathcurveto{\tikz@curve@first}{\tikz@curve@second}{\tikz@curve@third}%
      \global\let\tikz@timer@end@temp=\tikz@curve@third% move out of group
    }%
    \let\tikz@timer@end=\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}%    
  \else%
    \pgfpathcurveto{\tikz@curve@first}{\tikz@curve@second}{\tikz@curve@third}%
    \let\tikz@timer@end=\tikz@curve@third
    \let\tikz@moveto@waiting=\relax%
  \fi%
  \let\tikz@timer=\tikz@timer@curve%  
  \tikz@scan@next@command%
}


% Syntax for rectangles: 
% rectangle <corner point> 
\def\tikz@rect ectangle{%
  \tikz@flush@moveto%
  \edef\tikz@timer@start{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \tikz@@rect}%
\def\tikz@@rect{%
  \@ifnextchar n
  {\tikz@collect@label@onpath\tikz@@rect}
  {\@ifnextchar c{\tikz@collect@coordinate@onpath\tikz@@rect}%
    {
      \pgf@xa=\tikz@lastx\relax%
      \pgf@ya=\tikz@lasty\relax%
      \tikz@scan@one@point\tikz@rectB}}}
\def\tikz@rectB#1{%
  \tikz@make@last@position{#1}%
  \edef\tikz@timer@end{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \let\tikz@timer=\tikz@timer@line%  
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}%
  \tikz@path@lineto{\pgfpoint{\pgf@xa}{\tikz@lasty}}%
  \tikz@path@lineto{\pgfpoint{\tikz@lastx}{\tikz@lasty}}%
  \tikz@path@lineto{\pgfpoint{\tikz@lastx}{\pgf@ya}}%
  \tikz@path@close{\pgfpoint{\pgf@xa}{\pgf@ya}}%
  \pgfpathmoveto{\pgfpoint{\tikz@lastx}{\tikz@lasty}}%
  \def\pgfstrokehook{}%
  \tikz@scan@next@command%
}



% Syntax for grids: 
% grid <corner point> 
\def\tikz@grid rid{%
  \tikz@flush@moveto%
  \pgf@xa=\tikz@lastx\relax%
  \pgf@ya=\tikz@lasty\relax%
  \tikz@scan@one@point\tikz@gridB}%
\def\tikz@gridB#1{%
  \tikz@make@last@position{#1}%
  \pgfpathgrid[stepx=\tikz@grid@x,stepy=\tikz@grid@y]%
    {\pgfpoint{\pgf@xa}{\pgf@ya}}{\pgfpoint{\tikz@lastx}{\tikz@lasty}}%
  \tikz@scan@next@command%
}



% Syntax for plot: 
% plot [local options] ...    % starts with a moveto
% -- plot [local options] ... % starts with a lineto
\def\tikz@plot lot{%
  \tikz@flush@moveto%
  \@ifnextchar[{\tikz@@plot}{\tikz@@plot[]}}%}
\def\tikz@@plot[#1]{%
  \begingroup%
    \let\tikz@options=\@empty%
    \tikz@every@style{every plot}%
    \tikz@setkeys{#1}%
    \@ifnextchar f{\tikz@plot@f}%
    {\@ifnextchar c{\tikz@plot@scan@points}%
      {\PackageError{tikz}{Cannot parse this plotting data}{}%
       \endgroup}}}
\def\tikz@plot@f f{\@ifnextchar i{\tikz@plot@file}{\tikz@plot@function}}

\def\tikz@plot@file ile#1{\def\tikz@plot@data{\pgfplotxyfile{#1}}\tikz@@@plot}%
\def\tikz@plot@scan@points coordinates#1{%
  \pgfplothandlerrecord\tikz@plot@data%
  \pgfplotstreamstart%
  \@ifnextchar\pgf@stop{\pgfplotstreamend\expandafter\tikz@@@plot\@gobble}
  {\tikz@scan@one@point\tikz@plot@next@point}%
  #1\pgf@stop%
}
\def\tikz@plot@next@point#1{%
  \pgfplotstreampoint{#1}%
  \@ifnextchar\pgf@stop{\pgfplotstreamend\expandafter\tikz@@@plot\@gobble}%
  {\tikz@scan@one@point\tikz@plot@next@point}%
}  
\def\tikz@plot@function unction#1{%
  \def\tikz@plot@filename{\tikz@plot@prefix\tikz@plot@id}%  
  \iftikz@plot@raw@gnuplot%
    \def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{#1}}%
  \else%
    \iftikz@plot@parametric%   
      \def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{%
          set samples \tikz@plot@sampels;
          set parametric;
          plot [t=\tikz@plot@domain] #1}}%
    \else%
      \def\tikz@plot@data{\pgfplotgnuplot[\tikz@plot@filename]{%
          set samples \tikz@plot@sampels;
          plot [x=\tikz@plot@domain] #1}}%
    \fi%
  \fi%
  \tikz@@@plot%
}

\def\tikz@plot@no@resample{%
  \IfFileExists{\tikz@plot@filename.table}%
  {\def\tikz@plot@data{\pgfplotxyfile{\tikz@plot@filename.table}}}%
  {}%
}


\def\tikz@@@plot{%
    \def\pgfplotlastpoint{\pgfpointorigin}%
    \tikz@plot@handler%
    \tikz@plot@data%
    \global\let\tikz@@@temp=\pgfplotlastpoint%
    \ifx\tikz@plot@mark\@empty%
    \else%
      % Marks are drawn after the path.
      \setbox\tikz@figbox=\hbox{%
        \unhbox\tikz@figbox%
        \hbox{{%
          \pgfinterruptpath%
            \pgfscope%
              \let\tikz@options=\@empty%
              \let\tikz@transform=\@empty%
              \expandafter\tikz@setkeys\expandafter{\tikz@plot@mark@options}%
              \tikz@options%
              \pgfplothandlermark{\tikz@transform\pgfuseplotmark{\tikz@plot@mark}}%
              \tikz@plot@data%
            \endpgfscope
          \endpgfinterruptpath%
        }}%
      }%
    \fi%
    \global\setbox\tikz@tempbox=\copy\tikz@figbox%
  \endgroup%
  \setbox\tikz@figbox=\box\tikz@tempbox%  
  \tikz@make@last@position{\tikz@@@temp}%  
  \tikz@scan@next@command%
}


\pgfdeclareplotmark{ball}
{%
  \def\tikz@shading{ball}%
  \shade (0,0) circle (\pgfplotmarksize);%
}




% Syntax for cosine curves:
% cos <end of quarter-period>
\def\tikz@cosine s{\tikz@scan@one@point\tikz@@cosine}
\def\tikz@@cosine#1{%
  \tikz@flush@moveto%
  \pgf@process{#1}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \advance\pgf@xc by-\tikz@lastx%
  \advance\pgf@yc by-\tikz@lasty%
  \advance\tikz@lastx by\pgf@xc%
  \advance\tikz@lasty by\pgf@yc%
  \tikz@lastxsaved=\tikz@lastx%
  \tikz@lastysaved=\tikz@lasty%
  \tikz@updatecurrenttrue%
  \pgfpathcosine{\pgfpoint{\pgf@xc}{\pgf@yc}}%
  \tikz@scan@next@command%
}

% Syntax for sine curves:
% sin <end of quarter-period>
\def\tikz@sine in{\tikz@scan@one@point\tikz@@sine}
\def\tikz@@sine#1{%
  \tikz@flush@moveto%
  \pgf@process{#1}%
  \pgf@xc=\pgf@x%
  \pgf@yc=\pgf@y%
  \advance\pgf@xc by-\tikz@lastx%
  \advance\pgf@yc by-\tikz@lasty%
  \advance\tikz@lastx by\pgf@xc%
  \advance\tikz@lasty by\pgf@yc%
  \tikz@lastxsaved=\tikz@lastx%
  \tikz@lastysaved=\tikz@lasty%
  \tikz@updatecurrenttrue%
  \pgfpathsine{\pgfpoint{\pgf@xc}{\pgf@yc}}%
  \tikz@scan@next@command%
}

% Syntax for parabolas: 
% parabola[options] bend <coordinate> <coordinate>
\def\tikz@parabola arabola{%
  \@ifnextchar[{\tikz@parabola@options}{\tikz@parabola@options[]}}%}

\def\tikz@parabola@options[#1]{%
  \def\tikz@parabola@option{#1}%
  \@ifnextchar b{\tikz@parabola@scan@bend}{\tikz@scan@one@point\tikz@parabola@semifinal}}
\def\tikz@parabola@scan@bend bend{\tikz@scan@one@point\tikz@parabola@scan@bendB}
\def\tikz@parabola@scan@bendB#1{%
  \def\tikz@parabola@bend{#1}%
  \tikz@scan@one@point\tikz@parabola@semifinal%
}
\def\tikz@parabola@semifinal#1{%
  % Save original start:
  \pgf@xb=\tikz@lastx%
  \pgf@yb=\tikz@lasty%
  \tikz@make@last@position{#1}%
  \pgf@xc=\tikz@lastx%
  \pgf@yc=\tikz@lasty%
  \begingroup% now calculate bend:
    \expandafter\tikz@setkeys\expandafter{\tikz@parabola@option}%
    \tikz@lastxsaved=\tikz@parabola@bend@factor\tikz@lastx%
    \tikz@lastysaved=\tikz@parabola@bend@factor\tikz@lasty%
    \advance\tikz@lastxsaved by\pgf@xb%
    \advance\tikz@lastysaved by\pgf@yb%
    \advance\tikz@lastxsaved by-\tikz@parabola@bend@factor\pgf@xb%
    \advance\tikz@lastysaved by-\tikz@parabola@bend@factor\pgf@yb%
    \expandafter\tikz@make@last@position\expandafter{\tikz@parabola@bend}%
    % Calculate delta from bend
    \advance\pgf@xc by-\tikz@lastx%
    \advance\pgf@yc by-\tikz@lasty%
    % Ok, now calculate delta to bend
    \advance\tikz@lastx by-\pgf@xb%
    \advance\tikz@lasty by-\pgf@yb%
    \xdef\tikz@parabola@b{{\noexpand\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}{\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}}%
  \endgroup%
  \expandafter\pgfpathparabola\tikz@parabola@b%
  \tikz@scan@next@command%
}


% Syntax for circles:
% circle (radius)
%
% Syntax for ellipses:
% ellipse (x-radius/y-radius)
\def\tikz@circle ircle{\tikz@@circle}
\def\tikz@ellipse llipse{\tikz@@circle}
\def\tikz@@circle{%
  \tikz@flush@moveto%
  \@ifnextchar(\tikz@@@circle{%)
    \advance\tikz@expandcount by -1%
    \ifnum\tikz@expandcount<0\relax%
      \let\@next=\tikz@@circle@scangiveup%
    \else%
      \let\@next=\tikz@@circle@scanexpand%
    \fi%
    \@next%
  }%
}
\def\tikz@@circle@scanexpand{\expandafter\tikz@@circle}
\def\tikz@@circle@scangiveup#1{\PackageError{tikz}{Cannot parse this radius}{}#1{\tikz@scan@next@command}}
\def\tikz@@@circle(#1){%
  \in@{ and }{#1}%
  \ifin@%
    \tikz@@ellipseB(#1)%
  \else%
    \tikz@@ellipseB(#1 and #1)%
  \fi%
  \tikz@scan@next@command%
}
\def\tikz@@ellipseB(#1 and #2){%
  \pgfpathellipse{\tikz@last@position}{\pgfpoint{#1}{0pt}}{\pgfpoint{0pt}{#2}}%
}

% Syntax 1 for arcs:
% arc (start angle:end angle:radius)
%
% Syntax 2 for arcs:
% arc (start angle:end angle:x-radius/y-radius)
\def\tikz@arcA rc{%
  \tikz@flush@moveto%
  \@ifnextchar({\tikz@@arcto}{\expandafter\tikz@arcA\expandafter r\expandafter c}}

\def\tikz@@arcto(#1){%
  \edef\tikz@temp{(#1)}%
   \expandafter\tikz@@@arcto@and\tikz@temp%
}

\def\tikz@@@arcto@and(#1:#2:#3){%
  \in@{ and }{#3}%
  \ifin@% 
    \tikz@parse@arc@and(#1:#2:#3)%
  \else%
    \tikz@@@arcto(#1:#2:#3)%
  \fi%
}

\def\tikz@parse@arc@and(#1:#2:#3 and #4){%
  \tikz@@@arcto(#1:#2:#3/#4)%
}

\def\tikz@@@arcto(#1:#2:#3){%
  \pgfpatharc{#1}{#2}{#3}%
  \pgf@process{\pgfpointpolar{#1}{#3}}%
  \advance\tikz@lastx by-\pgf@x%
  \advance\tikz@lasty by-\pgf@y%
  \pgf@process{\pgfpointpolar{#2}{#3}}%
  \advance\tikz@lastx by\pgf@x%
  \advance\tikz@lasty by\pgf@y%
  \tikz@lastxsaved=\tikz@lastx%
  \tikz@lastysaved=\tikz@lasty%
  \tikz@scan@next@command%
}


% Syntax for coordinates:
% coordinate (coordinate name) at (point)
% where ``at (point)'' is optional
\def\tikz@coordinate ordinate{%
  \@ifnextchar({\tikz@@coordinate}
  {\tikz@fig ode[shape=coordinate]{}}}%}
\def\tikz@@coordinate(#1){%
  \@ifnextchar a{\tikz@@coordinate@at(#1)}
  {\tikz@fig ode[shape=coordinate](#1){}}}
\def\tikz@@coordinate@at(#1)at#2(#3){%
  \tikz@fig ode[shape=coordinate](#1)at(#3){}}
  


% Syntax for nodes:
% node[options] (node name) {label text}
%
% all of [options], (node name) and {label text} are optional. There
% can be multiple options before the label text as in
% node[draw] (a) [rotate=10] {text}
%
% A label text always ``ends'' the node.
\def\tikz@fig ode{%
  \begingroup%
  \let\tikz@fig@name=\@empty%
    \begingroup%
      \let\nodepart=\tikz@nodepart%
      \let\tikz@options=\@empty%
      \let\tikz@transform=\@empty%
      \let\tikz@mode=\@empty%
      \def\tikz@node@at{\pgfpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
      \iftikz@node@is@a@label%
      \else%
        \let\tikz@time=\@empty%
      \fi%
      \tikz@every@style{every node}%
      \tikz@@scan@fig}%
\def\tikz@@scan@fig{%
  \@ifnextchar a{\tikz@fig@scan@at}
  {\@ifnextchar({\tikz@fig@scan@name}
    {\@ifnextchar[{\tikz@fig@scan@options}%
      {\@ifnextchar\bgroup{\tikz@fig@main}%
      {\PackageError{tikz}{A node must have a (possibly empty) label text}{}%
       \tikz@fig@main{}}}}}}%}}
\def\tikz@fig@scan@at at{%
  \tikz@scan@one@point\tikz@@fig@scan@at}
\def\tikz@@fig@scan@at#1{%
  \def\tikz@node@at{#1}\tikz@@scan@fig}%
\def\tikz@fig@scan@name(#1){\edef\tikz@fig@name{#1}\tikz@@scan@fig}%
\def\tikz@fig@scan@options[#1]{\tikz@setkeys{#1}\tikz@@scan@fig}%
\def\tikz@fig@main{\afterassignment\tikz@@fig@main\let\next=}
\def\tikz@@fig@main{%
    \@ifundefined{pgf@sh@s@\tikz@shape}%
    {\PackageError{tikz}%
      {Unknown shape ``\tikz@shape.'' Using ``rectangle'' instead}{}%
      \def\tikz@shape{rectangle}}%
    {}%
    \tikz@every@style{every \tikz@shape\space node}%
    \setbox\pgfnodeparttextbox=\hbox%
      \bgroup%
        \tikz@every@style{every text node part}%
        \ifx\tikz@textopacity\@empty%
        \else%
          \pgfsetfillopacity{\tikz@textopacity}%
          \pgfsetstrokeopacity{\tikz@textopacity}%
        \fi%
        \pgfinterruptpicture%
          \ifx\tikz@text@width\@empty%
          \else%
            \begingroup%
              \minipage[t]{\tikz@text@width}%
                \tikz@text@action%
          \fi%
          \bgroup%
            \aftergroup\unskip%
            \ifx\tikz@textcolor\@empty%
              \color{.}%
            \else%
              \color{\tikz@textcolor}%
            \fi%
            \tikz@textfont%  
            \setbox\tikz@figbox=\box\voidb@x%
            \tikz@uninstallcommands%
            \aftergroup\tikz@fig@collectresetcolor%
            \ignorespaces%
}
\def\tikz@fig@collectresetcolor{%
  \@ifnextchar\reset@color%
  {\reset@color\afterassignment\tikz@fig@collectresetcolor\let\tikz@temp=}%
  {\tikz@fig@boxdone}%
}
\def\tikz@fig@boxdone{%
          \ifx\tikz@text@width\@empty%
          \else%
              \endminipage%
            \endgroup%
          \fi%
        \endpgfinterruptpicture%
      \egroup%
    \@ifnextchar c{\tikz@fig@withchildren}{\@ifnextchar[{\tikz@fig@withchildren}{\tikz@fig@continue}}}%}
\def\tikz@fig@withchildren{%
  \ifx\tikz@fig@name\@empty%
    % Assign a dummy name
    \global\advance\tikz@fig@count by1\relax
    \edef\tikz@fig@name{tikz@f@\the\tikz@fig@count}%
  \fi%
  \tikz@fig@continue%
}
\def\tikz@fig@continue{%
    \ifx\tikz@text@width\@empty%
    \else%
      \setlength{\pgf@x}{\tikz@text@width}%
      \wd\pgfnodeparttextbox=\pgf@x%
    \fi%
    % Possibly, we are ``online''
    \ifx\tikz@time\@empty%
      \pgftransformshift{\tikz@node@at}%
      \iftikz@fullytransformed%
      \else%
        \pgftransformresetnontranslations
      \fi%
    \else%
      \tikz@timer%
    \fi%
    % Invoke local transformations
    \tikz@transform%  
    \setbox\tikz@figbox=\hbox{%
      \setbox\@tempboxa=\copy\tikz@figbox%
      \unhbox\@tempboxa%
      \hbox{{%
          \pgfinterruptpath%
            \pgfscope%
              \tikz@options%
              \setbox\tikz@figbox=\box\voidb@x%
              \pgfmultipartnode{\tikz@shape}{\tikz@anchor}{\tikz@fig@name}{%
                \@tempdima=\pgflinewidth%
                {\begingroup\tikz@finish}%
                \global\pgflinewidth=\@tempdima%
              }%
            \endpgfscope
          \endpgfinterruptpath%
      }}%
    }%
    % shift box outside group
    \global\setbox\tikz@tempbox=\copy\tikz@figbox%
    \global\let\tikz@last@fig@name=\tikz@fig@name%
  \endgroup\endgroup%
  \setbox\tikz@figbox=\box\tikz@tempbox%  
  \tikz@scan@next@command%
}
\let\tikz@fig@continue@orig=\tikz@fig@continue


% Syntax for parts of  nodes:
% node ... {... \nodepart{name} ... \nodepart{name} ...}

\def\tikz@nodepart#1{%
  \unskip%
  \gdef\tikz@nodepart@name{#1}%
  \global\let\tikz@fig@continue=\tikz@nodepart@continue%
  \@ifnextchar x{\egroup\relax}{\egroup\relax}% gobble spaces
}
\def\tikz@nodepart@continue{%
  \global\let\tikz@fig@continue=\tikz@fig@continue@orig%
  % Now start new box:
   \expandafter\setbox\csname pgfnodepart\tikz@nodepart@name box\endcsname=\hbox%
      \bgroup%
        \tikz@every@style{every \tikz@nodepart@name\space node part}%
        \pgfinterruptpicture%
          \ifx\tikz@text@width\@empty%
          \else%
            \begingroup%
              \minipage[t]{\tikz@text@width}%
                \tikz@text@action%
          \fi%
          \bgroup%
            \aftergroup\unskip%
            \ifx\tikz@textcolor\@empty%
              \color{.}%
            \else%
              \color{\tikz@textcolor}%
            \fi%
            \tikz@textfont%  
            \setbox\tikz@figbox=\box\voidb@x%
            \tikz@uninstallcommands%
            \aftergroup\tikz@fig@collectresetcolor%
            \ignorespaces%
}



% Syntax for trees:
% node {...} child [options] {...} child [options] {...} ...
% node {...} children [options] \var in {list} [options] {...} ...

\def\tikz@children{%
  % Start collecting the children:
  \let\tikz@children@list=\@empty%
  \tikznumberofchildren=0\relax%
  \tikz@collect@children c}

\def\tikz@collect@children{\@ifnextchar c{\tikz@collect@children@cchar}{\tikz@children@collected}}
\def\tikz@collect@children@cchar c{\@ifnextchar h{\tikz@collect@child}{\tikz@children@collected c}}
\def\tikz@collect@child hild{\@ifnextchar[{\tikz@collect@childA}{\tikz@collect@childA[]}}%}
\def\tikz@collect@childA[#1]{\@ifnextchar f{\tikz@collect@children@foreach[#1]}{\tikz@collect@childB[#1]}}
\def\tikz@collect@childB[#1]{%
  \advance\tikznumberofchildren by1\relax
  \expandafter\def\expandafter\tikz@children@list\expandafter{\tikz@children@list \tikz@childnode[#1]}%
  \@ifnextchar\bgroup{\tikz@collect@child@code}{\tikz@collect@child@code{}}}
\def\tikz@collect@child@code#1{%
  \expandafter\def\expandafter\tikz@children@list\expandafter{\tikz@children@list{#1}}%
  \tikz@collect@children%
}
\def\tikz@collect@children@foreach[#1]foreach#2in#3{%
  \@ifnextchar\bgroup{\tikz@collect@children@foreachA{#1}{#2}{#3}}{\tikz@collect@children@foreachA{#1}{#2}{#3}{}}}
\def\tikz@collect@children@foreachA#1#2#3#4{%
  \expandafter\def\expandafter\tikz@children@list\expandafter
    {\tikz@children@list\tikz@childrennodes[#1]{#2}{#3}{#4}}%
  \c@pgf@counta=\tikznumberofchildren%
  \foreach#2in{#3}%
  {%
    \global\advance\c@pgf@counta by1\relax%
  }%
  \tikznumberofchildren=\c@pgf@counta%
  \tikz@collect@children%
}
\long\def\tikz@children@collected{%
  \begingroup%
    \advance\tikztreelevel by 1\relax%
    \let\tikz@options=\@empty%
    \let\tikz@transform=\@empty%
    \tikz@every@style{level \the\tikztreelevel}%
    \tikz@options%
    \tikz@transform%            
    \let\tikzparentnode=\tikz@last@fig@name%
    % Transform to center of node
    \pgftransformshift{\pgfpointanchor{\tikzparentnode}{center}}%
    \tikznumberofcurrentchild=0\relax%
    \tikz@children@list%
    \global\setbox\tikz@tempbox=\copy\tikz@figbox%
  \endgroup%
  \setbox\tikz@figbox=\box\tikz@tempbox%  
  \tikz@scan@next@command%
}


% Syntax for children:
%
% children [all children options] \var in {values} [child options] {...}
\def\tikz@childrennodes[#1]#2#3#4{%
  \c@pgf@counta=\tikznumberofcurrentchild\relax%
  \setbox\tikz@tempbox=\box\tikz@figbox%
  \foreach#2in{#3}{%
    \tikznumberofcurrentchild=\c@pgf@counta\relax%
    \setbox\tikz@figbox=\box\tikz@tempbox%
    \tikz@childnode[#1]{#4}%
    % we must now make the current child number and the figbox survive
    % the group
    \global\c@pgf@counta=\tikznumberofcurrentchild\relax%
    \global\setbox\tikz@tempbox=\box\tikz@figbox%
  }%
  \tikznumberofcurrentchild=\c@pgf@counta\relax%
  \setbox\tikz@figbox=\box\tikz@tempbox%
}


% Syntax for child:
%
% child
%
% child[options]
%
% child[options] {node (name) {child node text} ...
%   edge from parent[options] node {label text} node {label text}}

\def\tikz@childnode[#1]#2{%
  \advance\tikznumberofcurrentchild by1\relax%
  \setbox\tikz@figbox=\hbox\bgroup%
    \unhbox\tikz@figbox%
    \hbox\bgroup\bgroup%
        \pgfinterruptpath%
          \pgfscope%
            \let\tikz@options=\@empty%
            \let\tikz@transform=\@empty%
            \tikz@every@style{every child}%
            \tikz@setkeys{#1}%
            \tikz@options%
            \tikz@transform%            
            \tikz@grow%
            % Typeset node:
            \edef\tikz@parent@node@name{[name=\tikzparentnode-\the\tikznumberofcurrentchild,style=every child node]}%
            \def\tikz@child@node@text{[shape=coordinate]{}}
            \tikz@parse@child@node#2\pgf@stop%
            \expandafter\expandafter\expandafter\node
            \expandafter\tikz@parent@node@name
              \tikz@child@node@text
              \pgfextra{\global\let\tikz@childnode@name=\tikz@last@fig@name};%
            \let\tikzchildnode=\tikz@childnode@name%
            {%
              \def\tikz@edge@to@parent@needed{edge from parent}
              \ifx\tikz@child@node@rest\@empty%
                \path edge from parent;%
              \else%
                \path (0,0) \tikz@child@node@rest \tikz@edge@to@parent@needed;%
              \fi%
            }%
        \endpgfscope%
      \endpgfinterruptpath%
    \egroup\egroup%
  \egroup%
}

\def\tikz@parse@child@node{%
  \@ifnextchar n{\tikz@parse@child@node@n}%
  {\@ifnextchar c{\tikz@parse@child@node@c}%
    {\tikz@parse@child@node@rest}}}
\def\tikz@parse@child@node@rest#1\pgf@stop{\def\tikz@child@node@rest{#1}}
\def\tikz@parse@child@node@c c{\@ifnextchar o{\tikz@parse@child@node@co}{\tikz@parse@child@node@rest c}}
\def\tikz@parse@child@node@co o{\@ifnextchar o{\tikz@parse@child@node@coordinate}{\tikz@parse@child@node@rest co}}
\def\tikz@parse@child@node@coordinate ordinate{%
  \@ifnextchar ({\tikz@@parse@child@node@coordinate}{%
    \def\tikz@child@node@text{[shape=coordinate]{}}%
    \tikz@parse@child@node@rest}}%}
\def\tikz@@parse@child@node@coordinate(#1){%
  \@ifnextchar a{\tikz@p@c@n@c@at(#1)}{%
    \def\tikz@child@node@text{[shape=coordinate,name=#1]{}}%
    \tikz@parse@child@node@rest}}
\def\tikz@p@c@n@c@at(#1)at#2(#3){%
  \def\tikz@child@node@text{[shape=coordinate,name=#1]at(#3){}}%
  \tikz@parse@child@node@rest}%
\def\tikz@parse@child@node@n node{%
  \let\tikz@child@node@text=\@empty%
  \tikz@p@c@s}%
\def\tikz@p@c@s{%
  \@ifnextchar a{\tikz@p@c@s@at}
  {\@ifnextchar ({\tikz@p@c@s@paran}
    {\@ifnextchar [{\tikz@p@c@s@bra}
      {\@ifnextchar \bgroup{\tikz@p@c@s@group}
        {\PackageError{tikz}{Cannot parse this node}{}}}}}}%}}
\def\tikz@p@c@s@at at#1(#2){%
  \expandafter\def\expandafter\tikz@child@node@text\expandafter{\tikz@child@node@text at(#2)}
  \tikz@p@c@s}
\def\tikz@p@c@s@paran(#1){%
  \expandafter\def\expandafter\tikz@child@node@text\expandafter{\tikz@child@node@text(#1)}
  \tikz@p@c@s}
\def\tikz@p@c@s@bra[#1]{%
  \expandafter\def\expandafter\tikz@child@node@text\expandafter{\tikz@child@node@text[#1]}
  \tikz@p@c@s}
\def\tikz@p@c@s@group#1{%
  \expandafter\def\expandafter\tikz@child@node@text\expandafter{\tikz@child@node@text{#1}}
  \tikz@parse@child@node@rest}


%
% Timers
% 

\def\tikz@timer@line{%
  \pgftransformlineattime{\tikz@time}{\tikz@timer@start}{\tikz@timer@end}%
}

\def\tikz@timer@vhline{%
  \ifdim\tikz@time pt<0.5pt% first half
    \pgf@process{\tikz@timer@start}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\tikz@timer@end}%
    \pgf@xb=\tikz@time pt%
    \pgf@xb=2\pgf@xb%    
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}{\noexpand\tikz@timer@start}{%
        \noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@y}}}%
    \tikz@marshal%
  \else% second half
    \pgf@process{\tikz@timer@start}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\tikz@timer@end}%
    \pgf@xb=\tikz@time pt%
    \pgf@xb=2\pgf@xb%
    \advance\pgf@xb by-1pt%
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
      {\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@y}}{\noexpand\tikz@timer@end}}%
    \tikz@marshal%
  \fi%
}

\def\tikz@timer@hvline{%
  \ifdim\tikz@time pt<0.5pt% first half
    \pgf@process{\tikz@timer@start}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\tikz@timer@end}%
    \pgf@xb=\tikz@time pt%
    \pgf@xb=2\pgf@xb%    
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}{\noexpand\tikz@timer@start}{%
        \noexpand\pgfpoint{\the\pgf@x}{\the\pgf@ya}}}%
    \tikz@marshal%
  \else% second half
    \pgf@process{\tikz@timer@start}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\tikz@timer@end}%
    \pgf@xb=\tikz@time pt%
    \pgf@xb=2\pgf@xb%
    \advance\pgf@xb by-1pt%
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
      {\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@ya}}{\noexpand\tikz@timer@end}}%
    \tikz@marshal%
  \fi%
}

\def\tikz@timer@curve{%
  \pgftransformcurveattime{\tikz@time}{\tikz@timer@start}{\tikz@timer@cont@one}{\tikz@timer@cont@two}{\tikz@timer@end}%
}




%
% Coordinate management
%


% Last position visited
\def\tikz@last@position{\pgfpoint{\tikz@lastx}{\tikz@lasty}}
\def\tikz@last@position@saved{\pgfpoint{\tikz@lastxsaved}{\tikz@lastysaved}}

% Make given point the last position visited
\def\tikz@make@last@position#1{%
  \pgf@process{#1}%
  \tikz@lastx=\pgf@x\relax%
  \tikz@lasty=\pgf@y\relax%
  \iftikz@updatecurrent%
    \tikz@lastxsaved=\pgf@x\relax%
    \tikz@lastysaved=\pgf@y\relax%
  \fi%
  \tikz@updatecurrenttrue%
}

\newif\iftikz@updatecurrent
\tikz@updatecurrenttrue



% Scanner: Scans a point or a relative point. 
% It then calls the first parameter with the argument set to an
% appropriate pgf command representing that point.

\def\tikz@scan@one@point#1{%
  \tikz@shapeborderfalse%
  \@ifnextchar+{\tikz@scan@relative#1}{\tikz@scan@absolute#1}}
\def\tikz@scan@absolute#1{%
  \@ifnextchar({\tikz@scan@@absolute#1}%)
  {%
    \advance\tikz@expandcount by -1%
    \ifnum\tikz@expandcount<0\relax%
      \let\@next=\tikz@@scangiveup%
    \else%
      \let\@next=\tikz@@scanexpand
    \fi%
    \@next{#1}%
  }%
}
\def\tikz@@scanexpand#1{\expandafter\tikz@scan@one@point\expandafter#1}
\def\tikz@@scangiveup#1{\PackageError{tikz}{Cannot parse this coordinate}{}#1{\pgfpointorigin}}
\def\tikz@scan@@absolute#1(#2){%
  \edef\tikz@temp{(#2)}%
  \expandafter\tikz@@scan@@absolute\expandafter#1\tikz@temp%
}
\def\tikz@@scan@@absolute#1({%
  \@ifnextchar[% uhoh... options!
  {\def\tikz@scan@point@recall{#1}\tikz@scan@options}%
  {\tikz@@@scan@@absolute#1(}%
}

\def\tikz@scan@options[#1]#2{%
  \def\tikz@scan@point@options{#1}%
  \tikz@@@scan@@absolute\tikz@scan@handle@options(#2%
}

\def\tikz@scan@handle@options#1{%
  {%
    % Ok, compute point with options set and zero transformation
    % matrix:
    \pgftransformreset%
    \let\tikz@transform=\@empty%
    \expandafter\tikz@setkeys\expandafter{\tikz@scan@point@options}%
    \tikz@transform%
    \pgf@process{\pgfpointtransformed{#1}}%
    \xdef\tikz@marshal{\expandafter\noexpand\tikz@scan@point@recall{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}}%
  }%
  \tikz@marshal%  
}

\def\tikz@@@scan@@absolute#1(#2){%
  \in@{intersection of}{#2}%
  \ifin@%
    \let\@next\tikz@parse@intersection%
  \else%
    \in@|{#2}%
    \ifin@
      \in@{-|}{#2}%
      \ifin@
        \let\@next\tikz@parse@hv%
      \else%
        \let\@next\tikz@parse@vh%
      \fi%
    \else%
      \in@:{#2}%
      \ifin@
        \let\@next\tikz@parse@polar%
      \else%
        \in@,{#2}%
        \ifin@%      
          \let\@next\tikz@parse@regular%
        \else%
          \let\@next\tikz@parse@node%
        \fi%
      \fi%
    \fi%
  \fi%
  \@next#1(#2)%
}

\newif\iftikz@isdimension
\def\tikz@checkunit#1{%
  \@tempdima\z@%
  \afterassignment\tikz@@checkunit%
  \@tempdima#1\@tempdima\tikz@unique%
}
\def\tikz@@checkunit{\@ifnextchar\tikz@unique{\tikz@checkunit@number}{\tikz@checkunit@dimension}}
\def\tikz@checkunit@number\tikz@unique{\tikz@isdimensionfalse}
\def\tikz@checkunit@dimension#1\tikz@unique{\tikz@isdimensiontrue}

\def\tikz@parse@polar#1(#2:#3){%
  \@ifundefined{tikz@polar@dir@#2}
  {#1{\pgfpointpolar{#2}{#3}}}
  {%
    \edef\tikz@marshal{\noexpand#1{\noexpand\pgfpointpolar{\csname tikz@polar@dir@#2\endcsname}{#3}}}%
    \tikz@marshal%
  }%
}
\def\tikz@polar@dir@up{90}
\def\tikz@polar@dir@down{-90}
\def\tikz@polar@dir@left{180}
\def\tikz@polar@dir@right{0}
\def\tikz@polar@dir@north{90}
\def\tikz@polar@dir@south{-90}
\def\tikz@polar@dir@east{0}
\def\tikz@polar@dir@west{180}
\expandafter\def\csname tikz@polar@dir@north east\endcsname{45}
\expandafter\def\csname tikz@polar@dir@north west\endcsname{135}
\expandafter\def\csname tikz@polar@dir@south east\endcsname{-45}
\expandafter\def\csname tikz@polar@dir@south west\endcsname{-135}

\def\tikz@parse@regular#1(#2,#3){%
  \in@,{#3}%
  \ifin@%  
    \tikz@parse@splitxyz{#1}{#2}#3,%
  \else%
    \tikz@checkunit{#2}%
    \iftikz@isdimension%
      \def\@next{#1{\pgfpoint{#2}{#3}}}%
    \else%
      \def\@next{#1{\pgfpointxy{#2}{#3}}}%
    \fi%
  \fi%
  \@next%
}

\def\tikz@parse@splitxyz#1#2#3,#4,{%
  \def\@next{#1{\pgfpointxyz{#2}{#3}{#4}}}%
}

\def\tikz@coordinate@text{coordinate}

\def\tikz@parse@node#1(#2){%
  \in@.{#2}% Ok, flag this
  \ifin@
    \tikz@calc@anchor#2\tikz@stop%
  \else%
    \tikz@calc@anchor#2.center\tikz@stop% to be on the save side, in
                                % case iftikz@shapeborder is ignored...
    \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\tikz@coordinate@text%
    \else
      \tikz@shapebordertrue%
      \def\tikz@shapeborder@name{#2}%
    \fi%
  \fi%
  \edef\tikz@marshal{\noexpand#1{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}}%
  \tikz@marshal%
}

\def\tikz@calc@anchor#1.#2\tikz@stop{%
  \pgfpointanchor{#1}{#2}%
}


\def\tikz@parse@hv#1(#2){%
  \in@{ -| }{#2}%
  \ifin@%
    \let\tikz@next=\tikz@parse@hvboth%
  \else%
    \in@{ -|}{#2}%
    \ifin@%
      \let\tikz@next=\tikz@parse@hvleft%
    \else%
      \in@{-| }{#2}%
      \ifin@%
        \let\tikz@next=\tikz@parse@hvright%
      \else%
        \let\tikz@next=\tikz@parse@hvdone%
      \fi%
    \fi%
  \fi%
  \tikz@next#1(#2)}
\def\tikz@parse@hvboth#1(#2 -| #3){\tikz@parse@vhdone#1(#3|-#2)}
\def\tikz@parse@hvleft#1(#2 -|#3){\tikz@parse@vhdone#1(#3|-#2)}
\def\tikz@parse@hvright#1(#2-| #3){\tikz@parse@vhdone#1(#3|-#2)}
\def\tikz@parse@hvdone#1(#2-|#3){\tikz@parse@vhdone#1(#3|-#2)}

\def\tikz@parse@vh#1(#2){%
  \in@{ |- }{#2}%
  \ifin@%
    \let\tikz@next=\tikz@parse@vhboth%
  \else%
    \in@{ |-}{#2}%
    \ifin@%
      \let\tikz@next=\tikz@parse@vhleft%
    \else%
      \in@{|- }{#2}%
      \ifin@%
        \let\tikz@next=\tikz@parse@vhright%
      \else%
        \let\tikz@next=\tikz@parse@vhdone%
      \fi%
    \fi%
  \fi%
  \tikz@next#1(#2)}
\def\tikz@parse@vhboth#1(#2 |- #3){\tikz@parse@vhdone#1(#2|-#3)}
\def\tikz@parse@vhleft#1(#2 |-#3){\tikz@parse@vhdone#1(#2|-#3)}
\def\tikz@parse@vhright#1(#2|- #3){\tikz@parse@vhdone#1(#2|-#3)}
\def\tikz@parse@vhdone#1(#2|-#3){%
  {%
    \tikz@@@scan@@absolute\tikz@parse@vh@mid(#2)%
    \tikz@@@scan@@absolute\tikz@parse@vh@end(#3)%
    \xdef\tikz@marshal{\noexpand#1{\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}}%
  }%
  \tikz@shapeborderfalse%
  \tikz@marshal%
}
\def\tikz@parse@vh@mid#1{\pgf@process{#1}\pgf@xa=\pgf@x}
\def\tikz@parse@vh@end#1{\pgf@process{#1}\pgf@ya=\pgf@y}

\def\tikz@parse@intersection#1(intersection of #2--#3 and #4--#5){%
  {%
    \tikz@@@scan@@absolute\tikz@parse@intersection@a(#2)%
    \tikz@@@scan@@absolute\tikz@parse@intersection@b(#3)%
    \tikz@@@scan@@absolute\tikz@parse@intersection@c(#4)%
    \tikz@@@scan@@absolute\tikz@parse@intersection@d(#5)%
    \xdef\tikz@marshal{\noexpand#1{\noexpand\pgfpointintersectionoflines%
        {\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}%
        {\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@yb}}%
        {\noexpand\pgfpoint{\the\pgf@xc}{\the\pgf@yc}}%
        {\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}}}%
  }%
  \tikz@shapeborderfalse%
  \tikz@marshal%  
}

\def\tikz@parse@intersection@a#1{\pgf@process{#1}\pgf@xa=\pgf@x\pgf@ya=\pgf@y}
\def\tikz@parse@intersection@b#1{\pgf@process{#1}\pgf@xb=\pgf@x\pgf@yb=\pgf@y}
\def\tikz@parse@intersection@c#1{\pgf@process{#1}\pgf@xc=\pgf@x\pgf@yc=\pgf@y}
\def\tikz@parse@intersection@d#1{\pgf@process{#1}}

\def\tikz@scan@relative#1+{%
  \@ifnextchar+{\tikz@scan@plusplus#1}{\tikz@scan@oneplus#1}}

\def\tikz@scan@plusplus#1+{%
  \def\tikz@doafter{#1}%
  \tikz@scan@absolute\tikz@add%
}
\def\tikz@add#1{%
  \tikz@doafter{\pgfpointadd{#1}{\tikz@last@position@saved}}%
}
\def\tikz@scan@oneplus#1{%
  \def\tikz@doafter{#1}%
  \tikz@updatecurrentfalse%
  \tikz@scan@absolute\tikz@add%
} 


\endinput

xkeyval.tex
%%
%% This is file `xkeyval.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xkeyval.dtx  (with options: `xkvtex')
%% 
%% ---------------------------------------
%% Copyright (C) 2004-2005 Hendri Adriaens
%% ---------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% This Current Maintainer of this work is Hendri Adriaens.
%%
%% This work consists of the file xkeyval.dtx and derived files
%% keyval.tex, xkvtxhdr.tex, xkeyval.sty, xkeyval.tex, xkvview.sty,
%% xkvltxp.sty, pst-xkey.tex, pst-xkey.sty, xkveca.cls, xkvecb.cls,
%% xkvesa.sty, xkvesb.sty, xkvesc.sty, xkvex1.tex, xkvex2.tex,
%% xkvex3.tex and xkvex4.tex.
%%
%% The following files constitute the xkeyval bundle and must be
%% distributed as a whole: readme, xkeyval.pdf, keyval.tex,
%% pst-xkey.sty, pst-xkey.tex, xkeyval.sty, xkeyval.tex, xkvview.sty,
%% xkvltxp.sty, xkvtxhdr.tex, pst-xkey.dtx and xkeyval.dtx.
%%
\csname XKeyValLoaded\endcsname
\let\XKeyValLoaded\endinput
\edef\XKVcatcodes{%
  \catcode`\noexpand\@\the\catcode`\@\relax
  \catcode`\noexpand\=\the\catcode`\=\relax
  \catcode`\noexpand\,\the\catcode`\,\relax
  \catcode`\noexpand\:\the\catcode`\:\relax
  \let\noexpand\XKVcatcodes\relax
}
\catcode`\@11\relax
\catcode`\=12\relax
\catcode`\,12\relax
\catcode`\:12\relax
\newtoks\XKV@toks
\newcount\XKV@depth
\newif\ifXKV@st
\newif\ifXKV@sg
\newif\ifXKV@pl
\newif\ifXKV@knf
\newif\ifXKV@rkv
\newif\ifXKV@inpox
\newif\ifXKV@preset
\let\XKV@rm\@empty
\ifx\ProvidesFile\@undefined
  \message{2005/11/25 v2.5e key=value parser (HA)}
  \input xkvtxhdr
\else
  \ProvidesFile{xkeyval.tex}[2005/11/25 v2.5e key=value parser (HA)]
  \@addtofilelist{xkeyval.tex}
\fi
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\long\def\XKV@afterfi#1\fi{\fi#1}
\long\def\XKV@afterelsefi#1\else#2\fi{\fi#1}
\ifx\ifcsname\@undefined\XKV@afterelsefi
  \def\XKV@ifundefined#1{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
      \expandafter\ifx\csname#1\endcsname\relax
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }
\else
  \def\XKV@ifundefined#1{%
    \ifcsname#1\endcsname
      \expandafter\@secondoftwo
    \else
      \expandafter\@firstoftwo
    \fi
  }
\fi
\XKV@ifundefined{ver@keyval.sty}{
  \input keyval
  \expandafter\def\csname ver@keyval.sty\endcsname{1999/03/16}
}{}
\long\def\@ifnextcharacter#1#2#3{%
  \@ifnextchar\bgroup
  {\@ifnextchar{#1}{#2}{#3}}%
  {\@ifncharacter{#1}{#2}{#3}}%
}
\long\def\@ifncharacter#1#2#3#4{%
  \if\string#1\string#4%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {#2}{#3}#4%
}
\long\def\XKV@for@n#1#2#3{%
  \def#2{#1}%
  \ifx#2\@empty
    \XKV@for@break
  \else
    \expandafter\XKV@f@r
  \fi
  #2{#3}#1,\@nil,%
}
\long\def\XKV@f@r#1#2#3,{%
  \def#1{#3}%
  \ifx#1\@nnil
    \expandafter\@gobbletwo
  \else
    #2\expandafter\XKV@f@r
  \fi
  #1{#2}%
}
\long\def\XKV@for@break #1\@nil,{\fi}
\long\def\XKV@for@o#1{\expandafter\XKV@for@n\expandafter{#1}}
\long\def\XKV@for@en#1#2#3{\XKV@f@r#2{#3}#1,\@nil,}
\long\def\XKV@for@eo#1#2#3{%
  \def#2{\XKV@f@r#2{#3}}\expandafter#2#1,\@nil,%
}
\long\def\XKV@whilist#1#2#3\fi#4{%
  #3\expandafter\XKV@wh@list#1,\@nil,\@nil\@@#2#3\fi{#4}{}\fi
}
\long\def\XKV@wh@list#1,#2\@@#3#4\fi#5#6{%
  \def#3{#1}%
  \ifx#3\@nnil
    \def#3{#6}\expandafter\XKV@wh@l@st
  \else
    #4%
      #5\expandafter\expandafter\expandafter\XKV@wh@list
    \else
      \def#3{#6}\expandafter\expandafter\expandafter\XKV@wh@l@st
    \fi
  \fi
  #2\@@#3#4\fi{#5}{#1}%
}
\long\def\XKV@wh@l@st#1\@@#2#3\fi#4#5{}
\def\XKV@addtomacro@n#1#2{%
  \expandafter\def\expandafter#1\expandafter{#1#2}%
}
\def\XKV@addtomacro@o#1#2{%
  \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter#1\expandafter
    \expandafter\expandafter{\expandafter#1#2}%
}
\def\XKV@addtolist@n#1#2{%
  \ifx#1\@empty
    \XKV@addtomacro@n#1{#2}%
  \else
    \XKV@addtomacro@n#1{,#2}%
  \fi
}
\def\XKV@addtolist@o#1#2{%
  \ifx#1\@empty
    \XKV@addtomacro@o#1#2%
  \else
    \XKV@addtomacro@o#1{\expandafter,#2}%
  \fi
}
\def\XKV@addtolist@x#1#2{\edef#1{#1\ifx#1\@empty\else,\fi#2}}
\def\@selective@sanitize{\@testopt\@s@lective@sanitize\@M}
\def\@s@lective@sanitize[#1]#2#3{%
  \begingroup
    \count@#1\relax\advance\count@\@ne
    \XKV@toks\expandafter{#3}%
    \def#3{#2}\@onelevel@sanitize#3%
    \edef#3{{#3}{\the\XKV@toks}}%
    \expandafter\@s@l@ctive@sanitize\expandafter#3#3%
  \expandafter\endgroup\expandafter\def\expandafter#3\expandafter{#3}%
}
\def\@s@l@ctive@sanitize#1#2#3{%
  \def\@i{\futurelet\@@tok\@ii}%
  \def\@ii{%
    \expandafter\@iii\meaning\@@tok\relax
    \ifx\@@tok\@s@l@ctive@sanitize
      \let\@@cmd\@gobble
    \else
      \ifx\@@tok\@sptoken
        \XKV@toks\expandafter{#1}\edef#1{\the\XKV@toks\space}%
        \def\@@cmd{\afterassignment\@i\let\@@tok= }%
      \else
        \let\@@cmd\@iv
      \fi
    \fi
    \@@cmd
  }%
  \def\@iii##1##2\relax{\if##1\@backslashchar\let\@@tok\relax\fi}%
  \def\@iv##1{%
    \toks@\expandafter{#1}\XKV@toks{##1}%
    \ifx\@@tok\bgroup
      \advance\count@\m@ne
      \ifnum\count@>\z@
        \begingroup
          \def#1{\expandafter\@s@l@ctive@sanitize
            \csname\string#1\endcsname{#2}}%
          \expandafter#1\expandafter{\the\XKV@toks}%
          \XKV@toks\expandafter\expandafter\expandafter
            {\csname\string#1\endcsname}%
          \edef#1{\noexpand\XKV@toks{\the\XKV@toks}}%
        \expandafter\endgroup#1%
      \fi
      \edef#1{\the\toks@{\the\XKV@toks}}%
      \advance\count@\@ne
      \let\@@cmd\@i
    \else
      \edef#1{\expandafter\string\the\XKV@toks}%
      \expandafter\in@\expandafter{#1}{#2}%
      \edef#1{\the\toks@\ifin@#1\else
              \ifx\@@tok\@sptoken\space\else\the\XKV@toks\fi\fi}%
      \edef\@@cmd{\noexpand\@i\ifx\@@tok\@sptoken\the\XKV@toks\fi}%
    \fi
    \@@cmd
  }%
  \let#1\@empty\@i#3\@s@l@ctive@sanitize
}
\def\XKV@checksanitizea#1#2{%
  \XKV@ch@cksanitize{#1}#2=%
  \ifin@\else\XKV@ch@cksanitize{#1}#2,\fi
  \ifin@\@selective@sanitize[0]{,=}#2\fi
}
\def\XKV@checksanitizeb#1#2{%
  \XKV@ch@cksanitize{#1}#2,%
  \ifin@\@selective@sanitize[0],#2\fi
}
\def\XKV@ch@cksanitize#1#2#3{%
  \def#2{#1}%
  \@onelevel@sanitize#2%
  \@expandtwoargs\in@#3{#2}%
  \ifin@
    \def#2##1#3##2\@nil{%
      \def#2{##2}%
      \ifx#2\@empty\else\in@false\fi
    }%
    #2#1#3\@nil
  \fi
  \def#2{#1}%
}
\def\XKV@sp@deflist#1#2{%
  \let#1\@empty
  \XKV@for@n{#2}\XKV@resa{%
    \expandafter\KV@@sp@def\expandafter\XKV@resa\expandafter{\XKV@resa}%
    \XKV@addtomacro@o#1{\expandafter,\XKV@resa}%
  }%
  \ifx#1\@empty\else
    \def\XKV@resa,##1\@nil{\def#1{##1}}%
    \expandafter\XKV@resa#1\@nil
  \fi
}
\def\XKV@merge#1#2#3{%
  \XKV@checksanitizea{#2}\XKV@tempa
  \XKV@for@o\XKV@tempa\XKV@tempa{%
    \XKV@pltrue
    #3\XKV@tempa\XKV@tempb
    \let\XKV@tempc#1%
    \let#1\@empty
    \XKV@for@o\XKV@tempc\XKV@tempc{%
      #3\XKV@tempc\XKV@tempd
      \ifx\XKV@tempb\XKV@tempd
        \XKV@plfalse
        \XKV@addtolist@o#1\XKV@tempa
      \else
        \XKV@addtolist@o#1\XKV@tempc
      \fi
    }%
    \ifXKV@pl\XKV@addtolist@o#1\XKV@tempa\fi
  }%
  \ifXKV@st\global\let#1#1\fi
}
\def\XKV@delete#1#2#3{%
  \XKV@checksanitizeb{#2}\XKV@tempa
  \let\XKV@tempb#1%
  \let#1\@empty
  \XKV@for@o\XKV@tempb\XKV@tempb{%
    #3\XKV@tempb\XKV@tempc
    \@expandtwoargs\in@{,\XKV@tempc,}{,\XKV@tempa,}%
    \ifin@\else\XKV@addtolist@o#1\XKV@tempb\fi
  }%
  \ifXKV@st\global\let#1#1\fi
}
\def\XKV@warn#1{\message{xkeyval warning: #1}}
\def\XKV@err#1{\errmessage{xkeyval error: #1}}
\def\KV@errx{\XKV@err}
\let\KV@err\KV@errx
\def\XKV@ifstar#1{\@ifnextcharacter*{\@firstoftwo{#1}}}
\def\XKV@ifplus#1{\@ifnextcharacter+{\@firstoftwo{#1}}}
\def\XKV@makepf#1{%
  \KV@@sp@def\XKV@prefix{#1}%
  \def\XKV@resa{XKV}%
  \ifx\XKV@prefix\XKV@resa
    \XKV@err{`XKV' prefix is not allowed}%
    \let\XKV@prefix\@empty
  \else
    \edef\XKV@prefix{\ifx\XKV@prefix\@empty\else\XKV@prefix @\fi}%
  \fi
}
\def\XKV@makehd#1{%
  \expandafter\KV@@sp@def\expandafter\XKV@header\expandafter{#1}%
  \edef\XKV@header{%
    \XKV@prefix\ifx\XKV@header\@empty\else\XKV@header @\fi
  }%
}
\def\XKV@srstate#1#2{%
  \ifx\@empty#2\@empty\advance\XKV@depth\@ne\fi
  \XKV@for@n{XKV@prefix,XKV@fams,XKV@na,ifXKV@st,ifXKV@pl,ifXKV@knf}%
    \XKV@resa{\expandafter\let\csname\XKV@resa#1\expandafter
      \endcsname\csname\XKV@resa#2\endcsname
  }%
  \ifx\@empty#1\@empty\advance\XKV@depth\m@ne\fi
}
\def\XKV@testopta#1{%
  \XKV@ifstar{\XKV@sttrue\XKV@t@stopta{#1}}%
    {\XKV@stfalse\XKV@t@stopta{#1}}%
}
\def\XKV@t@stopta#1{\XKV@ifplus{\XKV@pltrue#1}{\XKV@plfalse#1}}
\def\XKV@testoptb#1{\@testopt{\XKV@t@stoptb#1}{KV}}
\def\XKV@t@stoptb#1[#2]#3{%
  \XKV@makepf{#2}%
  \XKV@makehd{#3}%
  \KV@@sp@def\XKV@tfam{#3}%
  #1%
}
\def\XKV@testoptc#1{\@testopt{\XKV@t@stoptc#1}{KV}}
\def\XKV@t@stoptc#1[#2]#3{%
  \XKV@makepf{#2}%
  \XKV@checksanitizeb{#3}\XKV@fams
  \expandafter\XKV@sp@deflist\expandafter
    \XKV@fams\expandafter{\XKV@fams}%
  \@testopt#1{}%
}
\def\XKV@testoptd#1#2{%
  \XKV@testoptb{%
    \edef\XKV@tempa{#2\XKV@header}%
    \def\XKV@tempb{\@testopt{\XKV@t@stoptd#1}}%
    \expandafter\XKV@tempb\expandafter{\XKV@tempa}%
  }%
}
\def\XKV@t@stoptd#1[#2]#3{%
  \@ifnextchar[{\XKV@sttrue#1{#2}{#3}}{\XKV@stfalse#1{#2}{#3}[]}%
}
\def\XKV@ifcmd#1#2#3{%
  \def\XKV@@ifcmd##1#2##2##3\@nil##4{%
    \def##4{##2}\ifx##4\@nnil
      \def##4{##1}\expandafter\@secondoftwo
    \else
      \expandafter\@firstoftwo
    \fi
  }%
  \XKV@@ifcmd#1#2{\@nil}\@nil#3%
}
\def\XKV@getkeyname#1#2{\expandafter\XKV@g@tkeyname#1=\@nil#2}
\def\XKV@g@tkeyname#1=#2\@nil#3{%
  \XKV@ifcmd{#1}\savevalue#3{\XKV@rkvtrue\XKV@sgfalse}{%
    \XKV@ifcmd{#1}\gsavevalue#3%
      {\XKV@rkvtrue\XKV@sgtrue}{\XKV@rkvfalse\XKV@sgfalse}%
  }%
}
\def\XKV@getsg#1#2{%
  \expandafter\XKV@ifcmd\expandafter{#1}\global#2\XKV@sgtrue\XKV@sgfalse
}
\def\XKV@define@default#1#2{%
  \expandafter\def\csname\XKV@header#1@default\expandafter
    \endcsname\expandafter{\csname\XKV@header#1\endcsname{#2}}%
}
\def\define@key{\XKV@testoptb\XKV@define@key}
\def\XKV@define@key#1{%
  \@ifnextchar[{\XKV@d@fine@k@y{#1}}{%
    \expandafter\def\csname\XKV@header#1\endcsname####1%
  }%
}
\def\XKV@d@fine@k@y#1[#2]{%
  \XKV@define@default{#1}{#2}%
  \expandafter\def\csname\XKV@header#1\endcsname##1%
}
\def\define@cmdkey{\XKV@testoptd\XKV@define@cmdkey{cmd}}
\def\XKV@define@cmdkey#1#2[#3]#4{%
  \ifXKV@st\XKV@define@default{#2}{#3}\fi
  \def\XKV@tempa{\expandafter\def\csname\XKV@header#2\endcsname####1}%
  \begingroup\expandafter\endgroup\expandafter\XKV@tempa\expandafter
    {\expandafter\def\csname#1#2\endcsname{##1}#4}%
}
\def\define@cmdkeys{\XKV@testoptd\XKV@define@cmdkeys{cmd}}
\def\XKV@define@cmdkeys#1#2[#3]{%
  \XKV@sp@deflist\XKV@tempa{#2}%
  \XKV@for@o\XKV@tempa\XKV@tempa{%
    \edef\XKV@tempa{\noexpand\XKV@define@cmdkey{#1}{\XKV@tempa}}%
    \XKV@tempa[#3]{}%
  }%
}
\def\define@choicekey{\XKV@testopta{\XKV@testoptb\XKV@define@choicekey}}
\def\XKV@define@choicekey#1{\@testopt{\XKV@d@fine@choicekey{#1}}{}}
\def\XKV@d@fine@choicekey#1[#2]#3{%
  \toks@{#2}%
  \XKV@sp@deflist\XKV@tempa{#3}\XKV@toks\expandafter{\XKV@tempa}%
  \@ifnextchar[{\XKV@d@fine@ch@icekey{#1}}{\XKV@d@fine@ch@ic@key{#1}}%
}
\def\XKV@d@fine@ch@icekey#1[#2]{%
  \XKV@define@default{#1}{#2}%
  \XKV@d@fine@ch@ic@key{#1}%
}
\def\XKV@d@fine@ch@ic@key#1{%
  \ifXKV@pl\XKV@afterelsefi
    \expandafter\XKV@d@f@ne@ch@ic@k@y
  \else\XKV@afterfi
    \expandafter\XKV@d@f@ne@ch@ic@key
  \fi
  \csname\XKV@header#1\endcsname
}
\def\XKV@d@f@ne@ch@ic@key#1#2{\XKV@d@f@n@@ch@ic@k@y#1{{#2}}}
\def\XKV@d@f@ne@ch@ic@k@y#1#2#3{\XKV@d@f@n@@ch@ic@k@y#1{{#2}{#3}}}
\def\XKV@d@f@n@@ch@ic@k@y#1#2{%
  \edef#1##1{%
    \ifXKV@st\noexpand\XKV@sttrue\else\noexpand\XKV@stfalse\fi
    \ifXKV@pl\noexpand\XKV@pltrue\else\noexpand\XKV@plfalse\fi
    \noexpand\XKV@checkchoice[\the\toks@]{##1}{\the\XKV@toks}%
  }%
  \def\XKV@tempa{\def#1####1}%
  \expandafter\XKV@tempa\expandafter{#1{##1}#2}%
}
\def\define@boolkey{\XKV@t@stopta{\XKV@testoptd\XKV@define@boolkey{}}}
\def\XKV@define@boolkey#1#2[#3]{%
  \ifXKV@pl\XKV@afterelsefi
    \expandafter\XKV@d@f@ne@boolkey
  \else\XKV@afterfi
    \expandafter\XKV@d@fine@boolkey
  \fi
  \csname\XKV@header#2\endcsname{#2}{#1#2}{#3}%
}
\def\XKV@d@fine@boolkey#1#2#3#4#5{%
  \XKV@d@f@ne@b@olkey#1{#2}{#3}{#4}%
    {{\csname#3\XKV@resa\endcsname#5}}%
}
\def\XKV@d@f@ne@boolkey#1#2#3#4#5#6{%
  \XKV@d@f@ne@b@olkey#1{#2}{#3}{#4}%
    {{\csname#3\XKV@resa\endcsname#5}{#6}}%
}
\def\XKV@d@f@ne@b@olkey#1#2#3#4#5{%
  \expandafter\newif\csname if#3\endcsname
  \ifXKV@st\XKV@define@default{#2}{#4}\fi
  \ifXKV@pl
    \def#1##1{\XKV@pltrue\XKV@sttrue
      \XKV@checkchoice[\XKV@resa]{##1}{true,false}#5%
    }%
  \else
    \def#1##1{\XKV@plfalse\XKV@sttrue
      \XKV@checkchoice[\XKV@resa]{##1}{true,false}#5%
    }%
  \fi
}
\def\define@boolkeys{\XKV@plfalse\XKV@testoptd\XKV@define@boolkeys{}}
\def\XKV@define@boolkeys#1#2[#3]{%
  \XKV@sp@deflist\XKV@tempa{#2}%
  \XKV@for@o\XKV@tempa\XKV@tempa{%
    \expandafter\XKV@d@fine@boolkeys\expandafter{\XKV@tempa}{#1}{#3}%
  }%
}
\def\XKV@d@fine@boolkeys#1#2#3{%
  \expandafter\XKV@d@f@ne@b@olkey\csname\XKV@header#1\endcsname
    {#1}{#2#1}{#3}{{\csname#2#1\XKV@resa\endcsname}}%
}
\def\XKV@cc{\XKV@testopta{\@testopt\XKV@checkchoice{}}}
\def\XKV@checkchoice[#1]#2#3{%
  \def\XKV@tempa{#1}%
  \ifXKV@st\lowercase{\fi
  \ifx\XKV@tempa\@empty
    \def\XKV@tempa{\XKV@ch@ckch@ice\@nil{#2}{#3}}%
  \else
    \def\XKV@tempa{\XKV@ch@ckchoice#1\@nil{#2}{#3}}%
  \fi
  \ifXKV@st}\fi\XKV@tempa
}
\def\XKV@ch@ckchoice#1#2\@nil#3#4{%
  \def\XKV@tempa{#2}%
  \ifx\XKV@tempa\@empty\XKV@afterelsefi
    \XKV@ch@ckch@ice#1{#3}{#4}%
  \else\XKV@afterfi
    \XKV@@ch@ckchoice#1#2{#3}{#4}%
  \fi
}
\def\XKV@ch@ckch@ice#1#2#3{%
  \def\XKV@tempa{#1}%
  \ifx\XKV@tempa\@nnil\let\XKV@tempa\@empty\else
    \def\XKV@tempa{\def#1{#2}}%
  \fi
  \in@{,#2,}{,#3,}%
  \ifin@
    \ifXKV@pl
      \XKV@addtomacro@n\XKV@tempa\@firstoftwo
    \else
      \XKV@addtomacro@n\XKV@tempa\@firstofone
    \fi
  \else
    \ifXKV@pl
      \XKV@addtomacro@n\XKV@tempa\@secondoftwo
    \else
      \XKV@toks{#2}%
      \XKV@err{value `\the\XKV@toks' is not allowed}%
      \XKV@addtomacro@n\XKV@tempa\@gobble
    \fi
  \fi
  \XKV@tempa
}
\def\XKV@@ch@ckchoice#1#2#3#4{%
  \edef\XKV@tempa{\the\count@}\count@\z@
  \def\XKV@tempb{#3}%
  \def\XKV@tempc##1,{%
    \def#1{##1}%
    \ifx#1\@nnil
      \def#1{#3}\def#2{-1}\count@\XKV@tempa
      \ifXKV@pl
        \let\XKV@tempd\@secondoftwo
      \else
        \XKV@toks{#3}%
        \XKV@err{value `\the\XKV@toks' is not allowed}%
        \let\XKV@tempd\@gobble
      \fi
    \else
      \ifx#1\XKV@tempb
        \edef#2{\the\count@}\count@\XKV@tempa
        \ifXKV@pl
          \let\XKV@tempd\XKV@@ch@ckch@ice
        \else
          \let\XKV@tempd\XKV@@ch@ckch@ic@
        \fi
      \else
        \advance\count@\@ne
        \let\XKV@tempd\XKV@tempc
      \fi
    \fi
    \XKV@tempd
  }%
  \XKV@tempc#4,\@nil,%
}
\def\XKV@@ch@ckch@ice#1\@nil,{\@firstoftwo}
\def\XKV@@ch@ckch@ic@#1\@nil,{\@firstofone}
\def\key@ifundefined{\@testopt\XKV@key@ifundefined{KV}}
\def\XKV@key@ifundefined[#1]#2{%
  \XKV@makepf{#1}%
  \XKV@checksanitizeb{#2}\XKV@fams
  \expandafter\XKV@sp@deflist\expandafter
    \XKV@fams\expandafter{\XKV@fams}%
  \XKV@key@if@ndefined
}
\def\XKV@key@if@ndefined#1{%
  \XKV@knftrue
  \KV@@sp@def\XKV@tkey{#1}%
  \XKV@whilist\XKV@fams\XKV@tfam\ifXKV@knf\fi{%
    \XKV@makehd\XKV@tfam
    \XKV@ifundefined{\XKV@header\XKV@tkey}{}{\XKV@knffalse}%
  }%
  \ifXKV@knf
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\def\disable@keys{\XKV@testoptb\XKV@disable@keys}
\def\XKV@disable@keys#1{%
  \XKV@checksanitizeb{#1}\XKV@tempa
  \XKV@for@o\XKV@tempa\XKV@tempa{%
    \XKV@ifundefined{\XKV@header\XKV@tempa}{%
      \XKV@err{key `\XKV@tempa' undefined}%
    }{%
      \edef\XKV@tempb{%
        \noexpand\XKV@warn{key `\XKV@tempa' has been disabled}%
      }%
      \XKV@ifundefined{\XKV@header\XKV@tempa @default}{%
        \edef\XKV@tempc{\noexpand\XKV@define@key{\XKV@tempa}}%
      }{%
        \edef\XKV@tempc{\noexpand\XKV@define@key{\XKV@tempa}[]}%
      }%
      \expandafter\XKV@tempc\expandafter{\XKV@tempb}%
    }%
  }%
}
\def\presetkeys{\XKV@stfalse\XKV@testoptb\XKV@presetkeys}
\def\gpresetkeys{\XKV@sttrue\XKV@testoptb\XKV@presetkeys}
\def\XKV@presetkeys#1#2{%
  \XKV@pr@setkeys{#1}{preseth}%
  \XKV@pr@setkeys{#2}{presett}%
}
\def\XKV@pr@setkeys#1#2{%
  \XKV@ifundefined{XKV@\XKV@header#2}{%
    \XKV@checksanitizea{#1}\XKV@tempa
    \ifXKV@st\expandafter\global\fi\expandafter\def\csname
      XKV@\XKV@header#2\expandafter\endcsname\expandafter{\XKV@tempa}%
  }{%
    \expandafter\XKV@merge\csname XKV@\XKV@header
      #2\endcsname{#1}\XKV@getkeyname
  }%
}
\def\delpresetkeys{\XKV@stfalse\XKV@testoptb\XKV@delpresetkeys}
\def\gdelpresetkeys{\XKV@sttrue\XKV@testoptb\XKV@delpresetkeys}
\def\XKV@delpresetkeys#1#2{%
  \XKV@d@lpresetkeys{#1}{preseth}%
  \XKV@d@lpresetkeys{#2}{presett}%
}
\def\XKV@d@lpresetkeys#1#2{%
  \XKV@ifundefined{XKV@\XKV@header#2}{%
    \XKV@err{no presets defined for `\XKV@header'}%
  }{%
    \expandafter\XKV@delete\csname XKV@\XKV@header
      #2\endcsname{#1}\XKV@getkeyname
  }%
}
\def\unpresetkeys{\XKV@stfalse\XKV@testoptb\XKV@unpresetkeys}
\def\gunpresetkeys{\XKV@sttrue\XKV@testoptb\XKV@unpresetkeys}
\def\XKV@unpresetkeys{%
  \XKV@ifundefined{XKV@\XKV@header preseth}{%
    \XKV@err{no presets defined for `\XKV@header'}%
  }{%
    \ifXKV@st\expandafter\global\fi\expandafter\let
      \csname XKV@\XKV@header preseth\endcsname\@undefined
    \ifXKV@st\expandafter\global\fi\expandafter\let
      \csname XKV@\XKV@header presett\endcsname\@undefined
  }%
}
\def\savekeys{\XKV@stfalse\XKV@testoptb\XKV@savekeys}
\def\gsavekeys{\XKV@sttrue\XKV@testoptb\XKV@savekeys}
\def\XKV@savekeys#1{%
  \XKV@ifundefined{XKV@\XKV@header save}{%
    \XKV@checksanitizeb{#1}\XKV@tempa
    \ifXKV@st\expandafter\global\fi\expandafter\def\csname XKV@%
      \XKV@header save\expandafter\endcsname\expandafter{\XKV@tempa}%
  }{%
    \expandafter\XKV@merge\csname XKV@\XKV@header
      save\endcsname{#1}\XKV@getsg
  }%
}
\def\delsavekeys{\XKV@stfalse\XKV@testoptb\XKV@delsavekeys}
\def\gdelsavekeys{\XKV@sttrue\XKV@testoptb\XKV@delsavekeys}
\def\XKV@delsavekeys#1{%
  \XKV@ifundefined{XKV@\XKV@header save}{%
    \XKV@err{no save keys defined for `\XKV@header'}%
  }{%
    \expandafter\XKV@delete\csname XKV@\XKV@header
      save\endcsname{#1}\XKV@getsg
  }%
}
\def\unsavekeys{\XKV@stfalse\XKV@testoptb\XKV@unsavekeys}
\def\gunsavekeys{\XKV@sttrue\XKV@testoptb\XKV@unsavekeys}
\def\XKV@unsavekeys{%
  \XKV@ifundefined{XKV@\XKV@header save}{%
    \XKV@err{no save keys defined for `\XKV@header'}%
  }{%
    \ifXKV@st\expandafter\global\fi\expandafter\let
      \csname XKV@\XKV@header save\endcsname\@undefined
  }%
}
\def\setkeys{\XKV@testopta{\XKV@testoptc\XKV@setkeys}}
\def\XKV@setkeys[#1]#2{%
  \XKV@checksanitizea{#2}\XKV@resb
  \let\XKV@naa\@empty
  \XKV@for@o\XKV@resb\XKV@tempa{%
    \expandafter\XKV@g@tkeyname\XKV@tempa=\@nil\XKV@tempa
    \XKV@addtolist@x\XKV@naa\XKV@tempa
  }%
  \let\XKV@rm\@empty
  \XKV@usepresetkeys{#1}{preseth}%
  \expandafter\XKV@s@tkeys\expandafter{\XKV@resb}{#1}%
  \XKV@usepresetkeys{#1}{presett}%
}
\def\XKV@usepresetkeys#1#2{%
  \XKV@presettrue
  \XKV@for@eo\XKV@fams\XKV@tfam{%
    \XKV@makehd\XKV@tfam
    \XKV@ifundefined{XKV@\XKV@header#2}{}{%
      \XKV@toks\expandafter\expandafter\expandafter
        {\csname XKV@\XKV@header#2\endcsname}%
      \@expandtwoargs\XKV@s@tkeys{\the\XKV@toks}%
        {\XKV@naa\ifx\XKV@naa\@empty\else,\fi#1}%
    }%
  }%
  \XKV@presetfalse
}
\def\XKV@s@tkeys#1#2{%
  \XKV@sp@deflist\XKV@na{#2}%
  \XKV@for@n{#1}\CurrentOption{%
    \expandafter\XKV@s@tk@ys\CurrentOption==\@nil
  }%
}
\def\XKV@s@tk@ys#1=#2=#3\@nil{%
  \XKV@g@tkeyname#1=\@nil\XKV@tkey
  \expandafter\KV@@sp@def\expandafter\XKV@tkey\expandafter{\XKV@tkey}%
  \ifx\XKV@tkey\@empty
    \XKV@toks{#2}%
    \ifcat$\the\XKV@toks$\else
      \XKV@err{no key specified for value `\the\XKV@toks'}%
    \fi
  \else
    \@expandtwoargs\in@{,\XKV@tkey,}{,\XKV@na,}%
    \ifin@\else
      \XKV@knftrue
      \KV@@sp@def\XKV@tempa{#2}%
      \ifXKV@preset\XKV@s@tk@ys@{#3}\else
        \ifXKV@pl
          \XKV@for@eo\XKV@fams\XKV@tfam{%
            \XKV@makehd\XKV@tfam
            \XKV@s@tk@ys@{#3}%
          }%
        \else
          \XKV@whilist\XKV@fams\XKV@tfam\ifXKV@knf\fi{%
            \XKV@makehd\XKV@tfam
            \XKV@s@tk@ys@{#3}%
          }%
        \fi
      \fi
      \ifXKV@knf
        \ifXKV@inpox
          \ifx\XKV@doxs\relax
            \ifx\@currext\@clsextension\else
              \let\CurrentOption\XKV@tkey\@unknownoptionerror
            \fi
          \else\XKV@doxs\fi
        \else
          \ifXKV@st
            \global\XKV@addtolist@o\XKV@rm\CurrentOption
          \else
            \XKV@err{`\XKV@tkey' undefined in families `\XKV@fams'}%
          \fi
        \fi
      \else
        \ifXKV@inpox\ifx\XKV@testclass\XKV@documentclass
          \expandafter\XKV@useoption\expandafter{\CurrentOption}%
        \fi\fi
      \fi
    \fi
  \fi
}
\def\XKV@s@tk@ys@#1{%
  \XKV@ifundefined{\XKV@header\XKV@tkey}{}{%
    \XKV@knffalse
    \XKV@ifundefined{XKV@\XKV@header save}{}{%
      \expandafter\XKV@testsavekey\csname XKV@\XKV@header
        save\endcsname\XKV@tkey
    }%
    \ifXKV@rkv
      \ifXKV@sg\expandafter\global\fi\expandafter\let
        \csname XKV@\XKV@header\XKV@tkey @value\endcsname\XKV@tempa
    \fi
    \expandafter\XKV@replacepointers\expandafter{\XKV@tempa}%
    \ifx\@empty#1\@empty\XKV@afterelsefi
      \XKV@ifundefined{\XKV@header\XKV@tkey @default}{%
        \XKV@err{no value specified for key `\XKV@tkey'}%
      }{%
        \expandafter\expandafter\expandafter\XKV@default
          \csname\XKV@header\XKV@tkey @default\endcsname\@nil
      }%
    \else\XKV@afterfi
      \XKV@srstate{@\romannumeral\XKV@depth}{}%
      \csname\XKV@header\XKV@tkey\expandafter
        \endcsname\expandafter{\XKV@tempa}\relax
      \XKV@srstate{}{@\romannumeral\XKV@depth}%
    \fi
  }%
}
\def\XKV@testsavekey#1#2{%
  \ifXKV@rkv\else
    \XKV@for@o#1\XKV@resa{%
      \expandafter\XKV@ifcmd\expandafter{\XKV@resa}\global\XKV@resa{%
        \ifx#2\XKV@resa
          \XKV@rkvtrue\XKV@sgtrue
        \fi
      }{%
        \ifx#2\XKV@resa
          \XKV@rkvtrue\XKV@sgfalse
        \fi
      }%
    }%
  \fi
}
\def\XKV@replacepointers#1{%
  \let\XKV@tempa\@empty
  \let\XKV@resa\@empty
  \XKV@r@placepointers#1\usevalue\@nil
}
\def\XKV@r@placepointers#1\usevalue#2{%
  \XKV@addtomacro@n\XKV@tempa{#1}%
  \def\XKV@tempb{#2}%
  \ifx\XKV@tempb\@nnil\else\XKV@afterfi
    \XKV@ifundefined{XKV@\XKV@header#2@value}{%
      \XKV@err{no value recorded for key `#2'; ignored}%
      \XKV@r@placepointers
    }{%
      \@expandtwoargs\in@{,#2,}{,\XKV@resa,}%
      \ifin@\XKV@afterelsefi
        \XKV@err{back linking pointers; pointer replacement canceled}%
      \else\XKV@afterfi
        \XKV@addtolist@x\XKV@resa{#2}%
        \expandafter\expandafter\expandafter\XKV@r@placepointers
          \csname XKV@\XKV@header#2@value\endcsname
      \fi
    }%
  \fi
}
\def\XKV@default#1#2\@nil{%
  \expandafter\edef\expandafter\XKV@tempa
    \expandafter{\expandafter\@gobble\string#1}%
  \edef\XKV@tempb{\XKV@header\XKV@tkey}%
  \@onelevel@sanitize\XKV@tempb
  \ifx\XKV@tempa\XKV@tempb
    \begingroup
      \expandafter\def\csname\XKV@header\XKV@tkey\endcsname##1{%
        \gdef\XKV@tempa{##1}%
      }%
      \csname\XKV@header\XKV@tkey @default\endcsname
    \endgroup
    \XKV@ifundefined{XKV@\XKV@header save}{}{%
      \expandafter\XKV@testsavekey\csname XKV@\XKV@header
        save\endcsname\XKV@tkey
    }%
    \ifXKV@rkv
      \ifXKV@sg\expandafter\global\fi\expandafter\let
        \csname XKV@\XKV@header\XKV@tkey @value\endcsname\XKV@tempa
    \fi
    \expandafter\XKV@replacepointers\expandafter
      {\XKV@tempa}\XKV@afterelsefi
    \XKV@srstate{@\romannumeral\XKV@depth}{}%
    \expandafter#1\expandafter{\XKV@tempa}\relax
    \XKV@srstate{}{@\romannumeral\XKV@depth}%
  \else\XKV@afterfi
    \XKV@srstate{@\romannumeral\XKV@depth}{}%
    \csname\XKV@header\XKV@tkey @default\endcsname\relax
    \XKV@srstate{}{@\romannumeral\XKV@depth}%
  \fi
}
\def\setrmkeys{\XKV@testopta{\XKV@testoptc\XKV@setrmkeys}}
\def\XKV@setrmkeys[#1]{%
  \def\XKV@tempa{\XKV@setkeys[#1]}%
  \expandafter\XKV@tempa\expandafter{\XKV@rm}%
}
\XKVcatcodes
\endinput
%%
%% End of file `xkeyval.tex'.

math0404011.extracted_bib
\begin{thebibliography}{9}

\bibitem{Acz1966}
  J{\'a}nos Acz{\'e}l,
  \emph{Lectures on functional equations and their applications},
  Mathematics in Science and Engineering, Vol. 19,
  Academic Press, New York, 1966.
  
\bibitem{FosKla2000}
  Damiano Foschi and Sergiu Klainerman,
  \emph{Bilinear space-time estimates
    for homogeneous wave equations},
  Ann. Sci. \'Ecole Norm. Sup. (4) \textbf{33} (2000),
  no.~2, 211--274.

\bibitem{Hor1990}
  Lars H{\"o}rmander,
  \emph{The analysis of linear partial differential operators {I}.
    Distribution theory and Fourier analysis}, 2nd ed.,
  Springer Study Edition,
  Springer-Verlag, Berlin, 1990.

\bibitem{Jar2003}
  Antal J{\'a}rai,
  \emph{Measurability implies continuity 
    for solutions of functional equations---even with few variables},
  Aequationes Math. \textbf{65} (2003), no.~3, 236--266.
  
\bibitem{KlaMac1996}
  Sergiu Klainerman and Matei Machedon,
  \emph{Remark on {S}trichartz-type inequalities},
  Internat. Math. Res. Notices (1996), no.~5, 201--220.
  
\bibitem{Kun2003}
  Markus Kunze,
  \emph{On the existence of a maximizer
    for the {S}trichartz inequality},
  Comm. Math. Phys. \textbf{243} (2003), 137--162.
  
\bibitem{Rat1985}
  J{\"u}rg R{\"a}tz,
  \emph{On orthogonally additive mappings},
  Aequationes Math. \textbf{28} (1985), no.~1-2, 35--49.
  
\bibitem{Str1977}
  Robert S. Strichartz,
  \emph{Restrictions of {F}ourier transforms to quadratic surfaces
    and decay of solutions of wave equations},
  Duke Math. J. \textbf{44} (1977), no.~3, 705--714.
  
\end{thebibliography}