git @ Cat's Eye Technologies
Import of Cabra version 1.0 revision 2011.1214 (just HTML fixes.) Cat's Eye Technologies 11 years ago
1 changed file(s) with 35 addition(s) and 30 deletion(s).
 0 0 1 1 2 2 3 3 4 4 5 The Cabra Programming Language 6 7 8 9 5 10 6 11 7 12 27 32 relation is introduced there in order to make sense of how program texts (syntax) can be manipulated in 28 33 tandem with the programs (semantics) they represent. In short, many different program texts are equivalent to 29 34 the same (abstract) program, so the equality operator = used in the group axioms is simply replaced 30 by the equivalence operator, ≡. Obviously, this technique isn't restricted to groups, and the idea can be 35 by the equivalence operator, ≡. Obviously, this technique isn't restricted to groups, and the idea can be 31 36 extended to that of any algebra over an equivalence relation, and it is this notion that 32 37 is applied in Cabra to dioids.

33 38 161 166 problems any easier.

162 167 163 168

Another reason is that Cabra, despite almost being, say, just a kind of algebraical structure, looks a lot 164 like the beginnings of a programming language. It's got a conditional form, and imperative update. It almost looks like an overspecified language — 165 heck, a machine — because of the definition of how parallel composition works in terms of cycles and everything.

169 like the beginnings of a programming language. It's got a conditional form, and imperative update. It almost looks like an overspecified language — 170 heck, a machine — because of the definition of how parallel composition works in terms of cycles and everything.

166 171 167 172

A third reason is that it's just a little... askew. Note that if we had a WHILE instruction, 168 173 we wouldn't need a BOTTOM instruction 176 181 177 182

Dioid Theory

178 183 179

Now, recall — or go look up in an abstract algebra textbook — or just take my word for it — that 180 an idempotent semiring is a triple ⟨S, +, *⟩ where:

184

Now, recall — or go look up in an abstract algebra textbook — or just take my word for it — that 185 an idempotent semiring is a triple 〈S, +, *〉 where:

181 186 182 187
183 188
• S is a set of elements;
• 184
• + : S × SS is a binary operation on S; and
• 185
• * : S × SS is another binary operation on S,
• 189
• + : S × SS is a binary operation on S; and
• 190
• * : S × SS is another binary operation on S,
• 186 191
187 192

where the following axioms of dioid theory (over an equivalence relation!) hold:

188 193 189 194
190
• (a + b) + ca + (b + c) (addition is associative)
• 191
• a + bb + a (addition is commutative)
• 192
• a + 0 ≡ 0 + aa (existence of additive identity)
• 193
• a + aa (addition is idempotent)
• 194
• (a * b) * ca * (b * c) (multiplication is associative)
• 195
• a * 1 ≡ 1 * aa (existence of multiplicative identity)
• 196
• a * (b + c) ≡ (a * b) + (a * c) (multiplication left-distributes over addition)
• 197
• (a + b) * c ≡ (a * c) + (b * c) (multiplication right-distributes over addition)
• 198
• a * 0 ≡ 0 * a ≡ 0 (additive identity is multiplicative annihiliator)
• 195
• (a + b) + ca + (b + c) (addition is associative)
• 196
• a + bb + a (addition is commutative)
• 197
• a + 0 ≡ 0 + aa (existence of additive identity)
• 198
• a + aa (addition is idempotent)
• 199
• (a * b) * ca * (b * c) (multiplication is associative)
• 200
• a * 1 ≡ 1 * aa (existence of multiplicative identity)
• 201
• a * (b + c) ≡ (a * b) + (a * c) (multiplication left-distributes over addition)
• 202
• (a + b) * c ≡ (a * c) + (b * c) (multiplication right-distributes over addition)
• 203
• a * 0 ≡ 0 * a ≡ 0 (additive identity is multiplicative annihiliator)
• 199 204
200 205 201 206

Now I'll attempt to show that Cabra programs form an idempotent semiring, over the equivalence relation of "semantically identical", under the 212 217 this is completely independent of the order in which they are considered to have been organized into a parallel arrangement.

213 218 214 219

Parallel composition is commutative. When running programs in parallel, one would naturally expect that the order of the programs 215 doesn't matter — in fact, the concept doesn't really make sense. In a+b, a and b aren't 220 doesn't matter — in fact, the concept doesn't really make sense. In a+b, a and b aren't 216 221 really running in any order; they're running at the same time. The result of a+b 217 222 is determined by which of a or b terminates first, and this is not affected by which order they appear on either 218 223 side of the + operator. (In fact, that was why I introduced the "lexical order" tie-breaker, 220 225 221 226

There is a neutral element for parallel composition. Indeed, BOTTOM is this neutral element. 222 227 Any program a that terminates will by definition terminate before BOTTOM, 223 therefore a+BOTTOMBOTTOM+aa.

228 therefore a+BOTTOMBOTTOM+aa.

224 229 225 230

