# Theory of Optical Pump THz Probe with sub-picosecond time-dependent material
properties: the Perturbative Transfer Matrix Method

Yingshu Yang  School of Physical and Mathematical Sciences, Nanyang
Technological University, Singapore, Singapore  Stefano Dal Forno  School of
Physical and Mathematical Sciences, Nanyang Technological University,
Singapore, Singapore  Marco Battiato<EMAIL_ADDRESS>School of
Physical and Mathematical Sciences, Nanyang Technological University,
Singapore, Singapore

(August 27, 2024)

###### Abstract

Optical Pump THz Probe (OPTP) is a technique by which an optical subpicosecond
laser pulse is used to trigger ultrafast dynamics in a target multilayered
film, and a THz pulse is sent with variable delay to probe the status of the
system. For a slowly varying dielectric response, the non-equilibrium THz
response can be described using a quasi-static description and hence standard
transfer matrix methods (TMM) can be employed. However, if the non-equilibrium
timescale is similar to or shorter than the THz probe time width, there are
currently no available theoretical tools to describe this situation. We
develop a theoretical framework, the Perturbative Transfer Matrix Method
(PTMM), to fill in this gap. The full time dependence of the properties of the
materials, as well as the proper propagation via Maxwell’s equations, are
correctly accounted for. We observe that, while slowly varying material
properties produce an OPTP signal which can very well be interpreted within
the quasi-static limit when the excitation dynamics are fast, that
approximation cannot account for crucial features of the OPTP signal. The fast
excitation timescale produces a significant broadening of the OPTP signal. We
show that not only OPTP can be used to extract the sub-picosecond timescale of
the excitation, but it also provides a sub THz period resolution, and dynamics
as fast as a few hundreds of femtoseconds can be distinguished even with
narrowband THz pulses with time durations as long as many picoseconds.

###### pacs:

Terahertz time-domain spectroscopy (THz-TDS) is an attractive experimental
method that uses a frequency range between 0.1 THz to 10 THz to measure and
extract dielectric properties of materials such as permittivities and
refractive indices. This method exploits the fact that electric fields are
measured in the time domain and does not rely on simple intensity measurements
Schmuttenmaer (2004).

Thus, THz-TDS is often used for the measurement of THz responses of materials
in the steady state. Additionally, based on the optically gated emission and
detection technique together with the time domain measurement of THz pulse in
THz-TDS, another experimental method – Optical Pump Terahertz Probe (OPTP) –
has been developed and is currently widely used for the measurement and study
of non-equilibrium condition material properties, such as charge carrier
dynamics and mobilitiesUlbricht  _et al._ (2011); George  _et al._ (2008);
Strait  _et al._ (2011).

In OPTP experiments, the optical pump drives the system into a strong out-of-
equilibrium state. Subsequently, a THz probe is sent onto the sample to
investigate its properties. In this excited state, a number of ultrafast
processes can be triggered: THz emissionSeifert  _et al._ (2016); Hoffmann
_et al._ (2007); Matthäus  _et al._ (2006); Kampfrath  _et al._ (2013),
ultrafast laser induced demagnetization Carva  _et al._ (2011); Battiato  _et
al._ (2010); Eschenlohr  _et al._ (2013); Zhang and Hübner (2000); Beaurepaire
_et al._ (1996), superdiffusive spin transportBattiato  _et al._ (2012); Carva
_et al._ (2013), coherent magnetic precessionJu  _et al._ (1998); Van Kampen
_et al._ (2002); Langner  _et al._ (2009), and laser induced phase transitions
Agranat  _et al._ (1998); Kirilyuk  _et al._ (2010). The application of the
OPTP experimental technique provides in-depth analysis of these processes as
well as information on the non-equilibrium status of materials such as
semiconductors, superconductors and metals, and other interesting materials
such as, MxenesLi  _et al._ (2018), perovskitesLa-o vorakiat  _et al._ (2017),
$MoS_{2}$Kar  _et al._ (2015), grapheneKar  _et al._ (2014); Tomadin  _et al._
(2018); George  _et al._ (2008), topological insulatorsRuan  _et al._ (2021),
which are all important component to computers, lasers, light-emitting
devices, electrodes, information storage devices, and future electronic
devicesUlbricht  _et al._ (2011); Alberding  _et al._ (2016).

Typically, THz-TDS experiments are performed in multilayered system where the
THZ probe is used to access the equilibrium properties of a specific layer of
the sample. However, in the case of OPTP, the optical pump drives the system
to a strong out-of-equilibrium state. The material undergoes a sub-picosecond
excitation and the subsequent relaxation produces dynamics in the picosecond
or subpicosecond regime. In this case the responses to the electromagnetic
radiation are not anymore invariant with time translation.

The Transfer Matrix Method (TMM) (or transfer function), is a basic and mature
method for the theoretical study of electromagnetic wave propagation in
multilayer structuresNeu and Schmuttenmaer (2018). However, the TMM is
restricted to describe the propagation of electromagnetic (EM) waves in
systems at equilibrium, where the dielectric response of the material varies
on a slower time scale than the period of the probe. Within this approximation
one can define a time and frequency dependent dielectric response function,
where the slow time variation is accounted by the explicit time dependence,
while the high frequency contributions are modelled within the Fourier domain.
Notice that this approach requires a clear separation of the slow timescale
related to the evolution of the out-of-equilibrium dynamics of the materials
and a fast timescale related to the period of the used probe radiation.
Methods, based on this approximation have been developed and applied to the
extraction of slowly time-dependent conductivity and susceptibility for
ultrafast far-infrared dynamicsNěmec  _et al._ (2002, 2005a, 2005b) as well as
layered systemsKužel  _et al._ (2007).

However, that approximation fails in the case of OPTP. The frequency of the
probe and the time evolution dynamics timescales are completely overlapping.
This causes even the interpretation of the results as a time-varying
dielectric response to lose meaning, as spectral features typical of the time-
evolution of the excited system are expected to appear within the spectrum of
the transmitted or reflected THz radiation. The problem becomes more complex
and the interaction of the radiation with materials with time-varying
properties must be described in more detail.

Figure 1: Concept figure: A description of the OPTP setup and the PTMM recipe.
The frequency map is the spectrum difference between the transmitted THz probe
through a non-excited and excited sample with different time delay.

To address this challenge we extend the TMM method using perturbation theory.
We describe the dielectric response of the material using a time-dependent
generalised Drude function. We explicitly account for the out-of-equilibrium
carrier densities and scattering rates induced by the optical pump. With this,
our Perturbative Tranfer Matrix method (PTMM) is capable of solving Maxwell’s
equations for a strongly excited multilayered system. We also calculate the
frequency map of the pump-on pump-off spectrum difference of the transmitted
THz probe (Fig. 1) and demonstrate that an accurate analysis of the OPTP
spectrum can provide sub-period time resolution (less than 100 fs) into the
sample’s dynamics. In particular, this allows for OPTP to resolve not only
slow dynamics but even the very fast excitation process, which often takes
only a few hundreds of fs for ferromagnets like Ni Beaurepaire  _et al._
(1996); Eschenlohr  _et al._ (2013); Battiato  _et al._ (2010) and FeCarpene
_et al._ (2008); Kampfrath  _et al._ (2002) and for noble metals like Au Fann
_et al._ (1992); Sun  _et al._ (1994); Suárez  _et al._ (1995) .

The article is organised as follows: First, we introduce the Maxwell-Drude
system and expand it in perturbation orders. Second, we briefly recap the
application of the TMM to the 0-th order. Third, we proceed to develop an
extension to the TMM, the PTMM to obtain an analytic expression of the 1-st
order. We then construct the analytic expression of the OPTP spectra in
transmission and reflection. Finally, we apply our developed method to
simulate two types of time-resolved spectral maps to study the sub-period
dynamics of excited multilayers.

##  I Perturbation expansion of the Maxwell-Drude system

We first address the case of radiation within a uniform material with material
properties changing with time as a result of a femtosecond laser excitation
and subsequent thermalisation. We assume that the frequency $\omega$-dependent
total permittivity $\epsilon_{T}[\omega]$ of the material can be written as
the sum of a Drude component $\epsilon_{D}[\omega]$ and a remaining background
component $\epsilon_{B}[\omega]$, which accounts for all the non-Drude
contributions (e.g. the interband transitions) with a generic frequency
dependence. We further assume that the background component of the
permittivity is not modified by the laser. Conversely, we will allow the Drude
parameters to be explicitly time-dependent.

The above situation for a single linear polarisation of the electric $E$ and
magnetic $H$ fields propagating along the $z$ axis is described by the
Maxwell-Drude system (where we have taken the Fourier transform in time $t$,
but not in space, of the Faraday’s and Ampere’s laws):

$\begin{split}\partial_{z}E\left[z,\omega\right]=&-i\,\omega\,\mu[\omega]\,H\left[z,\omega\right],\\\
\partial_{z}H\left[z,\omega\right]=&-i\,\omega\,\epsilon_{B}[\omega]\,E\left[z,\omega\right]+J[z,\omega],\\\
\partial_{t}J[z,t]=&-\gamma J[z,t]+\frac{ne^{2}}{m}E[z,t],\end{split}$ (1)

where $\mu$ is the permeability of the medium, $J[z,t]$ is the current density
(along the same direction as the electric field) induced by the Drude
response, $e$ is the electron charge, and $m$ the effective mass, $n$ is the
number of carriers, and $\gamma$ the inverse scattering lifetime. Notice that
we have not taken the Fourier transform of the last equation. We take the
chance to highlight that the system of equations is homogeneous.

In the case $n$ and $\gamma$ are constant in time, the last equation leads to
the known expression for the Drude conductivity,

$\sigma_{D}[\omega]=\frac{ne^{2}}{m\left(\gamma-i\omega\right)},$ (2)

corresponding to a total permittivity $\epsilon_{T}[\omega]$ (i.e. including
the background contribution and the Drude contribution) of

$\epsilon_{T}[\omega]=\epsilon_{B}[\omega]+i\frac{\sigma_{D}[\omega]}{\omega}.$
(3)

We now treat the case where the number of carriers $n$ and the inverse Drude
scattering lifetime $\gamma$ instead have a generic dependence on time. An
increase in the number of carriers in time can, for instance, describe the
transient photodoping of a semiconductor during a femtosecond laser
excitation, while its decrease could be due to the subsequent carrier
recombination. On the other hand, a change in $\gamma$ can, for instance,
describe the increased number of scatterings triggered by the increased phonon
temperature after an excitation. We write the Drude parameters as the sum of
their equilibrium values, $\gamma^{[0]}$ and $n^{[0]}$, and a time-dependent
part, $\gamma^{[1]}$ and $n^{[1]}$,

$\displaystyle\gamma[z,t]$ $\displaystyle=\gamma^{[0]}+\gamma^{[1]}[z,t],$ (4)
$\displaystyle n[z,t]$ $\displaystyle=n^{[0]}+n^{[1]}[z,t].$ (5)

Notice that we allow for the variations to be also position-dependent.
However, for shortness, we will suppress the explicit position dependence
throughout the rest of this section as it does not play any role. We will
recover it explicitly in the next section.

