User loginNavigation |
Programming with alternativesI've come up with a new concept, called 'alternative programs', where expressions can have multiple alternatives. I wonder if there are any papers out there that discuss a similar concept. I'm having trouble defining the concept, but here is a try: Every expression takes the form of a sequence of alternative expressions, syntactically enclosed within curly brackets and separated by commas (in the case of a single alternative, curly brackets are omitted). The combination of two alternative expressions results in the cartesian product combination of their alternatives. Example alternative expressions:
1 + 2 => 3
{1,2} + 3 => {1+3,2+3} => {4,5}
1 {+,*} 2 => {1+2,1*2} => {3,2}
{1,2} + {9,7} => {1+9,1+7,2+9,2+7} => {10,8,11,9}
I've taken the bold step to generalise the above into the following: Consecutive alternatives in a sequence that are equal are compressed into singletons, then prefixed with a colon, together with the multiplicity of the consecutive equal alternatives. A compressed representation of a sequence is called the canonical representation of a sequence. Next to that, multiplicities are of type rational and can be negative (where negative multiplicities are prefixed with an underscore). Luckily, the cartesian product of alternatives can be naturally defined over negative and rational multiplicities. Example canonical representations:
{1,1,1/4:2,2,_1/2:2,1,_3,_3,_3,3,1} =>
{2:1,3/4:2,1,_2:3,1}
{1/2:1,1/4:2} + {4:3,_2:4} =>
{2:(1+3),_(1+4),2+3,_1/2:(2+4)} =>
{2:4,_5,5,_1/2:6} =>
{2:4,_1/2:6}
By Robbert van Dalen at 2013-01-03 22:21 | LtU Forum | previous forum topic | next forum topic | other blogs | 1726 reads
|
Browse archivesActive forum topics |
Recent comments
1 hour 10 min ago
2 hours 29 min ago
3 hours 16 min ago
4 hours 3 min ago
4 hours 5 min ago
10 hours 14 min ago
13 hours 54 min ago
14 hours 7 min ago
15 hours 18 min ago
21 hours 4 min ago