Section lb_mask_nat.
Let lb_mask_nat_1 l : ⟬ ⟦l⟧⟭  ⪯  l.
Let lb_mask_nat_2 l : l ⪯  ⟬ ⟦l⟧⟭  .
Fact lb_mask_nat l : ⟬ ⟦l⟧⟭ ≂ l.
Hint Resolve lb_mask_eq_binary_le binary_le_eq_lb_mask : core.
Fact binary_le_trans x y z : x ≲ y -> y ≲ z -> x ≲ z.
Fact lb_mask_equiv_equal l m : l ≂ m <-> ⟦l⟧ = ⟦m⟧.
Fact equal_lb_mask_equiv x y : x = y <-> ⟬ x⟭ ≂⟬ y⟭.
Local Notation lbeq := lb_mask_equiv (only parsing).
Add Parametric Morphism: (lb_nat) with signature (lbeq) ==> (eq) as lb_nat_eq.
End binary_le_dio.
Definition lb_dio (R : (nat -> lb) -> Prop) := { f | forall v, df_pred f (fun n => ⟦v n⟧) <-> R v }.
*)
Definition bool_add_with_rem a b c : bool * bool :=
match a, b, c with
| ⟘, ⟘, ⟘ => (⟘,⟘)
| ⟘, ⟘, ⟙ => (⟘,⟙)
| ⟘, ⟙, ⟘ => (⟘,⟙)
| ⟘, ⟙, ⟙ => (⟙,⟘)
| ⟙, ⟘, ⟘ => (⟘,⟙)
| ⟙, ⟘, ⟙ => (⟙,⟘)
| ⟙, ⟙, ⟘ => (⟙,⟘)
| ⟙, ⟙, ⟙ => (⟙,⟙)
end.
Notation bin_add := bool_add_with_rem.
Fact bin_add_eq_00x x : bin_add ⟘ ⟘  x = (⟘,x).
Fact lb_succ_spec_1 l : ⟦lb_succ ⟙ l⟧ = S ⟦l⟧.
Fact lb_succ_spec a l : ⟦lb_succ a l⟧ = bool2nat a + ⟦l⟧.
Fact lb_succ_bot l : lb_succ ⟘ l ≂ l.
Fixpoint lb_plus a l m :=
match l, m with
| nil,   m   => lb_succ a m
| l,    nil  => lb_succ a l
| x::l, y::m => let (r,z) := bin_add a x y in z::lb_plus r l m
end.
Fact lb_plus_fix_0 a l : lb_plus a nil l = lb_succ a l.
Local Infix "⊕" := (lb_plus ⟘ ) (at level 41, left associativity).
Fact lb_plus_spec_0 l m : ⟦l⊕m⟧ = ⟦l⟧ + ⟦m⟧.
Fact lb_ortho_plus l m : l ⟂ m <-> l ⪯ l⊕m.
(*  Theorem lb_ortho_diophantine x y : lb_dio (fun v => v x ⟂ v y).  *)
Fact lb_ortho_plus_join x y : x ⟂ y -> x⊕y ≂ x↑y.
Fact lb_ortho_plus_id a x y : a ⟂ x -> a ⟂ y -> x ⟂ y <-> (a⊕x)↓(a⊕y) ≂ a.
(* A purely Boolean algebraic proof *)
Fact lb_minus_plus a b : a ⪯ b -> exists x, b ≂ a⊕x /\ a ⪯  a⊕x.
(* A diophantine representation of bitwise and *)

Theorem lb_meet_dio a b c : a ≂ b↓c <-> exists x y, b ≂ a⊕x /\ c ≂ a⊕y /\ a ⪯  a⊕x /\ a ⪯  a⊕y /\ x ⪯  x⊕y.