src/HOL/Matrix_LP/Compute_Oracle/compute.ML
changeset 59582 0fbed69ff081
parent 58669 6bade3d91c49
child 59586 ddf6deaadfe8
equal deleted inserted replaced
59580:cbc38731d42f 59582:0fbed69ff081
   366     end)));
   366     end)));
   367 
   367 
   368 fun export_thm thy hyps shyps prop =
   368 fun export_thm thy hyps shyps prop =
   369     let
   369     let
   370         val th = export_oracle (thy, hyps, shyps, prop)
   370         val th = export_oracle (thy, hyps, shyps, prop)
   371         val hyps = map (fn h => Thm.assume (cterm_of thy h)) hyps
   371         val hyps = map (fn h => Thm.assume (Thm.cterm_of thy h)) hyps
   372     in
   372     in
   373         fold (fn h => fn p => Thm.implies_elim p h) hyps th 
   373         fold (fn h => fn p => Thm.implies_elim p h) hyps th 
   374     end
   374     end
   375         
   375         
   376 (* --------- Rewrite ----------- *)
   376 (* --------- Rewrite ----------- *)
   377 
   377 
   378 fun rewrite computer ct =
   378 fun rewrite computer ct =
   379     let
   379     let
   380         val thy = Thm.theory_of_cterm ct
   380         val thy = Thm.theory_of_cterm ct
   381         val {t=t',T=ty,...} = rep_cterm ct
   381         val {t=t',T=ty,...} = Thm.rep_cterm ct
   382         val _ = super_theory (theory_of computer) thy
   382         val _ = super_theory (theory_of computer) thy
   383         val naming = naming_of computer
   383         val naming = naming_of computer
   384         val (encoding, t) = remove_types (encoding_of computer) t'
   384         val (encoding, t) = remove_types (encoding_of computer) t'
   385         val t = runprog (prog_of computer) t
   385         val t = runprog (prog_of computer) t
   386         val t = infer_types naming encoding ty t
   386         val t = infer_types naming encoding ty t
   399 
   399 
   400 exception ParamSimplify of computer * theorem
   400 exception ParamSimplify of computer * theorem
   401 
   401 
   402 fun make_theorem computer th vars =
   402 fun make_theorem computer th vars =
   403 let
   403 let
   404     val _ = super_theory (theory_of computer) (theory_of_thm th)
   404     val _ = super_theory (theory_of computer) (Thm.theory_of_thm th)
   405 
   405 
   406     val (ComputeThm (hyps, shyps, prop)) = thm2cthm th 
   406     val (ComputeThm (hyps, shyps, prop)) = thm2cthm th 
   407 
   407 
   408     val encoding = encoding_of computer
   408     val encoding = encoding_of computer
   409  
   409  
   450             case mk_prem encoding t  of 
   450             case mk_prem encoding t  of 
   451                 (encoding, t) => (encoding, t::l)) (Logic.strip_imp_prems prop) (encoding, []))
   451                 (encoding, t) => (encoding, t::l)) (Logic.strip_imp_prems prop) (encoding, []))
   452     val (encoding, concl) = remove_types encoding (Logic.strip_imp_concl prop)
   452     val (encoding, concl) = remove_types encoding (Logic.strip_imp_concl prop)
   453     val _ = set_encoding computer encoding
   453     val _ = set_encoding computer encoding
   454 in
   454 in
   455     Theorem (theory_of_thm th, stamp_of computer, vartab, varsubst, 
   455     Theorem (Thm.theory_of_thm th, stamp_of computer, vartab, varsubst, 
   456              prems, concl, hyps, shyps)
   456              prems, concl, hyps, shyps)
   457 end
   457 end
   458     
   458     
   459 fun theory_of_theorem (Theorem (thy,_,_,_,_,_,_,_)) = thy
   459 fun theory_of_theorem (Theorem (thy,_,_,_,_,_,_,_)) = thy
   460 fun update_theory thy (Theorem (_,p0,p1,p2,p3,p4,p5,p6)) = Theorem (thy,p0,p1,p2,p3,p4,p5,p6)
   460 fun update_theory thy (Theorem (_,p0,p1,p2,p3,p4,p5,p6)) = Theorem (thy,p0,p1,p2,p3,p4,p5,p6)
   504         else 
   504         else 
   505             raise Compute "instantiate: not a closed term"
   505             raise Compute "instantiate: not a closed term"
   506 
   506 
   507     fun compute_inst (s, ct) vs =
   507     fun compute_inst (s, ct) vs =
   508         let
   508         let
   509             val _ = super_theory (theory_of_cterm ct) thy
   509             val _ = super_theory (Thm.theory_of_cterm ct) thy
   510             val ty = typ_of (ctyp_of_term ct) 
   510             val ty = Thm.typ_of (Thm.ctyp_of_term ct) 
   511         in          
   511         in          
   512             (case Symtab.lookup vartab s of 
   512             (case Symtab.lookup vartab s of 
   513                  NONE => raise Compute ("instantiate: variable '"^s^"' not found in theorem")
   513                  NONE => raise Compute ("instantiate: variable '"^s^"' not found in theorem")
   514                | SOME (x, ty') => 
   514                | SOME (x, ty') => 
   515                  (case Inttab.lookup vs x of 
   515                  (case Inttab.lookup vs x of 
   517                     | SOME NONE => 
   517                     | SOME NONE => 
   518                       if ty <> ty' then 
   518                       if ty <> ty' then 
   519                           raise Compute ("instantiate: wrong type for variable '"^s^"'")
   519                           raise Compute ("instantiate: wrong type for variable '"^s^"'")
   520                       else
   520                       else
   521                           let
   521                           let
   522                               val t = rewrite computer (term_of ct)
   522                               val t = rewrite computer (Thm.term_of ct)
   523                               val _ = assert_varfree vs t 
   523                               val _ = assert_varfree vs t 
   524                               val _ = assert_closed t
   524                               val _ = assert_closed t
   525                           in
   525                           in
   526                               Inttab.update (x, SOME t) vs
   526                               Inttab.update (x, SOME t) vs
   527                           end
   527                           end
   609 let
   609 let
   610     val _ = check_compatible computer th
   610     val _ = check_compatible computer th
   611     val thy = 
   611     val thy = 
   612         let
   612         let
   613             val thy1 = theory_of_theorem th
   613             val thy1 = theory_of_theorem th
   614             val thy2 = theory_of_thm th'
   614             val thy2 = Thm.theory_of_thm th'
   615         in
   615         in
   616             if Theory.subthy (thy1, thy2) then thy2 
   616             if Theory.subthy (thy1, thy2) then thy2 
   617             else if Theory.subthy (thy2, thy1) then thy1 else
   617             else if Theory.subthy (thy2, thy1) then thy1 else
   618             raise Compute "modus_ponens: theorems are not compatible with each other"
   618             raise Compute "modus_ponens: theorems are not compatible with each other"
   619         end 
   619         end