{"id":3333,"date":"2016-04-12T07:01:48","date_gmt":"2016-04-12T07:01:48","guid":{"rendered":"http:\/\/www.dyalog.com\/blog\/?p=3333"},"modified":"2016-04-12T07:15:37","modified_gmt":"2016-04-12T07:15:37","slug":"the-halting-problem-rendered-in-apl","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2016\/04\/the-halting-problem-rendered-in-apl\/","title":{"rendered":"The Halting Problem Rendered in APL"},"content":{"rendered":"<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Halting_problem\" target=\"_blank\">halting problem<\/a> is the problem of determining, from a description of a program and an input, whether the program will finish running or continue to run forever. It was proved in the negative by Alonzo Church and Alan Turing in 1936, and can be rendered in Dyalog APL as follows:<\/p>\n<p>Suppose there is an operator <code class=\" language-apl\">H<\/code> such that <code class=\" language-apl\">f H \u2375<\/code> is <code class=\" language-apl\">1<\/code> or <code class=\" language-apl\">0<\/code> according to whether <code class=\" language-apl\">f \u2375<\/code> halts. Consider:<\/p>\n<p><strong>In dfns<\/strong><\/p>\n<pre><code class=\" language-apl\">   f\u2190{\u2207 H \u2375:\u2207 \u2375 \u22c4 \u236c}\r\n<\/code><\/pre>\n<p>For <code class=\" language-apl\">f 0<\/code>, if <code class=\" language-apl\">\u2207\u00a0H\u00a00<\/code> is <code class=\" language-apl\">1<\/code>, then <code class=\" language-apl\">\u2207\u00a00<\/code> is invoked, leading to an infinite recursion, therefore <code class=\" language-apl\">\u2207\u00a0H\u00a00<\/code> should have been <code class=\" language-apl\">0<\/code>. On the other hand, if <code class=\" language-apl\">\u2207\u00a0H\u00a00<\/code> is <code class=\" language-apl\">0<\/code>, then the <code class=\" language-apl\">\u236c<\/code> part is invoked and is the result of <code class=\" language-apl\">f\u00a00<\/code>, therefore <code class=\" language-apl\">\u2207\u00a0H\u00a00<\/code> should have been <code class=\" language-apl\">1<\/code>.<\/p>\n<p>Presented as a table: For <code class=\" language-apl\">f 0<\/code><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"7\">\n<tbody>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" ><strong>suppose<\/strong> <code class=\" language-apl\">\u2207 H 0 <\/code> <strong>is<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" ><strong>invokes<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><strong>consequence<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">\u2207 H 0 <\/code> <strong>should be<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">1<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">\u2207 0<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\">infinite recursion<\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">0<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">0<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">\u236c<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">f 0 <\/code>results in <code class=\" language-apl\">\u236c<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">1<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Therefore, there cannot be such an operator <code class=\" language-apl\">H<\/code>.<\/p>\n<p><strong>In Tradfns<\/strong><\/p>\n<pre><code class=\" language-apl\">   \u2395fx 'f x' '\u2192f H x'\r\n<\/code><\/pre>\n<p>For <code class=\" language-apl\">f 0<\/code><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"7\">\n<tbody>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" ><strong>suppose<\/strong><code class=\" language-apl\"> f H 0 <\/code> <strong>is<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" ><strong>invokes<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\"><strong>consequence<\/strong><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\"><code class=\" language-apl\">f H 0 <\/code> <strong>should be<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\"><code class=\" language-apl\">1<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\"><code class=\" language-apl\">\u21921<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\">\u00a0 \u00a0 infinite loop<\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\"  align=\"center\"><code class=\" language-apl\">0<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">0<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">\u21920<\/code><\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">f 0 <\/code>exits<\/td>\n<td style=\"border-right: solid 1px #ddd; border-left: solid 1px #ddd;\" align=\"center\"><code class=\" language-apl\">1<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>The halting problem is the problem of determining, from a description of a program and an input, whether the program will finish running or continue to run forever. It was proved in the negative by Alonzo Church and Alan Turing &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2016\/04\/the-halting-problem-rendered-in-apl\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-3333","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/3333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=3333"}],"version-history":[{"count":9,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/3333\/revisions"}],"predecessor-version":[{"id":3843,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/3333\/revisions\/3843"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=3333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=3333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=3333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}