In my previous post about propagators, we looked at how to define simple one- and two-way relations and we looked at generic operators, which were used extending the definition of conflicts to include sets. In this post, we will examine how to define mathemtical relations between cells containing not only simple values, but also sets. We will use these relations to build a version of the celcius to fahrenheit relation that works not only between cells containing numbers, but also between cells containing sets.

All the code here uses version 0.2.0 of the propaganda library. The code in it’s full form is available at github.

We want generic versions of addition, subtraction, multiplication and
division that will accept two numbers, a set and a number, and two
sets. To do this, we write a function `generic-set-operator`

that takes
an operator and returns a generic operator based on the given operator.

We can lift the operators to propagator constructors.

Finally, we can create the two-way relations for sums and products.

In the previous post, we did not have sum and product relations, so we had to write two function for defining the two-way relation. This time around, we can use these new propagator constructors to define our relation.

The constants we need to define are stored under three new cells
allocated for the purpose. `gensym`

is used to come up with unique
identifiers for those cells.

The `c-f-relation`

function works both ways, so our examples from the
previous post will still give us the results we want.

Using the `extend-merge`

function from the previous post, we can have
our relations working on sets, as `c-f-relation`

only uses generic
operators that work on both sets and numbers.

As conflicts only occur when the there is an empty intersection between sets, we can have several restrictions on the same cell to refine the value of the temperature in celcius

And, as data flows both ways, the temperature in fahrenheit will automatically have been restricted.

In this second tutorial we have explored how to define mathemtical relations that not only operate on numbers, but also across compound data structures, in this case sets. We have redefined our temperature relation to use generic two-way operators which has two consequences: we do not need to define the bijective relation explicitly, and the relation will work on both numbers and sets.

I hope you’ve enjoyed reading through the tutorial. If you’re interested in other applications of propagators, I can recommend the article The Art of the Propagator.

comments powered by Disqus