If we assume that the time variations are small, we can write the fields and
the current up to the first perturbative order as,

$\begin{split}E[z,t]&\approx E^{[0]}[z,t]+E^{[1]}[z,t],\\\ H[z,t]&\approx
H^{[0]}[z,t]+H^{[1]}[z,t],\\\ J[z,t]&\approx
J^{[0]}[z,t]+J^{[1]}[z,t],\end{split}$ (6)

where the two orders must satisfy two different sets of equations. Before
proceeding let us stress here the crucial point of this approach: the
perturbative expansion does not impose any requirement for the variations to
be slow. This is critical since we aim at addressing the case where the
material properties are changing over a similar timescale as the THz
radiation’s period.

The 0-th order satisfies the unperturbed Maxwell-Drude system Eqs. 1, with
constant equilibrium Drude parameters. This set of equations can be solved
analytically within a multilayer using standard approaches like the Transfer
Matrix Method Yang  _et al._ (2021). We assume the 0-th order solved (we will
explicitly write the expression in the next section), and focus on the 1-st
order set of equations. We address explicitly only the case of a time-varying
Drude scattering rate (the generalisation is straightforward),

$\displaystyle\partial_{z}E^{[1]}[z,\omega]=-i\omega\mu[\omega]H^{[1]}[z,\omega],$
$\displaystyle\partial_{z}H^{[1]}[z,\omega]=-i\omega\epsilon_{B}[\omega]E^{[1]}[z,\omega]+J^{[1]}[z,\omega],$
(7)
$\displaystyle\partial_{t}J^{[1]}[z,t]=-\gamma^{[0]}J^{[1]}[z,t]+\frac{n^{[0]}e^{2}}{m}E^{[1]}[z,t]-\gamma^{[1]}J^{[0]}[z,t].$

We can observe that, different from Eqs. 1, this system of equations is not
homogeneous, and the last term in the first order Drude equation acts as a
source term.

We now take the Fourier transform of the last of Eqs. 7, and reduce the system
to the Maxwell’s equations,

$\begin{split}&\partial_{z}E^{[1]}\left[z,\omega\right]=-i\,\omega\,\mu[\omega]\,H^{[1]}\left[z,\omega\right],\\\
&\partial_{z}H^{[1]}\left[z,\omega\right]=-i\,\omega\,\epsilon_{T}[\omega]\,E^{[1]}\left[z,\omega\right]+\mathcal{J}[z,\omega],\end{split}$
(8)

with a source term,

$\mathcal{J}[z,\omega]=\sigma_{D}^{[0]}[\omega]\;\mathcal{F}\left[-\frac{m\,\gamma^{[1]}[t]}{n^{[0]}\,e^{2}}J^{[0]}[z,t],\omega\right],$
(9)

which has the dimensionality of a volume current.

In case both the Drude scattering rate and the Drude carrier density are time
dependent, the expression in Eqs. 8 remains the same, with a source which now
includes another term,

$\displaystyle\mathcal{J}[z,\omega]=$ $\displaystyle\sigma_{D}^{[0]}[\omega]$
(10) $\displaystyle\times$
$\displaystyle\mathcal{F}\left[\frac{n^{[1]}[t]}{n^{[0]}}E^{[0]}[z,t]-\frac{m\,\gamma^{[1]}[t]}{n^{[0]}\,e^{2}}J^{[0]}[z,t],\omega\right].$

For later convenience, we express the source in terms of its spatial Fourier
transform:

$\mathcal{J}[z,\omega]=\sum_{l}\mathcal{J}[k_{l},\omega]\exp[i\,k_{l}\,z].$
(11)

So far we have only described how to treat the effect of time-varying Drude
material parameters on Maxwell’s equations within a single material. We have
found that by expanding the electric and magnetic fields in orders of the
time-dependent correction to the equilibrium Drude parameters, the 0-th order
satisfies the standard Maxwell’s equations, while the 1-st order the non-
homogeneous Eqs. 8. In the following section, we will see how to apply them to
a multilayer system and how to describe an OPTP experiment.

##  II Perturbative Transfer Matrix Method

We address the propagation of electromagnetic radiation through a multilayer
at normal incidence. We count layers from left to right starting from 1 up to
the number of layers $N$. We assume the multilayer system to be sandwiched by
air. Below we will treat the air on the left and on the right of the sample as
semi-infinite layers and assign the index $0$ to the air on the left and $N+1$
to the air on the right. We further assume all layers’ thicknesses $d_{n}$ to
be known. To address the case of propagation through a multilayer, one
typically solves the Maxwell’s equations independently within each layer using
the local material’s properties and then enforces the appropriate field
continuity equations at the interfaces.

The case of materials with time-dependent material properties is handled in a
similar way, with two important differences. The propagating radiation is the
sum of a 0-th and a 1-st order component within each layer. Within each layer,
the four fields (electric and magnetic, 0-th and 1-st) satisfy four equations,
of which the last two are Eqs. 8 and involve both the 0-th and the 1-st order.
The first two instead involve only the 0-th order components and are the
standard Maxwell’s equations within the multilayer. For this reason, we first
solve the propagation of the 0-th order component using standard techniques,
and only after the expression for the 0-th order component is known, we can
proceed with solving Eqs. 8.

###  II.1 0-th order propagation

For the 0-th order, we follow the textbook TMM (a derivation with symbols
consistent with this article can be found in Ref. Yang  _et al._ , 2021). We
report below the main TMM results for the reader’s convenience and to make the
extension to PTMM easier to follow. Within a given layer $n$ the 0-th order
electric and magnetic field can be expressed as a multiplication of a $2\times
2$ matrix and a vector containing the amplitudes of the right $f^{[0]>}_{n}$
and left $f^{[0]<}_{n}$ propagating waves:

$\begin{bmatrix}E_{n}^{[0]}\left[\omega,z\right]\\\
H_{n}^{[0]}\left[\omega,z\right]\end{bmatrix}=\bar{\bar{a}}_{n}\left[\omega,z\right]\begin{bmatrix}f^{[0]>}_{n}\left[\omega\right]\\\
f^{[0]<}_{n}\left[\omega\right]\end{bmatrix},$ (12)

where

$\displaystyle\bar{\bar{a}}_{n}\left[\omega,z\right]=\begin{bmatrix}e^{i\omega\sqrt{\epsilon_{n}\mu_{n}}z}&e^{-i\omega\sqrt{\epsilon_{n}\mu_{n}}z}\\\
-\sqrt{\frac{\epsilon_{n}}{\mu_{n}}}e^{i\omega\sqrt{\epsilon_{n}\mu_{n}}z}&{\sqrt{\frac{\epsilon_{n}}{\mu_{n}}}e^{-i\omega\sqrt{\epsilon_{n}\mu_{n}}z}}\end{bmatrix}.$
(13)

By requiring appropriate continuity equations to the fields at the interfaces
between layers, one finds that the field amplitudes at the two air layers to
the left and the right of the sample are linked by,

$\begin{bmatrix}f^{[0]>}_{N+1}\\\
f^{[0]<}_{N+1}\end{bmatrix}=\bar{\bar{T}}_{[0,N+1]}\begin{bmatrix}f^{[0]>}_{0}\\\
f^{[0]<}_{0}\end{bmatrix},$ (14)

where $\bar{\bar{T}}_{[0,N+1]}$ is the Transfer Matrix with a generalised
form,

$\bar{\bar{T}}_{[n,m]}=\bar{\bar{a}}_{m}^{-1}\left[0\right]\left(\prod_{j=m-1}^{n+1}\bar{\bar{a}}_{j}[d_{j}]\bar{\bar{a}}_{j}^{-1}[0]\right)\bar{\bar{a}}_{n}\left[0\right].$
(15)

###  II.2 1-st order propagation

On the other hand, the set of equations Eqs. 7 cannot be solved using the TMM,
since the equations are not homogeneous, and a source term is present.

We first construct the general solution to Eqs. 7. We obtain that the 1-st
order corrections to the fields within a given layer $n$ as,

$\begin{bmatrix}E_{n}^{[1]}\left[\omega,z\right]\\\
H_{n}^{[1]}\left[\omega,z\right]\end{bmatrix}=\bar{\bar{a}}_{n}\left[\omega,z\right]\bar{f}_{n}\left[\omega\right]+\sum_{l}\mathcal{J}_{n}[k_{l},\omega]\,\bar{b}[\omega,k_{l},z].$
(16)

For the full derivation of the expression above and the definition of
$\bar{b}$ refer to Appendix A.

Without loss of generality, we can assume that only the layer $M$ has time-
dependent properties. The general case can be constructed as the summation of
1-st order corrections due to all the layers that present time-dependent
properties. Using the expression in Eq. 16, the field continuity conditions at
all the layers’ interfaces can be written. We obtain that the wave intensities
in any two layers $n<M$ and $m>M$ are linked by the expression,

$\displaystyle\begin{bmatrix}f^{[1]>}_{m}\\\
f^{[1]<}_{m}\end{bmatrix}=\bar{\bar{T}}_{[n,m]}\begin{bmatrix}f^{[1]>}_{n}\\\
f^{[1]<}_{n}\end{bmatrix}+\sum_{l}\mathcal{J}[k_{l},\omega]\,\bar{\bar{T}}_{[M,m]}$
(17)
$\displaystyle\times\left(\bar{\bar{a}}_{N}^{-1}\left[d_{N}\right]\bar{b}[\omega,k_{l},d_{N}]-\bar{\bar{a}}_{N}^{-1}\left[0\right]\bar{b}[\omega,k_{l},0]\right),$

where $\bar{\bar{T}}_{[n,m]}$ has the same expression as shown in Eq. 15. For
simplicity, considering the two semi-infinite air layers, Eq. 17 can be
written as,

$\displaystyle\begin{bmatrix}f^{[1]>}_{N+1}\\\
f^{[1]<}_{N+1}\end{bmatrix}=\bar{\bar{T}}_{[0,N+1]}\begin{bmatrix}f^{[1]>}_{0}\\\
f^{[1]<}_{0}\end{bmatrix}+\begin{bmatrix}J^{>}_{M}\\\ J^{<}_{M}\end{bmatrix}.$
(18)

The above Eq. 17 can be used to calculate, for instance, transmitted and
reflected waves (more on this below) and, after that, the amplitudes of right
and left moving waves in any layer.

###  II.3 Reflection and transmission through excited layers

We are now ready to compute the reflection and transmission. For the 0-th
order, the approach is the textbook one. Assuming that the THz probe is
incident from the left, we substitute in Eq. 14 $f^{[0]>}_{0}$ with the
temporal shape of the incoming probe, and $f^{[0]<}_{N+1}$ with 0 to signify
that no wave is sent towards the sample from the right. Solving the two
equations for $f^{[0]>}_{N+1}$ and $f^{[0]<}_{0}$ will provide the shape of
the transmitted and the reflected waves, respectively Yang  _et al._ (2021).