Parallel composition is idempotent. Intuitively, executing two copies of the same program in parallel will have the same result as 226 231 executing only one copy would. Since they both have the same input set and they both 253 258 Now suppose we sequentially compose c onto each of these subprograms: 254 259 a*c will take x + z cycles, and 255 260 b*c will take y + z cycles. 256 Because addition is monotonic — if x > y then x + z > y + z — whichever branch was the "winner" of a+b, 261 Because addition is monotonic — if x > y then x + z > y + z — whichever branch was the "winner" of a+b, 257 262 the same branch will be the winner of (a*c)+(b*c). 258 263 Also, in this branch, the input set to c will still be T, the output set of the winning branch of a+b. 259 264 Thus the final result will be the same. (See below for much more on this.)

276 281 277 282

For Cabra programs to form a full-fledged ring, every program would need to have a unique additive inverse. 278 283 That is, for every program a, there would need to be another program b, 279 where a+bBOTTOM. 284 where a+bBOTTOM. 280 285 But there can be no such program, as Cabra has been defined: if a terminates, then there's nothing b can do to 281 286 stop a from terminating.

282 287 283 288

So Cabra programs do not form a ring. Further, it's unclear what would have to change to allow this. 284 289 A simple instruction HANGOTHERS could be defined as sort of throwing a monkey wrench into every other 285 currently executing program: a+HANGOTHERSHANGOTHERS+aBOTTOM. 290 currently executing program: a+HANGOTHERSHANGOTHERS+aBOTTOM. 286 291 But every element is supposed to have a unique additive inverse, and this doesn't do that, because HANGOTHERS 287 292 causes every other program to hang.

288 293 340 345 341 346

Also, both of these approaches would, naturally, require both of the parallel programs to terminate before 342 347 their results could be merged to form the combined result (whether it be union or intersection.) This means that if either of them was BOTTOM, 343 the result would be BOTTOM — which in turn suggests that BOTTOM 348 the result would be BOTTOM — which in turn suggests that BOTTOM 344 349 would be an annihilator for addition as well as for multiplication, and that (at least in the union case) SKIP 345 350 also serves as a neutral element for both multiplication and addition. 346 351 This is less than swell, in terms of conforming to ring axioms, because one theorem of ring theory is that 347 352 the multiplicative identity and the additive identity are equal iff the ring consists of only one element, 348 353 which is clearly not the case here.

349 354 350

(I think, also, that if you do manage to have a "ring" where 1 ≡ 0, but where there are clearly elements that aren't 355

(I think, also, that if you do manage to have a "ring" where 1 ≡ 0, but where there are clearly elements that aren't 351 356 either 0 or 1, it's that the additive operation and multiplicative operation are really the same operation 352 357 under the semantic equivalence relation. One of my very early designs for Cabra came up against this, and it's 353 358 somewhat intuitive once you think about 354 359 it: if two programs which don't depend on each other at all have some given result 355 360 when one is executed after the other, they'll have the same result when 356 they are executed concurrently — because they don't depend on each other at all! Thus 361 they are executed concurrently — because they don't depend on each other at all! Thus 357 362 in this case + = * 358 363 and we're really talking about something that's a monoid or group or something, not a ring.)

359 364 365 370 366 371

Other Algebras

367 372 368

There are ways to address the problems of Cabra — or otherwise try to make it more interesting — 373

There are ways to address the problems of Cabra — or otherwise try to make it more interesting — 369 374 by formulating other algebras using other sets of axioms.

370 375 371 376

Take, for example, Kleene algebras. 372 A Kleene algebra is a dioid with an additional unary postfix operator *: SS. 377 A Kleene algebra is a dioid with an additional unary postfix operator *: SS. 373 378 It denotes a kind of additive closure: for any element a, 374 a* ≡ 0 + a + (a * a) + (a * a * a) 379 a* ≡ 0 + a + (a * a) + (a * a * a) 375 380 + (a * a * a * a) + ... Kleene algebras are used for such things 376 381 as the theory of regular expressions, where the Kleene star indicates "zero or more occurrences."

377 382 378 383

If we try to extend Cabra from a dioid to a Kleene algebra by adding a Kleene star, we appear to get a nonplussing 379 384 result. Since a always takes fewer cycles than a*a 380 (except when a is SKIP, and in that case a*aa,) 385 (except when a is SKIP, and in that case a*aa,) 381 386 and since any a takes fewer cycles than BOTTOM, it appears that 382 a*a in Cabra.

387 a*a in Cabra.

383 388 384 389

What does that get us? I'm not sure. I suspect nothing, unless there is some neat property of the 385 390 ordering induced by the Kleene algebra that shows up. But it doesn't seem worth checking, to me.

402 407 403 408

History

404 409 405

I came up with the idea to make a language whose programs formed a ring shortly after getting Burro basically done — 410

I came up with the idea to make a language whose programs formed a ring shortly after getting Burro basically done — 406 411 fall or winter of 2005. I didn't develop the idea until around the spring of 2007, when it occurred to me that parallel and sequential execution 407 412 could work for the operators. Developing the language itself (and compromising on a dioid) occurred in late summer and fall of 2007.

408 413