2
$\begingroup$

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:

class diagram

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:

  1. 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".
  2. 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 = "+" ) \}. $

  • 0
    Fields of objects can be objects. Consider a date field as an example. A Date could be considered an objects. Also, why not use the "Relational Model" and replace "Relation" with "Object"?2012-10-26

1 Answers 1

1

I don't see that there's fundamentally any difference between the set formalism and the object formalism. If I want to define a data type Obj with fields Statement and Operation, that's equivalent to defining functions $S, O$ such that if $s$ is an Obj, $S(s)=s.$Statement and $O(s)=s.$Operation. One convenient way to represent $s$ is then as the ordered pair $(s.$Statement$,s.$Operation$)$, as you've already done.

As to the problem that the ordered pair representing $s$ doesn't have a type, just define another function $T$ that takes objects to their type in some set of permitted types.

I don't really understand what's worrying you about indices, so let me know if there's something I'm not addressing. But as far as the set notation goes, arrays with indices are easy to realize as plain sets: $\{a_{ij}\}$ can be set up as a set of ordered triples $\{(a,i,j)\}$.

  • 0
    I'll tell you what's worrying my about indices: they imply some order. But my sets are unordered.2012-10-26