We are however interested in the changes to the reflected and transmitted
waves due to the time-varying properties in the sample. Eq. 17 works in
particular for the semi-infinite air layers on the left and on the right. We
need to substitute $f^{[1]>}_{0}$ and $f^{[1]<}_{N+1}$ with 0, since the time-
dependence of the material’s properties, obviously, induces no variation to
the incoming THz probe on the left or the absence of incoming radiation from
the right. Eq. 18 reduces to two equations for $f^{[1]>}_{N+1}$ and
$f^{[1]<}_{0}$, that are respectively the correction to transmitted and
reflected waves.

The correction to the transmission is:

$f^{[1]>}_{N+1}=J^{>}_{M}-\frac{\bar{\bar{T}}_{[0,N+1],12}}{\bar{\bar{T}}_{[0,N+1],22}}J^{<}_{M},$
(19)

where the further subscriptions of $\bar{\bar{T}}_{[0,N+1]}$ refer to the
matrix elements. For the reader’s convenience we have summarised and collected
all the expressions required for the application of the PTMM in Appendix B.

##  III Results

Figure 2: A simple description of the two type of testings. (a) A comparison
between the transmitted probe through non-excited system $|E_{0}|$ and the
1-st order change $|E_{p}-E_{0}|$ pulse and the influence of the material
property change on the $|E_{p}-E_{0}|$ pulse shape (again, not in scale). (b)
The normalized spectrum of $|E_{0}|$ and $|E_{p}-E_{0}|$ (notice that the two
spectra are not in scale with each other). (c) Testing type I: The excitation
pulse and the THz probe is sent at different time delays, so that the material
property function with a fixed increase time can be considered as scanning
over the full THz pulse. (d) Testing type II: The excitation pulse and the THz
pulse are sent at a fixed time delay when the excitation time is overlapping
with the central time position of the THz pulse. The increase time of the
material property function is changed from 80fs (orange) to 800fs (red).
(Note: All blue and red axes are THz amplitude in arbitrary units while not in
the same scale. All orange axes represent the material property change.)

We now apply the approach developed above to an example: the computation of
the propagation of a THz wave through a multilayer. We use the same
experimental THz profile as in Ref. Yang  _et al._ , 2021, as a probe incoming
from the left. We compute the propagation through a quartz(1mm)/Ti(8nm)
sample.We construct the dielectric response for quartz at equilibrium by using
a frequency-independent refractive index of $2.01+0i$,Davies  _et al._ (2018);
Naftaly and Miles (2007) (yet notice that the software works for generic
frequency-dependent material’s properties). We do not add any Drude
contribution for quartz. We assume that Ti’s response to the electric field is
purely Drude-like: we construct the number of carriers $n$ and the Drude
scattering rate $\gamma$ at equilibrium by using a plasma and damping
frequency taken as 7.29eV and 0.082eV respectively Rakić  _et al._ (1998). No
further contributions to the response of Ti at equilibrium have been
considered (yet, again, a further contribution to the dielectric function with
a generic frequency-dependence can be included).

The changes in the materials’ properties due to an optical excitation are
supposed to be known before computing the propagation of the probe pulse. The
method above can address only changes that can be approximated as
modifications of Drude parameters (meaning that bleaching of inter-band
transitions is beyond the proposed approach). An increase in the number of
carriers is what is expected to dominate in semiconductors irradiated with a
frequency above the optical bandgap. On the other hand, an increase in the
scattering rate is what is to be expected of excited metals, where the
increase in the phononic temperature acts as a temporary reduction of
conductivity. Nonetheless, the proposed approach can handle all intermediate
cases as well and can be used to characterise the out-of-equilibrium behaviour
of a material using OPTP.

In the example at hand, for simplicity, we ignore the effect of the optical
laser excitation on quartz and assume that Ti experiences an increase
$\gamma^{[1]}(t)$ in its Drude scattering rate in the form,

$\delta\gamma(t)=h\;\frac{e^{-\frac{t-t_{0}}{b}}}{e^{-\frac{(t-t_{0})-\nicefrac{{a}}{{2}}}{\nicefrac{{a}}{{4}}}}+1},$
(20)

where $h$ controls the maximum scattering rate change, $a$ is the increase
time and $b$ is the following decrease time, $t_{0}$ is the time position of
the excitation.

The effect of the non-equilibrium is shown in Fig. 2(a) and (b). We here refer
the transmitted probe through a non-excited system as $E_{0}$ (blue in Fig.
2(a)) and an excited system as $E_{p}$. Thus, $E_{p}-E_{0}$ (red in Fig. 2(a))
is the first-order change of the transmitted probe. And the orange line refers
to the scattering rate $\gamma^{[1]}(t)$ change. In Fig. 2(b) one can observe
that the transmitted wave at equilibrium has relatively a narrow spectrum. On
the other hand, when the scattering rate is assumed to be time-dependent
(orange line) the first-order correction ($E_{p}-E_{0}$) to the transmission
shows a much broadened spectrum (see Fig. 2(b)). One can observe that, for the
parts of the THz probe which overlap with the slowly changing scattering rate,
the correction retains a similar shape to the transmitted probe. However, the
part of the probe that overlaps with times when the scattering rate changes
sharply, produces a 1-st order correction which gains the temporal features of
the dynamics of the non-equilibrium state broadening the spectrum. This is a
very promising feature that rises the hope of increasing the time-sensitivity
of the OPTP technique below the period of the employed THz radiation. One can
further observe that, as expected, the correction has the same sign as the
probe signal, since the increase of the scattering rate decreases the
conductivity and therefore increases the transmission.

In order to address this aspect, we perform two types of analysis. In the
first type (Type I) we will maintain the temporal shape of $\gamma^{[1]}(t)$
and vary the time delay between the optical pump and the THz probe, with the
aim of analysing how sensitive OPTP is to the excited state of the system. For
Type II analysis, we will keep the delay constant and change the rise time of
the perturbation $\gamma^{[1]}(t)$, with the aim of testing the lowest time
resolution achievable with this technique. A schematic description of these
two types of testings is shown in Fig. 2 (c) and (d). Fig. 2 (c) shows the two
extremes of the delay between the probe (blue line) and the pump. The orange
line shows the time evolution of the Drude scattering rate: its time position
is linked to the optical excitation time position. Fig. 2 (d) shows the case
of a very fast increase of the scattering rate, compared to a slower dynamics:
we will analyse the differences in the OPTP signal to study what is the
fastest dynamics that can be resolved.

We perform a set of calculations based on Type I analysis. We vary the time
delay between the optical pump and THz probe for four cases of dynamics with
an increasing rise time of the scattering rate (100fs, 200fs, 300fs, and
400fs) and generate a spectrum map of the OPTP signal (change in transmitted
electric field with pump-on and pump-off) as shown in Fig. 3. We observe that
the spectral maps show quantitative differences when the out-of-equilibrium
dynamics (increase time of $\gamma^{[1]}(t)$) of the system changes. The
effect is strongest when the time position of the optical pump and the THz
probe overlap within the time width of the THz pulse. We can clearly observe a
pronounced broadening of the OPTP spectrum with faster non-equilibrium
dynamics. The widest broadening happens at around -8ps, which is when the pump
pulse overlaps with the central position time of the probe.

Figure 3: The normalized frequency maps of $|E_{p}-E_{0}|$ when the material
property function with increase time of 100fs, 200fs, 300fs and 400fs is
scanning through the THz porbe (the time delay between the excitation laser
and THz probe is changing).

We now perform Type II analysis to try to extract some systematic dependence
of the spectral width of the OPTP spectrum on the rise time of the Drude
scattering rate. We fix the optical pump THz probe delay time at the delay
that shows approximately the maximal spectral width (-8 ps). Then we change
the rise time of the Drude scattering rate from 80fs to 800fs and produce a
new frequency map as shown in Fig. 4. In this new map, we can more clearly see
how faster non-equilibrium dynamics lead to broader spectral features in the
OPTP signal. We observe that the inverse of frequency at which the spectrum
reaches 1$\%$ of its maximum for each increase time (red dotted line in Fig. 4
and inset) is a good indication of the increase time. The increase time and
the frequency of the probe scale with an inverse proportionality for points of
equal spectral intensity. Specifically, when the intensity of the transmitted
THz is 1$\%$ of the total, the proportionality is close to $1/\omega$ (as
shown in Fig. 4 inset). This is indeed a very interesting feature since a very
simple operation can lead to a reasonable estimation of the material’s
properties ultrafast modification time under laser irradiation. Notice that
this analysis does not require performing calculations, and can be conducted
directly on the experimental results.

The above-mentioned correspondence, although very convenient due to its
simplicity, is not perfect, as can be observed from the inset in Fig. 4. For
an accurate extraction of the excitation time, a comparison between
experiments and theory is needed. It is however important to note how the
method can clearly resolve timescales (hundreds of fs) that are far shorter
than the period and the time width of the employed radiation ($\approx$ 5ps).

Figure 4: A Normalized frequency map of testing Type II, where the excitation
time delay is fixed at the central position of the THz probe (-8 ps) and the
increase time of the material property function increases from 80 fs to 800
fs. The red dotted line on the map represents the frequency width of 1$\%$ of
the maximum spectrum amplitude. The blue line is increase time vs. 1/increase
time. Inset: The inverse plotting of the extracted red dotted line and blue
line on the map. The relationship between 1/frequency-width and increase time.
Red dotted line: increase time vs. 1/ frequency. Blue solid line: increase
time vs. increase time.

##  IV Conclusion

We have constructed a theoretical treatment that can describe the propagation
of a THz pulse through a material with Drude properties changing in time over
a timescale shorter or comparable to the probe period and time-width. To do
that we had to go beyond the approximation of quasi-static changes in material
properties. Such treatment allowed us to observe spectral features of the time
evolution of the material’s properties being transferred to the OPTP signal.
The analysis of these emerging spectral features allows for the extraction of
timescales well below the commonly assumed time resolution of the OPTP
technique. We have, in particular, suggested a very simple analysis of the
spectral features of the OPTP signal that gives a reasonable approximation of
the excitation time of a material, without requiring a direct comparison of
experiment and theory. Yet it is clear that such comparison can lead to much
more precise estimations.

These results show how the OPTP technique can reveal a range of information
regarding the ultrafast time evolution of out-of-equilibrium states in
materials that has been so far neglected.

