Questions tagged [totality]
38 questions
1
vote
0 answers
Making strIndex total in Quick Search?
I am working on a version of the Quick Search string searching algorithm in Idris, and have come up with this:
quickSearch : (needle : String) ->
(haystack : String) ->
{auto lengths : (length needle) `LTE`…

Tommy McGuire
- 1,223
- 13
- 16
1
vote
1 answer
Why does this function hang the REPL?
Chapter 9 of Test-Driven Development with Idris presents the following data type and removeElem function.
import Data.Vect
data MyElem : a -> Vect k a -> Type where
MyHere : MyElem x (x :: xs)
MyThere : (later : MyElem x xs) -> MyElem x (y…

Kevin Meredith
- 41,036
- 63
- 209
- 384
1
vote
1 answer
Showing terminating recursion for cumsum in Coq
I want to prove that computing the cumulative sum between a and b terminates.
I use an Acc lt x term to show that the recursion decreases, like this
Require Import Omega.
Lemma L1 : forall a b, a (b-(1+a)) < (b-a).
intros; omega. Qed.
Lemma…

larsr
- 5,447
- 19
- 38
0
votes
1 answer
How to crash on internal bug and force totality
I'm ffi-ing to C and the function I call returns an int to mean gt, eq or lt. I want to crash on anything other than 1, 0 or -1 cos that should never happen. And I'd like Idris to consider 0, 1 and -1 to be exhaustive matches. I tried
prim__compare…

joel
- 6,359
- 2
- 30
- 55
0
votes
1 answer
Can I avoid explicitly discharging invalid cases in total functions in Idris?
Consider the following (very simplified) example of constraining a datatype via a side-condition on its values:
data Transport = Car | Foot | Boat
total wheels : (transport : Transport) -> {auto hasWheels : transport = Car} -> Int
wheels Car…

Ganesh Sittampalam
- 28,821
- 4
- 79
- 98
0
votes
2 answers
Cannot determine termination
Function for determining if a set is a subset of another:
Fixpoint subset (s1:bag) (s2:bag) : bool :=
match s1 with
| nil => true
| h :: t => match (beq_nat (count h s1) (count h s2)) with
| true => subset (remove_all h t) (remove_all h…

Alex
- 18,484
- 8
- 60
- 80
0
votes
2 answers
Is this recursive function not total, or is the compiler just unable to prove it? How to rewrite it as total?
When presented with the following code:
module TotalityOrWhat
%default total
data Instruction = Jump Nat | Return Char | Error
parse : List Char -> Instruction
parse ('j' :: '1' :: _) = Jump 1
parse ('j' :: '2' :: _) = Jump 2
parse ('j' :: '3' ::…

Keith Pinson
- 7,835
- 7
- 61
- 104
0
votes
1 answer
How to get an induction principle for nested fix
I am working with a function that searches through a range of values.
Require Import List.
(* Implementation of ListTest omitted. *)
Definition ListTest (l : list nat) := false.
Definition SearchCountList n :=
(fix f i l := match i with
| 0 =>…

scubed
- 307
- 3
- 10