src/HOL/Matrix/cplex/MatrixLP.ML
changeset 20485 3078fd2eec7b
parent 19404 9bf2cdc9e8e8
equal deleted inserted replaced
20484:3d3d24186352 20485:3078fd2eec7b
    14 end
    14 end
    15 
    15 
    16 structure MatrixLP : MATRIX_LP =
    16 structure MatrixLP : MATRIX_LP =
    17 struct
    17 struct
    18 
    18 
    19 val sg = sign_of (theory "MatrixLP")
    19 val thy = theory "MatrixLP";
    20 
    20 
    21 fun inst_real thm = standard (Thm.instantiate ([(ctyp_of sg (TVar (hd (term_tvars (prop_of thm)))),
    21 fun inst_real thm = standard (Thm.instantiate ([(ctyp_of thy (TVar (hd (term_tvars (prop_of thm)))),
    22 						 ctyp_of sg HOLogic.realT)], []) thm)
    22 						 ctyp_of thy HOLogic.realT)], []) thm)
    23 
    23 
    24 fun lp_dual_estimate_prt_primitive (y, (A1, A2), (c1, c2), b, (r1, r2)) = 
    24 fun lp_dual_estimate_prt_primitive (y, (A1, A2), (c1, c2), b, (r1, r2)) = 
    25     let
    25     let
    26 	val th = inst_real (thm "SparseMatrix.spm_mult_le_dual_prts_no_let")
    26 	val th = inst_real (thm "SparseMatrix.spm_mult_le_dual_prts_no_let")
    27 	fun var s x = (cterm_of sg (Var ((s,0), FloatSparseMatrixBuilder.real_spmatT)), x)
    27 	fun var s x = (cterm_of thy (Var ((s,0), FloatSparseMatrixBuilder.real_spmatT)), x)
    28 	val th = Thm.instantiate ([], [var "A1" A1, var "A2" A2, var "y" y, var "c1" c1, var "c2" c2, 
    28 	val th = Thm.instantiate ([], [var "A1" A1, var "A2" A2, var "y" y, var "c1" c1, var "c2" c2, 
    29 				       var "r1" r1, var "r2" r2, var "b" b]) th
    29 				       var "r1" r1, var "r2" r2, var "b" b]) th
    30     in
    30     in
    31 	th
    31 	th
    32     end
    32     end
    41 		(y l, A l, c l, b l, r12 l)
    41 		(y l, A l, c l, b l, r12 l)
    42 	    end		
    42 	    end		
    43     in
    43     in
    44 	lp_dual_estimate_prt_primitive certificate
    44 	lp_dual_estimate_prt_primitive certificate
    45     end
    45     end
    46 	 
    46 
    47 fun read_ct s = read_cterm sg (s, TypeInfer.logicT);
    47 fun read_ct s = read_cterm thy (s, TypeInfer.logicT);
    48     
    48     
    49 fun is_meta_eq th =
    49 fun is_meta_eq th =
    50     let
    50     let
    51 	fun check ((Const ("==", _)) $ _ $ _) = true
    51 	fun check ((Const ("==", _)) $ _ $ _) = true
    52 	  | check _ = false
    52 	  | check _ = false
    54 	check (concl_of th)
    54 	check (concl_of th)
    55     end
    55     end
    56     
    56     
    57 fun prep ths = (Library.filter is_meta_eq ths) @ (map (standard o mk_meta_eq) (Library.filter (not o is_meta_eq) ths))
    57 fun prep ths = (Library.filter is_meta_eq ths) @ (map (standard o mk_meta_eq) (Library.filter (not o is_meta_eq) ths))
    58 
    58 
    59 fun make ths = Compute.basic_make sg ths
    59 fun make ths = Compute.basic_make thy ths
    60 	  
    60 	  
    61 fun inst_tvar ty thm = 
    61 fun inst_tvar ty thm = 
    62     let
    62     let
    63 	val ord = prod_ord (prod_ord string_ord int_ord) (list_ord string_ord)
    63 	val ord = prod_ord (prod_ord string_ord int_ord) (list_ord string_ord)
    64 	val v = TVar (hd (sort ord (term_tvars (prop_of thm))))
    64 	val v = TVar (hd (sort ord (term_tvars (prop_of thm))))
    65     in	
    65     in	
    66 	standard (Thm.instantiate ([(ctyp_of sg v, ctyp_of sg ty)], []) thm)
    66 	standard (Thm.instantiate ([(ctyp_of thy v, ctyp_of thy ty)], []) thm)
    67     end
    67     end
    68     
    68     
    69 fun inst_tvars [] thms = thms
    69 fun inst_tvars [] thms = thms
    70   | inst_tvars (ty::tys) thms = inst_tvars tys (map (inst_tvar ty) thms)
    70   | inst_tvars (ty::tys) thms = inst_tvars tys (map (inst_tvar ty) thms)
    71 				
    71 
    72 val matrix_compute =
    72 val matrix_compute =
    73     let 
    73     let 
    74 	val spvecT = FloatSparseMatrixBuilder.real_spvecT
    74 	val spvecT = FloatSparseMatrixBuilder.real_spvecT
    75 	val spmatT = FloatSparseMatrixBuilder.real_spmatT
    75 	val spmatT = FloatSparseMatrixBuilder.real_spmatT
    76 	val spvecT_elem = HOLogic.mk_prodT (HOLogic.natT, HOLogic.realT)
    76 	val spvecT_elem = HOLogic.mk_prodT (HOLogic.natT, HOLogic.realT)
   115 	val th = lp_dual_estimate_prt lptfile prec
   115 	val th = lp_dual_estimate_prt lptfile prec
   116     in
   116     in
   117 	matrix_simplify th
   117 	matrix_simplify th
   118     end
   118     end
   119 
   119 
   120 fun realFromStr s = valOf (Real.fromString s)
   120 val realFromStr = the o Real.fromString;
   121 fun float2real (x,y) = (realFromStr x) * (Math.pow (2.0, realFromStr y))
   121 fun float2real (x, y) = realFromStr x * Math.pow (2.0, realFromStr y);
   122 
   122 
   123 end
   123 end
   124 
   124