## References

  * Schmuttenmaer (2004) C. A. Schmuttenmaer, Chemical Reviews 104, 1759 (2004).
  * Ulbricht  _et al._ (2011) R. Ulbricht, E. Hendry, J. Shan, T. F. Heinz, and M. Bonn, Reviews of Modern Physics 83, 543 (2011).
  * George  _et al._ (2008) P. A. George, J. Strait, J. Dawlaty, S. Shivaraman, M. Chandrashekhar, F. Rana, and M. G. Spencer, Nano letters 8, 4248 (2008).
  * Strait  _et al._ (2011) J. H. Strait, H. Wang, S. Shivaraman, V. Shields, M. Spencer, and F. Rana, Nano letters 11, 4902 (2011).
  * Seifert  _et al._ (2016) T. Seifert, S. Jaiswal, U. Martens, J. Hannegan, L. Braun, P. Maldonado, F. Freimuth, A. Kronenberg, J. Henrizi, I. Radu, E. Beaurepaire, Y. Mokrousov, P. M. Oppeneer, M. Jourdan, G. Jakob, D. Turchinovich, L. M. Hayden, M. Wolf, M. Münzenberg, M. Kläui, and T. Kampfrath, Nature Photonics 10, 483 (2016), number: 7 Publisher: Nature Publishing Group.
  * Hoffmann  _et al._ (2007) M. C. Hoffmann, K.-L. Yeh, J. Hebling, and K. A. Nelson, Opt. Express 15, 11706 (2007).
  * Matthäus  _et al._ (2006) G. Matthäus, T. Schreiber, J. Limpert, S. Nolte, G. Torosyan, R. Beigang, S. Riehemann, G. Notni, and A. Tünnermann, Optics communications 261, 114 (2006).
  * Kampfrath  _et al._ (2013) T. Kampfrath, M. Battiato, P. Maldonado, G. Eilers, J. Nötzold, S. Mährlein, V. Zbarsky, F. Freimuth, Y. Mokrousov, S. Blügel, _et al._ , Nature nanotechnology 8, 256 (2013).
  * Carva  _et al._ (2011) K. Carva, M. Battiato, and P. M. Oppeneer, Physical Review Letters 107, 207201 (2011), publisher: American Physical Society.
  * Battiato  _et al._ (2010) M. Battiato, K. Carva, and P. M. Oppeneer, Physical Review Letters 105, 027203 (2010), publisher: American Physical Society.
  * Eschenlohr  _et al._ (2013) A. Eschenlohr, M. Battiato, P. Maldonado, N. Pontius, T. Kachel, K. Holldack, R. Mitzner, A. Föhlisch, P. M. Oppeneer, and C. Stamm, Nature Materials 12, 332 (2013).
  * Zhang and Hübner (2000) G. Zhang and W. Hübner, Physical review letters 85, 3025 (2000).
  * Beaurepaire  _et al._ (1996) E. Beaurepaire, J.-C. Merle, A. Daunois, and J.-Y. Bigot, Physical Review Letters 76, 4250 (1996).
  * Battiato  _et al._ (2012) M. Battiato, K. Carva, and P. M. Oppeneer, Physical Review B 86, 024404 (2012), publisher: American Physical Society.
  * Carva  _et al._ (2013) K. Carva, M. Battiato, D. Legut, and P. M. Oppeneer, Physical Review B 87, 184425 (2013), publisher: American Physical Society.
  * Ju  _et al._ (1998) G. Ju, A. Nurmikko, R. Farrow, R. Marks, M. Carey, and B. Gurney, Physical Review B 58, R11857 (1998).
  * Van Kampen  _et al._ (2002) M. Van Kampen, C. Jozsa, J. Kohlhepp, P. LeClair, L. Lagae, W. De Jonge, and B. Koopmans, Physical review letters 88, 227201 (2002).
  * Langner  _et al._ (2009) M. Langner, C. Kantner, Y. Chu, L. Martin, P. Yu, J. Seidel, R. Ramesh, and J. Orenstein, Physical review letters 102, 177601 (2009).
  * Agranat  _et al._ (1998) M. Agranat, S. Anhitkov, A. Kirillin, V. Fortov, S. Anislmov, A. Granovskii, and P. Kondratenko, JETP letters 67, 953 (1998).
  * Kirilyuk  _et al._ (2010) A. Kirilyuk, A. V. Kimel, and T. Rasing, Rev. Mod. Phys. 82, 2731 (2010).
  * Li  _et al._ (2018) G. Li, K. Kushnir, Y. Dong, S. Chertopalov, A. M. Rao, V. N. Mochalin, R. Podila, and L. V. Titova, 2D Materials 5, 035043 (2018), publisher: IOP Publishing.
  * La-o vorakiat  _et al._ (2017) C. La-o vorakiat, L. Cheng, T. Salim, R. A. Marcus, M.-E. Michel-Beyerle, Y. M. Lam, and E. E. M. Chia, Applied Physics Letters 110, 123901 (2017), publisher: American Institute of Physics.
  * Kar  _et al._ (2015) S. Kar, Y. Su, R. R. Nair, and A. K. Sood, ACS Nano 9, 12004 (2015), publisher: American Chemical Society.
  * Kar  _et al._ (2014) S. Kar, D. R. Mohapatra, E. Freysz, and A. K. Sood, Physical Review B 90, 165420 (2014).
  * Tomadin  _et al._ (2018) A. Tomadin, S. M. Hornett, H. I. Wang, E. M. Alexeev, A. Candini, C. Coletti, D. Turchinovich, M. Kläui, M. Bonn, F. H. Koppens, _et al._ , Science advances 4, eaar5313 (2018).
  * Ruan  _et al._ (2021) S. Ruan, X. Lin, H. Chen, B. Song, Y. Dai, X. Yan, Z. Jin, G. Ma, and J. Yao, Applied Physics Letters 118, 011102 (2021).
  * Alberding  _et al._ (2016) B. G. Alberding, G. P. Kushto, P. A. Lane, and E. J. Heilweil, Applied Physics Letters 108, 223104 (2016), publisher: American Institute of Physics.
  * Neu and Schmuttenmaer (2018) J. Neu and C. A. Schmuttenmaer, Journal of Applied Physics 124, 231101 (2018).
  * Němec  _et al._ (2002) H. Němec, F. Kadlec, and P. Kužel, The Journal of Chemical Physics 117, 8454 (2002), publisher: American Institute of Physics.
  * Němec  _et al._ (2005a) H. Němec, F. Kadlec, C. Kadlec, P. Kužel, and P. Jungwirth, The Journal of Chemical Physics 122, 104504 (2005a), publisher: American Institute of Physics.
  * Němec  _et al._ (2005b) H. Němec, F. Kadlec, S. Surendran, P. Kužel, and P. Jungwirth, The Journal of Chemical Physics 122, 104503 (2005b), publisher: American Institute of Physics.
  * Kužel  _et al._ (2007) P. Kužel, F. Kadlec, and H. Němec, The Journal of Chemical Physics 127, 024506 (2007).
  * Carpene  _et al._ (2008) E. Carpene, E. Mancini, C. Dallera, M. Brenna, E. Puppin, and S. De Silvestri, Phys. Rev. B 78, 174422 (2008).
  * Kampfrath  _et al._ (2002) T. Kampfrath, R. G. Ulbrich, F. Leuenberger, M. Münzenberg, B. Sass, and W. Felsch, Phys. Rev. B 65, 104429 (2002).
  * Fann  _et al._ (1992) W. Fann, R. Storz, H. Tom, and J. Bokor, Physical Review B 46, 13592 (1992).
  * Sun  _et al._ (1994) C.-K. Sun, F. Vallée, L. Acioli, E. Ippen, and J. Fujimoto, Physical Review B 50, 15337 (1994).
  * Suárez  _et al._ (1995) C. Suárez, W. Bron, and T. Juhasz, Physical review letters 75, 4536 (1995).
  * Yang  _et al._ (2021) Y. Yang, S. Dal Forno, and M. Battiato, Journal of Infrared, Millimeter, and Terahertz Waves (2021), 10.1007/s10762-021-00815-5.
  * Davies  _et al._ (2018) C. L. Davies, J. B. Patel, C. Q. Xia, L. M. Herz, and M. B. Johnston, Journal of Infrared, Millimeter, and Terahertz Waves 39, 1236 (2018).
  * Naftaly and Miles (2007) M. Naftaly and R. E. Miles, Journal of Applied Physics 102, 043517 (2007).
  * Rakić  _et al._ (1998) A. D. Rakić, A. B. Djurišić, J. M. Elazar, and M. L. Majewski, Appl. Opt. 37, 5271 (1998).

##  Appendix A Detailed expression for PTMM

We assume here that the 0-th order component of the fields have been computed
and is known in all the layers. We need to solve the Eqs. 8. The TMM is suited
to solve Eqs. 8 in the absence of the source term $\mathcal{J}[z,\omega]$, but
not when the term is different from 0.

The general solution of the non-homogeneous system can be constructed by
computing the general solution of the associated homogeneous system and
summing it to a particular solution. The general solution of the associated
homogeneous system,

$\begin{split}&\partial_{z}E^{[1]}\left[z,\omega\right]=-i\,\omega\,\mu[\omega]\,H^{[1]}\left[z,\omega\right],\\\
&\partial_{z}H^{[1]}\left[z,\omega\right]=-i\,\omega\,\epsilon_{T}[\omega]\,E^{[1]}\left[z,\omega\right],\end{split}$
(21)

is constructed using TMM.

We now have to construct any one particular solution to the non-homogeneous
system. We write the source within a given layer in terms of its spatial
Fourier components,

$\mathcal{J}[z,\omega]=\sum_{l}\mathcal{J}[k_{l},\omega]\exp[i\,k_{l}\,z],$
(22)

where it should be noted that $k_{l}$ is the spatial Fourier wavevector of the
spatial distribution of the source term and not the light wavevector,
therefore in general $k_{l}\neq\omega\sqrt{\epsilon\mu}$. For shortness in the
following formulas we will drop the Fourier summation, to recover it only in
the final expression.

We look for a particular solution in the form

$\displaystyle E^{[1]}\left[z,t\right]=$ $\displaystyle Ee^{i(k_{l}z-\omega
t)},$ (23) $\displaystyle H^{[1]}\left[z,t\right]=$ $\displaystyle
He^{i(k_{l}z-\omega t)},$ (24)

By substituting in the Eqs. 8 we obtain the amplitudes of the fields for the
particular solution,

$\displaystyle k_{l}E=$ $\displaystyle\mu\omega H,$ (25) $\displaystyle
ik_{l}H=$ $\displaystyle i\epsilon\omega E+\mathcal{J}[k_{l},\omega],$ (26)

giving the particular solution,

$\bar{F}\left[\omega,z\right]=\begin{bmatrix}E\left[\omega,z\right]\\\
H\left[\omega,z\right]\end{bmatrix}=\mathcal{J}[k_{l},\omega]\;\bar{b}[\omega,k_{l},z],$
(27)

with

$\bar{b}[\omega,k,z]=\frac{i\,e^{ikz}}{\epsilon\mu\omega^{2}-k^{2}}\begin{bmatrix}\omega\mu\\\
k\end{bmatrix}.$ (28)

We therefore write the general solution (recovering the summation on all the
Fourier components of the source term) as,

$\bar{F}\left[\omega,z\right]=\bar{\bar{a}}\left[\omega,z\right]\bar{f}\left[\omega\right]+\sum_{l}\mathcal{J}[k_{l},\omega]\,\bar{b}[\omega,k_{l},z].$
(29)

Notice that the expression above is the solution to the inhomogeneous
Maxwell’s equation within a single layer: the interface conditions still need
to be applied and the propagation through the multilayer still needs to be
computed. This is however done following the same idea as in the TMM, and will
not be addressed explicitly here.

##  Appendix B Summary of the method

For the reader’s convenience, we collect and summarise in this section the
results of the whole developed approach.

