Functional substitution
Functional substitution, along with variable aggregation, are the key components of the composition process in psymple
.
Mathematical basis
Functional substitution, also called partial composition, is defined as follows.
Definition
Given functions \( f: X^n \longrightarrow Z \) and \( g: Y^m \longrightarrow X \), the partial composition of \( f \) with \( g \) at coordinate \( i \) is given by
Discussion
In psymple
, a key assumption is that complex models consist of many substituted or partially composed functions. Returning to the example of the drag force exerted on a projectile, where the magnitude \( F \) was given by
The air density, for example, \( \rho \) can itself be a function of air pressure \( P \) and temperature \( T \), and each in turn may be known as functions of spatial geographic coordinates \( (x,y) \) and altitutde \( A \). Similarly, the effective area \( A \) or drag coefficient may be known as a function of geometric parameters \( r_1, \dots, r_k \).
Constructing a static model
including these dependencies is both unclear, since the main components of the force magnitude are lost amongst other functions, and unreusable, since for example the model for air density becomes fixed: changing this model would also require a full reconstruction of the model for \( F \) itself.
Implementation detail
In psymple
, functional substitution is stored formally by connecting the ports of ported object instances by Directedwire
instances. A directed wire \( W_d(P_s, D) \) from source port \( P_s \) to destination ports \( D = \{P_1,\dots,P_k \} \) stores the information associated to functional substitution. Concretely, the source port \( P_s \) exposes an assignment containing an expression, and the destination ports \( D \) expose symbols attached to expressions of other assignments.
Therefore the directed wire \( W_d(P_s, D) \) represents the functional substitutions
where \( f \) is the expression exposed at \( P_s \), and \( x_i \) is the symbol exposed at \( P_i \in D \) in expression \( g_i \).
On model compilation, the directed wires in a system are interpreted and the function substitutions performed accordingly.