non-termination

With clauses obscuring termination

烈酒焚心 提交于 2020-01-03 04:49:07
问题 I'm trying to define binary numbers in agda but agda cant see that ⟦_⇑⟧ is terminating. I really dont want to have to break out accessibility relations. How can I show agda that n gets smaller? module Binary where open import Data.Nat using (ℕ; _+_; +-suc) open ℕ 2* : ℕ → ℕ 2* n = n + n data Parity : ℕ → Set where 𝕖 : ∀ k → Parity (2* k) 𝕠 : ∀ k → Parity (1 + 2* k) parity : ∀ n → Parity n parity zero = 𝕖 0 parity (suc n) with parity n parity (suc .(k + k)) | 𝕖 k = 𝕠 k parity (suc .(suc (k + k

Is Well-Founded recursion safe?

两盒软妹~` 提交于 2019-12-12 20:23:55
问题 In the question about non-termination With clauses obscuring termination an answer suggests to recourse to <-wellFounded . I looked at the definition of <-wellFounded before, and it strikes me there is a --safe in OPTIONS . Is it meant to work without this option? That is, is using --safe some optimisation, or is it working around some fundamental problem? So in this case we just delegate the termination problem to a function marked as "safe"? 回答1: It is completely safe. --safe holds a module

Trying to count steps through recursion?

a 夏天 提交于 2019-12-11 08:43:36
问题 This is a cube, the edges of which are directional; It can only go left to right, back to front and top to bottom. edge(a,b). edge(a,c). edge(a,e). edge(b,d). edge(b,f). edge(c,d). edge(c,g). edge(d,h). edge(e,f). edge(e,g). edge(f,h). edge(g,h). With the method below we can check if we can go from A-H for example: cango(A,H). move(X,Y):- edge(X,Y). move(X,Y):- edge(X,Z), move(Z,Y). With move2, I'm trying to impalement counting of steps required. move2(X,Y,N):- N is N+1, edge(X,Y). move2(X,Y

How to choose the design for a well-founded inductive type?

柔情痞子 提交于 2019-12-10 19:22:37
问题 While studying well-foundedness, I wanted to see how different designs behave. For example, for a type: data _<_ (x : Nat) : Nat -> Set where <-b : x < (suc x) <-s : (y : Nat) -> x < y -> x < (suc y) well-foundedness is easy to demonstrate. But if a similar type is defined differently: data _<_ : Nat -> Nat -> Set where z-< : (m : Nat) -> zero < (suc m) s<s : (m n : Nat) -> m < n -> (suc m) < (suc n) It is obvious that in both cases the descending chain is not infinite, but in the second case

Transforming a sentence creates an infinite loop - but how?

折月煮酒 提交于 2019-12-10 18:09:31
问题 I can't figure out where this is going wrong. Please note that I am very new to Prolog and I'm sure I'm missing something - just no idea what that might be. Could anyone help me out please? Thanks, here is my code: printSentence([]). printSentence([W|[]]) :- write(W), write('.'), nl. printSentence([W|R]) :- write(W), write(' '), printSentence(R). transform([], Result). transform([Word|Rest], Result) :- replace(Word, Replacement), append(Result, Replacement, NewResult), transform(Rest,

Steadfastness: Definition and its relation to logical purity and termination

北城余情 提交于 2019-12-04 00:07:28
问题 So far, I have always taken steadfastness in Prolog programs to mean: If, for a query Q , there is a subterm S , such that there is a term T that makes ?- S=T, Q. succeed although ?- Q, S=T. fails , then one of the predicates invoked by Q is not steadfast. Intuitively, I thus took steadfastness to mean that we cannot use instantiations to "trick" a predicate into giving solutions that are otherwise not only never given, but rejected . Note the difference for nonterminating programs! In

Steadfastness: Definition and its relation to logical purity and termination

只谈情不闲聊 提交于 2019-12-01 02:58:35
So far, I have always taken steadfastness in Prolog programs to mean: If, for a query Q , there is a subterm S , such that there is a term T that makes ?- S=T, Q. succeed although ?- Q, S=T. fails , then one of the predicates invoked by Q is not steadfast. Intuitively, I thus took steadfastness to mean that we cannot use instantiations to "trick" a predicate into giving solutions that are otherwise not only never given, but rejected . Note the difference for nonterminating programs! In particular, at least to me, logical-purity always implied steadfastness. Example . To better understand the

Prolog predicate - infinite loop

喜你入骨 提交于 2019-11-28 13:47:18
I need to create a Prolog predicate for power of 2, with the natural numbers. Natural numbers are: 0, s(0), s(s(0)) ans so on.. For example: ?- pow2(s(0),P). P = s(s(0)); false. ?- pow2(P,s(s(0))). P = s(0); false. This is my code: times2(X,Y) :- add(X,X,Y). pow2(0,s(0)). pow2(s(N),Y) :- pow2(N,Z), times2(Z,Y). And it works perfectly with the first example, but enters an infinite loop in the second.. How can I fix this? This happends because the of evaluation order of pow2. If you switch the order of pow2, you'll have the first example stuck in infinite loop.. So you can check first if Y is a

Prolog predicate - infinite loop

ε祈祈猫儿з 提交于 2019-11-27 07:54:31
问题 I need to create a Prolog predicate for power of 2, with the natural numbers. Natural numbers are: 0, s(0), s(s(0)) ans so on.. For example: ?- pow2(s(0),P). P = s(s(0)); false. ?- pow2(P,s(s(0))). P = s(0); false. This is my code: times2(X,Y) :- add(X,X,Y). pow2(0,s(0)). pow2(s(N),Y) :- pow2(N,Z), times2(Z,Y). And it works perfectly with the first example, but enters an infinite loop in the second.. How can I fix this? 回答1: This happends because the of evaluation order of pow2. If you switch