We assume a multilayer, with layers numbered with $n=1...N$ and with known
thicknesses $d_{n}$, sandwiched by two semi-infinite air regions (identified
by the indices $n=0$ and $n=N+1$). We further assume that one or more of the
layers are brought out of equilibrium by some means (which, notice, are not
described here). We restrict ourselves to the case where only the Drude
component of the dielectric response is modified by the out-of-equilibrium
configuration, but allow for the materials to have a dielectric response which
is the summation of a Drude part and background contributions
$\epsilon_{B}[\omega]$ (which are however assumed not altered by the
excitation). We assume that the Drude carrier density’s $n$, and the Drude
scattering rate’s $\gamma$ position and time dependence are perturbations of
the equilibrium value,

$\displaystyle\gamma[z,t]$ $\displaystyle=\gamma^{[0]}+\gamma^{[1]}[z,t],$
(30) $\displaystyle n[z,t]$ $\displaystyle=n^{[0]}+n^{[1]}[z,t].$ (31)

We describe here only the propagation of electromagnetic waves through the
layers with explicitly time-dependent material’s properties only at normal
incidence.

The fields $E$ and $H$ in each layer $n$ can be constructed as a summation of
a 0-th order and a 1-st order contribution:

$\begin{bmatrix}E_{n}\left[\omega,z\right]\\\
H_{n}\left[\omega,z\right]\end{bmatrix}\approx\begin{bmatrix}E_{n}^{[0]}\left[\omega,z\right]\\\
H_{n}^{[0]}\left[\omega,z\right]\end{bmatrix}+\begin{bmatrix}E_{n}^{[1]}\left[\omega,z\right]\\\
H_{n}^{[1]}\left[\omega,z\right]\end{bmatrix}.$ (32)

Before proceeding, we remind that the fields are more conveniently expressed
in terms of the right and left propagation wave intensities as,

$\begin{bmatrix}E\left[\omega,z\right]\\\
H\left[\omega,z\right]\end{bmatrix}=\bar{\bar{a}}\left[\omega,z\right]\begin{bmatrix}f^{>}\left[\omega\right]\\\
f^{<}\left[\omega\right]\end{bmatrix},$ (33)

where,

$\displaystyle\bar{\bar{a}}\left[\omega,z\right]=\begin{bmatrix}e^{i\omega\sqrt{\epsilon\mu}z}&e^{-i\omega\sqrt{\epsilon\mu}z}\\\
-\sqrt{\frac{\epsilon}{\mu}}e^{i\omega\sqrt{\epsilon\mu}z}&{\sqrt{\frac{\epsilon}{\mu}}e^{-i\omega\sqrt{\epsilon\mu}z}}\end{bmatrix}.$
(34)

The 0-th order component is calculated using standard TMM and gives that the
wave intensities in any two layers $n$ and $m$ (including the seminfinite air
regions on either side of the multilayer) are linked by the expression

$\begin{bmatrix}f^{[0]>}_{m}\\\
f^{[0]<}_{m}\end{bmatrix}=\bar{\bar{T}}_{[n,m]}\begin{bmatrix}f^{[0]>}_{n}\\\
f^{[0]<}_{n}\end{bmatrix},$ (35)

where

$\bar{\bar{T}}_{[n,m]}=\bar{\bar{a}}_{m}^{-1}\left[0\right]\left(\prod_{j=m-1}^{n+1}\bar{\bar{a}}_{j}[d_{j}]\bar{\bar{a}}_{j}^{-1}[0]\right)\bar{\bar{a}}_{n}\left[0\right].$
(36)

The above expression can be used to calculate, for instance, transmitted and
reflected waves and, after that, the amplitudes of right and left moving waves
in any layer.

For the 1-st order components, starting from Eq. 8, the general solution can
be written as Eq. 29. Assuming that only the layer M ($n<M<m$) is excited with
time-dependent properties. We obtain the wave intensities in any two layers
$n$ and $m$ are linked by the expression,

$\displaystyle\begin{bmatrix}f^{[1]>}_{m}\\\
f^{[1]<}_{m}\end{bmatrix}=\bar{\bar{T}}_{[n,m]}\begin{bmatrix}f^{[1]>}_{n}\\\
f^{[1]<}_{n}\end{bmatrix}+\sum_{l}\mathcal{J}[k_{l},\omega]\,\bar{\bar{T}}_{[M,m]}$
(37)
$\displaystyle\times\left(\bar{\bar{a}}_{N}^{-1}\left[d_{N}\right]\bar{b}[\omega,k_{l},d_{N}]-\bar{\bar{a}}_{N}^{-1}\left[0\right]\bar{b}[\omega,k_{l},0]\right),$

For simplicity, Eq. 37 can be written as,

$\displaystyle\begin{bmatrix}f^{[1]>}_{m}\\\
0\end{bmatrix}=\bar{\bar{T}}_{[n,m]}\begin{bmatrix}0\\\
f^{[1]<}_{n}\end{bmatrix}+\begin{bmatrix}J^{>}_{M}\\\ J^{<}_{M}\end{bmatrix}.$
(38)

Here $f^{[1]>}_{n}$ and $f^{[1]<}_{m}$ equal to zero because that the time-
dependence of the material’s properties will induce no variation to the
incoming THz probe on the left or the absence of incoming radiation from the
right. Based on this, the correction of the transmission will be

$f^{[1]>}_{m}=J^{>}_{M}-\frac{\bar{\bar{T}}_{[n,m],12}}{\bar{\bar{T}}_{[n,m],22}}J^{<}_{M}.$
(39)


# Reducing Programs to Objects

Ver:  tcbcolupper0.1.0

Yegor Bugayenko  HuaweiRussiaMoscow<EMAIL_ADDRESS>
###### Abstract.

C++, Java, C#, Python, Ruby, JavaScript are the most powerful object-oriented
programming languages, if language power would be defined as the number of
_features_ available for a programmer. EO, on the other hand, is an object-
oriented programming language with a reduced set of features: it has nothing
by objects and mechanisms of their composition and decoration. We are trying
to answer the following research question: “Which known features are possible
to implement using only objects?”

##  1\. Features

To answer our research question we selected most complex features and
demonstrated how each of them may be represented in EO (Bugayenko, 2021)
objects:

  * •

Non-conditional jumps (Sec. 1.1),

  * •

Data and code pointers (Sec. 1.2),

  * •

Procedures (Sec. 1.3),

  * •

Classes (Sec. 1.4),

  * •

Exceptions (Sec. 1.6),

  * •

Anonymous functions (Sec. 1.7),

  * •

Generators (Sec. 1.8),

  * •

Types and casting (Sec. 1.9),

  * •

Reflection (Sec. 1.10),

  * •

Static methods (Sec. 1.11),

  * •

Inheritance (Sec. 1.12),

  * •

Method overloading (Sec. 1.13),

  * •

Java generics (Sec. 1.14),

  * •

C++ templates (Sec. 1.15),

  * •

Mixins (Sec. 1.16),

  * •

Java annotations (Sec. 1.17).

Other features are more trivial, that’s why they are not presented in this
paper, such as operators, loops, variables, code blocks, constants, branching,
and so on.

###  1.1. Goto

Goto is a one-way imperative transfer of control to another line of code.
There are only two possible cases of goto jumps: forward and backward.

####  1.1.1. Backward Jump

This is a “backward” jump example in C language:

#include ”stdio.h” void f() int i = 1; again: i++; if (i ¡ 10) goto again;
printf(”Finished!”);

It can be mapped to the following EO code:

[] ¿ f memory ¿ i seq ¿ @ i.write 1 Q.org.eolang.gray.goto [g] seq ¿ @ i.write
(i.add 1) if. i.less 10 g.backward TRUE Q.org.eolang.io.stdout ”Finished!”

Here, the one-argument abstract atom goto is being copied with a one-argument
abstract anonymous object, which is the sequence of objects doing the
increment of i and then the comparison of it with the number ten. If the
condition is true, g.backward is called, which leads to a backward jump and
re-iteration of goto.

####  1.1.2. Forward Jump

This is an example of a “forward” jump in C language:

int f(int x) int r = 0; if (x == 0) goto exit; r = 42 / x; exit: return r;

It can be mapped to the following EO code:

[x] ¿ f memory ¿ r seq ¿ @ r.write 0 Q.org.eolang.gray.goto [g] seq ¿ @ if.
x.eq 0 g.forward TRUE r.write (42.div x) r

Here, the same abstract atom goto is copied with an abstract one-argument
object, which is a sequence of objects. When the condition is true, a forward
jump is performed by g.forward atom.

Similar way, the atom goto may be used to simulate other conditional jump
statements, like break, continue, or return in the middle of a function body
(see Sec. 1.3).

####  1.1.3. Complex Case

This is a more complex case of using goto in C:

#include ”stdio.h” void f(int a, int b) goto start; back: printf(”A”); start:
if (a ¿ b) goto back; printf(”B”);

In order to translate this code to EO it has to be refactored as Fig. 1
demonstrates. The function f() is copied twice and each copy has its own
execution flow implemented.

Figure 1. The function f with a few goto statements inside is translated to
two functions, reducing the complexity of the code at the cost of introducing
duplication.

#include ”stdio.h” void f(int a, int b) f1(a, b); void f1(int a, int b) if (a
¿ b) f2(a, b); printf(”B”); void f2(int a, int b) back: printf(”A”); if (a ¿
b) goto back; printf(”B”);

Then, the translation to EO is trivial, with the use of the goto object.

In more complex cases a program may first be restructured to replace goto
statements with loops and branching, as suggested by Williams and Chen (1985);
Pan and Dromey (1996); Erosa and Hendren (1994); Ceccato et al. (2008).

####  1.1.4. Multiple Returns

Some programming languages allow a function to exit at an arbitrary place, not
only at the end, using return statements, for example:

void abs(int x) if (x ¿ 0) return x; return -1 * x;

This can be mapped to the following EO code using goto object:

[x] ¿ abs Q.org.eolang.gray.goto ¿ @ [g] seq ¿ @ if. x.greater 0 g.forward x
TRUE g.forward -1.mul x

The dataization of g.forward will exit the goto object wrapping the entire
code in the “function” abs.

###  1.2. Pointers

A pointer is an object in many programming languages that stores a memory
address. Pointers may point to data memory and to program memory.

####  1.2.1. Pointers to Data

This is an example of C code, where the pointer p is first incremented by
seven times sizeof(book) (which is equal to 108) and then de-referenced to
become a struct book mapped to memory. Then, the title part of the struct is
filled with a string and the price part is returned as a result of the
function f:

#include ”string.h” struct book char title[100]; long long price; ; int
f(struct book* p) struct book b = *(p + 7); strcpy(b.title, ”Object
Thinking”); return b.price;

This code can be mapped to the following EO code:

[ptr] ¿ book ptr.block ¿ title 100 [b] (b.as-string ¿ @) ptr.block ¿ price 8
[b] (b.as-int ¿ @) Q.org.eolang.gray.heap.pointer ¿ p1 0x1A76EC09 108 [p] ¿ f
seq ¿ @ book (p.add 7) ¿ b b.title.write ”Object Thinking” b.price

