coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Anton Trunov <anton.a.trunov AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Why doesn't compute this recursive function on Z?
- Date: Fri, 26 May 2017 09:34:58 +0300
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=anton.a.trunov AT gmail.com; spf=Pass smtp.mailfrom=anton.a.trunov AT gmail.com; spf=None smtp.helo=postmaster AT mail-lf0-f65.google.com
- Ironport-phdr: 9a23:Qg+V8xCe3ZXm/QgBduiqUyQJP3N1i/DPJgcQr6AfoPdwSPT+pMbcNUDSrc9gkEXOFd2CrakV1ayL7OigATVGusfe9ihaMdRlbFwst4Y/p08aPIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0IufrymUoHdgN6q2O+s5pbdfxtHhCanYbN1MR66sRjdutMYjIZmK6s90BvEr3lVcOhS2W9kOEifkhj468qy5pJv7zhct/c8/MNcTKv2eLg1QrNfADk6KW4549HluwfeRgWV/HscVWsWkhtMAwfb6RzxQ4n8vCjnuOdjwSeWJcL5Q6w6VjSk9KdrVQTniDwbOD4j8WHYkdJ/gaRGqx+8vRN/worUYIaINPpie67WYN0XSXZdUstXSidMBJ63YYkSAOobJetWr5XyqVQBohWjCwesCv3hxT1LiHHxxqA6z/0hEQTa0AwgA94DsnLZp8j1OqcIVuC1ybHFwCnFb/NK3jf97pXDfA47ofGRW7JwdtTRwlQoGgzfiFWQtYvlPzWP2usXqWSb8/BgVf+pi24gtQF8uTevxsI2hYnIgoIZ0EzL9SJ8wIssI9CzVUB1YdmhEJRKtiGaMZN7Qtg+Q25ypCk6yboGuYClcygQxpQnwxnfavKdf4eU5RLjUeCcKip7inJ9YL+zmQq+/Ey6xuD/VsS4ykhGojdFn9XWt30A1wTf5tWDR/Z95EutxDKC2x3J5u1ZLk05lLDXJ4Mgz7M2i5Edq17MHjXsl0XzlKKWdlsr+uyv6+n/Z7XpvJ6cN4tthgH6PKQihtWzAeo5PwUORWSb9uO81Lrs/U39XrpGlOE5kq7csJzCJMQboLC2AxNN34o99xqyCy2q3dcYkHUdMl5JZRKKg5LoNlzOOPz4CO2wg1WokDdl3fDGObjhD43XIXjFjLfherB951RGxwYp0dBf/Y9UCrcGIPLtQULxu9nYAQU4Mwyw2eroFNJ91oYGVWKVHqCZKL/SsUOP5u83P+aMY5YVtC/hJPgh+v7hlmQ0mUQdfKmsxZsYcmq0HvVgI0WDYHrjmM0NEWkQvll2cOu/g1qbFDVXenyaXqQm5zh9Bpj1I53EQ9WEhqCG2m+HBIBQYX4OXlmKDXDuMYzCR+0RbiWMCsBkmz0AE7OmTtlyhlmVqAbmxu8/faLv8SoCuMe72Q==
Hi Lars!
This is due to the fact that Zwf_well_founded’s proof uses destruction on a
logical term:
...
case (Z.le_gt_cases c y)
...
Just posted an answer on Stackoverflow :)
https://stackoverflow.com/questions/44186751/coq-cant-compute-a-well-founded-function-on-z-but-it-works-on-nat/
-Anton
> On 26 May 2017, at 09:30, Lars Rasmusson
> <lars.rasmusson AT ri.se>
> wrote:
>
> (** * How can I compute with integers Z in Coq?
>
> I write the sum of 1 to n with well-founded recursion,
> essentially like this.
>
> fix sum_n n _ := if 0 <? n then n + sum_n (n-1) _ else 0.
>
> When using nat I can use Compute to run the function
> but when using Z the program doesn't reduce.
>
> *)
>
> Require Import Arith.Arith Program.Utils Wellfounded.
>
> Fixpoint sum_n (n:nat) (H: Acc lt n) {struct H} : nat.
> refine (if dec (0 <? n) then n + sum_n (n-1) _ else 0).
> apply (Acc_inv H); apply Nat.ltb_lt in e; auto with *.
> Defined.
>
> Compute (sum_n 50 (lt_wf _)). (* Prints 1275 *)
>
> Require Import ZArith Zwf.
> Open Scope Z.
>
> Fixpoint sum_nZ (n:Z) (H: Acc (Zwf 0) n) {struct H} : Z.
> refine (if dec (0 <? n) then n + sum_nZ (n-1) _ else 0).
> apply (Acc_inv H); apply Z.ltb_lt in e; split; auto with *.
> Defined.
>
> Compute (sum_nZ 50 ((Zwf_well_founded _) _)). (* Doesn't reduce... *)
>
>
- [Coq-Club] Why doesn't compute this recursive function on Z?, Lars Rasmusson, 05/26/2017
- Re: [Coq-Club] Why doesn't compute this recursive function on Z?, Anton Trunov, 05/26/2017
- RE: [Coq-Club] Why doesn't compute this recursive function on Z?, Soegtrop, Michael, 05/29/2017
- Re: [Coq-Club] Why doesn't compute this recursive function on Z?, Anton Trunov, 05/26/2017
Archive powered by MHonArc 2.6.18.