\section{Unit Experiments}
\label{text:experiments/unit}

\subsection{Goal Objective Function}
In Table \ref{table:goal_horizon_weighting}, the convergence speed of both the "unweighted" \ref{eq:goal_unweighted} and the "weighted" \ref{eq:goal_weighted} objective formulation are compared over 100 runs in a simplified setup, with no pedestrian in the scene and random assignments of the robot's initial and goat state. Weighting the cost terms non-uniformly over the horizon enables finding "trade-offs" of a locally higher cost for faster global convergence, such as gaining speed in a non-goal-direction at the beginning of the horizon but leads to a smaller cost at the end of it.

\begin{table}[!ht]
\begin{center}
\begin{tabular}{c|c|c}
\bf Goal Objective & \bf MSI & \bf M95OD \\
\hline
Un-Weighted & 9.64 & 6.64 \\
\hline
\rowcolor{our_color}
Weighted & 9.58 & 5.86 \\
\end{tabular}
\caption{Comparison of key performance parameter of the optimization using either the "un-weighted" (Equation \ref{eq:goal_unweighted}) or the "weighted" (Equation  \ref{eq:goal_weighted}) goal objective formulation over 100 runs in a simplified environment setup. For further details please have a look into the example notebook: \href{https://github.com/simon-schaefer/mantrap/blob/master/examples/module_goal.ipynb}{examples/module\_goal}.}
\label{table:goal_horizon_weighting}
\end{center}
\end{table}

\subsection{Interactive Objective Function}
Next to the interactive objective function $J_{int}(\cdot)$, described in Section \ref{text:approach/objective/interactive}, there are several other ways to formulate it. Instead of taking the full trajectory distribution into account for computing the distance measure between the unconditioned $\distwo[]$ and the conditioned trajectory distribution $\dist[]$, it can be approximated by computing the expected value over sample pairs. Consequently, the distance measure breaks down to a weighted sum over $L_2$-norms for each discrete time-step within the time horizon and for every trajectory pair, which are efficient to compute.

\begin{equation}
D_{int}^{sp} = \sum_{samples} \sum_T ||\xpedwo[s]_t - \xped[s]_t||_2
\end{equation}

The samples are deterministic trajectories and can be numerically differentiated efficiently, using central difference expressions. As previously described, it might be more meaningful to compare velocity or acceleration instead of positions.

\begin{align}
J_{int, sa}^{k} &= \sum_{samples} \sum_T ||\ddxpedwo[s]_t - \ddxped[s]_t||_2	 \\
J_{int, sv}^{k} &= \sum_{samples} \sum_T ||\dxpedwo[s]_t - \dxped[s]_t||_2	 \\
J_{int, sp}^{k} &= \sum_{samples} \sum_T ||\xpedwo[s]_t - \xped[s]_t||_2
\label{eq:interaction_diff}
\end{align}

Although quite intuitive, it turns out that a sample-wise objective is hard to optimize. This has two predominant reasons: Firstly, it intrinsically relies on a trade-off between computational feasibility (to compute many times per second for an online optimization) and capability to capture the properties of the underlying real distributions sufficiently well. Secondly, when randomly drawn samples are used, stochasticity is introduced into the objective function, which might lead to a different objective value even when evaluated with the same input. When the distribution's means are used instead, the distribution's uncertainty is disregarded.
\newline
In the following, the projection-probability-based interactive loss function in Equation \ref{eq:objective_interact_prob} is compared against the alternative difference-based objectives, presented above in \ref{eq:interaction_diff}. Due to the previously explained limitations instead of sampled trajectories, the mean trajectory is merely being used, thereby neglecting the prediction's variance. For the comparison, a Monte Carlo simulation is used for a set of custom defined scenarios. Due to the uncertainty evolved in the environment dynamics, the performance is evaluated over 10 test runs each. A meaningful comparison should exclude external factors as best as possible, therefore to exclude interactive effects occurring due to other parts of the optimization, other than the compared objective functions, the safety constraint is not used in this experiment. \\

\begin{table}[!ht]
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c}
\bf Interactive Objective & \bf MPE[\%] & \bf RTD[\%] & \bf RCE[\%] & \bf ETT & \bf TGD & \bf MSD \\
\hline
diff\_pos & 183 & 99 & 41 & 0.0 & 0.24 & 0.94 \\
\hline
diff\_vel & 161 & 98 & 65 & 0.0 & 0.26 & 1.16 \\
\hline
diff\_acc & 116 & 98 & 69 & 0.0 & 0.27 & 1.24 \\
\hline
\rowcolor{baseline_color}
without & 172 & 100 & 34 & 0.0 & 0.23 & 1.08 \\
\hline
\rowcolor{our_color}
projection & 100 & 92 & 100 & 0.8 & 0.39 & 1.44
\end{tabular}
\end{center}
\label{table:interactive_objective}
\end{table}

The experiments show the effect of the interactive objective function: It trades off the required travel time to reach the goal position with increasing the safety and "ease" of the interaction by reducing the pedestrian's efforts and increasing the minimum separation distance. Figure \ref{img:interactive_comp} displays the solution trajectories for an exemplary scenario.  The projection-probability objective accomplishes to increase distance when necessary but gets on track afterward. In opposition, the alternative formulations either fail to establish a sufficient distance to the pedestrian (comp. the second or third image, associated with diff\_pos and diff\_vel) or cannot recover afterward as in the case for the acceleration difference objective.

\begin{figure}[!ht]
\begin{center}
\includegraphics[width=\textwidth]{images/inter_comp_multi.png}
\captionof{figure}{Example solution trajectories for different interactive objective function, beginning from the left: projection, diff\_pos, diff\_vel, diff\_acc, without interactive loss function}
\label{img:interactive_comp}
\end{center}
\end{figure}

\subsection{HJR Safety Constraint}
The necessity and feasibility of approximating the \ac{HJR} value function have been motivated in Section \ref{text:approach/constraint/safety}. In the following several approximation methods are compared and evaluated.
\newline
Figure \ref{img:hj_approx_bar} shows the logarithmic approximation error for several pre-computed grid sizes and using linear (as in \cite{Leung2020})) and Nearest Neighbor interpolation methods. LWPR (not shown here) has been tested as well but turned out to be infeasible for a large number of grid points.\footnote{For more information about the implementation of the LWPR value function approximation see \href{https://github.com/simon-schaefer/HJReachibility}{HJ-Reachability Toolbox} on GitHub.} The value function has been computed on a dense grid exactly, and point-wise compared with the grid interpolated approximations for computing the error metric. While linear interpolation widely outperforms Nearest Neighbor, as expected, the absolute error is tiny. As displayed in Figure \ref{img:hj_approx_hist}, the interpolation error is not uniform over all joint state axes, but larger for positional axes (which likely is due to the larger amount of non-linearity in position compared to velocity directions, compare Figure \ref{img:hj_value_function}). Therefore, the number of grid points have not been equally distributed over the axes, but biased to the positional axes (interior), while keeping the overall size of the grid constant.

\begin{figure}[!ht]
\begin{center}
\includegraphics[width=0.45\textwidth]{images/hj_bar_linear.png}
\includegraphics[width=0.45\textwidth]{images/hj_bar_nearest.png}
\caption{Logarithmic value function approximation error using linear (left) and nearest neighbor (right) interpolation methods based on various pre-computed grid sizes (small < interior < medium)}
\label{img:hj_approx_bar}
\end{center}
\end{figure}

\begin{figure}[!ht]
\begin{center}
\includegraphics[width=\imgwidth]{images/hj_hist_linear.png}
\caption{Absolute error distribution over joint system state axes using linear interpolation based on various pre-computed grid sizes (small < interior < medium)}
\label{img:hj_approx_hist}
\end{center}
\end{figure}

\subsection{Warm-Starting Methods}
The warm-starting method used in the underlying work simplifies the full trajectory optimization problem to a convex and efficiently computable sub-problem. This process has been described in Section \ref{text:approach/runtime/warm_starting}. This simplified formulation merely takes into account the goal objective as well as a physical constraint imposed by the robot, while neglecting any interaction between robot and pedestrian in the scene. It this way, not only pedestrian-target objectives are ignored, but also constraints enforcing a safe interaction. Despite being efficient to solve, it might return a solution estimate far from the real solution. For example, in the case of a densely crowded area, it might return a solution trajectory, passing very close to other pedestrians, which surely violates the safety constraints of the full formulation. Consequently, the runtime would not be reduced much, if at all.
\newline
As previously pointed out, there is no simple way of warm-starting interior-point-based methods using preceding solutions. This difficulty motivates finding other warm-starting approaches designed explicitly for crowd-navigation. In the following several other concepts for warm-starting, the underlying optimization problem is introduced and baselined against the used method. The used method, which is solving a simplified, robot-focussed optimization problem, is thereby referred to as \ac{GFW}.

\paragraph{\ac{SCW}}
SCW follows a similar idea as \ac{GFW}, which is using a simplified formulation of the full optimization problem (Problem \ref{problem:general}) as a wart-start. \ac{GFW}s formulation is thereby extended by the safety constraint $g_{HJR}(\cdot)$ to guarantee that the warm-starting solution is feasible with respect to the system's safety constraint. $g_{HJR}(\cdot)$ is by design independent from pedestrian predictions as well as, for the assumed agent dynamics, widely linear. As a result, \ac{SCW} not only accounts for interactions and feasibility of the warm-started solution trajectory in the full problem but also is comparably efficient to solve.

\paragraph{\ac{PCBW}}
Merkt et alt. \cite{Merkt2018} use nearby pre-computed trajectories to warm-start an optimization problem for controlling a 38-DoF NASA Valkyrie robot in a pick-and-place scenario. Therefore, they encrypt the given initial conditions with problem-specific descriptors, expensively compute solutions for settings distributed over the full state-space, and clusters the pre-computed scenarios using $k$-Means-Clustering. Then, online, the initial conditions are encrypted and efficiently assigned to the closest pre-computed solution with $k$-Nearest-Neighbor classification.
\newline
For the socially aware trajectory optimization problem in \project, there are several possibilities of encrypting the initial conditions. Finding descriptive but efficient encryption is particularly hard due to the varying number of pedestrians in the scene. To avoid this issue, the internal encoding of a prediction model, such as the latent space $z$ of the Trajectron model \cite{Ivanovic2018}, could be utilized. It is small and constant size makes it very appealing. On the contrary, using a prediction model (latent) encoding would firstly demand the prediction model to have such an encoding (which is only valid (C)\ac{VAE}-based models in the field of pedestrian prediction). Secondly, even if the model does have such an internal encoding, there is no guarantee for it to be meaningful for the task of encrypting a given scene. As not all possible scenes can be pre-solved, it is crucial for the encryption to exhibit a spatial correlation between "close" scenarios, so that matching a non-pre-computed scenario to its closest (spatial) neighbors is feasible. However, the latent space of a prediction model is not guaranteed to have this property.

\begin{figure}[!ht]
\begin{center}
\includegraphics[width=\imgwidth]{images/enc_latent_reg.png}
\caption{Latent space encoding for randomly perturbed scenarios. A multi-pedestrian scenario has been perturbed by randomly shifting the initial positions of randomly picked pedestrian in the scene by the amount displayed on the x-axis, resulting in the logarithmic $L2$-distance mapped on the y-axis. For more information please visit the warm-starting testing notebook \href{https://github.com/simon-schaefer/mantrap/blob/master/examples/warm_start.ipynb}{warm\_start}.}
\label{img:pcbw_encoding_latent}
\end{center}
\end{figure}

Figure \ref{img:pcbw_encoding_latent} illustrates the spatial distribution of the latent space of the Trajectron model. The underlying assumption of a spatial correlation between similar scenarios does not hold. For this reason, a manually-design encoding is used within this work. As previously discussed, designing an encoding for all pedestrian states, the robot and goal state is intrinsically governed by the trade-off between an ample search space and representative capabilities of the encoding. Encryption of the complete environment state increases query time and demands an exponentially larger amount of pre-computed scenarios. As some crowd-navigation works merely take into account the closest or most endangered single pedestrian, a similar idea is considered for encoding. Specifically, the scene descriptors are the local coordinates of the closest pedestrian, with respect to the robot, between it and its goal position. Using a local coordinate frame pointing from the robot's to the goal position saves encoding the goal position as well, by implicitly encoding it. Figure \ref{img:pcbw_encoding_manual} pictures a typical scene encoding. Similarly to \cite{Merkt2018}, the pre-computed solution trajectories are matched to the queried scene using $k$-Nearest-Neighbor classification.

\begin{figure}[!ht]
\begin{center}
\begin{tikzpicture}

    \node (R) at (0, 0)
    {\includegraphics[width=.04\textwidth]{images/robot.png}};
    \node (G) at (8, 4)
    {\includegraphics[width=.04\textwidth]{images/flag.png}};
    \node (P1) at (-4, 1)
    {\includegraphics[width=.04\textwidth]{images/walking.png}};
    \node (P2) at (6, 1)
    {\includegraphics[width=.04\textwidth]{images/walking.png}};
    \node (P3) at (2, 4)
    {\includegraphics[width=.04\textwidth]{images/walking.png}};

    \draw[->, very thick] (R) to node[midway, sloped, above] {$\eta$} (1, 0.5);
    \draw[->, very thick] (R) to node[midway, sloped, above] {$\mu$} (-0.5, 1);
    \draw[->, dotted] (R) to node[midway, sloped, above] {$(\eta_{P1}, \mu_{P1})$} (P1);
    \draw[->, dotted] (R) to node[midway, sloped, above] {$(\eta_{P2}, \mu_{P2})$} (P2);
   	\draw[->, dotted] (R) to node[midway, sloped, above] {$(\eta_{P3}, \mu_{P3})$} (P3);
   	\draw[->, dotted] (R) to node[midway, sloped, above] {$(\eta_G, 0.0)$} (G);

\end{tikzpicture}
\end{center}
\caption{Manual encoding of robot-pedestrian scenario, with local coordinate frame $(\eta, \mu)$ originating in the robots position and pointing in the goal direction.}
\label{img:pcbw_encoding_manual}
\end{figure}

\paragraph{\ac{SPMW}}
It is straightforward to see that the computational complexity of evaluating the interactive terms of the optimization, especially their gradients, is tightly-coupled to the complexity of the underlying prediction model.
Thus, as an example, it is effortful to compute the gradient of the interactive objective with respect to the robot's trajectory for Trajectron \cite{Ivanovic2018}, but computationally light-weight to do so for the Social Forces environment \cite{Helbing1995}. Following this idea, the \ac{SPMW} method warm-starts the optimization by solving the same (full) optimization problem and using a less complicated environment. The Potential Field prediction model, as described in Section \ref{text:exp_particles}, has been developed for warm-starting. It is worth noting that \ac{SPMW} enables us to improve the efficiency of the optimization and take advantage of prior knowledge. Therefore, the Potential Field model has been designed so that the pedestrian is only affected by the robot when it is close to the pedestrian and in front of it. Consequently, the optimization is driven to a solution in which the robot moves behind or in the distance of each pedestrian.

\paragraph{Evaluation}
Evaluating the performance of the exhibited warm-starting methodologies generally is hard, as for each warm-starting method a set of scenarios can be constructed, in which the resulting warm-started trajectory is very close to the optimal trajectory. As an example \ac{GFW} works well for sparse scenarios, with few pedestrians, while \ac{SCW} performs well, when the robot starts close to a pedestrian. However, in most cases the warm-starting methods decrease the average optimization runtime by $5-10 \%$, while not qualitatively affecting the shape of the solution trajectory. Empirically, \ac{SCW} seems to perform best. Automatically deciding the optimal warm-starting method for a given scenario, as e.g., by leveraging learning-based methods as in \cite{Banerjee2020}, is left for future work.

\subsection{Attention Methods}
Section \ref{text:approach/runtime/filtering} has introduced the concept of attention for filtering the significant pedestrians for evaluating the interactive objective and cutting computational runtime. Next to the purposed euclidean-distance-based attention module, there are several other methodologies for this purpose, out of which two more sophisticated options will be presented in the following:

\paragraph{Forward Reachability Attention}
Forward reachability generally determines the reachable set of an agent given its dynamics and some time-horizon $T_{FR}$. In opposite to back-ward reachability (\ac{HJR}), which has been introduced in Section \ref{text:approach/constraint/safety}, forward reachability merely regards one agent instead of joint systems. Thereby, forward reachability deals with finding the set of all states that the agent can reach from a given set of states $\mathcal{L}$ at time $T_{FR}$. With dynamics $\dot{x} = f(x, u)$, the reachable set $\mathcal{X}_{FR}$ is determined as:

\begin{equation}
\mathcal{X}_{FR} = \{x_T: \in u, \textit{ s.t. } x(\cdot) \textit{ satisfies } \dot{x} = f(x, u), x(0) \in \mathcal{L}; x(T_{FR}) = x_T\}
\end{equation}

For single- and double-integrator dynamics, the forward reachable set $\mathcal{X}_{FR}$ turns out to be a circle, due to their isotropy. The radius and center point, thereby, depends on the agent's initial state. Due to the ability to determine these sets analytically, the forward reachability-based attention filter is very computationally efficient to apply.
\newline
Consequently, the forward reachable set attention selects the pedestrian of which the reachable sets overlap with the robot's reachable set for the planning horizon $T_{FR} = T$. If the reachable sets do not overlap, it is not possible for the robot and some pedestrian $k$ to meet within the planning horizon. Then pedestrian $k$ can safely be neglected within the optimization.

\paragraph{Proximate Attention}
The proximate attention module is re-using a concept, that is frequently used in game-theoretic crowd-navigation. Here, the problem is formulated as games between each robot-pedestrian-pair \cite{Bouzat2014}\cite{Nikolaidis2017}. Following this idea, the proximate attention module merely considers the pedestrian, which is closest to the robot (and within a pre-determined euclidean range).

\begin{equation}
\attention_{closest}(\x, \xped[k]) = \left( ||\x - \xped[k]||_2 > D_{Attention} \land \arg \min ||\x - \xped[k]||_2 \right)
\end{equation}

\paragraph{Evaluation}
Table \ref{table:attention} and Figure \ref{img:attention} show the results of a Monte Carlo-based evaluation, averaged over ten scenarios with 20 time-steps each. "Without" thereby refers to using trajectory optimization without any attention. Due to its conservative safety estimate, the reachability-based approach does not cut the computational effort since hardly a pedestrian is removed from the robot's attention. Conversely, the euclidean and proximate attention modules show very similar performance. In case of very cluttered scenarios (not shown here), the proximate attention sometimes leads to rapidly changing the related pedestrian, which might cause an "in-constant" robot movement. Hence, the euclidean module is the better overall choice.
\newline
Using euclidean-based attention dramatically reduces the average computational cost since the interactive objective function does not have to be evaluated with respect to all surrounding pedestrians, or not at all when no pedestrian is close to the robot. Therefore, the effect of attention on computational effort is two-fold: It decreases the average cost of objective/gradient evaluation and the number of required optimization iterations. Also, the derived trajectories do not necessarily perform worse in terms of interactive trajectory cost.

\begin{table}[!ht]
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c|c}
\bf Attention & \bf MPE[\%] & \bf RTD & \bf RCE[\%] & \bf ETT & \bf TGD & \bf MSD & \bf MSR \\
\hline
proximate & 102 & 0.97 & 104 & 0.28 & 0.14 & 2.24 & 0.058 \\
\hline
reachability & 98 & 0.98 & 113 & 0.0 & 0.13 & 2.24 & 0.68 \\
\hline
\rowcolor{baseline_color}
without & 104 & 0.97 & 130 & 0.04 & 0.14 & 2.23 & 0.77 \\
\hline
\rowcolor{our_color}
euclidean & 100 & 0.97 & 100 & 0.28 & 0.14 & 2.22 & 0.06
\end{tabular}
\end{center}
\caption{Quantitative comparison of several attention filters by evaluating the performance of the underlying trajectory optimization.}
\label{table:attention}
\end{table}

In fact, filtering non-significant agents may accelerate the overall optimization by simplifying the trade-off between the interactive cost with respect to multiple pedestrians to minimizing the interactive cost of a single pedestrian. Figure \ref{img:attention} displays such a scenario. Here, the robot chooses to wait and follow behind the green (closest) pedestrian, which is the least interventional action for this single agent. Regarding the impact the robot's action has on all pedestrians, however, it seems to be more optimal to accelerate and increase the average distance to all pedestrians as quickly as possible. Nonetheless, it turns out that the decision based on the single pedestrian is not only more computationally efficient, but also more globally (!) optimal with respect to all pedestrians (at least in this scenario). As explained in Section \ref{text:experiments/discussion}, the purposed optimization formulation is prone to erroneous predictions; by reducing the number of pedestrians, which is taken into account, we hence also reduce the number of sources of misleading predictions.

\begin{figure}[!ht]
\begin{center}
\includegraphics[width=\textwidth]{images/attention.png}
\end{center}
\caption{Trajectory Optimization with different attention modules. From left to right: euclidean, closest, reachability and without the use of attention. For further information please have a look at \href{https://github.com/simon-schaefer/mantrap/blob/master/examples/attention.ipynb}{attention notebook}.}
\label{img:attention}
\end{figure}


\section{TEAL for RAVEN}
A generalized module within the TEAL software (called TEAL.CashFlow) for economic analysis within RAVEN has been developed \cite{MSApril2017}. The module is able to compute
the NPV (Net Present Value), the IRR (Internal Rate of Return) and the PI (Profitability Index). Furthermore, it is possible to
do an NPV, IRR or PI search, i.e. CashFlow will compute a multiplicative value (for example the production cost) so that the
NPV, IRR or PI has a desired value (for details see \ref{subsec:NPV_search}, NPV\_search). This CashFlow module has been written using the script language Python.
The Python code can be used as an ``external model'' in RAVEN (for installation and usage instructions, see \ref{sec:Installation}).

The input of \textbf{TEAL.CashFlow} is an XML file. An example of the input structure is given in Listing \ref{lst:InputExample}. The following section will discuss the
 different keywords in the input and describe how they are used in the \textbf{TEAL.CashFlow} module.

\begin{lstlisting}[style=XML,morekeywords={anAttribute},caption=Economics input example., label=lst:InputExample]
<Economics verbosity='0'>
    <Global>
        <Indicator name='IRR,NPV_search,NPV' target='0'>
            Component1|Cfname1
            Component1|Cfname2
            ...
        </Indicator>
        <DiscountRate>0.08</DiscountRate>
        <tax>0.392</tax>
        <inflation>0.04</inflation>
        <ProjectTime>100</ProjectTime> <!-- optional -->
    </Global>

    <Component name='Component1'>
        <Life_time>20</Life_time>
        <StartTime>10</StartTime> <!-- optional -->
        <Repetitions>3</Repetitions> <!-- optional -->
        <tax>0.3</tax> <!-- optional -->
        <inflation>0.07</inflation> <!-- optional -->
	<CashFlows>
	    <Capex name='Cfname1' tax='false' inflation='none' multiply='multiplier1' mult_target='false'>
    	        <driver>Cfdriver1</driver>
                <alpha>-4000000000</alpha>
                <reference>1000000000</reference>
                <X>1.0</X>
            </Capex>

            <Recurring name='Cfname2' tax='false' inflation='none' multiply='multiplier2' mult_target='true'>
                ...
            </Recurring>
            ...
	</CashFlows>
    </Component>

    <Component name='Component2'>
        ...
    </Component>
    ...
</Economics>
\end{lstlisting}

As one can see, all the specifications of the \textbf{TEAL.CashFlow} module are given in the \xmlNode{Economics} block. The block accepts an attribute called \xmlAttr{verbosity},
which can range from 0 to 100, 0 meaning maximum debug verbosity and 100 meaning
errors only. Setting the verbosity to 50 will output (in addition to errors) the
 NPV, IRR, PI or NPV\_mult. Inside the \xmlNode{Economics} block, there are two
 types of blocks: \xmlNode{Global} and \xmlNode{Component}.

\subsection{\xmlNode{Global}}
Exactly one \xmlNode{Global} block has to be provided. The \xmlNode{Global} block does not have any attributes. The following sub-blocks can be given in the \xmlNode{Global} block:

\begin{enumerate}
\item[\xmlNode{Indicator}] List of cash flows considered in the computation of the economic indicator. See later for the definition
 of the cash flows. Only cash flows listed here are considered, additional cash flows defined, but not listed are ignored.
\xmlNode{Indicator} can have two attributes:
  \begin{enumerate}
  \item[\xmlAttr{name}] The names of the economic indicators that should be computed. So far, \textbf{'NPV'}, \textbf{'NPV\_search'}, \textbf{'IRR'} and \textbf{'PI'} are supported. More than one indicator can be asked for.
The \xmlAttr{name} attribute can contain a comma-separated list as shown in the example in Listing \ref{lst:InputExample}.

\textbf{NPV}: computes the NPV according to Eq. \ref{eq:NPV}.
\begin{equation}\label{eq:NPV}
NPV=\sum_{y=0}^{N}\frac{CF_{y}}{(1+DiscountRate)^{y}}
\end{equation}

The sum runs over the years $y=0$ to $N$. The net cash flows $CF_{y}$ are the sum of all cash flows defined in the indicator block (see later for how to define these cash flows).
$N$ is the least common multiple (LCM) of all component life times involved. This guarantees that the NPV is computed for a time span so that all components reach their end of life in the same year.
The individual component cash flows are repeated until the LCM is reached. For example, lets assume the calculation involves two components \textit{Component1} and \textit{Component2}
 with life times of 60 years and 40 years respectively. $N$ will be 120 years where 2 successive \textit{Component1} and 3 successive \textit{Component2} will be build. For every ‘building year’,
the cash flow for the last year (of the old component) and the year zero (for the newly built component) will be summed. Table \ref{tbl:cashflows} shows an example for illustration.
The variable sent back to RAVEN, i.e. what needs to be added to the output data object is 'NPV'.

\begin{table}[]
\centering
\caption{Example cash flows for NPV calculation.}
\label{tbl:cashflows}
\begin{tabular}{ll|l|l|l|l|l|ll}
\cline{3-4} \cline{6-7}
                           &  & \multicolumn{2}{l|}{Compo 1}                                                                                &  & \multicolumn{2}{l|}{Compo 2}                                                                                &                       &                                                                                \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{Year} &  & \begin{tabular}[c]{@{}l@{}}Comp. \\ lifetime\end{tabular} & \begin{tabular}[c]{@{}l@{}}Cash Flow\\ (year)\end{tabular}         &  & \begin{tabular}[c]{@{}l@{}}Compo. \\ Lifetime\end{tabular} & \begin{tabular}[c]{@{}l@{}}  Cash Flow \\ (year) \end{tabular}      & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}Total Net Cash flow \\ ($CF_{y}$)         \end{tabular}}   \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{0}    &  & 0                                                         & $CF^{comp1}_{0}$                                                          &  & 0                                                          & $CF^{comp2}_{0}$                                                           & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{0} + CF^{comp2}_{0}$ }                                     \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{1}    &  & 1                                                         & $CF^{comp1}_{1}$                                                          &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{1} + CF^{comp2}_{1}$ }                                     \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{}                                                                                \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{39}   &  & 39                                                        & $CF^{comp1}_{39}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{39} + CF^{comp2}_{39}$ }                                   \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{40}   &  & 40                                                        & $CF^{comp1}_{40}$                                                         &  & 40 and 0                                                   & \begin{tabular}[c]{@{}l@{}}$CF^{comp2}_{40}$  \\ $+ CF^{comp2}_{0}$ \end{tabular} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{40} + CF^{comp2}_{40}$ \\  $+ CF^{comp2}_{0}$ \end{tabular}} \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{41}   &  & 41                                                        & $CF^{comp1}_{41}$                                                         &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{41} + CF^{comp2}_{1}$ }                                  \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{}                                                                                \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{59}   &  & 59                                                        & $CF^{comp1}_{59}$                                                         &  & 19                                                         & $CF^{comp2}_{19}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{59} + CF^{comp2}_{19}$ }                                 \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{60}   &  & 60 and 0                                                  & \begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{60}$ \\ $+ CF^{comp1}_{0}$ \end{tabular} &  & 20                                                         & $CF^{comp2}_{20}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{60} + CF^{comp1}_{0}$ \\ $+ CF^{comp2}_{20}$ \end{tabular}} \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{61}   &  & 1                                                         & $CF^{comp1}_{1}$                                                          &  & 21                                                         & $CF^{comp2}_{21}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{1} + CF^{comp2}_{21}$ }                                                          \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{}                                                                                \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{79}   &  & 19                                                        & $CF^{comp1}_{19}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{19} + CF^{comp2}_{39}$ }                                                         \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{80}   &  & 20                                                        & $CF^{comp1}_{20}$                                                         &  & 40 and 0                                                   & \begin{tabular}[c]{@{}l@{}}$CF^{comp2}_{40}$ \\  $+ CF^{comp2}_{0}$ \end{tabular} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}$CF^{comp1}_{20} + CF^{comp2}_{40}$ \\ $+ CF^{comp2}_{0}$ \end{tabular}}  \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{81}   &  & 21                                                        & $CF^{comp1}_{21}$                                                         &  & 1                                                          & $CF^{comp2}_{1}$                                                           & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{21} + CF^{comp2}_{1}$ }                                                          \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{…}    &  &                                                           &                                                                    &  &                                                            &                                                                     & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{}                                                                                \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{119}  &  & 59                                                        & $CF^{comp1}_{59}$                                                         &  & 39                                                         & $CF^{comp2}_{39}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{59} + CF^{comp2}_{39}$ }                                                         \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\multicolumn{1}{|l|}{120}  &  & 60                                                        & $CF^{comp1}_{60}$                                                         &  & 40                                                         & $CF^{comp2}_{40}$                                                          & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{$CF^{comp1}_{60} + CF^{comp2}_{40}$}                                                         \\ \cline{1-1} \cline{3-4} \cline{6-7} \cline{9-9}
