Library QedkConcrete.consensusdecisions

Boolean bridges for the readable consensus checks. The implementation uses propositions with bool_decide; these equalities let execution proofs compare them with the native integer and string tests.
From Stdlib Require Import List String ZArith Bool Lia.
From stdpp Require Import decidable numbers strings list.
Set Default Goal Selector "!".
Local Open Scope Z_scope.

Lemma bool_decide_Z_le (x y : Z) : bool_decide (x ≤ y) = Z.leb x y.
Proof.
  destruct (Z.leb x y) eqn:Hle.
  - apply bool_decide_eq_true_2. now apply Z.leb_le.
  - apply bool_decide_eq_false_2. apply Z.leb_gt in Hle. lia.
Qed.

Lemma bool_decide_string_eq (a b : string) : bool_decide (a = b) = String.eqb a b.
Proof.
  destruct (String.eqb a b) eqn:Heq.
  - apply bool_decide_eq_true_2. now apply String.eqb_eq.
  - apply bool_decide_eq_false_2. now apply String.eqb_neq.
Qed.

Lemma bool_decide_not_in (a : string) (xs : list string) :
  bool_decide (¬ elem_of a xs) = negb (existsb (fun b ⇒ String.eqb b a) xs).
Proof.
  destruct (existsb (fun b ⇒ String.eqb b a) xs) eqn:Hin; cbn [negb].
  - apply bool_decide_eq_false_2. intro Hnot. apply Hnot, list_elem_of_In.
    apply existsb_exists in Hin as [b [Hin Heq]].
    apply String.eqb_eq in Heq. now subst b.
  - apply bool_decide_eq_true_2. intro Hin'. apply list_elem_of_In in Hin'.
    assert (existsb (fun b ⇒ String.eqb b a) xs = true) as Hyes.
    { apply existsb_exists. ∃ a. split; [exact Hin'|apply String.eqb_refl]. }
    congruence.
Qed.