Here, p1 is an object that can be used as an argument of f. It is a copy of an
abstract object heap.pointer, which expects two: 1) an absolute address in
memory, and 2) the size of the memory block it points to, in bytes. Its
attribute block expects two attributes: 1) the number of bytes in the heap,
and 2) an abstract object that can encapsulate bytes which were just read from
memory.

The object heap is an abstraction of a random access memory.

####  1.2.2. Pointers to Code

A pointer may not only refer to data in the heap, but also to executable code
in memory (there is no difference between “program” and “data” memories both
in x86 and ARM architectures). This is an example of C program, which calls a
function referenced by a function pointer, providing two integer arguments to
it:

int foo(int x, int y) return x + y; int f() int (*p)(int, int); p = &foo;
return (*p) (7, 42);

This code can be mapped to the following EO code:

[x y] ¿ foo x.add y ¿ @ [] ¿ f Q.org.eolang.gray.cage ¿ p seq ¿ @ p.write [x
y] foo x y ¿ @ p 7 42

Important to notice that the following code is not possible to represent in
EO:

int f() int (*p)(int); p = (int(*)(int)) 0x761AFE65; return (*p) (42);

Here, the pointer refers to an arbitrary address in program memory, where some
executable code is supposed to be located.

####  1.2.3. Variables in Stack

This C function, which returns seven (tested with GCC), assumes that variables
are placed in stack sequentially and uses pointer de-referencing to access
them:

int f() long long a = 42; long long b = 7; return *(&a - 1);

This code can be mapped to the following EO code:

[p] ¿ long64 p.block ¿ @ 8 [b] (b.as-int ¿ @) [p] ¿ f seq ¿ @
Q.org.eolang.gray.heap.malloc 16 ¿ stack long64 (stack.pointer 0 8) ¿ b
b.write 7 long64 (stack.pointer 8 8) ¿ a a.write 42 long64 (a.p.sub 1) ¿ ret!
h.free stack ret

Here, the atom malloc allocates a segment of bytes in the heap. Later, the
atom free releases it. The attribute ret is made constant in order to avoid
its recalculation after it’s “returned” (this mechanism is explained in Sec.
1.5 where destructors are discussed).

###  1.3. Procedures

A subroutine is a sequence of program instructions that performs a specific
task, packaged as a unit. In different programming languages, a subroutine may
be called a routine, subprogram, function, method, or procedure. In this PHP
example, a function max is defined:

function max($a,$b) if ($a>$b) return $a;return$b;

It can be mapped to the following EO code:

[a b] ¿ max goto ¿ @ [g] seq ¿ @ if. a.greater b g.forward a TRUE b

This example also demonstrates how goto object can be used to simulate the
behavior of the return statement from within the body of a method.

###  1.4. Classes

A class is an extensible program-code-template for creating objects, providing
initial values for state (member variables) and implementations of behavior
(member functions or methods). The following program contains a Ruby class
with a single constructor, two methods, and one mutable member variable:

class Book def initialize(i) @id = id puts ”New book!” end def path
”/tmp/${@id}.txt"enddefmove(i)@id=iendend\par
ItcanbemappedtothefollowingEOcode,whereaclassbecomesafactoryofobjects:\par\ffcode+importorg.eolang.gray.cage+importorg.eolang.txt.sprintf\par[]>book[i]>newcage>idseq>@id.writei[][]>pathsprintf>@"/tmp/id[i]>moveid.writei>@\par
Here,theconstructorisrepresentedbytheobject\definecolor{tcbcolframe}{rgb}{0.6,0.6,0.6}\definecolor{tcbcolback}{rgb}{0.975,0.975,0.975}\definecolor{tcbcol@origin}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\leavevmode\hbox
to20.82pt{\vbox to10pt{\pgfpicture\makeatletter\hbox{\hskip 0.0pt\lower
0.0pt\hbox to0.0pt{\pgfsys@beginscope\pgfsys@invoke{
}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{
}\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{
}\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox
to0.0pt{{}{}{}{}\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.6,0.6,0.6}\pgfsys@color@gray@fill{0.6}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.0pt}{1.1pt}\pgfsys@lineto{0.0pt}{8.9pt}\pgfsys@curveto{0.0pt}{9.5075pt}{0.4925pt}{10.0pt}{1.1pt}{10.0pt}\pgfsys@lineto{19.72224pt}{10.0pt}\pgfsys@curveto{20.32976pt}{10.0pt}{20.82225pt}{9.5075pt}{20.82225pt}{8.9pt}\pgfsys@lineto{20.82225pt}{1.1pt}\pgfsys@curveto{20.82225pt}{0.4925pt}{20.32976pt}{0.0pt}{19.72224pt}{0.0pt}\pgfsys@lineto{1.1pt}{0.0pt}\pgfsys@curveto{0.4925pt}{0.0pt}{0.0pt}{0.4925pt}{0.0pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.975,0.975,0.975}\pgfsys@color@gray@fill{0.975}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.1pt}{1.1pt}\pgfsys@lineto{0.1pt}{8.9pt}\pgfsys@curveto{0.1pt}{9.45229pt}{0.54771pt}{9.9pt}{1.1pt}{9.9pt}\pgfsys@lineto{19.72224pt}{9.9pt}\pgfsys@curveto{20.27454pt}{9.9pt}{20.72224pt}{9.45229pt}{20.72224pt}{8.9pt}\pgfsys@lineto{20.72224pt}{1.1pt}\pgfsys@curveto{20.72224pt}{0.54771pt}{20.27454pt}{0.1pt}{19.72224pt}{0.1pt}\pgfsys@lineto{1.1pt}{0.1pt}\pgfsys@curveto{0.54771pt}{0.1pt}{0.1pt}{0.54771pt}{0.1pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{{}}{{}}{{}}{{}}{{}}{{}}{{}}\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{1.8pt}{2.5pt}\pgfsys@invoke{
}\hbox{{\color[rgb]{0,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@gray@stroke{0}\pgfsys@color@gray@fill{0}\hbox{\set@color{\ignorespaces\vrule
height=6.0pt,depth=1.0pt,width=0.0pt{new}}}}}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope{}{}{}\hss}\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\hss}}\lxSVG@closescope\endpgfpicture}},whichinitializesthe``gray^{\prime\prime}object\definecolor{tcbcolframe}{rgb}{0.6,0.6,0.6}\definecolor{tcbcolback}{rgb}{0.975,0.975,0.975}\definecolor{tcbcol@origin}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\leavevmode\hbox
to22.49pt{\vbox to10.94pt{\pgfpicture\makeatletter\hbox{\hskip 0.0pt\lower
0.0pt\hbox to0.0pt{\pgfsys@beginscope\pgfsys@invoke{
}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{
}\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{
}\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox
to0.0pt{{}{}{}{}\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.6,0.6,0.6}\pgfsys@color@gray@fill{0.6}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.0pt}{1.1pt}\pgfsys@lineto{0.0pt}{9.84444pt}\pgfsys@curveto{0.0pt}{10.45195pt}{0.4925pt}{10.94444pt}{1.1pt}{10.94444pt}\pgfsys@lineto{21.38892pt}{10.94444pt}\pgfsys@curveto{21.99643pt}{10.94444pt}{22.48892pt}{10.45195pt}{22.48892pt}{9.84444pt}\pgfsys@lineto{22.48892pt}{1.1pt}\pgfsys@curveto{22.48892pt}{0.4925pt}{21.99643pt}{0.0pt}{21.38892pt}{0.0pt}\pgfsys@lineto{1.1pt}{0.0pt}\pgfsys@curveto{0.4925pt}{0.0pt}{0.0pt}{0.4925pt}{0.0pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.975,0.975,0.975}\pgfsys@color@gray@fill{0.975}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.1pt}{1.1pt}\pgfsys@lineto{0.1pt}{9.84444pt}\pgfsys@curveto{0.1pt}{10.39673pt}{0.54771pt}{10.84444pt}{1.1pt}{10.84444pt}\pgfsys@lineto{21.38892pt}{10.84444pt}\pgfsys@curveto{21.94121pt}{10.84444pt}{22.38892pt}{10.39673pt}{22.38892pt}{9.84444pt}\pgfsys@lineto{22.38892pt}{1.1pt}\pgfsys@curveto{22.38892pt}{0.54771pt}{21.94121pt}{0.1pt}{21.38892pt}{0.1pt}\pgfsys@lineto{1.1pt}{0.1pt}\pgfsys@curveto{0.54771pt}{0.1pt}{0.1pt}{0.54771pt}{0.1pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{{}}{{}}{{}}{{}}{{}}{{}}{{}}\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{1.8pt}{3.44444pt}\pgfsys@invoke{
}\hbox{{\color[rgb]{0,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@gray@stroke{0}\pgfsys@color@gray@fill{0}\hbox{\set@color{\ignorespaces\vrule
height=6.0pt,depth=1.0pt,width=0.0pt{cage}}}}}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope{}{}{}\hss}\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\hss}}\lxSVG@closescope\endpgfpicture}}withtheincomingparameter\definecolor{tcbcolframe}{rgb}{0.6,0.6,0.6}\definecolor{tcbcolback}{rgb}{0.975,0.975,0.975}\definecolor{tcbcol@origin}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\leavevmode\hbox
to6.38pt{\vbox to10.68pt{\pgfpicture\makeatletter\hbox{\hskip 0.0pt\lower
0.0pt\hbox to0.0pt{\pgfsys@beginscope\pgfsys@invoke{
}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{
}\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{
}\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox
to0.0pt{{}{}{}{}\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.6,0.6,0.6}\pgfsys@color@gray@fill{0.6}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.0pt}{1.1pt}\pgfsys@lineto{0.0pt}{9.57858pt}\pgfsys@curveto{0.0pt}{10.1861pt}{0.4925pt}{10.67859pt}{1.1pt}{10.67859pt}\pgfsys@lineto{5.27779pt}{10.67859pt}\pgfsys@curveto{5.8853pt}{10.67859pt}{6.37779pt}{10.1861pt}{6.37779pt}{9.57858pt}\pgfsys@lineto{6.37779pt}{1.1pt}\pgfsys@curveto{6.37779pt}{0.4925pt}{5.8853pt}{0.0pt}{5.27779pt}{0.0pt}\pgfsys@lineto{1.1pt}{0.0pt}\pgfsys@curveto{0.4925pt}{0.0pt}{0.0pt}{0.4925pt}{0.0pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.975,0.975,0.975}\pgfsys@color@gray@fill{0.975}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.1pt}{1.1pt}\pgfsys@lineto{0.1pt}{9.57858pt}\pgfsys@curveto{0.1pt}{10.13087pt}{0.54771pt}{10.57858pt}{1.1pt}{10.57858pt}\pgfsys@lineto{5.27779pt}{10.57858pt}\pgfsys@curveto{5.83008pt}{10.57858pt}{6.27779pt}{10.13087pt}{6.27779pt}{9.57858pt}\pgfsys@lineto{6.27779pt}{1.1pt}\pgfsys@curveto{6.27779pt}{0.54771pt}{5.83008pt}{0.1pt}{5.27779pt}{0.1pt}\pgfsys@lineto{1.1pt}{0.1pt}\pgfsys@curveto{0.54771pt}{0.1pt}{0.1pt}{0.54771pt}{0.1pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{{}}{{}}{{}}{{}}{{}}{{}}{{}}\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{1.8pt}{2.5pt}\pgfsys@invoke{
}\hbox{{\color[rgb]{0,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@gray@stroke{0}\pgfsys@color@gray@fill{0}\hbox{\set@color{\ignorespaces\vrule
height=6.0pt,depth=1.0pt,width=0.0pt{i}}}}}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope{}{}{}\hss}\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\hss}}\lxSVG@closescope\endpgfpicture}}andthenmakesanewanonymousobjectwithtwoattributes\definecolor{tcbcolframe}{rgb}{0.6,0.6,0.6}\definecolor{tcbcolback}{rgb}{0.975,0.975,0.975}\definecolor{tcbcol@origin}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\leavevmode\hbox
to23.6pt{\vbox to11.89pt{\pgfpicture\makeatletter\hbox{\hskip 0.0pt\lower
0.0pt\hbox to0.0pt{\pgfsys@beginscope\pgfsys@invoke{
}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{
}\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{
}\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox
to0.0pt{{}{}{}{}\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.6,0.6,0.6}\pgfsys@color@gray@fill{0.6}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.0pt}{1.1pt}\pgfsys@lineto{0.0pt}{10.78888pt}\pgfsys@curveto{0.0pt}{11.3964pt}{0.4925pt}{11.88889pt}{1.1pt}{11.88889pt}\pgfsys@lineto{22.50006pt}{11.88889pt}\pgfsys@curveto{23.10757pt}{11.88889pt}{23.60007pt}{11.3964pt}{23.60007pt}{10.78888pt}\pgfsys@lineto{23.60007pt}{1.1pt}\pgfsys@curveto{23.60007pt}{0.4925pt}{23.10757pt}{0.0pt}{22.50006pt}{0.0pt}\pgfsys@lineto{1.1pt}{0.0pt}\pgfsys@curveto{0.4925pt}{0.0pt}{0.0pt}{0.4925pt}{0.0pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.975,0.975,0.975}\pgfsys@color@gray@fill{0.975}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.1pt}{1.1pt}\pgfsys@lineto{0.1pt}{10.78888pt}\pgfsys@curveto{0.1pt}{11.34117pt}{0.54771pt}{11.78888pt}{1.1pt}{11.78888pt}\pgfsys@lineto{22.50006pt}{11.78888pt}\pgfsys@curveto{23.05235pt}{11.78888pt}{23.50006pt}{11.34117pt}{23.50006pt}{10.78888pt}\pgfsys@lineto{23.50006pt}{1.1pt}\pgfsys@curveto{23.50006pt}{0.54771pt}{23.05235pt}{0.1pt}{22.50006pt}{0.1pt}\pgfsys@lineto{1.1pt}{0.1pt}\pgfsys@curveto{0.54771pt}{0.1pt}{0.1pt}{0.54771pt}{0.1pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{{}}{{}}{{}}{{}}{{}}{{}}{{}}\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{1.8pt}{3.44444pt}\pgfsys@invoke{
}\hbox{{\color[rgb]{0,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@gray@stroke{0}\pgfsys@color@gray@fill{0}\hbox{\set@color{\ignorespaces\vrule
height=6.0pt,depth=1.0pt,width=0.0pt{path}}}}}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope{}{}{}\hss}\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\hss}}\lxSVG@closescope\endpgfpicture}}and\definecolor{tcbcolframe}{rgb}{0.6,0.6,0.6}\definecolor{tcbcolback}{rgb}{0.975,0.975,0.975}\definecolor{tcbcol@origin}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\definecolor{.}{rgb}{0,0,0}\leavevmode\hbox
to26.1pt{\vbox to10pt{\pgfpicture\makeatletter\hbox{\hskip 0.0pt\lower
0.0pt\hbox to0.0pt{\pgfsys@beginscope\pgfsys@invoke{
}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{
}\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{
}\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox
to0.0pt{{}{}{}{}\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.6,0.6,0.6}\pgfsys@color@gray@fill{0.6}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.0pt}{1.1pt}\pgfsys@lineto{0.0pt}{8.9pt}\pgfsys@curveto{0.0pt}{9.5075pt}{0.4925pt}{10.0pt}{1.1pt}{10.0pt}\pgfsys@lineto{25.00005pt}{10.0pt}\pgfsys@curveto{25.60756pt}{10.0pt}{26.10005pt}{9.5075pt}{26.10005pt}{8.9pt}\pgfsys@lineto{26.10005pt}{1.1pt}\pgfsys@curveto{26.10005pt}{0.4925pt}{25.60756pt}{0.0pt}{25.00005pt}{0.0pt}\pgfsys@lineto{1.1pt}{0.0pt}\pgfsys@curveto{0.4925pt}{0.0pt}{0.0pt}{0.4925pt}{0.0pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}{}{}{}{}{}{}{}{}\definecolor[named]{pgffillcolor}{rgb}{0.975,0.975,0.975}\pgfsys@color@gray@fill{0.975}\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}{{}{}{{}}}{{}{}{{}}}{}{}\pgfsys@moveto{0.1pt}{1.1pt}\pgfsys@lineto{0.1pt}{8.9pt}\pgfsys@curveto{0.1pt}{9.45229pt}{0.54771pt}{9.9pt}{1.1pt}{9.9pt}\pgfsys@lineto{25.00005pt}{9.9pt}\pgfsys@curveto{25.55234pt}{9.9pt}{26.00005pt}{9.45229pt}{26.00005pt}{8.9pt}\pgfsys@lineto{26.00005pt}{1.1pt}\pgfsys@curveto{26.00005pt}{0.54771pt}{25.55234pt}{0.1pt}{25.00005pt}{0.1pt}\pgfsys@lineto{1.1pt}{0.1pt}\pgfsys@curveto{0.54771pt}{0.1pt}{0.1pt}{0.54771pt}{0.1pt}{1.1pt}\pgfsys@closepath\pgfsys@fill\pgfsys@invoke{
}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@fill@opacity{1.0}\pgfsys@invoke{
}{{{}}{{}}{{}}{{}}{{}}{{}}{{}}\pgfsys@beginscope\pgfsys@invoke{
}\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{1.8pt}{2.5pt}\pgfsys@invoke{
}\hbox{{\color[rgb]{0,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@gray@stroke{0}\pgfsys@color@gray@fill{0}\hbox{\set@color{\ignorespaces\vrule
height=6.0pt,depth=1.0pt,width=0.0pt{move}}}}}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope}\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope{}{}{}\hss}\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope
}\pgfsys@endscope\hss}}\lxSVG@closescope\endpgfpicture}}.Themakingan``instance^{\prime\prime}ofabookwouldlooklikethis:\par\ffcode
book.new42>bb.move7b.path\par$

