6 kyu
Verified list maximum
31 of 45donaldsebleung
Description:
This Kata is a warm-up exercise for "Verified C array maximum" (coming soon).
Coq.Lists.List
provides a built-in function list_max
for computing the maximum natural number within a given list, or 0
if the list is empty; however, an equivalent function for integers is not present in the standard library.
Here, we present list_max_Z
(list-max-ℤ
in Agda), the integer equivalent of list_max
which computes the maximum integer in a given list or 0
if all integers are negative. A specification for list_max_Z
could be as follows:
- No integer in the list exceeds the maximum returned by
list_max_Z
- The maximum returned by
list_max_Z
must appear in the list, or else it must be0
Convince yourself that the above specification is complete, i.e. it fully describes the expected behavior of Your task is to prove it.list_max_Z
, and then proceed
Preloaded
Require Import Coq.Lists.List.
Import ListNotations.
Require Import Coq.ZArith.BinInt.
Open Scope Z_scope.
Definition list_max_Z : list Z -> Z := fold_right Z.max 0.
Theorem Proving
Fundamentals
Similar Kata:
Stats:
Created | May 31, 2021 |
Published | May 31, 2021 |
Warriors Trained | 141 |
Total Skips | 9 |
Total Code Submissions | 140 |
Total Times Completed | 45 |
Coq Completions | 31 |
Lean Completions | 12 |
Agda Completions | 7 |
Total Stars | 1 |
% of votes with a positive feedback rating | 100% of 9 |
Total "Very Satisfied" Votes | 9 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 6 kyu |