## Getting more from Mathematica

Previous chapters described what is considered a core FMT modeling language. The core language is relatively simple in the sense that the set of supported concepts is just the minimum that is necessary to support basic programming patterns and design structures. In fact, engineers that are fluent in any of the popular programming languages can find the FMT core to be somewhat constraining.

This was actually intentional - the core language is supposed to be feasible to analyze and verify and also straightforward to translate into any of the target programming languages. As such it is analogous to a very rigorous coding standard and engineers working with critical systems might find the core language to be just what is needed. But FMT has a lot more to offer for those who already know Mathematica as a computing platform or who are willing to invest some effort into learning Wolfram as a programming language, as the core functionality of FMT can be greatly extended with a bit of Wolfram scripting.

There are three different mechanisms in which Wolfram programming can be used to expand the basic modeling options in FMT:

• Custom preprocessors - these are functions that can be automatically invoked at early stages of model processing and which can perform user-defined model transformations. This is how new syntax elements can be added to the modeling language.
• Metaprogramming - this concept refers to the programmatic invocation of basic model-building functions, possibly with algorithmic modification of some model parameters. For example, if there is a need to create a large number of variables (perhaps representing external signals of an embedded system), then instead of laborious and error-prone duplication of code the needed variables can be created by means of a program. If some of the model values, like type range constraints, need to be parameterized, then instead of hard-coding them in the model they can be provided as valued symbols. Such techniques allow also to achieve the effects of generic or template programming.
• Model synthesis - which shares some of the properties of both preprocessing and metaprogramming and allows to inject code fragments that are symbolically computed at the time of model construction.

It is important to note, however, that each of these techniques, even though very helpful in a number of modeling problems, can raise the complexity of the model and therefore make it more difficult to validate. The liberty and scope of use of such methods should be evaluated and planned up-front and mature engineering teams might want to include such resolutions in their modeling standards.

The following chapters present each of these mechanisms and provide examples of varying levels of difficulty. Even though the explanation of all Wolfram constructs is beyond the scope of this documentation, the examples are kept readable to be followed by those engineers who are willing to explore the details on their own.

Previous: Model persistency, next: Grammar preprocessors