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
    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?2012-10-26
  • 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
    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) = "+" ) \}$?2012-10-26
  • 0
    Sure, you may do all of that. I don't quite see what the $C$ is for.2012-10-26
  • 0
    $C$ is now a function which makes a change "object" of its arguments.2012-10-26
  • 0
    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](http://manuales.gfc.edu.co/rur-ple/html/en/inter/30-dot.htm). Is not there a notation in maths that lets address a value of a pair by its name?2012-10-26
  • 0
    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.2012-10-26
  • 0
    I agree, but editors often look suspiciosly at such names :).2012-10-26
  • 0
    Well, sure, you didn't say this was for a math publication!2012-10-26
  • 0
    There is still some difference: functions are global, there is no formal way to bound them to a certain class or namespace, and fields are local to a class.2012-10-26
  • 0
    I'll tell you what's worrying my about indices: they imply some order. But my sets are unordered.2012-10-26