Go Back   Science Forums
View Single Post
Old 05-23-2009   #2 (permalink)
CraigD's Avatar
CraigD
Creating


Location:
Silver Spring, MD, USA
 
CraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond reputeCraigD has a reputation beyond repute
 



Not Ranked  0 score     
Post A weak halting deciding program for Lobotomized Brainfuck

The Brainfuck esoteric computer language is discussed in the thread [thread=]“Brainfuck”[/thread]. In this post, I’ll describe a variation of this language I call “Lobotomized Brainfuck”, and give a halting deciding program for it.

Lobotomized Brainfuck (LBF) is Brainfuck with only the characters +, [, and ]. Thus, it has only a single 1-byte cell, which is assumed to overflow without error, that is, incrementing the value 255 results in a value of 0. It can be interpreted on any Brainfuck interpreter that has this overflow behavior.

A halting deciding program for LBF is described by the following vague pseudo-code logical expression:
If, for each [...] in program P
( if (count of + before [...]) =mod 256= 0
or (count of + before [...]) =mod (count of + within [...])= 256
) and (count of + withing ]...]) == 0
, program P halts.

The following MUMPS code implements this program:
Code:
n (XLLBFHP,R) s P=R,I=1 f  s J=$f(P,"[",I) x XLLBFHP(3) q:'R!'J  x XLLBFHP(1) q:'I  e  x XLLBFHP(2) q:'R!'I  ;XLLBFHP: Lobotomized Brainfuck halting program
s E=$e(P,I,J-2),L1=$l(E)-$l($tr(E,"+")) i '(L1#256) s D=1 f I=J:1 s E=$e(P,I),D=$s(E="[":1,E="]":-1,1:0)+D s:E="" (I,R)="" q:'I  i 'D s I=I+1 q  ;XLLBFHP(1): if (count of + before [...]) =mod 256= 0
s I=$f(P,"]",J),E=$e(P,J,I-2),L2=$l(E)-$l($tr(E,"+")) i $s(L2:(L1#L2)-(256#L2),1:1) s R=0 q  ;XLLBFHP(2): or [not] (count of + before [...]) =mod (count of + within [...])= 256
s R=1,E=$e(P,I,$s(J:J-2,1:$l(P))) i $p(E,"]",1,$l(E,"]")-1)["+" s R=0 ;XLLBFHP(3): [not] (count of + withing ]...]) = 0
The following use of it:
Code:
f  r R," " S R=$P(R," ") x XLLBFHP W $s(R="":" invalid",R:" ends",1:" doesn't end"),!
produced the following output for various LBF programs:
Code:
[]                  ends
+                   ends
+[]                 doesn't end
+[+]                ends
[+++]               ends
+++++[+]            ends
+[++]               doesn't end
+++[+++++]          doesn't end
++++[+++]           ends
+++++[+[++]]        doesn't end
++[+[++]]           doesn't end
+[+[++]++++[+++]]   ends
+[+[++[+++]][++]]   doesn't end
+[[+++]]            ends
+[++]               doesn't end
++++[+++]           ends
+[+]++[++]          ends
+[[+]++[++]]        ends
+[[+]++[++]]+       ends
+[[+]++[++]+]       doesn't end
+[[+]++[++]+]+[+]   doesn't end
[[[[]               invalid
]]]][               invalid
+[+[++[+++][++]]    doesn't end
+[+][]]]]           ends
I use the output “ends” and “doesn’t end” as synonyms for HALTS and LOOPS in the previous posts description of halting program results.

If the runtime failure of a syntactically ill-formed LBF program is considered halting, then the “invalid” results above may be considered “ends”. Note, however, that although this program returns R=”” indicating that the program is ill-formed, it is not a validity checking program, so may also return “ends” and “doesn’t end” for syntactically invalid programs.

As mentioned in post #1, this program is an example of a halting program that doesn’t run the program it decides, but rather analyzes the input program’s structure.


----------------
Moderator: Computers and Technology; Medical Science; Science Projects and Homework; Philosophy of Science; Physics and Mathematics; Environmental Studies
Reply With Quote
 
» Advertisement
» Current Poll
Who's the sexiest man alive? Johnny Depp or Robert Pattinson?
Johnny Depp - 30.00%
3 Votes
Robert Pattinson - 0%
0 Votes
Someone else (please specify) - 40.00%
4 Votes
I'm too macho to think a guy is sexy - 30.00%
3 Votes
Total Votes: 10
You may not vote on this poll.


All times are GMT -8. The time now is 12:37 PM.

Hypography?

Hypography [n.]: A combination of "hyperlink" and "bibliography" - ie, a list of links to electronic documents. Comparable to discography and bibliography, but not cartography.

We have been online since May 2000, and aim to be the best place to find and share science-related content of all kinds.

Share the love!

Please add more science to your life. Use our RSS feeds on your blog, your portal, or your favorite feedreader!


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000-2009 Hypography
Part of the Hypography - Science for Everyone Network