Library UniMath.Algebra.Universal.Examples.Bool

Example on booleans.

Gianluca Amato, Marco Maggesi, Cosimo Perini Brogi 2019-2021
This file contains the definition of the signature of booleans and the standard boolean algebra.

Algebra structure over type bool.

Boolean ground terms.


Module GTerm.

The type of ground terms.

Definition T := gterm bool_signature bool_sort.

Constructors for ground terms.

Definition bot : T := build_gterm' (0 : names bool_signature).
Definition top : T := build_gterm' (1 : names bool_signature).
Definition neg : T T := build_gterm' (2 : names bool_signature).
Definition conj : T T T := build_gterm' (3 : names bool_signature).
Definition disj : T T T := build_gterm' (4 : names bool_signature).
Definition impl : T T T := build_gterm' (5 : names bool_signature).

End GTerm.

Booleans terms and semantics for boolean formulae.

Type for boolean (open) terms.
Constructors for terms.

Definition bot : T := build_term' (0 : names bool_signature).
Definition top : T := build_term' (1 : names bool_signature).
Definition neg : T T := build_term' (2 : names bool_signature).
Definition conj : T T T := build_term' (3 : names bool_signature).
Definition disj : T T T := build_term' (4 : names bool_signature).
Definition impl : T T T := build_term' (5 : names bool_signature).

Interpretation of propositional formulae.
Computations and interactive proofs.

Module Tests.

Definition x : T := varterm (0: bool_varspec).
Definition y : T := varterm (1: bool_varspec).
Definition z : T := varterm (2: bool_varspec).

Example: evaluation of true & false
A simple evaluation function for variables: assign true to x and y (the 0th and 1st variable) and false otherwise.

Definition v n :=
  match n with
    0 => true
  | 1 => true
  | _ => false
  end.

Example: evaluation of x ∧ (¬ y ∧ z)
Example: evaluation of x ∧ (z → ¬ y)
Dummett tautology

Local Lemma Dummett : i, interp i (disj (impl x y) (impl y x)) = true.
Show proof.
  intro i. lazy.
  induction (i 0); induction (i 1); apply idpath.

x ∨ ¬ (y ∧ z → x)

Local Lemma not_tautology : i, interp i (disj x (neg (impl (conj y z) x))) = false.
Show proof.
  use tpair.
 - exact (λ n, match n with _ => false end).
 - lazy.
   apply idpath.

Further tests.

Definition f (n : nat) : bool.
Show proof.
  induction n as [|n Hn].
  - exact true.
  - exact false.

Goal interp f (conj x top) = true.
Show proof.
lazy. apply idpath.

Goal interp f (conj x y) = false.
Show proof.
lazy. apply idpath.

Goal interp f (disj x y) = true.
Show proof.
lazy. apply idpath.

Goal interp f (disj x (conj y bot)) = true.
Show proof.
lazy. apply idpath.

End Tests.

End Term.