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<Statement> s0;
Set<Statement> s1;
Set<Statement> 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 = "+" ) \}. $$

  • $\begingroup$ I've given a first try at an answer. If it's missing some stuff you need, could you give some details about what the purpose of this translation is? $\endgroup$ Oct 26 '12 at 4:01
  • $\begingroup$ 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"? $\endgroup$
    – NoChance
    Oct 26 '12 at 4:08

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)\}$.

  • $\begingroup$ You mean replace $(p_{i,j}, s_{i,j})$ with $C(O(c_{i,j}), S(c_{i,j}))$? Seems better, but now I don't need indices to match between $c_{i,j}$, $s_{i,j}$, and $p_{i,j}$. May I just omit them? May I write $\{ C("-", s) \vert s \in \Bbb{S_0 \setminus S_i} \}$ and $\{ S(c) | c \in \Bbb C ( O(c) = "+" ) \}$? $\endgroup$
    – utapyngo
    Oct 26 '12 at 4:30
  • $\begingroup$ Sure, you may do all of that. I don't quite see what the $C$ is for. $\endgroup$ Oct 26 '12 at 4:32
  • $\begingroup$ $C$ is now a function which makes a change "object" of its arguments. $\endgroup$
    – utapyngo
    Oct 26 '12 at 4:36
  • $\begingroup$ What frustrates me is the number of made-up symbols. In OOP I don't need all those functions: $O$, $S$, and $C$. I can just address the fields using the dot notation. Is not there a notation in maths that lets address a value of a pair by its name? $\endgroup$
    – utapyngo
    Oct 26 '12 at 4:45
  • $\begingroup$ Sure, you can name the functions Statement and Operation instead of $S$ and $C$, which is exactly what you do when you name the fields with those words instead of with $S$ and $O$ in your programming. The mathematical habit of using one-letter names probably has a lot to do with our subject's roots long before computerization. $\endgroup$ Oct 26 '12 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.