\end{tabular}
\end{table}

\textbf{PI}: computes the PI according to Eq. \ref{eq:PI}.
\begin{equation}\label{eq:PI}
PI=\frac{NPV}{Initial\_investment}
\end{equation}
where the NPV is calculated as explained above and the $Initial\_investment$ is the Total Net Cash flow at year zero, i.e. $CF_{0}$ in the example above.
The variable sent back to RAVEN, i.e. what needs to be added to the output data object is 'PI'.

\textbf{IRR}: computes the IRR according to Eq. \ref{eq:IRR}.
\begin{equation}\label{eq:IRR}
0=\sum_{y=0}^{N}\frac{CF_{y}}{(1+IRR)^{y}}
\end{equation}
Same as for the NPV, the sum runs over the years $y=0$ to $N$. The net cash flows $CF_{y}$ are the sum of all cash flows defined in the indicator block
(see explanation of NPV above for details). $N$ is the least common multiple (LCM) of all component life times involved.
The variable sent back to RAVEN, i.e. what needs to be added to the output data object is 'IRR'.

\textbf{NPV\_search}: The NPV search finds a multiplier '$x$' that multiplies some of the cash flows, so that the NPV has a desired value (defined by the \xmlAttr{target} attribute). The equation solved is shown in Eq. \ref{eq:NPV_search}.
\label{subsec:NPV_search}
\begin{equation}\label{eq:NPV_search}
'target'=\sum_{y=0}^{N}\frac{CF^{dep\_on\_x}_{y}}{(1+DiscountRate)^{y}}x + \sum_{y=0}^{N}\frac{CF^{not\_dep\_on\_x}_{y}}{(1+DiscountRate)^{y}}
\end{equation}

