src/Provers/trancl.ML
author berghofe
Wed, 07 Feb 2007 12:08:48 +0100
changeset 22257 159bfab776e2
parent 15574 b1d1b5bfc464
child 26834 87a5b9ec3863
permissions -rw-r--r--
"prove" function now instantiates relation variable in order to avoid problems with higher-order unification. This allows relations to be encoded as binary predicates.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     1
(*
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
     2
  Title:	Transitivity reasoner for transitive closures of relations
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     3
  Id:		$Id$
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     4
  Author:	Oliver Kutter
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     5
  Copyright:	TU Muenchen
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     6
*)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
     7
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
     8
(*
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
     9
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    10
The packages provides tactics trancl_tac and rtrancl_tac that prove
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    11
goals of the form
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    12
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    13
   (x,y) : r^+     and     (x,y) : r^* (rtrancl_tac only)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    14
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    15
from premises of the form
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    16
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    17
   (x,y) : r,     (x,y) : r^+     and     (x,y) : r^* (rtrancl_tac only)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    18
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    19
by reflexivity and transitivity.  The relation r is determined by inspecting
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    20
the conclusion.
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    21
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    22
The package is implemented as an ML functor and thus not limited to
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    23
particular constructs for transitive and reflexive-transitive
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    24
closures, neither need relations be represented as sets of pairs.  In
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    25
order to instantiate the package for transitive closure only, supply
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    26
dummy theorems to the additional rules for reflexive-transitive
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    27
closures, and don't use rtrancl_tac!
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    28
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    29
*)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    30
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    31
signature TRANCL_ARITH = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    32
sig
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    33
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    34
  (* theorems for transitive closure *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    35
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    36
  val r_into_trancl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    37
      (* (a,b) : r ==> (a,b) : r^+ *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    38
  val trancl_trans : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    39
      (* [| (a,b) : r^+ ; (b,c) : r^+ |] ==> (a,c) : r^+ *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    40
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    41
  (* additional theorems for reflexive-transitive closure *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    42
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    43
  val rtrancl_refl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    44
      (* (a,a): r^* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    45
  val r_into_rtrancl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    46
      (* (a,b) : r ==> (a,b) : r^* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    47
  val trancl_into_rtrancl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    48
      (* (a,b) : r^+ ==> (a,b) : r^* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    49
  val rtrancl_trancl_trancl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    50
      (* [| (a,b) : r^* ; (b,c) : r^+ |] ==> (a,c) : r^+ *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    51
  val trancl_rtrancl_trancl : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    52
      (* [| (a,b) : r^+ ; (b,c) : r^* |] ==> (a,c) : r^+ *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    53
  val rtrancl_trans : thm
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    54
      (* [| (a,b) : r^* ; (b,c) : r^* |] ==> (a,c) : r^* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    55
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    56
  (* decomp: decompose a premise or conclusion
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    57
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    58
     Returns one of the following:
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    59
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
    60
     NONE if not an instance of a relation,
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
    61
     SOME (x, y, r, s) if instance of a relation, where
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    62
       x: left hand side argument, y: right hand side argument,
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    63
       r: the relation,
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    64
       s: the kind of closure, one of
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    65
            "r":   the relation itself,
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    66
            "r^+": transitive closure of the relation,
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    67
            "r^*": reflexive-transitive closure of the relation
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    68
  *)  
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
    69
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    70
  val decomp: term ->  (term * term * term * string) option 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    71
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    72
end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    73
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    74
signature TRANCL_TAC = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    75
sig
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    76
  val trancl_tac: int -> tactic;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    77
  val rtrancl_tac: int -> tactic;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    78
end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    79
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    80
functor Trancl_Tac_Fun (Cls : TRANCL_ARITH): TRANCL_TAC = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    81
struct
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    82
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    83
 
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    84
datatype proof
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    85
  = Asm of int 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    86
  | Thm of proof list * thm; 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    87
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    88
exception Cannot; (* internal exception: raised if no proof can be found *)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    89
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    90
fun prove thy r asms = 
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    91
  let
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    92
    fun inst thm =
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    93
      let val SOME (_, _, r', _) = Cls.decomp (concl_of thm)
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    94
      in Drule.cterm_instantiate [(cterm_of thy r', cterm_of thy r)] thm end;
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    95
    fun pr (Asm i) = List.nth (asms, i)
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
    96
      | pr (Thm (prfs, thm)) = map pr prfs MRS inst thm
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    97
  in pr end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    98
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
    99
  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   100
(* Internal datatype for inequalities *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   101
datatype rel 
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   102
   = Trans  of term * term * proof  (* R^+ *)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   103
   | RTrans of term * term * proof; (* R^* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   104
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   105
 (* Misc functions for datatype rel *)
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   106
fun lower (Trans (x, _, _)) = x
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   107
  | lower (RTrans (x,_,_)) = x;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   108
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   109
fun upper (Trans (_, y, _)) = y
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   110
  | upper (RTrans (_,y,_)) = y;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   111
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   112
fun getprf   (Trans   (_, _, p)) = p
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   113
|   getprf   (RTrans (_,_, p)) = p; 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   114
 
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   115
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   116
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   117
(*  mkasm_trancl Rel (t,n): term -> (term , int) -> rel list                *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   118
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   119
(*  Analyse assumption t with index n with respect to relation Rel:         *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   120
(*  If t is of the form "(x, y) : Rel" (or Rel^+), translate to             *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   121
(*  an object (singleton list) of internal datatype rel.                    *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   122
(*  Otherwise return empty list.                                            *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   123
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   124
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   125
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   126
fun mkasm_trancl  Rel  (t, n) =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   127
  case Cls.decomp t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   128
    SOME (x, y, rel,r) => if rel aconv Rel then  
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   129
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   130
    (case r of
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   131
      "r"   => [Trans (x,y, Thm([Asm n], Cls.r_into_trancl))]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   132
    | "r+"  => [Trans (x,y, Asm n)]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   133
    | "r*"  => []
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   134
    | _     => error ("trancl_tac: unknown relation symbol"))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   135
    else [] 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   136
  | NONE => [];
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   137
  
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   138
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   139
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   140
(*  mkasm_rtrancl Rel (t,n): term -> (term , int) -> rel list               *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   141
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   142
(*  Analyse assumption t with index n with respect to relation Rel:         *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   143
(*  If t is of the form "(x, y) : Rel" (or Rel^+ or Rel^* ), translate to   *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   144
(*  an object (singleton list) of internal datatype rel.                    *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   145
(*  Otherwise return empty list.                                            *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   146
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   147
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   148
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   149
fun mkasm_rtrancl Rel (t, n) =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   150
  case Cls.decomp t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   151
   SOME (x, y, rel, r) => if rel aconv Rel then
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   152
    (case r of
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   153
      "r"   => [ Trans (x,y, Thm([Asm n], Cls.r_into_trancl))]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   154
    | "r+"  => [ Trans (x,y, Asm n)]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   155
    | "r*"  => [ RTrans(x,y, Asm n)]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   156
    | _     => error ("rtrancl_tac: unknown relation symbol" ))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   157
   else [] 
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   158
  | NONE => [];
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   159
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   160
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   161
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   162
(*  mkconcl_trancl t: term -> (term, rel, proof)                            *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   163
(*  mkconcl_rtrancl t: term -> (term, rel, proof)                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   164
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   165
(*  Analyse conclusion t:                                                   *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   166
(*    - must be of form "(x, y) : r^+ (or r^* for rtrancl)                  *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   167
(*    - returns r                                                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   168
(*    - conclusion in internal form                                         *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   169
(*    - proof object                                                        *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   170
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   171
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   172
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   173
fun mkconcl_trancl  t =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   174
  case Cls.decomp t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   175
    SOME (x, y, rel, r) => (case r of
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   176
      "r+"  => (rel, Trans (x,y, Asm ~1), Asm 0)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   177
    | _     => raise Cannot)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   178
  | NONE => raise Cannot;
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   179
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   180
fun mkconcl_rtrancl  t =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   181
  case Cls.decomp t of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   182
    SOME (x,  y, rel,r ) => (case r of
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   183
      "r+"  => (rel, Trans (x,y, Asm ~1),  Asm 0)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   184
    | "r*"  => (rel, RTrans (x,y, Asm ~1), Asm 0)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   185
    | _     => raise Cannot)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15098
diff changeset
   186
  | NONE => raise Cannot;
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   187
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   188
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   189
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   190
(*  makeStep (r1, r2): rel * rel -> rel                                     *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   191
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   192
(*  Apply transitivity to r1 and r2, obtaining a new element of r^+ or r^*, *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   193
(*  according the following rules:                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   194
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   195
(* ( (a, b) : r^+ , (b,c) : r^+ ) --> (a,c) : r^+                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   196
(* ( (a, b) : r^* , (b,c) : r^+ ) --> (a,c) : r^+                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   197
(* ( (a, b) : r^+ , (b,c) : r^* ) --> (a,c) : r^+                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   198
(* ( (a, b) : r^* , (b,c) : r^* ) --> (a,c) : r^*                           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   199
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   200
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   201
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   202
fun makeStep (Trans (a,_,p), Trans(_,c,q))  = Trans (a,c, Thm ([p,q], Cls.trancl_trans))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   203
(* refl. + trans. cls. rules *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   204
|   makeStep (RTrans (a,_,p), Trans(_,c,q))  = Trans (a,c, Thm ([p,q], Cls.rtrancl_trancl_trancl))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   205
|   makeStep (Trans (a,_,p), RTrans(_,c,q))  = Trans (a,c, Thm ([p,q], Cls.trancl_rtrancl_trancl))   
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   206
|   makeStep (RTrans (a,_,p), RTrans(_,c,q))  = RTrans (a,c, Thm ([p,q], Cls.rtrancl_trans));
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   207
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   208
(* ******************************************************************* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   209
(*                                                                     *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   210
(* transPath (Clslist, Cls): (rel  list * rel) -> rel                  *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   211
(*                                                                     *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   212
(* If a path represented by a list of elements of type rel is found,   *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   213
(* this needs to be contracted to a single element of type rel.        *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   214
(* Prior to each transitivity step it is checked whether the step is   *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   215
(* valid.                                                              *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   216
(*                                                                     *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   217
(* ******************************************************************* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   218
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   219
fun transPath ([],acc) = acc
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   220
|   transPath (x::xs,acc) = transPath (xs, makeStep(acc,x))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   221
      
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   222
(* ********************************************************************* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   223
(* Graph functions                                                       *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   224
(* ********************************************************************* *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   225
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   226
(* *********************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   227
(* Functions for constructing graphs                           *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   228
(* *********************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   229
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   230
fun addEdge (v,d,[]) = [(v,d)]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   231
|   addEdge (v,d,((u,dl)::el)) = if v aconv u then ((v,d@dl)::el)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   232
    else (u,dl):: (addEdge(v,d,el));
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   233
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   234
(* ********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   235
(*                                                                        *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   236
(* mkGraph constructs from a list of objects of type rel  a graph g       *)
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   237
(* and a list of all edges with label r+.                                 *)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   238
(*                                                                        *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   239
(* ********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   240
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   241
fun mkGraph [] = ([],[])
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   242
|   mkGraph ys =  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   243
 let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   244
  fun buildGraph ([],g,zs) = (g,zs)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   245
  |   buildGraph (x::xs, g, zs) = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   246
        case x of (Trans (_,_,_)) => 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   247
	       buildGraph (xs, addEdge((upper x), [],(addEdge ((lower x),[((upper x),x)],g))), x::zs) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   248
	| _ => buildGraph (xs, addEdge((upper x), [],(addEdge ((lower x),[((upper x),x)],g))), zs)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   249
in buildGraph (ys, [], []) end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   250
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   251
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   252
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   253
(* adjacent g u : (''a * 'b list ) list -> ''a -> 'b list                  *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   254
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   255
(* List of successors of u in graph g                                      *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   256
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   257
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   258
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   259
fun adjacent eq_comp ((v,adj)::el) u = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   260
    if eq_comp (u, v) then adj else adjacent eq_comp el u
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   261
|   adjacent _  []  _ = []  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   262
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   263
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   264
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   265
(* dfs eq_comp g u v:                                                      *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   266
(* ('a * 'a -> bool) -> ('a  *( 'a * rel) list) list ->                    *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   267
(* 'a -> 'a -> (bool * ('a * rel) list)                                    *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   268
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   269
(* Depth first search of v from u.                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   270
(* Returns (true, path(u, v)) if successful, otherwise (false, []).        *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   271
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   272
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   273
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   274
fun dfs eq_comp g u v = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   275
 let 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   276
    val pred = ref nil;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   277
    val visited = ref nil;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   278
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   279
    fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   280
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   281
    fun dfs_visit u' = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   282
    let val _ = visited := u' :: (!visited)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   283
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   284
    fun update (x,l) = let val _ = pred := (x,l) ::(!pred) in () end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   285
    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   286
    in if been_visited v then () 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   287
    else (app (fn (v',l) => if been_visited v' then () else (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   288
       update (v',l); 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   289
       dfs_visit v'; ()) )) (adjacent eq_comp g u')
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   290
     end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   291
  in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   292
    dfs_visit u; 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   293
    if (been_visited v) then (true, (!pred)) else (false , [])   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   294
  end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   295
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   296
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   297
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   298
(* transpose g:                                                            *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   299
(* (''a * ''a list) list -> (''a * ''a list) list                          *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   300
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   301
(* Computes transposed graph g' from g                                     *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   302
(* by reversing all edges u -> v to v -> u                                 *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   303
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   304
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   305
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   306
fun transpose eq_comp g =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   307
  let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   308
   (* Compute list of reversed edges for each adjacency list *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   309
   fun flip (u,(v,l)::el) = (v,(u,l)) :: flip (u,el)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   310
     | flip (_,nil) = nil
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   311
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   312
   (* Compute adjacency list for node u from the list of edges
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   313
      and return a likewise reduced list of edges.  The list of edges
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   314
      is searches for edges starting from u, and these edges are removed. *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   315
   fun gather (u,(v,w)::el) =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   316
    let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   317
     val (adj,edges) = gather (u,el)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   318
    in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   319
     if eq_comp (u, v) then (w::adj,edges)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   320
     else (adj,(v,w)::edges)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   321
    end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   322
   | gather (_,nil) = (nil,nil)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   323
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   324
   (* For every node in the input graph, call gather to find all reachable
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   325
      nodes in the list of edges *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   326
   fun assemble ((u,_)::el) edges =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   327
       let val (adj,edges) = gather (u,edges)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   328
       in (u,adj) :: assemble el edges
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   329
       end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   330
     | assemble nil _ = nil
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   331
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   332
   (* Compute, for each adjacency list, the list with reversed edges,
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   333
      and concatenate these lists. *)
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   334
   val flipped = foldr (op @) nil (map flip g)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   335
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   336
 in assemble g flipped end    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   337
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   338
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   339
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   340
(* dfs_reachable eq_comp g u:                                              *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   341
(* (int * int list) list -> int -> int list                                *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   342
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   343
(* Computes list of all nodes reachable from u in g.                       *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   344
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   345
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   346
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   347
fun dfs_reachable eq_comp g u = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   348
 let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   349
  (* List of vertices which have been visited. *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   350
  val visited  = ref nil;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   351
  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   352
  fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   353
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   354
  fun dfs_visit g u  =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   355
      let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   356
   val _ = visited := u :: !visited
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   357
   val descendents =
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   358
       foldr (fn ((v,l),ds) => if been_visited v then ds
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   359
            else v :: dfs_visit g v @ ds)
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   360
        nil (adjacent eq_comp g u)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   361
   in  descendents end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   362
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   363
 in u :: dfs_visit g u end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   364
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   365
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   366
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   367
(* dfs_term_reachable g u:                                                  *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   368
(* (term * term list) list -> term -> term list                            *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   369
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   370
(* Computes list of all nodes reachable from u in g.                       *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   371
(*                                                                         *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   372
(* *********************************************************************** *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   373
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   374
fun dfs_term_reachable g u = dfs_reachable (op aconv) g u;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   375
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   376
(* ************************************************************************ *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   377
(*                                                                          *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   378
(* findPath x y g: Term.term -> Term.term ->                                *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   379
(*                  (Term.term * (Term.term * rel list) list) ->            *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   380
(*                  (bool, rel list)                                        *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   381
(*                                                                          *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   382
(*  Searches a path from vertex x to vertex y in Graph g, returns true and  *)
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   383
(*  the list of edges if path is found, otherwise false and nil.            *)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   384
(*                                                                          *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   385
(* ************************************************************************ *) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   386
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   387
fun findPath x y g = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   388
  let 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   389
   val (found, tmp) =  dfs (op aconv) g x y ;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   390
   val pred = map snd tmp;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   391
	 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   392
   fun path x y  =
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   393
    let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   394
	 (* find predecessor u of node v and the edge u -> v *)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   395
		
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   396
      fun lookup v [] = raise Cannot
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   397
      |   lookup v (e::es) = if (upper e) aconv v then e else lookup v es;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   398
		
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   399
      (* traverse path backwards and return list of visited edges *)   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   400
      fun rev_path v = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   401
	let val l = lookup v pred
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   402
	    val u = lower l;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   403
	in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   404
	  if u aconv x then [l] else (rev_path u) @ [l] 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   405
	end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   406
       
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   407
    in rev_path y end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   408
		
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   409
   in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   410
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   411
     
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   412
      if found then ( (found, (path x y) )) else (found,[])
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   413
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   414
     
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   415
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   416
   end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   417
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   418
(* ************************************************************************ *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   419
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   420
(* findRtranclProof g tranclEdges subgoal:                                  *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   421
(* (Term.term * (Term.term * rel list) list) -> rel -> proof list           *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   422
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   423
(* Searches in graph g a proof for subgoal.                                 *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   424
(*                                                                          *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 15078
diff changeset
   425
(* ************************************************************************ *)
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   426
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   427
fun findRtranclProof g tranclEdges subgoal = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   428
   case subgoal of (RTrans (x,y,_)) => if x aconv y then [Thm ([], Cls.rtrancl_refl)] else (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   429
     let val (found, path) = findPath (lower subgoal) (upper subgoal) g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   430
     in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   431
       if found then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   432
          let val path' = (transPath (tl path, hd path))
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   433
	  in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   434
	   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   435
	    case path' of (Trans (_,_,p)) => [Thm ([p], Cls.trancl_into_rtrancl )] 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   436
	    | _ => [getprf path']
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   437
	   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   438
	  end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   439
       )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   440
       else raise Cannot
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   441
     end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   442
   )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   443
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   444
| (Trans (x,y,_)) => (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   445
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   446
  let
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   447
   val Vx = dfs_term_reachable g x;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   448
   val g' = transpose (op aconv) g;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   449
   val Vy = dfs_term_reachable g' y;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   450
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   451
   fun processTranclEdges [] = raise Cannot
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   452
   |   processTranclEdges (e::es) = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   453
          if (upper e) mem Vx andalso (lower e) mem Vx
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   454
	  andalso (upper e) mem Vy andalso (lower e) mem Vy
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   455
	  then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   456
	      
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   457
	   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   458
	    if (lower e) aconv x then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   459
	      if (upper e) aconv y then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   460
	          [(getprf e)] 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   461
	      )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   462
	      else (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   463
	          let 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   464
		    val (found,path) = findPath (upper e) y g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   465
		  in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   466
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   467
		   if found then ( 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   468
		       [getprf (transPath (path, e))]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   469
		      ) else processTranclEdges es
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   470
		  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   471
		  end 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   472
	      )   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   473
	    )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   474
	    else if (upper e) aconv y then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   475
	       let val (xufound,xupath) = findPath x (lower e) g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   476
	       in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   477
	       
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   478
	          if xufound then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   479
		  	    
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   480
		    let val xuRTranclEdge = transPath (tl xupath, hd xupath)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   481
			    val xyTranclEdge = makeStep(xuRTranclEdge,e)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   482
				
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   483
				in [getprf xyTranclEdge] end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   484
				
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   485
	         ) else processTranclEdges es
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   486
	       
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   487
	       end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   488
	    )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   489
	    else ( 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   490
	   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   491
	        let val (xufound,xupath) = findPath x (lower e) g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   492
		    val (vyfound,vypath) = findPath (upper e) y g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   493
		 in 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   494
		    if xufound then (
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   495
		         if vyfound then ( 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   496
			    let val xuRTranclEdge = transPath (tl xupath, hd xupath)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   497
			        val vyRTranclEdge = transPath (tl vypath, hd vypath)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   498
				val xyTranclEdge = makeStep (makeStep(xuRTranclEdge,e),vyRTranclEdge)
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   499
				
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   500
				in [getprf xyTranclEdge] end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   501
				
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   502
			 ) else processTranclEdges es
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   503
		    ) 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   504
		    else processTranclEdges es
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   505
		 end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   506
	    )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   507
	  )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   508
	  else processTranclEdges es;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   509
   in processTranclEdges tranclEdges end )
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   510
| _ => raise Cannot
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   511
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   512
   
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   513
fun solveTrancl (asms, concl) = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   514
 let val (g,_) = mkGraph asms
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   515
 in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   516
  let val (_, subgoal, _) = mkconcl_trancl concl
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   517
      val (found, path) = findPath (lower subgoal) (upper subgoal) g
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   518
  in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   519
    if found then  [getprf (transPath (tl path, hd path))]
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   520
    else raise Cannot 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   521
  end
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   522
 end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   523
  
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   524
fun solveRtrancl (asms, concl) = 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   525
 let val (g,tranclEdges) = mkGraph asms
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   526
     val (_, subgoal, _) = mkconcl_rtrancl concl
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   527
in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   528
  findRtranclProof g tranclEdges subgoal
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   529
end;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   530
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   531
   
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   532
val trancl_tac =   SUBGOAL (fn (A, n) => fn st =>
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   533
 let
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   534
  val thy = theory_of_thm st;
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   535
  val Hs = Logic.strip_assums_hyp A;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   536
  val C = Logic.strip_assums_concl A;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   537
  val (rel,subgoals, prf) = mkconcl_trancl C;
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   538
  val prems = List.concat (ListPair.map (mkasm_trancl rel) (Hs, 0 upto (length Hs - 1)))
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   539
  val prfs = solveTrancl (prems, C);
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   540
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   541
 in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   542
  METAHYPS (fn asms =>
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   543
    let val thms = map (prove thy rel asms) prfs
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   544
    in rtac (prove thy rel thms prf) 1 end) n st
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   545
 end
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   546
handle  Cannot  => no_tac st);
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   547
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   548
 
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   549
 
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   550
val rtrancl_tac =   SUBGOAL (fn (A, n) => fn st =>
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   551
 let
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   552
  val thy = theory_of_thm st;
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   553
  val Hs = Logic.strip_assums_hyp A;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   554
  val C = Logic.strip_assums_concl A;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   555
  val (rel,subgoals, prf) = mkconcl_rtrancl C;
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   556
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   557
  val prems = List.concat (ListPair.map (mkasm_rtrancl rel) (Hs, 0 upto (length Hs - 1)))
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   558
  val prfs = solveRtrancl (prems, C);
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   559
 in
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   560
  METAHYPS (fn asms =>
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   561
    let val thms = map (prove thy rel asms) prfs
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   562
    in rtac (prove thy rel thms prf) 1 end) n st
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   563
 end
22257
159bfab776e2 "prove" function now instantiates relation variable in order
berghofe
parents: 15574
diff changeset
   564
handle  Cannot  => no_tac st);
15076
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   565
4b3d280ef06a New prover for transitive and reflexive-transitive closure of relations.
ballarin
parents:
diff changeset
   566
end;