let well_founded_relation (a:Type) = rel:binrel a{is_well_founded rel}
let well_founded_relation (a: Type) =
rel: binrel a {is_well_founded rel}
FStar.WellFounded.fst.checked
prims.fst.checked FStar.Squash.fsti.checked FStar.Pervasives.fsti.checked FStar.IndefiniteDescription.fsti.checked FStar.Classical.Sugar.fsti.checked
FStar.WellFounded.fst
FStar.WellFounded.binrel FStar.WellFounded.is_well_founded
(*
   Copyright 2015 Chantal Keller and Catalin Hritcu, Microsoft Research and Inria

   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.

   Authors: Chantal Keller, Catalin Hritcu, Aseem Rastogi, Nikhil Swamy
*)

(* Defining accessibility predicates and well-founded recursion like in Coq
   https://coq.inria.fr/library/Coq.Init.Wf.html
*)

module FStar.WellFounded

#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok

let binrel (a:Type) = a -> a -> Type

(*
 * The accessibility relation
 * -- Marked erasable, since this is a singleton type anyway
 * -- Erasability also simplifies proofs that use accessibility in
 *    with axioms like indefinitedescription
 *)
[@@ erasable]
noeq
type acc (#a:Type u#a) (r:binrel u#a u#r a) (x:a) : Type u#(max a r) =
  | AccIntro : access_smaller:(y:a -> r y x -> acc r y) -> acc r x

(*
 * A binrel r is well-founded if every element is accessible
 *)
let well_founded (#a:Type u#a) (r:binrel u#a u#r a) = x:a -> acc r x

(*
 * Accessibility predicates can be used for implementing
 *   total fix points
 *)
let rec fix_F (#aa:Type) (#r:binrel aa) (#p:(aa -> Type))
              (f: (x:aa -> (y:aa -> r y x -> p y) -> p x))
              (x:aa) (a:acc r x)
  : Tot (p x) (decreases a)
  = f x (fun y h -> fix_F f y (a.access_smaller y h))

let fix (#aa:Type) (#r:binrel aa) (rwf:well_founded r)
        (p:aa -> Type) (f:(x:aa -> (y:aa -> r y x -> p y) -> p x))
        (x:aa)
  : p x
  = fix_F f x (rwf x)

let is_well_founded (#a:Type) (rel:binrel a) =
  forall (x:a). squash (acc rel x)
val well_founded_relation : a: Type -> Type
a: Type -> Type