The cash flows that multiply ‘$x$’ have to have the \xmlAttr{mult\_target} attribute equal \textbf{'true'} (see later in cash flow definition). This functionality can be used for
 example to find a commodity price so that the NPV is zero. In this case, the \xmlAttr{target} will be set to \textbf{'0'} and all cash flows that depend (linearly) on the price will take
 \xmlAttr{mult\_target}$=$\textbf{'true'}, i.e. for example the revenue, while cash flows that do not depend on the price will have \xmlAttr{mult\_target}$=$\textbf{'false'}, i.e. for example the capital cost.
The variable sent back to RAVEN, i.e. what needs to be added to the output data object is 'NPV\_mult'.

\textbf{Note on IRR and PI search}: It should be noted that although the only search keyword allowed in \xmlAttr{name} is \textbf{NPV\_search}, it is possible to perform IRR and PI searches as well.

  \begin{itemize}
  \item To do an IRR search, the DiscountRate is set to the desired IRR and a NPV search with the target of ‘0’ is performed.
  \item To perform a PI search, an NPV search can be performed where the target PI is multiplied with the initial investment.
  \end{itemize}

  \item[\xmlAttr{Target}] Target value for the NPV search, i.e. \textbf{'0'} will look for ‘$x$’ so that $NPV(x) = 0$.

  \end{enumerate}

