src/Provers/order.ML
author ballarin
Mon, 02 Aug 2004 10:16:40 +0200
changeset 15098 0726e7b15618
parent 14445 4392cb82018b
child 15103 79846e8792eb
permissions -rw-r--r--
Documentation added/improved.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     1
(*
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     2
  Title:	Transitivity reasoner for partial and linear orders
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     3
  Id:		$Id$
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     4
  Author:	Oliver Kutter
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     5
  Copyright:	TU Muenchen
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     6
*)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     7
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
     8
(* TODO: reduce number of input thms *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
     9
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    10
(*
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    11
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    12
The packages provides tactics partial_tac and linear_tac that use all
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    13
premises of the form
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    14
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    15
  t = u, t ~= u, t < u, t <= u, ~(t < u) and ~(t <= u)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    16
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    17
to
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    18
1. either derive a contradiction,
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    19
   in which case the conclusion can be any term,
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    20
2. or prove the conclusion, which must be of the same form as the
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    21
   premises (excluding ~(t < u) and ~(t <= u) for partial orders)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    22
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    23
The package is implemented as an ML functor and thus not limited to the
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    24
relation <= and friends.  It can be instantiated to any partial and/or
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    25
linear order --- for example, the divisibility relation "dvd".  In
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    26
order to instantiate the package for a partial order only, supply
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    27
dummy theorems to the rules for linear orders, and don't use
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    28
linear_tac!
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    29
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    30
*)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    31
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    32
signature LESS_ARITH =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    33
sig
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    34
  (* Theorems for partial orders *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    35
  val less_reflE: thm  (* x < x ==> P *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    36
  val le_refl: thm  (* x <= x *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    37
  val less_imp_le: thm (* x < y ==> x <= y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    38
  val eqI: thm (* [| x <= y; y <= x |] ==> x = y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    39
  val eqD1: thm (* x = y ==> x <= y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    40
  val eqD2: thm (* x = y ==> y <= x *)
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    41
  val less_trans: thm  (* [| x < y; y < z |] ==> x < z *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    42
  val less_le_trans: thm  (* [| x < y; y <= z |] ==> x < z *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    43
  val le_less_trans: thm  (* [| x <= y; y < z |] ==> x < z *)
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    44
  val le_trans: thm  (* [| x <= y; y <= z |] ==> x <= z *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    45
  val le_neq_trans : thm (* [| x <= y ; x ~= y |] ==> x < y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    46
  val neq_le_trans : thm (* [| x ~= y ; x <= y |] ==> x < y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    47
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    48
  (* Additional theorems for linear orders *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    49
  val not_lessD: thm (* ~(x < y) ==> y <= x *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    50
  val not_leD: thm (* ~(x <= y) ==> y < x *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    51
  val not_lessI: thm (* y <= x  ==> ~(x < y) *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    52
  val not_leI: thm (* y < x  ==> ~(x <= y) *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    53
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    54
  (* Additional theorems for subgoals of form x ~= y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    55
  val less_imp_neq : thm (* x < y ==> x ~= y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    56
  val eq_neq_eq_imp_neq : thm (* [| x = u ; u ~= v ; v = z|] ==> x ~= z *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    57
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    58
  (* Analysis of premises and conclusion *)
15098
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    59
  (* decomp_part is for partial_tac, decomp_lin is for linear_tac;
0726e7b15618 Documentation added/improved.
ballarin
parents: 14445
diff changeset
    60
     decomp_x (`x Rel y') should yield (x, Rel, y)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    61
       where Rel is one of "<", "<=", "~<", "~<=", "=" and "~=",
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    62
       other relation symbols cause an error message *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    63
  val decomp_part: Sign.sg -> term -> (term * string * term) option
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    64
  val decomp_lin: Sign.sg -> term -> (term * string * term) option
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    65
end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    66
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    67
signature TRANS_TAC  =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    68
sig
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    69
  val partial_tac: int -> tactic
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    70
  val linear_tac:  int -> tactic
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    71
end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    72
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    73
functor Trans_Tac_Fun (Less: LESS_ARITH): TRANS_TAC =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    74
struct
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    75
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    76
(* Extract subgoal with signature *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    77
fun SUBGOAL goalfun i st =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    78
  goalfun (List.nth(prems_of st, i-1),  i, sign_of_thm st) st
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    79
                             handle Subscript => Seq.empty;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    80
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    81
(* Internal datatype for the proof *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    82
datatype proof
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    83
  = Asm of int 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    84
  | Thm of proof list * thm; 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    85
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    86
exception Cannot;
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
    87
 (* Internal exception, raised if conclusion cannot be derived from
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    88
     assumptions. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    89
exception Contr of proof;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    90
  (* Internal exception, raised if contradiction ( x < x ) was derived *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    91
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    92
fun prove asms = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    93
  let fun pr (Asm i) = nth_elem (i, asms)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    94
  |       pr (Thm (prfs, thm)) = (map pr prfs) MRS thm
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    95
  in pr end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    96
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    97
(* Internal datatype for inequalities *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    98
datatype less 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
    99
   = Less  of term * term * proof 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   100
   | Le    of term * term * proof
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   101
   | NotEq of term * term * proof; 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   102
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   103
(* Misc functions for datatype less *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   104
fun lower (Less (x, _, _)) = x
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   105
  | lower (Le (x, _, _)) = x
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   106
  | lower (NotEq (x,_,_)) = x;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   107
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   108
fun upper (Less (_, y, _)) = y
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   109
  | upper (Le (_, y, _)) = y
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   110
  | upper (NotEq (_,y,_)) = y;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   111
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   112
fun getprf   (Less (_, _, p)) = p
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   113
|   getprf   (Le   (_, _, p)) = p
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   114
|   getprf   (NotEq (_,_, p)) = p;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   115
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   116
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   117
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   118
(* mkasm_partial sign (t, n) : Sign.sg -> (Term.term * int) -> less         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   119
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   120
(* Tuple (t, n) (t an assumption, n its index in the assumptions) is        *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   121
(* translated to an element of type less.                                   *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   122
(* Partial orders only.                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   123
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   124
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   125
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   126
fun mkasm_partial sign (t, n) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   127
  case Less.decomp_part sign t of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   128
    Some (x, rel, y) => (case rel of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   129
      "<"   => if (x aconv y) then raise Contr (Thm ([Asm n], Less.less_reflE)) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   130
               else [Less (x, y, Asm n)]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   131
    | "~<"  => []
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   132
    | "<="  => [Le (x, y, Asm n)]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   133
    | "~<=" => [] 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   134
    | "="   => [Le (x, y, Thm ([Asm n], Less.eqD1)),
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   135
                Le (y, x, Thm ([Asm n], Less.eqD2))]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   136
    | "~="  => if (x aconv y) then 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   137
                  raise Contr (Thm ([(Thm ([(Thm ([], Less.le_refl)) ,(Asm n)], Less.le_neq_trans))], Less.less_reflE))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   138
               else [ NotEq (x, y, Asm n),
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   139
                      NotEq (y, x,Thm ( [Asm n], thm "not_sym"))] 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   140
    | _     => error ("partial_tac: unknown relation symbol ``" ^ rel ^
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   141
                 "''returned by decomp_part."))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   142
  | None => [];
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   143
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   144
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   145
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   146
(* mkasm_linear sign (t, n) : Sign.sg -> (Term.term * int) -> less          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   147
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   148
(* Tuple (t, n) (t an assumption, n its index in the assumptions) is        *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   149
(* translated to an element of type less.                                   *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   150
(* Linear orders only.                                                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   151
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   152
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   153
 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   154
fun mkasm_linear sign (t, n) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   155
  case Less.decomp_lin sign t of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   156
    Some (x, rel, y) => (case rel of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   157
      "<"   => if (x aconv y) then raise Contr (Thm ([Asm n], Less.less_reflE)) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   158
               else [Less (x, y, Asm n)]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   159
    | "~<"  => [Le (y, x, Thm ([Asm n], Less.not_lessD))]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   160
    | "<="  => [Le (x, y, Asm n)]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   161
    | "~<=" => if (x aconv y) then 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   162
                  raise (Contr (Thm ([Thm ([Asm n], Less.not_leD)], Less.less_reflE))) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   163
               else [Less (y, x, Thm ([Asm n], Less.not_leD))] 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   164
    | "="   => [Le (x, y, Thm ([Asm n], Less.eqD1)),
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   165
                Le (y, x, Thm ([Asm n], Less.eqD2))]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   166
    | "~="  => if (x aconv y) then 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   167
                  raise Contr (Thm ([(Thm ([(Thm ([], Less.le_refl)) ,(Asm n)], Less.le_neq_trans))], Less.less_reflE))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   168
               else [ NotEq (x, y, Asm n),
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   169
                      NotEq (y, x,Thm ( [Asm n], thm "not_sym"))] 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   170
    | _     => error ("linear_tac: unknown relation symbol ``" ^ rel ^
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   171
                 "''returned by decomp_lin."))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   172
  | None => [];
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   173
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   174
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   175
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   176
(* mkconcl_partial sign t : Sign.sg -> Term.term -> less                    *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   177
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   178
(* Translates conclusion t to an element of type less.                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   179
(* Partial orders only.                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   180
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   181
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   182
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   183
fun mkconcl_partial sign t =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   184
  case Less.decomp_part sign t of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   185
    Some (x, rel, y) => (case rel of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   186
      "<"   => ([Less (x, y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   187
    | "<="  => ([Le (x, y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   188
    | "="   => ([Le (x, y, Asm ~1), Le (y, x, Asm ~1)],
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   189
                 Thm ([Asm 0, Asm 1], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   190
    | "~="  => ([NotEq (x,y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   191
    | _  => raise Cannot)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   192
  | None => raise Cannot;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   193
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   194
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   195
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   196
(* mkconcl_linear sign t : Sign.sg -> Term.term -> less                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   197
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   198
(* Translates conclusion t to an element of type less.                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   199
(* Linear orders only.                                                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   200
(*                                                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   201
(* ************************************************************************ *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   202
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   203
fun mkconcl_linear sign t =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   204
  case Less.decomp_lin sign t of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   205
    Some (x, rel, y) => (case rel of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   206
      "<"   => ([Less (x, y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   207
    | "~<"  => ([Le (y, x, Asm ~1)], Thm ([Asm 0], Less.not_lessI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   208
    | "<="  => ([Le (x, y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   209
    | "~<=" => ([Less (y, x, Asm ~1)], Thm ([Asm 0], Less.not_leI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   210
    | "="   => ([Le (x, y, Asm ~1), Le (y, x, Asm ~1)],
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   211
                 Thm ([Asm 0, Asm 1], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   212
    | "~="  => ([NotEq (x,y, Asm ~1)], Asm 0)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   213
    | _  => raise Cannot)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   214
  | None => raise Cannot;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   215
 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   216
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   217
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   218
(* mergeLess (less1,less2):  less * less -> less                       *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   219
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   220
(* Merge to elements of type less according to the following rules     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   221
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   222
(* x <  y && y <  z ==> x < z                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   223
(* x <  y && y <= z ==> x < z                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   224
(* x <= y && y <  z ==> x < z                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   225
(* x <= y && y <= z ==> x <= z                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   226
(* x <= y && x ~= y ==> x < y                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   227
(* x ~= y && x <= y ==> x < y                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   228
(* x <  y && x ~= y ==> x < y                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   229
(* x ~= y && x <  y ==> x < y                                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   230
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   231
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   232
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   233
fun mergeLess (Less (x, _, p) , Less (_ , z, q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   234
      Less (x, z, Thm ([p,q] , Less.less_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   235
|   mergeLess (Less (x, _, p) , Le (_ , z, q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   236
      Less (x, z, Thm ([p,q] , Less.less_le_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   237
|   mergeLess (Le (x, _, p) , Less (_ , z, q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   238
      Less (x, z, Thm ([p,q] , Less.le_less_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   239
|   mergeLess (Le (x, z, p) , NotEq (x', z', q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   240
      if (x aconv x' andalso z aconv z' ) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   241
      then Less (x, z, Thm ([p,q] , Less.le_neq_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   242
      else error "linear/partial_tac: internal error le_neq_trans"
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   243
|   mergeLess (NotEq (x, z, p) , Le (x' , z', q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   244
      if (x aconv x' andalso z aconv z') 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   245
      then Less (x, z, Thm ([p,q] , Less.neq_le_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   246
      else error "linear/partial_tac: internal error neq_le_trans"
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   247
|   mergeLess (NotEq (x, z, p) , Less (x' , z', q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   248
      if (x aconv x' andalso z aconv z') 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   249
      then Less ((x' , z', q))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   250
      else error "linear/partial_tac: internal error neq_less_trans"
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   251
|   mergeLess (Less (x, z, p) , NotEq (x', z', q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   252
      if (x aconv x' andalso z aconv z') 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   253
      then Less (x, z, p)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   254
      else error "linear/partial_tac: internal error less_neq_trans"
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   255
|   mergeLess (Le (x, _, p) , Le (_ , z, q)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   256
      Le (x, z, Thm ([p,q] , Less.le_trans))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   257
|   mergeLess (_, _) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   258
      error "linear/partial_tac: internal error: undefined case";
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   259
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   260
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   261
(* ******************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   262
(* tr checks for valid transitivity step                                *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   263
(* ******************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   264
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   265
infix tr;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   266
fun (Less (_, y, _)) tr (Le (x', _, _))   = ( y aconv x' )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   267
  | (Le   (_, y, _)) tr (Less (x', _, _)) = ( y aconv x' )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   268
  | (Less (_, y, _)) tr (Less (x', _, _)) = ( y aconv x' )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   269
  | (Le (_, y, _))   tr (Le (x', _, _))   = ( y aconv x' )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   270
  | _ tr _ = false;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   271
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   272
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   273
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   274
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   275
(* transPath (Lesslist, Less): (less list * less) -> less              *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   276
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   277
(* If a path represented by a list of elements of type less is found,  *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   278
(* this needs to be contracted to a single element of type less.       *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   279
(* Prior to each transitivity step it is checked whether the step is   *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   280
(* valid.                                                              *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   281
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   282
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   283
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   284
fun transPath ([],lesss) = lesss
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   285
|   transPath (x::xs,lesss) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   286
      if lesss tr x then transPath (xs, mergeLess(lesss,x))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   287
      else error "linear/partial_tac: internal error transpath";
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   288
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   289
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   290
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   291
(* less1 subsumes less2 : less -> less -> bool                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   292
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   293
(* subsumes checks whether less1 implies less2                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   294
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   295
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   296
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   297
infix subsumes;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   298
fun (Less (x, y, _)) subsumes (Le (x', y', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   299
      (x aconv x' andalso y aconv y')
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   300
  | (Less (x, y, _)) subsumes (Less (x', y', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   301
      (x aconv x' andalso y aconv y')
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   302
  | (Le (x, y, _)) subsumes (Le (x', y', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   303
      (x aconv x' andalso y aconv y')
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   304
  | (Less (x, y, _)) subsumes (NotEq (x', y', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   305
      (x aconv x' andalso y aconv y') orelse (y aconv x' andalso x aconv y')
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   306
  | (NotEq (x, y, _)) subsumes (NotEq (x', y', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   307
      (x aconv x' andalso y aconv y') orelse (y aconv x' andalso x aconv y')
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   308
  | (Le _) subsumes (Less _) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   309
      error "linear/partial_tac: internal error: Le cannot subsume Less"
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   310
  | _ subsumes _ = false;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   311
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   312
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   313
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   314
(* triv_solv less1 : less ->  proof Library.option                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   315
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   316
(* Solves trivial goal x <= x.                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   317
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   318
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   319
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   320
fun triv_solv (Le (x, x', _)) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   321
    if x aconv x' then  Some (Thm ([], Less.le_refl)) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   322
    else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   323
|   triv_solv _ = None;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   324
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   325
(* ********************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   326
(* Graph functions                                                       *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   327
(* ********************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   328
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   329
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   330
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   331
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   332
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   333
(* General:                                                            *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   334
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   335
(* Inequalities are represented by various types of graphs.            *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   336
(*                                                                     *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   337
(* 1. (Term.term * (Term.term * less) list) list                       *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   338
(*    - Graph of this type is generated from the assumptions,          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   339
(*      it does contain information on which edge stems from which     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   340
(*      assumption.                                                    *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   341
(*    - Used to compute strongly connected components                  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   342
(*    - Used to compute component subgraphs                            *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   343
(*    - Used for component subgraphs to reconstruct paths in components*)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   344
(*                                                                     *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   345
(* 2. (int * (int * less) list ) list                                  *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   346
(*    - Graph of this type is generated from the strong components of  *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   347
(*      graph of type 1.  It consists of the strong components of      *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   348
(*      graph 1, where nodes are indices of the components.            *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   349
(*      Only edges between components are part of this graph.          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   350
(*    - Used to reconstruct paths between several components.          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   351
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   352
(* ******************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   353
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   354
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   355
(* *********************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   356
(* Functions for constructing graphs                           *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   357
(* *********************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   358
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   359
fun addEdge (v,d,[]) = [(v,d)]
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   360
|   addEdge (v,d,((u,dl)::el)) = if v aconv u then ((v,d@dl)::el)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   361
    else (u,dl):: (addEdge(v,d,el));
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   362
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   363
(* ********************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   364
(*                                                                       *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   365
(* mkGraphs constructs from a list of objects of type less a graph g,    *) 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   366
(* by taking all edges that are candidate for a <=, and a list neqE, by  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   367
(* taking all edges that are candiate for a ~=                           *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   368
(*                                                                       *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   369
(* ********************************************************************* *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   370
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   371
fun mkGraphs [] = ([],[],[])
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   372
|   mkGraphs lessList = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   373
 let
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   374
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   375
fun buildGraphs ([],leqG,neqG,neqE) = (leqG, neqG, neqE)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   376
|   buildGraphs (l::ls, leqG,neqG, neqE) = case l of 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   377
  (Less (x,y,p)) =>    
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   378
       buildGraphs (ls, addEdge (x,[(y,(Less (x, y, p)))],leqG) , 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   379
                        addEdge (x,[(y,(Less (x, y, p)))],neqG), l::neqE) 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   380
| (Le (x,y,p)) =>
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   381
      buildGraphs (ls, addEdge (x,[(y,(Le (x, y,p)))],leqG) , neqG, neqE) 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   382
| (NotEq  (x,y,p)) => 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   383
      buildGraphs (ls, leqG , addEdge (x,[(y,(NotEq (x, y, p)))],neqG), l::neqE) ;
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   384
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   385
  in buildGraphs (lessList, [], [], []) end;
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   386
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   387
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   388
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   389
(*                                                                         *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   390
(* adjacent g u : (''a * 'b list ) list -> ''a -> 'b list                  *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   391
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   392
(* List of successors of u in graph g                                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   393
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   394
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   395
 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   396
fun adjacent eq_comp ((v,adj)::el) u = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   397
    if eq_comp (u, v) then adj else adjacent eq_comp el u
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   398
|   adjacent _  []  _ = []  
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   399
  
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   400
     
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   401
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   402
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   403
(* transpose g:                                                            *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   404
(* (''a * ''a list) list -> (''a * ''a list) list                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   405
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   406
(* Computes transposed graph g' from g                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   407
(* by reversing all edges u -> v to v -> u                                 *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   408
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   409
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   410
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   411
fun transpose eq_comp g =
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   412
  let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   413
   (* Compute list of reversed edges for each adjacency list *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   414
   fun flip (u,(v,l)::el) = (v,(u,l)) :: flip (u,el)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   415
     | flip (_,nil) = nil
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   416
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   417
   (* Compute adjacency list for node u from the list of edges
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   418
      and return a likewise reduced list of edges.  The list of edges
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   419
      is searches for edges starting from u, and these edges are removed. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   420
   fun gather (u,(v,w)::el) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   421
    let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   422
     val (adj,edges) = gather (u,el)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   423
    in
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   424
     if eq_comp (u, v) then (w::adj,edges)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   425
     else (adj,(v,w)::edges)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   426
    end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   427
   | gather (_,nil) = (nil,nil)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   428
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   429
   (* For every node in the input graph, call gather to find all reachable
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   430
      nodes in the list of edges *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   431
   fun assemble ((u,_)::el) edges =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   432
       let val (adj,edges) = gather (u,edges)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   433
       in (u,adj) :: assemble el edges
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   434
       end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   435
     | assemble nil _ = nil
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   436
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   437
   (* Compute, for each adjacency list, the list with reversed edges,
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   438
      and concatenate these lists. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   439
   val flipped = foldr (op @) ((map flip g),nil)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   440
 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   441
 in assemble g flipped end    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   442
      
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   443
(* *********************************************************************** *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   444
(*                                                                         *)      
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   445
(* scc_term : (term * term list) list -> term list list                    *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   446
(*                                                                         *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   447
(* The following is based on the algorithm for finding strongly connected  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   448
(* components described in Introduction to Algorithms, by Cormon, Leiserson*)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   449
(* and Rivest, section 23.5. The input G is an adjacency list description  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   450
(* of a directed graph. The output is a list of the strongly connected     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   451
(* components (each a list of vertices).                                   *)          
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   452
(*                                                                         *)   
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   453
(*                                                                         *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   454
(* *********************************************************************** *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   455
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   456
fun scc_term G =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   457
     let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   458
  (* Ordered list of the vertices that DFS has finished with;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   459
     most recently finished goes at the head. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   460
  val finish : term list ref = ref nil
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   461
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   462
  (* List of vertices which have been visited. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   463
  val visited : term list ref = ref nil
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   464
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   465
  fun been_visited v = exists (fn w => w aconv v) (!visited)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   466
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   467
  (* Given the adjacency list rep of a graph (a list of pairs),
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   468
     return just the first element of each pair, yielding the 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   469
     vertex list. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   470
  val members = map (fn (v,_) => v)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   471
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   472
  (* Returns the nodes in the DFS tree rooted at u in g *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   473
  fun dfs_visit g u : term list =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   474
      let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   475
   val _ = visited := u :: !visited
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   476
   val descendents =
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   477
       foldr (fn ((v,l),ds) => if been_visited v then ds
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   478
            else v :: dfs_visit g v @ ds)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   479
        ((adjacent (op aconv) g u) ,nil)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   480
      in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   481
   finish := u :: !finish;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   482
   descendents
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   483
      end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   484
     in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   485
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   486
  (* DFS on the graph; apply dfs_visit to each vertex in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   487
     the graph, checking first to make sure the vertex is
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   488
     as yet unvisited. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   489
  app (fn u => if been_visited u then ()
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   490
        else (dfs_visit G u; ()))  (members G);
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   491
  visited := nil;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   492
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   493
  (* We don't reset finish because its value is used by
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   494
     foldl below, and it will never be used again (even
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   495
     though dfs_visit will continue to modify it). *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   496
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   497
  (* DFS on the transpose. The vertices returned by
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   498
     dfs_visit along with u form a connected component. We
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   499
     collect all the connected components together in a
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   500
     list, which is what is returned. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   501
  foldl (fn (comps,u) =>  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   502
      if been_visited u then comps
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   503
      else ((u :: dfs_visit (transpose (op aconv) G) u) :: comps))  (nil,(!finish))
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   504
end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   505
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   506
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   507
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   508
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   509
(* dfs_int_reachable g u:                                                  *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   510
(* (int * int list) list -> int -> int list                                *) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   511
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   512
(* Computes list of all nodes reachable from u in g.                       *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   513
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   514
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   515
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   516
fun dfs_int_reachable g u = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   517
 let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   518
  (* List of vertices which have been visited. *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   519
  val visited : int list ref = ref nil
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   520
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   521
  fun been_visited v = exists (fn w => w = v) (!visited)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   522
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   523
  fun dfs_visit g u : int list =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   524
      let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   525
   val _ = visited := u :: !visited
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   526
   val descendents =
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   527
       foldr (fn ((v,l),ds) => if been_visited v then ds
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   528
            else v :: dfs_visit g v @ ds)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   529
        ( ((adjacent (op =) g u)) ,nil)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   530
   in  descendents end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   531
 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   532
 in u :: dfs_visit g u end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   533
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   534
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   535
fun indexComps components = 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   536
    ListPair.map (fn (a,b) => (a,b)) (0 upto (length components -1), components);
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   537
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   538
fun indexNodes IndexComp = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   539
    flat (map (fn (index, comp) => (map (fn v => (v,index)) comp)) IndexComp);
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   540
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   541
fun getIndex v [] = ~1
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   542
|   getIndex v ((v',k)::vs) = if v aconv v' then k else getIndex v vs; 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   543
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   544
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   545
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   546
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   547
(*                                                                         *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   548
(* dfs eq_comp g u v:                                                       *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   549
(* ('a * 'a -> bool) -> ('a  *( 'a * less) list) list ->                   *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   550
(* 'a -> 'a -> (bool * ('a * less) list)                                   *) 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   551
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   552
(* Depth first search of v from u.                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   553
(* Returns (true, path(u, v)) if successful, otherwise (false, []).        *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   554
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   555
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   556
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   557
fun dfs eq_comp g u v = 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   558
 let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   559
    val pred = ref nil;
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   560
    val visited = ref nil;
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   561
    
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   562
    fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   563
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   564
    fun dfs_visit u' = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   565
    let val _ = visited := u' :: (!visited)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   566
    
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   567
    fun update (x,l) = let val _ = pred := (x,l) ::(!pred) in () end;
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   568
    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   569
    in if been_visited v then () 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   570
    else (app (fn (v',l) => if been_visited v' then () else (
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   571
       update (v',l); 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   572
       dfs_visit v'; ()) )) (adjacent eq_comp g u')
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   573
     end
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   574
  in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   575
    dfs_visit u; 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   576
    if (been_visited v) then (true, (!pred)) else (false , [])   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   577
  end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   578
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   579
  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   580
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   581
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   582
(* completeTermPath u v g:                                                 *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   583
(* Term.term -> Term.term -> (Term.term * (Term.term * less) list) list    *) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   584
(* -> less list                                                            *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   585
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   586
(* Complete the path from u to v in graph g.  Path search is performed     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   587
(* with dfs_term g u v.  This yields for each node v' its predecessor u'   *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   588
(* and the edge u' -> v'.  Allows traversing graph backwards from v and    *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   589
(* finding the path u -> v.                                                *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   590
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   591
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   592
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   593
  
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   594
fun completeTermPath u v g  = 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   595
  let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   596
   val (found, tmp) =  dfs (op aconv) g u v ;
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   597
   val pred = map snd tmp;
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   598
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   599
   fun path x y  =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   600
      let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   601
 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   602
      (* find predecessor u of node v and the edge u -> v *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   603
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   604
      fun lookup v [] = raise Cannot
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   605
      |   lookup v (e::es) = if (upper e) aconv v then e else lookup v es;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   606
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   607
      (* traverse path backwards and return list of visited edges *)   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   608
      fun rev_path v = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   609
       let val l = lookup v pred
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   610
           val u = lower l;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   611
       in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   612
        if u aconv x then [l]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   613
        else (rev_path u) @ [l] 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   614
       end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   615
     in rev_path y end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   616
       
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   617
  in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   618
  if found then (if u aconv v then [(Le (u, v, (Thm ([], Less.le_refl))))]
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   619
  else path u v ) else raise Cannot
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   620
end;  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   621
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   622
      
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   623
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   624
(*                                                                         *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   625
(* findProof (sccGraph, neqE, ntc, sccSubgraphs) subgoal:                  *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   626
(*                                                                         *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   627
(* (int * (int * less) list) list * less list *  (Term.term * int) list    *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   628
(* * ((term * (term * less) list) list) list -> Less -> proof              *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   629
(*                                                                         *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   630
(* findProof constructs from graphs (sccGraph, sccSubgraphs) and neqE a    *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   631
(* proof for subgoal.  Raises exception Cannot if this is not possible.    *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   632
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   633
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   634
     
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   635
fun findProof (sccGraph, neqE, ntc, sccSubgraphs) subgoal =
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   636
let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   637
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   638
 (* complete path x y from component graph *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   639
 fun completeComponentPath x y predlist = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   640
   let         
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   641
	  val xi = getIndex x ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   642
	  val yi = getIndex y ntc 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   643
	  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   644
	  fun lookup k [] =  raise Cannot
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   645
	  |   lookup k ((h,l)::us) = if k = h then l else lookup k us;	  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   646
	  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   647
	  fun rev_completeComponentPath y' = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   648
	   let val edge = lookup (getIndex y' ntc) predlist
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   649
	       val u = lower edge
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   650
	       val v = upper edge
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   651
	   in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   652
             if (getIndex u ntc) = xi then 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   653
	       (completeTermPath x u (nth_elem(xi, sccSubgraphs)) )@[edge]
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   654
	       @(completeTermPath v y' (nth_elem((getIndex y' ntc),sccSubgraphs)) )
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   655
	     else (rev_completeComponentPath u)@[edge]
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   656
	          @(completeTermPath v y' (nth_elem((getIndex y' ntc),sccSubgraphs)) )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   657
           end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   658
   in  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   659
      if x aconv y then 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   660
        [(Le (x, y, (Thm ([], Less.le_refl))))]
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   661
      else ( if xi = yi then completeTermPath x y (nth_elem(xi, sccSubgraphs))
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   662
             else rev_completeComponentPath y )  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   663
   end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   664
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   665
(* ******************************************************************* *) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   666
(* findLess e x y xi yi xreachable yreachable                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   667
(*                                                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   668
(* Find a path from x through e to y, of weight <                      *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   669
(* ******************************************************************* *) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   670
 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   671
 fun findLess e x y xi yi xreachable yreachable = 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   672
  let val u = lower e 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   673
      val v = upper e
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   674
      val ui = getIndex u ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   675
      val vi = getIndex v ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   676
            
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   677
  in 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   678
      if ui mem xreachable andalso vi mem xreachable andalso 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   679
         ui mem yreachable andalso vi mem yreachable then (
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   680
       
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   681
  (case e of (Less (_, _, _)) =>  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   682
       let
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   683
        val (xufound, xupred) =  dfs (op =) sccGraph xi (getIndex u ntc)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   684
	    in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   685
	     if xufound then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   686
	      let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   687
	       val (vyfound, vypred) =  dfs (op =) sccGraph (getIndex v ntc) yi  
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   688
	      in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   689
	       if vyfound then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   690
	        let 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   691
	         val xypath = (completeComponentPath x u xupred)@[e]@(completeComponentPath v y vypred)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   692
	         val xyLesss = transPath (tl xypath, hd xypath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   693
	        in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   694
		 if xyLesss subsumes subgoal then Some (getprf xyLesss) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   695
                 else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   696
	       end)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   697
	       else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   698
	      end)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   699
	     else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   700
	    end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   701
       |  _   => 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   702
         let val (uvfound, uvpred) =  dfs (op =) sccGraph (getIndex u ntc) (getIndex v ntc) 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   703
             in 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   704
	      if uvfound then (
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   705
	       let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   706
	        val (xufound, xupred) = dfs (op =) sccGraph xi (getIndex u ntc)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   707
	       in
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   708
		if xufound then (
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   709
		 let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   710
		  val (vyfound, vypred) =  dfs (op =) sccGraph (getIndex v ntc) yi
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   711
		 in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   712
		  if vyfound then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   713
		   let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   714
		    val uvpath = completeComponentPath u v uvpred
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   715
		    val uvLesss = mergeLess ( transPath (tl uvpath, hd uvpath), e)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   716
		    val xypath = (completeComponentPath  x u xupred)@[uvLesss]@(completeComponentPath v y vypred)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   717
		    val xyLesss = transPath (tl xypath, hd xypath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   718
		   in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   719
		    if xyLesss subsumes subgoal then Some (getprf xyLesss)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   720
                    else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   721
		   end )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   722
		  else None   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   723
	         end)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   724
		else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   725
	       end ) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   726
	      else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   727
	     end )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   728
    ) else None
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   729
end;  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   730
   
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   731
         
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   732
in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   733
  (* looking for x <= y: any path from x to y is sufficient *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   734
  case subgoal of (Le (x, y, _)) => (
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   735
  if sccGraph = [] then raise Cannot else ( 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   736
   let 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   737
    val xi = getIndex x ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   738
    val yi = getIndex y ntc
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   739
    (* searches in sccGraph a path from xi to yi *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   740
    val (found, pred) = dfs (op =) sccGraph xi yi
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   741
   in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   742
    if found then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   743
       let val xypath = completeComponentPath x y pred 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   744
           val xyLesss = transPath (tl xypath, hd xypath) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   745
       in  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   746
	  (case xyLesss of
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   747
	    (Less (_, _, q)) => if xyLesss subsumes subgoal then (Thm ([q], Less.less_imp_le))  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   748
				else raise Cannot
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   749
	     | _   => if xyLesss subsumes subgoal then (getprf xyLesss) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   750
	              else raise Cannot)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   751
       end )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   752
     else raise Cannot 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   753
   end 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   754
    )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   755
   )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   756
 (* looking for x < y: particular path required, which is not necessarily
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   757
    found by normal dfs *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   758
 |   (Less (x, y, _)) => (
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   759
  if sccGraph = [] then raise Cannot else (
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   760
   let 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   761
    val xi = getIndex x ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   762
    val yi = getIndex y ntc
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   763
    val sccGraph_transpose = transpose (op =) sccGraph
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   764
    (* all components that can be reached from component xi  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   765
    val xreachable = dfs_int_reachable sccGraph xi
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   766
    (* all comonents reachable from y in the transposed graph sccGraph' *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   767
    val yreachable = dfs_int_reachable sccGraph_transpose yi
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   768
    (* for all edges u ~= v or u < v check if they are part of path x < y *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   769
    fun processNeqEdges [] = raise Cannot 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   770
    |   processNeqEdges (e::es) = 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   771
      case  (findLess e x y xi yi xreachable yreachable) of (Some prf) => prf  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   772
      | _ => processNeqEdges es
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   773
        
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   774
    in 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   775
       processNeqEdges neqE 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   776
    end
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   777
  )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   778
 )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   779
| (NotEq (x, y, _)) => (
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   780
  (* if there aren't any edges that are candidate for a ~= raise Cannot *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   781
  if neqE = [] then raise Cannot
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   782
  (* if there aren't any edges that are candidate for <= then just search a edge in neqE that implies the subgoal *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   783
  else if sccSubgraphs = [] then (
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   784
     (case (Library.find_first (fn fact => fact subsumes subgoal) neqE, subgoal) of
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   785
       ( Some (NotEq (x, y, p)), NotEq (x', y', _)) =>
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   786
          if  (x aconv x' andalso y aconv y') then p 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   787
	  else Thm ([p], thm "not_sym")
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   788
     | ( Some (Less (x, y, p)), NotEq (x', y', _)) => 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   789
          if x aconv x' andalso y aconv y' then (Thm ([p], Less.less_imp_neq))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   790
          else (Thm ([(Thm ([p], Less.less_imp_neq))], thm "not_sym"))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   791
     | _ => raise Cannot) 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   792
   ) else (
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   793
   
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   794
   let  val xi = getIndex x ntc 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   795
        val yi = getIndex y ntc
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   796
	val sccGraph_transpose = transpose (op =) sccGraph
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   797
        val xreachable = dfs_int_reachable sccGraph xi
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   798
	val yreachable = dfs_int_reachable sccGraph_transpose yi
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   799
	
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   800
	fun processNeqEdges [] = raise Cannot  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   801
  	|   processNeqEdges (e::es) = (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   802
	    let val u = lower e 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   803
	        val v = upper e
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   804
		val ui = getIndex u ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   805
		val vi = getIndex v ntc
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   806
		
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   807
	    in  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   808
	        (* if x ~= y follows from edge e *)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   809
	    	if e subsumes subgoal then (
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   810
		     case e of (Less (u, v, q)) => (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   811
		       if u aconv x andalso v aconv y then (Thm ([q], Less.less_imp_neq))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   812
		       else (Thm ([(Thm ([q], Less.less_imp_neq))], thm "not_sym"))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   813
		     )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   814
		     |    (NotEq (u,v, q)) => (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   815
		       if u aconv x andalso v aconv y then q
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   816
		       else (Thm ([q],  thm "not_sym"))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   817
		     )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   818
		 )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   819
                (* if SCC_x is linked to SCC_y via edge e *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   820
		 else if ui = xi andalso vi = yi then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   821
                   case e of (Less (_, _,_)) => (
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   822
		        let val xypath = (completeTermPath x u (nth_elem(ui, sccSubgraphs)) ) @ [e] @ (completeTermPath v y (nth_elem(vi, sccSubgraphs)) )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   823
			    val xyLesss = transPath (tl xypath, hd xypath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   824
			in  (Thm ([getprf xyLesss], Less.less_imp_neq)) end)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   825
		   | _ => (   
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   826
		        let 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   827
			    val xupath = completeTermPath x u  (nth_elem(ui, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   828
			    val uxpath = completeTermPath u x  (nth_elem(ui, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   829
			    val vypath = completeTermPath v y  (nth_elem(vi, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   830
			    val yvpath = completeTermPath y v  (nth_elem(vi, sccSubgraphs))
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   831
			    val xuLesss = transPath (tl xupath, hd xupath)     
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   832
			    val uxLesss = transPath (tl uxpath, hd uxpath)			    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   833
			    val vyLesss = transPath (tl vypath, hd vypath)			
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   834
			    val yvLesss = transPath (tl yvpath, hd yvpath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   835
			    val x_eq_u =  (Thm ([(getprf xuLesss),(getprf uxLesss)], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   836
			    val v_eq_y =  (Thm ([(getprf vyLesss),(getprf yvLesss)], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   837
			in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   838
                           (Thm ([x_eq_u , (getprf e), v_eq_y ], Less.eq_neq_eq_imp_neq)) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   839
			end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   840
			)       
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   841
		  ) else if ui = yi andalso vi = xi then (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   842
		     case e of (Less (_, _,_)) => (
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   843
		        let val xypath = (completeTermPath y u (nth_elem(ui, sccSubgraphs)) ) @ [e] @ (completeTermPath v x (nth_elem(vi, sccSubgraphs)) )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   844
			    val xyLesss = transPath (tl xypath, hd xypath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   845
			in (Thm ([(Thm ([getprf xyLesss], Less.less_imp_neq))] , thm "not_sym")) end ) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   846
		     | _ => (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   847
		        
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   848
			let val yupath = completeTermPath y u (nth_elem(ui, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   849
			    val uypath = completeTermPath u y (nth_elem(ui, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   850
			    val vxpath = completeTermPath v x (nth_elem(vi, sccSubgraphs))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   851
			    val xvpath = completeTermPath x v (nth_elem(vi, sccSubgraphs))
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   852
			    val yuLesss = transPath (tl yupath, hd yupath)     
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   853
			    val uyLesss = transPath (tl uypath, hd uypath)			    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   854
			    val vxLesss = transPath (tl vxpath, hd vxpath)			
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   855
			    val xvLesss = transPath (tl xvpath, hd xvpath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   856
			    val y_eq_u =  (Thm ([(getprf yuLesss),(getprf uyLesss)], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   857
			    val v_eq_x =  (Thm ([(getprf vxLesss),(getprf xvLesss)], Less.eqI))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   858
			in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   859
			    (Thm ([(Thm ([y_eq_u , (getprf e), v_eq_x ], Less.eq_neq_eq_imp_neq))], thm "not_sym"))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   860
		        end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   861
		       )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   862
		  ) else (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   863
                       (* there exists a path x < y or y < x such that
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   864
                          x ~= y may be concluded *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   865
	        	case  (findLess e x y xi yi xreachable yreachable) of 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   866
		              (Some prf) =>  (Thm ([prf], Less.less_imp_neq))  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   867
                             | None =>  (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   868
		               let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   869
		                val yr = dfs_int_reachable sccGraph yi
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   870
	                        val xr = dfs_int_reachable sccGraph_transpose xi
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   871
		               in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   872
		                case  (findLess e y x yi xi yr xr) of 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   873
		                      (Some prf) => (Thm ([(Thm ([prf], Less.less_imp_neq))], thm "not_sym")) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   874
                                      | _ => processNeqEdges es
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   875
		               end)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   876
		 ) end) 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   877
     in processNeqEdges neqE end)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   878
  )    
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   879
end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   880
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   881
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   882
(* ******************************************************************* *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   883
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   884
(* mk_sccGraphs components leqG neqG ntc :                             *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   885
(* Term.term list list ->                                              *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   886
(* (Term.term * (Term.term * less) list) list ->                       *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   887
(* (Term.term * (Term.term * less) list) list ->                       *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   888
(* (Term.term * int)  list ->                                          *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   889
(* (int * (int * less) list) list   *                                  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   890
(* ((Term.term * (Term.term * less) list) list) list                   *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   891
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   892
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   893
(* Computes, from graph leqG, list of all its components and the list  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   894
(* ntc (nodes, index of component) a graph whose nodes are the         *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   895
(* indices of the components of g.  Egdes of the new graph are         *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   896
(* only the edges of g linking two components. Also computes for each  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   897
(* component the subgraph of leqG that forms this component.           *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   898
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   899
(* For each component SCC_i is checked if there exists a edge in neqG  *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   900
(* that leads to a contradiction.                                      *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   901
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   902
(* We have a contradiction for edge u ~= v and u < v if:               *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   903
(* - u and v are in the same component,                                *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   904
(* that is, a path u <= v and a path v <= u exist, hence u = v.        *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   905
(* From irreflexivity of < follows u < u or v < v. Ex false quodlibet. *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   906
(*                                                                     *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   907
(* ******************************************************************* *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   908
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   909
fun mk_sccGraphs _ [] _ _ = ([],[])
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   910
|   mk_sccGraphs components leqG neqG ntc = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   911
    let
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   912
    (* Liste (Index der Komponente, Komponente *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   913
    val IndexComp = indexComps components;
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   914
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   915
       
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   916
    fun handleContr edge g = 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   917
       (case edge of 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   918
          (Less  (x, y, _)) => (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   919
	    let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   920
	     val xxpath = edge :: (completeTermPath y x g )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   921
	     val xxLesss = transPath (tl xxpath, hd xxpath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   922
	     val q = getprf xxLesss
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   923
	    in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   924
	     raise (Contr (Thm ([q], Less.less_reflE ))) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   925
	    end 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   926
	  )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   927
        | (NotEq (x, y, _)) => (
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   928
	    let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   929
	     val xypath = (completeTermPath x y g )
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   930
	     val yxpath = (completeTermPath y x g )
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   931
	     val xyLesss = transPath (tl xypath, hd xypath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   932
	     val yxLesss = transPath (tl yxpath, hd yxpath)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   933
             val q = getprf (mergeLess ((mergeLess (edge, xyLesss)),yxLesss )) 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   934
	    in 
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   935
	     raise (Contr (Thm ([q], Less.less_reflE )))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   936
	    end  
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   937
	 )
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   938
	| _ =>  error "trans_tac/handleContr: invalid Contradiction");
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   939
 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   940
   	
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   941
    (* k is index of the actual component *)   
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   942
       
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   943
    fun processComponent (k, comp) = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   944
     let    
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   945
        (* all edges with weight <= of the actual component *)  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   946
        val leqEdges = flat (map (adjacent (op aconv) leqG) comp);
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   947
        (* all edges with weight ~= of the actual component *)  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   948
        val neqEdges = map snd (flat (map (adjacent (op aconv) neqG) comp));
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
   949
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   950
       (* find an edge leading to a contradiction *)   
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   951
       fun findContr [] = None
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   952
       |   findContr (e::es) = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   953
		    let val ui = (getIndex (lower e) ntc) 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   954
			val vi = (getIndex (upper e) ntc) 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   955
		    in 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   956
		        if ui = vi then  Some e
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   957
		        else findContr es
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   958
		    end; 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   959
		   
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   960
		(* sort edges into component internal edges and 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   961
		   edges pointing away from the component *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   962
		fun sortEdges  [] (intern,extern)  = (intern,extern)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   963
		|   sortEdges  ((v,l)::es) (intern, extern) = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   964
		    let val k' = getIndex v ntc in 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   965
		        if k' = k then 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   966
			    sortEdges es (l::intern, extern)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   967
			else sortEdges  es (intern, (k',l)::extern) end;
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   968
		
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   969
		(* Insert edge into sorted list of edges, where edge is
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   970
                    only added if
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   971
                    - it is found for the first time
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   972
                    - it is a <= edge and no parallel < edge was found earlier
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   973
                    - it is a < edge
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   974
                 *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   975
          	 fun insert (h,l) [] = [(h,l)]
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   976
		 |   insert (h,l) ((k',l')::es) = if h = k' then (
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   977
		     case l of (Less (_, _, _)) => (h,l)::es
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   978
		     | _  => (case l' of (Less (_, _, _)) => (h,l')::es
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   979
	                      | _ => (k',l)::es) )
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   980
		     else (k',l'):: insert (h,l) es;
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   981
		
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   982
		(* Reorganise list of edges such that
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   983
                    - duplicate edges are removed
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   984
                    - if a < edge and a <= edge exist at the same time,
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   985
                      remove <= edge *)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   986
    		 fun reOrganizeEdges [] sorted = sorted: (int * less) list
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   987
		 |   reOrganizeEdges (e::es) sorted = reOrganizeEdges es (insert e sorted); 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   988
	
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   989
                 (* construct the subgraph forming the strongly connected component
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   990
		    from the edge list *)    
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   991
		 fun sccSubGraph [] g  = g
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   992
		 |   sccSubGraph (l::ls) g = 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   993
		          sccSubGraph ls (addEdge ((lower l),[((upper l),l)],g))
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   994
		 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   995
		 val (intern, extern) = sortEdges leqEdges ([], []);
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   996
                 val subGraph = sccSubGraph intern [];
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   997
		  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   998
     in  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
   999
         case findContr neqEdges of Some e => handleContr e subGraph
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1000
	 | _ => ((k, (reOrganizeEdges (extern) [])), subGraph)
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1001
     end; 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1002
  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1003
    val tmp =  map processComponent IndexComp    
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1004
in 
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1005
     ( (map fst tmp), (map snd tmp))  
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1006
end; 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1007
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1008
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1009
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1010
(* solvePartialOrder sign (asms,concl) :                                   *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1011
(* Sign.sg -> less list * Term.term -> proof list                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1012
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1013
(* Find proof if possible for partial orders.                              *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1014
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1015
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1016
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1017
fun solvePartialOrder sign (asms, concl) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1018
 let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1019
  val (leqG, neqG, neqE) = mkGraphs asms
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1020
  val components = scc_term leqG
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1021
  val ntc = indexNodes (indexComps components)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1022
  val (sccGraph, sccSubgraphs) = mk_sccGraphs components leqG neqG ntc 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1023
 in
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1024
   let 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1025
   val (subgoals, prf) = mkconcl_partial sign concl
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1026
   fun solve facts less =
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1027
       (case triv_solv less of None => findProof (sccGraph, neqE, ntc, sccSubgraphs ) less
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1028
       | Some prf => prf )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1029
  in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1030
   map (solve asms) subgoals
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1031
  end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1032
 end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1033
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1034
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1035
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1036
(* solveTotalOrder sign (asms,concl) :                                     *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1037
(* Sign.sg -> less list * Term.term -> proof list                          *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1038
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1039
(* Find proof if possible for linear orders.                               *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1040
(*                                                                         *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1041
(* *********************************************************************** *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1042
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1043
fun solveTotalOrder sign (asms, concl) =
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1044
 let 
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1045
  val (leqG, neqG, neqE) = mkGraphs asms
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1046
  val components = scc_term leqG   
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1047
  val ntc = indexNodes (indexComps components)
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1048
  val (sccGraph, sccSubgraphs) = mk_sccGraphs components leqG neqG ntc
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1049
 in
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1050
   let 
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1051
   val (subgoals, prf) = mkconcl_linear sign concl
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1052
   fun solve facts less =
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1053
      (case triv_solv less of None => findProof (sccGraph, neqE, ntc, sccSubgraphs) less
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1054
      | Some prf => prf )
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1055
  in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1056
   map (solve asms) subgoals
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1057
  end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1058
 end;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1059
  
14445
4392cb82018b Bug-fixes for transitivity reasoner.
ballarin
parents: 14398
diff changeset
  1060
(* partial_tac - solves partial orders *)
14398
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1061
val partial_tac = SUBGOAL (fn (A, n, sign) =>
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1062
 let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1063
  val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1064
  val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1065
  val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1066
  val lesss = flat (ListPair.map (mkasm_partial sign) (Hs, 0 upto (length Hs - 1)))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1067
  val prfs = solvePartialOrder sign (lesss, C);
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1068
  val (subgoals, prf) = mkconcl_partial sign C;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1069
 in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1070
  METAHYPS (fn asms =>
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1071
    let val thms = map (prove asms) prfs
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1072
    in rtac (prove thms prf) 1 end) n
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1073
 end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1074
 handle Contr p => METAHYPS (fn asms => rtac (prove asms p) 1) n
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1075
      | Cannot  => no_tac
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1076
      );
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1077
       
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1078
(* linear_tac - solves linear/total orders *)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1079
val linear_tac = SUBGOAL (fn (A, n, sign) =>
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1080
 let
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1081
  val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1082
  val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1083
  val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1084
  val lesss = flat (ListPair.map (mkasm_linear sign) (Hs, 0 upto (length Hs - 1)))
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1085
  val prfs = solveTotalOrder sign (lesss, C);
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1086
  val (subgoals, prf) = mkconcl_linear sign C;
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1087
 in
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1088
  METAHYPS (fn asms =>
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1089
    let val thms = map (prove asms) prfs
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1090
    in rtac (prove thms prf) 1 end) n
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1091
 end
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1092
 handle Contr p => METAHYPS (fn asms => rtac (prove asms p) 1) n
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1093
      | Cannot  => no_tac);
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1094
       
c5c47703f763 Efficient, graph-based reasoner for linear and partial orders.
ballarin
parents:
diff changeset
  1095
end;