src/HOL/Real_Asymp/real_asymp.ML
author wenzelm
Wed, 20 Oct 2021 17:11:46 +0200
changeset 74560 5c8177fd1295
parent 69597 ff784d5a5bfb
child 80636 4041e7c8059d
permissions -rw-r--r--
clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     1
signature REAL_ASYMP = sig
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     2
val tac : bool -> Proof.context -> int -> tactic
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     3
end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     4
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     5
functor Real_Asymp (Exp : EXPANSION_INTERFACE) : REAL_ASYMP = struct
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     6
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     7
open Lazy_Eval
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     8
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
     9
val dest_arg = dest_comb #> snd
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    10
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    11
fun prove_limit_at_top ectxt f filter =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    12
  let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    13
    val ctxt = get_ctxt ectxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    14
    val basis = Asymptotic_Basis.default_basis
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    15
    val prover =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    16
      case filter of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    17
        Const (\<^const_name>\<open>Topological_Spaces.nhds\<close>, _) $ _ => SOME Exp.prove_nhds
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    18
      | \<^term>\<open>at (0 :: real)\<close> => SOME Exp.prove_at_0
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    19
      | \<^term>\<open>at_left (0 :: real)\<close> => SOME Exp.prove_at_left_0
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    20
      | \<^term>\<open>at_right (0 :: real)\<close> => SOME Exp.prove_at_right_0
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    21
      | \<^term>\<open>at_infinity :: real filter\<close> => SOME Exp.prove_at_infinity
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    22
      | \<^term>\<open>at_top :: real filter\<close> => SOME Exp.prove_at_top
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    23
      | \<^term>\<open>at_bot :: real filter\<close> => SOME Exp.prove_at_bot
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    24
      | _ => NONE
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    25
    val lim_thm = Option.map (fn prover => prover ectxt (Exp.expand_term ectxt f basis)) prover
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    26
  in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    27
    case lim_thm of
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    28
      NONE => no_tac
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    29
    | SOME lim_thm =>
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    30
        HEADGOAL (
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    31
          resolve_tac ctxt [lim_thm, lim_thm RS @{thm filterlim_mono'}]
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    32
          THEN_ALL_NEW (TRY o resolve_tac ctxt @{thms at_within_le_nhds at_within_le_at nhds_leI}))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    33
  end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    34
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    35
fun prove_eventually_at_top ectxt p =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    36
  case Envir.eta_long [] p of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    37
    Abs (x, \<^typ>\<open>Real.real\<close>, Const (rel, _) $ f $ g) => ((
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    38
      let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    39
        val (f, g) = apply2 (fn t => Abs (x, \<^typ>\<open>Real.real\<close>, t)) (f, g)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    40
        val _ = if rel = \<^const_name>\<open>Orderings.less\<close> 
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    41
                    orelse rel = \<^const_name>\<open>Orderings.less_eq\<close> then ()
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    42
                  else raise TERM ("prove_eventually_at_top", [p])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    43
        val ctxt = get_ctxt ectxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    44
        val basis = Asymptotic_Basis.default_basis
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    45
        val ([thm1, thm2], basis) = Exp.expand_terms ectxt [f, g] basis
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    46
        val thm = Exp.prove_eventually_less ectxt (thm1, thm2, basis)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    47
      in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    48
        HEADGOAL (resolve_tac ctxt [thm, thm RS @{thm eventually_lt_imp_eventually_le}])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    49
      end)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    50
    handle TERM _ => no_tac | THM _ => no_tac)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    51
  | _ => raise TERM ("prove_eventually_at_top", [p])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    52
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    53
fun prove_landau ectxt l f g =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    54
  let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    55
    val ctxt = get_ctxt ectxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    56
    val l' = l |> dest_Const |> fst
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    57
    val basis = Asymptotic_Basis.default_basis
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    58
    val ([thm1, thm2], basis) = Exp.expand_terms ectxt [f, g] basis
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    59
    val prover =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    60
      case l' of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    61
        \<^const_name>\<open>smallo\<close> => Exp.prove_smallo
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    62
      | \<^const_name>\<open>bigo\<close> => Exp.prove_bigo
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    63
      | \<^const_name>\<open>bigtheta\<close> => Exp.prove_bigtheta
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    64
      | \<^const_name>\<open>asymp_equiv\<close> => Exp.prove_asymp_equiv
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    65
      | _ => raise TERM ("prove_landau", [f, g])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    66
  in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    67
    HEADGOAL (resolve_tac ctxt [prover ectxt (thm1, thm2, basis)])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    68
  end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    69
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    70
val filter_substs = 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    71
  @{thms at_left_to_top at_right_to_top at_left_to_top' at_right_to_top' at_bot_mirror}
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    72
val filterlim_substs = map (fn thm => thm RS @{thm filterlim_conv_filtermap}) filter_substs
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    73
val eventually_substs = map (fn thm => thm RS @{thm eventually_conv_filtermap}) filter_substs
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    74
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    75
fun preproc_exp_log_natintfun_conv ctxt =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    76
  let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    77
    fun reify_power_conv x _ ct =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    78
      let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    79
        val thm = Conv.rewr_conv @{thm reify_power} ct
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    80
      in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    81
        if exists_subterm (fn t => t aconv x) (Thm.term_of ct |> dest_arg) then
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    82
          thm
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    83
        else
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    84
          raise CTERM ("reify_power_conv", [ct])
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    85
      end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    86
    fun conv (x, ctxt) =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    87
      let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    88
        val thms1 =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    89
           Named_Theorems.get ctxt \<^named_theorems>\<open>real_asymp_nat_reify\<close>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    90
        val thms2 =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
    91
           Named_Theorems.get ctxt \<^named_theorems>\<open>real_asymp_int_reify\<close>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    92
        val ctxt' = put_simpset HOL_basic_ss ctxt addsimps (thms1 @ thms2)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    93
      in
74560
5c8177fd1295 clarified modules;
wenzelm
parents: 69597
diff changeset
    94
        Conv.repeat_changed_conv
5c8177fd1295 clarified modules;
wenzelm
parents: 69597
diff changeset
    95
         (Simplifier.rewrite ctxt'
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    96
          then_conv Conv.bottom_conv (Conv.try_conv o reify_power_conv (Thm.term_of x)) ctxt)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    97
      end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    98
  in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
    99
    Thm.eta_long_conversion
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   100
    then_conv Conv.abs_conv conv ctxt 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   101
    then_conv Thm.eta_conversion
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   102
  end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   103
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   104
fun preproc_tac ctxt =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   105
  let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   106
    fun natint_tac {context = ctxt, concl = goal, ...} =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   107
      let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   108
        val conv = preproc_exp_log_natintfun_conv ctxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   109
        val conv =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   110
          case Thm.term_of goal of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   111
            \<^term>\<open>HOL.Trueprop\<close> $ t => (case t of
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   112
              Const (\<^const_name>\<open>Filter.filterlim\<close>, _) $ _ $ _ $ _ =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   113
                Conv.fun_conv (Conv.fun_conv (Conv.arg_conv conv))
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   114
            | Const (\<^const_name>\<open>Filter.eventually\<close>, _) $ _ $ _ =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   115
                Conv.fun_conv (Conv.arg_conv conv)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   116
            | Const (\<^const_name>\<open>Set.member\<close>, _) $ _ $ (_ $ _ $ _) =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   117
                Conv.combination_conv (Conv.arg_conv conv) (Conv.arg_conv conv)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   118
            | Const (\<^const_name>\<open>Landau_Symbols.asymp_equiv\<close>, _) $ _ $ _ $ _ =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   119
                Conv.combination_conv (Conv.fun_conv (Conv.arg_conv conv)) conv
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   120
            | _ => Conv.all_conv)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   121
          | _ => Conv.all_conv
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   122
      in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   123
        HEADGOAL (CONVERSION (Conv.try_conv (Conv.arg_conv conv)))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   124
      end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   125
  in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   126
    SELECT_GOAL (Local_Defs.unfold_tac ctxt @{thms real_asymp_preproc})
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   127
    THEN' TRY o resolve_tac ctxt @{thms real_asymp_real_nat_transfer real_asymp_real_int_transfer}
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   128
    THEN' TRY o resolve_tac ctxt 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   129
      @{thms filterlim_at_leftI filterlim_at_rightI filterlim_atI' landau_reduce_to_top}
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   130
    THEN' TRY o resolve_tac ctxt @{thms smallo_imp_smallomega bigo_imp_bigomega}
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   131
    THEN' TRY o Subgoal.FOCUS_PREMS natint_tac ctxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   132
    THEN' TRY o resolve_tac ctxt @{thms real_asymp_nat_intros real_asymp_int_intros}
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   133
  end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   134
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   135
datatype ('a, 'b) sum = Inl of 'a | Inr of 'b
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   136
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   137
fun prove_eventually ectxt p filter =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   138
  case filter of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   139
    \<^term>\<open>Filter.at_top :: real filter\<close> => (prove_eventually_at_top ectxt p
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   140
      handle TERM _ => no_tac | THM _ => no_tac)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   141
  | _ => HEADGOAL (CONVERSION (Conv.rewrs_conv eventually_substs) 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   142
         THEN' tac' (#verbose (#ctxt ectxt)) (Inr ectxt))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   143
and prove_limit ectxt f filter filter' =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   144
  case filter' of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   145
    \<^term>\<open>Filter.at_top :: real filter\<close> => (prove_limit_at_top ectxt f filter 
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   146
      handle TERM _ => no_tac | THM _ => no_tac)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   147
  | _ => HEADGOAL (CONVERSION (Conv.rewrs_conv filterlim_substs) 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   148
         THEN' tac' (#verbose (#ctxt ectxt)) (Inr ectxt))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   149
and tac' verbose ctxt_or_ectxt =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   150
  let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   151
    val ctxt = case ctxt_or_ectxt of Inl ctxt => ctxt | Inr ectxt => get_ctxt ectxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   152
    fun tac {context = ctxt, prems, concl = goal, ...} =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   153
      (if verbose then print_tac ctxt "real_asymp: Goal after preprocessing" else all_tac) THEN
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   154
      let
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   155
        val ectxt = 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   156
          case ctxt_or_ectxt of 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   157
            Inl _ => 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   158
              Multiseries_Expansion.mk_eval_ctxt ctxt |> add_facts prems |> set_verbose verbose
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   159
          | Inr ectxt => ectxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   160
      in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   161
        case Thm.term_of goal of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   162
          \<^term>\<open>HOL.Trueprop\<close> $ t => ((case t of
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   163
            \<^term>\<open>Filter.filterlim :: (real \<Rightarrow> real) \<Rightarrow> _\<close> $ f $ filter $ filter' =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   164
              (prove_limit ectxt f filter filter' handle TERM _ => no_tac | THM _ => no_tac)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   165
          | \<^term>\<open>Filter.eventually :: (real \<Rightarrow> bool) \<Rightarrow> _\<close> $ p $ filter =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   166
              (prove_eventually ectxt p filter handle TERM _ => no_tac | THM _ => no_tac)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   167
          | \<^term>\<open>Set.member :: (real => real) => _\<close> $ f $ 
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   168
              (l $ \<^term>\<open>at_top :: real filter\<close> $ g) =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   169
                (prove_landau ectxt l f g handle TERM _ => no_tac | THM _ => no_tac)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68630
diff changeset
   170
          | (l as \<^term>\<open>Landau_Symbols.asymp_equiv :: (real\<Rightarrow>real)\<Rightarrow>_\<close>) $ f $ _ $ g =>
68630
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   171
              (prove_landau ectxt l f g handle TERM _ => no_tac | THM _ => no_tac)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   172
          | _ => no_tac) THEN distinct_subgoals_tac)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   173
        | _ => no_tac
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   174
      end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   175
    fun tac' i = Subgoal.FOCUS_PREMS tac ctxt i handle TERM _ => no_tac | THM _ => no_tac
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   176
    val at_tac =
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   177
      HEADGOAL (resolve_tac ctxt 
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   178
        @{thms filterlim_split_at eventually_at_left_at_right_imp_at landau_at_top_imp_at
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   179
                 asymp_equiv_at_top_imp_at})
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   180
      THEN PARALLEL_ALLGOALS tac'
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   181
  in
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   182
    (preproc_tac ctxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   183
     THEN' preproc_tac ctxt
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   184
     THEN' (SELECT_GOAL at_tac ORELSE' tac'))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   185
    THEN_ALL_NEW (TRY o SELECT_GOAL (SOLVE (HEADGOAL (Simplifier.asm_full_simp_tac ctxt))))
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   186
  end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   187
and tac verbose ctxt = tac' verbose (Inl ctxt)
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   188
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   189
end
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   190
c55f6f0b3854 Added Real_Asymp package
Manuel Eberl <eberlm@in.tum.de>
parents:
diff changeset
   191
structure Real_Asymp_Basic = Real_Asymp(Multiseries_Expansion_Basic)