###  1.5. Destructors

In C++ and some other languages, a destructor is a method that is called for a
class object when that object passes out of scope or is explicitly deleted.
The following code will print both Alive and Dead texts:

#include ¡iostream¿ class Foo public: Foo() std::cout ¡¡ ”Alive”; Foo()
std::cout ¡¡ ”Dead”; ; ; int main() Foo f = Foo();

It may be translated to EO as such:

+import org.eolang.io.stdout

[] ¿ Foo [] ¿ new seq ¿ @ stdout ”Alive” ¿ @ [] [] ¿ destructor stdout ”Dead”
¿ @ [] ¿ main seq ¿ @ Foo.new ¿ f f.destructor

There is no garbage collection in EO, that’s why a destructor must be
explicitly “called” when an object passes out of scope or is deleted.

###  1.6. Exceptions

Exception handling is the process of responding to the occurrence of
exceptions—anomalous or exceptional conditions requiring special
processing—during the execution of a program provided. This C++ program
utilizes exception handling to avoid segmentation fault due to null pointer
de-referencing:

#include ¡iostream¿ class Book public: int price(); ; int price(Book* b) if (b
== NULL) throw ”NPE!”; return (*b).price() * 1.1; void print(Book* b) try
std::cout ¡¡ ”The price: ” ¡¡ price(b); catch (char const* e) std::cout ¡¡
”Error: ” ¡¡ e;

This mechanism may be implemented in EO:

[] ¿ Book [] ¿ price /int [b throw] ¿ price if. ¿ @ b.eq 0 throw ”error!”
(Book b).price.mul 1.1 [b] ¿ print Q.org.eolang.gray.try ¿ @ [t] seq ¿ @
stdout ”The price: ” stdout (price b t).as-string [e] seq ¿ @ stdout ”Error: ”
stdout e TRUE

Here, the object try expects three arguments: 1) an abstract object to be
dataized, and 2) an abstract object to be copied with one argument, in case
dataization fails, and 3) an object to be dataized anyway (similar to Java
finaly block).

The object ff expects two arguments instead of one, as in C++ example. The
second argument is the object throw, which if copied and dataized, causes the
termination of dataization and a non-conditional jump to the “catch” object of
the try. The mechanism is similar to “checked” exceptions in Java, where a
method’s signature must declare all types of exceptions the method may throw.

####  1.6.1. Many Exception Types

A Java method may throw a number of either checked or unchecked exceptions,
for example:

void f(int x) throws IOException if (x == 0) throw new IOException(); throw
new RuntimeException();

This would be represented in EO as such:

[x io-throw rt-throw] ¿ f seq ¿ @ if. x.eq 0 io-throw TRUE rt-throw

To catch both exceptions the object f would be used like this:

try [rt-throw] try ¿ @ [io-throw] f 5 io-throw rt-throw ¿ @ [e1] stdout
e1.message ¿ @ TRUE [e2] stdout e2.message ¿ @ TRUE

###  1.7. Anonymous Functions

Anonymous functions that can be passed into methods as arguments. For example,
in this Ruby code a “block” (a name Ruby uses for anonymous functions) is
passed:

def scan(lines) lines.each do —t— if t.starts_with? ’#’ yield t end end
scan(array) —x— puts x

This mechanism may be implemented in EO:

+import org.eolang.io.stdout

[lines b] ¿ scan lines.each ¿ @ [t] if. ¿ @ t.starts ’#’ b t TRUE scan array
[x] stdout x ¿ @

Here, the anonymous function passed to the object scan as an argument b. The
“call” of this function is the dataization of its copy, performed by the if
atom.

###  1.8. Generators

A generator is a routine that can be used to control the iteration behaviour
of a loop. For example, this PHP program will print first ten Fibonacci
numbers:

function fibonacci(int
$limit):generator{yield$a=$b=$i=1;while(++$i<$limit){$b=$a+$b;yield$b-$a;$a=$b;}}foreach(fibonacci(10)as$n)
echo ”$n\n";$

This mechanism may be implemented in EO:

+import org.eolang.io.stdout +import org.eolang.txt.sprintf

[limit f] ¿ fibonacci memory ¿ a memory ¿ b memory ¿ i seq ¿ @ a.write 1
b.write 1 f 1 while. seq (i.write (i.add 1)) (i.less limit) [idx] seq ¿ @
b.write a.add b f (b.sub a) a.write b fibonacci 10 [n] stdout ¿ @ sprintf ”

