<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mathematics and Computation &#187; Computation</title>
	<atom:link href="http://math.andrej.com/category/computation/feed/?category_name=computation" rel="self" type="application/rss+xml" />
	<link>http://math.andrej.com</link>
	<description>Mathematics for computers</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:47:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2-beta2-18055</generator>
		<item>
		<title>A puzzle about typing</title>
		<link>http://math.andrej.com/2012/01/20/a-puzzle-about-typing/</link>
		<comments>http://math.andrej.com/2012/01/20/a-puzzle-about-typing/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 13:42:44 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Computation]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=1109</guid>
		<description><![CDATA[<p>While making a comment on Stackoverflow I noticed something: suppose we have a term in the $\lambda$-calculus in which no abstracted variable is used more than once. For example, $\lambda a b c . (a b) (\lambda d. d c)$ is such a term, but $\lambda f . f (\lambda x . x x)$ is not because [...]]]></description>
			<content:encoded><![CDATA[<p>While making a comment on <a href="http://cstheory.stackexchange.com/questions/9690/functions-that-typed-lambda-calculus-cannot-compute">Stackoverflow</a> I noticed something: suppose we have a term in the $\lambda$-calculus in which no abstracted variable is used more than once. For example, $\lambda a b c . (a b) (\lambda d. d c)$ is such a term, but $\lambda f . f (\lambda x . x x)$ is not because $x$ is used twice. If I am not mistaken, all such terms can be typed. For example:</p>
<pre class="brush: plain; gutter: false; title: ;">
# fun a b c -&gt; (a b) (fun d -&gt; d c) ;;
- : ('a -&gt; (('b -&gt; 'c) -&gt; 'c) -&gt; 'd) -&gt; 'a -&gt; 'b -&gt; 'd = &lt;fun&gt;

# fun a b c d e e' f g h i j k l m n o o' o'' o''' p q r r' s t u u' v w x y z -&gt;
    q u i c k b r o w n f o' x j u' m p s o'' v e r' t h e' l a z y d o''' g;;
  - : 'a -&gt; 'b -&gt; 'c -&gt; 'd -&gt; 'e -&gt; 'f -&gt; 'g -&gt; 'h -&gt; 'i -&gt; 'j -&gt;
    'k -&gt; 'l -&gt; 'm -&gt; 'n -&gt; 'o -&gt; 'p -&gt; 'q -&gt; 'r -&gt; 's -&gt; 't -&gt;
    ('u -&gt; 'j -&gt; 'c -&gt; 'l -&gt; 'b -&gt; 'v -&gt; 'p -&gt; 'w -&gt; 'o -&gt; 'g -&gt;
     'q -&gt; 'x -&gt; 'k -&gt; 'y -&gt; 'n -&gt; 't -&gt; 'z -&gt; 'r -&gt; 'a1 -&gt; 'e -&gt;
     'b1 -&gt; 'c1 -&gt; 'i -&gt; 'f -&gt; 'm -&gt; 'a -&gt; 'd1 -&gt; 'e1 -&gt; 'd -&gt; 's
     -&gt; 'h -&gt; 'f1) -&gt; 'v -&gt; 'b1 -&gt; 'z -&gt; 'c1 -&gt; 'u -&gt; 'y -&gt; 'a1
     -&gt; 'w -&gt; 'x -&gt; 'e1 -&gt; 'd1 -&gt; 'f1 = &lt;fun&gt;
</pre>
<p>What is the easiest way to see that this really is the case?</p>
<p>A related question is this (I am sure people have thought about it): how big can a type of a typeable $\lambda$-term be? For example, the Ackermann function can be typed as follows, although the type prevents it from doing the right thing in a typed setting:</p>
<pre class="brush: plain; gutter: false; title: ;">
# let one = fun f x -&gt; f x ;;
val one : ('a -&gt; 'b) -&gt; 'a -&gt; 'b =
# let suc = fun n f x -&gt; n f (f x) ;;
val suc : (('a -&gt; 'b) -&gt; 'b -&gt; 'c) -&gt; ('a -&gt; 'b) -&gt; 'a -&gt; 'c =
# let ack = fun m -&gt; m (fun f n -&gt; n f (f one)) suc ;;
val ack :
  ((((('a -&gt; 'b) -&gt; 'a -&gt; 'b) -&gt; 'c) -&gt;
   (((('a -&gt; 'b) -&gt; 'a -&gt; 'b) -&gt; 'c) -&gt; 'c -&gt; 'd) -&gt; 'd) -&gt;
   ((('e -&gt; 'f) -&gt; 'f -&gt; 'g) -&gt; ('e -&gt; 'f) -&gt; 'e -&gt; 'g) -&gt; 'h) -&gt; 'h = &lt;fun&gt;
</pre>
<p>That&#8217;s one mean type there! Can it be &#8220;explained&#8221;? Hmm, why <em>does</em> <code>ack</code> compute the Ackermann function in the untyped $\lambda$-calculus?</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2012/01/20/a-puzzle-about-typing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Definability and extensionality of the modulus of continuity functional</title>
		<link>http://math.andrej.com/2011/07/27/definability-and-extensionality-of-the-modulus-of-continuity-functional/</link>
		<comments>http://math.andrej.com/2011/07/27/definability-and-extensionality-of-the-modulus-of-continuity-functional/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 12:54:39 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Computation]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=983</guid>
		<description><![CDATA[<p>In an earlier post I talked about the modulus of continuity functional, where I stated that it cannot be defined without using some form of computational effects. It is a bit hard to find the proof of this fact so I am posting it on my blog in two parts, for Google and everyone else to [...]]]></description>
			<content:encoded><![CDATA[<p>In an <a href="/2006/03/27/sometimes-all-functions-are-continuous/">earlier post</a> I talked about the modulus of continuity functional, where I stated that it cannot be defined without using some form of computational effects. It is a bit hard to find the proof of this fact so I am posting it on my blog in two parts, for Google and everyone else to find more easily. In the first part I show that there is no extensional modulus of continuity. In the second part I will show that every functional that is defined in <a href="http://en.wikipedia.org/wiki/Programming_language_for_Computable_Functions">PCF</a> (simply-typed $\lambda$-calculus with natural numbers and recursion) is extensional. <span id="more-983"></span></p>
<p>The original reference for the first part is Troelstra and van Dalen, <em>Constructivism in mathematics, volume 2</em>, Sections 9.6.10 and 9.6.11, page 500. I transformed the proof to make the main idea a bit more transparent.</p>
<p>Define the <em>finite type hierarchy</em> $N_0, N_1, N_2, \ldots$ over the natural numbers $\mathtt{nat}$ by $$N_0 = \mathtt{nat}$$ and $$N_{k+1} = N_k \to \mathtt{nat}.$$ The elements of $N_k$ are known as the <em>type $k$ functionals</em>. Let us keep the exact meaning of $\mathtt{nat}$ and $\to$ a bit unspecified. We might interpret $\mathtt{nat}$ as the set of natural numbers, or as a domain, or as a datatype in a programming language. We require that $\mathbb{N} \subseteq N_0$, i.e., each number has a representation, but there might be extra elements in $\mathtt{nat}$, such as the undefined value $\perp$. The arrow $\to$ may represent the function type in a programming language, or an exponential in a cartesian-closed category. We will make things precise when we need to.</p>
<p>For each $k$ we define the <em>(hereditarily) total functionals</em> $T_k$ by $T_0 = \mathbb{N}$ and<br />
$$T_{k+1} = \lbrace f \in N_{k+1} \mid \forall x \in T_k . f x \in T_0 \rbrace.$$<br />
We call $T_0, T_1, T_2, \ldots$ the <em>total hierachy</em> derived from $N_0, N_1, N_2, \ldots$. When $N_k = T_k$ for all $k$, we say that the hierarchy $N_0, N_1, N_2, \ldots$ is <em>total</em>.</p>
<p>We also need the notion of <em>extensionality</em>. For each $k$ define the relation $\approx_k$ on $T_k$ by<br />
$$n \approx_0 m \iff n = m$$<br />
and<br />
$$f \approx_{k+1} g \iff \forall x, y \in T_k . x \approx_k y \Rightarrow f(x) = g(y).$$<br />
It can be shown easily that $\approx_k$ is symmetric and transitive, but it need not be reflexive. We say that $f \in N_k$ is <em>extensional</em> when $f \approx_k f$.</p>
<p>After this barrage of definitions some examples will hopefully make things a bit clearer. It is easy to come up with non-total functions, just write down something that cycles. A total function which is not extensional would be the following type 3 functional <code>u</code>, implemented in ocaml:</p>
<pre class="brush: plain; gutter: false; title: ;">
let u f =
  let k = ref 0 in
  let a n = (k := 1 ; 0) in
    ignore (f a) ;
    !k
</pre>
<p>The functional <code>u</code> returns 1 if its argument <code>f</code> evaluates its argument, and 0 otherwise. It is not extensional:</p>
<pre class="brush: plain; gutter: false; title: ;">
# u (fun a -&gt; 0) ;;
- : int = 0
# u (fun a -&gt; 0 * a 0) ;;
- : int = 1
</pre>
<p>As you can see, <code>u</code> uses local references. Exercise: write a total non-extensional functional using some other computational effect, such as exceptions or continuations.</p>
<p>To avoid writing down lots of ugly types, we preassign types to the following variables:</p>
<ul>
<li>$i, j, k, m, n$ stand for the elements of $N_0 = \mathtt{nat}$,</li>
<li>$\alpha, \beta, \gamma$ stand for functions, which are the elements of $N_1 = \mathtt{nat} \to \mathtt{nat}$</li>
<li>$F, G, H$ stand for type 2 functionals, which are the elements of $N_2 = (\mathtt{nat} \to \mathtt{nat}) \to \mathtt{nat}$,</li>
<li>$\Phi, \Psi, \Xi$ stand for type 3 functionals, which are the elements of $N_3 = ((\mathtt{nat} \to \mathtt{nat}) \to \mathtt{nat}) \to \mathtt{nat}$.</li>
</ul>
<p>We need one further piece of notation. Given a total function $\alpha$, let $\overline{\alpha}(k) = [\alpha(0), \alpha(1), \ldots, \alpha(k-1)]$ be the finite list of the first $k$ values of $\alpha$.</p>
<p>A total type 2 functional $F$ is <em>continuous at a total $\alpha$</em> if the value $F(\alpha)$ depends only on a finite prefix $\overline{\alpha}(k)$: $$\forall \beta \in T_1 . \overline{\beta}(k) = \overline{\alpha}(k) \Rightarrow F(\alpha) = F(\beta).$$<br />
You should convince yourself that this definition of continuity coincides with the usual one for metric spaces if we equip $\mathbf{N}$ with the usual metric $d(i,j) = |i &#8211; j|$ and $T_1$  with the <em>comparison metric</em> $$d(\alpha, \beta) = 2^{-\min \lbrace k \mid \alpha(k) \neq \beta(k) \rbrace}.$$ We would expect every computable total functional to be continuous because, intuitively speaking, in order for an algorithm to compute $F(\alpha)$ in finitely many steps it can only inspect finitely many values of $\alpha$. Of course, this assumes that an algorithm cannot do anything other than test $\alpha$ at various values. There are theorems in computability theory which say that, provided $F$ is extensional (see below), an algorithm cannot really do much else, even if it has the source code of $\alpha$ at its disposal. (Exercise: which theorems?)</p>
<p>To keep things simple we shall concentrate on continuity at the zero sequence $o = \lambda n . 0$. Thus a functional $F$ is continuous at $o$ if there exists $k$ such that $\forall \beta \in T_1. \overline{\beta}(k) = \overline{o}(k) \Rightarrow F(\beta) = F(o)$. We say that $k$ is a <em>modulus of continuity</em> for $F$ at $o$.</p>
<p>It is natural to ask whether we can compute a modulus of continuity $k$ from the total functional $F$, i.e., whether there is a <em>modulus of continuity functional </em>$\Phi$ of type 3 such that $$\forall F \in T_2. \forall \beta \in T_1. \overline{\beta}(\Phi(F)) = \overline{o}(\Phi(F)) \Rightarrow F(\beta) = F(o).$$ The existence of $\Phi$ implies that all type 2 functionals are continuous. So clearly we cannot expect to have one in a setting where discontinuous functional can be defined, such as the category of sets.</p>
<p>But how about defining $\Phi$ in a programming language? Well, you can do it in ocaml by using local references:</p>
<pre class="brush: plain; gutter: false; title: ;">
let phi f =
  let k = ref (-1) in
  let o i = (k := max !k i ; 0) in
    ignore (f o) ;
    !k + 1
</pre>
<p>We expect <code>phi</code> to compute a modulus of continuity if <code>f</code> is extensional, but I would really like to see a carefully written proof of this fact.</p>
<p>The modulus of continuity <code>phi</code> defined above is not extensional, since it returns different values for extensionally equal functionals:</p>
<pre class="brush: plain; gutter: false; title: ;">
# phi (fun alpha -&gt; 0) ;;
- : int = 0
# phi (fun alpha -&gt; 0 * alpha 41) ;;
- : int = 42
</pre>
<p>Can we have an extensional modulus of continuity? Suppose $\Psi$ were one. Let $n = \Psi (\lambda \alpha . 0)$ and consider the type 2 functional $H$ defined by<br />
$$H(\beta) = \Psi (\lambda \alpha . \beta(\alpha(n))).$$<br />
Because $\lambda \alpha . 0$ is extensionally equal to $\lambda \alpha . o(\alpha(n))$ we get by extensionality of $\Psi$ that<br />
$$H(o) = \Psi(\lambda \alpha . o (\alpha(n))) = \Psi (\lambda \alpha . 0) = n.$$<br />
On the other hand, if $\beta \neq o$ then the value $\beta(\alpha(n))$ cannot be determined by looking at $\alpha(0), \ldots, \alpha(n-1)$, therefore $H(\beta) = \Psi (\beta (\alpha (n))) &gt; n$. This means that $H$ is not continuous at $o$, which contradicts existence of $\Psi$. We have shown:</p>
<p style="padding-left: 30px;"><strong>Theorem:</strong> <em>There is no extensional modulus of continuity functional.</em></p>
<p>The consequence of this is that we cannot define the modulus of continuity functional in a programming language in which all total functionals are extensional. Next time we will see that PCF is such a language.</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/07/27/definability-and-extensionality-of-the-modulus-of-continuity-functional/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Running a classical proof with choice in Agda</title>
		<link>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/</link>
		<comments>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/#comments</comments>
		<pubDate>Tue, 10 May 2011 21:17:36 +0000</pubDate>
		<dc:creator>Martin Escardo</dc:creator>
				<category><![CDATA[Computation]]></category>
		<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=928</guid>
		<description><![CDATA[<p>As a preparation for my part of a joint tutorial Programs from proofs at MFPS 27 at the end of this month with Ulrich Berger, Monika Seisenberger, and Paulo Oliva, I&#8217;ve developed in Agda some things we&#8217;ve been doing together.</p>
<p>Using</p>

 Berardi-Bezem-Coquand functional, or alternatively,
Berger-Oliva modified bar recursion, or alternatively,
Escardo-Oliva countable product of selection functions,

<p>for giving a [...]]]></description>
			<content:encoded><![CDATA[<p>As a preparation for my part of a joint tutorial <em>Programs from proofs</em> at <a href="http://129.81.170.14/~mfps/MFPS27/MFPS_XXVII.html">MFPS 27</a> at the end of this month with <a href="http://www.cs.swan.ac.uk/~csulrich/">Ulrich Berger</a>, <a href="http://www.cs.swan.ac.uk/~csmona/">Monika Seisenberger</a>, and <a href="http://www.eecs.qmul.ac.uk/~pbo/">Paulo Oliva</a>, I&#8217;ve developed in <a href="http://wiki.portal.chalmers.se/agda/pmwiki.php">Agda</a> some things we&#8217;ve been doing together.</p>
<p>Using</p>
<ul>
<li> <a href="http://projecteuclid.org/DPubS?service=UI&amp;version=1.0&amp;verb=Display&amp;handle=euclid.jsl/1183745524">Berardi-Bezem-Coquand functional</a><a>, or alternatively,</a></li>
<li><a href="http://journals.cambridge.org/action/displayAbstract?fromPage=online&amp;aid=439279&amp;fulltextType=RA&amp;fileId=S0960129506005093">Berger-Oliva modified bar recursion</a>, or alternatively,</li>
<li><a href="http://journals.cambridge.org/action/displayAbstract?fromPage=online&amp;aid=7423096&amp;fulltextType=RA&amp;fileId=S0960129509990351">Escardo-Oliva countable product of selection functions</a>,</li>
</ul>
<p>for giving a proof term for classical countable choice, we prove the classical infinite pigeonhole principle in Agda: every infinite boolean sequence has a constant infinite subsequence, where the existential quantification is classical (double negated).</p>
<p>As a corollary, we get the finite pigeonhole principle, using Friedman&#8217;s trick to make the existential quantifiers intuitionistic.</p>
<p>This we can run, and it runs fast enough. The point is to illustrate in Agda how we can get witnesses from classical proofs that use countable choice. The finite pigeonhole principle has a simple constructive proof, of course, and hence this is really for illustration only.</p>
<p>The main Agda files are</p>
<ul>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/InfinitePigeon.html">InfinitePigeon</a></li>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/FinitePigeon.html">FinitePigeon</a></li>
<li><a href="http://www.cs.bham.ac.uk/~mhe/pigeon/html/Examples.html">Examples</a></li>
</ul>
<p>These are Agda files converted to html so that you can navigate them by clicking at words to go to their definitions.  A <a href="http://www.cs.bham.ac.uk/~mhe/pigeon/Pigeon.zip">zip file</a> with all Agda files is available. Not much more information is available <a href="http://www.cs.bham.ac.uk/~mhe/pigeon/">here</a>.</p>
<p>The three little modules that implement the Berardi-Bezem-Coquand, Berger-Oliva and Escardo-Oliva functionals disable the termination checker, but no other module does. The type of these functionals in Agda is the <a href="http://portal.acm.org/citation.cfm?id=1876437">J-shift principle</a>, which generalizes the double-negation shift.</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/05/10/running-a-classical-proof-with-choice-in-agda/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Canonical Effective Subalgebras of Classical Algebras as Constructive Metric Completions</title>
		<link>http://math.andrej.com/2011/01/24/canonical-effective-subalgebras-of-classical-algebras-as-constructive-metric-completions/</link>
		<comments>http://math.andrej.com/2011/01/24/canonical-effective-subalgebras-of-classical-algebras-as-constructive-metric-completions/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 07:22:36 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[Computation]]></category>
		<category><![CDATA[Constructive math]]></category>
		<category><![CDATA[Publications]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=431</guid>
		<description><![CDATA[<p>Jens Blanck and I presented a paper at Computability and Complexity in Analysis 2009 with a complicated title (I like complicated titles):</p>
<p>Canonical Effective Subalgebras of Classical Algebras as Constructive Metric Completions</p>
<p>which has been published in Volume 16, Issue 18 of the Journal of Universal Computer Science. I usually just post the abstract, but this time I would like [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cs.swan.ac.uk/~csjens/">Jens Blanck</a> and I presented a paper at <a href="http://cca-net.de/cca2009/">Computability and Complexity in Analysis 2009</a> with a complicated title (I like complicated titles):</p>
<blockquote><p><em><a href="http://www.jucs.org/jucs_16_18/canonical_effective_subalgebras_of">Canonical Effective Subalgebras of Classical Algebras as Constructive Metric Completions</a></em></p></blockquote>
<p>which has been published in <a href="http://www.jucs.org/jucs_16_18">Volume 16, Issue 18 of the Journal of Universal Computer Science</a>. I usually just post the abstract, but this time I would like to explain the general idea informally, the way one can do it on a blog. But first, here is the abstract:</p>
<p><strong>Abstract:</strong> We prove general theorems about unique existence of effective subalgebras of classical algebras. The theorems are consequences of standard facts about completions of metric spaces within the framework of constructive mathematics, suitably interpreted in realizability models. We work with general realizability models rather than with a particular model of computation. Consequently, all the results are applicable in various established schools of computability, such as type 1 and type 2 effectivity, domain representations, equilogical spaces, and others.</p>
<p><strong>Download paper:</strong> <a href="/wp-content/uploads/2010/01/effalg.pdf">effalg.pdf</a> or <a href="http://www.jucs.org/jucs_16_18/canonical_effective_subalgebras_of">directly from JUCS</a></p>
<p><span id="more-431"></span></p>
<h3>Computability via constructive mathematics</h3>
<p>I have been going around <a href="/2005/08/23/realizability-as-the-connection-between-computable-and-constructive-mathematics/">telling people</a> they should use constructive mathematics to study computability of structures in analysis and topology. This is supposed to work as follows:</p>
<ol>
<li>Develop the constructive theory of a mathematical gadget $X$.</li>
<li>Interpret the constructive theory via the realizability interpretation in a model of computation, such as Turing machines (see <a href="/2005/08/23/realizability-as-the-connection-between-computable-and-constructive-mathematics/">these notes</a>).</li>
<li>The interpretation gives the computable version of $X$.</li>
</ol>
<p>I still think this general approach to computable mathematics works really well. I have heard a number of talks in which the authors invented computable versions of their mathematical gadgets &#8220;by hand&#8221;, where all they had to do was to open <a href="http://books.google.com/books?as_isbn=0387150668">Bishop&#8217;s book</a> and calculate some realizability interpretations.</p>
<p>By the way, it does not really matter whether you use realizability to interpret the constructive theory, it might be something else, for example type theory (and here is <a href="/2010/01/07/tutorial-on-videolecturesnet/">a tutorial</a> that does precisely that to real numbers and more).</p>
<p>However, there are practical obstacles to the above plan. The biggest one is the fact that mathematicians do not find it easy to switch from classical to constructive thinking. That&#8217;s an understatement. In my experience deprogramming oneself from classical mathematics takes a considerable effort and at least some external guidance. It&#8217;s just hard to know whether a proof uses excluded middle or choice if you&#8217;re not trained to spot it. (But let me tell you it&#8217;s a liberating experience to peek outside Hilbert&#8217;s &#8220;Paradise&#8221;.)</p>
<p>A more serious practical obstacle is that the proposed program requires us to develop all of mathematics constructively. While this may be a worthy goal, often times I just do not have the time to, say, develop the constructive theory of overt compact groups when all I want is an implementation of the unit circle in the complex plane. And most of the time people have a pretty good idea how to equip their gadget $X$ with computable structure anyhow. They don&#8217;t need heavy machinery that reconstructs everything from scratch.</p>
<p>Jens and I proved a couple of theorems which generalize previous work of Malcev, <a href="http://www.math.ucla.edu/~ynm/">Yiannis Moschovakis</a>, <a href="http://www.unibw.de/inf1/personen/professoren/hertling/">Peter Hertling</a> and others, and allow us to skip the whole business of &#8220;do it constructively first&#8221;. I would like to spend a couple of kilobytes explaining how the theorems work.</p>
<h3>Assemblies</h3>
<p>Let us consider a set $A$ with distinguished elements and operations. Some examples might be:</p>
<ul>
<li>the set $\mathbb{N}$ of natural numbers with the constant $0$ and the operations $S$ (successor), $+$ and $\times$,</li>
<li>the set $\mathbb{R}$ of real numbers with constants $0$, $1$, and operations $+$, $-$, $\times$ and ${}^{-1}$,</li>
<li>the Hilbert space $L^2[0,1]$ with the usual vector-space operations and the inner product.</li>
</ul>
<p>We shall call such a set with operations an <em>algebra</em>, but keep in mind that the structure may have little to do with traditional algebra.</p>
<p>A general question in computable mathematics is how to equip with a computability structure a given algebra $A$, or at least a canonically chosen subalgebra. In many cases the answer seems obvious, but when you start thinking about all possible computable structures that $A$ could receive, it is not obvious which one is &#8220;the correct&#8221; one.</p>
<p>Before we can answer the question we have to make it technically precise. A natural way of equipping $A$ with a computable structure is to provide its implementation, say in Haskell. This amounts to giving a datatype <code>t</code> whose values represent the elements of the set $A$ together with a <em>realizability relation</em> which tells us which values $v$ of type <code>t</code> represent which elements $x \in A$. Let us write $v \vdash x$ for &#8220;the value $v$ of type <code>t</code> represents the element $x \in A$&#8221; (the symbol is supposed to be <code>\Vdash</code> in LaTeX but MathJax does not have it). We call $v$ a <em>realizer</em> of $x$. The triple $(A, \mathtt{t}, {\vdash})$ is called an <em>assembly</em>. We require that every $x \in A$ has at least one $v$ of type <code>t</code> which realizes it, $v \vdash x$.</p>
<p>We say that a map $f : A \to B$ between assemblies $(A, \mathtt{s}, {\vdash_A})$ and $(B, \mathtt{t}, {\vdash_B})$ is <em>implemented</em> or <em>realized</em> by a value $g$ of type <code>s -&gt; t</code> when we have for all $x \in A$ and $v$ of type <code>s</code>:</p>
<blockquote><p>if $v \;\vdash_A x$ then $g \, v \;\vdash_B  f(x)$.</p></blockquote>
<p>The notions of assemblies and realized maps are just explicit mathematical manifestation of how mathematicians-programmers think when they implement mathematical gadgets.</p>
<p>In the context of type 2 effectivity assemblies are viewed as <em>multi-valued representations</em>: the realizability relation $\vdash$ may be viewed equivalently as a map $\delta: A \to P(t)$ which assigns to each $x \in A$ the set of those values which implement it, $\delta(x) = \lbrace v : t \mid v \vdash x$. I am mentioning this because type 2 effectivity is a fairly popular model of computation among mathematicians who do this sort of thing. We are going to stick to Haskell.</p>
<h3>What is a nice assembly?</h3>
<p>We seek a &#8220;nice&#8221; assembly which implements our algebra $A$. One obvious criterion for &#8220;niceness&#8221; is that the operations of $A$ should be implementable. Let us look at a silly example to explain this point. Suppose we would like to implement the set of integers $\mathbb{Z}$ with the constants $0$, $1$, addition $+$ and subtraction $-$.  Probably everyone would agree that we should use Haskell&#8217;s type <code>Integer</code> as the representing datatype, where each integer is represented by the corresponding value. Both constants $0$ and $1$ as well as the operations $+$ and $-$ on type <code>Integer</code> are of course implemented in Haskell. But there are also other implementations that programmers would never consider, although mathematicians might. For example, we might represent $\mathbb{Z}$ with the Haskell type <code>Integer -&gt; </code><code>Integer</code> and declare that $f \vdash n$ when $f$ is a monotone sequence of integers whose limit is $n$. Thus the value</p>
<blockquote><p><code>\k -&gt; min 3 k</code></p></blockquote>
<p>which is the sequence $\ldots, -1, 0, 1, 2, 3, 3, 3, \ldots$ represents the number $3$. Now again $0$ and $1$ are realized (every integer $n$ is realized by the constant sequence <code>const n</code>), and addition is implemented as</p>
<blockquote><p><code>add f g = \k -&gt; f k + g k</code></p></blockquote>
<p>With subtraction we face a problem because it is <em>anti</em>monotone in the second argument. In fact, it is impossible to implement it (exercise: assume it is implemented and derive from it the Halting oracle).</p>
<p>Here is another unreasonable representation of $\mathbb{Z}$: we implement integers with the unit type <code>()</code> and represent every integer $n$ with the unit value <code>()</code>. This is very silly, of course. But notice that the operations $+$ and $-$, and in fact <em>all</em> maps, including the non-computable ones, are trivially implemented by the Haskell function which always returns <code>()</code>. So in a sense this representation is &#8220;better&#8221; because it allows implementation of more operations.</p>
<p>In order to eliminate the last example we need to require something more than just computability of constants and operations.</p>
<h3>The theorems</h3>
<p>This brings me to the two theorems Jens and I proved. The starting point were the following known results:</p>
<ul>
<li>If the algebra $A$ is finitely generated, then it has at most one computable structure such that equality is semidecidable. (Malcev 1961)</li>
<li>The recursive reals have a unique representation under which they form a recursive field which is recursively complete and the strict order $&lt;$ is semidecidable. (<a href="http://www.numdam.org/item?id=CM_1965-1966__17__40_0">Moschovakis 1965</a>)</li>
<li>There is a unique type 2 representation of the reals under which they form a computable field which is computably complete and the strict order $&lt;$ is computably open. (<a href="http://researchspace.auckland.ac.nz/handle/2292/3566">Hertling 1997</a>)</li>
</ul>
<p>The second and the third result give us a hint as to what else is needed in order to get a canonical computable structure, namely <em>computable completeness</em> and something involving semidecidability of $&lt;$.</p>
<p>Completeness is a metric property, so we focus on <em>metric algebras</em>, which are metric spaces equipped with constants and continuous operations. The real numbers are a metric algebra (I am ignoring the fact that inverse is a partial operation, the paper deals with partial operations, too), while the case of finitely generated algebras can be brought into the picture by equipping them with the discrete metric, which is complete.</p>
<p>What is the common generalization of having semidecidable equality on a discrete space and having semidecidable $&lt;$ in $\mathbb{R}$? It turns out to be the semidecidability of relation $d(x,y) &lt; q$, where $d$ is the metric, $x, y \in A$ and $q$ is rational. So our two main theorems are as follows, slightly paraphrased:</p>
<blockquote><p><strong>Theorem 11: </strong> Suppose $A$ is a metric algebra whose initial subalgebra is dense. Then there exists at most one computably complete computable subalgebra of $A$ for which the relation $d(x,y) &lt; q$ is semidecidable.</p>
<p><strong>Theorem 12:</strong> Suppose $A$ is a metric algebra such that its initial subalgebra has computably locally uniformly continuous operations and a semidecidable relation $d(x,y) &lt; q$. Then there is at least one computably complete computable subalgebra of $A$ for which the relation $d(x,y) &lt; q$ is semidecidable.</p></blockquote>
<p>The first theorem restricts reasonable computability substructures and the second one guarantees their existence. Notice how the first theorem does not contain <em>any</em> assumptions about computability. The conditions of the second theorem are a bit technical, however, they correspond precisely to what is usually needed in practice (see the paper for details).</p>
<p>The upshot of these two theorems is as follows. Suppose we have a classical algebra $A$ and we have a pretty good idea on how to implement it reasonably (by which we mean that the operations are computable and computably locally uniformly continuous, the limit operator is computable, and the metric is semidecidable). Then all we need to do is verify the conditions of the two theorems. If they are satisfied then there is precisely one reasonable implementation, up to computable isomorphism, hence it has to be the one we have in mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/01/24/canonical-effective-subalgebras-of-classical-algebras-as-constructive-metric-completions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alg</title>
		<link>http://math.andrej.com/2011/01/22/alg/</link>
		<comments>http://math.andrej.com/2011/01/22/alg/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 23:27:11 +0000</pubDate>
		<dc:creator>Andrej Bauer</dc:creator>
				<category><![CDATA[alg]]></category>
		<category><![CDATA[Computation]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://math.andrej.com/?p=839</guid>
		<description><![CDATA[<p>Alg is a program for enumeration of finite models of single-sorted first-order theories. These include groups, rings, fields, lattices, posets, graphs, and many more. Alg was written as a class project by Aleš Bizjak, a student of mine whose existence I cannot confirm with a URL. I joined the effort, added bells and whistles, as well [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Alg</strong> is a program for enumeration of finite models of single-sorted first-order theories. These include groups, rings, fields, lattices, posets, graphs, and <a href="http://hg.andrej.com/alg/file/tip/theories">many more</a>. Alg was written as a class project by Aleš Bizjak, a student of mine whose existence I cannot confirm with a URL. I joined the effort, added bells and whistles, as well as an alternative algorithm that works well for relational structures. Alg is ready for public consumption, although it should be considered of &#8220;beta&#8221; quality. Instructions for downloading alg are included at the end of this post.</p>
<p><span id="more-839"></span></p>
<p>Suppose we want to know how many rings of size $n$ there are. If $n$ happens to be the square of a prime we are lucky because a theorem says there are exactly 11 of them. Otherwise we can look up the numbers on the on <a href="http://oeis.org/A027623">The On-Line Encyclopedia of Integer Sequences</a> (OEIS). But what if we want to know the number of <a href="http://en.wikipedia.org/wiki/Semiring">semirings</a> of a given size? Unfortunately OEIS does not seem to have an answer. And what if we want the list of 52 non-isomorphic commutative rings of size 8?</p>
<p>Alg comes in handy when you need the list or the count of non-isomorphic copies of an ad-hoc structure. For example, the number of non-isomorphic rings satisfying the additional equation $x \cdot y \cdot x = 0$ is:</p>
<pre class="brush: plain; gutter: false; title: ;">
$ ./alg.native theories/ring.th --axiom 'x * y * x = 0' --size 1-8 --count
    ...
    size | count
    -----|------
       1 | 1
       2 | 1
       3 | 1
       4 | 4
       5 | 1
       6 | 1
       7 | 1
       8 | 19
</pre>
<p>We could have guessed that there would be at least one such ring of each size, namely the one with zero multiplication. But what are the non-trivial examples of size 4?</p>
<pre class="brush: plain; gutter: false; title: ;">
$ ./alg.native --size 4 theories/ring.th \
  --axiom 'x * y * x = 0' --axiom 'exists x y, x * y &lt;&gt; 0'
# Theory ring_with_extras

    Constant 0.
    Unary ~.
    Binary + *.

    Axiom plus_commutative: x + y = y + x.
    Axiom plus_associative: (x + y) + z = x + (y + z).
    Axiom zero_neutral_left: 0 + x = x.
    Axiom zero_neutral_right: x + 0 = x.
    Axiom negative_inverse: x + ~ x = 0.
    Axiom negative_inverse: ~ x + x = 0.
    Axiom zero_inverse: ~ 0 = 0.
    Axiom inverse_involution: ~ (~ x) = x.

    Axiom mult_associative: (x * y) * z = x * (y * z).
    Axiom distrutivity_right: (x + y) * z = x * z + y * z.
    Axiom distributivity_left: x * (y + z) = x * y + x * z.

    # Extra command-line axioms
    Axiom: exists x y, x * y &lt;&gt; 0.
    Axiom: x * y * x = 0.

# Size 4

### ring_with_extras_4_1

    ~ |  0  a  b  c
    --+------------
      |  0  a  b  c

    + |  0  a  b  c
    --+------------
    0 |  0  a  b  c
    a |  a  0  c  b
    b |  b  c  0  a
    c |  c  b  a  0

    * |  0  a  b  c
    --+------------
    0 |  0  0  0  0
    a |  0  0  0  0
    b |  0  0  a  a
    c |  0  0  a  a

- - - - - - - - - - - - - - - - - - - - - - - - - - - -

### ring_with_extras_4_2

    ~ |  0  a  b  c
    --+------------
      |  0  a  c  b

    + |  0  a  b  c
    --+------------
    0 |  0  a  b  c
    a |  a  0  c  b
    b |  b  c  a  0
    c |  c  b  0  a

    * |  0  a  b  c
    --+------------
    0 |  0  0  0  0
    a |  0  0  0  0
    b |  0  0  a  a
    c |  0  0  a  a

- - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Statistics

    size | count
    -----|------
       4 | 2
</pre>
<p>Interesting. Or maybe not. Anyhow, it is easy to play with alg this way.</p>
<p>The supported output formats are text (actually Markdown), HTML, LaTeX and JSON. If you generate three or more sizes, alg outputs a URL for checking the numbers in OEIS.</p>
<p>On my dekstop with Intel Core 2 Duo E8500 @ 3.16 Ghz groups of size up to 9 are enumerated in 3.4 seconds, up to size 10 in 50 seconds, and up to size 11 in 9.5 minutes. Clearly, we are hitting a combinatorial explosion here. As there are $n^{n^2}$ multiplication tables of size $n \times n$, alg has to do something better than trying out $10^{100}$ possible multiplication tables to enumerate groups of size 10. Indeed, alg fights the combinatorial explosion by filling in the tables in a smart way. It uses two algorithms:</p>
<ol>
<li>The default algorithm fills in the tables in all possible ways, where with each new entry it also checks the axioms to see what else could be filled in. The algorithm works well for equational theories, such as groups, rings, and lattices.</li>
<li>The alternative algorithm, which is enabled with the <code>--sat</code> command-line option, transforms the axioms into a set of constraints that it then satisfies in all possible ways. The algorithm works well for relational theories, such as posets and graphs.</li>
</ol>
<p>Each new solution is compared for isomorphism with previously found ones. Since isomorphism testing is hard, alg uses simple invariants to quickly test for non-isomorphism. The memory footprint is very low. As I type this alg is using measly 880 kB of memory for enumeration of groups of size 11.</p>
<p>Alg is possibly the right tool for you if you want to:</p>
<ul>
<li>list or count non-isomorphic structures satisfying certain axioms, and you cannot find the data on the web</li>
<li>quickly check a hypothesis such as &#8220;In which rings does $x^5 + x^3 + 1 = 0$ have a solution?&#8221;</li>
<li>quickly check if two axiomatizations describe the same structures (count models of both and compare)</li>
</ul>
<p>Can you trust alg? Well, we do not have  a formal proof of correctness. If the results seem fishy there are several things you can do:</p>
<ol>
<li>Check the counts at OEIS.</li>
<li>Compare the answers given by the default and the alternative algorithm.</li>
<li>Use the <code>--paranoid</code> option for double-checking of results.</li>
</ol>
<p>Here are the promised download instructions. You may:</p>
<ol>
<li><strong>Check out the source code</strong> from <a href="http://hg.andrej.com/alg">Mercurial repository</a> with
<pre class="brush: plain; gutter: false; title: ;">
hg clone http://hg.andrej.com/alg/
</pre>
<p>and compile the program yourself (you need Ocaml 3.11 and menhir, as described in the manual).</li>
<li><strong>Download the archived source code</strong> from Mercurial repository: <a href="http://hg.andrej.com/alg/archive/tip.zip">alg.zip</a>, <a href="http://hg.andrej.com/alg/archive/tip.tar.gz">alg.tar.gz</a> or <a href="http://hg.andrej.com/alg/archive/tip.tar.bz2">alg.tar.bz2</a>.</li>
<li><a href="/wp-content/uploads/alg/"><strong>Download</strong><strong> precompiled executables</strong></a> with the manual and example theories included. We have prepared executables for Linux, MacOS X and Windows 7.</li>
</ol>
<p>The <a href="http://hg.andrej.com/alg/raw-file/tip/doc/manual.pdf">alg manual</a> explains how to compile and use alg and how to write your own theories.</p>
<p>Alg is open source software released under the <a href="http://www.opensource.org/licenses/bsd-license.php">simplified BSD license</a>. Feedback and bug reports are appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://math.andrej.com/2011/01/22/alg/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

