So if R is an n-ary relation connecting n sets X1,X2,...,X[n], then we can model it as a set of simple objects with functions mapping R into X1, X2, ...X[n]:
As examples, consider part of a model of a college where a class has
a subject, units, time, room, etc.:
Net
The mappings can be quantified: If
Codd discovered and publicized procedures for constructing a set of simple n-ary relations which can support a set of given data. He also argues that instead of n-tples it is better to use labeled tuples and to talk about tables rather than relations. Finally he constructed an extension of the calculus of Binary Relations which is capable of handling many data retrieval problems.
In MATHS n-tples are generalized to labeled tples and powerful ways of documenting them are available,
[ math_12_Structure.html ]
[ notn_4_Re_Use_.html ]
[ notn_15_Naming_Documentn.html ]
[ notn_13_Docn_Syntax.html ]
Convenient Notations
The ".Table" format is a simple way to encode a relationship:
.Table X Y Z ...
.Row x y z ...
...
.Close.TableWhen rendered something like this:
| Real | Real | Real | |
|---|---|---|---|
| x | y | sqrt(x^2+y2) |
Relational Operators
Given a collection of sets of tuples, Codd's Relational operations are already
define in MATHS:
| Relational | MATHS |
|---|---|
| Projection | Relation.(Names_of_components) |
| Selection | Relation and Condition |
| Product | variables(Relation1) and variables(Relation2) |
| Join | Relation1 and Relation2 and Net{Connection } |
| Union | Relation1 or Relation2 |
| Intersection | Relation1 and Relation2 |
| Difference | Relation1 not Relation2 |
Entities and Relations
In this model it is not necessary (and it can be a waste of time) to distinguish a priori whether you have an entity or a relation. At the logical or conceptual level they are both sets of more or less complicated sets. Similarly it is wise to avoid early commitment as to any particular technique (relational, object, hierarchic, network). These decisions can be delayed until the problem itself is sorted out.
Diagram
When there are many disjoint sets and at most one map connects each set to another one set then a list of set names determines a unique operator sets of one set into sets of another set. Such a list is called a navigation path. To help determine valid paths, (where maps fit each other) a digraph can be shown with nodes for the sets and arcs for the maps. Such a digraph is called a conceptual model or Bachman diagram.
Quantification
An important validation step - and preparation for performance analysis - is to quantify how many of each set of tpls there are. Similarly for each of the maps connecting the sets of tpls, a number (or set of numbers) needs to be documented showing how many elements correspond to a single projected image on each component. The mathematical Pigeon-hole Principle can now be used to check whether the model makes sense:
Access Paths
A shorthand to combine many relations and sets together is essential for
documenting long paths through data bases. For example, given a class
we can find what room it is in, and from there what building and campus:
Using semicolons inside operations is confusing to the eye and other simple parsers.
Given a para-regular expression in a context that requires a relation (eg... after a period) with items that are names of sets like A,B and C above then (A B C) means A..B..C and #R means do(R). The other operators are treated literally ( "|" indicates union, "&" intersection. "~" complement,... ). For example (Faculty Section Student) might be a table showing which faculty teach student various sections.
Also note the following theorems:
So for example: Widgets..Prices;min;Prices..Widgets -- find least cost widgets.
. . . . . . . . . ( end of section Conceptual Models) <<Contents | End>>
Formal analysis delays these until a network of cooperating classes of objcts has been developed:
To specify certain transaction however it may be useful to be able to generalize the operators on binary relations above to work on n-ary relations. Adding new items is easy, suppose we have a structured type T and S is a subset of T and A a subset of T then S'=S|A or S:|A describes the addition of the elements in A to S. Deletion is more complex because it is often described as deleting all records with a particular property - but not giving the values of all variables. For example a typical command would be to delete the record of an object with identifier "123-45-678" what ever other values it has. Suppose we have a structured type T and a projection operation p into another type P (typically a single attribute/variable, or a list of them) then if S is a subset of T and D a subset of P then we can describe the removal of all elements in S that project into D as `{ s:S || s.p not in D } or S ~ /p(D)`. Hence, a specification might indicate that a system must be able to execute the following S:~/p(D).
An update operation is best specified in terms of S being updated by a set of changes U where each element in U is a pair (an old item, a new item). So U:@(T><T) The operation is to first delete items and then add the changed ones, or S' = { t:T || for some s:S ( (s,t) in U }, `S' = S.U, or S :.U.
Finally there are often preconditions on addition, deletion and update operations. So a typical collection of operation might be:
A simple example in the USA is if S is a set of records about people and the key is their Social Security number.
The objects in set S have an identifier and data parts:
Deletion is expressed typically in terms of a set of key values, because the other data is needed to identify what is being deleted,
For example: Delete({"123-45-6789"}).
Updates no longer need to describe the whole item being removed, and so give a set of key+value pairs:
For example Update("123-45-6789"+>("Dick Botting", ...).
Addition of new items must still provide complete information on both key+data and must not lead to more than one item having the same key value:
For example, Add({("123-45-6789", "Dick Botting", ...)}).
It is easy to show that the properties (unique1) and (unique2) above are preserved by these operations.
Exercise
Repeat the above analysis only replacing sets by (a) bags/multisets, (b) fuzzy sets.
Note that these changes can be derived from a simpler model of how the entities themselves change.
. . . . . . . . . ( end of section Z-like Operators) <<Contents | End>>
. . . . . . . . . ( end of section N-ary Relations and n-tples.) <<Contents | End>>
Notes on MATHS Notation
Special characters are defined in
[ intro_characters.html ]
that also outlines the syntax of expressions and a document.
Proofs follow a natural deduction style that start with assumptions ("Let") and continue to a consequence ("Close Let") and then discard the assumptions and deduce a conclusion. Look here [ Block Structure in logic_25_Proofs ] for more on the structure and rules.
The notation also allows you to create a new network of variables and constraints. A "Net" has a number of variables (including none) and a number of properties (including none) that connect variables. You can give them a name and then reuse them. The schema, formal system, or an elementary piece of documentation starts with "Net" and finishes "End of Net". For more, see [ notn_13_Docn_Syntax.html ] for these ways of defining and reusing pieces of logic and algebra in your documents. A quick example: a circle = Net{radius:Positive Real, center:Point}.
For a complete listing of pages in this part of my site by topic see [ home.html ]
Notes on the Underlying Logic of MATHS
The notation used here is a formal language with syntax
and a semantics described using traditional formal logic
[ logic_0_Intro.html ]
plus sets, functions, relations, and other mathematical extensions.
For a more rigorous description of the standard notations see