Here, the generator is turned into an object fibonacci with an extra parameter
f, which is specified with an abstract object argument, which prints what’s
given as n.

###  1.9. Types and Type Casting

A type system is a logical system comprising a set of rules that assigns a
property called a type to the various constructs of a computer program, such
as variables, expressions, functions or modules. The main purpose of a type
system is to reduce possibilities for bugs in computer programs by defining
interfaces between different parts of a computer program, and then checking
that the parts have been connected in a consistent way. In this example, a
Java method add expects an argument of type Book and compilation would fail if
another type is provided:

class Cart private int total; void add(Book b) this.total += b.price();

The restrictions enforced by Java type system through types Cart and Book may
be represented in EO by means of decorators, for example:

[] ¿ original-cart memory ¿ total [b] ¿ add total.write (total.add b.price) []
¿ Cart original-cart ¿ @ [b] ¿ add if. b.&.subtype-of ”Book” @.add b [] msg ¿
”Type mismatch, Book expected”

Here, it is expected that the parameter b is defined in a “class,” which has
subtype-of attribute, which may also be provided by a decorator (a simplified
example):

[] ¿ original-book memory ¿ price [] ¿ Book original-book ¿ @ [t] ¿ subtype-of
t.eq ”Book” ¿ @ [] ¿ price @.price ¿ @

This decoration may be simplified through a “fluent” supplementary object:

+import org.eolang.gray.type

type ”Cart” ¿ cart-type .super-types ”Object” ”Printable” .method ”add” ”Book”
cart-type original-cart ¿ cart

Here, the type object implements all necessary restrictions Java type system
may provide for the type Cart and its methods.

Type casting, which is a mechanism of changing an expression from one data
type to another, may also be implemented through same decorators.

###  1.10. Reflection

Reflection is the ability of a process to examine, introspect, and modify its
own structure and behavior. In the following Python example the method hello
of an instance of class Foo is not called directly on the object, but is first
retrieved through reflection functions globals and getattr, and then executed:

def Foo(): def hello(self, name): print(”Hello, obj = globals()[”Foo”]()
getattr(obj, ”hello”)(”Jeff”)

It may be implemented in EO just by encapsulating additional meta information
in classes explained in Sec. 1.4.

####  1.10.1. Monkey Patching

Monkey patching is making changes to a module or a class while the program is
running. This JavaScript program adds a new method print to the object b after
the object has already been instantiated:

function Book(t) this.title = t; var b = new Book(”Object Thinking”); b.print
= function() console.log(this.title); b.print();

This program may be translated to EO, assuming that b is being held by an
attribute of a larger object, for example app:

[] ¿ app Q.org.eolang.gray.cage ¿ b b’ ¿ copy seq ¿ @ b.write [] ¿ Book [t] ¿
new memory ¿ title seq ¿ @ title.write t [] copy.¡ b.write [] ¿ Book [t] ¿ new
seq ¿ @ [] copy ¿ @ [] ¿ print stdout (^.title) b.print

Here, the modification to the object Book is happening through making a copy
of it, creating a decorator, and then storing it to where the original object
was located.

###  1.11. Static Methods

A static method (or static function) is a method defined as a member of an
object but is accessible directly from an API object’s constructor, rather
than from an object instance created via the constructor. For example, this C#
class consists of a single static method:

class Utils public static int max(int a, int b) if (a ¿ b) return a; return b;

It may be converted to the following EO code, since a static method is nothing
else but a “global” function:

[a b] ¿ Utils-max if. ¿ @ a.greater b a b

###  1.12. Inheritance

Inheritance is the mechanism of basing a class upon another class retaining
similar implementation. In this Java code class Book inherits all methods and
non-private attributes from class Item:

class Item private int p; int price() return p; class Book extends Item int
tax() return price() * 0.1;

It may be represented in EO like this:

[] ¿ item memory ¿ p [] ¿ price p ¿ @ [] ¿ book item ¿ i [] ¿ tax i.price.mul
0.1 ¿@

Here, composition is used instead of inheritance.

####  1.12.1. Prototype-Based Inheritance

Prototype-based programming uses generalized objects, which can then be cloned
and extended. For example, this JavaScript program defines two objects, where
Item is the parent object and Book is the child that inherits the parent
through its prototype:

function Item(p) this.price = p; function Book(p) Item.call(this, p); this.tax
= function () return this.price * 0.1; var t = new Book(42).tax();
console.log(t); // prints ”4.2”

This mechanism of prototype-based inheritance may be translated to the
following EO code, using the mechanism of decoration:

[] ¿ Item [p] ¿ new memory ¿ price seq ¿ @ price.write p [] [] ¿ Book [p] ¿
new [] Item p ¿ @ [] ¿ tax mul. ¿ @ ^.price 0.1 stdout as-string. tax.
Book.new 42

####  1.12.2. Multiple Inheritance

Multiple inheritance is a feature of some object-oriented computer programming
languages in which an object or class can inherit features from more than one
parent object or parent class. In this C++ example, the class Jack has both
bark and listen methods, inherited from Dog and Friend respectively:

#include ¡iostream¿ class Dog virtual void bark() std::cout ¡¡ ”Bark!”; ;
class Friend virtual void listen(); ; class Jack: Dog, Friend void listen()
override Dog::bark(); std::cout ¡¡ ”Listen!”; ;

It may be represented in EO like this:

+import org.eolang.io.stdout

[] ¿ dog [] ¿ bark stdout ”Bark!” ¿ @ [] ¿ jack dog ¿ d friend ¿ f [] ¿ listen
seq ¿ @ d.bark stdout ”listen!”

Here, inherited methods are explicitly listen as attributes in the object
jack. This is very close to what would happen in the virtual table of a class
Jack in C++. The EO object jack just makes it explicit.

###  1.13. Method Overloading

Method overloading is the ability to create multiple functions of the same
name with different implementations. Calls to an overloaded function will run
a specific implementation of that function appropriate to the context of the
call, allowing one function call to perform different tasks depending on
context. In this Kotlin program two functions are defined with the same name,
while only one of them is called with an integer argument:

fun foo(a: Int) fun foo(a: Double) foo(42)

It may be represented in EO like this:

[args…] ¿ foo (args.get 0) ¿ a0 if. a0.&.subtype-of ”Int” first-foo a0 second-
foo a0 foo 42

This code expects arguments of foo to be equipped with the type system
suggested in Sec. 1.9. The attribute subtype-of will help dispatching the call
to the right objects.

###  1.14. Java Generics

Generics extend Java’s type system to allow a type or method to operate on
objects of various types while providing compile-time type safety. For
example, this Java class expects another class to be specified as T before
usage:

class Cart¡T extends Item¿ private int total; void add(T i) total +=
i.price();

It may be represented in EO like this:

[] ¿ cart memory ¿ total [i] ¿ add total.write ¿ @ total.add i.price

As the example demonstrates, the presence of generics in class declaration may
be ignored, since EO is a language without types and type checking.

###  1.15. C++ Templates

Templates are a feature of the C++ programming language that allows functions
and classes to operate with generic types, allowing a function or class to
work on many different data types without being rewritten for each one.

template¡typename T¿ T max(T a, T b) return a ¿ b ? a : b; int x = max(7, 42);

It may be represented in EO like this:

[a b] ¿ max if. ¿ @ a.greater a b max 7 42 ¿ x

As the example demonstrates, the presence of templates may be ignored, since
EO is a language without types and type checking.

###  1.16. Mixins

A mixin is a class that contains methods for use by other classes without
having to be the parent class of those other classes. The following code
demonstrates how Ruby module is included into a class:

module Timing def recent? @time - Time.now ¡ 24 * 60 * 60 end end def News
include Timing def initialize(t) @time = t end end n = News.new(Time.now)
n.recent?

This code may be represented in EO by just copying the method recent? to the
object News as if it was defined there.

###  1.17. Annotations

In Java, an annotation is a form of syntactic metadata that can be added to
source code; classes, methods, variables, parameters and Java packages may be
annotated. Later, annotations may be retrieved through Reflection API. For
example, this program analyzes the annotation attached to the class of the
provided object and changes the behavior depending on one of its attributes:

interface Item @Ship(true) class Book /*..*/ @Ship(false) class Song /*..*/
class Cart void add(Item i) /* add the item to the cart */ if (i.getClass()
.getAnnotation(Ship.class) .value()) /* mark the cart as shippable */

The code may be represented in EO using classes suggested in Sec. 1.4:

[] ¿ Book Ship true ¿ a1 [] ¿ new [] ¿ @ [] ¿ Song Ship false ¿ a1 [] ¿ new []
¿ @ [] ¿ Cart [i] ¿ add seq ¿ @ ”// Add the item to the cart” if. i.&.a1.value
”// Mark the cart shippable” TRUE

Annotations become attributes of objects, which represent classes in EO, as
explained in Sec. 1.4: Book.a1 and Song.a1.

##  2\. Traceability

Certain amount of semantic information may be lost during the translation from
a more powerful programming language to EO objects, such as, for example,
namings, line numbers, comments, etc. Moreover, it may be useful to have an
ability to trace EO objects back to original language constructs, which they
were motivated by. For example, a simple C function:

int f(int x) return 42 / x;

It may be mapped to the following EO object:

[x] ¿ f [] ¿ @ ”src/main.c:1-1” ¿ source 42.div x ¿ @ ”src/main.c:0-2” ¿
source

Here, synthetic source attribute represents the location in the source code
file with the original C code. It’s important to make sure during translation
that the name source doesn’t conflict with a possibly similar name in the
object.

##  3\. Conclusion

We demonstrated how some language features often present in high-level object-
oriented languages, such as Java or C++, may be expressed using objects. We
used EO as a destination programming language because of its minimalistic
semantics: it doesn’t have any language features aside from objects and their
composition and decoration mechanisms.

## References

  * (1)
  * Bugayenko (2021) Yegor Bugayenko. 2021\.  EOLANG and phi-calculus.  arXiv:2111.13384 [cs.PL]
  * Ceccato et al. (2008) Mariano Ceccato, Paolo Tonella, and Cristina Matteotti. 2008\.  Goto Elimination Strategies in the Migration of Legacy Code to Java. In _2008 12th European Conference on Software Maintenance and Reengineering_. IEEE, IEEE, USA, 53–62.
  * Erosa and Hendren (1994) Ana M Erosa and Laurie J Hendren. 1994.  Taming Control Flow: A structured approach to eliminating goto statements. In _Proceedings of 1994 IEEE International Conference on Computer Languages (ICCL’94)_. IEEE, IEEE, USA, 229–240.
  * Pan and Dromey (1996) Si Pan and R. Geoff Dromey. 1996.  A Formal Basis for Removing Goto Statements.  _Comput. J._ 39, 3 (1996), 203–214.
  * Williams and Chen (1985) M. Howard Williams and G Chen. 1985.  Restructuring Pascal Programs Containing Goto Statements.  _Comput. J._ 28, 2 (1985), 134–137.