Extended Plefka Expansion for Stochastic Dynamics
B Bravi$^1$
P Sollich$^1$ and M Opper$^2$
We propose an extension of the Plefka expansion, which is well known for the dynamics of discrete spins, to stochastic differential equations with continuous degrees of freedom and exhibiting generic nonlinearities. The scenario is sufficiently general to allow application to e.g.\ biochemical networks involved in metabolism and regulation. The main feature of our approach is to constrain in the Plefka expansion not just first moments akin to magnetizations, but also second moments, specifically two-time correlations and responses for each degree of freedom. The end result is an effective equation of motion for each single degree of freedom, where couplings to other variables appear as a self-coupling to the past (i.e. memory term) and a coloured noise. This constitutes a new mean field approximation that should become exact in the thermodynamic limit of a large network, for suitably long-ranged couplings. For the analytically tractable case of linear dynamics we establish this exactness explicitly by appeal to spectral methods of Random Matrix Theory, for Gaussian couplings with arbitrary degree of symmetry.
Paper_PlefkaExpansion.tex
\documentclass[12pt]{iopart}
%\documentclass[a4paper,12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[UKenglish]{babel}
% @@ hack to avoid conflict with amsmaths' equation* @@
\expandafter\let\csname equation*\endcsname\relax
\expandafter\let\csname endequation*\endcsname\relax
\usepackage{amsmath}
\usepackage{iopams}
\usepackage{amssymb}
\usepackage{fullpage}
\usepackage{bm}
\usepackage{bbold}
\usepackage{appendix}
\usepackage{graphicx}
\usepackage{color}
\usepackage{tikz}
%\usepackage{hyperref}
\usetikzlibrary{calc,decorations.markings}
%\input{rgb}
%\usepackage{auto-pst-pdf} %needed for .eps files and pstricks, -shell-escape
%\pagestyle{empty}%%do I need this? doesn't seem to make a difference
%% to compile use pdflatex -shell-escape projection2.tex &
%\usepackage{caption}% http://ctan.org/pkg/caption
%\captionsetup[figure]{labelformat=empty}%
%% stops the Figure label infront of figure captions
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\w}{\text{i}\omega}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\eee}{\mathrm{e}}
\newcommand{\ii}{\mathrm{i}}
\newcommand{\eq}{^{\rm{eq}}}
\newcommand{\bea}{\begin{eqnarray}}
\newcommand{\eea}{\end{eqnarray}}
\newcommand{\xh}{\hat{x}}
\newcommand{\muh}{\hat{\mu}}
\newcommand{\dx}{\delta x}
\newcommand{\dxh}{\delta\hat{x}}
\newcommand{\dphi}{\delta\phi}
\newcommand{\dR}{\delta R}
\newcommand{\dC}{\delta C}
\newcommand{\dB}{\delta B}
\newcommand{\xe}{\Xi^{\rm eff}}
\newcommand{\lhe}{l_i^{\rm eff}(t)}
\newcommand{\he}{\bm{h}^{\rm eff}}
\newcommand{\psie}{\psi_i^{\rm eff}(t)}
\newcommand{\che}{\hat{C}_i^{\rm eff}(t,t')}
\newcommand{\rhe}{\hat{R}_i^{\rm eff}(t,t')}
\newcommand{\bhe}{\hat{B}_i^{\rm eff}(t,t')}
\newcommand{\Ga}{G_\alpha}
\newcommand{\Gha}{\hat{G}_\alpha}
\newcommand{\Gexp}[1]{G^{#1}}
\newcommand{\Ha}[1][\alpha]{\mathcal{H}_#1}
\newcommand{\Hint}{\mathcal{H}_{\rm int}}
\newcommand{\Xa}{\Xi_\alpha}
\newcommand{\mv}{\bm{m}}
\newcommand{\hv}{\bm{h}}
\newcommand{\hexp}[1]{\bm{h}^{#1}}
\newcommand{\hhexp}[1]{h^{#1}}
\newcommand{\Sv}{\bm{S}}
\newcommand{\eff}{^{\text{eff}}}
\usepackage{cite}
\bibliographystyle{iopart-num.bst}
%\bibliographystyle{plain}
\numberwithin{equation}{section}
\allowdisplaybreaks[1]

\begin{document}
\title[Extended Plefka Expansion]{Extended Plefka Expansion for Stochastic Dynamics}
\author{B Bravi$^1$, P Sollich$^1$ and M Opper$^2$}
\address{$^1$ Department of Mathematics, King's College London, Strand, London, WC2R 2LS UK}
\address{$2$ Department of Artificial Intelligence, Technische Universit\"{a}t Berlin, Marchstra{\ss}e 23,
Berlin 10587, Germany}
\ead{barbara.bravi@kcl.ac.uk, peter.sollich@kcl.ac.uk and manfred.opper@tu-berlin.de}
\date{}


\begin{abstract}
We propose an extension of the Plefka expansion, which is well known for the dynamics of discrete spins, to stochastic differential equations with continuous degrees of freedom and exhibiting generic nonlinearities. The scenario is sufficiently general to allow application to e.g.\ biochemical networks involved in metabolism and regulation. The main feature of our approach is to constrain in the Plefka expansion not just first moments akin to magnetizations, but also second moments, specifically two-time correlations and responses for each degree of freedom. The end result is an effective equation of motion for each single degree of freedom, where couplings to other variables appear as a self-coupling to the past (i.e. memory term) and a coloured noise. This constitutes a new mean field approximation that should become exact in the thermodynamic limit of a large network, for suitably long-ranged couplings. For the analytically tractable case of linear dynamics we establish this exactness explicitly by appeal 
to spectral methods of Random Matrix Theory, for Gaussian couplings with arbitrary degree of symmetry.
\end{abstract}
% \pacs{1315, 9440T}
\noindent{\it Keywords: Plefka expansion, Mean Field, Random Matrix Theory, Biochemical Networks, Dynamical Functional\/}\\
\submitto{\jpa}
\maketitle

\section{Introduction}
Stochastic Differential Equations (SDEs) with continuous variables are a well-established tool to describe the dynamical behaviour of a variety of systems, in areas ranging from physics and chemistry to biology and engineering \cite{vankampen,gardiner}: they are used frequently, for example, for dynamical modelling of intracellular kinetics and biochemical networks \cite{systems}.

In the context of network studies, in particular with regard to applications in systems biology, a major task is model simplification \cite{okino,apri}, using model reduction strategies that should retain as much as possible of the qualitative dynamical information. In addition one requires techniques for inferring model parameters from observed data,  
since experimental uncertainties on parameters, resulting e.g.\ from the fact that some dynamical variables may not be observed, can crucially affect the predictions of dynamical models \cite{achcar}.

The application of approaches based on statistical mechanics and spin glass theory has a long history \cite{virasoro}. In particular,
mean field (MF) methods have emerged as powerful tools for characterizing statistical quantities in systems where the combinatorial complexity of exact calculations rules out a tractable description \cite{meanfield}. From the theoretical point of view, further motivation for the use of mean field methods comes from the fact that they can often be proved to retrieve the exact solution in an appropriate limit, typically involving high network connectivity and/or weak couplings.

The so called  ``Plefka expansion" for the Sherrington-Kirkpatrick (SK) \cite{SK} model was introduced by Plefka \cite{plefka} as a convenient method to derive MF  
equations and their more refined analogue, the TAP equations \cite{TAP}. The advantage of the method, essentially an expansion of the Gibbs free energy in powers of the interaction 
strength, is that it does not rely on an average over interactions drawn from some statistical ensemble. This makes it potentially useful in applications to e.g.\ biology, where it is 
generally a {\em specific} network that is of interest.

Roudi and Hertz \cite{roudi} applied the Plefka expansion to the problem of approximating spin-glass dynamics: in this case, variables are not single spins but entire time histories of each spin.
They developed a dynamical theory that relates mean magnetizations, potentially time varying fields and quenched couplings for two versions of SK model kinetics (synchronous and asynchronous updates, respectively). Using the generating functional approach, the (naive) MF and TAP dynamical equations were retrieved as first and second orders of a power expansion in analogy with the equilibrium Plefka expansion for the Gibbs free energy. In more detail, the logarithm of the generating functional for the dynamics
plays the role of the equilibrium free energy: performing the Legendre transform w.r.t.\ the real and auxiliary fields one obtains the dynamical equivalent of the Gibbs free energy and then can expand for weak couplings. Importantly, as long as the generating functional is by definition dependent only
on fields that act linearly on the degrees of freedom, this expansion will closely resemble the standard Plefka approach and only the first moments of the resulting probability measure over trajectories will be fixed.


The aim of our paper is two-fold. First we want to introduce an improvement, taylored to continuous degrees of freedom, of the approximation strategy outlined above; we call the improved method an ``extended" Plefka expansion.
The dynamical model is a set of stochastic differential equations for continuous degrees of freedom and with generic nonlinear couplings between them. The basic idea of the extension 
that we propose is to include among the set of order parameters all second moments, i.e.\ two-time correlations and responses, for each degree of freedom. Expanding up to second order 
in interaction strength then provides a mean field description where couplings between trajectories are replaced by a coupling to the past (i.e.\ a memory term) and 
a coloured noise. 

Our second aim is an analytical investigation of a solvable limit, which concerns large networks with linear dynamics. This partly serves the purpose of verifying explicitly a case 
where the approximation becomes exact, but the calculation also provides additional insight how the dynamical behaviour of correlations and responses depends on the symmetry of the couplings. 
We show that the exact thermodynamic limit is recovered from the approximate
equations for any degree of symmetry, i.e.\ irrespective of whether the system reaches an equilibrium stationary state. This keeps the analysis as general as possible and suggests multiple possible applications, for  
example in neural networks and gene expression where couplings are typically asymmetric.

The paper is organized as follows: after recalling the expansion conceived by Plefka in section \ref{sec:PE}, we introduce in section \ref{sec:EPE} the basic functional integral approach that provides 
the framework within which we build the extended Plefka expansion for dynamics. In sections \ref{sec:MF} and \ref{sec:TAP} we present and discuss the derivation of the approximate dynamical 
equations from the functional integral. In sections \ref{sec:LD}, \ref{sec:LD1} and \ref{sec:TLLD} we apply the approximation to the particular case of a linear dynamics, which is analytically tractable both in the static and dynamic scenario. In section \ref{sec:ED} we resort to Random Matrix Theory and related spectral methods \cite{mehta} to average the exact dynamics over the disordered interactions, in the limit of an infinitely large sample and in the stationary regime.
This allows us to derive expressions for correlations and responses in Laplace space, and comparison with the predictions of the extended Plefka approximation shows perfect agreement. This 
confirms and strenghtens the theoretical justification of our method. In section \ref{sec:PS} we study in more detail the qualitative features of the dynamics, in particular non-exponential relaxation 
behaviour that manifests as low-frequency power law tails in the power spectra. Finally, an explicit analytical characterization of correlations and responses in the temporal domain can be found in the limit of symmetric and antisymmetric couplings and is discussed briefly in section \ref{sec:TD}.

\section{Plefka Expansion}
\label{sec:PE}
We briefly summarize the main steps of the ``Plefka expansion'' introduced by Plefka \cite{plefka}, using, as in the
original paper, the Sherrington-Kirkpatrick (SK) \cite{SK} model as an example.
The SK model of a spin glass consists of $N$ Ising spins ($S_i=\pm 1$) with Hamiltonian
\begin{equation}
 \mathcal{H}= \frac{1}{2}\sum_{i\neq j}J_{ij}S_iS_j + \sum_i h_i^{\rm ext} S_i
\label{eq:Hdef}
\end{equation}
In the SK model, specifically, the interactions are symmetric (i.e.\ $J_{ij}=J_{ji}$) and infinitely long-ranged, with the $J_{ij}$
for $i<j$ chosen as independent Gaussian variables of mean zero and
variance $1/N$, though these properties are not required to write down
the general expansion. Note that the left hand side of (\ref{eq:Hdef})
would conventionally be written as $-\beta \mathcal{H}$ with $\beta$ the inverse temperature, but we omit factors of $-\beta$ here and below as we do not need them in the application to dynamics.
In order to construct the Plefka expansion one introduces a parameter $\alpha$ controlling the interaction strength, defining a modified Hamiltonian as
\begin{equation}
\Ha = \frac{\alpha}{2}\sum_{i\neq j}J_{ij}S_iS_j + \sum_i h^{\rm ext}_i S_i
 \end{equation}
The full interacting Hamiltonian is then $\Ha[1]=\mathcal{H}$, while $\Ha[0]$ is the Hamiltonian of a non-interacting system. 
The Gibbs free energy $\Ga$ is now defined as the free energy
subject to a constraint on certain averages, typically the magnetizations
$m_i=\langle S_i\rangle$
\begin{equation}
\Ga(\mv) = \text{extr}_{\hv} \Gha(\mv, \hv)
\end{equation}
with
\begin{equation}
\Gha(\mv, \hv)= \ln \text{Tr}\,\text{e}^{\Xa} 
\end{equation}
and
\begin{equation}
\label{eq:s_m_zero}
\Xa = \Ha + \sum_i h_i(S_i - m_i)
\end{equation}
One can write 
\begin{equation}
\Ga(\mv) = \text{extr}_{\hv} \left(
\ln \text{Tr}\,\text{e}^{\Ha + \sum_i h_i S_i} 
- \sum_i h_i m_i\right)
\end{equation}
and this shows that $\Ga$ is the Legendre transform of a Helmholtz free energy -- the first term in the brackets -- that depends on
the auxiliary fields $h_i$. The extremization condition over the $h_i$
gives
\begin{equation}
m_i = \langle S_i \rangle
\label{eq:m_equals_average_S}
\end{equation}
and this ensures that the $m_i$ have the intended meaning. The average here is over the distribution of states $P(\Sv) \propto \text{e}^{\Xa}$. This is biased away from the Boltzmann distribution $(1/Z)\text{e}^{\Ha}$ by the factor 
$\text{e}^{\hv\cdot\Sv}$ involving the auxiliary fields $h_i$. We will denote the fields that produce the desired values of the magnetizations $\mv$ by $\hv_\alpha(\mv)$, where the subscript emphasizes the dependence on the interaction strength $\alpha$.
The fields $\hv_\alpha$ can be deduced as derivatives of $\Ga$, once this is known. Explicitly, because of
the condition (\ref{eq:m_equals_average_S}), the variation of the fields $\hv_\alpha$ with $\mv$ does
not contribute to the $\mv$-derivative of $\Ga$, so that
\begin{equation}
\frac{\partial \Ga}{\partial m_i} = -h_{i\alpha}
\end{equation}
as expected on general grounds from the Legendre transform
definition of $\Ga$. The Gibbs free energy becomes equal to the
unconstrained equilibrium free energy when the fields $h_{i\alpha}$ vanish, so
that the condition for the equilibrium magnetizations is simply
\begin{equation}
\frac{\partial \Ga}{\partial m_i} = 0
\end{equation}
The formalism so far is generic. In the Plefka expansion, the
interacting part of the Hamiltonian is treated perturbatively by
expanding the Gibbs free energy in powers of $\alpha$, typically to
first or second order
% @@  have suggested a version with expansion order as {\bf superscript} below as that's what we use anyway for the fields in our calculation @@
\begin{equation}
\Ga = \Gexp{0}+\alpha\Gexp{1}+\frac{\alpha^2}{2}\Gexp{2}+\ldots
\end{equation}
where $\Gexp{k} = (\partial / \partial \alpha)^k \left. \Ga \right|_{\alpha=0}$.
The fields $h_{i\alpha}= -\partial \Ga / \partial m_i $ can be expanded analogously 
\begin{equation}
\hv_{\alpha} = \hexp{0} + \alpha \hexp{1} +\frac{\alpha^2}{2} \hexp{2} + \ldots
\end{equation}
To the second order, the equilibrium condition $\hv_\alpha=0$ for the order
parameters $\mv$ is then given by
\be 
0 = \hexp{0} + \alpha \hexp{1} +\frac{\alpha^2}{2} \hexp{2}
\label{eq:equilibrium_nonzero_alpha}
\ee 
In applications to equilibrium spin systems, the non-interacting Gibbs
free energy $\Gexp{0}$ can often be found explicitly, e.g.\ for our
Ising spin example
\begin{equation}
G^0= -\sum_i\left[\frac{1+m_i}{2}\ln{\bigg(\frac{1+m_i}{2}\bigg)} +\frac{1-m_i}{2}\ln{\bigg(\frac{1-m_i}{2}\bigg)}\right] + \sum_i h^{\rm ext}_i m_i
\end{equation}
In dynamical problems, finding $\Gexp{0}$ explicitly
is often awkward but can be avoided by noting that 
in order to obtain a certain value of $\mv$ at $\alpha=0$ requires
a field $\he=\hexp{0}$. The equilibrium condition
(\ref{eq:equilibrium_nonzero_alpha}) for nonzero $\alpha$ can then be
rewritten as
\be 
\label{eq:zerofields}
\he = -\alpha \hexp{1} -\frac{ \alpha^2}{2} \hexp{2}
\ee 
This expression gives us the effective fields $\he$ that produce the
{\em same} magnetizations $\mv$ in the non-interacting system as
at equilibrium in the interacting system. To obtain the equilibrium
condition for the interacting system, one then only needs to combine
this with the relation between magnetization and field in the
non-interacting system, which for Ising spins reads simply
\be 
m_i = \tanh(h^{\rm ext}_i + h_i\eff)
\ee 
To carry out the actual calculation of the first and second order
Plefka free energies $\Gexp{1}$ and $\Gexp{2}$, one notes first that
$\Ga(\mv)=\Gha(\mv,\hv_\alpha(\mv))$, hence
\be
\frac{\partial \Ga}{\partial \alpha}
= \frac{d \Gha}{d \alpha} = \left\langle \frac{d \Xa}{d\alpha}\right\rangle_{\alpha}
\label{eq:G1_first_version}
\ee
where we use $(d/d\alpha)$ to indicate a total derivative that
includes the $\alpha$-dependence of $\hv_\alpha$. On the other hand
\eqref{eq:s_m_zero} shows that in $\Xa$ each field
$h_{i\alpha}$ multiplies $S_i-m_i$, whose average vanishes,
so this $\alpha$ dependence drops out and one has simply
\be
\frac{\partial \Ga}{\partial \alpha}
= \left\langle \Hint \right\rangle_{\alpha}
\label{eq:G1_second_version}
\ee
where $\Hint = \partial \Ha/\partial\alpha$ is the interacting part of the original Hamiltonian.
Evaluating the average in the non-interacting system ($\alpha=0$) then
gives $\Gexp{1}=\langle \Hint \rangle_0$, and by derivation
$\hexp{1}$. For the SK model, one finds in this way $\Gexp{1}=
(1/2)\sum_{i\neq j}J_{ij}m_im_j$ and $h^{1}_i = - \partial
\Gexp{1}/\partial m_i = - \sum_{j\neq i} J_{ij}m_j$. To first order
the effective field is then $h\eff_i = -\alpha \hhexp{1}_i = \alpha
\sum_{j\neq i} J_{ij}m_j$ and the equilibrium condition $m_i =
\tanh(h^{\text{ext}}_i + \alpha \sum_{j\neq i}J_{ij}m_j)$ has the
familiar mean-field form.
For the second order one has in general
\begin{eqnarray}
\frac{\partial^2 \Ga}{\partial \alpha^2}&= \frac{d^2 \Gha}{d \alpha^2}=\notag \\
&= \left\langle \frac{d^2 \Xa}{d\alpha^2}\right\rangle_{\alpha}
+ \biggl\langle \left(\frac{d \Xa}{d\alpha}\right)^2
\biggr\rangle_{\alpha} 
- \biggl\langle \frac{d \Xa}{d\alpha}\biggr\rangle_{\alpha}^2
\end{eqnarray}
%
The first term vanishes because $\partial^2 \Ha/\partial\alpha^2 = 0$
and because $\partial^2 h_{i\alpha}/\partial \alpha^2$ is multiplied
again by a vanishing average. Evaluating at $\alpha=0$ then gives (as discussed in \cite{roudi})
\bea
\label{eq:roudi}
\Gexp{2}
&=& \biggl\langle \left(\delta \frac{d \Xa}{d\alpha}\right)^2\biggr\rangle_0
\eea
where
\be
\delta \frac{d \Xa}{d\alpha}
= \frac{d \Xa}{d\alpha} - \left\langle \frac{d \Xa}{d\alpha}\right\rangle_0
= \Hint - \langle \Hint\rangle_0 + \hexp{1}\cdot(\Sv-\mv)
\ee
From $\Gexp{2}$ one finds $\hexp{2}$ by taking $\mv$-derivatives
again, and in principle this process can be iterated to higher order. The first order gives a MF approximation as shown above, 
while at second order one retrieves what are known as the TAP equations for the SK-model \cite{SK}.

\section{Extended Plefka expansion}
\label{sec:EPE}
We start from the dynamical equations
\begin{equation}
\frac{dx_i(t)}{dt} = - \lambda_{i}x_i(t)+\phi_i(\bm{x}(t))  +\xi_i(t)
\end{equation}
for a set of $N$ continuous (real-valued) degrees of freedom $x_i$ ($i=1,\ldots,N$) evolving in time $t$. The $x_i$ may represent e.g.\ concentrations of chemical species in a biochemical reaction network, or 
deviations of such concentrations from steady state values. On the r.h.s., $\phi_i(\bm{x}(t))$ is a generic function of the vector $\bm{x}(t)=\lbrace x_i(t) \rbrace$ of all concentrations and determines the drift of $x_i$.
In the biochemical context it gives the rate of change in $x_i$ due to reactions with other species and includes the relevant reaction rates. A term $-\lambda_i x_i$ has been included that drives each $x_i$ back to zero, with $\lambda_i$ having the meaning of a decay rate. Finally, $\xi_i(t)$ is  Gaussian white noise with the properties
\begin{equation}
\langle\xi_i\rangle=0 \qquad \langle \xi_i(t) \xi_j(t')\rangle= \Sigma_{ii} \delta_{ij}\delta(t-t')
\end{equation}
The Kronecker delta $\delta_{ij}$ signifies that each variable $x_i$ has independent noise acting on it. Correlations in the noise could be allowed for by extending the matrix $\Sigma_{ii}\delta_{ij}$ to one having nonzero off-diagonal entries, but become difficult to express in terms of the local parameters that define the core of the extended Plefka expansion, as will be explained below.

After discretizing time in elementary time steps $\Delta$, a dynamical partition function for this system can be written in the Martin--Siggia--Rose--Janssen--De Dominicis (MSRJD) 
functional integral formalism \cite{martin}, \cite{janssen}, \cite{dedominicis} 
\begin{eqnarray}
Z&=&\bigg\langle \int\prod_{it}dx_i(t)\delta\big( x_i(t+\Delta)-x_i(t)-\Delta[-\lambda_i x_i(t)+\phi_i(\bm{x}(t))+\xi_i(t)] \big)\bigg\rangle_{\bm{\xi}} =\notag \\
&=&\bigg\langle\int \prod_{it}\frac{dx_i(t)d\hat{x}_i(t)}{2\pi}\text{e}^{\text{i}\hat{x}_i(t)\left(x_i(t+\Delta)-x_i(t)-\Delta[-\lambda_i x_i(t)+\phi_i(\bm{x}(t)) +\xi_i(t)]   \right)} \bigg\rangle_{\bm{\xi}}
\end{eqnarray}
We use the It\^o convention \cite{vankampen} to discretize the noise, where $\xi_i(t)$ above is to be read as the average of the continuous-time noise over the time interval $[t,t+\Delta]$, which has covariance \begin{equation}
\langle {\xi}_i(t){\xi}_i(t') \rangle=\frac{1}{\Delta}\Sigma_{ii}\delta_{tt'}
\end{equation}
Here $\delta_{tt'}/\Delta$ is the discrete-time replacement of $\delta(t-t')$. The average over the white noise can then be performed by applying a standard Gaussian identity
\begin{equation}
\langle \text{e}^{\text{i}\Delta \hat{\bm{x}}^{\rm T} \cdot {\bm{\xi}}} \rangle_{\bm{\xi}}= \text{e}^{-\Delta\,\bm{\hat{x}}^{T}\bm{\Sigma}\bm{\hat{x}}/2}
\end{equation}
To develop a Plefka expansion, we now need to consider which averages should be constrained in the relevant Legendre transform. By reinterpreting the static TAP equations from the perspective of 
a cavity argument \cite{romanobattistin}, one would obtain marginals where the covariance of the cavity field and a quadratic term for the spins is present. These are effectively constant in the 
case of Ising spins ($s_i^2=1$) but should be explicitly taken into account for continuous variables (even in a static problem) and for tracking time dependencies (see \cite{romanobattistin} for 
spin dynamics).

Let us now introduce some shorthands to explain in intuitive terms the logic beyond the ``extended'' Plefka expansion, connecting it to the version for equilibrium systems outlined in section \ref{sec:PE}. We denote
\begin{subequations}
\label{shorthands}
\begin{align}
\hat{\bm{m}}&=\lbrace \bm{x}, -\text{i}\hat{\bm{x}}, \bm{x}\bm{x}, -\text{i}\hat{\bm{x}}\bm{x}, \text{i}\hat{\bm{x}}\text{i}\hat{\bm{x}}  \rbrace\\
\bm{m}&=\lbrace \bm{\mu},-\text{i}\hat{\bm{\mu}},\bm{C}, \bm{R}, \bm{B}\rbrace\\
\bm{h}_{\alpha}&=\lbrace \bm{\Psi}_{\alpha}, \bm{l}_{\alpha}, \hat{\bm{C}}_{\alpha}, \hat{\bm{R}}_{\alpha}, \hat{\bm{B}}_{\alpha} \rbrace
\end{align}
\end{subequations}
Here $\hat{\bm{m}}$ is a compact notation for the quantities whose averages we will constrain, consisting of the $x_i(t)$, $\text{i}\hat{x}_i(t)$ and all their products involving the same degree of freedom or ``site'' $i$. It is the inclusion of these products that extends our approach beyond the standard applications of the Plefka method, where only first order moments such as magnetizations are constrained. We indicate by $\bm{m}$ the constrained values of the relevant averages, which are the order parameters of the theory, and by $\bm{h}_\alpha$ the conjugate fields. $\bm{\mu},\hat{\bm{\mu}},\bm{C}, \bm{R}, \bm{B}$ summarize the various groups of order 
parameters defined as follows
\begin{subequations}
\label{eq:moments}
\begin{align}
\mu_i(t)&= \langle x_i(t) \rangle_{\alpha}\\
\hat{\mu}_i(t)&= \langle \hat{x}_i(t) \rangle_{\alpha} \\
C_{i}(t, t')&=  \langle x_i(t)x_i(t')\rangle_{\alpha} \\
R_{i}(t', t)&=  -\text{i}\langle\hat{x}_i(t)x_i(t') \rangle_{\alpha} \\
B_{i}(t, t')&= - \langle\hat{x}_i(t)\hat{x}_i(t')\rangle_{\alpha}
\end{align}
\end{subequations}
We denote the corresponding groups of conjugate fields by $\bm{\Psi}_{\alpha}, \bm{l}_{\alpha}, \hat{\bm{C}}_{\alpha}, \hat{\bm{R}}_{\alpha}, \hat{\bm{B}}_{\alpha}$.

The second order quantities we are constraining involve firstly the (disconnected, local) two-time correlation functions $C_i(t,t')$. From general results for MSRJD path integrals \cite{coolen} it follows that $R_{i}(t', t)$ has the meaning of a local response of $x_i(t')$ to a perturbing field $-\text{i}\hat{x}_i(t)$ applied at some earlier time; it should therefore be non-vanishing only for $t'>t$. $B_i(t,t')$, finally, is expected to vanish for all times $t$ and $t'$, as is $\hat\mu_i(t)$; both follow from the fact that the dynamical partition function remains equal to unity when generating terms linear in $\hat x_i(t)$ are added in the exponent (we refer to \cite{coolen} for a derivation from the normalization condition).

To define the Plefka free energy, note that after the noise average has been carried out, our partition function can be written in the form $Z=\int D\bm{x} D\hat{\bm{x}}\, \text{e}^{\mathcal{H}_{\alpha}}$ with a suitable Hamiltonian (or action) $\mathcal{H}_\alpha$ for the stochastic dynamics. Here $D\bm{x} D\hat{\bm{x}}$ is a shorthand for  the integral $\prod_{it}\frac{dx_i(t)d\hat{x}_i(t)}{2\pi}$ and corresponds to the trace over spins. As in the equilibrium calculation one now defines the Plefka energy $G_{\alpha}$ as
\begin{equation}
\label{eq:gammaxi}
G_{\alpha}(\bm{m}) =\hat{G}_{\alpha}(\bm{m}, \bm{h}_{\alpha}(\bm{m})) =\ln{ \int D\bm{x} D\hat{\bm{x}}\, \text{e}^{\Xi_{\alpha}}}
\end{equation}
where
\begin{equation}
 \Xi_{\alpha}=\mathcal{H}_{\alpha}+ \bm{h}_{\alpha}\cdot (\hat{\bm{m}}-\bm{m})
\end{equation}
Explicitly, one has for our system and with the extended set of Plefka order parameters
\begin{eqnarray}
\fl\Xi_{\alpha}=\sum_{it} \text{i}\hat{x}_i(t)\big(x_i(t+\Delta)-x_i(t)+\Delta\lambda_i x_i(t)-\alpha\Delta\phi_i(\bm{x}(t))\big)+ \Delta\sum_{it}\psi_{i\alpha}(t)\big(x_i(t)-\mu_i(t)\big)+\notag\\
\fl-\Delta\sum_{it}l_{i\alpha}(t)\big(\text{i}\hat{x}_i(t)-\text{i}\hat{\mu}_i(t)\big)+\Delta^2\sum_{itt'}\hat{C}_{i\alpha}(t,t')\big(x_i(t)x_i(t')-C_i(t,t')\big)+\notag\\
\fl+\Delta^2\sum_{itt'}\hat{R}_{i\alpha}(t,t')\big(-\text{i}\hat{x}_i(t)x_i(t')-R_i(t',t)\big)+\frac{\Delta^2}{2}\sum_{itt'}\hat{B}_{i\alpha}(t,t')\big(-\hat{x}_i(t)\hat{x}_i(t')-  B_{i}(t,t')\big)+\notag\\
\fl-\frac{\Delta}{2}\sum_{it}\Sigma_{ii}\hat{x}_i(t)\hat{x}_i(t)
\end{eqnarray}
where the first and last terms constitute the Hamiltonian $\mathcal{H}_\alpha$. Note that we have inserted powers of $\Delta$ in such a way as to keep the fields of order unity in the continuous time limit $\Delta\to 0$.
The parameter $\alpha$ characterizes the strength of the interactions as in the equilibrium case, here via $\phi_i$;  the linear self-interaction via $-\lambda_i x_i$ is tractable and so is left as part of the non-interacting baseline. Our aim will be to use a second-order Plefka expansion to derive an effective non-interacting description of our system, where the interactions between variables are replaced by additional coloured noise and a coupling of each variable to its past.

In analogy with the equilibrium expansion, the fields $\bm{h}_{\alpha}$ are determined by extremization of $\hat{G}_\alpha$. Once $G_\alpha$ has been found, the fields can be retrieved from $\bm{h}_{\alpha}=-\partial G_{\alpha}/\partial \bm{m}$ and order parameters of the original system dynamics can be found from the condition $\bm{h}_{\alpha}=0$. Split into the various order parameter groups, the derivatives of $G_{\alpha}$ read
\begin{subequations}
\label{fields}
\begin{align}
\psi_{i\alpha}(t)&=-\frac{1}{\Delta}\frac{\partial G_{\alpha}}{\partial \mu_i(t)}\\
-\text{i}l_{i\alpha}(t)&=-\frac{1}{\Delta}\frac{\partial G_{\alpha}}{\partial (\hat{\mu}_i(t))}\\
\hat{R}_{i\alpha}(t,t') &= -\frac{1}{\Delta^2}\frac{\partial G_{\alpha}}{\partial R_i(t',t)}\\
\hat{C}_{i\alpha}(t,t') &= -\frac{1}{\Delta^2}\frac{\partial G_{\alpha}}{\partial C_i(t,t')}\\
\hat{B}_{i\alpha}(t,t') &= -\frac{1}{\Delta^2}\frac{\partial G_{\alpha}}{\partial B_{i}(t,t')}
\end{align}
\end{subequations}
We now proceed with the Plefka expansion of $G_{\alpha}$ around $\alpha=0$ up to second order, and define a set of effective fields $\he$ as in \eqref{eq:zerofields}. These provide the effective non-interacting 
description of the true interacting dynamics, whereby with these fields at $\alpha=0$ the order parameters have the same values as in the interacting system. As the $\he$ themselves depend on the order parameters, 
this typically leads to nonlinear self-consistency equations, which are the analogues of the MF and TAP equations for the SK model. 

The above makes clear why we have introduced only fields depending on a single site: this assumption guarantees that the effective dynamics will be non-interacting. We also see now why correlations between the noises $\xi_i$ affecting the different $x_i$ would complicate matters: the correlations $C_{ij}(t,t')$ would be non-local even at $\alpha=0$, and determined only in a very indirect way from the local order parameters $C_i(t,t')$.
In the application to biochemical reaction networks there generally are non-trivial noise correlations as discussed in section \ref{sec:conclusions} below, and further work would be required to understand how best to deal with those.

\subsection{Structure of the non-interacting problem}
In the logic explained above, the intractable part of the interactions becomes condensed into local fields that describe the effective single-site dynamics. These effective fields
$\psie, \lhe, \rhe$, $\che, \bhe$ appear in the corresponding effective action $\xe$
\begin{eqnarray}
\fl\xe=\sum_{it} \text{i}\hat{x}_i(t)\bigg(x_i(t+\Delta)-x_i(t)+\Delta\lambda_i x_i(t)\bigg)-\frac{\Delta}{2}\sum_{it}\Sigma_{ii}\hat{x}_i(t)\hat{x}_i(t)
+\Delta\sum_{it}\psie\bigg(x_i(t)-\mu_i(t)\bigg)+\notag \\
\fl-\Delta\sum_{it}\lhe\bigg(\text{i}\hat{x}_i(t)-\text{i}\hat{\mu}_i(t)\bigg)+\Delta^2\sum_{itt'}\che\bigg(x_i(t)x_i(t')-C_i(t,t')\bigg)+\notag \\
\fl+\Delta^2\sum_{itt'}\rhe\bigg(-\text{i}\hat{x}_i(t)x_i(t')-R_i(t',t)\bigg)+\frac{\Delta^2}{2}\sum_{itt'}\bhe\bigg(-\hat{x}_i(t)\hat{x}_i(t')-  B_{i}(t,t')\bigg)
\end{eqnarray}
To get the generic self-consistency equations for our order parameters, we should in principle
evaluate the
averages $\mu_i(t)$, $\muh_i(t)$, $C_i(t,t')$, $R_i(t',t)$ and $B_i(t,t')$ for this action. The result is the analogue of what for an equilibrium spin problem is $m_i=\tanh(h^{\rm ext}_i + h_i\eff)$.

To simplify this procedure, one can make the natural (see above) assumptions that the solution of the self-consistency equations will obey $\hat{\mu}_i(t)= 0$, $B_i(t,t')= 0$ and $R_i(t,t')=0$ for $t'\geq t$;
the vanishing of the response at equal times is a generic consequence of the It\^o discretization. We will have to check that these assumptions are self-consistent. As we show below, they imply $\psie=0$, $\che=0$ and $\rhe=0$
for $t'\geq t$ so that the effective action reduces to
%@@ please check whether this should include the equality, also in the restriction in the sum I've added below @@ 
\begin{eqnarray}
\label{eq:xhe}
\fl \xe=\sum_{it} \text{i}\hat{x}_i(t)\bigg[x_i(t+\Delta)-x_i(t)+\Delta\bigg(\lambda_i x_i(t) -\lhe -\Delta\sum_{t'< t}\rhe x_i(t')\bigg) \bigg]+\notag\\
-\frac{\Delta^2}{2}\sum_{itt'}\bhe\hat{x}_i(t)\hat{x}_i(t')-\frac{\Delta}{2}\sum_{it}\Sigma_{ii}\hat{x}_i(t)\hat{x}_i(t)
\end{eqnarray}
This is exactly the action for the Langevin dynamics
\begin{equation}
\frac{x_i(t+\Delta)-x_i(t)}{\Delta}= -\lambda_i x_i(t)+ \lhe +\Delta\sum_{t'}\rhe x_i(t') +\xi_i(t)+\chi_i(t)
\end{equation}
where $\bm{\chi}$ is a coloured, local Gaussian noise with
\begin{equation}
\langle\chi_i\rangle=0 \qquad \langle\chi_i(t) \chi_i(t')\rangle= \bhe
\end{equation}
Note that the covariance of this effective noise is defined exactly so that the quadratic terms in $\hat{x}_i(t)$ in $\xe$ arise from averaging over $\chi_i$ 
\begin{equation}
\text{e}^{-\Delta^2\sum_{tt'}\hat{x}_i(t)\hat{B}^{\text{eff}}_i(t,t')\hat{x}_i(t')/2}=\langle\text{e}^{\text{i}\Delta\sum_t \hat{x}_i(t)\chi_i(t)} \rangle_{\bm{\chi}}
\end{equation}

The remainder of the analysis is easier to carry out in the continuous time-limit $\Delta\to 0$. The effective equation of motion becomes 
\begin{equation}
\label{eq:eff_dyn}
\frac{d x_i(t)}{dt}= -\lambda_i x_i(t)+ \lhe +\int_{0}^t dt'\rhe x_i(t') +\xi_i(t)+\chi_i(t)
\end{equation}
which shows that $\rhe$ plays the role of a memory function. Because this dynamics is causal, it does indeed give $\muh_i=0$, $B_i(t,t')=0$ and $R_i(t,t')=0$ for $t' \geq  t$, and so our original assumptions about the order parameter values are self-consistent.

It remains to obtain the equations for the nonzero order parameters $\mu_i(t)$, $R_i(t,t')$ for $t>t'$, and $C_i(t,t')$.
For the means we have by simple averaging over the zero mean noises $\xi_i$ and $\chi_i$ 
\begin{equation}
\label{eq:eff_mu}
\frac{d \mu_i(t)}{dt}= -\lambda_i \mu_i(t) +\int_{0}^t dt'\rhe\mu_i(t') + \lhe
\end{equation}
For the responses, standard results for linear dynamics with Gaussian noise give 
\begin{equation}
\label{eq:eff_R}
\frac{\partial R_i(t,t')}{\partial t}=\frac{\partial \dot \mu_i(t)}{\partial l^{\rm eff}_i(t')}= -\lambda_i R_i(t,t') +\int_{t'}^{t} dt'' \hat{R}^{\rm eff}_i(t,t'')R_i(t'',t')+ \delta(t-t')
\end{equation}
For the correlations it makes sense to consider the connected version $\delta C_i(t',t) = C_i(t',t) - \mu_i(t')\mu_i(t)$, which obeys
%@@ changed $C$ to $\delta C$ in first integral, swapped the indices so $t$ is first, added $dt''$ integration variable in last integral @@
\begin{equation}
\label{eq:eff_C}
 \frac{\partial \delta C_i(t,t')}{\partial t}= -\lambda_i \delta C_i(t,t') +\int_{t'}^{t} dt'' \hat{R}^{\rm eff}_i(t,t'')\delta C_i(t'',t')+\int_{0}^{t'}dt'' R_i(t',t'')\big(\hat{B}^{\rm eff}_i(t,t'')+\Sigma_{ii}\delta(t-t'') \big)
\end{equation}
These order parameters $\mu_i(t)$, $\delta C_i(t,t')$ and $R_i(t',t)$ are uniquely determined from the above equations when supplemented with initial values $\mu_i(0)$ and $\delta C_i(0,0)$, which we assume are given as part of the specification of our system. 


\subsection{First order: Mean Field equations}
\label{sec:MF}

As explained above the equilibrium case, see equations (\ref{eq:G1_first_version}) and (\ref{eq:G1_second_version}), the first order correction in $\alpha$ to the Plefka free energy is
\begin{equation}
G^1=\frac{\partial G_{\alpha}}{\partial \alpha}\bigg\vert_{\alpha=0}=\bigg\langle \frac{\partial\Xi_{\alpha}}{d \alpha} \bigg\rangle_{0}
\end{equation}
or explicitly
\begin{equation}
\label{g1}
G^1=-\Delta\sum_{it} \big \langle\text{i}\hat{x}_i(t)\phi_i(\bm{x}(t))\big\rangle_{0}
\end{equation}
For the sake of brevity we drop the subscript $0$: all averages below are to be taken at $\alpha=0$ unless otherwise specified. To find $G^1$ explicitly, consider first a generic vector $\bm{z}=\lbrace z_a \rbrace$ of Gaussian variables
with mean $\bm{\mu}$ and covariance matrix $\bm{\Gamma}$. Then by
integration by parts
\be
\langle \delta z_a \phi(\bm{z})\rangle = \sum_b \Gamma_{ab}\langle \partial_{z_b}\phi(\bm{z})\rangle
\label{eq:av_z_phi}
\ee
where $\delta z_a = z_a - \mu_a$. 
Applying this first identity to our case gives
\be
\langle \delta\hat{x}_i(t) \phi_i(\bm{x}(t))\rangle = \text{i}\delta R_i(t,t)\bigg\langle \frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)}
\bigg\rangle
\ee
where $\delta\hat{x}_i = \hat{x}_i-\hat{\mu}_i$ and $\delta R_i(t,t')=  R_i(t,t') + \text{i} \hat{\mu}_i(t')\mu_i(t))$ is the connected response function.
As a consequence,
\begin{eqnarray}
G^1=-\Delta\sum_{it}\bigg( \text{i} \hat{\mu}_i(t)\langle\phi_i(\bm{x}(t))\rangle-\delta R_i(t,t)\bigg\langle \frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)}\bigg\rangle\bigg)
\label{eq:G1_full}
\end{eqnarray}
While not fully explicit, the value of this expression is fully determined by our order parameters; specifically the averages over $\bm{x}(t)$ are over independent Gaussian variables $x_i(t)$ with mean $\mu_i(t)$ and variance $\delta C_i(t,t) = C_i(t,t)-\mu_i^2(t)$.

We can now obtain the first order (in $\alpha$) conjugate fields, which are the negative derivatives of $G^1$ w.r.t.\ the order parameters
\be
\bm{h}^1=-\frac{1}{\Delta^n}\frac{\partial G^1}{\partial\bm{m}},\qquad \bm{h}^1 = \lbrace \psi_i^1(t),l_i^1(t),\hat{C}_i^1(t,t'),\hat{R}_i^1(t',t),\hat{B}_i^1(t,t') \rbrace
\label{eq:h1_generic}
\ee
where according to our convention in the construction of $\Xi_\alpha$, the exponent $n=1$ for linear order parameters and $n=2$ for quadratic ones. Explicitly we obtain
\begin{subequations}
\label{eq:first_fields}
\begin{align}
\begin{split}
\psi_i^1(t)=&\quad\sum_{j} \bigg(\text{i}\hat{\mu}_{j}(t)
\frac{\partial \langle\phi_j(\bm{x}(t))\rangle}{\partial \mu_i(t)}
-\delta R_j(t,t) \frac{\partial}{\partial \mu_i(t)}\bigg\langle \frac{\partial \phi_j(\bm{x}(t))}{\partial x_j(t)}\bigg\rangle\bigg)+\\
&\quad -\text{i}\hat{\mu}_i(t)\bigg\langle \frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)}\bigg\rangle
\end{split}\\
l_i^1(t)=&\quad\mu_i(t)\bigg\langle\frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)}\bigg\rangle-\langle\phi_i(\bm{x}(t))\rangle\label{eq:first_fields_l}\\
\hat{C}_i^1(t,t')=&\quad \frac{1}{\Delta}\sum_{j}\bigg(\text{i}\hat{\mu}_j(t)\frac{\partial\langle \phi_j(\bm{x}(t))\rangle}{\partial C_i(t,t)}-
\delta R_j(t,t)\frac{\partial}{\partial C_i(t,t)}\bigg\langle \frac{\partial \phi_j(\bm{x}(t))}{\partial x_j(t)}\bigg\rangle\bigg)\delta_{tt'}\\
\hat{R}_i^1(t,t') =&{}-\frac{1}{\Delta}\bigg\langle\frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)} \bigg\rangle\delta_{tt'}\label{eq:first_fields_r}\\
\hat{B}_i^1(t,t') =&\quad0 \label{eq:first_fields_b}
\end{align}
\end{subequations}
Using the general identity for Gaussian variables $\bm{z}=\lbrace z_a \rbrace$ with means $\mu_a$
\be 
\partial_{\mu_a}\langle \phi(\bm{z})\rangle = \langle \partial_{z_a}\phi(\bm{z})\rangle
\ee 
the first average in the expression for $\psi_i^1$ could also be written as $\langle \partial \phi_j(\bm{x}(t)) / \partial x_i(t)\rangle$.

The effective fields defining the effective non-interacting dynamics are now $\he = - \alpha \bm{h}^1$. To evaluate these we can exploit that the final order parameter values should obey $\hat\mu_i(t)=0$ and $R_i(t,t)=0$, hence also $\delta R_i(t,t)=0$. This then gives $\psi_i^1(t)=0$ and $\hat{C}_i^1(t,t)=0$ so that also the corresponding effective fields vanish, as anticipated above in our general discussion of the effective non-interacting dynamics. Note that it is important to make the above simplifying assumptions only in the final expressions for the effective fields, not already in $G^1$ as derivatives w.r.t.\ e.g.\ $\hat\mu_i(t)$ do contribute to the effective fields.

The only remaining nonzero effective fields at this stage are $\lhe=-\alpha l^1_i(t)$ and $\rhe=-\alpha \hat{R}^1_i(t,t')$. We insert these into \eqref{eq:xhe} to get the mean field equations for the now effectively non-interacting degrees of freedom $x_i(t)$
\begin{equation}
\frac{d x_i(t)}{dt} = -\lambda_i x_i(t)+\alpha\bigg\langle\frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)} \bigg\rangle(x_i(t)-\mu_i(t)) +\alpha\langle\phi_i(\bm{x}(t))\rangle+ \xi_i(t)  
\end{equation}
Not unexpectedly for an effective linear dynamics, the interaction term $\phi_i(\bm{x}(t))$ has here effectively been linearized in deviations of $x_i(t)$ from its mean. The self-consistency equation for this mean reads
\begin{equation}
\frac{d\mu_i(t)}{dt} =  -\lambda_i \mu_i(t) +\alpha\langle\phi_i(\bm{x}(t))\rangle
\end{equation}
The equations for the equal-time correlations $C_i(t,t)$ can be obtained from the equation of motion for the fluctuations around the mean $\dx_i(t)=x_i(t)-\mu_i(t)$
\bea
\frac{d \dx_i(t)}{dt}  &=& \bigg(-\lambda_i +\alpha\bigg\langle\frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)} \bigg\rangle\bigg) \dx_i(t)
 + \xi_i(t)
 \label{eq:dxi_dt_first_order}
\eea
This gives directly, in the standard manner for an Ornstein-Uhlenbeck process with time-dependent drift,
\begin{equation}
\frac{d\delta C_i(t,t)}{dt} = 2\bigg(-\lambda_i +\alpha\bigg\langle\frac{\partial \phi_i(\bm{x}(t))}{\partial x_i(t)} \bigg\rangle\bigg)\delta C_i(t,t)+\Sigma_{ii}
\end{equation}
In general, the above equations need to be solved jointly for the $2N$ time-dependent order parameters $\mu_i(t)$ and $C_i(t,t)$; this is because the average of $\partial \phi_i / \partial x_i$ generically depends on both means and variances. The case of purely linear interactions, where $\phi_i = \sum_{j\neq i} K_{ij} x_j$, is an obvious exception: here the equations for the means do not involve the variances so can be solved separately.

It is worth commenting at this stage how our first order result compares with that of a conventional Plefka approach that constrains only the first moments $\mu_i(t)$ and $\hat\mu_i(t)$. 
The effective field terms in the effective dynamical action are then linear in $x_i(t)$ and $\hat x_i(t)$. This means that all second order fluctuation statistics remain as in a non-interacting problem.
In particular, $\delta C_i(t,t')$ and $R_i(t,t')$ do not feel any effect of the non-trivial drift $\phi_i$. The second term in the brackets in the r.h.s.\ of \eqref{eq:dxi_dt_first_order} would be absent, and the interaction
term $\phi_i$ would only appear via its average. Already to first order in $\alpha$ it is clear, then, that the extended Plefka approach captures qualitatively more of the dynamics of the interacting system than a
conventional Plefka method constraining linear averages.

\subsection{Second order: TAP equations}
\label{sec:TAP}
The second order of the Plefka free energy can be evaluated starting from the equality \eqref{eq:roudi}
\begin{equation}
G^2=\frac{\partial^2 G_{\alpha}}{\partial \alpha^2}\bigg\vert_{\alpha=0}=\bigg \langle  \bigg(\delta\,\frac{d \Xi_{\alpha}}{d\alpha}\bigg)^2 \bigg \rangle_{0} 
\end{equation}
Including the first order fields in the effective action, with the prefactor
$\alpha$, and taking $\frac{d \Xi_{\alpha}}{d \alpha}$ at $\alpha=0$ gives


\begin{eqnarray}
\label{eq:dXi_alpha_TAP}
\fl\frac{d\Xi_{\alpha}}{d \alpha}\bigg\vert_{\alpha=0}= -\Delta\sum_{it}\text{i}\hat{x}_i(t)\phi_i(\bm{x}(t))+ \Delta\sum_{it}\psi^1_i(t)\bigg(x_i(t)-\mu_i(t)\bigg)-\Delta\sum_{it}l_i^1(t)\bigg(\text{i}\hat{x}_i(t)-\text{i}\hat{\mu}_i(t)\bigg)+\notag \\ 
\fl+\Delta^2\sum_{itt'}\hat{C}^1_i(t,t')\bigg(x_i(t)x_i(t')-C_i(t,t')\bigg)+\Delta^2\sum_{itt'}\hat{R}^1_i(t,t')\bigg(-\text{i}\hat{x}_i(t)x_i(t')-R_i(t',t)\bigg)
\end{eqnarray}

While the following analysis can be carried out for general drift $\phi_i(\bm{x})$, we will restrict the scenario slightly by assuming that
\be
\frac{\partial \phi_i(\bm{x})}{\partial x_i}=0
\ee
as this significantly reduces the number of terms in the expressions. Intuitively, we are assuming that 
$\phi_i(\bm{x})$ is a function only of the other variables $x_j$; equivalently, $x_i$ interacts with itself only via the linear term $-\lambda_i x_i$. In the later steps of the calculation, from \eqref{secondh},
we will add the assumption that the drift $\phi_i$ is an additive combinations of functions of the other variables $x_j$, i.e.\ of the form $\phi_i(\bm{x})=\sum_{j\neq i}g_{ij}(x_j)$.
The above expressions for the first order conjugate fields then simplify to
\begin{subequations}
\begin{align}
\psi_i^1(t)=&\quad\sum_{j}\text{i}\hat{\mu}_{j}(t)\frac{\partial \langle\phi_j(\bm{x}(t))\rangle}{\partial \mu_i(t)}\\
l_i^1(t)=&-\langle\phi_i(\bm{x}(t))\rangle\\
\hat{C}_i^1(t,t')=&\quad \frac{1}{\Delta}\sum_{j}\text{i}\hat{\mu}_j(t)\frac{\partial\langle \phi_j(\bm{x}(t))\rangle}{\partial C_i(t,t')}\delta_{tt'}\\
\hat{R}_i^1(t,t') =&\quad0\\
\hat{B}_i^1(t,t') =&\quad0
\end{align}
\end{subequations}
Inserting these into \eqref{eq:dXi_alpha_TAP} one finds
\begin{eqnarray}
\fl\delta\,\frac{d \Xi_{\alpha}}{d \alpha}=\frac{d \Xi_{\alpha}}{d \alpha} - \bigg\langle\frac{d \Xi_{\alpha}}{d \alpha} \bigg\rangle_{0}=&-\Delta\sum_{it} \bigg[ \text{i} \delta \hat{x}_i(t)\delta\phi_i(\bm{x}(t))+\text{i} \hat{\mu}_i(t)\sum_{j}\bigg(\delta \phi_i(\bm{x}(t))+\notag\\
&-\frac{\partial \langle \phi_i(\bm{x}(t))\rangle}{\partial \mu_j(t)}\delta x_j(t) - \frac{\partial \langle \phi_i(\bm{x}(t))\rangle}{\partial C_j(t,t)}\delta (x_j(t)x_j(t))    \bigg) \bigg]
\end{eqnarray}
where $\delta \hat{x}_i(t)=\hat{x}_i(t)-\hat{\mu}_i(t)$ as before and $\delta  \phi_i(\bm{x}(t))= \phi_i(\bm{x}(t))-\langle \phi_i(\bm{x}(t)) \rangle$, while $\delta(x_j(t)x_j(t)) = x_j^2(t) - C_j(t,t)$. 
To calculate $G^2$ one now needs to square this and evaluate the relevant averages, expressing them in terms of the relevant order parameters \eqref{eq:moments}. Because the averages are taken at $\alpha=0$, there are no correlations between variables at different sites $i$.
For the same reason all statistics are Gaussian, and one can use Wick's theorem to reduce all higher order moments to first and second order ones.

Once $G^2$ has been found, the $O(\alpha^2)$ corrections for the fields can be calculated from
\be
\label{secondh}
\bm{h}^2=-\frac{1}{\Delta^n}\frac{\partial G^2}{\partial\bm{m}}
\ee
which is just the second order analogue of \eqref{eq:h1_generic}. With these general expressions for the fields we obtained, one can again impose the physical constraints on the order parameters, i.e.\ $\muh_i(t)=0$, $\dR_i(t,t')=0$ for $t'\geq t$ and $\delta B_i(t,t')=B_{i}(t,t') + \hat{\mu}_i(t)\hat{\mu}_i(t') =0$. We omit the details and write directly the final simplified form of the second order fields 
\begin{subequations} 
\begin{align}
\psi^2_i(t)&= 0\\
l^2_i(t)&=2\Delta\sum_{jt'} \bigg\langle \frac{\partial \phi_{i}(\bm{x}(t))}{\partial x_j(t)}\, \frac{\partial \phi_{j}(\bm{x}(t'))}{\partial x_i(t')}  \bigg\rangle\mu_i(t')  R_j(t,t')\\
\hat{R}^2_i(t,t') &=-2\sum_{j}\bigg\langle \frac{\partial \phi_{i}(\bm{x}(t))}{\partial x_j(t)}\, \frac{\partial \phi_{j}(\bm{x}(t'))}{\partial x_i(t')}  \bigg\rangle  R_j(t,t')\\
\hat{C}^2_i(t,t') &= 0\\
\hat{B}^2_i(t,t') &=-\big\langle \delta \phi_{i}(\bm{x}(t))\delta \phi_{i}(\bm{x}(t')) \big\rangle
\end{align}
\end{subequations}
These fields, multiplied by $-\frac{\alpha^2}{2}$, give the second order contributions to the effective fields in the non-interacting dynamical action, $\he=-\alpha \bm{h}^1-\frac{\alpha^2}{2}\bm{h}^2$. One sees that $\psie$ and $\che$ remain identically null also to second order, while the nonzero effective fields are, in the continuous time limit $\Delta\to 0$
\begin{equation}
\begin{split}
\lhe&= \alpha\big\langle \phi_{i}(\bm{x}(t)) \big\rangle- \alpha^2\int_{0}^t dt'\sum_{j}\bigg\langle \frac{\partial \phi_{i}(\bm{x}(t))}{\partial x_j(t)} \,\frac{\partial \phi_{j}(\bm{x}(t'))}{\partial x_i(t')}  \bigg\rangle\mu_i(t')R_j(t,t')
\end{split}
\end{equation}
\begin{equation}
 \rhe=\alpha^2\sum_{j}\bigg\langle \frac{\partial \phi_{i}(\bm{x}(t))}{\partial x_j(t)} \,\frac{\partial \phi_{j}(\bm{x}(t'))}{\partial x_i(t')}  \bigg\rangle R_j(t,t')
\end{equation}
\begin{equation}
\bhe=\alpha^2\big\langle \delta \phi_{i}(\bm{x}(t))\delta \phi_{i}(\bm{x}(t')) \big\rangle
\end{equation}
We notice that the causality structure of $\rhe$ is directly related to that of $R_i(t,t')$, i.e.\ both are nonzero only when the second time argument is smaller than the first. (In the first order calculation we had in addition found a nonzero equal-time value for $\rhe$ but this was due to a self-interaction that we have since assumed to be zero.)
Substituting the fields into $\xe$ \eqref{eq:xhe}, we obtain the uncoupled description of the dynamics to second order in $\alpha$
\begin{equation}
\frac{d x_i(t)}{dt} =  -\lambda_i x_i(t)+\alpha\big\langle \phi_{i}(\bm{x}(t)) \big\rangle+\alpha^2\sum_{j}\int_{0}^t dt' \bigg\langle \frac{\partial \phi_{i}(\bm{x}(t))}{\partial x_j(t)} 
\,\frac{\partial \phi_{j}(\bm{x}(t'))}{\partial x_i(t')}  \bigg\rangle R_j(t,t')\delta x_i(t')+\xi_i(t)+\chi_i(t)
\label{eq:dx_dt_TAP}
\end{equation}
The dynamical TAP equations are then the self-consistency equations for the $\mu_i(t)$, $R_i(t,t')$ and $C_i(t,t')$ that result. These are written in their general form in \eqref{eq:eff_mu} to \eqref{eq:eff_C} above. What is remarkable is that the integral over the past in \eqref{eq:dx_dt_TAP} does not contribute to the evolution equation for the means, which as to first order is given by
\begin{equation}
\frac{d \mu_i(t)}{dt}=-\lambda_i\mu_i(t)+\alpha\big\langle \phi_{i}(\bm{x}(t)) \big\rangle
\end{equation}
This does not mean, of course, that the actual time courses $\mu_i(t)$ wil be the same in the MF and TAP equations: the TAP equations for the variances $C_i(t,t)$ are different from MF, and these variances affect the average $\langle \phi_i\rangle$ in the evolution of the $\mu_i(t)$.

\subsection{Linear case}
\label{sec:LD}
It is instructive to consider this framework for a simple case, i.e. a differential equation with linear couplings
\begin{equation}
\label{eq:LDeq}
\frac{dx_i(t)}{dt} = - \lambda_{i}x_i(t)+\sum_{j} K_{ij}x_j(t) +\xi_i(t)
\end{equation}
This corresponds to the choice $\phi_i(\bm{x}) = \sum_{j} K_{ij} x_j$ for the drift. We assume throughout that $K_{ii}=0$, so that there is no self-interaction in $\phi_i$. 

\subsubsection{First order: Mean Field}

The first order in $\alpha$ of the Plefka free energy $G$ simplifies from \eqref{g1} to
\begin{equation}
\begin{split}
G^1=-\Delta \sum_{it}\text{i}\hat{\mu}_i(t)\sum_{j} K_{ij}\mu_j(t)
\end{split}
\end{equation}
and gives the first order fields
\begin{subequations}
\begin{align}
\psi_i^1(t)&= \sum_{j} \text{i}\hat{\mu}_{j}(t)K_{ji}\\
l_i^1(t)&= -\sum_jK_{ij}\mu_j(t)\\
\hat{R}_i^1(t,t')& =\hat{C}^1_i(t,t')=\hat{B}^1_i(t,t')=0
\end{align}
\end{subequations}
The effective dynamical equation becomes
\begin{equation}
\frac{d x_i(t)}{dt} = - \lambda_i x_i(t)+\alpha \sum_{j} K_{ij}\mu_j(t)+\xi_i(t)  
\end{equation}
and gives for the means the equations of motion
\begin{equation}
\frac{d\mu_i(t)}{dt} =  - \lambda_i \mu_i(t)+\alpha\sum_{j} K_{ij}\mu_j(t)
\end{equation}
For $\alpha=1$ these agree with the exact equations. 
The second order fluctuation statistics, on the other hand, are  unchanged from the non-interacting system at this level of approximation.

\subsubsection{Second order: TAP}
The effective dynamics to second order in $\alpha$ become, as a special case of \eqref{eq:dx_dt_TAP}
\begin{equation}
\label{eq:dx_dt_TAP1}
\frac{d x_i(t)}{dt} =- \lambda_i x_i(t)+  \alpha \sum_{j} K_{ij}\mu_j(t)  + \alpha^2 \int_{0}^{t}dt'\sum_{j}K_{ij}R_j(t,t')K_{ji}\delta x_i(t')+\xi_i(t)+\chi_i(t)
\end{equation}
In the integral term we have arranged the factors to allow a simple intuitive interpretation: a fluctuation $\delta x_i$ at time $t'$ acts via $K_{ji}$ as an effective field on $x_j$; at time $t$ this produces a response in $x_j$ modulated by $R_j(t,t')$, which then acts back on $x_i$ via $K_{ij}$.

Putting $\alpha=1$, the mean dynamics is identical to the (already exact) MF description
\begin{equation}
\label{eq:mean2o}
\frac{d\mu_i(t)}{dt} = - \lambda_i \mu_i(t)+\sum_{j}K_{ij}\mu_j(t)
\end{equation}
Responses have their temporal evolution governed by \eqref{eq:eff_R}
\begin{equation}
\label{resplin}
\frac{\partial R_i(t,t')}{\partial t}=  - \lambda_i R_i(t,t') +\sum_j\int^t_{t'} dt''K_{ij} R_j(t,t'') K_{ji} R_i(t'',t') +\delta(t-t')
\end{equation}
while for the connected correlations one has, from \eqref{eq:eff_C}
\begin{eqnarray}
\label{corrlin}
\frac{\partial\,\delta C_i(t,t')}{\partial t}& =  - \lambda_i \delta C_i(t,t') +\sum_{j}\int_{0}^t dt''K_{ij} R_j(t,t'') K_{ji}\delta C_i(t'',t') +\notag\\
&+\Sigma_{ii}R_i(t',t) + \sum_{j}\int_{0}^{t'}dt''R_i(t',t'')K_{ij}^2\delta C_j(t,t'') 
\end{eqnarray}
The last term involves the covariance of the coloured noise $\chi_i(t)$, which is $\sum_j K_{ij}^2 \delta C_j(t,t')$.

\section{Exactness in the thermodynamic limit}
\subsection{Motivation and setup}
\label{sec:LD1}

The extended Plefka expansion derived above is, of course, an approximation in general because we have truncated the power series expansion in the interaction strength $\alpha$ at second order. We would
expect the approximation to become exact, however, provided that the interactions between variables are suitably long-ranged and we take the thermodynamic limit $N\to\infty$ of a large system: a central
limit theorem argument then suggests that the interactions have Gaussian statistics as the extended Plefka expansion predicts. The purpose of this section is to study in detail one example of a model 
in this class, namely the linear interaction model introduced in section \ref{sec:LD} with random couplings $K_{ij}$. There are rather more general scenarios where we expect our method to give the exact
results, as discussed in section \ref{sec:conclusions} below.

We already know (see \ref{eq:eff_mu}) that the extended Plefka equations for the means are exact, and will show that the responses and correlations are also predicted correctly by the extended Plefka approach. The exact solution that we work out as our baseline has close similarities with the analysis of the $p=2$-spin spherical model;  see \cite{cugliandolo} for a detailed study of the latter.

We will focus on the long-time limit $t\to\infty$, where the analysis simplifies because two-time correlations and responses become time translation invariant (TTI), i.e.\ depend only on time differences. The derivation of the extended Plefka expansion does not of course rely on TTI, and we would expect that the agreement with the exact solution can be demonstrated also for transient relaxation to the steady state.

To be specific, we consider the linear dynamics \eqref{eq:LDeq}; this corresponds to the Langevin dynamics of a $p=2$-spin spherical model where the spins are replaced by arbitrary degrees of freedom $x_i(t)$ interacting in pairs.
For the sake of simplicity we assume $\lambda_i=\lambda$ and $\Sigma_{ii}=\Sigma$ for all $i=1,\ldots,N$, i.e.\ we take the self-interaction and noise strength as the same for all degrees of freedom.
The self-interaction plays the role of the Lagrange multiplier enforcing the spherical constraint in the $p=2$-spin spherical model: note that in our case it is not time dependent, however, but simply a constant.

We want to proceed with as few restrictive assumptions on the couplings $K_{ij}$ as possible; in fact, nothing in the derivation of the Plefka expansion requires particular conditions on $\bm{K}$. 
A simple choice is then to suppose that $\bm{K}$ is a real matrix with elements that are randomly distributed Gaussian variables with zero mean and variance $\langle K_{ij}^2\rangle=1/N$, drawn independently except for the correlation
\begin{equation}
\label{kji}
 \langle {K}_{ji} {K}_{ij} \rangle=\frac{\eta}{N}
\end{equation}
The parameter $\eta\in[-1,1]$ controls the degree to which the matrix $\bm{K}$ is symmetric, i.e.\ it is a measure of symmetry for the physical couplings in the system. Such ensembles of matrices with Gaussian-distributed elements were first studied by Girko \cite{girko} and Ginibre \cite{ginibre}: their characteristic feature is that unless $\eta=1$,
the eigenvalues are not restricted to the real axis but distributed over an area in the complex plane.

For $\eta=1$ we have symmetric matrices, which belong to what is known as the Wigner or Gaussian Orthogonal Ensemble. Symmetry here ensures that the dynamics obeys detailed balance with respect to the energy function $\sum_i \lambda x_i^2/2 + \sum_{ij}x_iK_{ij}x_j/2$ so that the stationary regime is an equilibrium state.

The value $\eta=0$ means that all correlations between matrix elements vanish and thus identifies a fully asymmetric $\bm{K}$: such random matrices, with completely independent real entries, belong to the Ginibre Orthogonal Ensembles~\cite{ginibre}. Finally, $\eta=-1$ describes the antisymmetric case, where all eigenvalues of $\bm{K}$ lie along the imaginary axis because $\text{i}\bm{K}$ is Hermitian.

\subsection{Extended Plefka expansion}
\label{sec:TLLD}

We next evaluate the predictions of the extended Plefka approach for our system with equation of motion \eqref{eq:LDeq}. 
As shown in \eqref{eq:dx_dt_TAP1} above, the effective single-site dynamics is given by
\begin{equation}
\label{eq:pl}
\frac{d x_i(t)}{dt}= - \lambda x_i(t)+ \sum_{j} K_{ij}\mu_j(t) +\int_0^t dt' \sum_{j}K_{ij}R_j(t,t')K_{ji}\delta x_i(t')+\phi_i(t)
\end{equation}
where 
\begin{equation}
\label{pl1}
\phi_i(t)=\xi_i(t)+\chi_i(t) \qquad \langle\phi_i(t) \phi_i(t')\rangle=\Sigma\delta(t-t') + \sum_{j}K_{ij}^2 \delta C_j(t, t')
\end{equation}
%Here the two point functions are intended as connected.\\
The dynamics of the means $\mu_i(t)$, obtained by averaging over the ensemble \eqref{eq:pl} as in \eqref{eq:mean2o}, is in full agreement with the exact one obtained by simply taking the mean of \eqref{eq:LDeq}.

Let us calculate the response, which in the Plefka approach is given by \eqref{resplin}. 
The dependence on the site $i$ on the r.h.s.\ arises only from the term $\sum_j K_{ij}K_{ji}R_j(t,t')$. Because $K_{ij}K_{ji}$ is of order $1/N$, while the $R_j$ are of order unity and are expected to have vanishing correlation 
with $K_{ij}K_{ji}$ 
(for any fixed $i$) for large $N$, this sum is self-averaging: for large $N$ it can be replaced by 
\begin{displaymath}
 \sum_{j}K_{ij}K_{ji}R_j(t,t')\sim \frac{\eta}{N}\sum_{j}R_j(t,t')\equiv \eta R(t,t')
\end{displaymath}
because $\langle K_{ij}K_{ji}\rangle = \eta/N$. For later we note that the non-trivial term in the noise covariance \eqref{pl1} self-averages similarly to
\begin{displaymath}
\sum_{j}K_{ij}^2 C_j(t, t')\sim \frac{1}{N}\sum_{j} C_j(t, t')\equiv C(t,t')
\label{eq:C_self_averaging}
\end{displaymath}
The self-averaged version of \eqref{resplin} now reads
\begin{equation}
\frac{\partial R_i(t,t')}{\partial t}=  - \lambda R_i(t,t') +\eta\int_{t'}^{t} dt''R(t,t'')R_i(t'',t') +\delta(t-t')
\end{equation}
From this one sees that all sites $i$ will have the same response for large $N$, which makes sense because with our 
long-range disordered couplings all sites $i$ become equivalent. We can thus drop the site index on $R_i$ from now on, or formally average over $i$ to get an equation for $R$. 

As explained above we now consider the long-time limit where a steady state should be reached so that the response becomes TTI, $R(t,t')=R(t-t')$
\begin{equation}
\label{RePl}
\frac{\partial R(t-t')}{\partial t}= - \lambda R(t-t') + \eta\int_{t'}^{t} dt''R(t-t'')R(t''-t')+\delta(t-t')
\end{equation}
Laplace transforming with respect to time differences, with $z$ the conjugate variable, gives
\begin{equation}
 (z+\lambda)\tilde{R}(z)= \eta\tilde{R}^2(z)+1
 \label{eq:Rz_Plefka}
\end{equation}
This second order equation for the Laplace transformed response $\tilde{R}(z)$ has solution
\begin{equation}
 \label{eq:PleRes}
 \tilde{R}(z)= \frac{1}{2\eta}(z+\lambda)-\frac{1}{2\eta}\sqrt{(z+\lambda)^2-4\eta}
\end{equation}
Here the sign is chosen to retrieve the correct behaviour for $z\to \infty$: as $R(t-t')$ must approach unity for small time differences, the Laplace transform $\tilde{R}(z)$ has 
to decay as $1/z$ for large $z$. The result \eqref{eq:PleRes} is particularly simple for $\eta=0$, where the response takes the form
\begin{equation}
\label{reAsPl}
 \tilde{R}(z)=\frac{1}{z+\lambda}
\end{equation}

We next apply the same approach to the calculation of the connected correlations $\delta C(t,t')$. As we will only consider connected correlations in the following we drop the $\delta$ and write simply $C(t,t')$. We start from \eqref{corrlin}, make the self-averaging replacement \eqref{eq:C_self_averaging}, drop the site index and obtain 
\begin{equation}
\label{CoPl}
 \frac{\partial C(t-t')}{\partial t}= -\lambda  C(t-t') + \eta\int_{-\infty}^{t} dt'' R(t-t'')C(t''- t')+ \int_{-\infty}^{t'} dt''\big[\Sigma \delta(t-t'')+C(t- t'')\big]R(t'- t'')
\end{equation}
We take a two-sided Laplace transform of this
\begin{equation}
z\tilde{C}(z) = -\tilde{C}(z) + \eta\tilde{R}(z)\tilde{C}(z)
+ [\Sigma + \tilde{C}(z)]\tilde{R}(-z)
\end{equation}
and solve to get
\begin{equation}
\label{eq:corple}
 \tilde{C}(z)=\frac{\Sigma\tilde{R}(-z)}{z+\lambda-\tilde{R}(-z)-\eta\tilde{R}(z)}=\frac{\Sigma\tilde{R}(z)\tilde{R}(-z)}{1-\tilde{R}(z)\tilde{R}(-z)}
\end{equation}
In the second equality we have simplified using \eqref{eq:Rz_Plefka} to obtain a form that is manifestly even in $z$, as it should be because $C(t-t')=C(t'-t)$. Note that for the response, which is causal so vanishes for negative time differences, the two-sided Laplace transform reduces to the one-sided version.

 \subsection{Exact Solution}
 \label{sec:ED}
To assess whether the above predictions of the extended Plefka method are correct, we now study the exact solution of our model.  

We will require as an essential ingredient the spectral density $\rho(k)$ of $\bm{K}$ in the thermodynamic limit, which follows from general theorems, namely Girko's elliptic and circular laws and the Wigner semicircular law. Girko's
elliptic law \cite{girko1} states that the average eigenvalue distribution $\rho(k)$ of $N\times N$ random matrices $\bm{K}$ drawn from a Gaussian ensemble described by
 \eqref{kji}, in the limit $N\rightarrow\infty$, is
\begin{equation}
  \rho(k)=\begin{cases}
    \frac{1}{\pi(1-\eta^2)} & \left(\frac{x}{1+\eta}\right)^2+\left(\frac{y}{1-\eta}\right)^2< 1\\
    0 & \text{otherwise}
  \end{cases}
\end{equation}
where we have written $x$ and $y$ for the real and imaginary values of the eigenvalue $k$. The density $\rho(k)$ is uniform in an ellipse in the complex plane whose semi-axes are $1+\eta$ and $1-\eta$, respectively, along the real and imaginary directions, and whose foci are $\pm 2 \sqrt{\eta}$. 
In the limit $\eta\rightarrow 1$ the Wigner semicircle law \cite{mehta} is recovered from this, for the distribution of real eigenvalues of matrices from the Wigner ensemble
\begin{equation}
\label{eq:proj}
 \rho(k)= \frac{1}{2\pi}\sqrt{4-k^2} \qquad k\in [-2, 2]
\end{equation}
Girko's elliptic law can then be regarded as the generalization of Wigner's semicircular law to the case of an arbitrary degree of symmetry. For $\eta=0$ the ellipse 
degenerates into the unit circle. Let us consider the vectorial form of the dynamics \eqref{eq:LDeq} of our model, where we temporarily add an external field $\bm{l}$ on the r.h.s.
\begin{equation}
\label{eq:LDeqvec}
 \frac{d \bm{x}(t)}{dt}=-\lambda \bm{x}(t)+\bm{K}\bm{x}(t)+\bm{\xi}(t) + \bm{l}(t)
\end{equation}
The solution can be written symbolically as, if we ignore contributions from the initial conditions
\begin{equation}
 \bm{x}(t)=\int_{0}^t dt' \text{e}^{(-\lambda+\bm{K})(t-t')}[\bm{\xi}(t') + \bm{l}(t')]
 \label{eq:gensol}
\end{equation}
This gives directly for the response function matrix
\begin{equation}
\bm{R}(t,t')= \frac{\partial \langle \bm{x}(t)\rangle}{\partial \bm{l}(t')}\bigg\vert_{\bm{l}=0}= \theta(t-t') \text{e}^{(-\lambda+\bm{K})(t-t')}
\end{equation}
and we can set the field to zero again from now on. One sees that $\lambda$ must be greater than the real part of all eigenvalues $k$ of $\bm{K}$, to avoid exponentially increasing solutions. 
As the expression for $\bm{R}$ is TTI, it has a simple representation in the Laplace domain
\begin{equation}
\label{eq:LapRes}
\tilde{\bm{R}}(z)=\int_0^{+\infty}\,  \text{e}^{(\bm{K}-\lambda)s} \text{e}^{-z s} d s= [z-(\bm{K}-\lambda)]^{-1}\qquad s \equiv t-t'
\end{equation}

For comparison with the Plefka approach we are interested in $R(t-t')=(1/N)\sum_i R_{ii}(t-t')=\text{Tr}\,\bm{R}(t-t')$ if we denote by Tr the normalized trace.
This can be evaluated by integrating over the spectral density
\begin{equation}
\label{eq:intresp}
\tilde{R}(z)= \langle \text{Tr}\,\tilde{\bm{R}}(z)\rangle=\int dk\,\rho(k)  [z-(k-\lambda)]^{-1}=\begin{cases}
    \frac{1}{2\eta}(\lambda+z)-\frac{1}{2\eta}\sqrt{(\lambda+z)^2-4\eta} & \eta \ \ \text{generic}\\
    \frac{1}{2}(\lambda+z)-\frac{1}{2}\sqrt{(\lambda+z)^2-4}& \eta=1\\
    \frac{1}{z+\lambda}& \eta=0
  \end{cases} 
\end{equation}
Note that the expressions \eqref{eq:intresp} are valid only for $z+\lambda$ outside the support of the eigenvalue spectrum as otherwise the integrand has singularities. Meaningful values can still be assigned to the integral for $z$ inside the support, by appropriate regularization, and this is necessary when $\tilde{R}(z)$ is regarded as a resolvent from which spectral information is to be obtained, see e.g. \cite{chalker} and \cite{crisanti} for an interesting analogy with a two-dimensional classical electrostatic field calculation. In our case $\tilde{R}(z)$ is a Laplace transform, as it was in the Plefka calculation, so we are only interested in its behaviour for large enough real $z$ and the analytic continuation from this region, which is exactly what
\eqref{eq:intresp} provides. To be precise, \eqref{eq:intresp} with the square root assigned its principal value is valid for ${\rm Re}(z)>-\lambda$, i.e.\ to the right of the 
midpoint of the branch cut between $z= - \lambda-2\sqrt{\eta}$ and $z= - \lambda+2\sqrt{\eta}$; to the left, one has to use the negative of the principal value to ensure that 
$\tilde{R}(z)$ is analytic except in the branch cut.
Comparing with \eqref{eq:PleRes}, we thus conclude that the extended Plefka method gives the exact response function for our system.

We next turn to the correlation function. To obtain the exact expressions for this we have to resort to different tools. Information about the spectrum is no longer enough, we also require 
the statistics of correlations between the left and right eigenvectors of $\bm{K}$; these eigenvectors are different in the generic case where $\bm{K}$ is not Hermitian, i.e.\ for $\eta \neq \pm 1$.
Eigenvector statistics in non-Hermitian random matrix ensembles were studied extensively by Chalker and Mehlig \cite{chalker} and we exploit their approach, slightly adjusted for our case of matrices with real rather than complex elements.

As for the response we start from the full non-local correlation matrix, which from \eqref{eq:gensol} is given by
\begin{eqnarray}
 \fl\bm{C}(t,t')= \langle \bm{x}(t)\bm{x}^{\rm T}(t')\rangle=
\int_{0}^{t} \int_{0}^{t'} dt''dt''' \text{e}^{(-\lambda+\bm{K})(t-t'')}\langle \bm{\xi}(t'')\bm{\xi}^{\rm T}(t''')\rangle \text{e}^{(-\lambda+\bm{K}^{\rm T})(t'-t''')}\notag\\
 =\Sigma \int_0^{\text{min}(t,t')}dt'' \text{e}^{(-\lambda+\bm{K})(t-t'')}\text{e}^{(-\lambda+\bm{K}^{\rm T})(t'-t'')}
\label{eq:Cmatrix_generic_t_tt}
\end{eqnarray}
In terms of the equal-time correlator
\begin{equation}
 \bm{C}(t,t)=\Sigma \int_{0}^{t}d\tau\,\text{e}^{(-\lambda+\bm{K})\tau}\text{e}^{(-\lambda+\bm{K}^{\rm T})\tau}
\end{equation}
this simplifies to
\begin{equation}
\bm{C}(t,t')=\begin{cases}\text{e}^{(-\lambda+\bm{K})(t-t')}\bm{C}(t',t')&t\geq t'\\
\bm{C}(t,t)\text{e}^{(-\lambda+\bm{K}^{\rm T})(t'-t)} &t'>t
\end{cases}
\end{equation}
In the long-time limit $\bm{C}(t,t')$ will become TTI again, with $\bm{C}(t,t')=\bm{C}(t-t')$; $\bm{C}(0)$ then is the long-time limit of $\bm{C}(t,t)$. 
Combining the expressions for the two relative orderings of $t$ and $t'$ above and performing a two-sided Laplace transform with respect to the time difference gives
\begin{equation}
 \label{firMan}
  \tilde{\bm{C}}(z)=\bm{C}(0)(-z + \lambda - \bm{K}^{\rm T})^{-1} + (z + \lambda - \bm{K})^{-1}\bm{C}(0)
 \end{equation}
For further analysis it is useful to rewrite $\bm{C}(0)$ as
 \begin{eqnarray}
  \bm{C}(0)&=\Sigma\int_{0}^{\infty}d\tau_1\int_{0}^{\infty}d\tau_2 \,\text{e}^{(-\lambda+\bm{K})\tau_1}\text{e}^{(-\lambda+\bm{K}^{\rm T})\tau_2}\delta(\tau_1-\tau_2)=\notag\\
&=\Sigma\int_0^{\infty}d \tau_1 \int_0^{\infty} d \tau_2 \int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} \, \text{e}^{\text{i} \omega (\tau_1-\tau_2)} \, \text{e}^{(-\lambda+ \bm{K})\tau_1}\,\text{e}^{(-\lambda+\bm{K}^{\rm T})\tau_2}
 \end{eqnarray}
so that after integrating over $\tau_1$ and $\tau_2$ one has
  \begin{equation}
  \label{eq:fortrace}
  \bm{C}(0)=\Sigma\int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} (\lambda- \text{i}\omega - \bm{K})^{-1}(\lambda + \text{i}\omega- \bm{K}^{\rm T})^{-1}
 \end{equation}
 For a comparison with the $\tilde{C}(z)$ obtained in the Plefka approximation we need the normalized trace again, as in the case of the response, and combining \eqref{firMan} and \eqref{eq:fortrace} this takes the form
  \begin{equation}
  \label{eq:trace}
  \text{Tr}\,\tilde{\bm{C}}(z)= \Sigma\int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} \, \frac{1}{z-\text{i}\omega}\bigg\lbrace\big\langle\text{Tr}\big[(\lambda-z - \bm{K})^{-1}(\lambda + \text{i}\omega - \bm{K}^{\rm T})^{-1}\big]\big\rangle-\big\langle\text{Tr}\big[(\lambda- \text{i}\omega - \bm{K})^{-1}(\lambda + z - \bm{K}^{\rm T})^{-1}\big]\big\rangle\bigg\rbrace 
  \end{equation}
where the simple matrix identity
\begin{equation}
(a-\bm{A})^{-1}-(b-\bm{A})^{-1}= (a-\bm{A})^{-1}(b-\bm{A})^{-1}(b-a)
  \end{equation}
 has been applied. We have explicitly added an average over the random sampling of $\bm{K}$ in order to be able to use random matrix technique for further evaluation. 
 This is justified because like the response, which depends only on the spectrum and is self-averaging for large $N$ because the spectrum is, 
 the correlation function is also expected to be self-averaging. For later notational convenience we have also transformed $z \rightarrow -z$ on the r.h.s.\ of \eqref{eq:trace}, anticipating 
 that the final result \eqref{eq:fincor} will be even in $z$.

The benefit of the above manipulations is that the calculation of the exact correlations is now reduced to finding the quadratic resolvents
 \begin{equation}
 \label{eq:res1}
 \big\langle \text{Tr}\big[(\lambda- \text{i}\omega - \bm{K})^{-1}(\lambda + z - \bm{K}^{\rm T})^{-1}\big]\big\rangle
 \end{equation}
 \begin{equation}
 \label{eq:res2}
\big\langle\text{Tr}\big[(\lambda-z - \bm{K})^{-1}(\lambda + \text{i}\omega - \bm{K}^{\rm T})^{-1}\big]\big\rangle
 \end{equation}
Adapting the technique of \cite{chalker} to our case of real-valued matrices, we find for such resolvents the general result
 \begin{equation}
 \label{reso1}
 \big\langle \text{Tr}\big[(z_1 - \bm{K})^{-1}(\bar{z}_2 - \bm{K}^{\rm T})^{-1}\big]\big\rangle = \frac{g_1 \bar{g}_2}{1-g_1 \bar{g}_2}
 \end{equation}
 where
 \begin{equation}
  g_1=\frac{z_1-\sqrt{z_1^2-4\eta}}{2\eta} \qquad \bar{g}_2=\frac{\bar{z}_2-\sqrt{\bar{z}_2^2-4\eta}}{2\eta}
 \end{equation}
Comparing with \eqref{eq:intresp}, one observes that $g_1$ and $\bar{g}_2$ are themselves response functions, with $z_1$ and $\bar{z}_2$ respectively replacing $z+\lambda$. In the case $\eta=0$, the r.h.s.\ of \eqref{reso1} simplifies further to $1/(z_1\bar{z}_2-1)$.

One expects the result \eqref{reso1} to apply whenever both $z_1$ and $\bar{z}_2$ are outside of the spectral ellipse. This is easily verified: one checks 
that $|g_1|=1$ is another parametrization for the boundary of this ellipse
 \begin{equation}
  |g_1|=1 \Leftrightarrow \quad \vline z_1-\sqrt{z_1^2-4\eta}\, \vline =2\eta
 \end{equation}
with foci $z_1=\pm 2\sqrt{\eta}$ and semi-axes $1+\eta$ and $1-\eta$ as before. So $z_1$ and $\bar{z}_2$ are outside of the spectral ellipse when $|g_1|<1$ and $|\bar{g}_2|<1$, which ensures that \eqref{reso1} is non-singular. The resolvent then diverges when e.g.\ $z_1=z_2$ and $z_1$ approaches the boundary of the ellipse.

 To work out the trace \eqref{eq:trace} defining the Laplace transformed correlation function, we need to set in the first resolvent \eqref{eq:res1} $z_1=\lambda-\text{i}\omega$ and $\bar{z}_2=\lambda+z$, and in the second \eqref{eq:res2} $z_1=\lambda-z$ and $\bar{z}_2=\lambda+\text{i}\omega$. After 
these substitutions the integration can be conveniently carried out using residues (see \ref{appendix:a}), with the result
    \begin{equation}
   \label{eq:fincor}
\tilde{C}(z)=\frac{\Sigma\,\tilde{R}(z)\tilde{R}(-z)}{1-\tilde{R}(z)\tilde{R}(-z)}
 \end{equation}
This is identical to the prediction  \eqref{eq:corple} of the Plefka approximation. Our conclusion is, therefore, that for our model with weak long-range interactions the extended Plefka approach provides fully exact results for response and correlation functions, in the thermodynamic limit $N\to\infty$.


\section{Quantitative results}

In this section we look at the quantitative results for our model system in more detail. As the model does not obey detailed balance when $\eta < 1$, we are in general 
dealing with a non-equilibrium steady state and will see some nontrivial features emerge from this.

We focus initially on the correlation function \eqref{eq:fincor}, which after substituting $\tilde{R}(z)$ and $\tilde{R}(-z)$ and simplifying reads
 \begin{equation}
 \label{FinCor}
  \tilde{C}(z)=\frac{4\,\Sigma}{\big[(\lambda+z)+\sqrt{(\lambda+z)^2-4\eta}\big]\big[(\lambda-z)+\sqrt{(\lambda-z)^2-4\eta}\big]-4}
 \end{equation}
Particular cases of note are
 \begin{equation}
\label{eq:CorAsym}
\tilde{C}(z)\big\rvert_{\eta=0}=
\frac{\Sigma}{\lambda^2-z^2-1}
 \end{equation}
 \begin{equation}
 \label{CorSym}
 \tilde{C}(z)\big\rvert_{\eta=1}=\Sigma\bigg[-\frac{1}{2} + \frac{1}{4 z}\sqrt{(\lambda+z)^2-4}-\frac{1}{4 z}\sqrt{(\lambda-z)^2-4}\bigg]
 \end{equation}
 \begin{equation}
 \tilde{C}(z)\big\rvert_{\eta=-1}=\Sigma\bigg[-\frac{1}{2} + \frac{1}{4 \lambda}\sqrt{(\lambda+z)^2+4}+\frac{1}{4 \lambda}\sqrt{(\lambda-z)^2+4}\bigg]
 \end{equation}
where the middle one is the detailed balance limit.

The long-time behaviour of $C(t-t')$ is determined by the singularities, i.e.\ poles and branch cuts, of $\tilde{C}(z)$ that are closest to the origin. It will be useful to think of 
these in relation to two copies of the spectral ellipse: bearing in mind that $\tilde{R}(\pm z)=g_1(z\mp\lambda)$, these are shifted to have their centres at $\pm \lambda$.

For generic $\eta$ (see figures \ref{fig:symPo}, \ref{fig:symPoN} in \ref{appendix:a}), each of the two square roots in $\tilde{C}(z)$ contributes a branch cut. Each branch cut lies completely 
inside the relevant shifted spectral ellipse, and extends from one focus of the ellipse to the other. Explicitly, the branch cuts are
\begin{subequations}
\label{branchcuts}
\begin{align}
\pm\lambda-2\sqrt{\eta}<\,\text{Re}(z_{\text{bc}})<\pm\lambda+ 2\sqrt{\eta} \qquad \qquad \text{Im}(z_{\text{bc}})=0 \qquad &\eta>0\label{branchcuts_first}\\
\text{Re}(z_{\text{bc}}) =\pm\lambda   \qquad  -2\sqrt{|\eta|}<\text{Im}(z_{\text{bc}})<+ 2\sqrt{|\eta|} \qquad &\eta<0\label{branchcuts_second}
\end{align}
\end{subequations}
In the symmetric and anti-symmetric limits the ellipses degenerate to straight lines that coincide with the branch cuts while in the asymmetric case $\eta=0$ each branch cut shrinks to a point $z_{\text{bc}}=\pm \lambda$ at the centre of the spectral circle; see figure \ref{fig:AsyPo} in \ref{appendix:a}.
In addition to branch cuts, the Laplace transformed correlation function \eqref{FinCor} can have poles (for $\eta\neq 1,-1$). Setting the denominator of \eqref{FinCor} to zero gives
 \begin{equation}
 \label{zpole}
 z_{\text{pole}}=\pm z_0   \ \ {\rm with}\ \ z_0=  \bigg( \frac{1-\eta}{1+\eta} \bigg)\sqrt{\lambda^2-(1+\eta)^2} 
 \end{equation}
These poles emerge from the branch cuts as $\lambda$ is decreased below the threshold value $\lambda_{\text{threshold}}=(1+\eta)^2/(2\sqrt{\eta})$ for $\eta>0$ and $\lambda_{\text{threshold}}=(1-\eta^2)/(2\sqrt{|\eta|})$ for 
$\eta<0$ (see figure \ref{fig:l2th}); they do not exist for larger $\lambda$ because they are then no longer on the physical branch of $\tilde{C}(z)$. With decreasing $\lambda$ they then move towards the origin and reach it at a critical value for $\lambda$ given by $\lambda_{\text{min}}(\eta)=1+\eta$. 
This makes sense as the largest real part of eigenvalues within the spectral ellipse of $\bm{K}$ is exactly $1+\eta$: for $\lambda<\lambda_{\text{min}}$ these eigenvalues 
would cause the correlation function to diverge for long time differences.

The long-time or terminal decay rate $r$ of the correlation function is now given by the singularity, be it pole or branch cut edge, that has the smallest (positive) real part. Its inverse $1/r$ is the largest relaxation time.
The real part of the pole is $z_0$ itself, $r_{\text{pole}}=z_0$, while for the branch cut it is, from \eqref{branchcuts_first}, $r_{\text{bc}}=\lambda-2\sqrt{\eta}$ for $\eta>0$ and $r_{\text{bc}}=\lambda$ otherwise.
For $\lambda_{\text{min}}<\lambda<\lambda_{\text{threshold}}$, i.e.\ when the pole exists, one has $r_{\text{pole}}<r_{\text{bc}}$ thus $r_{\text{pole}}$ sets $r$. For all other values of $\lambda$, $r_{\text{bc}}=\lambda-2\sqrt{\eta}$ 
becomes responsible for the asymptotic decay. Bearing in mind that for a non-interacting system we would have $C(t-t')=\Sigma\exp(-\lambda |t-t'|)$, this means that the asymptotic decay rate of $C$ is only ever made smaller by the 
interactions, never larger.

\begin{figure}
\includegraphics[width=\textwidth]{lambda_th.eps}
\caption{$\lambda_{\text{threshold}}$ and $\lambda_{\rm min}$ as a function of $\eta$. The pole exists for $\lambda_{\rm min}<\lambda<\lambda_{\text{threshold}}$, i.e.\ for values of $\lambda$ lying in the grey shaded area. Where the pole exists it determines the asymptotic decay rate of the correlation function.}
\label{fig:l2th}
\end{figure}

\cleardoublepage

\subsection{Power Spectra and Power Laws}
\label{sec:PS}
We can obtain the power spectrum of the fluctuations in our system by setting $z=\text{i}\omega$ in \eqref{FinCor}, which converts the two-sided Laplace transform to a Fourier transform. For notational simplicity
we use the same symbol $\tilde{C}(\omega)$ for the latter as for the former, the meaning being clear from the argument of the function. Of primary interest is how the power spectrum differs from the simple Lorentzian
case corresponding to a purely exponential correlation function decay. 

We note first that the asymmetric case $\eta=0$ in \eqref{eq:CorAsym} always gives a Lorentzian power spectrum $\tilde{C}(\omega) = \Sigma/(\lambda^2-1+\omega^2)$. The presence of the interactions only manifests itself here in a change of the characteristic frequency from $\lambda$ to $r_{\text{pole}}=\sqrt{\lambda^2-1}$.
More generally for large $\lambda$ any non-trivial features of the correlation function will be hidden underneath a 
rapidly decaying $\exp(-\lambda |t-t'|)$ envelope, giving a Lorentzian power spectrum. This can be seen formally by taking $\lambda\to\infty$ in \eqref{FinCor} at $z$ of order $\lambda$.

Non-trivial power spectra are then expected to appear in the opposite regime of small $\lambda$, or more precisely small $\lambda - \lambda_{\text{min}}$ where $\lambda_{\text{min}}=1+\eta$. Keeping the self-interaction in the vicinity of this critical value allows one to detect interesting features such as power law tails, as illustrated in
figure \ref{fig:Com5}. To make the comparison of different spectral shapes easier it is convenient to remove uninteresting prefactors, i.e.\ to extract the overall scales of $\tilde{C}(\omega)$ and $\omega$ and plot the normalized quantities. For $\tilde{C}(\omega)$ we take as the scale
 \begin{equation}
  C(0)=\int_{-\infty}^{+\infty}\frac{d \omega}{2\pi}\,\tilde{C}(\omega)
 \end{equation}
 A scale for $\omega$ can be extracted as the inverse of a typical timescale $\tau$ for the decay of correlations; we choose in particular a root mean squared decay time 
 \begin{equation}
  \tau^2= \frac{\int_{-\infty}^{+\infty} dt \, t^2 C(t)}{2\int_{-\infty}^{+\infty} dt \, C(t)}=\frac{\int_{-\infty}^{+\infty} dt \, t^2 C(t)}{2\tilde{C}(0)}
 \end{equation}
 We then plot $\tilde{C}(\omega)/[\tau C(0)]$ versus $\omega \tau$ to ensure the normalized spectrum has a unit area under the curve. A log-log plot as in figure \ref{fig:Com5} shows clearly the large-frequency Lorentzian tail and suggests slower power law correlation decays for positive $\eta$ and oscillatory decay for negative $\eta$.
 
\begin{figure}
\includegraphics[width=\textwidth]{Com30.eps}
\caption{Log-log plots of normalized (see text) power spectra for different symmetries. $\lambda$ is taken close to the corresponding minimal value $1+\eta$ to highlight non-Lorentzian features. 
For small $\omega$, the horizontal plateau represents an exponential cutoff, while the large $\omega$ tail $\sim 1/\omega^2$ is as for a Lorentzian ($\eta=0$). The power spectra for $\eta>0$ are broader than Lorentzian, suggesting slower decays that approach power laws for $\lambda\to 1+\eta$. For $\eta<0$ sharp drops in the power spectrum suggest oscillatory correlation decay in the time domain.}
\label{fig:Com5}
\end{figure}

 \begin{figure}
\includegraphics[width=\textwidth]{NewPowerLaw.eps}
\caption{Power spectrum at minimal $\lambda=1+\eta$ for positive symmetry parameters $\eta$. Dashed lines show the asymptotic power laws at small frequency, which govern the long-time behaviour. For slight asymmetry 
($\eta=1-\epsilon$), one sees interpolation between two master curves governing the frequency regimes of $\omega=O(1)$ and $\omega \sim \epsilon^2$. All curves show unnormalized power spectra, for noise amplitude $\Sigma=1$.}
 \label{fig:powerLawPaper01}
\end{figure}
\begin{figure}
\includegraphics[width=\textwidth]{powerLaw1.eps}
\caption{Analogue of figure \ref{fig:powerLawPaper01} for negative symmetry parameters $\eta$. For small deviations from anti-symmetry ($\eta=-1+\epsilon$) the power spectrum splits into two regimes at $\omega=2$, each with its
own master curve (dashed lines). The amplitude in the low frequency part diverges as $1/\epsilon$ while the higher frequencies have a finite amplitude for $\epsilon\to 0$, so that an effective frequency cutoff at $\omega=2$ 
develops in the limit.}
 \label{fig:powerLawPaper02}
\end{figure}
We want to investigate more formally the emergence of power law behaviours for large time. This requires minimizing the effect of the exponential cut off provided by the self-interaction, so we consider $\lambda=\lambda_{\text{min}}$.
We then need to study the behaviour of $\tilde{C}(\omega)$ for small $\omega$. For $\eta=1$ one finds, by expansion of \eqref{CorSym}, $\tilde{C}(\omega)\sim 1/\sqrt{2\omega}$, corresponding to a $|t-t'|^{-1/2}$ decay in the time
domain. 
 
To understand the effect of slight deviations from symmetry we set $\eta=1-\epsilon$ with $\epsilon$ small. At fixed frequencies $\omega\sim O(1)$, the limit $\epsilon\to 0 $ then just 
retrieves $\tilde{C}(\omega)\vert_{\eta=1}$, so the latter
  \begin{equation}
\tilde{C}(\omega)\vert_{\eta=1}=-\frac{1}{2} + \frac{1}{2\sqrt{2}|\omega|}\sqrt{4-\lambda^2+\omega^2+\sqrt{\omega^4+2\omega^2(\lambda^2+4)+(\lambda^2-4)^2}}
 \end{equation}
evaluated at $\lambda=\lambda_{\text{min}}=2$ is the limiting ``master curve" for small $\epsilon$ in this part of the power spectrum
 \begin{equation}
\tilde{C}(\omega)\vert_{\eta=1,\,\lambda=2}=-\frac{1}{2} + \frac{1}{2\sqrt{2}|\omega|}\sqrt{\omega^2+\sqrt{\omega^4+16\omega^2}}
 \end{equation}
This master curve has asymptotic behaviour $\sim 1/\sqrt{2\omega}$ for small $\omega$, as found above: the power spectrum for small $\epsilon$ generically contains a non-Lorentzian power law regime as our initial numerics suggested.

If rather than fixing $\omega$ first and then taking $\epsilon\to 0$, we directly expand $\tilde{C}(\omega)$ for small $\omega$ at fixed $\epsilon$, we find
$\tilde{C}(\omega)\sim \frac{\epsilon^3}{2\omega^2}$ instead of $1/\sqrt{2\omega}$. Comparing the two expressions suggests that there is a crossover between two different regimes at a frequency scaling as $\epsilon^2$.  
To analyse the crossover region we therefore set $\omega=\epsilon^2 \gamma$ and take $\epsilon\to 0$ at fixed $\gamma$. The rescaled correlation $\epsilon \tilde{C}(\omega)$ then approaches a separate master curve 
 \begin{equation}
  \hat{C}(\gamma) = \frac{1+\sqrt{1+16\gamma^2}+ 2\sqrt{2}\gamma\sqrt{-1+\sqrt{1+16\gamma^2}}+\sqrt{2}\sqrt{1+\sqrt{1+16\gamma^2}}}{8\gamma^2\epsilon}
 \end{equation}
 The two tails of this low-frequency master curve retrieve the scalings found above as they should
\begin{subequations}
\begin{align}
&\gamma\ll1 \qquad (\omega\ll\epsilon^2) \qquad \hat{C}(\gamma)\sim 1/2\epsilon\gamma^2 \qquad \tilde{C}(\omega)\sim \epsilon^3/2\omega^2\\
&\gamma\gg1 \qquad (\omega\gg\epsilon^2) \qquad \hat{C}(\gamma)\sim 1/\epsilon\sqrt{2\gamma} \qquad \tilde{C}(\omega)\sim 1/\sqrt{2\omega}
\end{align}
 \end{subequations}
 The results of the above analysis are illustrated in figure \ref{fig:powerLawPaper01}. %@@ generally you need to place figures slightly before where they're first referenced in your latex file, as latex will only ever put them {\em later} than where they sit in the file @@
 Dashed lines indicate the exponents of the limiting power laws.

\newcommand{\lambdac}{\lambda_{\rm min}}

One notable aspect of the above power spectra is the $1/\omega^2$ tail for $\omega\to 0$, which makes the time-domain correlation function $C(t-t')$, obtained by inverse Fourier transform, formally infinite. 
This divergence could be regularized by taking $\lambda$ slightly larger than $\lambdac$; it turns out that in this limit the dominant contribution to $C(t-t')$ is from the pole $z_{\rm pole}$ defined 
in \eqref{zpole}. This contribution is of the order of $z_{\rm pole}^{-1} \exp[-z_{\rm pole}(t-t')]$, with $z_{\rm pole}$ scaling as $(\lambda-\lambdac)^{1/2}$.
 
Finally we consider the opposite end of the $\eta$ range and study the case of a slight deviation from antisymmetry, given by $\eta=-1+\epsilon$. To obtain the asymptotic behaviour for small $\epsilon$, we expand the power spectrum in $\epsilon$ and retain the two leading orders (which are $O(\epsilon^{-1})$ and $O(\epsilon^0)$). This yields
 \begin{equation}
\tilde{C}(\omega)\sim \frac{1}{\epsilon \omega^2}\bigg(4+2\sqrt{4-\omega^2}-\omega^2\bigg)+O(1) \qquad \omega<2
 \end{equation} 

 \begin{equation}
 \tilde{C}(\omega)\sim\frac{1}{\omega^2-4} +O(\epsilon) \qquad\omega>2
 \end{equation}
and these limiting curves are shown as dashed lines in figure \ref{fig:powerLawPaper02}. The key observation is that for small $\epsilon$ the power spectrum is confined almost entirely to the frequency range $0<\omega<2$, while higher frequencies are suppressed relative to this by a factor of $\epsilon$. As $\epsilon\to0$, a hard frequency cutoff therefore emerges at $\omega=2$.



\cleardoublepage
\subsection{Time Domain}
\label{sec:TD}
To gain further insight we can extract analytically the exact correlations in the time domain for $\eta=1$ (symmetric couplings) and $\eta=-1$ (anti-symmetric couplings).
For the symmetric case, using $\bm{K}^{\rm T}=\bm{K}$ in \eqref{eq:Cmatrix_generic_t_tt} gives
\begin{equation}
C(t,t') = 
\Sigma \int_0^{\text{min}(t,t')}dt'' \,\text{Tr}\,\text{e}^{(-\lambda+\bm{K})(t+t'-2t'')}
\end{equation}
The trace can be written as an integral over eigenvalues distributed according to Wigner's semi-circular law to give
\begin{eqnarray}
 C(t,t')&=\Sigma \int_{-2}^{2}\frac{dk}{2\pi}\sqrt{4-k^2}\,
\int_0^{\text{min}(t,t')}dt''\,\text{e}^{(-\lambda+k)(t+t'-2t'') }=\notag\\
 &= \Sigma\int_{0}^{\text{min}(t,t')}dt''\,\frac{I_1(2(t+t'-2t''))}{t+t'-2t''}\text{e}^{-\lambda(t+t'-2t'')}\\
 &=\Sigma\int_{|t-t'|}^{t+t'}dw\,\frac{I_1(2 w)}{2w}\text{e}^{-\lambda w} 
 \label{eq:mbf}
\end{eqnarray}
In the first step, we changed variable $k=2\cos{\theta}$ to write the $k$-integral as a modified Bessel function 
$\frac{I_1(\tau)}{\tau}=\frac{1}{\pi}\int_0^{\pi}d\theta(\sin{\theta})^2\text{e}^{\tau\cos{\theta}}$. The final equality follows by setting $w=t+t'-2t''$. In the long time limit the integral runs up to $+\infty$ and the result is manifestly TTI. The Fluctuation-Dissipation Theorem (FDT) \cite{FDT} is then expected to hold because for symmetric couplings the system has detailed balance. This can be checked by calculating the response function, which  comes out as simply the integrand of \eqref{eq:mbf}
%@@ this should be a ref to the last equation in the above group @@
\begin{equation}
 R(t-t')=\theta(t-t')\frac{I_1(2(t-t'))}{t-t'}\text{e}^{-\lambda(t-t')}
\end{equation}
This is as expected from the FDT $TR(t-t')=-(\partial/\partial t)C(t-t')$ where in our case $T=\Sigma/2$.

The power law behaviour we found above in Fourier space corresponds to a power law in the time domain as can be confirmed using the asymptotic expression of the modified Bessel function
%@@ use \verb|\gg| not $>>$ @@
\begin{equation}
\label{eq:bessela}
 I_1(z)\sim \frac{\text{e}^z}{\sqrt{2\pi z}} \qquad z \gg 1
\end{equation}
As a consequence, the response decays asymptotically as
\begin{equation}
\label{eq:asyre}
 R(t-t')\sim \frac{\text{e}^{-(\lambda-2)(t-t')}}{\sqrt{4 \pi}(t-t')^{{3}/{2}}}
\end{equation}
For the correlation function, if we substitute the expression (\ref{eq:bessela}) into \eqref{eq:mbf} and carry out the integration we obtain the asymptotic behaviour
\begin{equation}
\label{eq:mbfasy}
 C(t-t')\sim \frac{1}{2\sqrt{\pi(t-t')}}F((\lambda-2)(t-t'))
%& \sim \frac{1}{\sqrt{4 \pi}}\frac{\text{e}^{- (\lambda-2)(t-t')}}{2(t-t')^{{3}/{2}}(\lambda-2)}               
\end{equation}
where 
\be
F(x)= \text{e}^{-x}-\sqrt{\pi x}\,\text{erfc}(x)
\ee
Two regimes can be distinguished: for $x\ll 1$ (i.e. $t-t'\ll 1/(\lambda-2)$) $F(x)\sim 1$ and one has $C(t-t')\sim 1/2\sqrt{\pi (t-t')}$, whereas
for $x\gg 1$ (i.e. $t-t'\gg 1/(\lambda-2)$) $F(x)\sim \text{e}^{-x}/2 x$ thus $C(t-t')\sim \text{e}^{- (\lambda-2)(t-t')}/4\sqrt{\pi}(t-t')^{{3}/{2}}(\lambda-2)$.
 A comparison between the exact \eqref{eq:mbf} and the asymptotic \eqref{eq:mbfasy} expressions for the correlation function is shown in figure \ref{fig:exasy01}.

If $\bm{K}$ is anti-symmetric ($\eta=-1$), one can perform largely analogous calculations. The explicit expression for the correlations is
\begin{equation}
C(t,t') = \Sigma \int_0^{\text{min}(t,t')}dt'' \,\text{Tr}\,\text{e}^{-\lambda(t+t'-2t'')+\bm{K}(t-t')}=\frac{\Sigma}{2\lambda}(\text{e}^{-\lambda|t-t'|}-\text{e}^{-\lambda(t+t')})\text{Tr}\,\text{e}^{\bm{K}(t-t')}
\end{equation}
Replacing the trace by an integral over the eigenvalue spectrum, which is now a Wigner semicircle rotated onto the imaginary axis, and taking the long-time limit gives the TTI form
\begin{equation}
\label{eq:mbf1}
C(t-t')= \frac{\Sigma}{2\lambda}\frac{J_1(2(t-t'))}{t-t'}\text{e}^{-\lambda(t-t')}
\end{equation}
The Bessel function of the first kind in this is related to the modified Bessel function by $J_1(\text{i}x)=i I_1(x)$ \cite{abramowitz}. %We remark the TTI property of this result, $C(t,t')=C(t-t')$.\\
The response function for $t>t'$ is found similarly as
\begin{equation}
\label{eq:resasym}
 R(t-t')=\theta(t-t')\frac{J_1(2(t-t'))}{t-t'}\text{e}^{-\lambda(t-t')}
\end{equation}
From the asymptotics of $J_1$ one then finds for large time differences
\begin{equation}
\label{eq:mbf1asy}
 C(t-t')\sim \frac{\text{e}^{-\lambda(t-t')}\,\sin{\big[2\big((t-t') -\frac{\pi}{8}\big)\big]}}{\lambda \sqrt{\pi}(t-t')^{{3}/{2}}}
\end{equation}
so the power law component of the decay is as for the symmetric case $\eta=1$, but here with an oscillatory modulation from the exponential.
For a comparison between the exact \eqref{eq:mbf1} and the asymptotic \eqref{eq:mbf1asy} expressions for the correlation we refer to figure \ref{fig:exasy02}.

The results \eqref{eq:mbf1} and \eqref{eq:resasym} show that correlation and response are fully proportional for $\eta=-1$. This is unexpected from the point of view of the FDT, but of course here we are considering interactions that are not symmetric. Probability currents are then generically present in the steady state. These translate into  additional terms in the FDT, giving rise to a Modified Fluctuation-Dissipation Theorem; see e.g.~\cite{chetrite}. One can check that these terms generate exactly the proportionality between correlation and response we found above (see \cite{mythesis} for details).
 
\begin{figure}
\includegraphics[width=\textwidth]{asysym0.eps}
\caption{Correlations in the time domain: comparison between the analytically exact expression and the asymptotic curves for small and large $t-t'$, for symmetric interactions, $\eta=1$.}
\label{fig:exasy01}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{asyantisym.eps}
\caption{Analogue of figure \ref{fig:exasy01} for antisymmetric interactions, $\eta=-1$. The power law decay is visible here in the envelope of the oscillatory relaxation.}
\label{fig:exasy02}
\end{figure}

\section{Discussion and Conclusion}
\label{sec:conclusions}
In this paper we have developed and studied a novel approach for deriving approximate descriptions for large dynamical systems with continuous degrees of freedom. We refer to the method as an ``extended Plefka expansion", where the
extension lies in including second order statistics of the fluctuating degrees of freedom in the set of order parameters, rather than only first order averages, i.e.\ means.
Expanding in second order of interaction strength, we derive from the original dynamics -- a system of coupled stochastic differential equations -- effective equations of motion for each
single degree of freedom. These equations are decoupled, with interactions being represented by effective noise that is no longer white, and a memory term that connects each degree of 
freedom to its own past. The parameters governing these effective interaction terms are obtained from deterministic (nonlinear) coupled equations.

One key question we studied is under what circumstances the extended Plefka expansion can give exact results for large systems. We demonstrated explicitly for a linear dynamical model that this 
exactness holds when couplings are of mean field type, i.e.\ weak and long-ranged. An analogy can be drawn with works on soft spins dynamics \cite{sompolinsky0} \cite{sompolinsky1}, where the exact 
infinite-range limit produces local mean field equations with self-consistent propagator and noise.
Importantly, the agreement we show holds independently of whether the dynamics obeys detailed balance, due to symmetry in the interaction 
coefficients, or not; we explored the entire range of symmetry parameters from symmetry ($\eta=1$) to asymmetry ($\eta=0$) to anti-symmetry ($\eta=-1$). We also studied the quantitative features of the model in some detail, focussing on correlation functions and power spectra as their Fourier transform; this analysis revealed non-trivial crossover phenomena in the vicinity of either full symmetry or full anti-symmetry.

The extended Plefka method makes exact predictions for our linear model system, whereas -- as we discussed -- a conventional Plefka expansion fails to predict any non-trivial effects in correlations and 
responses. This suggests our method as a promising candidate for the accurate reconstruction of the dynamics of large systems also in generic nonlinear settings that cannot be solved analytically. 
The equations we have derived can be applied directly to such a generic case. We have mostly restricted ourselves to a model without self-interactions beyond the basic linear one that we assume, 
but this restriction can easily be lifted at the expense of longer expressions for the memory functions and effective noise correlations (see \ref{sec:complete_TAP} for a summary and \cite{mythesis} for details). 

An important question for such future applications is in what other scenarios one would expect the extended Plefka method to become exact in the large system limit. 
Generalizing from our linear model one could consider e.g.\ nonlinear drift terms of the form $\phi_i(\bm{x})= \sum_j K_{ij}g(x_j)$, where $g(\bm{x})$ is a generic non-linear function. With the potential application in biochemical networks in mind, $K_{ij}g(x_j)$ could describe the interaction due to reactions between different species $i$ and $j$, $K_{ij}$ being a reaction rates. From central limit theorem arguments one would expect that the dynamics of such a nonlinear system would again be described exactly by the extended Plefka method, provided that the $K_{ij}$ are weak and long-ranged. This should hold even if the nonlinearities are made species-specific so that $g(x_j)$ is replaced by $g_j(x_j)$.
Related models can be found  in the context of neural networks,  where $g(x_j)$ plays the role of a nonlinear gain function combining ``inputs'' to determine certain ``outputs". 
The mean field properties of such models, in the case of asymmetric $K_{ij}$ and $g(x_j)$ of sigmoid shape, were studied by Sompolinsky and coworkers \cite{sompolinsky2} and are consistent 
with the extended Plefka predictions. In general one could think of other simple scenarios where some moments of the variables $x_i$ can be calculated exactly and these may also provide useful 
future testbeds for our method. Interestingly, after the completion of this work, we discovered that an alternative perturbative approach also taking into account second 
moments had already been applied  by Biroli in the derivation of dynamical TAP equations for the $p$-spin spherical model~\cite{biroli}.
These TAP equations are the fixed-disorder analogue of the disorder-averaged equations first derived by \cite{thirumalai}. 
We have checked that the extended Plefka expansion gives back exactly Biroli's equations when applied to the $p$-spin model, with the Lagrange multiplier for the spherical constraint playing the role of our $\lambda_i$;
see \ref{sec:complete_TAP}. This is an important consistency check. Nevertheless we stress that the framework discussed in this paper is in principle wider, encompassing generic continuous variables and generic nonlinear
interaction terms. In addition, it is aimed at producing approximate decoupled equations that could be regarded as the first step for implementing inference algorithms.

A promising further development of our method would be to find a more sophisticated treatment of nonlinear self-interactions. In our present approach, these would be subsumed into the general interaction terms. Alternatively one could try to treat nonlinear self-interactions exactly, by keeping them as part of the non-interacting baseline for the Plefka expansion. This would result in effective equations of motion that are still decoupled but now nonlinear and driven by memory terms and coloured noise. The resulting self-consistency conditions for the order parameters would then have to be obtained by simulation, but there are precedents \cite{manfred} for doing this in a computationally efficient manner.

A further direction for future work would be to understand in more detail the relation to the Expectation-Propagation (EP) algorithm \cite{opperwinther}. For the case of linear self-interactions $-\lambda_i x_i$ that we mostly focussed on, EP and our extended Plefka method both yield factorized (over degrees of freedom) probability distributions over system trajectories, with the same non-interacting Gaussian baseline. It would therefore be interesting to clarify what the differences between the approaches are and under what circumstances they might lead to identical approximations. 

One important simplification we had to make was to assume that the different degrees of freedom $x_i$ are affected by independent noise, so that the noise covariance matrix 
$\bm{\Sigma}$ is diagonal. On the other hand,  in biochemical networks there are generically off-diagonal noise correlations: noise arises from the stochasticity of when reactions take place, and each non-trivial reaction affects the number of molecules from several molecular species.
The extension of our approach to this case requires further work. If the noise covariance $\bm{\Sigma}$ is at least independent of the state $\bm{x}$ of the system -- though even this is not the generic case for reaction networks -- then one could imagine transforming the variables $x_i$ linearly to diagonalize $\bm{\Sigma}$. This would then make our approach directly applicable, but would also make the biological interpretation of any predictions rather less intuitive.

In the long term our approximation framework should also help one to tackle network reconstruction problems, and this is a further important direction for future work. 
In fact, once the forward dynamics has been fully characterized as we have done here, one can think of setting up inverse techniques based on the same description. This would allow one e.g.\ to infer 
the states of hidden (unobserved) nodes from observations of other (visible) variables \cite{kalman}, and ultimately to learn interaction parameters and hence network structure from data.

\ack
This work is supported by the Marie Curie Training Network NETADIS (FP7, grant 290038). We thank Ludovica Bachschmid Romano, Zdzis\l{}aw Burda and Yasser Roudi for insightful discussions.

\cleardoublepage
\appendix
\section{Residue calculation}
\label{appendix:a}
\setcounter{section}{1}
We provide some details here of the exact calculation of the Laplace transformed correlation function $\tilde{C}(z)$ for the linear model with weak long-range interactions. The singularity structure of this function in the complex $z$-plane is sketched in figures \ref{fig:AsyPo}, \ref{fig:symPo} and \ref{fig:symPoN}. Below it will be useful to remember also that the singularities of the response function $\tilde{R}(z)$ are the same as those singularities of $\tilde{C}(z)$ that lie in the left half-plane. The difference arises because in the time domain the correlation function $C(t-t')$ is even in $t-t'$, while the response $R(t-t')$ vanishes for $t-t'<0$. 
 \begin{figure}
 \begin{center}
 \begin{tikzpicture} 
\draw [help lines,->] (0,-3) -- (0,3);  % Axis
\draw [help lines,->] (-5,0) -- (5,0);   
\node at (5,-0.3){$\text{Re}(z)$};
\node at (-0.6,2.8) {$\text{Im}(z)$};
% Contour line
  \node at (3,0) {$\bm{|}$};
  \node at (-3,0) {$\bm{|}$};
\node at (2.3,0) {$\times$};
  \node at (-2.3,0) {$\times$};
  \node at (3.1,-0.4){\small{$\lambda$}};
  \node at (2.2,-0.4){\small{$\sqrt{\lambda^2-1}$}};
  \node at (-1.9,-0.4){\small{$-\sqrt{\lambda^2-1}$}};
  \node at (-3.1,-0.4){\small{$-\lambda$}};
 \draw[style=dashed] (3,0) circle (1.5);
 \draw[style=dashed] (-3,0) circle (1.5);
\end{tikzpicture}
  \caption{Singularities of $\tilde{C}(z)$ in the complex $z$-plane for asymmetric interactions ($\eta=0$): for this value of $\eta$ the only singularities are the two poles $z_{\text{pole}}=\pm\sqrt{\lambda^2-1}$. The random matrix calculation following \cite{chalker}, which uses a perturbative approach, applies only outside the two copies of the spectral circle (of radius one) shifted to be centred at $z=\pm\lambda$, but the results can be continued analytically into the circles as $\tilde{C}(z)$ is a Laplace transform.}
\label{fig:AsyPo}
\end{center}
\end{figure} 

 \begin{figure}
 \begin{center}
 \begin{tikzpicture}
  \draw[style=dashed] (4,0) ellipse (2 and 1);
 \draw[style=dashed] (-4,0) ellipse (2 and 1);
\draw [help lines,->] (0,-5) -- (0,5);  % Axis
\draw [help lines,->] (-7,0) -- (7,0);   
\node at (6.8,-0.3){$ \text{Re}(z)$};
\node at (-0.6,4.8) {$ \text{Im}(z)$};
\node at (-0.6,0) {$\bm{\times}$}; % Pole
\node at (0.6,0) {$\bm{\times}$};
\node at (0.6,-0.3){$z_0$};
\node at (-0.6,-0.3){$-z_0$};
 \draw[very thick,black]
  (-3,0) -- (-5,0); 
  \draw[very thick,black]
  (3,0) -- (5,0);

  \node at (-4,0) {$\bm{\cdot}$};
  \node at (4,0) {$\bm{\cdot}$};
   \node at (-4,0.3) {$-\lambda$};
  \node at (4,0.3) {$+\lambda$};
    \node at (6,0) {$\bm{\cdot}$};
    \node at (-6,0) {$\bm{\cdot}$};
    \node at (2,0) {$\bm{\cdot}$};
    \node at (-2,0) {$\bm{\cdot}$};
     \node at (2,1.3) {$\lambda-(1+\eta)$};
     \draw [help lines,->] (2,1.0) -- (2,0.4); 
    \node at (-1.9,1.3) {$-\lambda+(1+\eta)$};
     \draw [help lines,->] (-2,1.0) -- (-2,0.4);
%     \node at (0,4) {$\bm{\cdot}$};
%    \node at (0,-4) {$\bm{\cdot}$};      
  \node at (5,0) {$\bm{|}$};
    \node at (3,0) {$\bm{|}$};
      \node at (-5,0) {$\bm{|}$};
        \node at (-3,0) {$\bm{|}$};
    \node at (6.2,1.3){\small{$\lambda+ (1 +\eta)$}}; 
    \draw [help lines,->] (6,1.0) -- (6,0.4); 
    \node at (-6.2,1.3){\small{$-\lambda- (1 +\eta)$}};
    \draw [help lines,->] (-6,1.0) -- (-6,0.4);
   %   \node at (0.8,-4.2){\small{$-\lambda- (1 -\eta)$}};  
   %   \node at (0.8,4.2){\small{$\lambda+ (1 -\eta)$}};  
  \node at (4.9,-1.3){\small{$\lambda+2 \sqrt{\eta}$}};
  \draw [help lines,->] (5,-1.0) -- (5,-0.4);
  \node at (2.9,-1.3){\small{$\lambda-2 \sqrt{\eta}$}};
  \draw [help lines,->] (3,-1.0) -- (3,-0.4); 
  \node at (-3,-1.3){\small{$-\lambda+2 \sqrt{\eta}$}};
  \draw [help lines,->] (-3,-1.0) -- (-3,-0.4);
  \node at (-5,-1.3){\small{$-\lambda-2 \sqrt{\eta}$}};
  \draw [help lines,->] (-5,-1.0) -- (-5,-0.4);
\end{tikzpicture}
\caption{Singularities of $\tilde{C}(z)$ in the complex $z$-plane for generic positive interaction symmetry ($\eta>0$): there are two  poles $z_{\text{pole}}=\pm z_0$ as well as two branch cuts connecting the four points $z_{\text{bc}}=\pm \lambda\pm 2\sqrt{\eta}$. The random matrix calculation applies only outside the two copies of the spectral ellipse shifted to be centred at $z=\pm\lambda$.
The ellipses have real and imaginary semi-axes $1+\eta$ and $1-\eta$, respectively; the foci are the edges of the branch cuts.}
\label{fig:symPo}
\end{center}
\end{figure} 

 \begin{figure}
 \begin{center}
 \begin{tikzpicture}
  \draw[style=dashed] (4,0) ellipse (1 and 2);
  \draw[style=dashed] (-4,0) ellipse (1 and 2);
\draw [help lines,->] (0,-5) -- (0,5);  % Axis
\draw [help lines,->] (-7,0) -- (7,0);   
\node at (6.8,-0.3){$ \text{Re}(z)$};
\node at (-0.6,4.8) {$ \text{Im}(z)$};
\node at (-5.5,0) {$\bm{\times}$}; % Pole
\node at (5.5,0) {$\bm{\times}$};
\node at (5.5,-0.3){$z_0$};
\node at (-5.5,-0.3){$-z_0$};
 \draw[very thick,black]
  (-4,-1) -- (-4,1); 
  \draw[very thick,black]
  (4,-1) -- (4,1);
  \node at (-4,0) {$\bm{\cdot}$};
  \node at (4,0) {$\bm{\cdot}$};
   \node at (-4.4,0.3) {$-\lambda$};
  \node at (4.4,0.3) {$+\lambda$};
    \node at (4,0) {$\bm{\cdot}$};
    \node at (-4,0) {$\bm{\cdot}$};
    \node at (3,0) {$\bm{\cdot}$};
    \node at (-5,0) {$\bm{\cdot}$};
    \node at (5,0) {$\bm{\cdot}$};
    \node at (-3,0) {$\bm{\cdot}$};
     \node at (1.7,0.6) {$\lambda-(1-|\eta|)$};
      \draw [help lines,->] (1.8,0.4) -- (2.9,0.1); 
    \node at (-1.7,0.6) {$-\lambda+(1-|\eta|)$};   
     \draw [help lines,->] (-1.9,0.4) -- (-2.9,0.1); 
  \node at (-4,1) {$\bm{-}$};
    \node at (-4,-1) {$\bm{-}$};
      \node at (4,1) {$\bm{-}$};
        \node at (4,-1) {$\bm{-}$};
    \node at (6.2,0.6){\small{$\lambda+ (1 -|\eta|)$}};  
     \draw [help lines,->] (6.,0.4) -- (5.1,0.1); 
    \node at (-6.2,0.6){\small{$-\lambda- (1 -|\eta|)$}};  
    \draw [help lines,->] (-6.,0.4) -- (-5.1,0.1); 
   %   \node at (0.8,-4.2){\small{$-\lambda- (1 -\eta)$}};  
   %   \node at (0.8,4.2){\small{$\lambda+ (1 -\eta)$}};  
  \node at (-4,-1.4){\small{$-2\sqrt{|\eta|}$}};
  \node at (-4,1.4){\small{$2 \sqrt{|\eta|}$}};
 \node at (4,-1.4){\small{$-2\sqrt{|\eta|}$}};
  \node at (4,1.4){\small{$2 \sqrt{|\eta|}$}};
\end{tikzpicture}
  \caption{Analogue of figure \ref{fig:symPo} for negative symmetry parameters $\eta$. The branch cuts and major semi-axes of the ellipses are now along the imaginary rather than the real direction, so that the foci and hence the edges of the branch cuts are at $z=\pm\lambda\pm2\text{i}\sqrt{|\eta|}$.}
\label{fig:symPoN}
\end{center}
\end{figure} 
Let us begin with asymmetric random interactions ($\eta=0$), for which \eqref{firMan} can be decomposed as
   \begin{equation}
  \text{Tr}\,\tilde{\bm{C}}(z) =\Sigma (I_1+I_2)
  %= \Sigma \int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} \, \frac{1}{z-\text{i}\omega}\bigg\lbrace \frac{1}{(\lambda+z)(\lambda-\text{i}\omega)-1} -\frac{1}{(\lambda-z)(\lambda+\text{i}\omega)-1} \bigg\rbrace
 \end{equation}
 where
 \begin{equation}
  I_1 = \int_{-\infty}^{+\infty}\frac{d \omega}{2\pi}\,\frac{1}{z-\text{i}\omega}\frac{1}{1-(\lambda+z)(\lambda-\text{i}\omega)} 
 \end{equation}
 \begin{equation}
  I_2 = \int_{-\infty}^{+\infty}\frac{d \omega}{2\pi}\,\frac{1}{z-\text{i}\omega}\frac{1}{(\lambda-z)(\lambda+\text{i}\omega)-1} 
 \end{equation}
 
 \begin{figure}[h]
 \begin{center}
 \begin{tikzpicture}
\draw [help lines,->] (0,-5) -- (0,5);  % Axis
\draw [help lines,->] (-5,0) -- (5,0);   
\node at (4.8,-0.3){$\text{Re}(\omega)$};
\node at (-0.6,4.8) {$\text{Im}(\omega)$};
\node at (-2,4.3) {$\mathcal{C}$};
\node at (0,-4) {$\bm{\times}$}; % Pole
\node at (0,2.5) {$\bm{\times}$};
\node at (0,-1.9) {$\bm{\times}$};
\node at (0.5,-4){$\omega_1$};
\node at (0.5,-1.9){$\omega_2$};
\node at (0.5,2.5){$\omega_3$};
\node at (-4.7,4.7){$I_1+I_2$};
% Contour line
\draw[very thick,black,xshift=2pt,
decoration={ markings,  % This schema allows for fine-tuning the positions of arrows
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.6 with {\arrow{latex}},
      mark=at position 0.8 with {\arrow{latex}}, 
      mark=at position 0.98 with {\arrow{latex}}}, 
      postaction={decorate}]
  (-4.5,0) -- (4.5,0);
\draw[thick,black,xshift=2pt,
decoration={ markings,
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.4 with {\arrow{latex}},
      mark=at position 0.6 with {\arrow{latex}}, 
      mark=at position 0.8 with {\arrow{latex}}}, 
      postaction={decorate}]
 (4.5,0) arc (0:180:4.5) ;

\end{tikzpicture}
  \caption{Integration contour in the complex plane for $I_1+I_2$ in the asymmetric case.}
\label{fig:Iasy}
\end{center}
\end{figure}
 These integrals can be performed in the complex plane as parts of integrals along a closed path. In fact, if we denote the integrands as $f_{1,2}(\omega)$, we can write
   \begin{equation}
I_{1,2}=\int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} f_{1,2}(\omega)= \big( \int_{-\infty}^{+\infty}+\int_{\mathcal{C}} \big) \frac{d \omega}{2\pi} f_{1,2}(\omega)= \oint \frac{d \omega}{2\pi} f_{1,2}(\omega) = \frac{1}{2\pi} \,2\pi \text{i} \sum_i \text{Res} f_{1,2}(\omega)\vert_{\omega=\omega_i} 
 \end{equation}
Here the $\omega_i$ refer to the poles inside the closed path, as drawn in figure \ref{fig:Iasy}. The value of the integral along the semicircle $\mathcal{C}$ vanishes when the radius goes to infinity as $f_{1,2}(\omega)\approx\frac{1}{\omega^2}\rightarrow 0$ for $|\omega|\rightarrow\infty$. 
The poles for $f_1(\omega)$ are
\begin{equation}
 \omega_1=-\text{i}z \qquad \omega_2= \text{i}\,\bigg[\frac{1-\lambda(\lambda+z)}{\lambda+z}\bigg]
\end{equation}
while the poles for $f_2(\omega)$ are
\begin{equation}
 \omega_1=-\text{i}z \qquad \omega_3= -\text{i}\,\bigg[\frac{1-\lambda(\lambda-z)}{\lambda-z}\bigg] 
\end{equation}
To locate the poles in the complex $\omega$-plane we can fix a convenient region for the value of $z$, which for the purposes of our integration is an external parameter, and then continue the result analytically in $z$ at the end. In particular, it is useful to ensure that $z+\lambda$ and $\lambda-z$ are kept outside the support of the spectrum of the interaction matrix $\bm{K}$, i.e.\ that $z$ stays outside the circles in figure \ref{fig:AsyPo}.
Let us therefore choose $z$ as real and $z>\lambda+1$. With this choice, $\omega_1$ and $\omega_2$ lie on the negative imaginary axis, while $\omega_3$ lies on the positive axis. We thus close the integration contour in the upper half plane so that 
it includes only $\omega_3$ and obtain
  \begin{equation}
I_1+I_2 = 2\pi \text{i} \,\text{Res} f_1(\omega)\vert_{\omega=\omega_2}= \frac{1}{2\pi} \,2\pi \text{i} \,  \frac{1}{\text{i}\,(\lambda^2-z^2-1)} =\frac{1}{\lambda^2-z^2-1}
 \end{equation}
 Thus
 \begin{equation}
 \label{CorAsym}
  \tilde{C}(z)=\frac{\Sigma}{\lambda^2-z^2-1}
 \end{equation}
This exact result agrees with the prediction \eqref{eq:corple} of the extended Plefka method once we insert the appropriate expression \eqref{reAsPl} for the response in the asymmetric case.

For arbitrary correlations $\eta$ between $K_{ij}$ and $K_{ij}$, \eqref{eq:trace} can be rewritten as
\begin{eqnarray}
   \label{eq:gen}
\fl\tilde{C}(z)&=\Sigma\int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} \big[\tilde{R}(-z)f_1(\omega)+\tilde{R}(z)f_2(\omega)\big]= \notag\\
\fl&=\Sigma\bigg(-\oint_1 \frac{d \omega}{2\pi} \tilde{R}(-z)f_1(\omega)+\oint_2 \frac{d \omega}{2\pi}\tilde{R}(z)f_2(\omega)+\int_{\mathcal{C}_1} \frac{d \omega}{2\pi}\tilde{R}(-z)f_1(\omega)-\int_{\mathcal{C}_2} \frac{d \omega}{2\pi}\tilde{R}(z)f_2(\omega)\bigg)=\notag\\
\fl&=\frac{\Sigma}{2\pi}\,2\pi\text{i}\bigg(-\sum_i\text{Res} \big[\tilde{R}(-z)f_1(\omega)\big]\bigg\vert_{\omega=\omega_i}+\sum_j\text{Res} \big[\tilde{R}(z)f_2(\omega)\big]\bigg\vert_{\omega=\omega_j} \bigg)
 \end{eqnarray}
where the signs refer to integration contours arranged as 
figures \ref{fig:Isym1} and  \ref{fig:Isym2}, i.e.\ with an anticlockwise orientation.
%@@ I don't understand -- your $I_1$ is {\em plus} the integral along contour 1 as you write only if the integration direction is clockwise as your figure shows. To make things consistent you then need to have a minus sign in front of the first residue term above. This also seems to agree with what you write below. @@ 
The functions $f_1$ and $f_2$ are defined as
 \begin{equation}
 \label{eq:f1}
  f_1(\omega)= \frac{1}{z-\text{i}\omega}\,\frac{\frac{\lambda+\text{i}\omega-\sqrt{(\lambda+\text{i}\omega)^2-4\eta}}{2\eta}}{1-\tilde{R}(-z)\bigg(\frac{\lambda+\text{i}\omega-\sqrt{(\lambda+\text{i}\omega)^2-4\eta}}{2\eta}\bigg)}= \frac{1}{z-\text{i}\omega}\,\frac{\tilde{R}(\text{i}\omega)}{1-\tilde{R}(-z)\tilde{R}(\text{i}\omega)}
 \end{equation}
 \begin{equation}
  f_2(\omega)= \frac{1}{z-\text{i}\omega}\,\frac{\frac{\lambda-\text{i}\omega-\sqrt{(\lambda-\text{i}\omega)^2-4\eta}}{2\eta}}{1-\tilde{R}(z)\bigg(\frac{\lambda-\text{i}\omega-\sqrt{(\lambda-\text{i}\omega)^2-4\eta}}{2\eta}\bigg)}=\frac{1}{z-\text{i}\omega}\,\frac{\tilde{R}(-\text{i}\omega)}{\tilde{R}(z)\tilde{R}(-\text{i}\omega)-1}
 \end{equation}
In the last line of \eqref{eq:gen} we have already exploited that, because $\text{lim}_{|\omega|\rightarrow \infty}|\omega f_1(\omega)|=0$ and $\text{lim}_{|\omega|\rightarrow \infty}|\omega f_2(\omega)|=0$, the contributions 
from the semicircles $\mathcal{C}_1$ and $\mathcal{C}_2$ vanish when their radius is sent to infinity.

For further evaluation we first focus on $\eta>0$. As before it is convenient to restrict $z$, here such that it lies outside the left spectral ellipses in figure \ref{fig:symPo}. 
The denominator of $f_1(\omega)$ and $f_2(\omega)$ then has only one relevant zero
 \begin{equation}
  \omega_1=-\text{i}z
 \end{equation}
 This is because with $z$ restricted as above, $|\tilde R(-z)|<1$, for exactly the same reason that $|g_1|<1$ outside the (unshifted) spectral ellipse as discussed in section \ref{sec:ED}. Our choice of contour 1 also guarantees that
 $|\tilde{R}(\text{i}\omega)|<1$ because the integration contour avoids the appropriately rotated spectral ellipse that governs $\tilde{R}(\text{i}\omega)$, as shown in figure \ref{fig:Isym1}. Thus 
 the denominator $1-\tilde{R}(-z)\tilde{R}(\text{i}\omega)$ in \eqref{eq:f1} can never be zero inside our integration contour. An exactly analogous argument applies to the integration over $f_2$. 
 
We now further restrict $z$ to be real and positive, such that $\omega_1$ lies in the lower half plane (see figures \ref{fig:Isym1} and \ref{fig:Isym2}). 
Only the integration contour for $f_1$  then encircles any singularities at all, and we obtain from \eqref{eq:gen}
    \begin{eqnarray}
\tilde{C}(z)&=\Sigma\int_{-\infty}^{+\infty} \frac{d \omega}{2\pi} \big[\tilde{R}(-z)f_1(\omega)+\tilde{R}(z)f_2(\omega)\big]=\notag\\
&=-\frac{\Sigma}{2\pi}\,2\pi\text{i}\,\text{Res}\big[\tilde{R}(-z)f_1(\omega)\big]\bigg\vert_{\omega=\omega_1}=\frac{\Sigma\,\tilde{R}(z)\tilde{R}(-z)}{1-\tilde{R}(z)\tilde{R}(-z)}
 \end{eqnarray}
as claimed in \eqref{eq:fincor} in the main text.
 
\begin{figure}
\begin{center}
\begin{tikzpicture}
\draw [help lines,->] (0,-5) -- (0,5);  % Axis
\draw [help lines,->] (-5,0) -- (5,0);   
\node at (5.2,-0.3){$\text{Re}(\omega)$};
\node at (-0.6,4.8) {$\text{Im}(\omega)$};
\node at (-2,-4.5) {$\mathcal{C}_1$};
\node at (0,-0.5) {$\bm{\times}$}; % Pole
%\node at (0,1.5) {$\bm{\times}$};
\node at (0.5,-0.5){$\omega_1$};
%\node at (0.5,1.5){$w_2$};
\node at (-4.7,4.7){$I_1$};
% Contour line
\node at (0,2){$\bm{-}$};
\node at (0,3){$\bm{-}$};
\node at (1,2){$\lambda-2\sqrt{\eta}$};
\node at (1,3){$\lambda+2\sqrt{\eta}$};
\draw[very thick,black]
  (0,2) -- (0,3);
\draw[very thick,black,xshift=2pt,
decoration={ markings,  % This schema allows for fine-tuning the positions of arrows
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.6 with {\arrow{latex}},
      mark=at position 0.8 with {\arrow{latex}}, 
      mark=at position 0.98 with {\arrow{latex}}}, 
      postaction={decorate}]
  (-4.5,0) -- (4.5,0);
\draw[thick,black,xshift=2pt,
decoration={ markings,
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.4 with {\arrow{latex}},
      mark=at position 0.6 with {\arrow{latex}}, 
      mark=at position 0.8 with {\arrow{latex}}}, 
      postaction={decorate}]
 (4.5,0) arc (0:-180:4.5) ;
\draw[style=dashed] (0,2.5) ellipse (0.7 and 1.5);
\end{tikzpicture}
  \caption{Integration contour in the complex plane for $I_1$ in the case of generic symmetry $\eta>0$.}
\label{fig:Isym1}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\begin{tikzpicture}
\draw [help lines,->] (0,-5) -- (0,5);  % Axis
\draw [help lines,->] (-5,0) -- (5,0);   
\node at (4.8,-0.3){$\text{Re}(\omega)$};
\node at (-0.6,4.8) {$ \text{Im}(\omega)$};
\node at (-2,4.5) {$\mathcal{C}_2$};
\node at (0,-0.5) {$\bm{\times}$}; % Pole
%\node at (0,-1.5) {$\bm{\times}$};
\node at (0.5,-0.5){$\omega_1$};
%\node at (0.5,-1.5){$w_3$};
\node at (-4.7,4.7){$I_2$};
\node at (0,-2){$\bm{-}$};
\node at (0,-3){$\bm{-}$};
\node at (1.2,-2){$-\lambda+2\sqrt{\eta}$};
\node at (1.2,-3){$-\lambda-2\sqrt{\eta}$};
\draw[very thick,black]
  (0,-2) -- (0,-3);
% Contour line
\draw[very thick,black,xshift=2pt,
decoration={ markings,  % This schema allows for fine-tuning the positions of arrows
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.6 with {\arrow{latex}},
      mark=at position 0.8 with {\arrow{latex}}, 
      mark=at position 0.98 with {\arrow{latex}}}, 
      postaction={decorate}]
  (-4.5,0) -- (4.5,0);
\draw[thick,black,xshift=2pt,
decoration={ markings,
      mark=at position 0.2 with {\arrow{latex}}, 
      mark=at position 0.4 with {\arrow{latex}},
      mark=at position 0.6 with {\arrow{latex}}, 
      mark=at position 0.8 with {\arrow{latex}}}, 
      postaction={decorate}]
 (4.5,0) arc (0:180:4.5) ;
\draw[style=dashed] (0,-2.5) ellipse (0.7 and 1.5);
\end{tikzpicture}
  \caption{Integration contour in the complex plane for $I_2$ in the case of generic symmetry $\eta>0$.}
\label{fig:Isym2}
\end{center}
\end{figure}




For $\eta<0$ an analogous calculation of the correlation function integral can be performed. Some changes in the relevant regions of the complex plane occur, 
namely the ellipses bounding the support of the spectrum are rotated (compare figures \ref{fig:symPo} and \ref{fig:symPoN}), but the method is the same for $\eta>0$, and so is the result.


\cleardoublepage

\section{Complete TAP equations}
\label{sec:complete_TAP}
%\label{appendix:b}
We lift the restriction ${\partial \phi_i(\bm{x}(t))}/{\partial x_i(t)}=0$ and the one regarding the additivity of variables in the drift $\phi_i(\bm{x}(t))$.
Then the dynamical equation up to $\alpha^2$ order can be written, from \eqref{eq:zerofields} and \eqref{eq:eff_dyn}, in the form
\begin{eqnarray}
\label{eq:ovdyn}
\fl\frac{d x_i(t)}{dt}=& -\lambda_i x_i(t)+ \alpha\langle\phi_i(t)\rangle
+\alpha \langle\partial_i \phi_i(t)\rangle\delta x_i(t)
\notag\\
&{}+\alpha^2\bigg[\int_{0}^t dt'\sum_j\, R_j(t,t')\langle \partial_{j}\phi_i(t)\partial_{i}\phi_j(t')\rangle\delta x_i(t')\notag\\
&{}-\int_{0}^t dt'R_i(t,t')\langle\partial_i\phi_i(t)\rangle\langle \partial_i \phi_i(t')\rangle\delta x_i(t')\notag\\
&{}+\int_{0}^t dt'\,\sum_j R_j(t,t')(\langle\partial_j\phi_i(t)\delta \phi_j(t')\rangle-\langle \partial^2_j \phi_i(t) \rangle C_j(t,t')\langle \partial_j\phi_j(t')\rangle)\notag\\
&{}+\int_{0}^t dt'\,\sum_j \big(\langle\partial_i\partial_j\phi_i(t)\delta \phi_j(t')\rangle-\delta C_j(t,t')\langle \partial_j \phi_j(t')\rangle \langle\partial_j^2\partial_i \phi_i(t)\rangle\big)\notag\\
&{}\qquad\qquad \qquad  R_j(t,t')\delta x_i(t)\bigg]+\xi_i(t)+\chi_i(t)
\end{eqnarray}
where the effective noise has correlator
\begin{equation}
\label{eq:beffself}
\langle \chi_i(t)\chi_i(t')\rangle= \frac{\alpha^2}{2}\big(\langle \delta\phi_i(t)\delta \phi_i(t')\rangle-\langle\partial_i\phi_i(t)\rangle\langle \partial_i \phi_i(t')\rangle\delta C_i(t,t')\big)
\end{equation}
For the sake of brevity we have dropped all $\bm{x}$-dependencies above, writing e.g.\ $\partial_i \phi_i(t)={\partial \phi_i(\bm{x}(t))}/{\partial x_i(t)}$ and $\phi_i(t)=\phi_i(\bm{x}(t))$. 

\newcommand{\dtp}{\delta\tilde{\phi}}

Compared to \eqref{eq:dx_dt_TAP} in the main text, there are a number of additional terms. The last term in the first line is the linearization of the self-interaction already familiar 
from our generic first order result \eqref{eq:dxi_dt_first_order}. This systematic effect of the self-interaction is correspondingly removed from the effective noise $\chi_i(t)$, whose correlator \eqref{eq:beffself} is easily shown to be the correlation function of $\dtp_i\equiv \delta\phi_i-\langle \partial_i \phi_i\rangle \delta x_i$. This is the genuinely interacting part of the drift, i.e.\ the one that is 
not captured in the first line of \eqref{eq:ovdyn}. The third line of \eqref{eq:ovdyn} similarly subtracts off the self-interaction term from the main memory term in the second line.

The fourth line of \eqref{eq:ovdyn} is a contribution that is independent of the specific history of $x_i$; instead it involves a time integral of {\em averages} over fluctuation statistics in the past. It can again be written in terms of $\dtp_i$, with the coefficients in brackets after 
$R_j(t,t')$ equal to $\langle \partial_j \phi_i(t)\dtp_j(t')\rangle$. The coefficient in front of $\delta x_i(t)$ in the fifth and sixth line of \eqref{eq:ovdyn} has an analogous form, as $\langle \partial_i \partial_j \phi_i(t)\dtp_j(t')\rangle$.
The overall contribution from the fourth, fifth and sixth line of \eqref{eq:ovdyn} can be cast as
\begin{equation}
\alpha^2 \int_{0}^t dt' \sum_j R_j(t,t')\big(\langle \partial_j \phi_i(t)\dtp_j(t')\rangle
+\delta x_i(t)\langle \partial_i \partial_j \phi_i(t)\dtp_j(t')\rangle\big)
\end{equation}
This has a fairly straightforward interpretation: a fluctuation in the drift of variable $j$ ($\dtp_j(t')$) that changes $x_j(t')$ is propagated forward to time $t$ by $R_j(t,t')$ and then affects the drift $\tilde\phi_i(t)$ including the linearized dependence on $x_i$. 

It is interesting to note that all of the additional terms disappear if there are no self-interactions ($\partial_i \phi_i=0$), except for the first term in the fourth line of \eqref{eq:ovdyn}. 
The latter vanishes if one makes in addition the assumption that interactions are additive in the variables, as then $\partial_j \phi_i$ depends only on $x_j$ and so is independent 
of $\dtp_j$ if there are no self-interactions. In the generic case of non-additive interactions, the first term in the fourth line remains. In particular, it gives a correction to the time evolution of the means
\begin{equation}
\label{eq:ovdynm}
\frac{d \mu_i(t)}{dt}= -\lambda_i \mu_i(t)+ \alpha\langle\phi_i(t)\rangle+\alpha^2\int_{0}^t dt'\,\sum_j R_j(t,t')\langle \partial_j \phi_i(t)\dtp_j(t')\rangle
\end{equation}
In an exact theory, only the first two terms are present, so that the last one has to be interpreted as correcting for the fact that the Plefka expansion produces an 
approximating distribution where all variables are decoupled. For the case of additive interactions, no such correction appears because $\langle \phi_i\rangle$ is then a 
sum of averages over single variables.

For the special case of the $p$-spin spherical model, we have verified that the above equations reproduce those derived by other means by Biroli \cite{biroli}. The correction to the mean dynamics vanishes for $p=2$ as expected, as the interactions are then additive, but is nonzero for $p>2$ where the drift involves products of variables.
   
\cleardoublepage
\bibliography{./Plefkabib}
\nocite{*}


\end{document}
pstricks.tex
%% pstricks.tex
%% COPYRIGHT 1993, 1994, 1999 by Timothy Van Zandt, tvz@nwu.edu.
%% COPYRIGHT 2000-2003 by Denis Girou.
%% Copyright 2004-2015 Herbert Voss
%
% 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 Herbert Voss
%
\csname PSTricksLoaded\endcsname
\let\PSTricksLoaded\endinput  
%
%% !! loading additional TeX packages see line 112 !!
%% !! loading config file pstricks.con    line 476 !!
%% !! loading pro files                   line 489 !!
%% !! fileversion and date see            line 119 !!
%
\edef\PstAtCode{\the\catcode`\@}
\catcode`\@=11\relax
%
\expandafter\ifx\csname @latexerr\endcsname\relax%	do we have LaTeX?
  \def\typeout#1{\immediate\write\@unused{#1}}%
  \gdef\ch@ck#1#2#3{\ifnum\count1#1<#2 \else\errmessage{No room for a new #3}\fi}
  \countdef\allocationnumber=21
  \chardef\sixt@@n=16
  \def\alloc@#1#2#3#4#5{\global\advance\count1#1\@ne
    \ch@ck#1#4#2% make sure there's still room
    \allocationnumber\count1#1%
    \global#3#5\allocationnumber
    \wlog{\string#5=\string#2\the\allocationnumber}}
  \alloc@7\write\chardef\sixt@@n\@unused
  \typeout{we are running tex and have to define some LaTeX commands ...}%
  \long\def\@ifundefined#1#2#3{\expandafter\ifx\csname #1\endcsname\relax#2\else#3\fi}
  \def\@namedef#1{\expandafter\def\csname #1\endcsname}
  \def\@nameuse#1{\csname #1\endcsname}
  \def\@eha{%
    Your command was ignored.^^J
    Type \space I <command> <return> \space to replace
    it with another command,^^J
    or \space <return> \space to continue without it.}
  \def\@spaces{\space\space\space\space}
  \def\@empty{}
  \def\@gobble#1{}
  \def\@nnil{\@nil}
%
  \def\@ifnextchar#1#2#3{%
    \let\@tempe#1\def\@tempa{#2}\def\@tempb{#3}\futurelet\@tempc\@ifnch}
%
  \def\@ifnch{%
    \ifx\@tempc\@sptoken \let\@tempd\@xifnch
    \else\ifx\@tempc\@tempe \let\@tempd\@tempa \else \let\@tempd\@tempb \fi
    \fi
    \@tempd%
  }
  \begingroup
  \def\:{\global\let\@sptoken= } \:
  \def\:{\@xifnch} \expandafter\gdef\: {\futurelet\@tempc\@ifnch}
  \endgroup
  \def\endtabular{\crcr\egroup\egroup $\egroup}
  \def\@width{width}% needed by pst-node
  \def\@tfor#1:={\@tf@r#1 }
  \long\def\@tf@r#1#2\do#3{\def\@fortmp{#2}\ifx\@fortmp\space\else
     \@tforloop#2\@nil\@nil\@@#1{#3}\fi}%
  \long\def\@tforloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
       \expandafter\@fornoop \else
      #4\relax\expandafter\@tforloop\fi#2\@@#3{#4}}
  \long\def\@break@tfor#1\@@#2#3{\csname fi\endcsname\csname fi\endcsname}
\fi%
\catcode`\@=\PstAtCode\relax
%
% now we have all commands defined, for TeX and LaTeX
%
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey.tex \fi
\catcode`\@=11\relax
\def\XKV@ch@ckch@ice#1#2#3{%  bugfix for xkeyval
  \def\XKV@tempa{#1}%
  \ifx\XKV@tempa\@nnil\let\XKV@tempa\@empty\else
    \def\XKV@tempa{\def#1{#2}}%
  \fi
%  \in@{,#2,}{,#3,}%
\begingroup\edef\x{\endgroup\noexpand\in@{,#2,}}\x{,#3,}%
%\expandafter\in@\expandafter{\expandafter,#2,}{,#3,}% --- hv 2012-04-27
  \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\ProvidesPackageRCS{\@ifnextchar[\ProvidesPackageRCS@i{\ProvidesPackageRCS@i[] }}  %$
\def\ProvidesPackageRCS@i[#1] $#2${} %$
\catcode`\@=\PstAtCode\relax
\ifx\PSTFPloaded\endinput\else   \input pst-fp.tex\fi

\input pgfutil-common.tex
\input pgfkeys.code.tex
\input pgffor.code.tex
\let\pgfforeach\foreach
%
\def\fileversion{2.63}
\def\filedate{2015/09/11}
\catcode`\@=11\relax
\pst@addfams{pstricks}
%
% stolen from latex.ltx to make it TeX compatible
\newcount\psLoopIndex
\def\@fornoop#1\@@#2#3{}
\long\def\@for#1:=#2\do#3{%
  \pst@cntm=0
  \expandafter\def\expandafter\@fortmp\expandafter{#2}%
  \ifx\@fortmp\@empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}
%
\long\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx#4\@nnil \else
       #5\def#4{#2}\ifx#4\@nnil \else\global\advance\psLoopIndex by \@ne\relax
       #5\@iforloop #3\@@#4{#5}\fi\fi}

\long\def\@iforloop#1,#2\@@#3#4{\global\advance\psLoopIndex by \@ne\relax%
   \def#3{#1}\ifx #3\@nnil
     \expandafter\@fornoop \else
     #4\relax\expandafter\@iforloop\fi#2\@@#3{#4}}
%
\long\def\psforeach#1#2#3{%
  \global\psLoopIndex=0\relax
  \if$\ifnum9<1#2$\else\fi\psforeach@ii{#1}{#2}{#3}%
  \else                      \expandafter\psforeach@i#2,..,,..,\@nil{#1}{#3}\fi}
\long\def\psforeach@i#1,#2,..,#3,..,#4\@nil#5#6{% 
  \ifx\relax#3\relax\psforeach@ii{#5}{#1,#2}{#6}%
  \else\psforeach@iii{#5}{#1}{#2}{#3}{#6}\fi}
\long\def\psforeach@ii#1#2#3{%
  \begingroup
  \edef\reserved@a{#2}%
  \@for#1:=\reserved@a\do{#3}%
  \endgroup}
\long\def\psforeach@iii#1#2#3#4#5{%
  \pstFPsub\pst@tempA{#3}{#2}%
  \pst@dimm=\pst@tempA pt%
  \pstFPstripZeros{\pst@tempA}\pst@tempB%
  \def\pst@tempA{#2}%
  \def\pst@tempa{#2}%
  \pst@dimn=#4pt%
  \loop
    \pst@dimm=\pst@tempA pt
    \ifdim\pst@dimm<\pst@dimn
      \pstFPadd\pst@tempA{\pst@tempA}{\pst@tempB}%
      \pstFPstripZeros{\pst@tempA}\pst@tempA%
      \edef\pst@tempa{\pst@tempa,\pst@tempA}%
  \repeat%
  \psforeach@ii{#1}{\pst@tempa}{#5}}
%
\long\def\psForeach#1#2#3{%  without grouping the contents
  \global\psLoopIndex=0\relax%
  \if$\ifnum9<1#2$\else\fi\psforeach@ii{#1}{#2}{#3}%
  \else                   \expandafter\psForeach@i#2,..,,..,\@nil{#1}{#3}\fi}
\long\def\psForeach@i#1,#2,..,#3,..,#4\@nil#5#6{% 
  \ifx\relax#3\relax\psForeach@ii{#5}{#1,#2}{#6}%
  \else\psForeach@iii{#5}{#1}{#2}{#3}{#6}\fi%
}
\long\def\psForeach@ii#1#2#3{%
  \edef\reserved@a{#2}%
  \@for#1:=\reserved@a\do{#3}}
\long\def\psForeach@iii#1#2#3#4#5{%
  \pstFPsub\pst@tempA{#3}{#2}%
  \pst@dimm=\pst@tempA pt%
  \pstFPstripZeros{\pst@tempA}\pst@tempB%
  \def\pst@tempA{#2}%
  \def\pst@tempa{#2}%
  \pst@dimn=#4pt%
  \loop%
    \pst@dimm=\pst@tempA pt%
    \ifdim\pst@dimm<\pst@dimn%
      \pstFPadd\pst@tempA{\pst@tempA}{\pst@tempB}%
      \pstFPstripZeros{\pst@tempA}\pst@tempA
      \edef\pst@tempa{\pst@tempa,\pst@tempA}%
  \repeat%
  \psForeach@ii{#1}{\pst@tempa}{#5}
}
  
\def\psrecur@i#1{\csname ps@rn#1\psrecur@i} 
\long\def\ps@rnm#1{\endcsname{#1}#1\global\advance\psLoopIndex by \@ne}
\long\def\ps@rn#1{}
\def\psLoop#1{\global\psLoopIndex=0\relax%
  \csname ps@rn\expandafter\psrecur@i
  \romannumeral\number\number#1 000\endcsname\endcsname}

%
% hv 2007-10-16 to fix the bug in pst-node with \\[name=...]
% hv fix bug with empty fnodes in psmatrix
\def\ps@ifnextchar#1#2#3{%
  \let\reserved@d= #1%
  \def\reserved@a{#2}\def\reserved@b{#3}%
  \futurelet\@let@token\ps@ifnch}
\def\ps@ifnch{%
  \ifx\@let@token\reserved@d \let\reserved@b\reserved@a \fi
  \reserved@b
}
\def\pshskip#1{\vrule \@width\z@\nobreak \hskip #1\hskip \z@skip}
% end bugfix
\typeout{`PSTricks' v\fileversion\space\space <\filedate> (tvz)}
\def\@pstrickserr#1#2{%
  \begingroup
  \newlinechar`\^^J
  \edef\pst@tempc{#2}%
  \expandafter\errhelp\expandafter{\pst@tempc}%
  \typeout{%
    PSTricks error. \space See User's Guide for further information.^^J
    \@spaces\@spaces\@spaces\@spaces
    Type \space H <return> \space for immediate help.}%
  \errmessage{#1}%
  \endgroup}
\def\@ehpa{%
  Your command was ignored. Default value substituted.^^J
  Type \space <return> \space to procede.}
\def\@ehpb{%
  Your command was ignored. Will recover best I can.^^J
  Type \space <return> \space to procede.}
\def\@ehpc{%
  You better fix this before proceding.^^J
  See the PSTricks User's Guide or ask your system administrator for help.^^J
  Type \space X <return> \space to quit.}
\def\@ehpd{%
  Not allowed optional argument.^^J
  Will proceed with the default setting.^^J
  Type \space X <return> \space to quit.}
\def\pst@misplaced#1{\@pstrickserr{Misplaced \string#1 command}\@ehpb}
\newdimen\pst@dima
\newdimen\pst@dimb
\newdimen\pst@dimc
\newdimen\pst@dimd
\newdimen\pst@dimg
\newdimen\pst@dimh
\newdimen\pst@dimm
\newdimen\pst@dimn
\newdimen\pst@dimo
\newdimen\pst@dimp
\chardef\f@ur=4
%
\newbox\pst@hbox
\newbox\pst@ibox
\newbox\pst@boxg
\newcount\pst@cnta
\newcount\pst@cntb
\newcount\pst@cntc
\newcount\pst@cntd
\newcount\pst@cntg
\newcount\pst@cnth
\newcount\pst@cntm
\newcount\pst@cntn
\newcount\pst@cnto
\newcount\pst@cntp
\newcount\@zero\@zero=0\relax
%
\newif\ifPst@SpecialLength
\Pst@SpecialLengthfalse
%
\newif\if@pst
\newtoks\pst@toks
\newif\if@star
\def\pst@ifstar#1{%
  \@ifnextchar*{\@startrue\def\ps@next*{#1}\ps@next}{\@starfalse#1}}
%
\def\pst@expandafter#1#2{%
  \def\ps@next{#1}%
  \edef\@tempa{#2}%
  \ifx\@tempa\@empty
    \@pstrickserr{Unexpected empty argument!}\@ehpb
    \def\@tempa{\@empty}%
  \fi
  \expandafter\ps@next\@tempa}
%
\def\pst@dimtonum#1#2{\edef#2{\pst@@dimtonum#1}}
\def\pst@@dimtonum#1{\expandafter\pst@@@dimtonum\the#1}
{\catcode`\p=12 \catcode`\t=12 \global\@namedef{pst@@@dimtonum}#1pt{#1}}
%
\def\pst@getdimdim#1 #2 #3\@nil{%
  \def\pst@tempA{#2}%
  \ifx\pst@tempA\@empty
    \pssetlength\pst@dimn{#1}%
    \pst@dimm=\z@%
  \else%
    \pssetlength\pst@dimm{#1}%
    \pssetlength\pst@dimn{#2}%
  \fi%
}
\def\pst@getxdimdim#1 #2 #3\@nil{%
  \def\pst@tempA{#2}%
  \ifx\pst@tempA\@empty
    \pssetxlength\pst@dimn{#1}%
    \pst@dimm=\z@
  \else%
    \pssetxlength\pst@dimm{#1}%
    \pssetxlength\pst@dimn{#2}%
  \fi%
}
\def\pst@getydimdim#1 #2 #3\@nil{%
  \def\pst@tempA{#2}%
  \ifx\pst@tempA\@empty
    \pssetylength\pst@dimn{#1}%
    \pst@dimm=\z@%
  \else
    \pssetylength\pst@dimm{#1}%
    \pssetylength\pst@dimn{#2}%
  \fi}
%
% A modulo macro for integer values
% \pst@mod{34}{6}\value ==> \value is 4
%
\def\pst@mod#1#2#3{%
  \begingroup%
  \pst@cntm=#1\pst@cntn=#2\relax%
  \pst@cnto=\pst@cntm%
  \divide\pst@cntm by \pst@cntn%
  \multiply\pst@cntn by \pst@cntm%
  \advance\pst@cnto by -\pst@cntn%
  \edef\value{\endgroup\def\noexpand#3{\number\pst@cnto}}\value%
}
\def\pst@max#1#2#3{%
  \begingroup%
  \pst@cntm=#1\pst@cntn=#2\relax%
  \ifnum\pst@cntm<\pst@cntn\pst@cntm=\pst@cntn\fi
  \global#3=\the\pst@cntm%
  \endgroup%
}
\def\pst@maxdim#1#2#3{%
  \begingroup%
  \pst@dimm=#1\pst@dimn=#2\relax%
  \ifdim\pst@dimm<\pst@dimn\pst@dimm=\pst@dimn\fi
  \global#3=\the\pst@dimm%
  \endgroup%
}
\def\pst@mindim#1#2#3{%
  \begingroup%
  \pst@dimm=#1\pst@dimn=#2\relax%
  \ifdim\pst@dimm>\pst@dimn\pst@dimm=\pst@dimn\fi
  \global#3=\the\pst@dimm%
  \endgroup%
}
\def\pst@abs#1#2{%
  \begingroup%
  \pst@cntm=#1\relax%
  \ifnum\pst@cntm<\z@\pst@cntm=-\pst@cntm\fi%
  \global#2=\the\pst@cntm
  \endgroup%
}
\def\pst@absdim#1#2{%
  \begingroup%
  \pst@dimm=#1\relax%
  \ifdim\pst@dimm<\z@\pst@dimm=-\pst@dimm\fi%
  \global#2=\the\pst@dimm%
  \endgroup%
}
%
\def\pst@pyth#1#2#3{% from pst-3d
  \begingroup%
    \pst@dima=#1\relax%
    \ifnum\pst@dima<\z@\pst@dima=-\pst@dima\fi% dima=abs(x)
    \pst@dimb=#2\relax%
    \ifnum\pst@dimb<\z@\pst@dimb=-\pst@dimb\fi% dimb=abs(y)
    \advance\pst@dimb\pst@dima         % dimb=s=abs(x)+abs(y)
    \ifnum\pst@dimb=\z@
      \global\pst@dimg=\z@             % dimg=z=sqrt(x^2+y^2)
    \else
      \multiply\pst@dima 8\relax              % dima= 8abs(x)
      \pst@@divide\pst@dima\pst@dimb     % dimg =8t=8abs(x)/s
      \advance\pst@dimg -4pt            % dimg = 4tau = (8t-4)
      \multiply\pst@dimg 2
      \pst@dimtonum\pst@dimg\pst@tempa
      \pst@dima=\pst@tempa\pst@dimg           % dima=(8tau)^2
      \advance\pst@dima 64pt         % dima=u=[64+(8tau)^2]/2
      \divide\pst@dima 2\relax                      % =(8f)^2
      \pst@dimd=7pt                % initial guess at sqrt(u)
      \pst@@pyth\pst@@pyth\pst@@pyth            % dimd=sqrt(u)
      \pst@dimtonum\pst@dimd\pst@tempa
      \pst@dimg=\pst@tempa\pst@dimb
      \global\divide\pst@dimg 8             % dimg=z=(8f)*s/8
    \fi
  \endgroup
  #3=\pst@dimg}
%
\def\pst@@pyth{%                      dimd = g <-- (g + u/g)/2
  \pst@@divide\pst@dima\pst@dimd
  \advance\pst@dimd\pst@dimg
  \divide\pst@dimd 2\relax}
%
% ----- the old pst@pyth begin -----  did not use dimens
\def\pst@Pyth#1#2#3{\ifdim#1>#2\pst@@Pyth#1#2#3\else\pst@@Pyth#2#1#3\fi}
\def\pst@@Pyth#1#2#3{%
  \ifdim4#1>9#2\relax
    #3=#1\advance#3 .2122#2%
  \else
    #3=.8384#1\advance#3 .5758#2%
  \fi%
}
% ----- the old pst@pyth end -----
%
%------ new version \pst@divide ̣-------- by Michael Sharpe
\def\pst@divide#1#2#3{%
  \pst@@divide{#1}{#2}%
  \advance\pst@dimg \pst@cnta pt%
  \pst@dimtonum\pst@dimg{#3}%
}
\def\pst@@divide#1#2{%
  \pst@dimg=#1\relax%
  \pst@dimh=#2\relax%
  \pst@cnth=\pst@dimh%
  \pst@cntg=\pst@dimg%
  \pst@cnta=\pst@cntg%
  \divide\pst@cnta\pst@cnth%
  \advance\pst@dimg -\pst@cnta\pst@dimh%
  \pst@cntm=67108863\relax %2^26 -1
  \pst@@@divide\pst@@@divide\pst@@@divide\pst@@@divide%
  \divide\pst@dimg\pst@cnth%
}%
\def\pst@@@divide{%
  \ifnum%
    \ifnum\pst@dimg<\z@-\fi\pst@dimg<\pst@cntm%
      \multiply\pst@dimg\sixt@@n%
  \else%
    \divide\pst@cnth\sixt@@n%
  \fi%
}%
%
%-------------- the old version ----------
\iffalse
\def\pst@divide#1#2#3{%
  \pst@@divide{#1}{#2}%
  \pst@dimtonum\pst@dimg{#3}%
}
\def\pst@@divide#1#2{%
  \pst@dimg=#1\relax
  \pst@dimh=#2\relax
  \pst@cntg=\pst@dimh
  \pst@cnth=67108863
  \pst@@@divide\pst@@@divide\pst@@@divide\pst@@@divide
  \divide\pst@dimg\pst@cntg%
}
\def\pst@@@divide{%
  \ifnum
    \ifnum\pst@dimg<\z@-\fi\pst@dimg<\pst@cnth
      \multiply\pst@dimg\sixt@@n
    \else
      \divide\pst@cntg\sixt@@n
    \fi%
}
\fi
%-------------- end old vesrion ---------------
%
\def\pst@configerr#1{\@pstrickserr{\string#1 not defined in pstricks.con}\@ehpc}
%
\def\pstVerb#1{\pst@configerr\pstVerb}
\def\pstverb#1{\pst@configerr\pstverb}
\def\pstverbscale{\pst@configerr\pstverbscale}
\def\pstrotate{\pst@configerr\pstrotate}
\def\pstheader#1{\pst@configerr\pstheader}
\def\pstdriver{\pst@configerr\pstdriver}
\@ifundefined{pstcustomize}%
  {\def\pstcustomize{\endinput\let\pstcustomize\relax}}{}
%
\input pstricks.con		% local config file
%
\newif\ifPSTricks
\PSTrickstrue
\def\PSTricksOff{%
  \def\pstheader##1{}%
  \def\pstverb##1{}%
  \def\pstVerb##1{}%
  \PSTricksfalse%
}
\@ifundefined{pst@def}{\def\pst@def#1<#2>{\@namedef{tx@#1}{#2 }}}{}
\@ifundefined{pst@ATH}{\def\pst@ATH<#1>{}}{}
%
\pstheader{pstricks.pro}
\pstheader{pst-algparser.pro}
\pstheader{pst-tools.pro}
%
\def\pst@dict{tx@Dict begin }
\def\pst@theheaders{pstricks.pro, pst-algparser.pro}
\def\pst@Verb#1{\pstVerb{\pst@dict #1 end}}
\def\tx@Atan{Atan }
\def\tx@Div{Div }
\def\tx@NET{NET }
\def\tx@Pyth{Pyth }
\def\tx@PtoC{PtoC }
\def\tx@PathLength@{PathLength@ }
\def\tx@PathLength{PathLength }
\pst@dimg=\pstunit\relax
\ifdim\pst@dimg=1bp
\def\pst@stp{.996264 dup scale}
\else
\edef\pst@stp{1 \pst@@dimtonum\pst@dimg\space div dup scale}
\fi
\def\tx@STP{STP }
\def\tx@STV{STV }
%
%--------------------------------------- PS stuff ---------------------------------
% on stack x y 
\pst@def{UserCoor}< \pst@number\psyunit div exch \pst@number\psxunit div exch >
\pst@def{ScreenCoor}< \pst@number\psyunit mul exch \pst@number\psxunit mul exch >
%--------------------------------------- PS stuff end -----------------------------
%
\def\pst@number#1{\pst@@dimtonum#1\space}
%
%-----------------------% hv 20100413
\def\pst@strip@dot#1{\expandafter\pst@strip@dot@i#1..\@nil}
\def\pst@strip@dot@i#1.#2.#3\@nil{%
  \ifnum1#2>10\relax #1.#2\else#1\fi}
%-----------------------% hv 20100413
\def\pst@checknum#1#2{%
  \edef\ps@next{#1}%
  \ifx\ps@next\@empty\let\pst@num\z@%
  \else\expandafter\pst@@checknum\ps@next..\@nil%
  \fi%
  \ifcase\pst@num%  0
    \@pstrickserr{Bad number: `#1'. 0 substituted.}\@ehpa%
    \def#2{0 }%
  \or%              1
    \edef#2{\ifnum\pst@num=\tw@-\fi\the\pst@cntg.%
      \expandafter\@gobble\the\pst@cnth\space}%
  \or%              2
    \edef#2{\ifnum\pst@num=\tw@-\fi\the\pst@cntg.%
      \expandafter\@gobble\the\pst@cnth\space}%
  \or%              3
    \edef#2{\pst@tempA\space}%
  \fi}
\def\pst@@checknum{%
  \@ifnextchar-%
  {\let\pst@num\tw@\expandafter\pst@@@checknum\@gobble}%
  {\@ifnextchar !%
    {\def\pst@num{3}\pst@@@@@checknum}
    {\let\pst@num\@ne\pst@@@checknum}}%
}
\def\pst@@@checknum#1.#2.#3\@nil{%
\afterassignment\pst@@@@checknum\pst@cntg=0#1\relax\@nil%
\afterassignment\pst@@@@checknum\pst@cnth=1#2\relax\@nil}
\def\pst@@@@checknum#1\relax\@nil{\ifx\@nil#1\@nil\else\let\pst@num\z@\fi}
%
\def\pst@@@@@checknum#1#2.#3\@nil{\def\pst@tempA{#2}}% PostScript Notation with !<code>
%
\def\pst@getnumii#1 #2 #3\@nil{%
  \pst@checknum{#1}\pst@tempg%
  \ifx\relax#2\relax\let\pst@temph\pst@tempg\else\pst@checknum{#2}\pst@temph\fi}
\def\pst@getnumiii#1 #2 #3 #4\@nil{%
\pst@checknum{#1}\pst@tempg%
\pst@checknum{#2}\pst@temph%
\pst@checknum{#3}\pst@tempi}
\def\pst@getnumiv#1 #2 #3 #4 #5\@nil{%
\pst@checknum{#1}\pst@tempg%
\pst@checknum{#2}\pst@temph%
\pst@checknum{#3}\pst@tempi%
\pst@checknum{#4}\pst@tempj}
%
\def\pst@getdimnum#1 #2 #3\@nil{%
  \pssetlength\pst@dimg{#1}%
  \pst@checknum{#2}\pst@tempg%
}
\def\pst@getscale#1#2{%	read and check a scale input x [y]
  \edef\pst@tempg{#1}%
  \ifx\pst@tempg\@none
    \def#2{}%
  \else
    \pst@expandafter\pst@getnumii{#1 #1} {} {} {}\@nil
    \ifdim\pst@tempg\p@=\z@
      \@pstrickserr{Bad scaling argument `#1'}\@ehpa
      \def#2{}%
    \else
      \ifdim\pst@temph\p@=\z@
        \@pstrickserr{Bad scaling argument `#1'}\@ehpa
        \def#2{}%
      \else
        \edef#2{\pst@tempg\space \pst@temph\space scale }%
      \fi
    \fi
  \fi%
}
\def\pst@getint#1#2{%	read and check an integer
  \pst@cntg=#1\relax
  \edef#2{\the\pst@cntg\space}%
}
\begingroup
\catcode`\{=12
\catcode`\}=12
\catcode`\[=1
\catcode`\]=2
\gdef\pslbrace[{ ]
\gdef\psrbrace[} ]
\endgroup

\pstVerb{
  /pssetRGBcolor  /setrgbcolor  load def
  /pssetCMYKcolor /setcmykcolor load def
  /pssetGraycolor /setgray      load def
}
\def\@newcolor#1#2{%
  \expandafter\edef\csname #1\endcsname{\noexpand\pst@color{#2}}%
  %\expandafter\edef\csname color@#1\endcsname{#2}%
  \expandafter\edef\csname\string\color@#1\endcsname{#2}%    hv 1.14 2005-12-17
  \ignorespaces}
\def\pst@color#1{%
  \def\pst@currentcolor{#1}\pstVerb{#1}\aftergroup\pst@endcolor}%
\def\pst@endcolor{\pstVerb{\pst@currentcolor}}
\def\pst@currentcolor{0 setgray}
\def\altcolormode{%
\def\pst@color##1{%
  \pstVerb{gsave ##1}\aftergroup\pst@endcolor}%
\def\pst@endcolor{\pstVerb{\pst@grestore}}}
\def\pssetMonochrome{%
  \pstVerb{
    /setrgbcolor { add add 0 gt {0}{1} ifelse setgray } def 
    /setcmykcolor{ 4 dict begin
      /k ED /y ED /m ED /c ED 
      1 1 k sub c mul k add sub 0.29 mul 
      1 1 k sub m mul k add sub 0.587 mul add 
      1 1 k sub y mul k add sub 0.114 mul add
      end 0 gt {0}{1} ifelse setgray } def }}
\def\pssetGrayscale{%
  \pstVerb{
    /setrgbcolor { 0.07 mul exch 0.71 mul add exch 0.21 mul add setgray } def 
    /setcmykcolor{ 4 dict begin
      /k ED /y ED /m ED /c ED 
      1 1 k sub c mul k add sub 0.29 mul 
      1 1 k sub m mul k add sub 0.587 mul add 
      1 1 k sub y mul k add sub 0.114 mul add
      end setgray } def }}
\def\psresetColor{\pstVerb{
    /setrgbcolor  tx@Dict begin /pssetRGBcolor  load end def 
    /setcmykcolor tx@Dict begin /pssetCMYKcolor load end def }}

\def\pst@grestore{
  currentpoint
  matrix currentmatrix
  currentfont
  grestore
  setfont
  setmatrix
  moveto
}
%\def\pst@usecolor#1{\csname color@#1\endcsname\space}%    hv 1.14  2005--12-17
\def\pst@usecolor#1{\csname\string\color@#1\endcsname\space}
%
\def\newgray#1#2{%
  \pst@checknum{#2}\pst@tempg
  \@newcolor{#1}{\pst@tempg setgray}}
\def\newrgbcolor#1#2{%
  \pst@expandafter\pst@getnumiii{#2} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi setrgbcolor}}
\def\newhsbcolor#1#2{%
  \pst@expandafter\pst@getnumiii{#2} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi sethsbcolor}}
\def\newcmykcolor#1#2{%
  \pst@expandafter\pst@getnumiv{#2} {} {} {} {} {}\@nil
  \@newcolor{#1}{\pst@tempg \pst@temph \pst@tempi \pst@tempj setcmykcolor}}
\newgray{black}{0}
\newgray{darkgray}{.25}
\newgray{gray}{.5}
\newgray{lightgray}{.75}
\newgray{white}{1}
\newrgbcolor{red}{1 0 0}
\newrgbcolor{green}{0 1 0}
\newrgbcolor{blue}{0 0 1}
\newrgbcolor{yellow}{1 1 0}
\newrgbcolor{cyan}{0 1 1}
\newrgbcolor{magenta}{1 0 1}
%
\define@key[psset]{pstricks}{bgcolor}{\def\pst@bgcolor{#1}}% background for pspicture
\psset[pstricks]{bgcolor={}}% \pst@bgcolor is \@empty

\define@key[psset]{pstricks}{style}{%
  \@ifundefined{pscs@#1}%
    {\@pstrickserr{Custom style `#1' undefined}\@ehpa}%
    {\@nameuse{pscs@#1}}%
}
\def\newpsstyle#1#2{\@namedef{pscs@#1}{%
  \def\pst@tempA{#2}%
  \ifx\pst@tempA\@empty\else\psset{#2}\fi}%
}
\def\addto@psstyle#1#2{%
    \pst@toks=\expandafter{#1#2}%
    \edef#1{\the\pst@toks}}
\def\addtopsstyle#1#2{%
  \def\pst@tempA{#2}%
  \ifx\pst@tempA\@empty\else
    \@ifundefined{pscs@#1}%
      {\newpsstyle{#1}{#2}}%
      {\expandafter\addto@psstyle\csname pscs@#1\endcsname{\psset{#2}}}%
  \fi}
%------------ hv 1.16 end -------------------
%
\def\@none{none}
\def\pst@getcolor#1#2{%
%  \@ifundefined{color@#1}%	hv 1.14  2005-12-17
  \@ifundefined{\string\color@#1}%
    {\@pstrickserr{Color `#1' not defined}\@eha}%
    {\edef#2{#1}}%
}
\newdimen\psunit \psunit 1cm
\newdimen\psxunit \psxunit 1cm
\newdimen\psyunit \psyunit 1cm
\let\psrunit\psunit
%
\def\pstunit@off{\let\@psunit\ignorespaces\ignorespaces}
%
\def\pssetlength#1#2{%
  \let\@psunit\psunit
  \afterassignment\pstunit@off
  #1 #2\@psunit%
}
\def\psaddtolength#1#2{%
  \let\@psunit\psunit
  \afterassignment\pstunit@off
  \advance#1 #2\@psunit%
}
\def\pssetxlength#1#2{%
  \let\@psunit\psxunit
  \afterassignment\pstunit@off
  #1 #2\@psunit%
}
\def\pssetylength#1#2{%
  \let\@psunit\psyunit
  \afterassignment\pstunit@off
  #1 #2\@psunit%
}
\define@key[psset]{pstricks}{unit}[1cm]{%
  \pssetlength\psunit{#1}%
  \psxunit=\psunit%
  \psyunit=\psunit%
}
\define@key[psset]{pstricks}{runit}[1cm]{\pssetlength\psrunit{#1}}
\define@key[psset]{pstricks}{xunit}[1cm]{\pssetxlength\psxunit{#1}}
\define@key[psset]{pstricks}{yunit}[1cm]{\pssetylength\psyunit{#1}}
%
\define@key[psset]{pstricks}{PstDebug}[0]{\pst@getint{#1}\Pst@Debug}% hv 2004-06-22
\psset[pstricks]{PstDebug=0}
\def\psDEBUG{\@ifnextchar[\psDEBUG@i{\psDEBUG@i[PSTricks]}}%
\def\psDEBUG@i[#1]#2{\ifnum\Pst@Debug>0 \expandafter\typeout{<#1>: #2}\fi}%
%
\def\pst@getlength#1#2{%
  \pssetlength\pst@dimg{#1}%
  \edef#2{\pst@number\pst@dimg}%
}
\def\pst@@getlength#1#2{%
  \pssetlength\pst@dimg{#1}%
  \edef#2{\number\pst@dimg sp}%
}
\def\pst@getcoor#1#2{\pst@@getcoor{#1}\let#2\pst@coor}
\def\pst@coor{0 0 }
%
\def\pst@getcoors#1#2{%
  \def\pst@aftercoors{\addto@pscode{#1 \pst@coors }#2}%
  \def\pst@coors{}%
  \pst@@getcoors%
}
\def\pst@@getcoors(#1){%
  \pst@@getcoor{#1}%
  \edef\pst@coors{\pst@coor\pst@coors}%
  \@ifnextchar({\pst@@getcoors}{\pst@aftercoors}%
}
%
\newcount\pst@C@@rType% 0: default cartesian coordinates and angles
%
\def\pst@getangle#1#2{\pst@@getangle{#1}\let#2\pst@angle}
\def\pst@angle{0 }
%
\def\cartesian@coor#1,#2,#3\@nil{%
  \pssetxlength\pst@dimg{#1}%
  \pssetylength\pst@dimh{#2}%
  \edef\pst@coor{\pst@number\pst@dimg \pst@number\pst@dimh}%
}
\def\NormalCoor{%
  \def\pst@@getcoor##1{\pst@expandafter\cartesian@coor{##1},\relax,\@nil}%
  \def\pstCheckCoorType##1{\global\pst@C@@rType=0}%
  \Pst@SpecialLengthfalse
  \def\pssetlength##1##2{%
    \let\@psunit\psunit
    \afterassignment\pstunit@off
    ##1 ##2\@psunit%
  }%
  \def\pst@@getangle##1{%
    \pst@checknum{##1}\pst@angle%
    \edef\pst@angle{\pst@angle \pst@angleunit}%
  }%
  \def\psput@##1{\pst@@getcoor{##1}\leavevmode\psput@cartesian}%
}
%\NormalCoor% set to normal read of coors, angles and lengths
%
\def\degrees{\@ifnextchar[{\@degrees}{\def\pst@angleunit{}}}
\def\@degrees[#1]{%
  \pst@checknum{#1}\pst@tempg
  \edef\pst@angleunit{360 \pst@tempg div mul }%
  \ignorespaces}
%
\def\radians{\def\pst@angleunit{57.2956 mul }}
\def\pst@angleunit{}
%
\def\SpecialCoor{%
  \def\pst@@getcoor##1{%
    \begingroup%
      \pst@activecoor%
      \xdef\pst@tempg{##1}%
    \endgroup%
    \expandafter\special@coor\pst@tempg||\@nil}%
  \def\pstCheckCoorType##1{%
    \begingroup%
      \pst@activecoor%
      \xdef\pst@tempg{##1}%
    \endgroup
    \psDEBUG[pstCheckCoorType]{:Checking coor \pst@tempg:}%
    \expandafter\pst@CheckCoorType\pst@tempg||\@nil%
    \psDEBUG[pstCheckCoorType]{::Coor type=\the\pst@C@@rType::}%
  }%
  \def\pssetlength##1##2{%
    \begingroup%
      \pst@activecoor%
      \xdef\pst@tempg{##2}%
    \endgroup%
    \expandafter\special@length\pst@tempg\@nil{##1}%
  \ignorespaces}%
  \def\pst@@getangle##1{%
    \begingroup%
      \pst@activecoor%
      \xdef\pst@tempg{##1}%
    \endgroup%
    \expandafter\special@angle\pst@tempg\@empty)\@nil%
  }%
  \def\psput@##1{\pst@@getcoor{##1}\leavevmode\psput@special}%
}
\SpecialCoor% set to special read of coors, angles and lengths
%
\define@key[psset]{}{precode}{\def\pst@prepscode{#1 }}
\define@key[psset]{}{postcode}{\def\pst@postpscode{#1 }}
\psset{precode={},postcode={}}% For use in other packages
%
%
\begingroup
\catcode`\|=13
\catcode`\;=13
\catcode`\!=13
\catcode`\*=13
\catcode`\>=13
\catcode`\+=13
\gdef\pst@activecoor{%
  \def|{\string|}%
  \def;{\string;}%
  \def!{\string!}%
  \def*{\string*}%			algebraic expression hv 2007-11-17
  \def>{\string>}%
  \def+{\string+}%			pure algebaric 2013-04-23
}
\endgroup
% \pst@C@@rType = 0 cartesian (x,y)
%               = 1 polar     (r;phi)
%               = 2 PS        (! x y)
%               = 3 mixed     ((x,y)|(x,y))
%               = 4 algebraic (*x f(x))   x in PostScript notation
%               = 5 node      (A)
%               = 6 special node ([...]A)
%               = 7 node      (>A)
%               = 8 algebraic (+x,f(x))   _both_ algebraic
\def\pst@CheckCoorType#1|#2|#3\@nil{%
  \ifx#3|\relax 
    \global\pst@C@@rType=3\relax
  \else 
    \expandafter\pst@@CheckCoorType#1;;\@nil%
  \fi}
%
\def\pst@@CheckCoorType#1#2;#3;#4\@nil{%
%\typeout{====1:#1}%
%\typeout{====2:#2}%
%\typeout{====3:#3}%
%\typeout{====4:#4}%
  \ifx#1>\relax%			node with special rotation for \uput
    \global\pst@C@@rType=7\relax%
  \else
    \ifcat#1a\relax%			node names should start with a letter
      \global\pst@C@@rType=5\relax%
    \else
      \ifx#1[\relax%			special node coor: [..]A
        \global\pst@C@@rType=6\relax%
      \else
        \ifx#1!\relax%			PostScript code: x y
          \global\pst@C@@rType=2\relax%
        \else
          \ifx#1*\relax%			algebraic PostScript code: x f(x)
            \global\pst@C@@rType=4\relax%
          \else
            \ifx#1+\relax%			algebraic algebraic: x, f(x)
              \global\pst@C@@rType=8\relax%
  	    \else
              \ifx#4;\relax%		polar coordinates
                \global\pst@C@@rType=1\relax%
              \else
                \global\pst@C@@rType=0\relax%
              \fi
            \fi
          \fi
	\fi
      \fi
    \fi
  \fi
  \psDEBUG[pstCheckCoorType]{::\the\pst@C@@rType::}%
  }%
%
%
\def\special@coor#1|#2|#3\@nil{%
  \ifx#3|\relax
    \mixed@coor{#1}{#2}%
  \else
    \special@@coor#1;;\@nil%
  \fi}
%
\def\special@@coor#1{%
  \ifcat#1a\relax%			node names should start with a letter
    \def\ps@next{\node@coor#1}%
  \else
    \ifx#1[\relax%			special node coor: [..]A
      \def\ps@next{\Node@coor[}%
    \else
      \ifx#1>\relax%			PostScript code: x y
        \def\ps@next{\special@@@@coor}%
    \else
      \ifx#1!\relax%			PostScript code: x y
        \def\ps@next{\raw@coor}%
      \else
        \ifx#1*\relax%			PostScript/algebraic code: x f(x)
          \def\ps@next{\alg@coor}%
        \else
          \ifx#1+\relax%		algebraic code: x,f(x)
            \def\ps@next{\algalg@coor}%
	  \else%
            \def\ps@next{\special@@@coor#1}%
          \fi%
	\fi%
      \fi%
    \fi\fi%
  \fi%
  \ps@next%
}
\def\special@@@coor#1;#2;#3\@nil{%
  \ifx#3;\relax
    \polar@coor{#1}{#2}%
  \else
    \cartesian@coor#1,\relax,\@nil
  \fi%
}
\def\special@@@@coor#1#2;#3;#4\@nil{%
  \def\ps@A{A}\def\ps@B{#1}%
  \ifcat\ps@A\ps@B\relax%
    \node@coor#1#2;;\@nil%
  \else%
    \cartesian@coor#1#2,\relax,\@nil
  \fi%
}
\def\mixed@coor#1#2{%
  \begingroup%
% DG/SR modification begin - Oct. 27, 1997 - Patch 6
%\specialcoor@ii#1;;\@nil
%\let\pst@tempa\pst@coor
%\specialcoor@ii#2;;\@nil
    \special@@coor#1;;\@nil%
    \let\pst@tempa\pst@coor%
    \special@@coor#2;;\@nil%
% DG/SR modification end
    \xdef\pst@tempg{\pst@tempa pop \pst@coor exch pop }%
  \endgroup%
  \let\pst@coor\pst@tempg%
}
%
\def\polar@coor#1#2{%
%  \pssetlength\pst@dimg{#1}%
  \pssetlength\pst@dimb{#1}%	hv 2007-10-16  g is already used in get@@angle
  \pst@@getangle{#2}%
%  \edef\pst@coor{\pst@number\pst@dimg \pst@angle \tx@PtoC}%  dito
  \edef\pst@coor{\pst@number\pst@dimb \pst@angle \tx@PtoC }%
}
%
\def\raw@coor{\@ifnextchar !\raw@@coor\raw@@@coor}
\def\raw@@coor!#1;#2\@nil{%		PostScript code without using \tx@ScreenCoor 
  \edef\pst@coor{#1 }}
\def\raw@@@coor#1;#2\@nil{%		PostScript code 
  \edef\pst@coor{ #1 \tx@ScreenCoor }}
%
\def\alg@coor{\@ifnextchar*{\alg@@coor}{\alg@@@@coor}}
\def\alg@@coor*#1;#2\@nil{\expandafter\alg@@@coor#1\@nil}
\def\alg@@@coor#1 #2\@nil{%			algebraic PostScript code 
%\typeout{Nummer1: #1}%
%\typeout{Nummer2: #2}%
  \edef\pst@coor{%
    /Func (#1) AlgParser cvx def    
    /y #2 def
    y Func exch \tx@ScreenCoor }}
%
\def\alg@@@@coor#1;#2\@nil{\expandafter\alg@@@@@coor#1\@nil}
\def\alg@@@@@coor#1 #2\@nil{%			algebraic PostScript code 
  \edef\pst@coor{%
    /x #1 def
    /Func (#2) AlgParser cvx def 
    x Func \tx@ScreenCoor }}
%
\define@boolkey[psset]{}[Pst@]{exchange}[true]{}
\psset{exchange=false}
%
\def\algalg@coor#1;#2\@nil{\expandafter\algalg@@@coor#1\@nil}
\def\algalg@@@coor#1,#2\@nil{%			algebraic algebraic code 
  \edef\pst@coor{%
    /x (#1) AlgParser cvx def    
    /Func (#2) AlgParser cvx def    
    x Func \tx@ScreenCoor  }}
%
\def\node@coor#1\@nil{%
  \@pstrickserr{You must load `pst-node.tex' to use node coordinates.}\@ehps
  \def\pst@coor{0 0 }%
}
\def\Node@coor{\node@coor}
%
\def\special@angle#1#2)#3\@nil{%
  \ifx !#1\relax
    \edef\pst@angle{#2\space \pst@angleunit}%
  \else\ifx(#1\relax
    \pst@@getcoor{#2}%
    \edef\pst@angle{\pst@coor exch \tx@Atan}%
  \else
    \pst@checknum{#1#2}\pst@angle
    \edef\pst@angle{\pst@angle \pst@angleunit}%
  \fi\fi}
%
\def\special@length#1#2\@nil#3{%
  \psDEBUG[special@length]{ #1|#2|#3 }%
  \ifx !#1\relax
    \edef\pst@SpecialLength{ #2 \pst@number\psunit mul }%
    \Pst@SpecialLengthtrue%
    \psDEBUG[special@length]{ Special length: \pst@SpecialLength}%
  \else
    \let\@psunit\psunit
    \afterassignment\pstunit@off
    #3 #1#2\@psunit%
    \Pst@SpecialLengthfalse%
  \psDEBUG[special@length]{ Normal length: \the#3 }%
  \fi}
%
\def\Cartesian{%
  \def\cartesian@coor##1,##2,##3\@nil{%
    \pssetxlength\pst@dimg{##1}%
    \pssetylength\pst@dimh{##2}%
    \edef\pst@coor{\pst@number\pst@dimg \pst@number\pst@dimh}%
  }%
  \@ifnextchar({\Cartesian@}{}%
}
\def\Cartesian@(#1,#2){%
  \pssetxlength\psxunit{#1}%
  \pssetylength\psyunit{#2}%
  \ignorespaces%
}
\def\Polar{%
  \def\psput@cartesian{\psput@special}%
  \def\cartesian@coor##1,##2,##3\@nil{\polar@coor{##1}{##2}}%
}%
\define@key[psset]{pstricks}{origin}[]{%
  \pst@@getcoor{#1}%
  \edef\psk@origin{\pst@coor T }}
\def\psk@origin{}
%
\define@boolkey[psset]{pstricks}[Pst@]{algebraic}[true]{}
\psset%[pstricks]
{algebraic=false}
%
\define@boolkey[psset]{pstricks}[]{swapaxes}[true]{%			\if@pst
  \@nameuse{@pst#1}%
  \if@pst\def\psk@swapaxes{-90 rotate -1 1 scale }%
  \else\def\psk@swapaxes{}%
  \fi}
\psset[pstricks]{swapaxes=false}
%
\define@boolkey[psset]{pstricks}[]{showpoints}[true]{}
\psset[pstricks]{showpoints=false}
%
\let\pst@setrepeatarrowsflag\relax
%
\define@key[psset]{pstricks}{border}[0pt]{\pst@getlength{#1}\psk@border \pst@setrepeatarrowsflag}
\psset[pstricks]{border=0pt}
\define@key[psset]{pstricks}{bordercolor}[white]{\pst@getcolor{#1}\psbordercolor}
\psset[pstricks]{bordercolor=white}
\define@boolkey[psset]{pstricks}[ps]{doubleline}[true]{\pst@setrepeatarrowsflag}
\psset[pstricks]{doubleline=false}
\define@key[psset]{pstricks}{doublesep}[1.25\pslinewidth]{\def\psdoublesep{#1}}
\psset[pstricks]{doublesep=1.25\pslinewidth}
\define@key[psset]{pstricks}{doublecolor}[white]{\pst@getcolor{#1}\psdoublecolor}
\psset[pstricks]{doublecolor=white}
%
\define@boolkey[psset]{pstricks}[ps]{shadow}[true]{\pst@setrepeatarrowsflag}
\psset[pstricks]{shadow=false}
\define@key[psset]{pstricks}{shadowsize}[3pt]{\pst@getlength{#1}\psk@shadowsize}
\psset[pstricks]{shadowsize=3pt}
\define@key[psset]{pstricks}{shadowangle}[-45]{\pst@getangle{#1}\psk@shadowangle}
\psset[pstricks]{shadowangle=-45}
\define@key[psset]{pstricks}{shadowcolor}[darkgrey]{\pst@getcolor{#1}\psshadowcolor}
\psset[pstricks]{shadowcolor=darkgray}
%
\def\pst@repeatarrowsflag{\z@}
\def\pst@setrepeatarrowsflag{%
  \edef\pst@repeatarrowsflag{%
    \ifdim\psk@border\p@>\z@ 1\else\ifpsdoubleline 1\else
      \ifpsshadow 1\else \z@\fi\fi\fi}}
%
\def\psls@none{}
\def\psls@solid{ \psk@linejoin\space setlinejoin \psk@linecap\space setlinecap stroke }
\def\psls@coloreddashed{ \psls@solid grestore gsave \pst@usecolor\psdashcolor \tx@setlinejoin \psls@dashed }
%
\newdimen\pslinewidth
\define@key[psset]{pstricks}{linewidth}[0.8pt]{\pssetlength\pslinewidth{#1}}
\psset[pstricks]{linewidth=.8pt}
\define@key[psset]{pstricks}{linecolor}[black]{\pst@getcolor{#1}\pslinecolor}
\psset[pstricks]{linecolor=black}
\define@key[psset]{pstricks}{kitecolor}[red]{\pst@getcolor{#1}\ps@kitecolor}
\define@key[psset]{pstricks}{dartcolor}[blue]{\pst@getcolor{#1}\ps@dartcolor}
\psset[pstricks]{kitecolor,dartcolor}
%
\newif\ifPst@coloreddashed
\define@key[psset]{pstricks}{dashcolor}[white]{%
  \ifx\relax#1\relax\Pst@coloreddashedfalse%
  \else\Pst@coloreddashedtrue\pst@getcolor{#1}\psdashcolor
  \fi}
\psset{dashcolor=\relax}
%\define@key[psset]{pstricks}{linecap}[0]{\pst@getint{#1}\psk@linecap}%	hv 2007-12-01
%\psset[pstricks]{linecap=0}  >>>>>>>>>>>>> siehe unten
\define@key[psset]{pstricks}{linejoin}[0]{\pst@getint{#1}\psk@linejoin}%	hv 2007-10-13
\psset[pstricks]{linejoin=0}
\def\tx@setlinejoin{\psk@linejoin\space setlinejoin }%	hv 2007-10-13
%
\def\pst@missing{%
  \z@
  \@pstrickserr{Missing number or dimension. 0 substituted}\@ehpa}
%
%%------------------- begin patch 15 HV 2004-05-15 -------------
\def\pst@empty{\z@}

\define@key[psset]{pstricks}{dash}[5pt 3pt 0pt 0pt]{%	defined in pstricks.tex
  \pst@expandafter\psset@@dash{#1}\@nil}% Error handling for empty argument.
\define@key[psset]{pstricks}{maxdashes}[11]{\def\psk@maxdashes{#1}}
\psset[pstricks]{maxdashes=11}
%
\def\psset@@dash#1\@nil{%
 \def\psk@dash{}%
 \pst@cntm0
 \def\next##1 ##2\relax{%
   \expandafter\ifnum\psk@maxdashes>\pst@cntm\relax  % 04-08-07
     \edef\@tempa{##1}%
     \ifx\@tempa\@empty\else% gobble leading spaces
       \pssetlength\pst@dimc{##1}%
       \advance\pst@cntm by 1
       \edef\psk@dash{\psk@dash\space\pst@number\pst@dimc}%
     \fi%
     \edef\@tempa{##2}%
     \ifx\@tempa\@empty\else% detect end
       \ifx\@tempa\space\else% gobble trailing spaces
         \next##2\relax%
     \fi\fi%
   \else% 04-08-07
     \@pstrickserr{Number of dashes > \psk@maxdashes. Increasing 
        'maxdashes' might work.}\@ehpa% 04-08-07
   \fi% 04-08-07
 }%
 \expandafter\next#1 \relax}
\psset[pstricks]{dash=5pt 3pt 0pt 0pt}% black white black white 
%%------------------- end patch 15 HV 2004-05-15 -------------
\define@boolkey[psset]{pstricks}[ps]{dashadjust}[true]{}
\psset[pstricks]{dashadjust}
\def\tx@DashLine{DashLine }
%
\def\psls@dashed{
  \ifPst@coloreddashed \psls@solid grestore gsave \pst@usecolor\psdashcolor \tx@setlinejoin \fi
  \psk@linecap\space setlinecap 
  \ifpsdashadjust
    [ \psk@dash ] \pst@linetype\space \tx@DashLine
  \else
    [ \psk@dash ] 0 setdash stroke
  \fi}
%% End patch TN; Date (YY-MM-DD): 04-07-17; 2nd part
%
\define@key[psset]{pstricks}{dotsep}[3pt]{\pst@getlength{#1}\psk@dotsep}
\psset[pstricks]{dotsep=3pt}
\def\tx@DotLine{DotLine }
\def\psls@dotted{
  \ifpsdashadjust
    \psk@dotsep \pst@linetype\space \tx@DotLine
  \else
    [ 0 \psk@dotsep CLW add ] 0 setdash 1 setlinecap stroke
  \fi
}
%
\define@key[psset]{pstricks}{linestyle}[solid]{%
  \@ifundefined{psls@#1}%
    {\@pstrickserr{Line style `#1' not defined}\@eha}%
    {\def\pslinestyle{#1}}}
\psset[pstricks]{linestyle=solid}
%
\define@key[psset]{pstricks}{linecap}[0]{%
  \def\psk@linecap{0}%
  \ifnum#1>-1
    \ifnum#1<3
      \pst@getint{#1}\psk@linecap%
  \fi\fi}
\psset{linecap=0}
%------------------------- Transparency modes ----------------------------
\pst@def{setTransparency}< \psk@opacityalpha .setopacityalpha >
\pst@def{setStrokeTransparency}< \psk@strokeopacityalpha .setopacityalpha >
\pst@def{setBlendmode}<
    \ifcase\psk@blendmode
      /Normal \or
      /Compatible \or
      /Screen \or
      /Multiply \or
      /HardLight \or
      /Darken \or
      /Lighten \or
      /Difference\or
      /ColorDodge\or
      /ColorBurn\or
      /SoftLight\or
      /Hue\or
      /Saturation\or
      /Luminosity\or
      /Overlay\or
      /Exclusion\or
      /Color
    \else
      /Normal 
    \fi
    .setblendmode \psk@shapealpha .setshapealpha >
%
%--------------------------------- hv 2007-09-09 begin ---------------------
% transparency needs a run through latex -> dvips -> ps2pdf14(!) 
%
\def\e@fill@inverse{oefill}
\define@key[psset]{pstricks}{fillcolor}[white]{%
  \ifx\psk@fillstylename\e@fill@inverse
    \pst@getcolor{#1}\psk@oefillcolor
    \pst@getcolor{white}\psfillcolor
  \else \pst@getcolor{white}\psk@oefillcolor
        \pst@getcolor{#1}\psfillcolor
  \fi}

\psset[pstricks]{fillcolor=white}
\define@key[psset]{pstricks}{strokeopacity}[1]{\pst@checknum{#1}\psk@strokeopacityalpha }% for lines
\psset[pstricks]{strokeopacity=1}
\define@key[psset]{pstricks}{opacity}[1]{\pst@checknum{#1}\psk@opacityalpha }% for filled areas 
\psset[pstricks]{opacity=1}
\define@key[psset]{pstricks}{shapealpha}[0.6]{\pst@checknum{#1}\psk@shapealpha }
\psset[pstricks]{shapealpha=0.6}
\define@key[psset]{pstricks}{blendmode}[0]{\pst@getint{#1}\psk@blendmode }% must be one of 
% /Normal     0
% /Compatible 1
% /Screen     2
% /Multiply   3
% /HardLight  4
\psset[pstricks]{blendmode=0}
\define@key[psset]{pstricks}{fsAngle}[137.50775]{\pst@getangle{#1}\pst@fsAngle }
\define@key[psset]{pstricks}{fsOrigin}[(0,0)]{%
  \pst@@getcoor{#1}\edef\pst@fsOrigin{\pst@coor T }}
\psset[pstricks]{fsOrigin={0,0},fsAngle=137.50775}
%
\def\tx@LineFill{LineFill }
\def\tx@DotFill{DotFill }
\def\tx@PenroseFill{PenroseFill }
\def\tx@PenroseFillA{PenroseFillA }
\def\tx@TruchetFill{TruchetFill }
%
\def\psfs@none{}
\def\psfs@solid{\pst@fill{\pst@usecolor\psfillcolor \tx@setTransparency fill }}
\def\psfs@eofill{\pst@fill{\pst@usecolor\psfillcolor \tx@setTransparency eofill}}
\def\psfs@oefill{\pst@fill{\pst@usecolor\psk@oefillcolor  \tx@setTransparency fill } \psfs@eofill }
\def\psfs@shape{\pst@fill{\pst@usecolor\psfillcolor \tx@setBlendmode fill }}
\def\psfs@spiral{\pst@fill{\pst@fsOrigin \pst@usecolor\psfillcolor clip newpath
    0 .1 500 { dup dup sqrt 4 div 0 360 arc fill \pst@fsAngle rotate } for }}
%
\define@key[psset]{pstricks}{hatchwidth}[0.8pt]{\pst@getlength{#1}\psk@hatchwidth}
\psset[pstricks]{hatchwidth=.8pt}
\define@key[psset]{pstricks}{hatchsep}[4pt]{\pst@getlength{#1}\psk@hatchsep}
\psset[pstricks]{hatchsep=4pt}
\define@key[psset]{pstricks}{hatchcolor}[black]{\pst@getcolor{#1}\pshatchcolor}
\psset[pstricks]{hatchcolor=black}
\define@key[psset]{pstricks}{hatchangle}[45]{\pst@getangle{#1}\psk@hatchangle}
\psset[pstricks]{hatchangle=45}
\define@key[psset]{pstricks}{hatchsepinc}[0pt]{\pst@getlength{#1}\psk@hatchsepinc}
\define@key[psset]{pstricks}{hatchwidthinc}[0pt]{\pst@getlength{#1}\psk@hatchwidthinc}
\psset[pstricks]{hatchwidthinc=0pt,hatchsepinc=0pt}
%
\def\pst@linefill#1{
  /clipType { \ifx\relax#1\relax clip \else#1\fi} def 
  \psk@hatchangle rotate
  \psk@hatchwidth SLW
  \pst@usecolor\pshatchcolor
  \psk@hatchsep 
  \psk@hatchsepinc
  \psk@hatchwidthinc
  \tx@LineFill }
%
\def\psfs@vlines{\pst@fill{\pst@linefill{}}}
\def\psfs@eovlines{\pst@fill{\pst@linefill{eoclip}}}
\@namedef{psfs@vlines*}{\psfs@solid \psfs@vlines}
\@namedef{psfs@eovlines*}{\psfs@eofill \psfs@eovlines}
\def\psfs@hlines{\pst@fill{90 rotate \pst@linefill{}}}
\def\psfs@eohlines{\pst@fill{90 rotate \pst@linefill{eoclip}}}
\@namedef{psfs@hlines*}{\psfs@solid \psfs@hlines}
\@namedef{psfs@eohlines*}{\psfs@eofill \psfs@eohlines}
\def\psfs@crosshatch{\psfs@vlines \psfs@hlines}
\@namedef{psfs@crosshatch*}{\psfs@solid \psfs@vlines \psfs@hlines}
\@namedef{psfs@eocrosshatch*}{\psfs@eofill \psfs@eovlines \psfs@eohlines}
%
\define@key[psset]{pstricks}{psscale}[1]{%
  \def\psk@@psscale{#1}%   for use with \psscalebox
  \pst@checknum{#1}\psk@psscale}
\psset[pstricks]{psscale=1}
%
\def\pst@dotFill[#1]{%
  /clipType { \ifx\relax#1\relax clip \else #1 \fi } def 
  gsave
  \pst@number\pslinewidth SLW
  \pst@usecolor\pshatchcolor
%  /DotLineColor { \pst@usecolor\pslinecolor } def
  \psk@hatchsep 
  \psk@hatchwidth
  \tx@DotFill }

\def\psfs@dots{\pst@fill{ /SolidDot false def \pst@dotFill[] }}
\def\psfs@eodots{\pst@fill{ /SolidDot false def \pst@dotFill[eoclip] }}
\@namedef{psfs@dots*}{\pst@fill{ /SolidDot true def \pst@dotFill[] }}
\@namedef{psfs@eodots*}{\pst@fill{ /SolidDot true def \pst@dotFill[eoclip] }}
%
\def\pst@penroseFill{%
%  gsave					% restore in PenroseFill
  \pst@number\pslinewidth SLW
  \pst@usecolor\pshatchcolor
  \psk@psscale 
  \tx@PenroseFill }
\def\psfs@penrose{\pst@fill\pst@penroseFill}
\@namedef{psfs@penrose*}{\psfs@solid \psfs@penrose}
%
\def\pst@penroseFillA{%
%  gsave					% restore in PenroseFillA
  \pst@number\pslinewidth SLW
%  \pst@usecolor\pshatchcolor
%  on stack: scaling factor, border color, kite color, dart color
%  dup dup scale
%  /border_colour ED % 
%  /kite_colour ED %
%  /dart_colour 
  { \pst@usecolor\ps@dartcolor }
  { \pst@usecolor\ps@kitecolor }
  { \pst@usecolor\pshatchcolor }
  \psk@psscale 
  \tx@PenroseFillA }
\def\psfs@penroseA{\pst@fill\pst@penroseFillA}
\@namedef{psfs@penroseA*}{\psfs@solid \psfs@penroseA}
%
\def\pst@truchetFill{%
  gsave					% restore in PenroseFill
  \pst@number\pslinewidth SLW
  \pst@usecolor\pshatchcolor
  \psk@psscale 
  \tx@TruchetFill }
\def\psfs@truchet{ \pst@fill\pst@truchetFill }
\@namedef{psfs@truchet*}{\psfs@solid \psfs@truchet}
%
\define@key[psset]{pstricks}{fillstyle}[none]{%
  \def\psk@fillstylename{#1}%  needed for inverse eofill
  \edef\pst@tempg{#1}\def\pst@temph{none}%
  \ifx\pst@tempg\pst@temph
     \let\psk@fillstyle\relax
  \else
    \@ifundefined{psfs@#1}%
    {\@pstrickserr{Undefined fill style: `#1'}\@eha}%
    {\edef\psk@fillstyle{\expandafter\noexpand\csname psfs@#1\endcsname}}%
  \fi%
}
\define@key[psset]{pstricks}{addfillstyle}[]{%
  \@ifundefined{psfs@#1}%
    {\@pstrickserr{Undefined fill style: `#1'}\@eha}%
    {\edef\psk@fillstyle{%
      \expandafter\noexpand\psk@fillstyle
      \expandafter\noexpand\csname psfs@#1\endcsname}%
    }}
\psset[pstricks]{fillstyle=none}
%
%--------------------------- continous linewidth -------------------
\newdimen\psk@startLW
\newdimen\psk@endLW
\define@key[psset]{pstricks}{startLW}[\pslinewidth]{\pssetlength{\psk@startLW}{#1}}%
\define@key[psset]{pstricks}{endLW}[\pslinewidth]{\pssetlength{\psk@endLW}{#1}}%
\define@key[psset]{pstricks}{startWL}[380]{\pst@getint{#1}\psk@startWL}%
\define@key[psset]{pstricks}{endWL}[780]{\pst@getint{#1}\psk@endWL}%
\define@boolkey[psset]{pstricks}[Pst@]{variableLW}[true]{}
\define@boolkey[psset]{pstricks}[Pst@]{variableColor}[true]{}
\define@key[psset]{pstricks}{setflat}[0.1]{\pst@checknum{#1}\psk@setflat}%
\psset[pstricks]{startLW=\pslinewidth,endLW=\pslinewidth,variableColor=false,
  variableLW=false,startWL=380,endWL=780,setflat=0.1}
%
\def\pst@flattenpath{
  /Coors [] def         % the array of all points
  /lambda \psk@startWL\space def
  %
  /add2Values { Coors aload length 2 add array astore /Coors exch def } def
  /add6Values { Coors aload length 6 add array astore /Coors exch def } def
%
  \psk@setflat\space setflat   % the value for the line snippets
  flattenpath            % flatten the existing path into line segments
%
  { add2Values }         % what to do with moveto
  { add2Values }         % what to do with lineto 
  { add6Values }         % what to do with curveto (not needed here) 
  { }                    % what to do with closepath
  pathforall             % do it for the existing path
%
  \pst@number\psk@startLW setlinewidth
  \tx@setlinejoin
  \psk@linecap\space setlinecap
  Coors aload length 2 sub 2 div cvi /N0 exch def % set number of points
  /NN 0 def
  /N N0 def
  { N 3 gt { N 3 sub /N ED }{ N 1 sub /N ED } ifelse 
    NN 1 add /NN ED
    N 0 eq { exit } if
  } loop
  /dLW \pst@number\psk@endLW \pst@number\psk@startLW sub NN div def          % the step for the linewidth
  \ifPst@variableColor
    /dColor \psk@endWL\space \psk@startWL\space sub NN div def
    lambda dColor add dup /lambda ED 
    tx@addDict begin wavelengthToRGB Red Green Blue end setrgbcolor
  \else
    \pst@usecolor\pslinecolor
  \fi
  moveto                 % move to the first one
  /N N0 def
  {
    N 3 gt {  
%    CP 6 2 roll
    \psk@curvature\space /c ED /b ED /a ED
    /ArrowA {} def
    /ArrowB {} def
    BOC NC EOC %    curveto 
    N 3 sub /N ED }{ lineto N 1 sub /N ED } ifelse
    currentlinewidth dLW add setlinewidth % increase line width
    \ifPst@variableColor
      lambda dColor add dup /lambda ED 
      tx@addDict begin wavelengthToRGB Red Green Blue end setrgbcolor
    \else
      \pst@usecolor\pslinecolor
    \fi
    CP /Y ED /X ED       % put coors of current point on the stack
%    0.4 .setopacityalpha 
    stroke               % draw the line segment
    N 0 eq { exit }{ X Y moveto } ifelse
  } loop
%  N {                    % repeat for the other N coords
%    lineto               % line to next point
%    currentlinewidth dLW add setlinewidth % increase line width
%    lambda dColor add dup /lambda ED 
%    tx@addDict begin wavelengthToRGB Red Green Blue end setrgbcolor
%    currentpoint         % put coors of current point on the stack
%    0.4 .setopacityalpha 
%    stroke               % draw the line segment
%    moveto
%  } repeat
}

%
%--------------------------- A R R O W S ---------------------------
%
\def\psk@arrowA{}
\def\psk@arrowB{}
\def\pst@arrowtable{,-,<->,<<->>,>-<,>>-<<,(-),[-],)-(,]-[,|>-<|,<D-D>,D>-<D,<D<D-D>D>} % hv --1.16
\edef\pst@arrowtable{\pst@arrowtable,|<*->|*,|<->|}
\begingroup
  \catcode`\<=13
  \catcode`\>=13
  \catcode`\|=13
  \gdef\pst@activearrows{\def<{\string<}\def>{\string>}\def|{\string|}}
\endgroup
\def\tx@BeginArrow{BeginArrow }
\def\tx@EndArrow{EndArrow }
%
\def\tx@Arrow{ \tx@setStrokeTransparency Arrow }% hv 2008-01-13
\def\tx@ArrowD{ \tx@setStrokeTransparency ArrowD }% hv 2008-01-13
%
\@namedef{psas@<|}{ 
    \psk@tbarsize\space \tx@Tbar
    0 CLW 2 div T
    newpath
    true 
    \psk@arrowinset 
    \psk@arrowlength 
    \psk@arrowsize 
    \tx@Arrow 
}
% ]-[ arrow
\def\tx@BracketOut{BracketOut }
\@namedef{psas@[}{%
  /BracketOut {%
  CLW mul add dup CLW sub 2 div
%/x ED mul CLW add
  /x ED mul neg
  /y ED
  /z CLW 2 div def
  x neg y moveto
  x neg CLW 2 div L x CLW 2 div L x y L stroke 0 CLW moveto } def
  \psk@bracketlength\space \psk@tbarsize\space \tx@BracketOut
}
% )-( arrow
\def\tx@RoundBracketOut{ \tx@setStrokeTransparency RoundBracketOut }% hv 2008-01-13
\@namedef{psas@(}{%
  /RoundBracketOut {%
    CLW mul add dup 2 div
%/x ED mul
    /x ED mul neg
    /y ED
    /mtrx CM def
    0 CLW
    2 div T x y mul 0 ne { x y scale } if
    1 1 moveto
    .85 .5 .35 0 0 0 curveto
    -.35 0 -.85 .5 -1 1 curveto
    mtrx setmatrix stroke 0 CLW moveto } def
  \psk@rbracketlength\space \psk@tbarsize\space \tx@RoundBracketOut
}
% end of new definitions of the missing arrows ---- hv 1.12
\@namedef{psas@>}{ false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow }
\@namedef{psas@>>}{%
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
  0 h T gsave newpath
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
  CP grestore CP newpath moveto 2 copy 
  CLW \pst@arrowscale\space div SLW % set the original line width  
  L stroke moveto
}
\@namedef{psas@<}{true \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow}
\@namedef{psas@<<}{
  true \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
  CP newpath moveto 0 a neg 
  gsave
  CLW \pst@arrowscale\space div SLW % set the original line width  
  L stroke 
  grestore
  0 h neg T
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
}
\@namedef{psas@D>}{ false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD }%	hv 20071211
\@namedef{psas@D>D>}{ %	hv 20071211
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD
  0 h Inset sub T gsave newpath
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD
  CP grestore moveto 
}
\@namedef{psas@<D}{ %	hv 20071211
  true \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD
}
\@namedef{psas@<D<D}{ %	hv 20071211
  true \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD
  CP newpath moveto 0 a neg L stroke 0 h neg T
  true \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@ArrowD
}
\define@key[psset]{pstricks}{tbarsize}[2pt 5]{%
  \pst@expandafter\pst@getdimnum{#1} 0 {} {}\@nil
  \edef\psk@tbarsize{\pst@number\pst@dimg \pst@tempg}}
\psset[pstricks]{tbarsize=2pt 5}
%
\def\tx@Tbar{Tbar }
\@namedef{psas@|}{\psk@tbarsize \tx@Tbar}
\@namedef{psas@|*}{0 CLW -2 div T \psk@tbarsize \tx@Tbar}
\@namedef{psas@>|}{%
  \psk@tbarsize \tx@Tbar
  0 CLW 2 div T
  newpath
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
}
\@namedef{psas@>|*}{%
  0 CLW -2 div T
  \psk@tbarsize \tx@Tbar
  0 CLW 2 div T
  newpath
  false \psk@arrowinset \psk@arrowlength \psk@arrowsize \tx@Arrow
}
%
\define@key[psset]{pstricks}{bracketlength}[0.15]{\pst@checknum{#1}\psk@bracketlength}
\psset[pstricks]{bracketlength=.15}
\def\tx@Bracket{Bracket }
\@namedef{psas@]}{\psk@bracketlength \psk@tbarsize \tx@Bracket}
\define@key[psset]{pstricks}{rbracketlength}[0.15]{\pst@checknum{#1}\psk@rbracketlength}
\psset[pstricks]{rbracketlength=.15}
\def\tx@RoundBracket{RoundBracket }
\@namedef{psas@)}{\psk@rbracketlength \psk@tbarsize \tx@RoundBracket}
%
\def\psas@c{1 \psas@@c}
\def\psas@cc{0 CLW 2 div T 1 \psas@@c}
\def\psas@C{2 \psas@@c}
\def\psas@@c{%
  setlinecap
  0 0 moveto
  0 0.1 L % changed value from 0.5 to 0.1
  stroke
  0 0 moveto }
%
\def\psas@{}
%
\define@key[psset]{pstricks}{arrowLW}{\pst@getlength{#1}\psk@arrowLW}
\psset[pstricks]{arrowLW=0}
% arrowLW as LineWidth for the circled line ends
%
\def\psas@o{\psk@arrowLW\space dup 0 eq { pop }{ SLW } ifelse
  {\pst@usecolor\psfillcolor true} false \psk@dotsize \tx@EndDot }
\def\psas@oo{\psk@arrowLW\space dup 0 eq { pop }{ SLW } ifelse
  {\pst@usecolor\psfillcolor true} true \psk@dotsize \tx@EndDot }
\@namedef{psas@*}{\psk@arrowLW\space dup 0 eq { pop }{ SLW } ifelse
  {false} false \psk@dotsize \tx@EndDot }
\@namedef{psas@**}{\psk@arrowLW\space dup 0 eq { pop }{ SLW } ifelse
  {false} true \psk@dotsize \tx@EndDot }
%
\define@key[psset]{pstricks}{arrows}[-]{%
  \begingroup
    \pst@activearrows
    \xdef\pst@tempg{#1}%
  \endgroup
  \expandafter\psset@@arrows\pst@tempg\@empty-\@empty\@nil
  \if@pst\else\@pstrickserr{Bad arrows specification: #1}\@ehpa\fi}
\def\psset@@arrows#1-#2\@empty#3\@nil{%
  \@psttrue
  \def\ps@next##1,#1-##2,##3\@nil{\def\pst@tempg{##2}}%
  \expandafter\ps@next\pst@arrowtable,#1-#1,\@nil
  \@ifundefined{psas@\pst@tempg}{\@pstfalse\def\psk@arrowA{}}{\let\psk@arrowA\pst@tempg}%
  \@ifundefined{psas@#2}{\@pstfalse\def\psk@arrowB{}}{\def\psk@arrowB{#2}}}
\psset[pstricks]{arrows=-}
%
\define@key[psset]{pstricks}{arrowscale}[1]{%                                   hv --1.12
  \pst@getscale{#1}\psk@arrowscale
  \pst@@arrowscale@i#1 \@nil}%           hv --1.12
\def\pst@@arrowscale@i#1 #2\@nil{\edef\pst@arrowscale{#1}}% hv --1.12
\psset[pstricks]{arrowscale=1}
%
\define@key[psset]{pstricks}{arrowsize}[1.5pt 2]{%
  \pst@expandafter\pst@getdimnum{#1} 0 {} {}\@nil
  \edef\psk@arrowsize{\pst@number\pst@dimg \pst@tempg}%
}
\psset[pstricks]{arrowsize=1.5pt 2}
\define@key[psset]{pstricks}{arrowlength}[1.4]{\pst@checknum{#1}\psk@arrowlength}
\psset[pstricks]{arrowlength=1.4}
\define@key[psset]{pstricks}{arrowinset}[0.4]{\pst@checknum{#1}\psk@arrowinset}%
\psset[pstricks]{arrowinset=0.4}
%
\def\tx@SD{ \tx@setTransparency SD }
\def\tx@EndDot{EndDot }
%
\def\pst@par{}
\def\addto@par#1{%
  \ifx\pst@par\@empty
    \def\pst@par{#1}%
  \else
    \expandafter\def\expandafter\pst@par\expandafter{\pst@par,#1}%
  \fi%
}
\def\addbefore@par#1{%
  \ifx\pst@par\@empty
    \def\pst@par{#1}%
  \else
    \toks@{#1}%
    \pst@toks\expandafter{\pst@par}%
    \edef\pst@par{\the\toks@,\the\pst@toks}%
  \fi%
}
\def\use@par{%
  \ifx\pst@par\@empty\else%
    \expandafter\@psset\pst@par,\@nil%
    \def\pst@par{}%
  \fi}
\def\use@keep@par{%			same as \use@par, but keeps the values
  \ifx\pst@par\@empty\else
    \expandafter\@psset\pst@par,\@nil
%    \def\pst@par{}%
  \fi}
%
\def\pst@object#1{%
  \def\pst@par{}%
  \pst@ifstar{%
    \@ifnextchar[{\pst@@object{#1}}{\@nameuse{#1@i}}}%
}
\def\pst@@object#1[#2]{%
  \def\pst@par{#2}%
  \@ifnextchar+{\@nameuse{#1@i}}{\@nameuse{#1@i}}%
}
\def\newpsobject#1#2#3{%
\@ifundefined{#2@i}%
{\@pstrickserr{Graphics object `#2' not defined}\@eha}{%
\@namedef{#1}{\pst@object{#1}}%
\@namedef{#1@i}{\addbefore@par{#3}\@nameuse{#2@i}}}%
\ignorespaces}
%
\def\pst@getarrows#1{\@ifnextchar({#1}{\pst@@getarrows{#1}}}
% ------------------------- hv 1.10 beg ------------------------
%\def\pst@@getarrows#1#2{\addto@par{arrows=#2}#1}
\def\pst@@getarrows#1#2{%
  \def\pst@tempa{#2}% prevent empty arrow arguments, to allow \psline{}(...)(...)
  \ifx\pst@tempa\@empty\addto@par{arrows=-}\else\addto@par{arrows=#2}\fi#1}
% ------------------------- hv 1.10 end ------------------------
%
\def\begin@ClosedObj{%
  \leavevmode%
  \pst@killglue%
  \begingroup%
  \use@par%
  \solid@star%
  \ifpsdoubleline\pst@setdoublesep\fi%
  \pst@addarrowdef% DG addition
  \init@pscode}
%
\def\end@ClosedObj{%
  \ifpsshadow \pst@closedshadow \fi
  \ifdim\psk@border\p@>\z@ \pst@addborder \fi
  \psk@fillstyle
  \pst@stroke
  \ifpsdoubleline \pst@doublestroke \fi
  \ifshowpoints
% DG modification begin - Mar. 4, 1995
%\addto@pscode{Points aload length 2 div cvi /N ED \psdots@iii}%
  \pst@OpenShowPoints
% DG modification end
  \fi
  \use@pscode
  \endgroup
  \ignorespaces%
}
\def\begin@OpenObj{%
  \begin@ClosedObj%
  \let\pst@linetype\pst@arrowtype%
  \pst@addarrowdef%
}
\def\begin@AltOpenObj{%
  \begin@ClosedObj
  \def\pst@repeatarrowsflag{\z@}%
  \def\pst@linetype{0}}
%
\def\end@OpenObj{%
  \ifpsshadow \pst@openshadow \fi
  \ifdim\psk@border\p@>\z@ \pst@addborder \fi
  \psk@fillstyle
  \pst@stroke
  \ifpsdoubleline \pst@doublestroke \fi
  \ifnum\pst@repeatarrowsflag>\z@ \pst@repeatarrows \fi
  \ifshowpoints \pst@OpenShowPoints \fi
  \use@pscode
  \endgroup
  \ignorespaces}
%
\def\begin@SpecialObj{%
  \leavevmode
  \pst@killglue
  \begingroup
  \use@par
  \init@pscode}
%
\def\end@SpecialObj{%
  \use@pscode
  \endgroup
  \ignorespaces}
%
\def\pst@code{}%
\def\init@pscode{%
  \addto@pscode{%
    \pst@number\pslinewidth SLW
    \pst@usecolor\pslinecolor}%
}
\def\addto@pscode#1{\xdef\pst@code{\pst@code#1\space}}
\def\use@pscode{%
  \pstverb{
    \pst@dict
    \tx@STP
    \pst@newpath
    \psk@origin
    \psk@swapaxes
    \pst@code
    end
  }%
  \gdef\pst@code{}%
}
\def\use@psCode{%
  \pstVerb{
    \pst@dict
    \tx@STP
    \pst@newpath
    \psk@origin
    \psk@swapaxes
    \pst@code
    end
  }%
  \gdef\pst@code{}%
}
\def\pst@newpath{newpath }
%
\def\pst@@killglue{\unskip\ifdim\lastskip>\z@\expandafter\pst@@killglue\fi}
\def\KillGlue{\let\pst@killglue\pst@@killglue}
\def\DontKillGlue{\let\pst@killglue\relax}
\DontKillGlue
%
\def\solid@star{%
  \if@star
    \pslinewidth=\z@
    \psdoublelinefalse
    \def\pslinestyle{none}%
    \def\psk@fillstyle{\psfs@solid}%
    \let\psfillcolor\pslinecolor
  \fi}
%
\def\pst@setdoublesep{%
\pst@getlength\psdoublesep\psdoublesep
\pslinewidth=2\pslinewidth
\advance\pslinewidth\psdoublesep\p@
\let\pst@setdoublesep\relax}
\def\tx@Shadow{Shadow }
\def\pst@closedshadow{%
  \addto@pscode{%
    gsave
    \psk@shadowsize \psk@shadowangle \tx@PtoC
    \tx@Shadow
    \pst@usecolor\psshadowcolor
    gsave fill grestore
    stroke
    grestore
    gsave
    \pst@usecolor\psfillcolor
    gsave fill grestore
    stroke
    grestore}}
%
\def\pst@openshadow{%
  \addto@pscode{%
    gsave
    \psk@shadowsize \psk@shadowangle \tx@PtoC
    \tx@Shadow
    \pst@usecolor\psshadowcolor
    \ifx\psk@fillstyle\relax\else
      gsave fill grestore
    \fi
    stroke}%
  \pst@repeatarrows%
  \addto@pscode{grestore}%
  \ifx\psk@fillstyle\relax\else
    \addto@pscode{%
      gsave
      \pst@usecolor\psfillcolor
      gsave fill grestore
      stroke
      grestore}%
  \fi}
%
\def\pst@addborder{%
  \addto@pscode{%
    gsave
    \psk@border 2 mul
    CLW add SLW
    \pst@usecolor\psbordercolor
    stroke
    grestore}}
%
\def\pst@stroke{%
  \ifx\pslinestyle\@none\else
    \addto@pscode{%
      gsave
      \pst@number\pslinewidth SLW
      \pst@usecolor\pslinecolor
      \tx@setStrokeTransparency % hv 2008-01-13
      \@nameuse{psls@\pslinestyle}
      grestore}%
  \fi}
%
\def\pst@fill#1{\addto@pscode{gsave #1 grestore}}%
%
\def\pst@doublestroke{%
    \addto@pscode{%
      gsave
      \psdoublesep SLW
      \pst@usecolor\psdoublecolor
      stroke
      grestore
}}
%
\def\pst@arrowtype{%
  \ifx\psk@arrowB\@empty 0 \else -2 \fi
  \ifx\psk@arrowA\@empty 0 \else -1 \fi
  add }
%
\def\pst@addarrowdef{%
  \addto@pscode{%
    /ArrowA {
      \ifx\psk@arrowA\@empty
        \pst@oplineto
      \else
        \pst@arrowdef{A}
        moveto
      \fi
    } def
    /ArrowB { \ifx\psk@arrowB\@empty \else \pst@arrowdef{B} \fi } def
}}
%
\def\pst@arrowdef#1{%
  \ifnum\pst@repeatarrowsflag>\z@
    /Arrow#1c [ 6 2 roll ] cvx def Arrow#1c
  \fi
  \tx@BeginArrow 
  \psk@arrowscale
  \@nameuse{psas@\@nameuse{psk@arrow#1}}
  \tx@EndArrow
}
%
\def\pst@repeatarrows{%
  \addto@pscode{%
    gsave
    \ifx\psk@arrowA\@empty\else ArrowAc ArrowA pop pop \fi
    \ifx\psk@arrowB\@empty\else ArrowBc ArrowB pop pop pop pop \fi
    grestore
}}
%
\def\pst@OpenShowPoints{%
  \addto@pscode{%
    gsave
    \psk@dotsize
    \@nameuse{psds@\psk@dotstyle}
    newpath
    Points aload length 2 div 2 sub cvi /N ED
    N 0 ge
      { \ifx\psk@arrowA\@empty Dot \else pop pop \fi 
        N { Dot } repeat 
	\ifx\psk@arrowB\@empty Dot \else pop pop \fi }
      { N 2 mul { pop } repeat } ifelse
    grestore
}}
%
\newif\ifPst@custom\Pst@customfalse
\define@boolkey[psset]{pstricks}[Pst@]{noCurrentPoint}[true]{}
\psset[pstricks]{noCurrentPoint=false}
%
%
\def\pscustom{\pst@object{pscustom}}
\long\def\pscustom@i#1{%
  \begin@SpecialObj%
  \solid@star%
  \let\pst@ifcustom\iftrue%
  \Pst@customtrue%
  \let\begin@ClosedObj\begin@CustomObj%
  \let\end@ClosedObj\endgroup%
  \def\begin@OpenObj{\begin@CustomObj\pst@addarrowdef}%
  \let\end@OpenObj\endgroup%
  \let\begin@AltOpenObj\begin@CustomObj%
  \def\begin@SpecialObj{%
    \begingroup%
    \pst@misplaced{special graphics object}%
    \def\addto@pscode####1{}%
    \let\end@SpecialObj\endgroup}%
  \def\@multips(##1)(##2)##3##4{\pst@misplaced\multips}%
  \def\psclip##1{\pst@misplaced\psclip}%
  \def\pst@repeatarrowsflag{\z@}%
  \let\pst@setrepeatarrowsflag\relax%
  \showpointsfalse%
  \def\pst@linetype{\pslinetype}%
  \def\psk@liftpen{\z@}%
%  \psset{liftpen=0}%
  \def\pst@cp{/currentpoint load stopped pop }%
  \def\pst@oplineto{/lineto load stopped { moveto } if }%
  \def\pst@optcp##1##2{\ifnum##1=\z@\def##2{/currentpoint load stopped { 0 0 } if }\fi}%
  \let\caddto@pscode\addto@pscode%
  \def\cuse@par##1{{\use@par##1}}%
  \the\pst@customdefs%
  \setbox\pst@hbox=\hbox{#1}%
  \psk@fillstyle
  \pst@stroke
  \end@SpecialObj
  \let\pst@ifcustom\iffalse
}
%
\let\pst@ifcustom\iffalse
%
\def\begin@CustomObj{%
  \begingroup%
  \use@par%
  \addto@pscode{
    \pst@number\pslinewidth SLW
    \pst@usecolor\pslinecolor
  }%
}
\def\pst@oplineto{moveto }
\def\pst@cp{}
\def\pst@optcp#1#2{}
\define@key[psset]{pstricks}{liftpen}[0]{%
  \ifPst@custom%
  \ifcase#1\relax%
    \def\psk@liftpen{\z@}%
    \def\pst@cp{/currentpoint load stopped pop }%
    \def\pst@oplineto{/lineto load stopped { moveto } if }%
  \or%
    \def\psk@liftpen{1}%
    \def\pst@cp{}%
    \def\pst@oplineto{/lineto load stopped { moveto } if }%
  \or%
    \def\psk@liftpen{2}%
    \def\pst@cp{}%
    \def\pst@oplineto{moveto }%
  \fi\fi%
}
\psset[pstricks]{liftpen=0}
\def\psk@liftpen{-1}
%
\define@key[psset]{pstricks}{linetype}[2]{%
  \pst@getint{#1}\pslinetype
  \ifnum\pst@cntg<-3
    \@pstrickserr{linetype must be greater than -3}\@ehpa
    \def\pslinetype{2}%
  \fi}
\psset[pstricks]{linetype=2}% otherwise there is a problem when using e.g.
%                     \psaxes[axesstyle=frame,linestyle=dashed]{->}(3,-2)
%
\def\caddto@pscode#1{%
    \@pstrickserr{Command can only be used in \string\pscustom}\@ehpa}
\let\cuse@par\caddto@pscode
%
\def\tx@MSave{%
     /msavematrx
         [ tx@Dict /msavematrx known % does msavematrix exists?
             { msavematrx aload pop } if
             CM % matrix currentmatrix
         ]
     def
%----------------- hv begin 2004-05-07 ------------- patch 15
    msavematrx
%----------------- hv end 2004-05-07 ------------- patch 15
}
\def\tx@MRestore{% a typo in pstricks with msavematrx
     tx@Dict /msavematrx known { length 0 gt } { false } ifelse
         { msavematrx aload pop setmatrix } if
}
%
\newtoks\pst@customdefs
\pst@customdefs{%
  \def\newpath{\addto@pscode{newpath}}%
  \def\reversepath{\addto@pscode{ reversepath }}%                      20131209  hv
  \def\moveto(#1){\pst@@getcoor{#1}\addto@pscode{\pst@coor moveto}}%
  \def\rmoveto(#1){\pst@@getcoor{#1}\addto@pscode{\pst@coor rmoveto}}%
  \def\closepath{\addto@pscode{closepath}}%
  \def\gsave{\begingroup\addto@pscode{gsave}}%
  \def\grestore{\endgroup\addto@pscode{grestore}}%
  \def\translate(#1){\pst@@getcoor{#1}\addto@pscode{\pst@coor translate}}%
  \def\rotate#1{\pst@@getangle{#1}\addto@pscode{\pst@angle rotate}}%
  \def\scale#1{\pst@getscale{#1}\pst@tempg\addto@pscode{\pst@tempg}}%
  \def\msave{\addto@pscode{\tx@MSave}}%
  \def\mrestore{\addto@pscode{\tx@MRestore}}%
  \def\swapaxes{\addto@pscode{-90 rotate -1 1 scale}}%
  \def\stroke{\def\pst@par{}\pst@object{stroke}}%
  \def\fill{\def\pst@par{}\pst@object{fill}}%
  \def\openshadow{\def\pst@par{}\pst@object{openshadow}}%
  \def\closedshadow{\def\pst@par{}\pst@object{closedshadow}}%
  \def\movepath(#1){\pst@@getcoor{#1}\addto@pscode{\pst@coor \tx@Shadow}}%
  \def\lineto{\pst@onecoor{lineto}}%
  \def\rlineto{\pst@onecoor{rlineto}}%
  \def\curveto{\pst@threecoor{curveto}}%
  \def\rcurveto{\pst@threecoor{rcurveto}}%
  \def\code#1{\addto@pscode{#1}}%
  \def\coor(#1){\pst@@getcoor{#1}\addto@pscode\pst@coor\@ifnextchar({\coor}{}}%
  \def\rcoor{\pst@getcoors{}{}}%
  \def\dim#1{\pssetlength\pst@dimg{#1}\addto@pscode{\pst@number\pst@dimg}}%
  \def\setcolor#1{%
    \@ifundefined{\string\color@#1}{}{\addto@pscode{\pst@usecolor{#1}}}}%  hv 1.14  2005-12-17
  \def\arrows#1{{\psset[pstricks]{arrows=#1}\pst@addarrowdef}}%
  \let\file\pst@rawfile%
} % END \pst@customdefs
%
\def\closedshadow@i{\cuse@par\pst@closedshadow}
\def\openshadow@i{\cuse@par\pst@openshadow}
\def\stroke@i{\cuse@par\pst@stroke}%
\def\fill@i{\cuse@par\psk@fillstyle}%
\def\pst@onecoor#1(#2){%
\pst@@getcoor{#2}%
\addto@pscode{\pst@coor #1}}
\def\pst@threecoor#1(#2)#3(#4)#5(#6){%
  \begingroup
    \pst@getcoor{#2}\pst@tempa
    \pst@getcoor{#4}\pst@tempb
% DG/SR modification begin - Aug.  4, 1999 - Patch 11
%\pst@getcoor{#6}\pst@tembc
    \pst@getcoor{#6}\pst@tempc
% DG/SR modification end
    \addto@pscode{\pst@tempa \pst@tempb \pst@tempc #1}%
  \endgroup}
%
\def\pst@rawfile#1{%
  \begingroup
  \def\do##1{\catcode`##1=12\relax}"
  \dospecials
  \catcode`\%=14
  \pst@@rawfile{#1}%
  \endgroup}
%
\def\pst@@rawfile#1{%
  \immediate\openin1 #1
  \ifeof1
    \@pstrickserr{File `#1' not found}\@ehpa
  \else
    \immediate\read1 to \pst@tempg
    \loop
      \ifeof1 \@pstfalse\else\@psttrue\fi
      \if@pst
      \addto@pscode\pst@tempg
      \immediate\read1 to \pst@tempg
    \repeat
  \fi
  \immediate\closein1\relax}
%
\def\tx@NArray{NArray }
\def\tx@Line{Line }
\def\tx@Arcto{Arcto }
\def\tx@CheckClosed{CheckClosed }
\def\tx@Polygon{Polygon }
\define@key[psset]{pstricks}{gangle}[0]{\pst@getangle{#1}\psk@gangle}
\define@boolkey[psset]{pstricks}[Pst@]{trueAngle}[true]{}
\psset[pstricks]{trueAngle=false,gangle=0}
%
\def\tx@Diamond{Diamond }
\def\psdiamond{\def\pst@par{}\pst@object{psdiamond}}
\def\psdiamond@i(#1){\@ifnextchar({\psdiamond@ii(#1)}{\psdiamond@ii(0,0)(#1)}}
\def\psdiamond@ii(#1)(#2){%
  \begin@ClosedObj
  \pst@getcoor{#1}\pst@tempa
  \pst@getcoor{#2}\pst@tempb
  \addto@pscode{%
    \psline@iii
    pop
    \psk@dimen
    \pst@tempb
    \psk@gangle
    \pst@tempa
    \tx@Diamond
  }%
  \def\pst@linetype{4}%
  \end@ClosedObj}
%
\def\tx@Triangle{Triangle }
\def\pstriangle{\def\pst@par{}\pst@object{pstriangle}}
\def\pstriangle@i(#1){\@ifnextchar({\pstriangle@ii(#1)}{\pstriangle@ii(0,0)(#1)}}
\def\pstriangle@ii(#1)(#2){%
  \begin@ClosedObj
  \pst@getcoor{#1}\pst@tempa%	the center of the baseline
  \pst@getcoor{#2}\pst@tempb%	the height of the triangle
  \addto@pscode{%
    \psline@iii
    pop			    %	no showpoints option
    \psk@dimen		    %	outer/inner/middle
    \pst@tempb
    \psk@gangle		    %	rotating angle
    \pst@tempa
    \tx@Triangle
  }%
  \def\pst@linetype{2}%
  \end@ClosedObj}
%
\def\tx@CCA{CCA }
\def\tx@CCA{CCA }
\def\tx@CC{CC }
\def\tx@IC{IC }
\def\tx@BOC{BOC }
\def\tx@NC{NC }
\def\tx@EOC{EOC }
\def\tx@BAC{BAC }
\def\tx@NAC{NAC }
\def\tx@EAC{EAC }
\def\tx@OpenCurve{OpenCurve }
\def\tx@AltCurve{AltCurve }
\def\tx@ClosedCurve{ClosedCurve }
%
\define@key[psset]{pstricks}{curvature}[1 0.1 0]{%
  \edef\pst@tempg{#1 }%
  \expandafter\psset@@curvature\pst@tempg * * * \@nil}
\def\psset@@curvature#1 #2 #3 #4\@nil{%
  \pst@checknum{#1}\pst@tempg
  \pst@checknum{#2}\pst@temph
  \pst@checknum{#3}\pst@tempi
  \edef\psk@curvature{\pst@tempg \pst@temph \pst@tempi}}
%
\psset[pstricks]{curvature=1 .1 0}
%
\def\pscurve{\pst@object{pscurve}}
\def\pscurve@i{%
  \pst@getarrows{%
    \begin@OpenObj
      \pst@getcoors[\pscurve@ii%
    }%
}
\def\pscurve@ii{%
  \addto@pscode{
    \ifPst@noCurrentPoint\else\pst@cp\fi		% current point
    \psk@curvature\space /c ED /b ED /a ED
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol \psls@symbol OpenSymbolCurve \else \tx@OpenCurve \fi
    \ifPst@variableLW \pst@flattenpath \fi
  }%
  \ifx\pslinestyle\psls@@symbol\def\pslinestyle{none}\fi%
  \end@OpenObj%
}
\def\psecurve{\pst@object{psecurve}}
\def\psecurve@i{\pst@getarrows{\begin@OpenObj\pst@getcoors[\psecurve@ii}}
\def\psecurve@ii{%
  \addto@pscode{
    \psk@curvature\space /c ED /b ED /a ED
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol \psls@symbol AltOpenSymbolCurve \else \tx@AltCurve \fi
  }%
  \ifx\pslinestyle\psls@@symbol\def\pslinestyle{none}\fi%
  \end@OpenObj}
%
\def\psccurve{\pst@object{psccurve}}
\def\psccurve@i{\begin@ClosedObj\pst@getcoors[\psccurve@ii}
\def\psccurve@ii{%
  \addto@pscode{%
    \psk@curvature\space /c ED /b ED /a ED
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol \psls@symbol ClosedSymbolCurve \else \tx@ClosedCurve \fi
  }%
  \def\pst@linetype{1}%
  \ifx\pslinestyle\psls@@symbol\def\pslinestyle{none}\fi%
  \end@ClosedObj}
%
\def\pscspline{\pst@object{pscspline}}%  Christoph Bersch
\def\pscspline@i{%
  \pst@getarrows{%
    \begin@OpenObj
    \pst@getcoors[\pscspline@ii
  }%
}
\def\tx@Spline{Spline }
\def\pscspline@ii{%
  \addto@pscode{
    \ifPst@noCurrentPoint\else\pst@cp\fi
    \tx@setlinejoin
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol 
      \psls@symbol OpenSymbolSpline
    \else
      \tx@Spline
    \fi
  }%      
  \end@OpenObj
}
%
\define@key[psset]{pstricks}{dotsize}[2pt 2]{%
  \pst@expandafter\pst@getdimnum{#1} 0 {} {}\@nil%
  \edef\psk@@dotsize{\pst@number\pst@dimg}%
  \let\psk@@@dotsize\pst@tempg%
  \edef\psk@dotsize{ /DS \psk@@dotsize \psk@@@dotsize CLW mul add 2 div def }}
\psset[pstricks]{dotsize=2pt 2}
%
\define@key[psset]{pstricks}{dotscale}[1]{%
  \pst@getscale{#1}\psk@dotscale
  \ifx\psk@dotscale\@empty
    \def\psk@xdotscale{1 }%
    \def\psk@ydotscale{1 }%
  \else
    \let\psk@xdotscale\pst@tempg
    \let\psk@ydotscale\pst@temph
  \fi}
%
\def\pst@Getangle#1#2{%
  \pst@getangle{#1}\pst@tempg
  \def\pst@temph{0. }%
  \ifx\pst@tempg\pst@temph\def#2{}\else\edef#2{\pst@tempg\space rotate }\fi}
%
\define@key[psset]{pstricks}{dotangle}[0]{%
  \pst@getangle{#1}\psk@@dotangle
  \ifdim\psk@@dotangle\p@=\z@
    \let\psk@dotangle\@empty
  \else
    \edef\psk@dotangle{\psk@@dotangle rotate }%
  \fi}
\psset[pstricks]{dotangle=0}
%
\def\pst@getdotsize{%
\pst@dimg=\psk@@@dotsize\pslinewidth
\advance\pst@dimg\psk@@dotsize\p@
\pst@dimh=\psk@ydotscale\pst@dimg
\pst@dimg=\psk@xdotscale\pst@dimg
\divide\pst@dimh 2
\divide\pst@dimg 2\relax}
%
\psset[pstricks]{dotscale=1}
%
\def\psdot{\pst@object{psdot}}
\def\psdot@i{\@ifnextchar({\psdot@ii}{\psdot@ii(\z@,\z@)}}
\def\psdot@ii(#1){%
  \begin@SpecialObj%
% hv modification 1.13 2005-11-28 
  \solid@star%
% hv modification end 
  \pst@@getcoor{#1}%
  \addto@pscode{
    \psk@dotsize
    \@nameuse{psds@\psk@dotstyle}
    \tx@setStrokeTransparency
    \pst@coor Dot}%
  \end@SpecialObj}
%
\def\psdots{\pst@object{psdots}}
\def\psdots@i{%
  \begin@SpecialObj%
  \pst@getcoors[\psdots@ii}
\def\psdots@ii{%
  \addto@pscode{ false \tx@NArray \psdots@iii }%
  \end@SpecialObj}
\def\psdots@iii{%
  \psk@dotsize
  \@nameuse{psds@\psk@dotstyle}
  \tx@setStrokeTransparency
  newpath
  n { transform floor .5 add exch floor .5 add exch itransform Dot  } repeat }
%
% DG: dead code (to suppress until \psset[pstricks]{dotstyle) ? - Aug. 4, 1997
\def\tx@SQ{SQ }
\def\tx@ST{ST }
\def\tx@SP{SP }
%
\def\pst@gdot#1{ /Dot { gsave T \psk@dotangle \psk@dotscale #1 grestore } def }
%
\@namedef{psds@*}{\pst@gdot{ 0 0 DS \tx@SD }}
\@namedef{psds@o}{%
  /r2 DS CLW sub def
  \pst@gdot{ 0 0 DS \tx@SD \pst@usecolor\psfillcolor SLW 0 0 r2 \tx@SD }}
\@namedef{psds@square*}{ /r1 DS .886 mul def \pst@gdot{r1 \tx@SQ }}
\@namedef{psds@square}{%
  /r1 DS .886 mul def /r2 r1 CLW sub def
  \pst@gdot{r1 \tx@SQ \pst@usecolor\psfillcolor r2 \tx@SQ}}
\@namedef{psds@triangle*}{%
  /y1 DS .778 mul neg def /x1 y1 1.732 mul neg def
  \pst@gdot{x1 y1 \tx@ST}}
\@namedef{psds@triangle}{%
  /y1 DS .778 mul neg def /x1 y1 1.732 mul neg def
  /y2 y1 CLW add def /x2 y2 1.732 mul neg def
  \pst@gdot{x1 y1 \tx@ST \pst@usecolor\psfillcolor x2 y2 \tx@ST}}
\@namedef{psds@pentagon*}{%
  /r1 DS 1.149 mul def
  \pst@gdot{r1 \tx@SP}}
\@namedef{psds@pentagon}{%
  DS .93 mul dup 1.236 mul /r1 ED CLW sub 1.236 mul /r2 ED
  \pst@gdot{r1 \tx@SP \pst@usecolor\psfillcolor r2 \tx@SP}}
\@namedef{psds@+}{%
  /DS DS 1.253 mul def
  \pst@gdot{DS 0 moveto DS neg 0 L stroke 0 DS moveto 0 DS neg L stroke}}
\@namedef{psds@|}{%
  \psk@tbarsize CLW mul add 2 div /DS ED
  \pst@gdot{0 DS moveto 0 DS neg L stroke}}
% DG: end dead code?
%
\define@key[psset]{pstricks}{dotstyle}[*]{%
  \@ifundefined{psds@#1}%
    {\@pstrickserr{Dot style `#1' not defined}\@eha}%
    {\edef\psk@dotstyle{#1}}}
\psset[pstricks]{dotstyle=*}
%
\def\tx@FontDot{FontDot }
\def\newpsfontdot#1[#2]#3#4{%
  \@namedef{psds@#1}{%
    /#3 \psk@@dotangle [#2] \tx@FontDot
% DG/SR modification begin - Dec. 12, 1999 - Patch 14
%/Dot { moveto #4 show } bind def }}
    /Dot { moveto gsave \psk@dotscale #4 show grestore } bind def 
}}
% DG/SR modification end
\def\newpsfontdotH#1[#2]#3#4#5{%	for filled objects
  \@namedef{psds@#1}{%
    /#3 \psk@@dotangle [#2] \tx@FontDot
    /Dot {
      moveto
%      \iftrue
% DG/SR modification begin - Dec. 23, 1999 - Patch 14
%gsave \pst@usecolor\psfillcolor #5 show grestore
%\fi
%#4 show
      gsave \psk@dotscale \pst@usecolor\psfillcolor #5 show grestore % fill first
%      \fi					
      gsave \psk@dotscale #4 show grestore	% show the unfilled one
% DG/SR modification end
    } bind def 
}}
%
\pstheader{pst-dots.pro}
\newpsfontdot{*}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(b)}
\newpsfontdotH{o}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(c)}{(b)}
\newpsfontdotH{Bo}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(C)}{(b)}
\newpsfontdotH{triangle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(t)}{(u)}
\newpsfontdotH{Btriangle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(T)}{(u)}
\newpsfontdot{triangle*}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(u)}
\newpsfontdotH{square}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(s)}{(r)}
\newpsfontdotH{Bsquare}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(S)}{(r)}
\newpsfontdot{square*}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(r)}
\newpsfontdotH{pentagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(p)}{(q)}
\newpsfontdotH{Bpentagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(P)}{(q)}
\newpsfontdot{pentagon*}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(q)}
% DG/SR modification begin - Mar. 18, 1997 and Dec. 16, 1999 - Patch 14
%\newpsfontdot{diamond*}[1.9 0.0 0.0 1.9 -0.4598 -0.70775]{Symbol}{<E0>}
%\newpsfontdot{diamond}[2.3 0.0 0.0 2.3 -0.8533 -0.5336]{Symbol}{<A8>}
% D.G. modification begin - Jan. 17, 2000
\newpsfontdotH{diamond}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(d)}{(l)}
\newpsfontdotH{Bdiamond}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(D)}{(l)}
\newpsfontdot{diamond*}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(l)}
% DG/SR modification end
\newpsfontdot{oplus}[1.44928 0.0 0.0 1.44928 -0.562319 -0.478261]{Symbol}{<C5>}
\newpsfontdot{otimes}[1.44928 0.0 0.0 1.44928 -0.562319 -0.475362]{Symbol}{<C4>}
\newpsfontdot{x}[1.8 0.0 0.0 1.8 -0.495 -0.4788]{Symbol}{<B4>}
\newpsfontdot{+}[2.3 0.0 0.0 2.3 -0.6486 -0.5819]{Times-Roman}{<2B>}
\newpsfontdot{asterisk}[2.43309 0.0 0.0 2.43309 -0.609489 -1.14477]{Times-Roman}{<2A>}
\newpsfontdot{B+}[2.3 0.0 0.0 2.3 -0.6555 -0.5819]{Times-Bold}{<2B>}
\newpsfontdot{Basterisk}[2.29358 0.0 0.0 2.29358 -0.576835 -1.08486]{Times-Bold}{<2A>}
\newpsfontdot{|}[1.98413 0.0 0.0 1.38 -0.258929 -0.5]{Helvetica}{(|)}
% DG/SR modification begin - Oct. 27, 1997 - Patch 7
%[1.98413 0.0 0.0 1.98413 -0.258929 -0.712302]{Helvetica}{(|)}
% DG/SR modification end
\newpsfontdot{B|}[1.98413 0.0 0.0 1.38 -0.277778 -0.5]{Helvetica-Bold}{(|)}%
% DG/SR modification begin - Oct. 27, 1997 - Patch 7
%[1.98413 0.0 0.0 1.98413 -0.277778 -0.78302]{Helvetica-Bold}{(|)}

% DG/SR modification end
\iffalse
\newpsfontdot{*}[2.77778 0.0 0.0 2.77778 -0.638889 -0.813889]{Symbol}{<B7>}
\newpsfontdot{o}[3.33333 0.0 0.0 3.33333 -0.666667 -1.78167]{Symbol}{<B0>}
\newpsfontdot{Bo}[4.69484 0.0 0.0 4.69484 -0.78169 -2.97418]{Times-Bold}{<CA>}
\fi
% Etienne Riga
\newpsfontdot{Asterisk}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(k)}
\newpsfontdot{BoldAsterisk}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(K)}
\newpsfontdotH{SolidAsterisk}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(J)}{(b)}
%
\newpsfontdotH{Pentagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(p)}{(q)}
\newpsfontdotH{BoldPentagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(P)}{(q)}
\newpsfontdot{SolidPentagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(q)}
\newpsfontdotH{Hexagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(h)}{(G)}
\newpsfontdotH{BoldHexagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(H)}{(G)}
\newpsfontdot{SolidHexagon}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(G)}
\newpsfontdotH{Octogon}[1 0 0 1 0 0]{PSTricksDotFont}{(f)}{(g)}
\newpsfontdotH{BoldOctogon}[1 0 0 1 0 0]{PSTricksDotFont}{(F)}{(g)}
\newpsfontdot{SolidOctogon}[1 0 0 1 0 0]{PSTricksDotFont}{(g)}
%
\newpsfontdot{Bullet}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(b)}
\newpsfontdotH{Circle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(c)}{(b)}
\newpsfontdotH{BoldCircle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(C)}{(b)}
%\newpsfontdot{SolidCircle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(u)}
\newpsfontdotH{Triangle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(t)}{(u)}
\newpsfontdotH{BoldTriangle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(T)}{(u)}
\newpsfontdot{SolidTriangle}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(u)}
\newpsfontdotH{Square}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(s)}{(r)}
\newpsfontdotH{BoldSquare}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(S)}{(r)}
\newpsfontdot{SolidSquare}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(r)}
\newpsfontdot{Add}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(a)}
\newpsfontdot{BoldAdd}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(A)}
\newpsfontdot{Mul}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(x)}
\newpsfontdot{BoldMul}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(X)}
\newpsfontdotH{Oplus}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(m)}{(b)}
\newpsfontdotH{BoldOplus}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(M)}{(b)}
\newpsfontdotH{SolidOplus}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(e)}{(b)}
\newpsfontdotH{Otimes}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(n)}{(b)}
\newpsfontdotH{BoldOtimes}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(N)}{(b)}
\newpsfontdotH{SolidOtimes}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(E)}{(b)}
\newpsfontdot{Bar}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(i)}
\newpsfontdot{BoldBar}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(I)}
\newpsfontdotH{Diamond}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(d)}{(l)}
\newpsfontdotH{BoldDiamond}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(D)}{(l)}
\newpsfontdot{SolidDiamond}[1.0 0.0 0.0 1.0 0.0 0.0]{PSTricksDotFont}{(l)}
%
\newdimen\pslinearc
\define@key[psset]{pstricks}{linearc}[0pt]{\pssetlength\pslinearc{#1}}
\psset[pstricks]{linearc=0pt}
%
\def\psline{\pst@object{psline}}
\def\psline@i{%
  \pst@getarrows{%
    \begin@OpenObj
    \pst@getcoors[\psline@ii%
  }%
}
\def\psline@ii{%
  \ifx\pslinestyle\psls@@symbol\addto@pscode{ \psls@symbol SymbolLine }%
  \else%
    \addto@pscode{
      \ifPst@noCurrentPoint\else\pst@cp\fi 	  % current point?
      \psline@iii % arc and lineto type
      \tx@Line	  % .pro function
    }%
  \fi%
  \end@OpenObj%
}
\def\psline@iii{%
  \ifdim\pslinearc>\z@
    /r \pst@number\pslinearc def
    /Lineto { \tx@Arcto } def
  \else
    /Lineto /lineto load def
  \fi
  \tx@setlinejoin 			% hv 2007-10-13
  \ifshowpoints true \else false \fi
}
%
\def\pst@isnum#1{\pst@isnum@i\zap@space#1 \@empty\@nil}%
\def\pst@isnum@i#1\@nil{%
  \if!\ifnum9<1#1!\else_\fi%
      \expandafter\@firstoftwo%
  \else%
      \expandafter\@secondoftwo%
  \fi}
%
\def\psset@@symbol#1#2#3#4\@nil{%
  \ifx\relax#4\relax\def\psk@symbol{(#1)}%
  \else%
    \pst@isnum{#1#2#3}{%
      \pst@cnta='#1#2#3\relax%
      \ifnum\pst@cnta>'377\relax%
        \@pstrickserr{Number too large!}\@ehpb%
      \else%
        \def\psk@symbol{(\@backslashchar#1#2#3)}%
      \fi%
}{\@pstrickserr{Not a number!}\@ehpb}%
  \fi}
%
\define@key[psset]{pstricks}{symbol}[a]{\expandafter\psset@@symbol#1!!\@nil}
\psset[pstricks]{symbol=a}
%
\newdimen\pst@symbolStep
\define@key[psset]{pstricks}{symbolStep}[20pt]{\pst@expandafter\pst@@symbolStep#1\@nil}
\def\pst@@symbolStep#1#2\@nil{\if-#1\pssetlength\pst@symbolStep{-#2pt}\else\pssetlength\pst@symbolStep{#1#2}\fi}
\psset[pstricks]{symbolStep=20pt}

\newdimen\pst@symbolWidth
\newdimen\pst@symbolLinewidth
\define@key[psset]{pstricks}{symbolWidth}[10pt]{\pssetlength\pst@symbolWidth{#1}}
\define@key[psset]{pstricks}{symbolLinewidth}[0.5pt]{\pssetlength\pst@symbolLinewidth{#1}}
\psset[pstricks]{symbolWidth=10pt,symbolLinewidth=0.5pt}

\define@key[psset]{pstricks}{symbolFont}[Dingbats]{\def\psk@symbolFont{/#1 }}
\psset[pstricks]{symbolFont=Dingbats}
\define@boolkey[psset]{pstricks}[Pst@]{rotateSymbol}[true]{}
\psset[pstricks]{rotateSymbol=false}
\define@key[psset]{pstricks}{startAngle}[0]{\pst@getangle{#1}\psk@startAngle}
\define@key[psset]{pstricks}{tickAngle}[0]{\pst@getangle{#1}\psk@tickAngle}
\psset[pstricks]{startAngle=0,tickAngle=0}
\define@boolkey[psset]{pstricks}[Pst@]{curveticks}[true]{}
\psset[pstricks]{curveticks=false}

%
\def\psls@symbol{
  /Symbol \psk@symbol def
  /SymbolWidth \pst@number\pst@symbolWidth def
  /SymbolLinewidth \pst@number\pst@symbolLinewidth def
  /SymStep \pst@number\pst@symbolStep def
  \psk@symbolFont findfont %0. [1.0 0.0 0.0 1.0 0.0 0.0]
  \pst@number\pst@symbolWidth scalefont %dup 
  setfont 
  /rotateSymbol \ifPst@rotateSymbol true \else false \fi def
  /tickAngle \psk@tickAngle\space def
  /startAngle \psk@startAngle\space def
  /CorrAngle \ifx\psk@rot\@empty 0 \else \psk@rot \fi def
  /curveticks \ifPst@curveticks true \else false \fi def
  \pst@number\pslinewidth SLW
}
\def\psls@@symbol{symbol}
%
\def\psPline{\def\pst@par{}\pst@object{psPline}}% perpendicular to another line B-C
\def\psPline@i{%
  \pst@getarrows{%
    \begin@OpenObj
    \pst@getcoors[\psPline@ii}%   \pst@coors on stack
}
\def\psPline@ii{%
  \addto@pscode{ % [ pC pB pA  is on stack
    /yA ED /xA ED
    /yB ED /xB ED
    yB sub exch xB sub div /mBC ED		% the slope
    /mA 1 mBC neg div def			% orthogonal
    /xS yA yB sub mBC xB mul add mA xA mul sub mBC mA sub div def
    /yS mBC xS xB sub mul yB add def
    xS yS xA yA 
    \ifPst@noCurrentPoint\else\pst@cp\fi 	% current point
    \psline@iii % arc and lineto type
    \tx@Line	% .pro function
  }%
  \end@OpenObj%
  \ignorespaces%
}
%
\def\qline(#1)(#2){%
  \def\pst@par{}%
  \begin@SpecialObj
  \def\pst@linetype{0}%
  \pst@getcoor{#1}\pst@tempa
  \pst@@getcoor{#2}%
  \addto@pscode{%
    \pst@tempa moveto \pst@coor L
    \@nameuse{psls@\pslinestyle}%
  }%
  \end@SpecialObj}
%
\def\pspolygon{\pst@object{pspolygon}}
\def\pspolygon@i{%
  \begin@ClosedObj%
  \def\pst@cp{}%
  \pst@getcoors[\pspolygon@ii%
}
\def\pspolygon@ii{%
  \ifx\pslinestyle\psls@@symbol\addto@pscode{ \psls@symbol SymbolPolygon }%
  \else                        \addto@pscode{\psline@iii \tx@Polygon}%
  \fi%
  \def\pst@linetype{1}%
  \end@ClosedObj}
%
\define@key[psset]{pstricks}{framearc}[0]{\pst@checknum{#1}\psk@framearc}
\psset[pstricks]{framearc=0}
%
\define@key[psset]{pstricks}{cornersize}[relative]{\pst@expandafter\psset@@cornersize{#1}\@nil}
\def\psset@@cornersize#1#2\@nil{%
  \if #1a\relax
    \def\psk@cornersize{\pst@number\pslinearc false }%
  \else\def\psk@cornersize{\psk@framearc true }%
  \fi}
\psset[pstricks]{cornersize=relative}
%
\def\tx@Rect{Rect }
\def\tx@OvalFrame{OvalFrame }
\def\tx@Frame{Frame }
%
\define@key[psset]{pstricks}{dimen}[outer]{\pst@expandafter\psset@@dimen{#1}\@nil}
\def\psset@@dimen#1#2\@nil{%
  \if #1o\relax%	outer
    \def\psk@dimen{.5 }%
  \else
    \if #1m\relax%	middle
      \def\psk@dimen{0 }%
    \else
      \if #1i\relax%	inner
        \def\psk@dimen{-.5 }%
  \fi\fi\fi}
\psset[pstricks]{dimen=outer}
%
\def\psframe{\pst@object{psframe}}
\def\psframe@i(#1){%
  \@ifnextchar({\psframe@ii(#1)}{\psframe@ii(0,0)(#1)}}
\def\psframe@ii(#1)(#2){%
  \begin@ClosedObj
    \pst@getcoor{#1}\pst@tempa
    \pst@@getcoor{#2}%
    \addto@pscode{ \psk@cornersize \pst@tempa \pst@coor \psk@dimen \tx@Frame }%
    \def\pst@linetype{2}%
    \showpointsfalse
  \end@ClosedObj
}

\iffalse
\def\psSquare{\pst@object{psSquare}}
\def\psSquare@i(#1)(#2){%
  \begin@ClosedObj
    \pst@getcoor{#1}\pst@tempa
    \pst@getcoor{#2}\pst@tempb
    \addto@pscode{ \psk@cornersize 
      \pst@tempa /yA ED /xA ED 
      \pst@tempb /yB ED /xB ED
      xA yA moveto xB yB L
      xA xB sub yA yB sub atan /Angle ED
      xA yA xB yB Pyth2 dup xA add exch yA add 
      \psk@dimen 
      \tx@Frame 
%      grestore
    }%
    \def\pst@linetype{2}%
    \showpointsfalse
  \end@ClosedObj
}
\fi
%
\def\psTextFrame{\pst@object{psTextFrame}}
\def\psTextFrame@i(#1)(#2)#3{%
  \addbefore@par{ref=c}%	to prevent an empty value
  \leavevmode%
  \pst@killglue
  \begingroup
  \use@par
  \ifx\psk@yref\relax \def\psk@yref{0}\fi% no Baseline possible
  \SpecialCoor
  \pst@getcoor{#1}\pst@tempA
  \pst@getcoor{#2}\pst@tempB
  \if@star\psframe*(#1)(#2)\else\psframe(#1)(#2)\fi
  \rput(! \pst@tempA \pst@tempB % x1 y1 x2 y2
    exch 4 -1 roll 		% y1 y2 x2 x1
    dup /x1 ED			% y1 y2 x2 x1
    sub /dx ED			% y1 y2 
    exch dup /y1 ED 		% y2 y1
    sub /dy ED	
    x1 dx \psk@xref\space mul add \pst@number\psxunit div 
    y1 dy \psk@yref\space mul add \pst@number\psyunit div ){#3}
  \endgroup
  \ignorespaces}
%
\def\tx@BezierNArray{ BezierNArray }
\def\tx@OpenBezier{ OpenBezier }
\def\tx@ClosedBezier{ ClosedBezier }
\def\tx@BezierShowPoints{ BezierShowPoints }
\def\tx@BezierCurve{ BezierCurve }
\def\pst@BezierType{2 }	% the default
%
\def\psbezier{\pst@object{psbezier}}
\def\psbezier@i{%
  \pst@getarrows{%
    \begin@OpenObj
      \pst@getcoors[\psbezier@ii%
  }%
}
\def\psbezier@ii{%
  \addto@pscode{
    \ifPst@noCurrentPoint\else\pst@cp\fi
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol \psls@symbol OpenSymbolBezier 
    \else 
      \tx@OpenBezier 
      \ifshowpoints \tx@BezierShowPoints \fi
    \fi
  }%
  \def\pst@linetype{1}%
  \ifx\pslinestyle\psls@@symbol\def\pslinestyle{none}\fi%
  \end@OpenObj}
%
\def\pscbezier{\def\pst@par{}\pst@object{pscbezier}}
\def\pscbezier@i{%
  \begin@ClosedObj
  \pst@getcoors[\pscbezier@ii}
%
\def\pscbezier@ii{%
  \addto@pscode{%
    \ifshowpoints true \else false \fi
    \ifx\pslinestyle\psls@@symbol \psls@symbol ClosedSymbolBezier 
    \else 
      \tx@ClosedBezier
      \ifshowpoints \tx@BezierShowPoints \fi
    \fi}%
%  \chardef\pst@linetype=1
  \def\pst@linetype{1}%
  \ifx\pslinestyle\psls@@symbol\def\pslinestyle{none}\fi%
  \end@ClosedObj}
%
\iffalse
\define@key[psset]{pstricks}{epsilon}[0.005]{\pst@checknum{#1}\psk@epsilon}
\psset[pstricks]{epsilon=0.005}		% 200 steps for one curve
%
\def\psBezier#1{%		% allowed order is 1 ... 9
  \ifnum#1>0 \ifnum#1<10 \def\pst@BezierType{#1 }\fi\fi%
  \def\pst@par{}\pst@object{psBezier}}
\def\psBezier@i{%
  \pst@getarrows{%
    \begin@OpenObj
    \pst@getcoors[\psBezier@ii%
}}
\def\psBezier@ii{%
  \addto@pscode{%
    \psk@epsilon	    	% step for Bezier T=0,0+epsilon,0+i*epsilon,...,1
    \pst@BezierType 		% type of the Bezier curve 2,3,4,... 
    \tx@BezierCurve
    \ifshowpoints \tx@BezierShowPoints \fi
  }%
  \end@OpenObj}
\fi
%
\define@key[psset]{pstricks}{pType}[0]{\pst@cntg=#1\relax\edef\psk@pType{\the\pst@cntg}}
\psset[pstricks]{pType=0}
\def\tx@Parab{Parab }%	 given by 1 point and the min/max
\def\tx@Parabo{Parab1 }% given by 2 points for y-a=(x-b)^2
%
\def\psparabola{\pst@object{psparabola}}%  2009-05-19 (hv)
\def\psparabola@i{\pst@getarrows\psparabola@ii}
\def\psparabola@ii#1(#2)#3(#4){%  #2 P #4 SP
  \begin@OpenObj
  \pst@getcoor{#2}\pst@tempa
  \pst@@getcoor{#4}%
  \addto@pscode{\pst@tempa \pst@coor 
    \ifcase\psk@pType
      \tx@Parab \or
      \tx@Parabo
    \fi}%
  \end@OpenObj}
\let\parabola\psparabola% compatibility  (hv)
%
%
\define@key[psset]{pstricks}{gridwidth}[0.8pt]{\pst@getlength{#1}\psk@gridwidth}
\psset[pstricks]{gridwidth=.8pt}
\define@key[psset]{pstricks}{griddots}[0]{%
  \pst@cntg=#1\relax
  \edef\psk@griddots{\the\pst@cntg}}
\psset[pstricks]{griddots=0}
\define@key[psset]{pstricks}{gridcolor}[black]{\pst@getcolor{#1}\psgridcolor}
\psset[pstricks]{gridcolor=black}
\define@key[psset]{pstricks}{subgridwidth}[0.4pt]{\pst@getlength{#1}\psk@subgridwidth}
\psset[pstricks]{subgridwidth=0.4pt}
\define@key[psset]{pstricks}{subgridcolor}[gray]{\pst@getcolor{#1}\pssubgridcolor}
\psset[pstricks]{subgridcolor=gray}
\define@key[psset]{pstricks}{subgriddots}[0]{%
  \pst@cntg=#1\relax\edef\psk@subgriddots{\the\pst@cntg}}
\psset[pstricks]{subgriddots=0}
\define@key[psset]{pstricks}{subgriddiv}[5]{%
  \pst@cntg=#1\relax\edef\psk@subgriddiv{\the\pst@cntg}}
\psset[pstricks]{subgriddiv=5}
%
\define@key[psset]{pstricks}{gridfont}[Helvetica]{\def\psk@gridfont{/#1 }}%   hv 2007-11-13
\psset[pstricks]{gridfont=Helvetica}
%
\define@key[psset]{pstricks}{gridlabels}[10pt]{\pst@getlength{#1}\psk@gridlabels}
\psset[pstricks]{gridlabels=10pt}
\define@key[psset]{pstricks}{gridlabelcolor}[black]{\pst@getcolor{#1}\psgridlabelcolor}
\psset[pstricks]{gridlabelcolor=black}

\def\tx@Grid{Grid }

\def\psgrid{\pst@object{psgrid}}
\def\psgrid@i{\@ifnextchar({\psgrid@ii}{\expandafter\psgrid@iv\pic@coor}}
\def\psgrid@ii(#1){\@ifnextchar({\psgrid@iii(#1)}{\psgrid@iv(0,0)(0,0)(#1)}}
\def\psgrid@iii(#1)(#2){\@ifnextchar({\psgrid@iv(#1)(#2)}{\psgrid@iv(#1)(#1)(#2)}}
\def\psgrid@iv(#1)(#2)(#3){%
  \begin@SpecialObj%
    \pst@getcoor{#1}\pst@tempA%  hv 1.11
    \pst@getcoor{#2}\pst@tempB%  hv 1.11
    \pst@@getcoor{#3}%
    \ifnum\psk@subgriddiv>1\relax
      \addto@pscode{
        gsave
        \tx@setStrokeTransparency
        \psk@subgridwidth SLW 
        \pst@usecolor\pssubgridcolor
        \pst@tempB \pst@coor \pst@tempA                 % hv 1.11
%        \pst@number\psxunit \pst@number\psyunit        % hv 1.11
        \pst@number\psxunit abs \pst@number\psyunit abs % hv 1.11
        \psk@subgriddiv\space \psk@subgriddots\space
        {} 0 
        \psk@gridfont findfont 0 scalefont setfont      % hv 1.16
	\tx@Grid 
	grestore
      }%
    \fi%
    \addto@pscode{
      gsave
      \tx@setStrokeTransparency
      \psk@gridwidth SLW 
      \pst@usecolor\psgridcolor
      \pst@tempB \pst@coor \pst@tempA                 % hv 1.11
      \pst@number\psxunit abs \pst@number\psyunit abs % hv 1.11
%      \pst@number\psxunit \pst@number\psyunit        % hv 1.11
      1 \psk@griddots\space { \pst@usecolor\psgridlabelcolor }
      \psk@gridlabels 
      \psk@gridfont findfont \psk@gridlabels scalefont setfont  % hv 1.16
       \tx@Grid 
      grestore
    }%
  \end@SpecialObj}
%
\newif\ifpsmathbox
\psmathboxtrue
\def\pst@mathflag{\z@}
\newtoks\everypsbox
\let\pst@thisbox\relax
%
\long\def\pst@makenotverbbox#1#2{%
  \edef\pst@mathflag{%
  \ifpsmathbox\ifmmode\ifinner 1\else 2\fi\else\z@\fi\else\z@\fi}%
  \setbox\pst@hbox=\hbox{%
    \ifcase\pst@mathflag\or$\m@th\textstyle\or$\m@th\displaystyle\fi%
    {\pst@thisbox\the\everypsbox#2}%
    \ifnum\pst@mathflag>\z@$\fi%                                     $
  }%
  #1}
%
\def\pst@makeverbbox#1{%
  \def\pst@afterbox{#1}%
  \edef\pst@mathflag{\ifpsmathbox\ifmmode\ifinner1\else2\fi\else\z@\fi\else\z@\fi}%
  \afterassignment\pst@beginbox%
  \setbox\pst@hbox\hbox%
}
\def\pst@beginbox{%
  \ifcase\pst@mathflag\or$\m@th\or$\m@th\displaystyle\fi%
  \bgroup\aftergroup\pst@endbox%
  \pst@thisbox%
  \the\everypsbox%
}
\def\pst@endbox{%
  \ifnum\pst@mathflag>\z@\relax$\fi%                      $
  \egroup%
  \pst@afterbox%
}
\def\pst@makebox{\pst@@makebox}
\def\psverbboxtrue{\def\pst@@makebox{\pst@makeverbbox}}
\def\psverbboxfalse{\def\pst@@makebox{\pst@makenotverbbox}}
\psverbboxfalse
\def\pst@longbox{%
  \def\pst@makebox{%
    \gdef\pst@makebox{\pst@@makebox}%
    \pst@makelongbox%
  }%
}
\def\pst@makelongbox#1{%
  \def\pst@afterbox{#1}%
  \edef\pst@mathflag{%
    \ifpsmathbox\ifmmode\ifinner 1\else 2\fi\else \z@\fi\else \z@\fi%
  }%
  \setbox\pst@hbox\hbox\bgroup
  \aftergroup\pst@afterbox
  \ifcase\pst@mathflag\or$\m@th\or$\m@th\displaystyle\fi
  \begingroup
  \pst@thisbox
  \the\everypsbox%
}
\def\pst@endlongbox{%
  \endgroup
  \ifnum\pst@mathflag>\z@$\fi		%$
  \egroup%
}
\def\pslongbox#1#2{%
  \@namedef{#1}{\pst@longbox#2}%
  \@namedef{end#1}{\pst@endlongbox}}
%
\newdimen\psframesep
\define@key[psset]{pstricks}{framesep}[3pt]{\pssetlength\psframesep{#1}}
\psset[pstricks]{framesep=3pt}
%
\define@boolkey[psset]{pstricks}[ps]{boxsep}[true]{}
\psset[pstricks]{boxsep}
%
\def\pst@useboxpar{%
  \use@par%
  \if@star%
    \let\pslinecolor\psfillcolor%
    \solid@star%
    \let\solid@star\relax
  \fi%
  \ifpsdoubleline \pst@setdoublesep \fi}
%
\def\psframebox{\def\pst@par{}\pst@object{psframebox}}
\def\psframebox@i{\pst@makebox\psframebox@ii}
\def\psframebox@ii{%
  \begingroup
  \pst@useboxpar
  \pst@dima=\pslinewidth
  \advance\pst@dima by \psframesep
  \pst@dimc=\wd\pst@hbox\advance\pst@dimc by \pst@dima
  \pst@dimb=\dp\pst@hbox\advance\pst@dimb by \pst@dima
  \pst@dimd=\ht\pst@hbox\advance\pst@dimd by \pst@dima
  \setbox\pst@hbox=\hbox{%
    \ifpsboxsep\kern\pst@dima\fi
    \begin@ClosedObj
    \addto@pscode{%
      \psk@cornersize % arcradius boolean
      \pst@number\pst@dima neg
      \pst@number\pst@dimb neg
      \pst@number\pst@dimc
      \pst@number\pst@dimd
      .5
      \tx@Frame%
    }%
    \def\pst@linetype{2}%
    \showpointsfalse
    \end@ClosedObj
    \box\pst@hbox
    \ifpsboxsep\kern\pst@dima\fi%
  }%
  \ifpsboxsep\dp\pst@hbox=\pst@dimb\ht\pst@hbox=\pst@dimd\fi
  \leavevmode\box\pst@hbox
  \endgroup}
%
\def\psdblframebox{\def\pst@par{}\pst@object{psdblframebox}}
\def\psdblframebox@i{\addto@par{doubleline=true}\psframebox@i}
%
\define@key[psset]{pstricks}{clipcommand}[clip]{\def\pst@clipcommand{#1 }}
\psset[pstricks]{clipcommand=clip}% alternative is eoclip
%
\def\psclip{\@ifnextchar[\psclip@i{\psclip@i[]}}%
\def\psclip@i[#1]#2{%
  \leavevmode%
  \begingroup%
    \ifx\relax#1\relax\else\psset{#1}\fi%
    \begin@psclip%
      \begingroup%
        \def\use@pscode{%
          \pstVerb{
            \pst@dict
            /mtrxc CM def
            CP CP T
            \tx@STV
            \psk@origin
            \psk@swapaxes
            newpath
            \pst@code
            \pst@clipcommand
            newpath
            mtrxc setmatrix
            moveto
            0 setgray
            end
	  }%
          \gdef\pst@code{}}%
  \def\@multips(##1)(##2)##3##4{\pst@misplaced\multips}%
  \def\nc@object##1##2##3##4{\pst@misplaced{node connection}}%
  \hbox to\z@{#2}%
  \endgroup%
  \def\endpsclip{%
    \end@psclip%
    \endgroup}%
  \ignorespaces}
%
\def\endpsclip{\pst@misplaced\endpsclip}
\let\begin@psclip\relax
\def\end@psclip{\pstVerb{currentpoint initclip moveto}}
%
\def\AltClipMode{%
  \def\end@psclip{\pstVerb{\pst@grestore}}%
  \def\begin@psclip{\pstVerb{gsave}}}
  \def\clipbox{\@ifnextchar[{\clipbox@}{\clipbox@[\z@]}}
% DG modification begin - Apr. 3, 1997
% From paulus@immd5.informatik.uni-erlangen.de (Dietrich Paulus)
%\def\clipbox@[#1]{\pst@makebox\clipbox@@{#1}}
\def\clipbox@[#1]{\pst@makebox{\clipbox@@{#1}}}
% DG modification end
\def\clipbox@@#1{%
  \pssetlength\pst@dimg{#1}%
  \leavevmode\hbox{%
  \begin@psclip%
  \pst@Verb{
    CM \tx@STV CP T newpath
    /a \pst@number\pst@dimg def
    /w \pst@number{\wd\pst@hbox}a add def
    /d \pst@number{\dp\pst@hbox}a add neg def
    /h \pst@number{\ht\pst@hbox}a add def
    a neg d moveto
    a neg h L
    w h L
    w d L
    closepath
    \pst@clipcommand
    newpath
    0 0 moveto
    setmatrix}%
  \unhbox\pst@hbox%
  \end@psclip}}
%
\def\psshadowbox{\def\pst@par{}\pst@object{psshadowbox}}
\def\psshadowbox@i{\pst@makebox\psshadowbox@ii}
\def\psshadowbox@ii{%
\begingroup
\pst@useboxpar
\psshadowtrue
\psboxseptrue
\def\psk@shadowangle{-45 }%
\setbox\pst@hbox=\hbox{\psframebox@ii}%
\pst@dimh=\psk@shadowsize\p@
\pst@dimh=.7071\pst@dimh
\pst@dimg=\dp\pst@hbox
\advance\pst@dimg\pst@dimh
\dp\pst@hbox=\pst@dimg
\pst@dimg=\wd\pst@hbox
\advance\pst@dimg\pst@dimh
\wd\pst@hbox=\pst@dimg
\leavevmode
\box\pst@hbox
\endgroup}
%
\def\pscirclebox{\pst@object{pscirclebox}}
\def\pscirclebox@i{\pst@makebox\pscirclebox@ii}
\def\pscirclebox@ii{%
\begingroup%
\pst@useboxpar%
\setbox\pst@hbox=\hbox{%
\pst@nodehook%
\pscirclebox@iii%
\box\pst@hbox}%
\ifpsboxsep\pscirclebox@sep\fi%
\leavevmode%
\box\pst@hbox%
\endgroup}
%
\def\pscirclebox@iii{%
  \if@star%
    \pslinewidth\z@%
    \pstverb{\pst@dict \tx@STP \pst@usecolor\psfillcolor
             newpath \pscirclebox@iv \tx@SD end}%
  \else%
    \begin@ClosedObj%
    \def\pst@linetype{4}\showpointsfalse%
    \addto@pscode{ \pscirclebox@iv\space CLW 2 div add 0 360 arc closepath}%
    \end@ClosedObj%
  \fi}
%
\def\pscirclebox@iv{
  \pst@number{\wd\pst@hbox} 2 div
  \pst@number{\ht\pst@hbox} \pst@number{\dp\pst@hbox} add 2 div
  2 copy \pst@number{\dp\pst@hbox} sub 4 2 roll
  \tx@Pyth \pst@number\psframesep add }
%
\def\pscirclebox@sep{%
  \pst@dimn=\ht\pst@hbox%			% the height of the box
  \advance\pst@dimn by \dp\pst@hbox%		% the depth  of the box added to \pst@dimn
  \divide\pst@dimn by 2%			% \pst@dimn/2
  \pst@dimm=0.5\wd\pst@hbox%			% the half of the width
  \pst@Pyth\pst@dimm\pst@dimn\pst@dimo%		% the diameter
  \advance\pst@dimo by \pslinewidth%
  \advance\pst@dimo by \psframesep%
  \advance\pst@dimn by -\pst@dimo%
  \setbox\pst@hbox=\hbox to 2\pst@dimo{\hss\vbox{\kern-\pst@dimn\box\pst@hbox}\hss}%
  \advance\pst@dimn by -\dp\pst@hbox%
  \dp\pst@hbox=-\pst@dimn}
%  
\let\pst@nodehook\relax
%
\def\psCirclebox{\def\pst@par{}\pst@object{psCirclebox}}
\def\psCirclebox@i{\pst@makebox\psCirclebox@ii}
\def\psCirclebox@ii{%
  \begingroup
  \pst@useboxpar
  \pst@dima=\ht\pst@hbox
  \advance\pst@dima\dp\pst@hbox
  \divide\pst@dima\tw@
  \pssetlength\pst@dimb\psk@radius
  \setbox\pst@hbox=\hbox{%
    \pst@nodehook
    \pscircle(.5\wd\pst@hbox,\pst@dima){\pst@dimb}%
    \box\pst@hbox}%
  \ifpsboxsep \psCirclebox@sep \fi
  \leavevmode
  \box\pst@hbox
  \endgroup}
%
\def\psCirclebox@sep{%
  \pst@dimc=\pst@dimb
  \advance\pst@dimb-\pst@dima
  \advance\pst@dima\pst@dimc
  \setbox\pst@hbox=\hbox to\tw@\pst@dimc{%
    \hss\vrule width \z@ depth \pst@dimb height \pst@dima
    \box\pst@hbox\hss}}
%
\def\psovalbox{\def\pst@par{}\pst@object{psovalbox}}
\def\psovalbox@i{\pst@makebox{\psovalbox@ii}}
\def\psovalbox@ii{%
  \begingroup
  \pst@useboxpar
  \psovalbox@iii
  \ifpsboxsep\psovalbox@sep\fi
  \leavevmode
  \box\pst@hbox
  \endgroup}
%
\def\psovalbox@iii{%
  \psovalbox@iv
  \setbox\pst@hbox=\hbox{%
    \begin@ClosedObj
    \addto@pscode{%
      0 360
      \pst@number\pst@dimc CLW 2 div sub
      \pst@number\pst@dimd CLW 2 div sub
      \pst@number\pst@dima
      \pst@number\pst@dimb
      \tx@Ellipse
      closepath }%
    \def\pst@linetype{2}%
    \end@ClosedObj
    \unhbox\pst@hbox}}
%
\def\psovalbox@iv{%
  \pst@dimc=\pslinewidth\advance\pst@dimc\psframesep
  \pst@dimd=\ht\pst@hbox\advance\pst@dimd\dp\pst@hbox
  \pst@dima=.5\wd\pst@hbox
  \pst@dimb=.5\pst@dimd\advance\pst@dimb-\dp\pst@hbox
  \pst@dimd=.707\pst@dimd
  \advance\pst@dimd\pst@dimc
  \advance\pst@dimc.707\wd\pst@hbox}
%
\def\psovalbox@sep{%
  \setbox\pst@hbox\hbox to 2\pst@dimc{\hss\unhbox\pst@hbox\hss}%
  \pst@dimg=\pst@dimd
  \advance\pst@dimg-\pst@dimb
  \dp\pst@hbox=\pst@dimg
  \advance\pst@dimd\pst@dimb
  \ht\pst@hbox=\pst@dimd}
%
\def\psdiabox{\def\pst@par{}\pst@object{psdiabox}}
\def\psdiabox@i{\pst@makebox{\psdiabox@ii}}
\def\psdiabox@ii{%
\begingroup
\pst@useboxpar
\psdiabox@iii
\ifpsboxsep\psdiabox@sep\fi
\leavevmode
\box\pst@hbox
\endgroup}
\def\psdiabox@iv{%
\pst@dimg=.707\pslinewidth
\advance\pst@dimg.707\psframesep
\pst@dima=\wd\pst@hbox
\divide\pst@dima 2
\pst@dimc=\pst@dima
\advance\pst@dimc\pst@dimg
\pst@dimd=\ht\pst@hbox
\advance\pst@dimd\dp\pst@hbox
\divide\pst@dimd 2
\pst@dimb=\pst@dimd
\advance\pst@dimb-\dp\pst@hbox
\advance\pst@dimd\pst@dimg}
\def\psdiabox@iii{%
\psdiabox@iv
\setbox\pst@hbox=\hbox{%
\begin@ClosedObj
\addto@pscode{%
\psline@iii
pop
.5
\pst@number\pst@dimc 2 mul \pst@number\pst@dimd 2 mul
0
\pst@number\pst@dima \pst@number\pst@dimb
\tx@Diamond}%
\def\pst@linetype{4}%
\end@ClosedObj
\box\pst@hbox}}
\def\psdiabox@sep{%
\setbox\pst@hbox\hbox to 4\pst@dimc{\hss\unhbox\pst@hbox\hss}%
\multiply\pst@dimd 2
\advance\pst@dimd\pst@dimb
\ht\pst@hbox\pst@dimd
\advance\pst@dimd-2\pst@dimb
\dp\pst@hbox\pst@dimd}
%
\define@key[psset]{pstricks}{trimode}[U]{\pst@expandafter\psset@@trimode{#1}\@empty\@empty\@nil}
\def\psset@@trimode#1#2#3\@nil{%
  \let\pst@tempg#1\relax
  \ifx\pst@tempg*
    \let\psk@@trimode\@empty
    \let\pst@tempg#2\relax
  \else
    \let\psk@@trimode\relax
  \fi
  \edef\psk@trimode{%
    \ifx R\pst@tempg 1 % Right
    \else
      \ifx D\pst@tempg 2 % Down
      \else
        \ifx L\pst@tempg 3 % Left
        \else 
          \ifx l\pst@tempg 4 % |_
          \else
            \ifx r\pst@tempg 5 % _|
            \else 0 \fi     % Up
          \fi
        \fi
      \fi
    \fi}%
}
\psset[pstricks]{trimode=U}
%
\def\pstribox{\pst@object{pstribox}}
\def\pstribox@i{\pst@makebox{\pstribox@ii}}
\def\pstribox@ii{%
  \begingroup
  \pst@useboxpar
  \pstribox@iii
  \ifpsboxsep\pstribox@sep\fi
  \leavevmode
  \box\pst@hbox
  \endgroup}
%
\def\pstribox@iii{%
  \pstribox@iv
  \setbox\pst@hbox=\hbox{%
    \begin@ClosedObj
    \addto@pscode{
      \psline@iii
      pop
      0.5
      \pst@number\pst@dimc % Width
      \pst@number\pst@dimd % Height
      \ifcase\psk@trimode  
             \or  %% 0
        exch \or  %% 1
             \or  %% 2
        exch \or  %% 3
             \or  %% 4
             \or  %% 5
      \fi
      \psk@trimode -90 mul
      \pst@number\pst@dima % x coor for text
      \pst@number\pst@dimb % y coor for text
      \tx@Triangle}%
    \def\pst@linetype{2}%
    \end@ClosedObj
    \box\pst@hbox}%
}
%
\def\pstribox@iv{%
  \pst@dimh=\pslinewidth
  \advance\pst@dimh\psframesep
  \pst@dimg=\ht\pst@hbox
  \advance\pst@dimg-\dp\pst@hbox         % totalheight
  \divide\pst@dimg 2                     % 0.5 totalheight
  \edef\pst@tempa{\number\pst@dimg sp}%  % For use by nodes.
  \ifodd\psk@trimode                     % 
    \pst@dimb\pst@dimg
  \else
    \pst@dima=\wd\pst@hbox
    \divide\pst@dima 2
  \fi
  \ifcase\psk@trimode
    \pst@dimb=-\dp\pst@hbox
    \advance\pst@dimb-\pst@dimh
  \or\pst@dima=-\pst@dimh
  \or\pst@dimb=\ht\pst@hbox
     \advance\pst@dimb\pst@dimh
  \or\pst@dima=\wd\pst@hbox
     \advance\pst@dima\pst@dimh
  \fi
  \pst@dimd=\dp\pst@hbox
  \advance\pst@dimd\ht\pst@hbox
  \ifx\psk@@trimode\relax% no star for trimode=
    \pst@dimc=\wd\pst@hbox
    \advance\pst@dimc\ifodd\psk@trimode 1.447\else 1.789\fi\pst@dimh
    \multiply\pst@dimc 2
    \advance\pst@dimd\ifodd\psk@trimode 1.789\else 1.447\fi\pst@dimh
    \multiply\pst@dimd 2
  \else% trimode=R*,L*,U*,D*
    \ifodd\psk@trimode
      \advance\pst@dimd 1.1547\wd\pst@hbox
      \advance\pst@dimd 3.4641\pst@dimh
      \pst@dimc=.866\pst@dimd
    \else
      \advance\pst@dimd .866\wd\pst@hbox %.866=(sqrt(3)/2)
      \advance\pst@dimd 3\pst@dimh 
      \pst@dimc=1.1547\pst@dimd % 1.1547=(2/sqrt(3))
    \fi
  \fi}
%
\def\pstribox@sep{%
\ifodd\psk@trimode
\advance\pst@dimb.5\pst@dimd
\ht\pst@hbox=\pst@dimb
\advance\pst@dimd-\pst@dimb
\dp\pst@hbox=\pst@dimd
\else
\setbox\pst@hbox\hbox to \pst@dimc{\hss\unhbox\pst@hbox\hss}%
\global\pst@dimg=.5\pst@dimc
\fi
\ifcase\psk@trimode
\dp\pst@hbox-\pst@dimb
\advance\pst@dimd\pst@dimb
\ht\pst@hbox\pst@dimd
\or
\pst@dimg=.5\wd\pst@hbox
\global\advance\pst@dimg-\pst@dima
\setbox\pst@hbox\hbox to \pst@dimc{\kern-\pst@dima\box\pst@hbox\hss}%
\or
\ht\pst@hbox\pst@dimb
\advance\pst@dimd-\pst@dimb
\dp\pst@hbox\pst@dimd
\or
\pst@dimg=\pst@dimc
\advance\pst@dimg-\pst@dima
\global\advance\pst@dimg.5\wd\pst@hbox
\setbox\pst@hbox\hbox to \pst@dimc{%
\hss\box\pst@hbox\kern\psframesep\kern\pslinewidth}%
\fi}
%
\define@key[psset]{pstricks}{arcsepA}[0]{\pst@getlength{#1}\psk@arcsepA}
\define@key[psset]{pstricks}{arcsepB}[0]{\pst@getlength{#1}\psk@arcsepB}
\define@key[psset]{pstricks}{arcsep}[0]{%
  \pst@getlength{#1}\psk@arcsepA\let\psk@arcsepB\psk@arcsepA}
\psset[pstricks]{arcsep=0}
\def\tx@ArcArrow{ArcArrow }
%
\def\psarc{\pst@object{psarc}}
\def\psarc@i{\@ifnextchar({\psarc@iii}{\psarc@ii}}
\def\psarc@ii#1{\addto@par{arrows=#1}\@ifnextchar(\psarc@iii{\psarc@iii(0,0)}}
\def\psarc@iii(#1)#2#3#4{%
  \begin@OpenObj%
    \pst@getangle{#3}\pst@tempa%
    \pst@getangle{#4}\pst@tempb%
    \ifx\pst@tempa\pst@tempb\else%
      \pst@@getcoor{#1}%
      \pssetlength\pst@dima{#2}%
      \addto@pscode{\psarc@iv \psarc@v
        \ifPst@variableLW \pst@flattenpath \fi
      }%
      \gdef\psarc@type{0}%
      \showpointsfalse%
    \fi%
  \end@OpenObj%
}
\def\psarc@iv{%
  \pst@coor /y ED /x ED
  /r \ifPst@SpecialLength \pst@SpecialLength \else \pst@number\pst@dima \fi def
  /c 57.2957 r \tx@Div def
  /angleA
    \pst@tempa
    \psk@arcsepA c mul 2 div
    \ifcase\psarc@type add \or sub \fi
  def
  /angleB
    \pst@tempb
    \psk@arcsepB c mul 2 div
    \ifcase\psarc@type sub \or add \fi
  def
  \ifshowpoints\psarc@showpoints\fi
  \ifx\psk@arrowA\@empty
    \ifnum\psk@liftpen=2
      r angleA \tx@PtoC
      y add exch x add exch moveto
    \fi
  \fi}
% hv ---- 1.10 2005-05-05 ----------------------> hv begin
\def\psarc@v{%
  /angleAtoB angleB angleA gt { true }{ false } ifelse def
  x y r
  angleA
  \ifx\psk@arrowA\@empty\else
    { ArrowA CP }
    r 0 gt \pslbrace
    { \ifcase\psarc@type add \or sub \fi } \psrbrace\pslbrace
    { \ifcase\psarc@type sub \or add \fi } \psrbrace ifelse
%    { \ifcase\psarc@type add \or sub \fi }
    \tx@ArcArrow
%    dup AngleA gt AngleAtoB exor { neg } fi
  \fi
  angleB
  \ifx\psk@arrowB\@empty\else
    { ArrowB }
    r 0 gt \pslbrace
      { \ifcase\psarc@type sub \or add \fi } \psrbrace\pslbrace
      { \ifcase\psarc@type add \or sub \fi } \psrbrace ifelse
%      { \ifcase\psarc@type sub \or add \fi }
    \tx@ArcArrow
    dup angleA gt angleAtoB xor { pop angleA } if
  \fi
\ifcase\psarc@type arc \or arcn \fi}
% hv ----- 1.10 2005-05-05 ------------------------> end
%
\def\psarc@type{0}
\def\psarc@showpoints{%
  gsave
  newpath
  x y moveto
  x y r \pst@tempa \pst@tempb
  \ifcase\psarc@type arc \or arcn \fi
  closepath
  CLW 2 div SLW
  [ \psk@dash\space ] 0 setdash stroke
  grestore }
\def\psarcn{\def\pst@par{}\pst@object{psarcn}}
\def\psarcn@i{\def\psarc@type{1}\psarc@i}
%
\def\psarcAB{\pst@object{psarcAB}}%		hv 2008-11-26
\def\psarcAB@i{%
  \addbefore@par{psscale=1}% be sure, that it is defined
  \pst@getarrows{%
    \begin@OpenObj%
      \pst@getcoors{}\psarcAB@ii%
    }%
}
\def\psarcAB@ii{%
  \addto@pscode{
  /y ED /x ED /yA ED /xA ED /yB ED /xB ED 
  /r xB yB x y Pyth2 \psk@psscale\space mul def
  /c 57.2957 r \tx@Div def
  /angleA
    yA y sub xA x sub atan
    \psk@arcsepA c mul 2 div
    \ifcase\psarc@type add \else sub \fi
  def
  /angleB
    yB y sub xB x sub atan
    \psk@arcsepB c mul 2 div
    \ifcase\psarc@type sub \else add \fi 
  def
  \ifx\psk@arrowA\@empty
    \ifnum\psk@liftpen=2
      r angleA \tx@PtoC
      y add exch x add exch moveto
    \fi
  \fi
  \psarc@v }%
  \gdef\psarc@type{0}%
  \showpointsfalse%
  \end@OpenObj%
}
\def\psarcnAB{\def\pst@par{}\pst@object{psarcnAB}}
\def\psarcnAB@i{\def\psarc@type{1}\psarcAB@i}
%
%------------------ tvz/DG/hv (2004-05-10) begin -------------------%%
% from Denis Giroux: http://www.tug.org/pipermail/pstricks/2001/000507.html
%
% I - Definition of \psellipticwedge, a generalization of \pswedge for wedges
%     of ellipses (from the code of \pswedge and \psellipse)
%
\def\psellipticwedge{\pst@object{psellipticwedge}}
\def\psellipticwedge@i(#1){%
  \@ifnextchar({\psellipticwedge@ii(#1)}{\psellipticwedge@ii(0,0)(#1)}}
\def\psellipticwedge@ii(#1)(#2)#3#4{%
  \begin@ClosedObj
    \pst@getangle{#3}\pst@tempa
    \pst@getangle{#4}\pst@tempb
    \pst@getcoor{#1}\pst@tempc
    \pst@@getcoor{#2}%
    \def\pst@linetype{1}%
    \addto@pscode{%
      \pst@coor /ry ED /rx ED
      \ifx\psk@rot\@empty \else \psk@rot\space rotate \fi
      \pst@tempa 
      \ifPst@correctAngle
       cvi 90 mod 0 eq { \pst@tempa } 
         { rx abs ry abs sub cvi 0 eq { \pst@tempa }{ rx ry
           \tx@UserCoor exch \pst@tempa tan mul exch atan 
            \pst@tempa 180 div 0.5 add floor 
            180 mul sub } ifelse } ifelse
      \fi
      \pst@tempb
      \ifPst@correctAngle
       cvi 90 mod 0 eq { \pst@tempb } 
         { rx abs ry abs sub cvi 0 eq { \pst@tempb }{ rx ry
           \tx@UserCoor exch \pst@tempb tan mul exch atan 
            \pst@tempb 180 div 0.5 add floor 
            180 mul sub } ifelse } ifelse
      \fi
      rx ry
      \pst@tempc moveto
      \ifdim\psk@dimen\p@=\z@\else
        \psk@dimen CLW mul dup 3 1 roll
        sub 3 1 roll sub exch
      \fi
      \pst@tempc
      \tx@Ellipse
      closepath
    }%
  \showpointsfalse
  \end@ClosedObj%
}
%
% Code mainly from "pstricks.tex'' 0.94 beta (TvZ)
%
\def\psellipticarcn{\pst@object{psellipticarcn}}
\def\psellipticarcn@i{\let\if@psarcn\iftrue\psellipticarc@ii}
%
\def\psellipticarc{\pst@object{psellipticarc}}
\def\psellipticarc@i{\let\if@psarcn\iffalse\psellipticarc@ii}
\define@boolkey[psset]{pstricks}[Pst@]{correctAngle}[true]{}
\psset{correctAngle}

\let\if@psarcn\iffalse

\def\psellipticarc@ii{\pst@getarrows\psellipticarc@iii}
\def\psellipticarc@iii(#1){%
  \@ifnextchar({\psellipticarc@iv(#1)}{\psellipticarc@iv(0,0)(#1)}}
\def\psellipticarc@iv(#1)(#2)#3#4{%
%  \addbefore@par{correctAngle=false}
  \begin@OpenObj%
  \pst@getcoor{#1}\pst@tempa    %	origin
  \pst@getcoor{#2}\pst@tempb	%	a b
  \pst@getangle{#3}\pst@tempc	%	start angle
  \pst@getangle{#4}\pst@tempd	% 	end angle
  \addto@pscode{ 
    \psellipticarc@definearg \psellipticarc@draw
    \ifPst@variableLW \pst@flattenpath \fi 
  }%
  \ifshowpoints
    \addto@pscode{
      gsave
      xOrig yOrig T % set origin to ellipse origin
      \ifx\psk@rot\@empty \else \psk@rot\space rotate \fi
      rx ry scale   % now we draw a circle :-)
      1 \pst@tempc  % start angle
      \ifPst@correctAngle
       cvi 90 mod 0 eq { \pst@tempc } 
         { rx abs ry abs sub cvi 0 eq { \pst@tempc }{ rx ry
           \tx@UserCoor exch \pst@tempc tan mul exch atan 
            \pst@tempc 180 div 0.5 add floor 
            180 mul sub } ifelse } ifelse
      \fi
      PtoC moveto 
      0 0 lineto 
      1 \pst@tempd % end angle
      \ifPst@correctAngle
       cvi 90 mod 0 eq { \pst@tempd } 
         { rx ry \tx@UserCoor exch \pst@tempd tan mul exch atan 
            \pst@tempd 180 div .5 add floor 180 mul sub } ifelse 
      \fi
      PtoC lineto
   %  \ifcase\psarc@type arc \or arcn \fi
      CLW 2 div SLW 
      [ 1 1 \tx@UserCoor ] 0 setdash 
      stroke
      grestore 
    }
  \showpointsfalse%
  \fi
  \end@OpenObj%
}
\def\psellipticarc@definearg{%
%  \ifx\psk@rot\@empty \else \psk@rot\space rotate \fi
  \pst@tempa /yOrig ED /xOrig ED  % Origin
  \pst@tempb                      % radii. Now adjust:
  \ifdim\psk@dimen\p@=\z@\else
    \psk@dimen CLW mul dup 3 1 roll
    sub 3 1 roll sub exch
  \fi
  /ry ED /rx ED		% a b
  /angleA
    /d { \if@psarcn sub \else add \fi } def
%    \pst@tempc 
% the angle in the parameter equation is not proportional to the real angle!
% phi=atan(b*tan(angle)/a)+floor(angle/180+0.5)*180
   \pst@tempc 
   \ifPst@correctAngle 
     cvi 90 mod 0 eq { \pst@tempc } 
       { rx ry \tx@UserCoor exch \pst@tempc tan mul exch atan 
          \pst@tempc 180 div .5 add floor 180 mul sub } ifelse 
    \fi
    \psk@arcsepA 2 div
    ArcAdjust
  def
  /angleB
    /d { \if@psarcn add \else sub \fi } def
%    \pst@tempd 
  \pst@tempd 
  \ifPst@correctAngle
     cvi 90 mod 0 eq { \pst@tempd } 
       { rx ry \tx@UserCoor exch \pst@tempd tan mul exch atan 
          \pst@tempd 180 div .5 add floor 180 mul sub } ifelse 
  \fi
  \psk@arcsepB 2 div ArcAdjust  def
%  \ifshowpoints\psellipticarc@showpoints\fi
  \ifx\psk@arrowA\@empty
    \ifnum\psk@liftpen=2
      angleA cos rx mul xOrig add
      angleA sin ry mul yOrig add
      moveto
    \fi%
  \fi%
}
\def\psellipticarc@draw{%
  0 0 1
  angleA
  \ifx\psk@arrowA\@empty\else
    { ArrowA CP }
    { \if@psarcn sub \else add \fi }
    EllipticArcArrow
  \fi
  angleB
  \ifx\psk@arrowB\@empty\else
    { ArrowB }
    { \if@psarcn add \else sub \fi }
    EllipticArcArrow
  \fi
  /mtrx CM def
  xOrig yOrig T
  \ifx\psk@rot\@empty \else \psk@rot\space rotate \fi
  rx ry scale
  \pst@ifcustom\else
    0 0 moveto 
    exch dup dup               % end start start start
    cos exch sin moveto        % end start
    exch                       % start end 
  \fi
%%  \if@star 0 0 moveto \fi	% for filling
  \if@psarcn arcn \else arc \fi
%%  \if@star 0 0 moveto \fi
  mtrx setmatrix%
}
\def\psellipticarc@showpoints{%
  gsave
  /mtrx CM def
  xOrig yOrig T
  rx ry scale
  0 0 moveto
  0 0 1 
  \pst@tempc % start angle
  \ifPst@correctAngle
     cvi 90 mod 0 eq { \pst@tempc } 
       { rx abs ry abs sub cvi 0 eq { \pst@tempc }{ rx ry
         \tx@UserCoor exch \pst@tempc tan mul exch atan 
          \pst@tempc 180 div 0.5 add floor 
          180 mul sub } ifelse } ifelse
    \fi
  \pst@tempd % end angle
   \ifPst@correctAngle
     cvi 90 mod 0 eq { \pst@tempd } 
       { rx abs ry abs sub cvi 0 eq { \pst@tempd } { rx ry 
         \tx@UserCoor exch \pst@tempd tan mul exch atan 
          \pst@tempd 180 div 0.5 add floor 
          180 mul sub } ifelse } ifelse
    \fi
  \ifcase\psarc@type arc \or arcn \fi
  closepath
  mtrx setmatrix
  CLW 2 div SLW
  [ \psk@dash\space ] 0 setdash 
  stroke
  grestore %
}
\def\pscircle{\def\pst@par{}\pst@object{pscircle}}
\def\pscircle@i{\@ifnextchar({\pscircle@do}{\pscircle@do(0,0)}}
\def\pscircle@do(#1)#2{%
  \if@star{\use@par\qdisk(#1){#2}}%   	qdisk does not allow
  \else%				to use opacity option
    \begin@ClosedObj
    \pst@@getcoor{#1}%
    \pssetlength\pst@dimc{#2}%
    \def\pst@linetype{4}%
    \addto@pscode{
      \pst@coor 2 copy moveto
      \ifPst@SpecialLength \pst@SpecialLength \else \pst@number\pst@dimc \fi      
      \psk@dimen CLW mul sub
      dup 0 rmoveto
      0 360 arc
      \ifPst@variableLW \pst@flattenpath \fi
      closepath
    }%
    \showpointsfalse
    \end@ClosedObj
  \fi
  \ignorespaces}
%
\def\pscircleOA{\def\pst@par{}\pst@object{pscircleOA}}%	hv 2008-04-14
\def\pscircleOA@i(#1)(#2){%
  \begin@ClosedObj
  \pst@getcoor{#1}\pst@tempA
  \pst@@getcoor{#2}%
  \def\pst@linetype{4}%
  \addto@pscode{
    \pst@tempA			% x0 y0
    2 copy			% xO yO xO yO 
    \pst@coor			% xO yO xO yO xA yA 
    Pyth2			% xO yO radius
    \psk@dimen CLW mul sub
    \if@star \tx@SD \else
      0 360 arc
      closepath 
    \fi }%
  \showpointsfalse
  \end@ClosedObj
  \ignorespaces}
%
\def\qdisk(#1)#2{%
  \def\pst@par{}%
  \begin@SpecialObj
  \pst@@getcoor{#1}%
  \pssetlength\pst@dimg{#2}%
  \addto@pscode{ 
    \pst@coor 
    \ifPst@SpecialLength \pst@SpecialLength \else \pst@number\pst@dimg \fi
%    \pst@number\pst@dimg 
    \tx@SD }%
  \end@SpecialObj}
%
\define@key[psset]{pstricks}{radius}[0.25cm]{\pst@@getlength{#1}\psk@radius}
\psset[pstricks]{radius=.25cm}
%
\def\psCircle{\pst@object{psCircle}}% same as \pscircle, but uses \psk@radius
\def\psCircle@i{\@ifnextchar({\psCircle@ii}{\psCircle@ii(0,0)}}
\def\psCircle@ii(#1){\pscircle@do(#1){\psk@radius}}
%
\def\psRing{\def\pst@par{}\pst@object{psRing}}%% hv 20130405
\def\psRing@i{\@ifnextchar({\psRing@ii}{\psRing@ii(0,0)}}
\def\psRing@ii(#1){%
  \pst@@getcoor{#1}%
  \@ifnextchar[{\psRing@iii}{\psRing@iii[0,360]}}
\def\psRing@iii[#1,#2]#3#4{%   origin, inner radius, outer radius
  \begin@ClosedObj
  \pssetlength\pst@dimc{#3}%
  \pssetlength\pst@dimd{#4}%
  \pst@getangle{#1}\pst@tempa
  \pst@getangle{#2}\pst@tempb
  \def\pst@linetype{4}%
  \addto@pscode{
    \pst@coor translate 
    \pst@number\pst@dimc \psk@dimen CLW mul sub /InnerRadius ED
    \pst@number\pst@dimd \psk@dimen CLW mul sub /OuterRadius ED
    InnerRadius 0 moveto newpath
    0 0 InnerRadius \pst@tempa\space \pst@tempb\space arc 
    OuterRadius \pst@tempb\space PtoC 
    \pst@tempb\space \pst@tempa\space sub abs 360 eq { moveto }{ lineto } ifelse % whole circle or not??
    0 0 OuterRadius \pst@tempb\space \pst@tempa\space arcn 
    closepath
  }%
  \showpointsfalse
  \end@ClosedObj
  \ignorespaces}
%
\def\pswedge{\def\pst@par{}\pst@object{pswedge}}
\def\pswedge@i{\@ifnextchar({\pswedge@ii}{\pswedge@ii(0,0)}}
\def\pswedge@ii(#1)#2#3#4{%
  \begin@ClosedObj%
  \pssetlength\pst@dimc{#2}%
  \pst@getangle{#3}\pst@tempa%
  \pst@getangle{#4}\pst@tempb%
  \pst@@getcoor{#1}%
  \def\pst@linetype{1}%
  \addto@pscode{
    \ifx\psk@rot\@empty 0 \else \psk@rot \fi rotate
    \pst@coor
    2 copy
    moveto
    \ifPst@SpecialLength \pst@SpecialLength \else \pst@number\pst@dimc \fi
%    \pst@number\pst@dimc 
    \psk@dimen CLW mul sub % Adjusted radius
    \pst@tempa \pst@tempb
    arc
    closepath}%
  \showpointsfalse%
  \end@ClosedObj%
}
\def\tx@ellipse#1{ \ifx\psk@rot\@empty 0 \else \psk@rot \fi #1  Ellipse }
\def\tx@Ellipse{ \ifx\psk@rot\@empty 0 \else \psk@rot \fi Ellipse }
%
\def\psellipse{\def\pst@par{}\pst@object{psellipse}}
\def\psellipse@i(#1){\@ifnextchar({\psellipse@ii(#1)}{\psellipse@ii(0,0)(#1)}}
\def\psellipse@ii(#1)(#2){%
  \begin@ClosedObj
  \pst@getcoor{#1}\pst@tempa
  \pst@@getcoor{#2}%
  \addto@pscode{
    0 360
    \pst@coor 
    \ifdim\psk@dimen\p@=\z@\else
      \psk@dimen CLW mul
      dup 4 -1 roll sub neg 3 1 roll sub
    \fi
    \pst@tempa 
    \tx@ellipse{true}
    \ifPst@variableLW \pst@flattenpath \fi
    closepath
  }%
  \def\pst@linetype{2}%
  \end@ClosedObj%
}
\def\psellipseAB{\def\pst@par{}\pst@object{psellipseAB}}
\def\psellipseAB@i(#1)(#2)#3{%
  \begin@ClosedObj
  \pst@getcoor{#1}\pst@tempa
  \pst@getcoor{#2}\pst@tempb
  \addto@pscode{
    0 360
    #3 \pst@number\psxunit mul
    \pst@tempa /yA ED /xA ED
    \pst@tempb /yB ED /xB ED
    xA xB sub dup mul
    yA yB sub dup mul add sqrt 2 div
    \ifdim\psk@dimen\p@=\z@\else
      \psk@dimen CLW mul
      dup 4 -1 roll sub neg 3 1 roll sub
    \fi
    xA xB add 2 div yA yB add 2 div
    translate 0 0
    xB xA sub yA yB sub atan 
    Ellipse  % on stack is rotate coordinates
    \ifPst@variableLW \pst@flattenpath \fi
    closepath
  }%
  \def\pst@linetype{2}%
  \end@ClosedObj
}
\def\multips{\@ifnextchar({\def\pst@par{}\multips@ii}{\multips@i}}
\def\multips@i#1{\def\pst@par{rot=#1}\multips@ii}
\def\multips@ii(#1){\@ifnextchar({\multips@iii(#1)}{\multips@iii(\z@,\z@)(#1)}}
\long\def\multips@iii(#1)(#2)#3#4{%
  \begingroup
%----------------- hv 1.10 ------------------
  \pst@killglue
%----------------- hv 1.10 ------------------
  \use@par
  \pst@getcoor{#1}\pst@tempa
  \pst@@getcoor{#2}%
  \pst@cnta=#3\relax
  \init@pscode
  \addto@pscode{%
    \pst@tempa T \the\pst@cnta\space \pslbrace
    gsave \ifx\psk@rot\@empty\else\psk@rot rotate \fi}%
  \hbox to\z@{%
    \def\init@pscode{%
      \addto@pscode{%
        gsave
        \pst@number\pslinewidth SLW
        \pst@usecolor\pslinecolor}}%
    \def\use@pscode{\addto@pscode{grestore}}%
    \def\psclip##1{\pst@misplaced\psclip}%
    \def\nc@object##1##2##3##4{\pst@misplaced{node connection}}%
    #4%
  }%
  \addto@pscode{grestore \pst@coor T \psrbrace repeat}%
  \leavevmode
  \use@pscode
  \endgroup
  \ignorespaces}
\def\psscalebox#1{\pst@makebox{\ps@scalebox{#1}}}
\def\ps@scalebox#1{%
  \begingroup%
  \pst@getscale{#1}\pst@tempa%
  \let\pst@tempc\pst@tempg%
  \let\pst@tempd\pst@temph%
  \ps@@scalebox%
  \endgroup}
\def\ps@@scalebox{%
  \leavevmode%
  \hbox{%
    \ifdim\pst@tempd\p@<\z@%
      \pst@dimg=\pst@tempd\ht\pst@hbox%
      \pst@dimh=\pst@tempd\dp\pst@hbox%
      \dp\pst@hbox=-\pst@dimg%
      \ht\pst@hbox=-\pst@dimh%
    \else%
      \ht\pst@hbox=\pst@tempd\ht\pst@hbox%
      \dp\pst@hbox=\pst@tempd\dp\pst@hbox%
    \fi%
    \pst@dima=\pst@tempc\wd\pst@hbox%
    \ifdim\pst@dima<\z@\kern-\pst@dima\fi%
    \pst@Verb{CP CP translate \pst@tempa \tx@NET}%
    \hbox to \z@{\box\pst@hbox\hss}%
    \pst@Verb{
      CP CP translate
      1 \pst@tempc div 1 \pst@tempd div scale
      \tx@NET}%
    \ifdim\pst@dima>\z@\kern\pst@dima\fi%
  }%
}
\pslongbox{Scalebox}{\psscalebox}
%
\def\psscaleboxto(#1,#2){\pst@makebox{\ps@scaleboxto(#1,#2)}}
\def\ps@scaleboxto(#1,#2){%
  \begingroup
  \pssetlength\pst@dima{#1}%
  \pssetlength\pst@dimb{#2}%
  \ifdim\pst@dima=\z@\else
    \pst@divide{\pst@dima}{\wd\pst@hbox}\pst@tempc
    \edef\pst@tempc{\pst@tempc\space}%
  \fi
  \ifdim\pst@dimb=\z@
    \ifdim\pst@dima=\z@
      \@pstrickserr{%
        \string\psscaleboxto\space dimensions cannot both be zero}\@ehpa
      \def\pst@tempa{}%
      \def\pst@tempc{1 }%
      \def\pst@tempd{1 }% 
    \else
      \let\pst@tempd\pst@tempc
    \fi
  \else
    \pst@dimc=\ht\pst@hbox
    \advance\pst@dimc\dp\pst@hbox
    \pst@divide{\pst@dimb}{\pst@dimc}\pst@tempd
    \edef\pst@tempd{\pst@tempd\space}%
    \ifdim\pst@dima=\z@ \let\pst@tempc\pst@tempd \fi
  \fi
  \edef\pst@tempa{\pst@tempc \pst@tempd scale }%
  \ps@@scalebox
  \endgroup}
\pslongbox{Scaleboxto}{\psscaleboxto}
%
\def\tx@Rot{Rot }
\def\psrotateleft{\pst@makebox{\ps@rotateleft\pst@hbox}}
\def\ps@rotateleft#1{%
\leavevmode\hbox{\hskip\ht#1\hskip\dp#1\vbox{\vskip\wd#1%
\pst@Verb{90 \tx@Rot}
\vbox to \z@{\vss\hbox to \z@{\box#1\hss}\vskip\z@}%
\pst@Verb{-90 \tx@Rot}}}}
\def\psrotateright{\pst@makebox{\ps@rotateright\pst@hbox}}
\def\ps@rotateright#1{%
% ----------- hv begin 2004-05-07 ----------- patch 15
%    \hbox{%
  \leavevmode\hbox{%
% ----------- hv end 2004-05-07 ----------- patch 15
  \hskip\ht#1\hskip\dp#1\vbox{\vskip\wd#1%
  \pst@Verb{-90 \tx@Rot}
  \vbox to \z@{\hbox to \z@{\hss\box#1}\vss}%
  \pst@Verb{90 \tx@Rot}}}}
\def\psrotatedown{\pst@makebox{\ps@rotatedown\pst@hbox}}
\def\ps@rotatedown#1{%
\hbox{\hskip\wd#1\vbox{\vskip\ht#1\vskip\dp#1%
\pst@Verb{180 \tx@Rot}%
\vbox to \z@{\hbox to \z@{\box#1\hss}\vss}%
\pst@Verb{-180 \tx@Rot}}}}
\pslongbox{Rotateleft}{\psrotateleft}
\pslongbox{Rotateright}{\psrotateright}
\pslongbox{Rotatedown}{\psrotatedown}
% ----------- hv begin 2004-09-23 ----------- 1.11
% compatibility stuff 
\let\rotateleft\psrotateleft
\let\rotateright\psrotateright
\let\rotatedown\psrotatedown
% ----------- hv end 2005-09-23 ----------- 1.11
\def\pst@starbox{%
\setbox\pst@hbox\hbox{\psframebox*[boxsep=false]{\unhbox\pst@hbox}}}
\def\pst@@makesmall#1{%
\setbox#1=\hbox to\z@{\hss\vbox to \z@{\vss\box#1\vss}\hss}}
\def\pst@@@makesmall#1{%
\pst@dimh=\psk@xref\wd#1%
\ifx\psk@yref\relax
\pst@dimg=\dp#1%
\else
\pst@dimg=\psk@yref\ht#1%
\advance\pst@dimg\psk@yref\dp#1%
\fi
\setbox#1=\hbox to\z@{%
\kern-\pst@dimh\vbox to\z@{\vss\box#1\kern-\pst@dimg}\hss}}
%
\define@key[psset]{pstricks}{ref}[c]{\pst@expandafter\psset@@ref{#1}\@empty,,\@nil}
\def\psset@@ref#1#2,#3,#4\@nil{%
  \def\psk@xref{.5}%
  \def\psk@yref{.5}%
  \let\pst@makesmall\pst@@@makesmall
  \ifx\@empty#3\@empty
    \@nameuse{getref@#1}%
    \@nameuse{getref@#2}%
  \else
    \pst@checknum{#1#2}\psk@xref
    \pst@checknum{#3}\psk@yref
  \fi}
%
\def\getref@c{\let\pst@makesmall\pst@@makesmall}
\def\getref@t{\def\psk@yref{1}}
\def\getref@b{\def\psk@yref{0}}
\def\getref@B{\let\psk@yref\relax}
\def\getref@l{\def\psk@xref{0}}
\def\getref@r{\def\psk@xref{1}}
\psset[pstricks]{ref=c}
%
\def\pst@rotlist{ mark RAngle /ps@a ED cleartomark ps@a neg }
\def\pst@rottable{%
@0=%
@U=%
@L=90 %
@D=180 %
@R=-90 %
@N=\pst@rotlist
@W=\pst@rotlist 90 add %
@S=\pst@rotlist 180 add %
@E=\pst@rotlist 90 sub }
%
\define@key[psset]{pstricks}{rot}[0]{%
  \pst@expandafter{\@ifnextchar*{\psset@@@rot}{\psset@@rot}}{#1}\@nil}
\def\psset@@rot#1\@nil{%
  \def\next##1@#1=##2@##3\@nil{%
    \ifx##2\relax\pst@getangle{#1}\psk@rot \else\def\psk@rot{##2}\fi%
    \pst@Verb{ gsave  STV CP T /ps@rot \ifx\psk@rot\@empty 0 \else \psk@rot \fi def grestore }% (MJS)
  }%
  \expandafter\next\pst@rottable @#1=\relax @\@nil}
%
\def\psset@@@rot#1#2\@nil{%
  \psset@@rot#2\@nil%
  \edef\psk@rot{\pst@rotlist \ifx\psk@rot\@empty\else\space ps@rot add \fi}%
  \pst@Verb{ gsave  STV CP T /ps@rot \ifx\psk@rot\@empty 0 \else \psk@rot \fi def grestore }}% (MJS)
%
%\def\psset@@rot#1\@nil{%
%\def\ps@next##1@#1=##2@##3\@nil{%
%\ifx\relax##2\pst@getangle{#1}\psk@rot\else\def\psk@rot{##2}\fi}%
%\expandafter\ps@next\pst@rottable @#1=\relax @\@nil}
%
%\def\psset@@@rot#1#2\@nil{%
%\psset@@rot#2\@nil
%\edef\psk@rot{\pst@rotlist \ifx\psk@rot\@empty\else\psk@rot add \fi}}
\psset[pstricks]{rot=0}
%
\def\tx@RotBegin{RotBegin }
\def\tx@RotEnd{RotEnd }
\def\pst@rotate#1#2{%
  \ifx#1\@empty\else
  \setbox#2=\hbox{\pst@Verb{#1 \tx@RotBegin}\box#2\pst@Verb{\tx@RotEnd}}%
  \fi%
}
\def\psput@cartesian#1{%
  \hbox to \z@{\kern\pst@dimg{\vbox to \z@{\vss\box#1\vskip\pst@dimh}\hss}}%
}
\def\psput@special#1{%
  \hbox{%
    \pst@Verb{{ \pst@coor \pstnodescale } \tx@PutCoor \tx@PutBegin }%
    \box#1%
    \pst@Verb{ \tx@PutEnd }%
  }%
}
\def\tx@PutCoor{PutCoor }
\def\tx@PutBegin{PutBegin }
\def\tx@PutEnd{PutEnd }
\def\rput{\def\pst@par{}\pst@ifstar{\@ifnextchar[{\rput@i}{\rput@ii}}}
\def\rput@i[#1]{\addto@par{ref={#1}}\rput@ii}
\def\rput@ii{\@ifnextchar({\rput@iv}{\rput@iii}}
\def\rput@iii#1{\addto@par{rot={#1}}\@ifnextchar({\rput@iv}{\rput@iv(\z@,\z@)}}
\def\rput@iv(#1){\pst@killglue\pst@makebox{\rput@v{#1}}}
\def\rput@v#1{%
  \begingroup%
    \use@par%
    \if@star\pst@starbox\fi%
    \pst@makesmall\pst@hbox%
    \ifx\psk@rot\@empty\else\pst@rotate{ps@rot }\pst@hbox\fi% (MJS)
%    \pst@rotate\psk@rot\pst@hbox%
    \psput@{#1}\pst@hbox%
  \endgroup%
  \ignorespaces}
%
\def\multirput{%
  \def\pst@par{}%
  \pst@ifstar{\@ifnextchar[{\multirput@i}{\multirput@ii}}}
\def\multirput@i[#1]{\addto@par{ref={#1}}\multirput@ii}
\def\multirput@ii{\@ifnextchar({\multirput@iv}{\multirput@iii}}
\def\multirput@iii#1{\addto@par{rot={#1}}\multirput@iv}
\def\multirput@iv(#1){%
  \@ifnextchar({\multirput@v(#1)}{\multirput@v(\z@,\z@)(#1)}}
\def\multirput@v(#1,#2)(#3,#4)#5{%
  \pst@makebox{\multirput@vi(#1,#2)(#3,#4){#5}}}
\def\multirput@vi(#1,#2)(#3,#4)#5{%
  \pst@killglue%
  \global\psLoopIndex=\@ne\relax
  \begingroup
    \use@par
    \if@star\pst@starbox\fi
    \pst@makesmall\pst@hbox
    \ifx\psk@rot\@empty\else\pst@rotate{ps@rot }\pst@hbox\fi% (MJS)
%    \pst@rotate\psk@rot\pst@hbox
    \pssetxlength\pst@dima{#1}%
    \pssetylength\pst@dimb{#2}%
    \pssetxlength\pst@dimc{#3}%
    \pssetylength\pst@dimd{#4}%
    \pst@cntg=#5\relax
    \leavevmode
    \loop
      \vbox to \z@{%
        \vss
        \hbox to \z@{\kern\pst@dima\copy\pst@hbox\hss}%
        \vskip\pst@dimb%
      }%
      \ifnum\pst@cntg>\psLoopIndex
        \advance\pst@dima\pst@dimc
        \advance\pst@dimb\pst@dimd
        \global\advance\psLoopIndex by \@ne
    \repeat 
  \endgroup
  \ignorespaces%
}
%
\newif\if@fixedradius
\def\cput{\def\pst@par{}\pst@object{cput}}
\def\cput@i{\@fixedradiusfalse\cput@ii}
\def\cput@ii{\pst@killglue\@ifnextchar({\cput@iv}{\cput@iii}}
\def\cput@iii#1{%
  \addto@par{rot={#1}}%
  \@ifnextchar({\cput@iv}{\cput@iv(\z@,\z@)}%
}
\def\cput@iv(#1){\pst@makebox{\cput@v{#1}}}
  \def\cput@v#1{%
  \begingroup
    \use@par
    \setbox\pst@hbox=\hbox{%
      \psboxsepfalse
      \if@fixedradius\psCirclebox@ii\else\pscirclebox@ii\fi%
    }%
    \pst@@makesmall\pst@hbox
    \ifx\psk@rot\@empty\else\pst@rotate{ps@rot }\pst@hbox\fi% (MJS)
%    \pst@rotate\psk@rot\pst@hbox
    \psput@{#1}\pst@hbox
  \endgroup
  \ignorespaces%
}
%
\def\Cput{\def\pst@par{}\pst@object{Cput}}
\def\Cput@i{\@fixedradiustrue\cput@ii}
\newdimen\pslabelsep
\define@key[psset]{pstricks}{labelsep}[5pt]{%
  \pssetlength\pslabelsep{#1}%
  \ifx\PSTplotLoaded\endinput% Set labels for pst-plot, if laoded
    \let\psxlabelsep\pslabelsep%
    \let\psylabelsep\pslabelsep%
  \fi}
\psset[pstricks]{labelsep=5pt}
%
\define@key[psset]{pstricks}{refangle}[0]{\pst@expandafter\psset@@refangle{#1}\@nil}
\def\psset@@refangle#1\@nil{%
  \def\next##1@#1=##2"##3@##4\@nil{%
    \ifx\relax##2%
      \pst@getangle{#1}\psk@refangle
      \def\psk@uputref{}%
    \else
      \def\psk@refangle{##2 }%
      \def\psk@uputref{##3}%
    \fi}%
  \expandafter\next\pst@refangletable @#1=\relax"@\@nil%
  \pst@Verb{ gsave STV CP T /ps@refangle \psk@refangle\space def grestore }%ADDED (MJS)
}
%
\def\pst@refangletable{%
@r=0"20%
@u=90"02%
@l=180"10%
@d=-90"01%
@ur=45"22%
@ul=135"12%
@dr=-135"21%
@dl=-45"11}
\psset[pstricks]{refangle=0}

% DG/SR modification begin - Mar. 24, 1999 - Patch 10
%\def\uput{\def\pst@par{}\@ifnextchar[{\uput@ii}{\uput@i}}
\def\uput{\def\pst@par{}\pst@ifstar{\@ifnextchar[{\uput@ii}{\uput@i}}} 
% DG/SR modification end
\def\uput@i#1{\addto@par{labelsep=#1}\uput@ii}
\def\uput@ii[#1]{%
  \addto@par{refangle={#1}}%
  \@ifnextchar({\uput@iv}{\uput@iii}}
\def\uput@iii#1{%
  \addto@par{rot={#1}}%
  \@ifnextchar({\uput@iv}{\uput@iv(\z@,\z@)}}
\def\uput@iv(#1){\pst@killglue\pst@makebox{\uput@v{#1}}}
\def\uput@v#1{%
  \begingroup
  \use@par
  \if@star\pst@starbox\fi
  \pstCheckCoorType{#1}% needed for \uput@vii
  \uput@vi
  \psput@{#1}\pst@hbox
  \endgroup
  \ignorespaces}
%
\def\uput@vi{%
  \ifx\psk@uputref\@empty\uput@vii\tx@UUput{}%
  \else
    \ifx\psk@rot\@empty\expandafter\uput@viii\psk@uputref
    \else\uput@vii\tx@UUput{}\fi
  \fi}
% 
\def\uput@vii#1#2{%
  \edef\pst@coor{%
    \ifPst@SpecialLength \pst@SpecialLength \else \pst@number\pslabelsep \fi
%    \pst@number\pslabelsep % \ifdim\pslabelsep<\z@  neg \fi
    #2%
    \pst@number{\wd\pst@hbox}%
    \pst@number{\ht\pst@hbox}%
    \pst@number{\dp\pst@hbox}%
    \ifnum\pst@C@@rType=7\relax
      ps@refangle % CHANGED (MJS) FROM \psk@refangle\space
      \ifx\psk@rot\@empty\else ps@rot\space sub \fi
    \else
      \psk@refangle\space 
      \ifx\psk@rot\@empty\else \psk@rot\space sub \fi
    \fi
    \tx@Uput #1}%
    %\show\pst@coor
  \setbox\pst@hbox=\hbox to\z@{\hss\vbox to\z@{\vss\box\pst@hbox\vss}\hss}%
  \setbox\pst@hbox=\psput@special\pst@hbox
  \ifnum\pst@C@@rType=7\relax
    \ifx\psk@rot\@empty\else\pst@rotate{ps@rot }\pst@hbox\fi% CHANGED FROM \psk@rot (MJS)
  \else
    \ifx\psk@rot\@empty\else\pst@rotate{\psk@rot}\pst@hbox\fi% 
  \fi}
%
%
\def\uput@viii#1#2{%
  \ifnum#1>\z@\relax\ifnum#2>\z@\relax\pslabelsep=.707\pslabelsep\fi\fi
  \setbox\pst@hbox=\vbox to\z@{%
    \ifnum#2=1\relax\vskip\pslabelsep\else\vss\fi
    \hbox to\z@{%
      \ifnum#1=2\relax\hskip\pslabelsep \else\hss\fi
      \box\pst@hbox%
      \ifnum#1=1\relax\hskip\pslabelsep\else\hss\fi}%
    \ifnum#2=2\relax\vskip\pslabelsep\else\vss\fi}}
%
\def\tx@Uput{Uput }
\def\tx@UUput{UUput }
%
\def\Rput{\def\pst@par{}\pst@ifstar{\@ifnextchar[{\Rput@ii}{\Rput@i}}}
\def\Rput@i#1{\addto@par{labelsep=#1}\Rput@ii}
\def\Rput@ii[#1]{\addto@par{ref={#1}}\@ifnextchar({\Rput@iv}{\Rput@iii}}
\def\Rput@iii#1{\addto@par{rot={#1}}\@ifnextchar({\Rput@iv}{\Rput@iv(\z@,\z@)}}
\def\Rput@iv(#1){\pst@killglue\pst@makebox{\Rput@v{#1}}}
\def\Rput@v#1{%
  \begingroup
  \use@par
  \if@star\pst@starbox\fi
  \Rput@vi
  \pst@makesmall\pst@hbox
  \ifx\psk@rot\@empty\else\pst@rotate{ps@rot }\pst@hbox\fi% (MJS)
%  \pst@rotate\psk@rot\pst@hbox
  \psput@{#1}\pst@hbox
  \endgroup
  \ignorespaces}
%
\def\Rput@vi{%
  \pst@dimg=\dp\pst@hbox
  \advance\pst@dimg\pslabelsep
  \dp\pst@hbox=\pst@dimg
  \pst@dimg=\ht\pst@hbox
  \advance\pst@dimg\pslabelsep
  \ht\pst@hbox=\pst@dimg
  \setbox\pst@hbox\hbox{\kern\pslabelsep\box\pst@hbox\kern\pslabelsep}}%
%
\def\oldpsput{\def\pst@par{}\pst@ifstar{\@ifnextchar[{\oldpsput@i}{\oldpsput@ii}}}
\def\oldpsput@i[#1]{\addto@par{ref={#1}}\oldpsput@ii}
\def\oldpsput@ii{\@ifnextchar<{\oldpsput@iii}{\oldpsput@iv}}
\def\oldpsput@iii<#1>{\rput@iii{#1}}
\def\OldPsput{\let\psput\oldpsput}
\def\NewPsput{\let\psput\rput}
%
% -----------  hv 20120219 -------------------
\newpsstyle{gridstyle}{subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=8pt}
\newpsstyle{gridstyleA}{subgriddiv=5,gridcolor=red!30,subgridcolor=green!20!black!10,gridlabels=0pt}
%\define@boolkey[psset]{pstricks}[]{showgrid}[true]{}
\newif\ifshowgrid
\newdimen\sh@wgridXunit
\newdimen\sh@wgridYunit
\define@key[psset]{pstricks}{showgrid}[b]{\expandafter\pst@@showgrid#1!!\@nil}
\def\pst@@showgrid#1#2#3\@nil{%                            hv 20130403
  \def\showgridp@s{0}%
  \ifx#1b\showgridtrue\else%                               bottom
    \ifx#1f\showgridfalse\else%
      \ifx#1t%
        \ifx#2r\showgridtrue\else%  			   true->bottom
               \showgridtrue\def\showgridp@s{1}\fi%        top
  \fi\fi\fi%
  \ifnum\showgridp@s>0
    \sh@wgridXunit=\psxunit%
    \sh@wgridYunit=\psyunit%
  \fi%
}
\psset[pstricks]{showgrid=false}
\define@boolkey[psset]{pstricks}[Pst@]{pgffunctions}[true]{}
\psset[pstricks]{pgffunctions=false}
%
\newdimen\pst@shift
\newif\ifPst@shift@star
\define@key[psset]{pstricks}{shift}[0]{%
  \ifx#1*
    \global\Pst@shift@startrue
    \pst@shift=\p@
  \else
    \global\Pst@shift@starfalse
    \pssetlength\pst@dimg{#1}
    \global\pst@shift\pst@dimg%   only the outer pspicture env can have a shift
  \fi}
\psset[pstricks]{shift=0}
%
%------------------------------- pspicture ------------------------------
%
\def\pspicture{\begingroup\pst@ifstar\pst@picture}
\def\pst@picture{\@ifnextchar[{\pst@@picture}{\pst@@picture[]}}
\def\pst@@picture[#1]{\@ifnextchar({\pst@@picture@i[#1]}{\pst@@picture@i[#1](10,10)}}%
\def\pst@@picture@i[#1]#2(#3,#4){\@ifnextchar(%   ignore anything between [] and ()
  {\pst@@@picture[#1](#3,#4)}%
  {\pst@@@picture[#1](0,0)(#3,#4)}}
%
\def\pst@@@picture[#1](#2,#3)(#4,#5){%
  \pssetxlength\pst@dima{#2}%
  \pssetylength\pst@dimb{#3}%
  \pssetxlength\pst@dimc{#4}%
  \pssetylength\pst@dimd{#5}%
  \ifdim\pst@dima>\pst@dimc%
    \pst@dimg=\pst@dima%
    \pst@dima=\pst@dimc%
    \pst@dimc=\pst@dimg%
  \fi%
  \ifdim\pst@dimb>\pst@dimd%
    \pst@dimg=\pst@dimb%
    \pst@dimb=\pst@dimd%
    \pst@dimd=\pst@dimg%
  \fi%
  \setbox\pst@hbox=\hbox\bgroup%
  \begingroup\KillGlue%
  \@ifundefined{@latexerr}{}{\let\unitlength\psunit}%
  \edef\pic@coor{(#2,#3)(#2,#3)(#4,#5)}%
% ----------- 1.10/12 beg hv -------------------
  \psset{showgrid=false}%                % for nested pspicture environemnets
  \def\pst@tempA{#1}%
  \ifx\pst@tempA\@empty\else\psset{#1}\fi% sets the shift and grid option
  \ifx\pst@bgcolor\@empty \else\psframe*[linecolor=\pst@bgcolor](#2,#3)(#4,#5)\fi
  \ifshowgrid\ifnum\showgridp@s=0\psgrid[style=gridstyle]\fi\fi%
% ----------- 1.10/12 end hv -------------------
  \ignorespaces%			% 2008-12-07
  \ifPst@pgffunctions\pstVerb{ pgffunctions } \fi % hv 2013-04-17
}
\def\pic@coor{(0,0)(0,0)(10,10)}
%\newdimen\pst@shift
\def\endpspicture{%
  \ifshowgrid\ifnum\showgridp@s>0
    \psgrid[xunit=\sh@wgridXunit,yunit=\sh@wgridYunit,style=gridstyle]\fi\fi%
  \pst@killglue
%  \global\pst@shift=\pst@shift% in fact of the following endgroup
  \endgroup
  \egroup
  \ifdim\wd\pst@hbox=\z@\else
    %\@pstrickserr{Extraneous space in the pspicture environment}%
    %{Type \space <return> \space to proceed.}%
  \fi
  \ht\pst@hbox=\pst@dimd
  \dp\pst@hbox=-\pst@dimb
  \setbox\pst@hbox=\hbox{%
    \kern-\pst@dima
% Orig version ----------
%\ifx\pst@tempa\@empty\else
%\advance\pst@dimd-\pst@dimb
%\pst@dimd=\pst@tempa\pst@dimd
%\advance\pst@dimd\pst@dimb
%\lower\pst@dimd
%\fi
%----- end Orig
    \ifPst@shift@star%\typeout{==pstricks== old behaviour of the shift option}%     shift=*
      \advance\pst@dimd-\pst@dimb
      \pst@dimd=0.5\pst@dimd
    \else\pst@dimd-\pst@shift\fi
    \advance\pst@dimd\pst@dimb
    \lower\pst@dimd%
    \box\pst@hbox%
    \kern\pst@dimc}%
  \if@star\setbox\pst@hbox=\hbox{\clipbox@@\z@}\fi%
  \leavevmode\box\pst@hbox%
  \endgroup%
  \psset[pstricks]{shift=0}% reset value
}
%
\@namedef{pspicture*}{\pspicture*}
\@namedef{endpspicture*}{\endpspicture}
%
\ifx\pstcustomize\relax \input pstricks.con \fi
\catcode`\@=\PstAtCode\relax
%
\endinput
%%
%% END: pstricks.tex

Paper_PlefkaExpansion.bbl
\providecommand{\newblock}{}
\begin{thebibliography}{10}
\expandafter\ifx\csname url\endcsname\relax
  \def\url#1{{\tt #1}}\fi
\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi
\providecommand{\eprint}[2][]{\url{#2}}
% Bibliography created with iopart-num v2.1
% /biblio/bibtex/contrib/iopart-num

\bibitem{vankampen}
{Van Kampen} N~G 2007 {\em Stochastic Processes in Physics and Chemistry\/}
  (Elsevier, 3rd Edition)

\bibitem{gardiner}
{Gardiner} C~W 1985 {\em Handbook for Stochastic Methods\/} (Springer-Verlag,
  2nd edition)

\bibitem{systems}
{Szallasi} Z, {Stelling} J and {Periwal} V (eds) 2006 {\em System Modeling in
  Cellular Biology\/} (MIT press)

\bibitem{okino}
{Okino} M~S and {Mavrovouniotis} M~L 1998 {\em Chem. Rev.\/} {\bf 98} 391--408

\bibitem{apri}
{Apri} M, {De Gee} M and {Molenaar} J 2012 {\em J. Theor. Biol.\/} {\bf 304}
  16--26

\bibitem{achcar}
{Achcar} F, {Kerkhoven} E~J, {The SilicoTryp Consortium}, {Bakker} B, {Barrett}
  M and {Breitling} R 2012 {\em PLoS Comput. Biol.\/} {\bf 8} 1--11

\bibitem{virasoro}
{Mezard} M, {Parisi} G and Miguel A~V 1987 {\em Spin Glass Theory and Beyond\/}
  (World Scientific)

\bibitem{meanfield}
{Opper} M and {Saad} D (eds) 2001 {\em Advanced Mean Field Methods\/} (MIT
  press)

\bibitem{SK}
{Sherrington} D and {Kirkpatrick} S 1975 {\em Phys. Rev. Lett.\/} {\bf 35}
  1792--1796

\bibitem{plefka}
{Plefka} T 1982 {\em J. Phys. A: Math. Gen.\/} {\bf 15} 1971--1978

\bibitem{TAP}
{Thouless} D~J, {Anderson} P~W and {Palmer} R~G 1977 {\em Phil. Mag.\/} {\bf
  35} 593--601

\bibitem{roudi}
{Roudi} Y and {Hertz} J 2011 {\em J. Stat. Mech.\/} {\bf P03031}

\bibitem{mehta}
{Mehta} M~L 2004 {\em Random Matrices\/} 3rd ed (Elsevier-Academic Press,
  Amsterdam)

\bibitem{martin}
{Martin} P~C, {Siggia} E~D and {Rose} H~A 1973 {\em Phys. Rev. A\/} {\bf 8}
  423--436

\bibitem{janssen}
{Janssen} H 1976 {\em Z. Phys. B: Cond. Mat.\/} {\bf 23} 377--380

\bibitem{dedominicis}
{De Dominicis} C 1978 {\em Phys. Rev. B\/} {\bf 18} 4913--4919

\bibitem{romanobattistin}
{Bachschmid Romano} L, {Battistin} C, {Opper} M and {Roudi} Y 2016 {\em In
  preparation\/}

\bibitem{coolen}
{Coolen} A~C~C 2001 {\em Handbook of Biological Physics\/} vol~4
  (Elsevier-Academic Press, Amsterdam) chap Statistical Mechanics of Recurrent
  Neural Networks II Dynamics

\bibitem{cugliandolo}
{Cugliandolo} L~F and {Dean} D~S 1995 {\em J. Phys. A: Math. Gen.\/} {\bf 28}
  4213--4234

\bibitem{girko}
{Girko} V~L 1984 {\em Theory Probab. Appl.\/} {\bf 29} 694--706

\bibitem{ginibre}
{Ginibre} J 1965 {\em J. Math. Phys.\/} {\bf 6} 440--449

\bibitem{girko1}
{Girko} V~L 1986 {\em Theory Probab. Appl.\/} {\bf 30} 677--690

\bibitem{chalker}
{Mehlig} B and {Chalker} J~T 2000 {\em J. Math. Phys.\/} {\bf 41} 3233

\bibitem{crisanti}
{Sommers} H~J, {Crisanti} A, {Sompolinsky} H and {Stein} Y 1988 {\em Phys. Rev.
  Lett.\/} {\bf 60} 1895--1899

\bibitem{FDT}
{Callen} H~B and {Welton} T~A 1951 {\em Phys. Rev.\/} {\bf 83} 34--40

\bibitem{abramowitz}
{Abramowitz} M and {Stegun} I~A (eds) 1972 {\em Handbook of Mathematical
  Functions with Formulas, Graphs, and Mathematical Tables\/} 10th ed (National
  Bureau of Standards, Washington)

\bibitem{chetrite}
{Chetrite} R, {Falkovich} G and {Gawedzki} K 2008 {\em J. Stat. Mech.\/} {\bf
  P08005}

\bibitem{mythesis}
{Bravi} B 2016 {\em Model Reduction and Inference for Dynamics\/} Ph.D. thesis
  King's College London

\bibitem{sompolinsky0}
{Sompolinsky} H and {Zippelius} A 1982 {\em Phys. Rev. B\/} {\bf 25} 6870--6875

\bibitem{sompolinsky1}
{Crisanti} A and {Sompolinsky} H 1987 {\em Phys. Rev. A\/} {\bf 36} 4922--4939

\bibitem{sompolinsky2}
{Sompolinsky} H, {Crisanti} A and {Sommers} H~J 1988 {\em Phys. Rev. Lett.\/}
  {\bf 61} 259--262

\bibitem{biroli}
{Biroli} G 1999 {\em J. Phys. A: Math. Gen.\/} {\bf 32} 8365--8388

\bibitem{thirumalai}
{Kirkpatrick} T~R and {Thirumalai} D 1987 {\em Phys. Rev. B\/} {\bf 36}
  5388--5397

\bibitem{manfred}
{Eissfeller} H and {Opper} M 1994 {\em Phys. Rev. E\/} {\bf 50} 709--720

\bibitem{opperwinther}
{Opper} M and {Winther} O 2005 {\em JMLR\/} {\bf 6} 2177--2204

\bibitem{kalman}
{Bravi} B and {Sollich} P 2016 {\em Paper in preparation\/}

\end{thebibliography}