\item[\xmlNode{DiscountRate}] The discount rate used to compute the NPV and PI. Not used for the computation of the IRR (although it must be input).
\item[\xmlNode{tax}] The standard tax rate used to compute the taxes if no other tax rate is specified in the componet blocks. This is a required input. If a tax rate is specified inside a component block, the componet will use that tax rate. If no tax rate is specified in a component, this standard tax rate is used for the component. See later in the definition of the cash flows for more details how the tax rate is used.
\item[\xmlNode{inflation}] The standard inflation rate used to compute the inflation if no other inflation rate is specified in the componet blocks. This is a required input. If a inflation rate is specified inside a component block, the componet will use that inflation rate. If no inflation rate is specified in a component, this standard inflation rate is used for the component. See later in the definition of the cash flows for more details how the inflation rate is used.

\item[\xmlNode{ProjectTime}] This is a optional input. If it is included in the input, the global project time is not the LCM of all components (see \xmlNode{Indicator} attribute \xmlAttr{name} for more information), but the time indicated here.

\end{enumerate}

\subsection{\xmlNode{Component}}

The user can define as many \xmlNode{Component} blocks as needed. A component is typically a part of the system that has the same lifetime and
the same cash flows, i.e. for example a gas turbine, a battery or a nuclear plant. Each component needs to have a \xmlAttr{name} attribute that is unique.
Each \xmlNode{Component} has to have one \xmlNode{Life\_time} block and as many \xmlNode{CashFlow} blocks as needed.

\begin{enumerate}
  \item[\xmlNode{Life\_time}] The lifetime of the component in years. This is used to compute the least common multiple (LCM) of all components involved in the
    computation of the economics indicator. For more details see NPV, IRR and PI explanations above.
  \item[\xmlNode{tax}] This is a optional input. If the tax rate is specified here, i.e. inside the component block, the componet will use this tax rate.
    If no tax rate is specified in the component, the standard tax rate from the \xmlNode{Global} block is used for the component.
  \item[\xmlNode{inflation}] This is a optional input. If the inflation rate is specified here, i.e. inside the component block,
    the componet will use this inflation rate. If no inflation rate is specified in the component, the standard inflation rate from the \xmlNode{Global}
    block is used for the component.
  \item[\xmlNode{StartTime}] This is a optional input. If this input is specified for one or more components, the \xmlNode{Global}
    input \xmlNode{ProjectTime} is required. This input specifies the year in which this component is going to be build for the first time,
    i.e. is going to be included in the cash flows. The default is 0 and the componet is build at the start of the project, i.e. at project year 0.
    For example, if the \xmlNode{ProjectTime} is 100 years, and for this component, the \xmlNode{StartTime} is 20 years, the cash flows for this
    component are going to be zero for years 0 to 19 of the project. Year 20 of the project will be year 0 of this component and so on
    (project year 21 will be component year 1 etc.).
  \item[\xmlNode{Repetitions}] This is a optional input. If this input is specified for one or more components, the \xmlNode{Global}
    input \xmlNode{ProjectTime} is required. This input specifies the number of times this component is going to be rebuilt. The default is 0,
    which indicates that the component is going to be rebuild indefinitely until the project end (\xmlNode{ProjectTime}) is reached.
    Lets assume the \xmlNode{ProjectTime} is 100 years, and the component \xmlNode{Life\_time} is 20 years. Specifying 3 repetitions of this
    component will build 3 components in succession, at years 0, 20 and 40. For years 61 to 100 of the project, the cash flows for this component will be zero.

  \item[\xmlNode{CashFlows}] The user can define any number of 'cash flows' for a component. Each cash flow is of the form given in
    Eq. \ref{eq:CF} where $y$ is the year from 0 (capital investment) to the end of the \xmlNode{Life\_time} of the component.
    \begin{equation}\label{eq:CF}
    CF_{y}=mult\cdot\alpha_{y}\left ( \frac{driver_{y}}{ref} \right )^{X}
    \end{equation}

  The \xmlNode{CashFlows} currently can accept the following subnodes:
  \begin{enumerate}
    \item[\xmlNode{Capex}] The cash flow for capital expenditures, and this node will accept the following child nodes:
      \begin{enumerate}
        \item[\xmlNode{driver}] The $driver$ in Eq. \ref{eq:CF} of the cash flow. This can be any variable passed in from RAVEN or the name
          of another cash flow. If it is passed in from RAVEN, it has to be either a scalar or a vector with length \xmlNode{Life\_time} + 1.
          If its a scalar, all $driver_{y}$ in Eq. \ref{eq:CF}  are the same for all years of the project life. If it is a vector instead, each
          year of the project \xmlNode{Life\_time} will have its corresponding value for the driver. If the driver is another
          cash flow, the project \xmlNode{Life\_time} of the component to which the driving cash flow belongs has to be the same than the project
          \xmlNode{Life\_time} of the component to which this
          cash flow belongs. No loops of cash flows are allowed. The code will error out if there are loops of cash flows, i.e. A is the driver
          of B and B the driver of A.
        \item[\xmlNode{alpha}] $\alpha_{y}$ multiplier of the cash flow (see Eq. \ref{eq:CF}). Similar to \xmlNode{driver}, can be
          either scalar or vector. If a vector, exactly \xmlNode{Life\_time}$ + 1$
          values are expected. One for $y=0$ to $y=$\xmlNode{Life\_time}. If a scalar, we assume alpha is zero for all years of the lifetime
          of the component except the year zero (the provided scalar value will be used for year zero), which is the construction year.
        \item[\xmlNode{reference}] The $ref$ value of the cash flow (see Eq. \ref{eq:CF}).
        \item[\xmlNode{X}] The $X$ exponent (economy of scale factor) of the cash flow (see Eq. \ref{eq:CF}).
      \end{enumerate}
    \item[\xmlNode{Recurring}] The cash flow for recurring cost, such as operation and maintenance cost.
      \begin{enumerate}
        \item[\xmlNode{driver}] The $driver$ in Eq. \ref{eq:CF} of the cash flow. This can be any variable passed in from RAVEN or the name
          of another cash flow. If it is passed in from RAVEN, it has to be either a scalar or a vector with length \xmlNode{Life\_time} + 1.
          If its a scalar, all $driver_{y}$ in Eq. \ref{eq:CF}  are the same for all years of the project life. If it is a vector instead, each
          year of the project \xmlNode{Life\_time} will have its corresponding value for the driver. If the driver is another
          cash flow, the project \xmlNode{Life\_time} of the component to which the driving cash flow belongs has to be the same than the project
          \xmlNode{Life\_time} of the component to which this
          cash flow belongs. No loops of cash flows are allowed. The code will error out if there are loops of cash flows, i.e. A is the driver
          of B and B the driver of A.
          \item[\xmlNode{alpha}] $\alpha_{y}$ multiplier of the cash flow (see Eq. \ref{eq:CF}). Similar to \xmlNode{driver}, can be
            either scalar or vector. If a vector, exactly \xmlNode{Life\_time}$ + 1$
            values are expected. One for $y=0$ to $y=$\xmlNode{Life\_time}.
            If a scalar, we assume alpha is nonzero, i.e. the provided scalar value, for all years of the lifetime
            of the component except the year zero.
      \end{enumerate}
  \end{enumerate}

  These subnodes, such as \xmlNode{Capex} and \xmlNode{Recurring} will accept the following attributes:
  \begin{enumerate}
    \item[\xmlAttr{name}] The name of the Cash flow. Has to be unique across all components. This is the name that can be listed in the
      \xmlNode{Indicator} node of the \xmlNode{Global} block.
    \item[\xmlAttr{tax}] Can be \textbf{true} or \textbf{false}. If it is \textbf{true}, the cash flow is multiplied by $(1-tax)$, where tax
      is the tax rate given in \xmlNode{tax} in the \xmlNode{Global}
      block. As an example, the cash flow of \textit{comp2} for year 119 in Listing \ref{lst:InputExample} would become $CF^{comp2}_{39}(1-tax)$.
      If a cash flow with \xmlAttr{tax}$=$\textbf{true} is the driver of another cash flow, the cash flow without the tax is used as driver for the new cash flow.
      The limitation of having a global tax rate will be lifted in future version of the \textbf{TEAL.CashFlow} module. It is planned to have the possibility to
      input different tax rates for each component, since they might be in different tax regions.
    \item[\xmlAttr{inflation}] Can be \textbf{real, nominal} or \textbf{none}. If it is \textbf{real}, the cash flow is multiplied by
      $(1+inflation)^{-y}$. If it is \textbf{nominal}, the cash flow is multiplied by $(1+inflation)^y$.
      In both cases, inflation is given by \xmlNode{inflation} in the \xmlNode{Global} block. Furthermore, $y$ goes from year 0 (capital investment)
      to the LCM of all component lifetimes.
      This means that the cash flows as expressed in Listing \ref{lst:InputExample} are multiplied with the infloation seen from today, i.e. the cash
      flow for \textit{comp2} for year 119 assuming it includes \textbf{real}
      inflation would be $CF^{comp2}_{39}(1+inflation)^{-119}$
      If a cash flow with \xmlAttr{inflation} equal \textbf{real} or \textbf{nominal} is the driver of another cash flow, the cash flow without
      the inflation is used as driver for the new cash flow.
    \item[\xmlAttr{multiply}] This is an optional attribute. This can be the name of any scalar variable passed in from RAVEN. This number
      is $mult$ in Eq. \ref{eq:CF} that multiplies the cash flow.
    \item[\xmlAttr{mult\_target}] Can be \textbf{true} or \textbf{false}. If \textbf{true}, it means that this cash flow multiplies
      the search variable '$x$' as explained in the NPV\_search option above.
      If the NPV\_search option is used, al least one cash flow has to have \xmlAttr{mult\_target}$=$\textbf{true}.
  \end{enumerate}

