Questions tagged [totality]

34 questions
12
votes
1 answer

Coq simpl for Program Fixpoint

is there anything like the tactic simpl for Program Fixpoints? In particular, how can one proof the following trivial statement? Program Fixpoint bla (n:nat) {measure n} := match n with | 0 => 0 | S n' => S (bla n') end. Lemma obvious: forall n,…
ouler
  • 123
  • 6
12
votes
3 answers

Error in defining Ackermann in Coq

I am trying to define the Ackermann-Peters function in Coq, and I'm getting an error message that I don't understand. As you can see, I'm packaging the arguments a, b of Ackermann in a pair ab; I provide an ordering defining an ordering function for…
Mayer Goldberg
  • 1,288
  • 11
  • 21
11
votes
1 answer

What are sized types in Agda?

What are sized types in Agda? I've tried to read the paper about MiniAgda, but failed to proceed due to the following points: Why are data types generic over their size? As far as I know the size is the depth of the tree of induction. Why are data…
盛安安
  • 768
  • 1
  • 6
  • 19
9
votes
1 answer

What's the difference between Program Fixpoint and Function in Coq?

They seem to serve similar purposes. The one difference I've noticed so far is that while Program Fixpoint will accept a compound measure like {measure (length l1 + length l2) }, Function seems to reject this and will only allow {measure length…
LogicChains
  • 3,852
  • 2
  • 13
  • 21
7
votes
1 answer

If Idris thinks things may be total that are not, can Idris be used for proofs?

http://docs.idris-lang.org/en/v0.99/tutorial/theorems.html#totality-checking-issues states that: Secondly, the current implementation has had limited effort put into it so far, so there may still be cases where it believes a function is total which…
redfish64
  • 551
  • 3
  • 10
7
votes
1 answer

Limitations of Fixpoint in Coq?

I am fooling around with Coq. Specifically, I am trying to implement mergesort and then prove that it works. My attempt at an implementation was: Fixpoint sort ls := match ls with | nil => nil | cons x nil => cons x nil | xs => let (left, right)…
mushroom
  • 5,637
  • 5
  • 31
  • 60
6
votes
4 answers

Defining recursive function over product type

I'm trying to formalize each integer as an equivalence class of pairs of natural numbers, where the first component is the positive part, and the second component is the negative part. Definition integer : Type := prod nat nat. I want to define a…
Mark
  • 4,584
  • 5
  • 35
  • 61
5
votes
1 answer

Coq can't compute well-founded defined with Fix, but can if defined with Program Fixpoint

As an exercise to understand recursion by a well-founded relation I decided to implement the extended euclidean algorithm. The extended euclidean algorithm works on integers, so I need some well-founded relation on integers. I tried to use the…
Rafael Castro
  • 519
  • 4
  • 12
5
votes
2 answers

Cannot guess decreasing argument of fix for nested match in Coq

I have the following definition for terms : Inductive term : Type := | Var : variable -> term | Func : function_symbol -> list term -> term. and a function pos_list taking a list of terms and returning a list of "positions" for each subterms.…
Boris
  • 269
  • 1
  • 10
4
votes
0 answers

Strange pattern matching behavior in Idris

I stumbled upon what seems to be a strange behavior for Idris. I'm using Emacs 25.3 on Ubuntu 17.04 and Idris 1.0. Consider the following module: module Strange %default total fun : Int -> Int -> Int fun 0 0 = 0 fun 0 n = 10 fun n 0 = 20 When I…
Thales MG
  • 730
  • 4
  • 14
4
votes
2 answers

Coq best practice: mutual recursion, only one function is structurally decreasing

Consider the following toy representation for the untyped lambda calculus: Require Import String. Open Scope string_scope. Inductive term : Set := | Var : string -> term | Abs : string -> term -> term | App : term -> term -> term. Fixpoint print…
Carl Patenaude Poulin
  • 4,468
  • 4
  • 17
  • 36
4
votes
1 answer

Coq can't compute a well-founded function on Z, but it works on nat

I'm writing (for myself) an explanation of how to do well-founded recursion in Coq. (see i.e. the Coq'Art book, chapter 15.2). First I made an example function based on nat and that worked fine, but then I did it again for Z, and when I use Compute…
larsr
  • 5,061
  • 16
  • 32
4
votes
2 answers

Well founded recursion in Coq

I am trying to write a function for computing natural division in Coq and I am having some trouble defining it since it is not structural recursion. My code is: Inductive N : Set := | O : N | S : N -> N. Inductive Bool : Set := | True : Bool …
Martin Copes
  • 921
  • 1
  • 6
  • 14
4
votes
1 answer

Mutualy recursive function and termination checker in Coq

EDIT Require Import Bool List ZArith. Variable A: Type. Inductive error := | Todo. Inductive result (A : Type) : Type := Ok : A -> result A | Ko : error -> result A. Variable bool_of_result : result A -> bool. Variable…
Quyen
  • 1,323
  • 1
  • 10
  • 17
3
votes
2 answers

Teach coq to check termination

Coq, unlike many others, accepts an optional explicit parameter,which can be used to indicate the decreasing structure of a fixpoint definition. From Gallina specification, 1.3.4, Fixpoint ident params {struct ident0 } : type0 := term0 defines the…
Jason Hu
  • 5,731
  • 1
  • 16
  • 35
1
2 3