src/HOL/Tools/numeral_simprocs.ML
changeset 60801 7664e0916eec
parent 60642 48dd1cefb4ae
child 61144 5e94dfead1c2
equal deleted inserted replaced
60799:57dd0b45fc21 60801:7664e0916eec
   608     val ((x,y),(w,z)) =
   608     val ((x,y),(w,z)) =
   609          (Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct
   609          (Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct
   610     val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z,w]
   610     val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z,w]
   611     val T = Thm.ctyp_of_cterm x
   611     val T = Thm.ctyp_of_cterm x
   612     val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z]
   612     val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z]
   613     val th = instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq
   613     val th = Thm.instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq
   614   in SOME (Thm.implies_elim (Thm.implies_elim th y_nz) z_nz)
   614   in SOME (Thm.implies_elim (Thm.implies_elim th y_nz) z_nz)
   615   end
   615   end
   616   handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
   616   handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
   617 
   617 
   618  fun proc2 phi ctxt ct =
   618  fun proc2 phi ctxt ct =
   622   in (case (Thm.term_of l, Thm.term_of r) of
   622   in (case (Thm.term_of l, Thm.term_of r) of
   623       (Const(@{const_name Rings.divide},_)$_$_, _) =>
   623       (Const(@{const_name Rings.divide},_)$_$_, _) =>
   624         let val (x,y) = Thm.dest_binop l val z = r
   624         let val (x,y) = Thm.dest_binop l val z = r
   625             val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
   625             val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
   626             val ynz = prove_nz ctxt T y
   626             val ynz = prove_nz ctxt T y
   627         in SOME (Thm.implies_elim (instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz)
   627         in SOME (Thm.implies_elim (Thm.instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz)
   628         end
   628         end
   629      | (_, Const (@{const_name Rings.divide},_)$_$_) =>
   629      | (_, Const (@{const_name Rings.divide},_)$_$_) =>
   630         let val (x,y) = Thm.dest_binop r val z = l
   630         let val (x,y) = Thm.dest_binop r val z = l
   631             val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
   631             val _ = map (HOLogic.dest_number o Thm.term_of) [x,y,z]
   632             val ynz = prove_nz ctxt T y
   632             val ynz = prove_nz ctxt T y
   633         in SOME (Thm.implies_elim (instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz)
   633         in SOME (Thm.implies_elim (Thm.instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz)
   634         end
   634         end
   635      | _ => NONE)
   635      | _ => NONE)
   636   end
   636   end
   637   handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
   637   handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
   638 
   638 
   646     Const(@{const_name Orderings.less},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   646     Const(@{const_name Orderings.less},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   647       let
   647       let
   648         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   648         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   649         val _ = map is_number [a,b,c]
   649         val _ = map is_number [a,b,c]
   650         val T = Thm.ctyp_of_cterm c
   650         val T = Thm.ctyp_of_cterm c
   651         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
   651         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
   652       in SOME (mk_meta_eq th) end
   652       in SOME (mk_meta_eq th) end
   653   | Const(@{const_name Orderings.less_eq},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   653   | Const(@{const_name Orderings.less_eq},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   654       let
   654       let
   655         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   655         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   656         val _ = map is_number [a,b,c]
   656         val _ = map is_number [a,b,c]
   657         val T = Thm.ctyp_of_cterm c
   657         val T = Thm.ctyp_of_cterm c
   658         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
   658         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
   659       in SOME (mk_meta_eq th) end
   659       in SOME (mk_meta_eq th) end
   660   | Const(@{const_name HOL.eq},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   660   | Const(@{const_name HOL.eq},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
   661       let
   661       let
   662         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   662         val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
   663         val _ = map is_number [a,b,c]
   663         val _ = map is_number [a,b,c]
   664         val T = Thm.ctyp_of_cterm c
   664         val T = Thm.ctyp_of_cterm c
   665         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
   665         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
   666       in SOME (mk_meta_eq th) end
   666       in SOME (mk_meta_eq th) end
   667   | Const(@{const_name Orderings.less},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   667   | Const(@{const_name Orderings.less},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   668     let
   668     let
   669       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   669       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   670         val _ = map is_number [a,b,c]
   670         val _ = map is_number [a,b,c]
   671         val T = Thm.ctyp_of_cterm c
   671         val T = Thm.ctyp_of_cterm c
   672         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
   672         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
   673       in SOME (mk_meta_eq th) end
   673       in SOME (mk_meta_eq th) end
   674   | Const(@{const_name Orderings.less_eq},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   674   | Const(@{const_name Orderings.less_eq},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   675     let
   675     let
   676       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   676       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   677         val _ = map is_number [a,b,c]
   677         val _ = map is_number [a,b,c]
   678         val T = Thm.ctyp_of_cterm c
   678         val T = Thm.ctyp_of_cterm c
   679         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
   679         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
   680       in SOME (mk_meta_eq th) end
   680       in SOME (mk_meta_eq th) end
   681   | Const(@{const_name HOL.eq},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   681   | Const(@{const_name HOL.eq},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
   682     let
   682     let
   683       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   683       val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
   684         val _ = map is_number [a,b,c]
   684         val _ = map is_number [a,b,c]
   685         val T = Thm.ctyp_of_cterm c
   685         val T = Thm.ctyp_of_cterm c
   686         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
   686         val th = Thm.instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
   687       in SOME (mk_meta_eq th) end
   687       in SOME (mk_meta_eq th) end
   688   | _ => NONE)
   688   | _ => NONE)
   689   handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE
   689   handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE
   690 
   690 
   691 val add_frac_frac_simproc =
   691 val add_frac_frac_simproc =