\end{enumerate}

An example of a cash flow is shown in Listing \ref{lst:CashFlowExample}. In the example, a cash flow called CAPEX is defined.
In the example, the capital expenditure for a reference plant of capacity
 1'000'000'000 W is \$4 billion. The driver of this cash flow is the actual plant capacity in Watts. Building this plat has some economy
 of scale, so that a plant double the size does cost
less than double the money ($X=0.64$). The example assums an overnight building cost of the reactor, i.e. $\alpha$ is zero for
all years of the lifetime of the reactor except year zero, which is the construction year.

\begin{lstlisting}[style=XML,morekeywords={anAttribute},caption=CashFlow input example., label=lst:CashFlowExample]
<Capex name='CAPEX' tax='false' inflation='none'>
    <driver>Plant_capacity</driver>
    <alpha>-4000000000</alpha>
    <reference>1000000000</reference>
    <X>0.64</X>
</Capex>
\end{lstlisting}


\documentclass[fontsize=9pt, parskip=half, notitlepage, fleqn]{scrartcl}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{verbatim}

\usepackage[UKenglish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amssymb, amsmath, amsfonts, amsthm, empheq}
\usepackage[dvipsnames]{xcolor}
\usepackage{xspace}
\usepackage{siunitx}
\usepackage[margin=3cm]{geometry}
\usepackage{natbib}
\usepackage[pdftex,final,allcolors=myblue,colorlinks,breaklinks=True]{hyperref}

\frenchspacing
\definecolor{myblue}{rgb}{0,0,.8} % {0,0,.8}
\newcommand{\mr}[1]{\mathrm{#1}}

\title{Digital Linear Filter (DLF) design}
\author{Dieter Werthmüller}
\subtitle{Some notes regarding the \texttt{fdesign} add-on for \texttt{empymod}}

\begin{document}
\maketitle

\section{About and Info}

The add-on \texttt{fdesign} can be used to design digital linear filters for
the Hankel or Fourier transform, or for any linear transform. For this included
or provided theoretical transform pairs can be used. Alternatively, one can use
the EM modeller \texttt{empymod} \citep{GEO.17.Werthmuller} to use the
responses to an arbitrary 1D model as numerical transform pair.

More information can be found in the following places:

\begin{itemize}
  \item The article about \texttt{fdesign} is in the repo
    \href{https://github.com/empymod/article-fdesign}{github.com/empymod/article-fdesign}
  \item Example notebooks to design a filter can be found in the repo
    \href{https://github.com/empymod/example-notebooks}{github.com/empymod/example-notebooks}
\end{itemize}

The methodology of \texttt{fdesign} is based upon \cite{GP.07.Kong}. The whole
project of \texttt{fdesign} started with the Matlab scripts from Kerry Key,
which he used to design his filters for \cite{GEO.09.Key, GEO.12.Key}. Fruitful
discussions with Evert Slob and Kerry Key improved the add-on substantially.

Note that the use of \texttt{empymod} to create numerical transform pairs is,
as of now, only implemented for the Hankel transform (via
\texttt{fdesign.empy\_hankel}).

\section{Implemented analytical transform pairs}

The following tables list the transform pairs which are implemented by default.
Any other transform pair can be provided as input. A transform pair is defined
in the following way:
\begin{verbatim}
    from empyscripts.fdesign import Ghosh

    def my_tp_pair(var):
        """My transform pair."""

        def lhs(l):
            return func(l, var)

        def rhs(r):
            return func(r, var)

        return Ghosh(name, lhs, rhs)
\end{verbatim}

Here, \texttt{name} must be one of \texttt{j0}, \texttt{j1}, \texttt{sin}, or
\texttt{cos}, depending what type of transform pair it is. Additional variables
are provided with \texttt{var}. The evaluation points of the \texttt{lhs} are
denoted by \texttt{l}, and the evaluation points of the \texttt{rhs} are
denoted as \texttt{r}. As an example here the implemented transform pair
\texttt{j0\_1}:
\begin{verbatim}
    def j0_1(a=1):
        """Hankel transform pair J0_1 ([Anderson_1975]_)."""

        def lhs(l):
            return l*np.exp(-a*l**2)

        def rhs(r):
            return np.exp(-r**2/(4*a))/(2*a)

        return Ghosh('j0', lhs, rhs)
\end{verbatim}

\subsection{Implemented Hankel transforms}

\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{lp{2.6cm}X}
  Name & Reference & Transform pair \\
\toprule
   %
  j0\_1& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l \exp\left(-al^2\right) J_0(lr)\,\mr{d}l =
    \frac{\exp\left(\frac{-r^2}{4a}\right)}{2a}
    \label{eq:j0_1}
  \end{equation}
  } \\
   %
  j0\_2& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\exp\left(-al\right) J_0(lr)\,\mr{d}l =
    \frac{1}{\sqrt{a^2+r^2}}
    \label{eq:j0_2}
  \end{equation}
  } \\
   %
  j0\_3&
  \noindent\parbox[c]{\hsize}{\cite{GP.97.Guptasarma}}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l\exp\left(-al\right) J_0(lr)\,\mr{d}l =
    \frac{a}{(a^2 + r^2)^{3/2}}
    \label{eq:j0_3}
  \end{equation}
  } \\
   %
  j0\_4&
  \noindent\parbox[c]{\hsize}{\cite{JGR.82.Chave}}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\frac{l}{\beta} \exp\left(-\beta z_\mr{v} \right)
    J_0(lr)\,\mr{d}l =
    \frac{\exp\left(-\gamma R\right)}{R}
    \label{eq:j0_4}
  \end{equation}
  } \\
   %
  j0\_5&
  \noindent\parbox[c]{\hsize}{\cite{JGR.82.Chave}}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l \exp\left(-\beta z_\mr{v} \right)
    J_0(lr)\,\mr{d}l =
    \frac{ z_\mr{v} (\gamma R + 1)}{R^3}\exp\left(-\gamma R\right)
    \label{eq:j0_4}
  \end{equation}
  } \\
   %
  j1\_1& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l^2 \exp\left(-al^2\right) J_1(lr)\,\mr{d}l =
    \frac{r}{4a^2} \exp\left(-\frac{r^2}{4a}\right)
    \label{eq:j1_1}
  \end{equation}
  } \\
   %
  j1\_2& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\exp\left(-al\right) J_1(lr)\,\mr{d}l =
    \frac{\sqrt{a^2+r^2}-a}{r\sqrt{a^2 + r^2}}
    \label{eq:j1_2}
  \end{equation}
  } \\
   %
  j1\_3& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l \exp\left(-al\right) J_1(lr)\,\mr{d}l =
    \frac{r}{(a^2 + r^2)^{3/2}}
    \label{eq:j1_3}
  \end{equation}
  } \\
   %
  j1\_4&
  \noindent\parbox[c]{\hsize}{\cite{JGR.82.Chave}}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\frac{l^2}{\beta} \exp\left(-\beta z_\mr{v} \right)
    J_1(lr)\,\mr{d}l =
    \frac{r(\gamma R+1)}{R^3}\exp\left(-\gamma R\right)
    \label{eq:j1_4}
  \end{equation}
  } \\
   %
  j1\_5&
  \noindent\parbox[c]{\hsize}{\cite{JGR.82.Chave}}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l^2 \exp\left(-\beta z_\mr{v} \right)
    J_1(lr)\,\mr{d}l =
    \frac{r z_\mr{v} (\gamma^2R^2+3\gamma R+3)}{R^5}\exp\left(-\gamma R\right)
    \label{eq:j1_4}
  \end{equation}
  } \\
\end{tabularx}

\begin{align}
  a&>0,\quad r>0\\
  %
  z_\mr{v} &= |z_\mr{rec} - z_\mr{src}|\\
%
  R &= \sqrt{r^2 + z_\mr{v}^2}\\
%
    \gamma &= \sqrt{2j\pi\mu_0f/\rho}\\
%
    \beta &= \sqrt{l^2 + \gamma^2}\\
  \label{eq:symb}
\end{align}

\subsection{Implemented Fourier transforms}

\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{llX}
  Name & Reference & Transform pair \\
\toprule
   %
  sin\_1& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,l\exp\left(-a^2l^2\right) \sin(lr)\,\mr{d}l =
    \frac{\sqrt{\pi}r}{4a^3} \exp\left(-\frac{r^2}{4a^2}\right)
    \label{eq:sin_1}
  \end{equation}
  } \\
   %
  sin\_2& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\exp\left(-al\right) \sin(lr)\,\mr{d}l =
    \frac{r}{a^2 + r^2}
    \label{eq:sin_2}
  \end{equation}
  } \\
   %
  sin\_3& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\frac{l}{a^2+l^2} \sin(lr)\,\mr{d}l =
    \frac{\pi}{2} \exp\left(-ar\right)
    \label{eq:sin_3}
  \end{equation}
  } \\
   %
  cos\_1& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\exp\left(-a^2l^2\right) \cos(lr)\,\mr{d}l =
    \frac{\sqrt{\pi}}{2a} \exp\left(-\frac{r^2}{4a^2}\right)
    \label{eq:cos_1}
  \end{equation}
  } \\
   %
  cos\_2& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\exp\left(-al\right) \cos(lr)\,\mr{d}l =
    \frac{a}{a^2 + r^2}
    \label{eq:cos_2}
  \end{equation}
  } \\
   %
  cos\_3& \cite{USGS.75.Anderson}&
  \noindent\parbox[c]{\hsize}{
  \begin{equation}
    \int^\infty_0\,\frac{1}{a^2+l^2} \cos(lr)\,\mr{d}l =
    \frac{\pi}{2a} \exp\left(-ar\right)
    \label{eq:cos_3}
  \end{equation}
  } \\
   %
\end{tabularx}

%% ~ REFERENCES
\begin{thebibliography}{}
\itemsep0pt

\bibitem[Anderson, 1975]{USGS.75.Anderson}
Anderson, W.~L.,  1975, Improved digital filters for evaluating {F}ourier and
  {H}ankel transform integrals:
