User:Swampware/SRF programming language

SRF (Sets, Relations, and Functions) is a data manipulation language based on set notation.

Sets
A set is defined as zero or more elements within curly braces: {1,2,3}.

Tuples
A tuple is an ordered list of values. A tuple is defined as zero or more ordered elements within parentheses: (1,2,3). Tuples cannot be altered once they are created. You cannot add, remove, or alter items on a tuple. A tuple can contain elements of different data types. Tuples by themselves aren't very useful, but we can use them with sets to create data structures of arbitrary complexity.

Relations
A relation is a set of tuples: {(1,"a"),(2,"b"),(3,"c")}. Relations are similar to database tables, and we can perform relational algebra on them.

Functions
A function is a relation where each tuple has 2 elements (binary relation) and the first element of each tuple must be unique to the function. Functions are similar to dictionaries in that they map an keys to values. Functions are also similar to conventional functions, in that they can be invoked by passing a set of parameters and return a value. Functions provide a conceptual bridge between data and code.

Set operations
We can perform several operations on sets, and by definition relations and functions.

Union
Union allows us to take all of the elements in one set and combine them with the elements of another set to produce a third set.

Intersection
Intersections takes two sets and returns a new set containing only the element in common.

Difference
The difference of two sets is all of the items in the first set that are not also in the second set.

Cartesian Product
The cartesian product of 2 sets is a binary relation consisting of every combination of the 2 sets.

Relational Algebra
Now that we have defined relations we can apply operations to relations in the form of relational algebra.

Division
Division or subset partition is the process of chopping a relation into set of relations.

Aggregation
Aggregation allows us to summarize the results of our operations on a relation.