I am trying to describe a simple algorithm using the language of mathematics. But I am a programmer and used to think in terms of objects (as in object-oriented analysis, object-oriented design and object-oriented programming).
Here are the classes I have:
A changeset represents a set of changes. Each change has an operation (either "ADD" or "REMOVE") and a statement (I think it does not matter here what a statement is).
There are also some objects:
Set s0; Set s1; Set s2; ChangeSet c1; ChangeSet c2;
c1
is derived from s0
and s1
by some function delta
:
c1 = delta(s0, s1)
And so is c2
:
c2 = delta(s0, s2)
Now let's try to represent this in the language of maths:
$ \mathbb C_1 = \{ c_{1,1}, c_{1,2}, \ldots \} = \delta(\mathbb S_0, \mathbb S_1) $ $ \mathbb C_2 = \{ c_{2,1}, c_{2,2}, \ldots \} = \delta(\mathbb S_0, \mathbb S_2) $ $ c_{i,j} = (p_{i,j}, s_{i,j}) $ $ \delta(\mathbb S_0, \mathbb S_i) = \{ ("-", s_{i,j}) \vert s_{i,j} \in \Bbb{S_0 \setminus S_i} \} \cup \{ ("+", s_{i,j}) \vert s_{i,j} \in \Bbb{S_i \setminus S_0} \} $
where $p_{i,j}$ is an operation and $s_{i,j}$ is a statement.
It looks pretty compact but there are two things that bother me:
- I had to replace an object with a pair of variables $(p_{i,j}, s_{i,j})$ because I was unsure how to address "fields" of objects in the language of maths. Now since they are not objects, they loose its "type", they are just "pairs".
- I had to replace sets with arrays with indices. So now I have to think about $\Bbb C_1$ and $\Bbb C_2$ as of a big matrix of values rather than two sets of objects. But this is only a part of problem. I have to use indices everywhere and, for example, when I want iterate over $\Bbb{S^- = S_1 \setminus S_2}$, while keeping having in memory the big matrix, I reluctantly write $s_j \in \Bbb S^-$.
Is there anything I miss? Am I complicating things? Is there a way to operate true objects in the language of maths? So that I can write something like $ \Bbb S^+ = \{ c.statement | c \in \Bbb C ( c.operation = "+" ) \} $ instead of $ \Bbb S^+ = \{ s_i | c_i \in \Bbb C ( p_i = "+" ) \}. $