\newblock USGS, {\bf PB242800};
  \href{https://pubs.er.usgs.gov/publication/70045426}{https://pubs.er.usgs.gov/publication/70045426}.

\bibitem[Chave and Cox, 1982]{JGR.82.Chave}
Chave, A.~D., and C.~S. Cox,  1982, Controlled electromagnetic sources for
  measuring electrical conductivity beneath the oceans: 1. forward problem and
  model study: Journal of Geophysical Research,
\newblock {\bf 87}, 5327--5338;
  \href{http://doi.org/10.1029/JB087iB07p05327}{doi: 10.1029/JB087iB07p05327}.

\bibitem[Guptasarma and Singh, 1997]{GP.97.Guptasarma}
Guptasarma, D., and B. Singh,  1997, New digital linear filters for {H}ankel
  {J}0 and {J}1 transforms: Geophysical Prospecting,
\newblock {\bf 45}, 745--762;
  \href{http://doi.org/10.1046/j.1365-2478.1997.500292.x}{doi:
  10.1046/10.1046/j.1365-2478.1997.500292.x}.

\bibitem[Kong, 2007]{GP.07.Kong}
Kong, F.~N.,  2007, Hankel transform filters for dipole antenna radiation in a
  conductive medium: Geophysical Prospecting, {\bf 55}, 83--89.
\newblock (\href{http://doi.org/10.1111/j.1365-2478.2006.00585.x}{doi:
  10.1111/j.1365-2478.2006.00585.x}).

\bibitem[Key, 2009]{GEO.09.Key}
Key, K.,  2009, {1D} inversion of multicomponent, multifrequency marine {CSEM}
  data: {M}ethodology and synthetic studies for resolving thin resistive
  layers: Geophysics, {\bf 74}, F9--F20.
\newblock (\href{http://doi.org/10.1190/1.3058434}{doi: 10.1190/1.3058434}).

\bibitem[Key, 2012]{GEO.12.Key}
--------, 2012, Is the fast {H}ankel transform faster than quadrature?:
  Geophysics, {\bf 77}, F21--F30.
\newblock (\href{http://doi.org/10.1190/GEO2011-0237.1}{doi:
  10.1190/GEO2011-0237.1}).

\bibitem[Werthmüller, 2017]{GEO.17.Werthmuller}
Werthmüller, D.,  2017, An open-source full {3D} electromagnetic modeler for
  {1D} {VTI} media in {P}ython: empymod: Geophysics, {\bf 82}, WB9--WB19..
\newblock (\href{http://doi.org/10.1190/geo2016-0626.1}{doi:
  10.1190/geo2016-0626.1}).

\end{thebibliography}

\end{document}


\newpage\section{Functional Equations}

\begin{itemize}[left=0pt, itemsep=2em]
    \item Equating terms:
        \begin{enumerate}[left=0pt,label=\textbf{\arabic*.}]
            \item \textbf{Pseudo-symmetry}: If an equation is almost but not
                completely symmetrical, what happens if you change the order of
                the variables and compare with what you started with?

            \item \textbf{Fudging}: Can you change one variable so as to alter the
                equation only slightly? If so, compare with what you started with.

            \item \textbf{Self-cancelation}: Can you make two terms in the same
                functional equation cancel each other out?

            \item These are the most mechanical ways of getting the same value to
                show up multiple times, but each problem has its own tricks. If
                you see an interesting expression pop up, always ask yourself
                whether you can get it to pop up in a slightly different way too.
        \end{enumerate}
    \item Induction, Cauchy
        \begin{enumerate}[left=0pt,label=\textbf{\arabic*.}]
            \item If you want to solve a functional equation over the integers or
                over the rationals, it often helps to inductively calculate
                something like $f(n x)$ in terms of $f(x)$

            \item A slight variation: if the domain or range of $f$ is $\mathbb{N},$
                definitely look at induction! In addition to asking what is $f(1),$ you
                can also ask when is $f(n)=1$

            \item If you want to show $f(x) \geq y,$ it suffices to show
                $f(x) \geq y-\epsilon$ for all $\epsilon>0 .$ Can you find
                progressively tighter ways of bounding $f(x)$ and then
                apply this argument? Many of the hardest functional
                equations use this kind of idea.
        \end{enumerate}

    \item Injective, Surjective, Bijective
        \begin{enumerate}[left=0pt,label=\textbf{\arabic*.}]
            \item There are many variations on injectivity and you should
                not be too fixated on the form used here. The main idea is
                this: if you can show a relationship between $f(x)$ and
                $f(y),$ what can conclude about $x$ and $y$ ?
                \begin{enumerate}
                    \item If $f$ is injective and $f(x)=f(y),$ then $x=y$
                    \item If $f$ is increasing and $f(x)>f(y),$ then $x>y$
                    \item Often it helps to start with a weaker version of
                        injectivity: if $f(x)=f(y)=0,$ then $x=y$
                    \item Even if $f$ is not injective, we can often still
                        end up with something useful. For example, if
                        $f(x)=x^{2}$ is a valid solution, we will not be
                        able to show $f(x)$ is injective, but perhaps we
                        can show that if $f(x)=f(y),$ then $x=\pm y .$
                        That is almost as good.
                    \item If you can show any kind of injectivity results,
                        it is often useful to set $x=f(z)$ for some
                        arbitrary z.
                \end{enumerate}
            \item Surjectivity is a little less common but it still comes
                in a couple flavours. The main idea is this: is there some
                nasty expression in your equation that you wish could be
                replaced by $x ?$ If so, prove that expression is
                surjective, and you are good to go.
                \begin{enumerate}
                    \item Usually the nasty expression will be $f$ itself.
                    \item It does not have to be though. For example, if
                        you could show $f$ (blah) has some nice property,
                        then a good follow-up would be to show that blah
                        is surjective.
                \end{enumerate}
        \end{enumerate}
\end{itemize}

\begin{take_note*}[title={Can't Start? Try These}]{}
    \begin{enumerate}[wide=0em, label=\arabic*, itemsep=10pt, parsep=5pt, font=\bfseries]
        \item GUESS THE POSSIBLE SOLUTIONS.

        \item SUBSTITUTION
            \begin{enumerate}
                \item Try EVERY possible substitutions, and write them in a
                    list, dont think during this time.
                \item Now think what these results give you.
                \item Find values of $ f(0), f(1), f(2), f(-x) $ etc.
                \item Tweak the function a little bit, do substitution again.
                \item Assume some other functions according to the solutions,
                    substitute them to make the fe easier to get info out of.
            \end{enumerate}

        \item PROPERTIES OF THE FUNCTION
            \begin{enumerate}
                \item Try proving INJECTIVITY, SURJECTIVITY etc.
                \item Look for Injectivity or Surjectivity of $ f(x)-f(y) $.
            \end{enumerate}

        \item Assume for the sake of contradiction that the value of the
            function is greater or smaller than the estimated value at some
            point.

        \item Sometimes consider the difference of two values of $ f $.
    \end{enumerate}
\end{take_note*}

\begin{take_note*}{}
    \begin{enumerate}[wide=0em, label=\arabic*, itemsep=10pt, parsep=5pt, font=\bfseries]
        \item Proving that $f(x)-x$ is injective might come handy in some cases.
        \item If you're \emph{NOT} able to make one side of the equation equal
            to $0$, try to make it equal to any real or some particular real.
            (pco 169 P11)
        \item Sometimes in integer functions, divisibility of the type
            $f(1)^{k-1}\mid f(x)^k$ helps.
        \item Durr$\dots$ I want things to cancel.
    \end{enumerate}
\end{take_note*}

\newpage\subsection{Problems}

\prob{https://artofproblemsolving.com/community/c6h474746p2658967}{EGMO 2012 P3}{E}{Find all functions $f:\mathbb{R}\to\mathbb{R}$ such that \[f\left( {yf(x + y) + f(x)} \right) = 4x + 2yf\left(x + y\right)\] for all $x,y\in\mathbb{R}$.}

\prob{}{pco 169 P11}{M}{Find all $f:\R\rightarrow\R$ such that for all real numbers $x, y$ the following holds: \[ f(x)^2+2yf(x)+f(y)=f(y+f(x)) \]}

\prob{https://artofproblemsolving.com/community/c6h506p1611}{IMO 1994 P5}{MH}{Let $ S$ be the set of all real numbers strictly greater than $-1$. Find all functions $ f: S \to S$ satisfying the two conditions:

    \begin{enumerate}
        \item $ f(x + f(y) + xf(y)) = y + f(x) + yf(x)$ for all $ x, y$ in $ S$;
        \item $ \frac {f(x)}{x}$ is strictly increasing on each of the two intervals $ - 1 < x < 0$ and $ 0 < x$.
\end{enumerate}
}

\prob{https://artofproblemsolving.com/community/c6h219930p1219657}{ISL 1994 A4}{H}{Let $ \mathbb{R}$ denote the set of all real numbers and $ \mathbb{R}^+$ the subset of all positive ones. Let $ \alpha$ and $ \beta$ be given elements in $ \mathbb{R},$ not necessarily distinct. Find all functions $ f: \mathbb{R}^+ \mapsto \mathbb{R}$ such that: \[ f(x)f(y) = y^{\alpha} f \left( \frac{x}{2} \right) + x^{\beta} f \left( \frac{y}{2} \right) \forall x,y \in \mathbb{R}^+.\]}

\prob{https://artofproblemsolving.com/community/c6h1480146p8633190}{IMO 2017 P2}{H}{Let $\mathbb{R}$ be the set of real numbers. Determine all functions $f: \mathbb{R} \rightarrow \mathbb{R}$ such that, for any real numbers $x$ and $y$, \[ f(f(x)f(y)) + f(x+y) = f(xy). \]}

\prob{https://artofproblemsolving.com/community/c6h215430p1191683}{ISL 2008 A1}{E}{Find all functions $ f: (0, \infty) \mapsto (0, \infty)$ (so $ f$ is a function from the positive real numbers) such that
    \[ \frac {\left( f(w) \right)^2 + \left( f(x) \right)^2}{f(y^2) + f(z^2) } = \frac {w^2 + x^2}{y^2 + z^2} \]
for all positive real numbers $ w,x,y,z,$ satisfying $ wx = yz$.}

\prob{}{pco 169 P15}{EH}{Find all $a\in\R$ for which there exists a non-constant function $f:(0,1]\rightarrow\R$ such that \[a+f(x+y-xy)+f(x)f(y)\leq f(x)+f(y)\] for all $x, y \in (0,1]$}

\prob{}{pco 168 P18}{E}{Find all functions $f:\R\rightarrow\R$ such that \[f(f(x)+y)=f(x^2-y)+4f(x)y\] for all $x, y \in\R$}

\prob{https://artofproblemsolving.com/community/c6h488535p2737643}{ISL 2011 A3}{M}{Determine all pairs $(f,g)$ of functions from the set of real numbers to itself that satisfy \[g(f(x+y)) = f(x) + (2x + y)g(y)\] for all real numbers $x$ and $y$.}

\prob{https://artofproblemsolving.com/community/c6h85071p494821}{ISL 2005 A2}{M}{We denote by $\mathbb{R}^+$ the set of all positive real numbers. Find all functions $f: \mathbb R^ + \rightarrow\mathbb R^ +$ which have the property:
    \[f(x)f(y)=2f(x+yf(x))\]
for all positive real numbers $x$ and $y$.}

\solu{Let's first substitute. If there existed some $ x $ such that $ f(x)<1 $, we could find a nice substitution. But that leads to a contradiction. So what if we could do something like this for the other cases, $ f(x)<2 $ and $ f(x)>2 $?}

\prob{https://alrtofproblemsolving.com/community/c6h78909p452035}{ISL 2005 A4}{M}{Find all functions $ f: \mathbb{R}\to\mathbb{R}$ such that $ f(x+y)+f(x)f(y)=f(xy)+2xy+1$ for all real numbers $ x$ and $ y$.}

\solu{Substitution. }

\prob{https://artofproblemsolving.com/community/c6h1627524p10206608}{Iran TST T2P1}{E}{Find all functions $f:\mathbb{R}\rightarrow \mathbb{R}$ that satisfy the following conditions:

    \begin{enumerate}
        \item  $x+f(y+f(x))=y+f(x+f(y)) \quad \forall x,y \in \mathbb{R}$

        \item  The set $I=\left\{\frac{f(x)-f(y)}{x-y}\mid x,y\in \mathbb{R},x\neq y \right\}$ is an interval.
\end{enumerate}}

\prob{}{169 P20}{E}{Let $a$ be a real number and let $f : \R \rightarrow \R$ be a function satisfying: $f(0) = \frac{1}{2}$ and $$f(x + y) = f(x)f(a - y) + f(y)f(a - x)$$ $\forall x, y \in \R$. Prove that $f$ is constant}

\prob{}{Vietnam 1991}{E}{Find all functions $ f : \R \rightarrow \R $ for which
\[\frac{1}{2}f(xy)+\frac{1}{2}f(xz)-f(x)f(yz)\geq \frac{1}{4}\]}

\solu{Just substitute.}

\prob{}{}{M}{Suppose that $f$ and $g$ are two functions defined on the set of positive integers and taking positive integer values. Suppose also that the equations $f(g(n)) = f(n) + 1$ and $g(f(n)) = g(n) + 1$ hold for all positive integer $n$. Prove that $f(n) = g(n)$ for all positive integer $n$.}

\solu{Durrr... I want things to cancel... Hint: You want to show $ f(n)-g(n) = 0 $.}

\prob{https://artofproblemsolving.com/community/c6h17330p118698}{ISL 2002 A1}{EM}{Find all functions $f$ from the reals to the reals such that\[f\left(f(x)+y\right)=2x+f\left(f(y)-x\right)\]for all real $x,y$.}

\solu{On one of our substitution, we see that there is surjectivity in the equation. So trying to show injectivity is the most intuitive move after that. Again, we have $ x $ on the outside, so we need to make $ x $, $ a $ once and $ b $ once. but we have $ f(y)-x $ which we need to eleminate, keeping $ y $ constant. We can make it either $ a $ or $ b $ since we already have $ f(a)=f(b) $. And again we can take whatever value we want for $ f(y) $.}

\prob{https://artofproblemsolving.com/community/c6h17447p119159}{ISL 2001 A1}{EM}{Let $ T$ denote the set of all ordered triples $ (p,q,r)$ of nonnegative integers. Find all functions $ f: T \rightarrow \mathbb{R}$ satisfying
    \[ f(p,q,r) = \begin{cases} 0 & \text{if} \; pqr = 0, \\ 1 + \frac{1}{6}(f(p + 1,q - 1,r) + f(p - 1,q + 1,r) & \\ + f(p - 1,q,r + 1) + f(p + 1,q,r - 1) & \\ + f(p,q + 1,r - 1) + f(p,q - 1,r + 1)) & \text{otherwise} \end{cases} \]
for all nonnegative integers $ p$, $ q$, $ r$.}

\solu{First let us guess the ans. For all points on the $ 3 $ sides, our function gives $ 0 $. We get $ f(1, 1, 1)=1 $. We get $ f(1, 1, 2) = f(1, 2, 1) = f(2, 1, 1) = \frac{3}{2} $. We get $ f(1, 1, 3)=\frac{9}{5} $. We get $ f(1, 2, 2)=\frac{12}{5} $. Now, since for $ pqr=0 $, we have $ f=0 $, we need the expression $ pqr $ on the numerator. And we kinda guess that the denominator is $ p+q+r $. From here the guess is obvious.

Now proving that this solution is the only solution. Let the solution be $ g $. Define, $ h := f-g $. Our aim is to prove that $ h=0 $ for all inputs.}

\prob{https://artofproblemsolving.com/community/c6h1790448p11841779}{RMM 2019 P5}{M}{Determine all functions $f: \mathbb{R} \to \mathbb{R}$ satisfying\[f(x + yf(x)) + f(xy) = f(x) + f(2019y),\]for all real numbers $x$ and $y$.}

\solu{After getting $f(yf(0)) = f(y2019)$, one should think of proving that either $ f $ is constant, all zero except $ 0 $, or linear. How to do this?}

\prob{https://artofproblemsolving.com/community/c6h1071764p4663900}{APMO 2015 P2}{E}{Let $S = \{2, 3, 4, \ldots\}$ denote the set of integers that are greater than or equal to $2$. Does there exist a function $f : S \to S$ such that \[f (a)f (b) = f (a^2 b^2 )\text{ for all }a, b \in S\text{ with }a \ne b?\]}

\solu{Try to break the symmetry, add another variable.}

\prob{https://artofproblemsolving.com/community/c6h1268817p6621849}{ISL 2015 A2}{E}{Determine all functions $f:\mathbb{Z}\rightarrow\mathbb{Z}$ with the property that \[f(x-f(y))=f(f(x))-f(y)-1\]holds for all $x,y\in\mathbb{Z}$.}

\solu{It just flows.}

\prob{https://artofproblemsolving.com/community/c6h1113162p5083463}{ISL 2015 A4}{M}{Let $\mathbb R$ be the set of real numbers. Determine all functions $f:\mathbb R\to\mathbb R$ that satisfy the equation\[f(x+f(x+y))+f(xy)=x+f(x+y)+yf(x)\]for all real numbers $x$ and $y$.}

\solu{When you don't know any heavy techniques, just plug in simple values into the function, and write down all of the equations in a list.}

\prob{https://artofproblemsolving.com/community/c6h546165p3160554}{ISL 2012 A5}{M}{Find all functions $f:\mathbb{R} \rightarrow \mathbb{R}$ that satisfy the conditions
    \[f(1+xy)-f(x+y)=f(x)f(y) \quad \text{for all } x,y \in \mathbb{R},\]
and $f(-1) \neq 0$.}

\solu{In FE, always look back to what you have, and what things can you make from those.}

\prob{https://artofproblemsolving.com/community/c6h488500p2737336}{ISL 2012 A1}{E}{Find all functions $f:\mathbb Z\rightarrow \mathbb Z$ such that, for all integers $a,b,c$ that satisfy $a+b+c=0$, the following equality holds:
    \[f(a)^2+f(b)^2+f(c)^2=2f(a)f(b)+2f(b)f(c)+2f(c)f(a).\]
(Here $\mathbb{Z}$ denotes the set of integers.)}

\solu{Go with the flow.}

\prob{https://artofproblemsolving.com/community/c6h356075p1935849}{ISL 2012 A1}{E}{Find all function $f:\mathbb{R}\rightarrow\mathbb{R}$ such that for all $x,y\in\mathbb{R}$ the following equality holds \[ f(\left\lfloor x\right\rfloor y)=f(x)\left\lfloor f(y)\right\rfloor \] where $\left\lfloor a\right\rfloor $ is greatest integer not greater than $a.$}

\solu{Go with the flow.}

\prob{https://artofproblemsolving.com/community/c6h287852p1555894}
{ISL 2008 A3}{E}{
    Let $ S\subseteq\mathbb{R}$ be a set of real numbers. We say that a pair $
    (f, g)$ of functions from $ S$ into $ S$ is a Spanish Couple on $ S$, if
    they satisfy the following conditions:
    \begin{enumerate}
        \item Both functions are strictly increasing, i.e. $ f(x) < f(y)$ and
            $ g(x) < g(y)$ for all $ x$, $ y\in S$ with $ x < y$;
        \item The inequality $ f\left(g\left(g\left(x\right)\right)\right) <
            g\left(f\left(x\right)\right)$ holds for all $ x\in S$.
    \end{enumerate}
    Decide whether there exists a Spanish Couple
    \begin{itemize}
        \item on the set $ S = \mathbb{N}$ of positive integers;
        \item on the set $ S = \{a - \frac {1}{b}: a, b\in\mathbb{N}\}$
    \end{itemize}
}

\begin{solution}
    Inspecting the fe immediately gives us $g(g(x))<f(x)$.
    Any attempt at constructing a pair for $\mathbb{N}$, fails because
    eventually $g(x)$ becomes larger than $f(x)$. So there might be something
    with how $g$ grows that restricts the construction.\\

    This idea motivates us to further inspect the fe. We eventually notice
    that $g^n(x) < f(x)$ for all $n\in \mathbb{N}$, and that means $S =
    \mathbb{N}$ just won't work.\\

    Now we begin to suspect that this is definitely why the second set has be
    constructed that way. Thinking about the basic construction where $f(x) =
    x+1$, we see that if we think of $g(x)$ as moving $x$ by some step to the
    right on the number line, we get a better picture of how $f(g(g(x)))$
    behaves.\\

    And that motivates our solution:
    \[\boxed{f(x) = x+1,\quad g\left(a-\frac{1}{b}\right) = a - \frac{1}{b+3^a}}\]
\end{solution}

\prob{https://artofproblemsolving.com/community/c6h211465p1165901}
{ISL 2007 A4}{E}{
    Find all functions $ f: \mathbb{R}^{ + }\to\mathbb{R}^{ + }$ satisfying
    \[f\left(x + f\left(y\right)\right) = f\left(x + y\right) + f\left(y\right)\]
    for all pairs of positive reals $ x$ and $ y$. Here, $ \mathbb{R}^{ + }$
    denotes the set of all positive reals.
}

\begin{solution}[substitution]
    Set $x = f(y)$, we have
    \[\begin{aligned}
        f\left(2f(y)\right) &= f(2y) + 2f(y)\\
        \text{and, } f(x+kf(y)) &= f(x+ky) + kf(y)
    \end{aligned}\]
    Now setting $y = 2f(y)$, we get
    \[\begin{aligned}
        f\left(x+f(2f(y))\right) &= f\left(x+2f(y)\right) + f(2f(y))\\
                                 &=f(x+2y) + 4f(y) + f(2y)\\[1em]
        \text{Also, } f(x+f(2f(y))) &= f(x+f(2y)+2f(y))\\
        &= f(x+4y) + 2f(y) + f(2y)\\[1em]
        \implies f(x+4y) &= f(x+2y) + 2f(y) = f(x+2f(y))\\
    \end{aligned}\]
    \begin{equation}
        \boxed{\therefore f(x+4y) = f(x+2f(y))} \ \forall y\in \mathbb{R}^+
    \end{equation}
    If $f$ is injective, then we have $\boxed{f(x) = 2x}$. If not, then
    suppose $f(a) = f(b)$. Substituting $y = a, b$ we get
    \[\begin{aligned}
        f(x+a) = f(x+b) \ \forall x \in \mathbb{R}^+
    \end{aligned}\]
    Combining it with (1), we get that $f(x)$ is a constant function, and so
    $\boxed{f=0}$.
\end{solution}

\begin{solution}[cauchy, Raja Oktovin]
    For any positive real numbers $ z$, we have that
    \[f(x+f(y))+z=f(x+y)+f(y)+z\]
    \[f(f(x+f(y))+z)=f(f(x+y)+f(y)+z)\]
    \[f(x+f(y)+z)+f(x+f(y))=f(x+y+f(y)+z)+f(x+y)\]
    \[f(x+y+z)+f(y)+f(x+y)+f(y)=f(x+2y+z)+f(y)+f(x+y)\]
    \[f(x+y+z)+f(y)=f(x+2y+z)\]

    \[\boxed{f(a)+f(b)=f(a+b)}\] and by Cauchy in positive reals, then $
    f(x)=\alpha x$ for all $ x \in (0, \infty)$. Now it's easy to see that $
    \alpha=2$, then $ f(x)=2x$ for all positive real numbers $ x$.
\end{solution}

\prob{https://artofproblemsolving.com/community/c6h214702p1187155}
{ISL 2007 A2}{E}{
    Consider those functions $ f: \mathbb{N} \mapsto \mathbb{N}$ which satisfy the condition
    \[f(m + n) \geq f(m)+f(f(n))-1\]
    for all $ m,n \in \mathbb{N}.$ Find all possible values of $f(2007)$.
}

\begin{solution}
    Substituting $n=1$, we have
    \[f(m+1) \ge f(m), \quad f(m+1) \ge f(f(m))\]
    So $f$ is non decreasing. We prove that $f(n) \le n+1$. Suppose not, so
    there exists a $n$ for which
    \[\begin{aligned}
        f(n) \ge n+2&\\
        \implies f(2^kn) \ge 2^kn + 2^k +1& \qquad \forall k
    \end{aligned}\]
    Since $f$ grows without any bounds, there is a $t$ such that $f(2^t+1)>1$.
    Then we have,
    \[\begin{aligned}
        f(2^tn+2^t+1) &\ge f(2^t+1) + f(f(2^tn)) -1\\
                      &\ge f(2^t+1)-1 +f(2^tn+2^t+1)\\
                      &> f(2^tn+2^t+1)
    \end{aligned}\]
    A contradiction.\\

    So we get a nice bounding for $f(2007)$, that is $\left\{1, 2, \dots
    2008\right\}$. It's time to construct functions for that. For $1\le k \le
    2007$, consider the functions
    \[f(n) = \begin{cases}
        1 & \text{if } n < k\\
        n-k+1 & \text{if } n\ge k
    \end{cases}\]
    And for $2008$, consider the function
    \[f(n) = \begin{cases}
        n+1 & \text{if } 2007|n\\
        n & \text{otherwise}
    \end{cases}\]
    The constructions comes from the idea that we want $f(f(n)) =f(n)$, and we
    can use $1$'s to push our values to the right.
\end{solution}

\newpage\subsection{Weird Ones}

\prob{https://artofproblemsolving.com/community/c6h289055p1562848}{ISL 2009 A3}{E}{Determine all functions $ f$ from the set of positive integers to the set of positive integers such that, for all positive integers $ a$ and $ b$, there exists a non-degenerate triangle with sides of lengths
    \[ a, f(b) \text{ and } f(b + f(a) - 1).\]
(A triangle is non-degenerate if its vertices are not collinear.)}

\solu{$ f(1)>1 \implies\ f $ is periodic $ \implies $ repeatation $ \implies $ contradiction.\\
$ f(2)>2 \implies $ strictly increasing $ \implies $ repeatation.}

\prob{https://artofproblemsolving.com/community/c6h1558131p9513099}{USA TST 2018 P2}{H}{Find all functions $f: \mathbb{Z}^2 \to [0, 1]$ such that for any integers $x$ and $y$, \[f(x, y) = \frac{f(x - 1, y) + f(x, y - 1)}{2}.\]}

\solu{We know that the function has to be a constant function. So it is a intuitive idea considering the difference of two values of the function. Again as we wish to show that this difference is $ 0 $, we have to use either equality of limit. As equality is quite ambiguous in this problem, we approach with limits. We see that $ f(x,y) $ can be written as a term depending on the values of the $ 3 $rd quarter of the plane with $ (x, y) $ as its origin. With infinite values in our hand, we try bounding.}

\prob{https://artofproblemsolving.com/community/c6h2192982p16443789}
{IMEO 2020 P3}{M}{
    Find all functions $f:\mathbb{R^+} \to \mathbb{R^+}$ such that for all
    positive real $x, y$ holds
    \[xf(x)+yf(y)=(x+y)f\left(\frac{x^2+y^2}{x+y}\right)\]
}

\begin{solution}
    Note that \[\frac{xf(x)+yf(y)}{x+y} = f\left(\frac{x^2+y^2}{x+y}\right)\]
    Which looks just like a linear form. Also since we know that the solution
    is probably only $f(x) = ax+b$, we pursue this idea. \\

    It can be proved that all the rational points lie on a line. Now what if a
    irrational lies outside of the line?
\end{solution}

\begin{solution}[MarkBcc168, geometric]
    Our first step is to do Vieta Jumping on the functional equation. The main
    result from this is the following.

    \begin{claim}
        $af(a) - bf(b) = (a-b)f(a+b)$ for any $a,b\in\mathbb{R}^+$.
    \end{claim}

    \begin{prooof}
        Fix $t,k\in\mathbb{R}^+$ where $t<k$. Let $g(x)=\tfrac{x^2+t^2}{x+t}$.
        Since $\lim_{x\to\infty}g(x)=\infty$ and $g(t)=t$, there exists $a$
        such that $g(a) = \tfrac{t^2+a^2}{t+a}=k$. Moreover, by Vieta's
        Jumping, $g(k-a)=k$. Thus, by considering

        \[\begin{array}{rcrcl}
            P(t,a) & \implies & tf(t) + af(a)&=&(a+t)f(k)\qquad\text{ and}
            \\[4pt] P(t,k-a) & \implies & tf(t) + (k-a)f(k-a)&=&(k-a+t)f(k),
        \end{array}\]

        we get that
        \[af(a) - (k-a)f(k-a) = (2a-k)f(k)\]
        for any $a,k$ such that $k>a$. Thus, by setting $b=k-a$, we get the
        desired claim.
    \end{prooof}

    Now let's do some geometry. Let $P_x = (x,f(x))$. Then the claim above
    implies that $P_a, P_b, P_{a+b}$ are colinear whenever
    $a,b\in\mathbb{R}^+$.\\

    Fix any pairwise distinct $a,b,c\in\mathbb{R}^+$. Set $A=P_a$, $B=P_b$,
    $C=P_c$, $D=P_{b+c}$, $E=P_{c+a}$, and $F=P_{a+b}$. By the claim, $D\in
    BC$, $E\in CA$, $F\in AB$, and $AD,BE,CF$ are concurrent at $P_{a+b+c}$.
    However, we claim that

    \begin{claim}
        $D,E,F$ are colinear.
    \end{claim}

    \begin{prooof}
        If $A,B,C$ are colinear, then the result is trivial. Otherwise, we use
        Menelaus theorem. Observe that
        $$\frac{\overline{BD}}{\overline{DC}} = \frac{b - (b+c)}{(b+c)-c} =
        -\frac bc$$hence multiplying the result cyclically gives the result.
    \end{prooof}

    By Ceva's theorem, both $D,E,F$ being colinear and $AD,BE,CF$ being
    concurrent can only happen when $A,B,C$ are colinear. This means that
    $(a,f(a))$, $(b,f(b))$, $(c,f(c))$ are colinear for any
    $a,b,c\in\mathbb{R}^+$. This concludes, say by varying $c$, that $f$ must
    be linear.
\end{solution}


\subsection{Performance Requirements}

\begin{enumerate}
    %\item The programmable sampling rate of the pressure sensor \textit{shall} not be lesser than .
    \item[P.12] The accuracy of the ambient pressure measurements \textit{shall} be -1.5/+1.5 hPa for 25$\degree{C}$.
    \item[P.13] The accuracy of temperature measurements \textit{shall} be +3.5/-3$\degree{C}$ (max) for condition of -55$\degree{C}$ to 150$\degree{C}$.
    \item[P.23] The temperature sensor sampling rate \textit{shall} be 1 Hz.\label{newsamplerate}
    \item[P.24] The temperature of the Pump \textit{shall} be between 5$\degree{C}$ and 40$\degree{C}$.
    \item[P.25] The minimum volume of air in the bags for analysis \textit{shall} be 0.18 L at ground level.
    \item[P.26] The equivalent flow rate of the pump \textit{shall} be between 8 to 3 L/min from ground level up to 24 km altitude.
    \item[P.27] The accuracy range of the sampling time, or the resolution, \textit{shall} be less than 52.94 s, or 423.53 m.
    \item[P.28] The pressure sensor sampling rate \textit{shall} be 1 Hz.\label{newsamplerate}
    \item[P.29] The airflow sensor sampling rate \textit{shall} be 1 Hz.\label{newsamplerate}
    \item[P.30] The accuracy of the pressure measurements inside the tubing and sampling bags \textit{shall} be -0.005/+0.005 bar for 25$\degree{C}$.

 \end{enumerate}