Associative modelling 2
Symbolic expressions to epicycles
Last updated
Symbolic expressions to epicycles
Last updated
Composing mathematical expressions using basic arithmetic components gets out of hand pretty quickly. The reason is because addition for instance is a trivial operation yet when expressed as a component it requires significant amount visual real estate. As a result, performing basic arithmetic does not seem to scale very well in the sense of visual complexity escalation. Moreover, it is difficult to parse simple mathematical expressions by trying to detect and follow the flow of components and wires.
Using symbolic expressions for basic math logic is the preferred modelling approach. In this visual programming environment we can use a range of symbolic expression systems. Those are found in the “maths” palette and include spreadsheet-like syntax as well as established programming languages such as C#, Visual Basic and Python.
We will use the “expression” and “python script” components extensively in this part of the term. Since basic mathematical expressions are pretty much exactly the same across the programming world, it will not be too confusing. Let’s simplify the above graph using “expression” components.
After placing an “expression” component in the graph we typically edit its input and output parameters. You will notice that when we zoom-in close enough to its input parameter list, we are able to add or remove parameters by clicking the buttons that appear. Components that support this functionality are known as variable parameter components. Notice also that unfortunately we cannot change the output parameter number; the “expression” component always outputs one.
To edit the component’s expression we need to double-click over it, causing a pop-up window, the expressions designer, to appear. The syntax used in this visual editor is not unlike spreadsheet formulas. We proceed with expressing the circle’s points using two expressions, one for each coordinate, and remove the clutter caused by the basic arithmetic and trigonometry components. The process of reorganizing and often simplifying logic is also known as refactoring.
For demonstrating the scenario of using multiple input parameters in an “expression” component we may also compact the normalisation logic. The “expression” requires the “index” values created by the “series” component and the number of range items “count” i.e. the value of the “slider” component.
Simple expressions are so prevalent that there is yet another way to achieve the same result without even using the “expressions” component. Component’s input allow us to directly encode an expression transforming the values accepted via wires before being processed by the component.
We may apply the normalization logic directly via the “series” component by entering the formula “1 / ( x – 1 )” in its “step” input parameter. This is achieved via the context menu above the parameter’s label. The notation is using a variable named “x” instead of the parameter’s name “step”; a peculiarity we just have to live with. Observe how the “points of unit circle” has been compacted in a much more legible way below.
Practice
Familiarize yourself with other mathematical components in the “maths” palette. Recreate some of the previously created range transformations modeled using the spreadsheet for practice.
You may apply an input parameter expression directly into the the “x” and “y” coordinates of the “construct point” component. Note however that sometimes too much compaction is equally confusing as using numerous components.