halting-problem

Detecting infinite loop in brainfuck program

夙愿已清 提交于 2019-12-03 08:29:28
问题 I have written a simple brainfuck interpreter in MATLAB script language. It is fed random bf programs to execute (as part of a genetic algorithm project). The problem I face is, the program turns out to have an infinite loop in a sizeable number of cases, and hence the GA gets stuck at the point. So, I need a mechanism to detect infinite loops and avoid executing that code in bf. One obvious (trivial) case is when I have [] I can detect this and refuse to run that program. For the non-trivial

Detecting infinite loop in brainfuck program

给你一囗甜甜゛ 提交于 2019-12-02 23:54:54
I have written a simple brainfuck interpreter in MATLAB script language. It is fed random bf programs to execute (as part of a genetic algorithm project). The problem I face is, the program turns out to have an infinite loop in a sizeable number of cases, and hence the GA gets stuck at the point. So, I need a mechanism to detect infinite loops and avoid executing that code in bf. One obvious (trivial) case is when I have [] I can detect this and refuse to run that program. For the non-trivial cases, I figured out that the basic idea is: to determine how one iteration of the loop changes the

How can undecidable instances actually hang the compiler?

旧街凉风 提交于 2019-12-01 18:34:04
By the time I first read serious criticism on -XUndecidableInstances , I had already completely accustomed to it, seeing it as merely removal of an annoying restriction Haskell98 has to make compilers easier to implement . In fact I've encountered plenty of applications where undecidable instances were needed, but none where they actually caused any problems related to undecidability. Luke's example is problematic for quite a different reason class Group g where (%) :: g -> g -> g ... instance Num g => Group g where ... – well, this would clearly be overlapped by any proper Group instance, so

How can undecidable instances actually hang the compiler?

自古美人都是妖i 提交于 2019-12-01 18:08:02
问题 By the time I first read serious criticism on -XUndecidableInstances, I had already completely accustomed to it, seeing it as merely removal of an annoying restriction Haskell98 has to make compilers easier to implement . In fact I've encountered plenty of applications where undecidable instances were needed, but none where they actually caused any problems related to undecidability. Luke's example is problematic for quite a different reason class Group g where (%) :: g -> g -> g ... instance

Do agda programs necessarily terminate?

怎甘沉沦 提交于 2019-11-30 22:33:32
It has been stated a few places that all agda programs terminate. However I can construct a function like this: stall : ∀ n → ℕ stall 0 = 0 stall x = stall x The syntax highlighter doesn't seem to like it, but there are no compilation errors. Computing the normal form of stall 0 results in 0 . Computing the result of stall 1 causes Emacs to hang in what looks a lot like a non-terminating loop. Is this a bug? Or can Agda sometimes run forever? Or is something more subtle going on? In fact, there are compilation errors. The agda executable finds an error and passes that information to agda-mode

Infinite loops in Java

感情迁移 提交于 2019-11-30 00:12:48
Look at the following infinite while loop in Java. It causes a compile-time error for the statement below it. while(true) { System.out.println("inside while"); } System.out.println("while terminated"); //Unreachable statement - compiler-error. The following same infinite while loop, however works fine and doesn't issue any errors in which I just replaced the condition with a boolean variable. boolean b=true; while(b) { System.out.println("inside while"); } System.out.println("while terminated"); //No error here. In the second case also, the statement after the loop is obviously unreachable

Do all regular expressions halt?

徘徊边缘 提交于 2019-11-29 09:25:19
Is there any regular expression that will, for some input string, search for a match forever? For a finite input, there is no formal regular expression that will not halt. Any formal regular expression can be translated into a Deterministic Finite Automata. A DFA reads the input one character at a time, and, at the end of the input, you are either in an accepting state or in a non-accepting state. If the state is accepting, then the input matches the regular expression. Otherwise, it doesn't. Now, most "regular expression" libraries support things which are not regular expressions, such as

Proof that the halting problem is NP-hard?

半城伤御伤魂 提交于 2019-11-29 00:12:50
问题 In this answer to a question about the definitions of NP, NP-hard, and NP-complete, Jason makes the claim that The halting problem is the classic NP-hard problem. This is the problem that given a program P and input I, will it halt? This is a decision problem but it is not in NP. It is clear that any NP-complete problem can be reduced to this one. While I agree that the halting problem is intuitively a much "harder" problem than anything in NP, I honestly cannot come up with a formal,

Determining whether a regex is a subset of another

瘦欲@ 提交于 2019-11-28 16:32:03
I have a large collection of regular expression that when matched call a particular http handler. Some of the older regex's are unreachable (e.g. a.c* ⊃ abc* ) and I'd like to prune them. Is there a library that given two regex's will tell me if the second is subset of the first? I wasn't sure this was decidable at first (it smelled like the halting problem by a different name). But it turns out it's decidable . Kevin Stricker Trying to find the complexity of this problem lead me to this paper. The formal definition of the problem can be found within: this is generally called the inclusion

When have you come upon the halting problem in the field? [closed]

自闭症网瘾萝莉.ら 提交于 2019-11-28 03:18:34
When have you ever personally come upon the halting problem in the field? This can be when a co-worker / boss suggested a solution which would violate the fundamental limits of computation, or when you realized yourself that a problem you were trying to solve was, in fact, impossible to solve. The most recent time I came up with it was when studying type checkers. Our class realized that it would be impossible to write a perfect type checker (one that would accept all programs that would run without type errors, and reject all programs that would run with type errors) because this would, in