reduction_engine.mli 2.97 KB
Newer Older
MARCHE Claude's avatar
MARCHE Claude committed
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
Andrei Paskevich's avatar
Andrei Paskevich committed
4
(*  Copyright 2010-2016   --   INRIA - CNRS - Paris-Sud University  *)
MARCHE Claude's avatar
MARCHE Claude committed
5 6 7 8
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
9
(*                                                                  *)
MARCHE Claude's avatar
MARCHE Claude committed
10
(********************************************************************)
11 12


13
(** A reduction engine for Why3 terms *)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

(*
terms are normalized with respect to

1) built-in computation rules

 a) on propositional connectives, e.g.

   f /\ true -> f

 b) on integers, e.g.

   35 + 7 -> 42

 c) on projections of pairs and of other ADTs, e.g

  fst (x,y) -> x

  cdr (Cons x y) -> y

 d) on defined function symbols, e.g.

  function sqr (x:int) = x * x

  sqr 4 -> 4 * 4 -> 16

  sqr x -> x * x

 e) (TODO?) on booleans, e.g.

  True xor False -> True

 f) (TODO?) on reals, e.g.

  1.0 + 2.5 -> 3.5

2) axioms declared as rewrite rules, thanks to the "rewrite" metas, e.g. if

    function dot : t -> t -> t
    axiom assoc: forall x y z, dot (dot x y) z = dot x (dot y z)
    meta "rewrite" assoc

  then

  dot (dot a b) (dot c d) -> dot a (dot b (dot c d))

  axioms used as rewrite rules must be either of the form

    forall ... t1 = t2

  or

    forall ... f1 <-> f2

   where the root symbol of t1 (resp. f1) is a non-interpreted function
   symbol (resp. non-interpreted predicate symbol)

  rewriting is done from left to right


*)

type engine
77
(** abstract type for reduction engines *)
78

79 80 81 82 83 84 85 86 87 88 89 90
type params = {
  compute_defs : bool;
  compute_builtin : bool;
  compute_def_set : Term.Sls.t;
}
(** Configuration of the engine.
   . [compute_defs]: if set to true, automatically compute symbols using
     known definitions. Otherwise, only symbols in [compute_def_set]
     will be computed.
   . [compute_builtin]: if set to true, compute builtin functions. *)

val create : params -> Env.env -> Decl.decl Ident.Mid.t -> engine
91 92 93 94 95
(** [create env known_map] creates a reduction engine with
    . builtins theories (int.Int, etc.) extracted from [env]
    . known declarations from [known_map]
    . empty set of rewrite rules
*)
96 97 98 99

exception NotARewriteRule of string

val add_rule : Term.term -> engine -> engine
100 101
(** [add_rule t e] turns [t] into a new rewrite rule and returns the
    new engine.
102

103 104 105
    raise NotARewriteRule if [t] cannot be seen as a rewrite rule
    according to the general rules given above.
*)
106 107


108
val normalize : limit:int -> engine -> Term.term -> Term.term
109 110
(** [normalize e t] normalizes the term [t] with respect to the engine
    [e]
111

112 113
    parameter [limit] provides a maximum number of steps for execution.
    When limit is reached, the partially reduced term is returned.
114
*)
115