77 if term_of x aconv y then Lt (Thm.dest_arg ct) |
77 if term_of x aconv y then Lt (Thm.dest_arg ct) |
78 else if term_of x aconv z then Gt (Thm.dest_arg1 ct) else Nox |
78 else if term_of x aconv z then Gt (Thm.dest_arg1 ct) else Nox |
79 | Const (@{const_name Algebras.less_eq}, _) $ y $ z => |
79 | Const (@{const_name Algebras.less_eq}, _) $ y $ z => |
80 if term_of x aconv y then Le (Thm.dest_arg ct) |
80 if term_of x aconv y then Le (Thm.dest_arg ct) |
81 else if term_of x aconv z then Ge (Thm.dest_arg1 ct) else Nox |
81 else if term_of x aconv z then Ge (Thm.dest_arg1 ct) else Nox |
82 | Const (@{const_name Ring_and_Field.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$y$_) => |
82 | Const (@{const_name Rings.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$y$_) => |
83 if term_of x aconv y then Dvd (Thm.dest_binop ct ||> Thm.dest_arg) else Nox |
83 if term_of x aconv y then Dvd (Thm.dest_binop ct ||> Thm.dest_arg) else Nox |
84 | Const (@{const_name Not},_) $ (Const (@{const_name Ring_and_Field.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$y$_)) => |
84 | Const (@{const_name Not},_) $ (Const (@{const_name Rings.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$y$_)) => |
85 if term_of x aconv y then |
85 if term_of x aconv y then |
86 NDvd (Thm.dest_binop (Thm.dest_arg ct) ||> Thm.dest_arg) else Nox |
86 NDvd (Thm.dest_binop (Thm.dest_arg ct) ||> Thm.dest_arg) else Nox |
87 | _ => Nox) |
87 | _ => Nox) |
88 handle CTERM _ => Nox; |
88 handle CTERM _ => Nox; |
89 |
89 |
220 fun lin (vs as x::_) (Const (@{const_name Not}, _) $ (Const (@{const_name Algebras.less}, T) $ s $ t)) = |
220 fun lin (vs as x::_) (Const (@{const_name Not}, _) $ (Const (@{const_name Algebras.less}, T) $ s $ t)) = |
221 lin vs (Const (@{const_name Algebras.less_eq}, T) $ t $ s) |
221 lin vs (Const (@{const_name Algebras.less_eq}, T) $ t $ s) |
222 | lin (vs as x::_) (Const (@{const_name Not},_) $ (Const(@{const_name Algebras.less_eq}, T) $ s $ t)) = |
222 | lin (vs as x::_) (Const (@{const_name Not},_) $ (Const(@{const_name Algebras.less_eq}, T) $ s $ t)) = |
223 lin vs (Const (@{const_name Algebras.less}, T) $ t $ s) |
223 lin vs (Const (@{const_name Algebras.less}, T) $ t $ s) |
224 | lin vs (Const (@{const_name Not},T)$t) = Const (@{const_name Not},T)$ (lin vs t) |
224 | lin vs (Const (@{const_name Not},T)$t) = Const (@{const_name Not},T)$ (lin vs t) |
225 | lin (vs as x::_) (Const(@{const_name Ring_and_Field.dvd},_)$d$t) = |
225 | lin (vs as x::_) (Const(@{const_name Rings.dvd},_)$d$t) = |
226 HOLogic.mk_binrel @{const_name Ring_and_Field.dvd} (numeral1 abs d, lint vs t) |
226 HOLogic.mk_binrel @{const_name Rings.dvd} (numeral1 abs d, lint vs t) |
227 | lin (vs as x::_) ((b as Const("op =",_))$s$t) = |
227 | lin (vs as x::_) ((b as Const("op =",_))$s$t) = |
228 (case lint vs (subC$t$s) of |
228 (case lint vs (subC$t$s) of |
229 (t as a$(m$c$y)$r) => |
229 (t as a$(m$c$y)$r) => |
230 if x <> y then b$zero$t |
230 if x <> y then b$zero$t |
231 else if dest_numeral c < 0 then b$(m$(numeral1 ~ c)$y)$r |
231 else if dest_numeral c < 0 then b$(m$(numeral1 ~ c)$y)$r |
251 fun is_intrel (b$_$_) = is_intrel_type (fastype_of b) |
251 fun is_intrel (b$_$_) = is_intrel_type (fastype_of b) |
252 | is_intrel (@{term "Not"}$(b$_$_)) = is_intrel_type (fastype_of b) |
252 | is_intrel (@{term "Not"}$(b$_$_)) = is_intrel_type (fastype_of b) |
253 | is_intrel _ = false; |
253 | is_intrel _ = false; |
254 |
254 |
255 fun linearize_conv ctxt vs ct = case term_of ct of |
255 fun linearize_conv ctxt vs ct = case term_of ct of |
256 Const(@{const_name Ring_and_Field.dvd},_)$d$t => |
256 Const(@{const_name Rings.dvd},_)$d$t => |
257 let |
257 let |
258 val th = binop_conv (lint_conv ctxt vs) ct |
258 val th = binop_conv (lint_conv ctxt vs) ct |
259 val (d',t') = Thm.dest_binop (Thm.rhs_of th) |
259 val (d',t') = Thm.dest_binop (Thm.rhs_of th) |
260 val (dt',tt') = (term_of d', term_of t') |
260 val (dt',tt') = (term_of d', term_of t') |
261 in if is_numeral dt' andalso is_numeral tt' |
261 in if is_numeral dt' andalso is_numeral tt' |
276 (Thm.transitive dth (inst' [d'',t'] dvd_uminus')) |
276 (Thm.transitive dth (inst' [d'',t'] dvd_uminus')) |
277 else dth end |
277 else dth end |
278 | _ => dth |
278 | _ => dth |
279 end |
279 end |
280 end |
280 end |
281 | Const (@{const_name Not},_)$(Const(@{const_name Ring_and_Field.dvd},_)$_$_) => arg_conv (linearize_conv ctxt vs) ct |
281 | Const (@{const_name Not},_)$(Const(@{const_name Rings.dvd},_)$_$_) => arg_conv (linearize_conv ctxt vs) ct |
282 | t => if is_intrel t |
282 | t => if is_intrel t |
283 then (provelin ctxt ((HOLogic.eq_const bT)$t$(lin vs t) |> HOLogic.mk_Trueprop)) |
283 then (provelin ctxt ((HOLogic.eq_const bT)$t$(lin vs t) |> HOLogic.mk_Trueprop)) |
284 RS eq_reflection |
284 RS eq_reflection |
285 else reflexive ct; |
285 else reflexive ct; |
286 |
286 |
299 then (ins (dest_numeral c) acc,dacc) else (acc,dacc) |
299 then (ins (dest_numeral c) acc,dacc) else (acc,dacc) |
300 | Const(s,_)$_$(Const(@{const_name Algebras.times},_)$c$y) => |
300 | Const(s,_)$_$(Const(@{const_name Algebras.times},_)$c$y) => |
301 if x aconv y andalso member (op =) |
301 if x aconv y andalso member (op =) |
302 [@{const_name Algebras.less}, @{const_name Algebras.less_eq}] s |
302 [@{const_name Algebras.less}, @{const_name Algebras.less_eq}] s |
303 then (ins (dest_numeral c) acc, dacc) else (acc,dacc) |
303 then (ins (dest_numeral c) acc, dacc) else (acc,dacc) |
304 | Const(@{const_name Ring_and_Field.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$(Const(@{const_name Algebras.times},_)$c$y)$_) => |
304 | Const(@{const_name Rings.dvd},_)$_$(Const(@{const_name Algebras.plus},_)$(Const(@{const_name Algebras.times},_)$c$y)$_) => |
305 if x aconv y then (acc,ins (dest_numeral c) dacc) else (acc,dacc) |
305 if x aconv y then (acc,ins (dest_numeral c) dacc) else (acc,dacc) |
306 | Const("op &",_)$_$_ => h (h (acc,dacc) (Thm.dest_arg1 t)) (Thm.dest_arg t) |
306 | Const("op &",_)$_$_ => h (h (acc,dacc) (Thm.dest_arg1 t)) (Thm.dest_arg t) |
307 | Const("op |",_)$_$_ => h (h (acc,dacc) (Thm.dest_arg1 t)) (Thm.dest_arg t) |
307 | Const("op |",_)$_$_ => h (h (acc,dacc) (Thm.dest_arg1 t)) (Thm.dest_arg t) |
308 | Const (@{const_name Not},_)$_ => h (acc,dacc) (Thm.dest_arg t) |
308 | Const (@{const_name Not},_)$_ => h (acc,dacc) (Thm.dest_arg t) |
309 | _ => (acc, dacc) |
309 | _ => (acc, dacc) |
341 then cv (l div dest_numeral c) t else Thm.reflexive t |
341 then cv (l div dest_numeral c) t else Thm.reflexive t |
342 | Const(s,_)$_$(Const(@{const_name Algebras.times},_)$c$y) => |
342 | Const(s,_)$_$(Const(@{const_name Algebras.times},_)$c$y) => |
343 if x=y andalso member (op =) |
343 if x=y andalso member (op =) |
344 [@{const_name Algebras.less}, @{const_name Algebras.less_eq}] s |
344 [@{const_name Algebras.less}, @{const_name Algebras.less_eq}] s |
345 then cv (l div dest_numeral c) t else Thm.reflexive t |
345 then cv (l div dest_numeral c) t else Thm.reflexive t |
346 | Const(@{const_name Ring_and_Field.dvd},_)$d$(r as (Const(@{const_name Algebras.plus},_)$(Const(@{const_name Algebras.times},_)$c$y)$_)) => |
346 | Const(@{const_name Rings.dvd},_)$d$(r as (Const(@{const_name Algebras.plus},_)$(Const(@{const_name Algebras.times},_)$c$y)$_)) => |
347 if x=y then |
347 if x=y then |
348 let |
348 let |
349 val k = l div dest_numeral c |
349 val k = l div dest_numeral c |
350 val kt = HOLogic.mk_number iT k |
350 val kt = HOLogic.mk_number iT k |
351 val th1 = inst' [Thm.dest_arg1 t, Thm.dest_arg t] |
351 val th1 = inst' [Thm.dest_arg1 t, Thm.dest_arg t] |
560 fun qf_of_term ps vs t = case t |
560 fun qf_of_term ps vs t = case t |
561 of Const("True",_) => T |
561 of Const("True",_) => T |
562 | Const("False",_) => F |
562 | Const("False",_) => F |
563 | Const(@{const_name Algebras.less},_)$t1$t2 => Lt (Sub (i_of_term vs t1,i_of_term vs t2)) |
563 | Const(@{const_name Algebras.less},_)$t1$t2 => Lt (Sub (i_of_term vs t1,i_of_term vs t2)) |
564 | Const(@{const_name Algebras.less_eq},_)$t1$t2 => Le (Sub(i_of_term vs t1,i_of_term vs t2)) |
564 | Const(@{const_name Algebras.less_eq},_)$t1$t2 => Le (Sub(i_of_term vs t1,i_of_term vs t2)) |
565 | Const(@{const_name Ring_and_Field.dvd},_)$t1$t2 => |
565 | Const(@{const_name Rings.dvd},_)$t1$t2 => |
566 (Dvd(HOLogic.dest_number t1 |> snd, i_of_term vs t2) handle _ => cooper "Reification: unsupported dvd") (* FIXME avoid handle _ *) |
566 (Dvd(HOLogic.dest_number t1 |> snd, i_of_term vs t2) handle _ => cooper "Reification: unsupported dvd") (* FIXME avoid handle _ *) |
567 | @{term "op = :: int => _"}$t1$t2 => Eq (Sub (i_of_term vs t1,i_of_term vs t2)) |
567 | @{term "op = :: int => _"}$t1$t2 => Eq (Sub (i_of_term vs t1,i_of_term vs t2)) |
568 | @{term "op = :: bool => _ "}$t1$t2 => Iff(qf_of_term ps vs t1,qf_of_term ps vs t2) |
568 | @{term "op = :: bool => _ "}$t1$t2 => Iff(qf_of_term ps vs t1,qf_of_term ps vs t2) |
569 | Const("op &",_)$t1$t2 => And(qf_of_term ps vs t1,qf_of_term ps vs t2) |
569 | Const("op &",_)$t1$t2 => And(qf_of_term ps vs t1,qf_of_term ps vs t2) |
570 | Const("op |",_)$t1$t2 => Or(qf_of_term ps vs t1,qf_of_term ps vs t2) |
570 | Const("op |",_)$t1$t2 => Or(qf_of_term ps vs t1,qf_of_term ps vs t2) |