val is_transitive_intro (#a:Type) (r: binary_relation a)
  : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
val is_transitive_intro (#a:Type) (r: binary_relation a)
  : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r)
let is_transitive_intro #a r =
reveal_opaque (`%is_reflexive) (is_reflexive #a)
FStar.Fin.fst.checked
prims.fst.checked FStar.Seq.fst.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked FStar.Classical.Sugar.fsti.checked FStar.Classical.fsti.checked
FStar.Fin.fst
FStar.Fin.binary_relation FStar.Pervasives.reveal_opaque FStar.Fin.is_reflexive Prims.unit
(*
   Copyright 2008-2022 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)

module FStar.Fin

/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept  explicit,
/// effectively duplicating the interface file declarations.
 
module S = FStar.Seq 
 
(** Find an index of an element in [s] starting from [i] that validates [p]  *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
  if p (S.index s i) 
  then Some i 
  else if i + 1 < S.length s 
       then find #a s p (i + 1) 
       else None

(** Given a sequence [s] all of whose elements are at most [n], if the
    length of [s] is greater than [n], then there are two distinct
    indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) = 
   if n = 1 then (0, 1)
   else let k0 = S.index s 0 in
     match find s (fun k -> k = k0) 1 with
     | Some i -> 0, i
     | None -> let (i1,i2) = 
                pigeonhole (S.init #(under (n-1)) n
                                   (fun i -> let k = S.index s (i+1) in
                                          if k<k0 then k else k-1))
              in (i1+1, i2+1)
 
[@@"opaque_to_smt"]
let is_reflexive #a r  = forall (x:a).     x `r` x

[@@"opaque_to_smt"]
let is_symmetric #a r  = forall (x y:a).   x `r` y == y `r` x

[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z 

let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)

let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
val is_transitive_intro (#a:Type) (r: binary_relation a)
  : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r)
r: FStar.Fin.binary_relation a
  -> FStar.Pervasives.Lemma (requires forall (x: a). r x x) (ensures FStar.Fin.is_reflexive r)