6 kyu

Verified list maximum

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:

  1. No integer in the list exceeds the maximum returned by list_max_Z
  2. The maximum returned by list_max_Z must appear in the list, or else it must be 0

Convince yourself that the above specification is complete, i.e. it fully describes the expected behavior of list_max_Z, and then proceed Your task is to prove it.

Preloaded

{-# OPTIONS --safe #-}
module Preloaded where

open import Data.List
open import Data.Integer

list-max-ℤ : List ℤ  ℤ
list-max-ℤ xs = foldr _⊔_ (+ 0) xs
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.
def list_max_Z : list ℤ  ℤ := list.foldr max 0
Theorem Proving
Fundamentals

Stats:

CreatedMay 31, 2021
PublishedMay 31, 2021
Warriors Trained141
Total Skips9
Total Code Submissions140
Total Times Completed45
Coq Completions31
Lean Completions12
Agda Completions7
Total Stars1
% of votes with a positive feedback rating100% of 9
Total "Very Satisfied" Votes9
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • donaldsebleung Avatar
  • Madjosz Avatar
  • monadius Avatar
Ad