Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Section main.
- (*this program compiles with COQ 8.7*)
- (*The goal of this text is to show two famous undecidability results, namely
- the Rice theorem and the Turing halting theorem on a simplistic yet -hopefully- convincing
- computation model. We make 4 assumptions listed below (and in the case of the halting
- problem, we add the further assumption that there exists at least one non terminating
- program, since in the opposite case the constant function which returns true would be
- a perfectly reliable halting test*)
- Variables Input Output:Type.
- Variable pairing: Input -> Input -> Input. (*We assume we have a syntactic operation
- which makes an input with two other inputs, like putting parentheses*)
- Variable Calculate: Input -> Output -> Prop. (*We have an interpreter and
- "Calculate a b" means that when a is submitted to the interpreter, we get b as a result*)
- Variable b_false b_true:Output. (*booleans*)
- (*we introduce convenient notations*)
- Notation "a [ b ]" :=(pairing a b) (at level 61).
- Notation "p >>> q" := (Calculate p q) (at level 71).
- Notation same_result:= (fun a b:Input => forall r:Output, a >>> r <-> b >>> r).
- Notation halts := (fun x:Input => exists r:Output, x >>> r).
- Hypothesis A1: b_true <> b_false. (*the booleans are different*)
- Hypothesis A2: forall (x:Input) (a b:Output),
- x >>> a ->
- x >>> b ->
- a = b. (*if the result of a computation exists then it is unique*)
- Hypothesis A3: forall x:Input, exists diag_x:Input,
- forall (y:Input),
- same_result (diag_x [y]) (x [y[y]]). (*it is possible to handle parenthesis
- in the system in order to do this*)
- Hypothesis A4: forall condition case_1 case_2:Input, exists if_loop:Input, forall x:Input,
- (condition [x] >>> b_true -> same_result (if_loop [x]) case_1) /\
- (condition [x] >>> b_false -> same_result (if_loop [x]) case_2).
- (*our system handles if-then-else*)
- Theorem fixed_point: forall x:Input, exists e:Input,
- same_result e (x[e]).
- Proof.
- intro.
- destruct A3 with (x:=x) as (dx, D).
- exists (dx [dx]).
- apply D.
- Qed.
- Section no_semantical_tests.
- (*the Rice theorem states the three conditions below cannot hold simultaneously, namely
- there is no boolean non constant test which depends only on what a program actually does,
- and which can be programmed in the system we're discussing*)
- Variables test x1 x2: Input.
- Hypothesis T1:forall x y:Input, same_result x y -> same_result (test[x]) (test[y]).
- Hypothesis T2: forall x:Input, test[x] >>> b_true \/ test[x] >>> b_false.
- Hypothesis T3: test[x1] >>> b_true /\ test[x2] >>> b_false.
- Theorem Rice: False.
- Proof.
- destruct A4 with (condition:= test) (case_1 := x2) (case_2 := x1) as (u,Hyp_u).
- destruct fixed_point with (x:=u) as (e, Fix_ue).
- apply A1.
- destruct T2 with (x:=e).
- apply A2 with (x:= test [e]).
- assumption.
- apply T1 with (x:= x2).
- intro.
- apply iff_sym.
- apply iff_trans with (B:= u [e] >>> r).
- apply Fix_ue.
- apply Hyp_u.
- assumption.
- apply T3.
- apply A2 with (x:= test [e]).
- apply T1 with (x:= x1).
- intro.
- apply iff_sym.
- apply iff_trans with (B:= u [e] >>> r).
- apply Fix_ue.
- apply Hyp_u.
- assumption.
- apply T3.
- assumption.
- Qed.
- End no_semantical_tests.
- Section halting_problem.
- Variable halting_test: Input.
- Hypothesis HT1: exists stall:Input, halts stall -> False.
- Hypothesis HT2: forall x:Input, halting_test [x] >>> b_true <-> halts x.
- Hypothesis HT3: forall x:Input,
- halting_test [x] >>> b_true \/ halting_test [x] >>> b_false.
- Lemma calc_equality: forall (p q:Input) (r:Output),
- p >>> r -> q >>> r -> same_result p q.
- Proof.
- intros.
- intro.
- split.
- intro.
- assert (r = r0).
- apply A2 with (x:=p).
- assumption.
- assumption.
- rewrite <- H2.
- assumption.
- intro.
- assert (r = r0).
- apply A2 with (x:=q).
- assumption.
- assumption.
- rewrite <- H2.
- assumption.
- Qed.
- Theorem Turing_halting_theorem: False.
- Proof.
- destruct HT1 as (stall,Hyp_stall).
- apply Rice with (test:=halting_test) (x1 := halting_test [stall]) (x2:= stall).
- intros.
- destruct HT3 with (x:=x).
- apply calc_equality with (r:= b_true).
- assumption.
- apply HT2.
- apply HT2 in H0.
- destruct H0 as (rx, X).
- exists rx.
- apply H.
- assumption.
- apply calc_equality with (r:= b_false).
- assumption.
- destruct HT3 with (x:=y).
- apply False_ind.
- apply A1.
- apply A2 with (x:= halting_test [x]).
- apply HT2 in H1.
- destruct H1 as (ry, Y).
- apply HT2.
- exists ry.
- apply H.
- assumption.
- assumption.
- assumption.
- apply HT3.
- split.
- apply HT2.
- destruct HT3 with (x:=stall).
- exists b_true.
- assumption.
- exists b_false.
- assumption.
- destruct HT3 with (x:=stall).
- apply False_ind.
- apply Hyp_stall.
- apply HT2.
- assumption.
- assumption.
- Qed.
- End halting_problem.
- End main.
Add Comment
Please, Sign In to add comment