Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing code algebraically

I have a number of small algorithms that I would like to write up in a paper. They are relatively short, and concise. However, instead of writing them in pseudo-code (à la Cormen or even Knuth), I would like to write an algebraic representation of them (more linear and better LaTeX rendering) . However, I cannot find resources as to the best notation for this, if there is anything: e.g. how do I represent a loop? If? The addition of a tuple to a list?

Has any of you encountered this problem, and somehow solved it?

Thanks.

EDIT: Thanks, people. I think I did a poor job at phrasing the question. Here goes again, hoping I make it clearer: what is the common notation for talking about loops and if-then clauses in a mathematical notation? For instance, I can use $acc \leftarrow acc \cup \langle i,i+1 \rangle$ to represent the "add" method of a list.

like image 681
Dervin Thunk Avatar asked Jan 28 '10 19:01

Dervin Thunk


People also ask

What is code algebra?

Algebraic coding theory is the branch of coding theory in which the codes used to represent and encode information are characterized by or satisfy algebraic relationships. These relationships give algebraic codes useful properties and allow them to be analyzed using the powerful machinery of abstract algebra.

What is a symbolic expression in math?

Symbolic expressions. The symbolic language consists of symbolic expressions written in the way mathematicians traditionally write them. A symbolic expression consists of symbols arranged according to specific rules. Every symbolic expression is one of two types: symbolic assertion and symbolic term.

How do you write an expression?

To write an expression, we often have to interpret a written phrase. For example, the phrase “6 added to some number” can be written as the expression x + 6, where the variable x represents the unknown number.


2 Answers

Don't do this. You are deviating from what people expect to see when they read a paper about algorithms. You should follow expected practices; your ideas are more likely to get the attention that they deserve. When in Rome, do as the Romans do.

Formatting code (or pseudocode as it may be) in a LaTeXed paper is very easy. See, for example, Formatting code in LaTeX.

like image 132
jason Avatar answered Nov 18 '22 06:11

jason


I see if-expressions in mathematical notation fairly often. The usual thing for a loop is a recurrence relation, or equivalently, a function defined recursively.

Here's how the Ackermann function is defined on Wikipedia, for instance:

A(m, n) = n+1 if m=0; A(m-1, 1) if m>0 and n=0; and A(m-1, A(m, n-1)) if m>0 and n>0.

This picture is nice because it feels mathematical in flavor and yet you could clearly type it in almost exactly as written and have an implementation. It is not always possible to achieve that.

Other mathematical notations that correspond to loops include ∑-notation for summation and set-builder notation.

I hope this answers your question! But if your aim is to describe how something is done and have someone understand, I think it is probably a mistake to assume that mathematicians would prefer to see equations. I don't think they're interchangeable tools (despite Turing equivalence). If your algorithm involves mutable data structures, procedural code is probably going to be better than equations for explaining it.

like image 41
Jason Orendorff Avatar answered Nov 18 '22 06:11

Jason Orendorff