ChatGPT (GPT-6.2), December 2026
One of the oldest algorithms in mathematics presents computer science with a surprisingly modern problem.
Euclid's algorithm finds the greatest common divisor of two positive integers. In one version, you repeatedly subtract the smaller number from the larger until the two are equal. In another, familiar to generations of computer science students, you repeatedly divide and take the remainder.
Given the numbers 1,000,000 and 1, the first version requires 999,999 subtractions. The second requires a single remainder operation.
Are these the same algorithm?
Mathematicians generally regard both as versions of Euclid's algorithm. A computer scientist analysing their performance, however, has good reason to distinguish them. And the distinction becomes considerably less clear if the remainder operation is itself implemented by repeated subtraction.
This is not merely a terminological curiosity. It exposes a foundational question which computer science, despite its extraordinary theoretical sophistication, has yet to settle: what kind of mathematical object is an algorithm?
Between the program and the function
Computer scientists routinely distinguish three things: the program, the algorithm it implements and the function it computes.
Two programmers might implement mergesort in Lisp and Python respectively. Their programs are quite different syntactic objects, but we recognise them as implementations of the same algorithm. Meanwhile, mergesort and insertion sort are different algorithms which compute the same function: the transformation of an input sequence into its sorted counterpart.
We appear to have three distinct mathematical territories:
Programs → Algorithms → Functions
Each arrow represents a loss of information. In passing from a program to an algorithm, we discard accidental features of its expression. In passing from an algorithm to a function, we discard information about how the result is obtained.
We understand the two ends of this spectrum extremely well. Formal languages give us a mathematics of programs. Denotational semantics gives us a mathematics of their meaning. The middle territory is much less well charted.
We can state the problem quite precisely. Suppose E(p) denotes the partial function computed by a program p. We seek an equivalence relation under which two programs are equivalent whenever they express the same algorithm.
Algorithmic equivalence must imply extensional equivalence — equality of the functions computed — but not the other way round. It must also identify at least some syntactically distinct programs.
There are, of course, infinitely many possible equivalence relations satisfying these requirements. Which one captures what we mean by an algorithm?
The limitations of the lambda calculus
At first sight, the lambda calculus might seem to provide an answer. Its elegant mathematical machinery allows us to strip away many of the peculiarities of particular programming languages.
But consider the following familiar example of β-reduction:
(λx. pair(x,x))(f(a))
→ pair(f(a),f(a)).
Under ordinary call-by-value evaluation, the expression on the left evaluates f(a) once and uses the result twice. The expression on the right evaluates f(a) twice, unless the implementation performs an optimisation.
For a pure, terminating computation, the results are identical. The expressions are equivalent in the lambda calculus. But if f represents an expensive computation, the difference between them is of considerable algorithmic significance.
The equational theory has discarded information about the sharing of computational work. Depending on what we mean by algorithmic identity, it may have discarded too much.
Nor is undecidability the fundamental obstacle here. The impossibility of mechanically determining whether two arbitrary programs compute the same function does not undermine the mathematical legitimacy of functions. Similarly, an equivalence relation capturing algorithmic identity need not be decidable to be mathematically meaningful.
The difficulty is knowing which equivalence relation we want.
Giving algorithms a mathematical existence
One of the most ambitious attempts to solve this problem comes from the mathematical logician Yiannis Moschovakis.
In his 2001 paper What Is an Algorithm?, Moschovakis argues that algorithms should be understood through recursive definitions rather than identified with the abstract machines which execute them.
Consider a collection of mutually recursive definitions. Each defines some mathematical object, perhaps a function, in terms of the others. Taken together, the definitions constitute a system of recursive equations.
Domain theory provides an elegant way of understanding such systems. Beginning with the least informative approximation to their solution, we repeatedly apply the mappings specified by the equations. Under appropriate conditions, the successive approximations converge, in the domain-theoretic sense, to a least fixed point.
Ordinary denotational semantics is principally interested in that fixed point. Moschovakis is interested in the mathematical structure which determines it.
He calls such a structure a recursor. Two recursors represent the same algorithm if they are isomorphic: their components can be put into correspondence in a way which preserves the structure of the recursive equations.
We can illustrate this with Euclid's algorithm. Instead of regarding its recursive definition as defining a function, think of it as defining an operator T which transforms one partial function h into another:
T(h)(a,b) = a if b = 0,
and h(b, a mod b) otherwise.
Starting with the everywhere-undefined function, successive applications of T progressively construct the greatest common divisor function. The first application handles the base case; the second handles inputs requiring one remainder operation; the third handles those requiring two, and so on. The least fixed point is the complete gcd function.
But we could construct a different operator, S, based upon Euclid's repeated-subtraction procedure. It would generate a different sequence of approximations, ultimately arriving at exactly the same fixed point.
In ordinary denotational semantics we retain the fixed point and discard the operator which generated it. In Moschovakis's intensional semantics we retain the mathematical structure of the recursive system itself, together with its output mapping. This is the recursor.
We now have two distinct mathematical objects which compute exactly the same function. Their distinction is entirely semantic: no particular programming language or machine enters into the picture.
Crucially, two recursive systems might determine exactly the same function without possessing this structural equivalence. We therefore have a mathematical object which captures considerably more than the function computed, without being tied to the syntax of a programming language.
Moschovakis has also explored an intriguing application of this idea to the philosophy of language. The philosopher Gottlob Frege distinguished the reference of an expression from its sense. The two expressions 'the morning star' and 'the evening star' both refer to Venus, but they present the same object in different ways.
The reference is the object itself. The sense is the mode of presentation of that object — the particular way in which it is identified or understood.
This explains why the statement 'The morning star is the evening star' conveys astronomical knowledge, whereas 'The morning star is the morning star' is a trivial identity. The former establishes that two different senses determine the same reference.
In Moschovakis's approach, an abstract algorithm for determining a denotation provides a mathematical model of this distinction.
But does the theory of recursors finally settle the identity conditions for algorithms?
A problem of perspective
In 2009, Andreas Blass, Nachum Dershowitz and Yuri Gurevich published a paper entitled When Are Two Algorithms the Same? Their argument was rather unsettling: perhaps no single equivalence relation adequately captures our intuitive concept of algorithmic identity.
The difficulty is illustrated by the two versions of Euclid's algorithm with which we began.
If we regard remainder and subtraction as primitive operations, the algorithms are operationally quite different. If we concentrate instead on the mathematical principle underlying the computation — the preservation of the greatest common divisor while reducing the arguments — they look much more alike.
Which features belong to the algorithm itself, and which belong to its implementation?
The difficulty is familiar elsewhere in mathematics. A sphere and an ellipsoid are different as metric spaces but equivalent as topological spaces. There is no contradiction. Topology and metric geometry are interested in different structural properties of the same underlying objects.
Perhaps computer science should take a similar approach to algorithms.
A mathematics of computational perspectives
Suppose that instead of seeking a single mathematical definition of an algorithm, we construct a family of semantic interpretations, each retaining a particular aspect of computational structure.
One might retain recursive structure, as Moschovakis proposes. Another might retain the order in which computations occur. A third might retain their dependency relationships, distinguishing computations which must be performed sequentially from those which can be performed in parallel.
Let I(p) denote the mathematical object assigned to a program p by such an interpretation. Two programs express the same algorithm, relative to that interpretation, precisely when
I(p) = I(q).
We require that the ordinary extensional meaning of a program can always be recovered from its richer interpretation.
Some interpretations will preserve more computational detail than others. If all the information supplied by interpretation I2 can be recovered from interpretation I1, we say that I1 refines I2.
But not all interpretations need be comparable. An interpretation which preserves information about memory usage need not preserve information about the order of arithmetic operations, or vice versa.
Instead of a single semantic territory between programs and functions, we discover a whole landscape of possible computational abstractions.
Mathematically, these interpretations induce a partially ordered family of equivalence relations. At one extreme lies syntactic identity; at the other, extensional equivalence. Between them lie the various notions of algorithmic identity.
What does this look like in practice?
Consider a simple programming language in which we instrument certain primitive operations. Whenever the program performs an addition, we record the letter A. Whenever it performs a multiplication, we record M.
Instead of returning just a numerical result, a terminating program now returns a result together with a sequence of letters recording its computation.
Two programs might both return 42, but one might produce the trace AAM and the other AMA.
These programs are extensionally indistinguishable on this input, but their computational traces differ.
Now suppose we discard the order of the letters and simply count the operations. Both traces contain two additions and one multiplication. Under this coarser interpretation the computational distinction disappears.
We could go further and assign a cost to each operation. The semantics would then retain only the result and the total computational cost. Finally, by discarding all information about the computation, we recover ordinary extensional semantics.
What makes this example mathematically interesting is that these abstractions respect the way computations are combined.
If one computation produces the trace AAM and a subsequent computation produces MA, their combined trace is AAMMA. Operation counts can similarly be added, as can computational costs.
The underlying mathematical structure is a monoid: a set equipped with an associative composition operation and an identity element. Sequences of letters form a monoid under concatenation; operation counts and costs form monoids under addition. The mappings between these representations preserve composition.
This simple construction gives us several distinct, mathematically related intensional semantics for computation.
We have not invented new algorithms. We have constructed different mathematical spaces in which to study their identities.
Putting the pieces together
There is an important constraint on any satisfactory account of algorithmic identity. Computer programs are constructed by combining smaller computational components. If two components are equivalent, we would like to be able to substitute one for the other without destroying that equivalence.
In the terminology of algebra, we want our equivalence relation to be a congruence.
There is a standard construction from programming language semantics which can help us here. Rather than asking whether two program fragments are indistinguishable in isolation, we ask whether they remain indistinguishable when placed inside every compatible program context.
What constitutes indistinguishability depends on our chosen observations. We might observe the returned value, computational cost, or the sequence of certain operations. Two fragments are contextually equivalent if no program context can distinguish them according to these criteria.
The construction guarantees that equivalence is preserved under substitution. In fact, it gives us the coarsest congruence which respects the specified observations.
We therefore have a systematic mathematical procedure for turning a proposed collection of computational observations into a compositional notion of algorithmic identity.
And we have a substantive research problem. Which observations capture genuinely important computational structure, rather than accidental properties of a particular programming language or machine?
Algorithms without programming languages
Ultimately, a mathematics of algorithms should transcend the languages in which we express them.
Consider a compiler translating programs from one language into another. Ordinary compiler correctness requires that the translated program has the same extensional meaning as the original.
But a compiler can introduce sharing, reorganise computations or even replace one algorithm with another. It can preserve the function while changing the algorithm.
With an intensional semantics in place, we can formulate a stronger requirement: the translation must preserve not just the function computed but the relevant computational structure.
Which translations preserve which intensional semantics? Can we construct semantic domains sufficiently abstract to accommodate radically different programming paradigms, yet sufficiently rich to distinguish genuinely different algorithms?
These questions suggest a research programme extending well beyond the original problem of defining algorithms.
A plurality of mathematical objects
Moschovakis demonstrated that algorithms can be treated as abstract mathematical structures without reducing them to the functions they compute. Other researchers, notably Noson Yanofsky in his Towards a Definition of an Algorithm, have explored related approaches involving equivalence classes of programs and their algebraic structure.
Perhaps the mistake has been to assume that the intermediate semantic territory must possess a single, universally privileged notion of identity.
Algorithmic identity might instead resemble identity in geometry: mathematically objective, but relative to the structure under consideration.
This is not an argument for subjectivity. Once we have specified an intensional semantics, whether two programs are equivalent under it is a mathematical question. What remains open is which semantic abstractions are sufficiently natural and illuminating to deserve our attention.
The Church–Turing thesis gave computer science a remarkably unified understanding of what can be computed. A comparable understanding of the structure of computation itself might turn out to require not one mathematical theory, but a systematic family of related theories.
Algorithms inhabit the semantic world. We are still discovering its geography.
Further reading
Yiannis N. Moschovakis (2001), What Is an Algorithm?
Andreas Blass, Nachum Dershowitz and Yuri Gurevich (2009), When Are Two Algorithms the Same?
Noson S. Yanofsky (2011), Towards a Definition of an Algorithm.










