src/Tools/isac/Knowledge/DiffApp.thy
author Walther Neuper <wneuper@ist.tugraz.at>
Sat, 22 Jun 2019 14:34:06 +0200
changeset 59551 6ea6d9c377a0
parent 59545 4035ec339062
child 59552 ab7955d2ead3
permissions -rw-r--r--
funpack: remove code unnecessary after switch to partial_function, partially
neuper@37906
     1
(* application of differential calculus
neuper@37954
     2
   Walther Neuper 2002
neuper@37954
     3
   (c) due to copyright terms
neuper@37906
     4
*)
neuper@37906
     5
neuper@37954
     6
theory DiffApp imports Diff begin
neuper@37906
     7
neuper@37906
     8
consts
neuper@37906
     9
neuper@37906
    10
  dummy :: real
neuper@37906
    11
neuper@37906
    12
(*for script Maximum_value*)
neuper@37906
    13
  filterVar :: "[real, 'a list] => 'a list"
neuper@37906
    14
neuper@52148
    15
axiomatization where
neuper@52148
    16
  filterVar_Nil:		"filterVar v []     = []" and
neuper@37995
    17
  filterVar_Const:	"filterVar v (x#xs) =                       
neuper@41905
    18
			 (if (v : set (Vars x)) then x#(filterVar v xs)  
neuper@37954
    19
			                    else filterVar v xs)   "
wneuper@59472
    20
text \<open>WN.6.5.03: old decisions in this file partially are being changed
neuper@37954
    21
  in a quick-and-dirty way to make scripts run: Maximum_value,
neuper@37954
    22
  Make_fun_by_new_variable, Make_fun_by_explicit.
neuper@37954
    23
found to be reconsidered:
neuper@37954
    24
- descriptions (Descript.thy)
neuper@37954
    25
- penv: really need term list; or just rerun the whole example with num/var
neuper@37954
    26
- mk_arg, itms2args ... env in script different from penv ?
neuper@37954
    27
- L = SubProblem eq ... show some vars on the worksheet ? (other means for
neuper@37954
    28
  referencing are labels (no on worksheet))
neuper@37954
    29
neuper@37954
    30
WN.6.5.03 quick-and-dirty: mk_arg, itms2args just make most convenient env
neuper@37954
    31
  from penv as is.    
wneuper@59472
    32
\<close>
neuper@37954
    33
wneuper@59472
    34
ML \<open>
neuper@37972
    35
val thy = @{theory};
neuper@37972
    36
s1210629013@55444
    37
val eval_rls = prep_rls' (
wneuper@59416
    38
  Rule.Rls {id = "eval_rls", preconds = [], rew_ord = ("termlessI", termlessI), 
wneuper@59416
    39
    erls = Rule.e_rls, srls = Rule.Erls, calc = [], errpatts = [],
wneuper@59416
    40
    rules = [Rule.Thm ("refl", TermC.num_str @{thm refl}),
wneuper@59416
    41
      Rule.Thm ("order_refl", TermC.num_str @{thm order_refl}),
wneuper@59416
    42
      Rule.Thm ("radd_left_cancel_le", TermC.num_str @{thm radd_left_cancel_le}),
wneuper@59416
    43
      Rule.Thm ("not_true", TermC.num_str @{thm not_true}),
wneuper@59416
    44
      Rule.Thm ("not_false", TermC.num_str @{thm not_false}),
wneuper@59416
    45
      Rule.Thm ("and_true", TermC.num_str @{thm and_true}),
wneuper@59416
    46
      Rule.Thm ("and_false", TermC.num_str @{thm and_false}),
wneuper@59416
    47
      Rule.Thm ("or_true", TermC.num_str @{thm or_true}),
wneuper@59416
    48
      Rule.Thm ("or_false", TermC.num_str @{thm or_false}),
wneuper@59416
    49
      Rule.Thm ("and_commute", TermC.num_str @{thm and_commute}),
wneuper@59416
    50
      Rule.Thm ("or_commute", TermC.num_str @{thm or_commute}),
neuper@52139
    51
      
wneuper@59416
    52
      Rule.Calc ("Orderings.ord_class.less", eval_equ "#less_"),
wneuper@59416
    53
      Rule.Calc ("Orderings.ord_class.less_eq", eval_equ "#less_equal_"),
neuper@52139
    54
      
wneuper@59416
    55
      Rule.Calc ("Atools.ident", eval_ident "#ident_"),    
wneuper@59416
    56
      Rule.Calc ("Atools.is'_const", eval_const "#is_const_"),
wneuper@59416
    57
      Rule.Calc ("Atools.occurs'_in", eval_occurs_in ""),    
wneuper@59491
    58
      Rule.Calc ("Tools.matches", Tools.eval_matches "")],
wneuper@59416
    59
    scr = Rule.Prog ((Thm.term_of o the o (TermC.parse thy)) "empty_script")
wneuper@59406
    60
    });
wneuper@59472
    61
\<close>
wneuper@59472
    62
setup \<open>KEStore_Elems.add_rlss [("eval_rls", (Context.theory_name @{theory}, eval_rls))]\<close>
neuper@37954
    63
neuper@37954
    64
(** problem types **)
wneuper@59472
    65
setup \<open>KEStore_Elems.add_pbts
wneuper@59406
    66
  [(Specify.prep_pbt thy "pbl_fun_max" [] Celem.e_pblID
s1210629013@55339
    67
      (["maximum_of","function"],
s1210629013@55339
    68
        [("#Given" ,["fixedValues f_ix"]),
s1210629013@55339
    69
          ("#Find"  ,["maximum m_m","valuesFor v_s"]),
s1210629013@55339
    70
          ("#Relate",["relations r_s"])],
wneuper@59416
    71
        Rule.e_rls, NONE, [])),
wneuper@59406
    72
    (Specify.prep_pbt thy "pbl_fun_make" [] Celem.e_pblID
wneuper@59406
    73
      (["make","function"],
s1210629013@55339
    74
        [("#Given" ,["functionOf f_f","boundVariable v_v","equalities eqs"]),
s1210629013@55339
    75
          ("#Find"  ,["functionEq f_1"])],
wneuper@59416
    76
        Rule.e_rls, NONE, [])),
wneuper@59406
    77
    (Specify.prep_pbt thy "pbl_fun_max_expl" [] Celem.e_pblID
wneuper@59406
    78
      (["by_explicit","make","function"],
s1210629013@55339
    79
        [("#Given" ,["functionOf f_f","boundVariable v_v","equalities eqs"]),
s1210629013@55339
    80
          ("#Find"  ,["functionEq f_1"])],
wneuper@59416
    81
      Rule.e_rls, NONE, [["DiffApp","make_fun_by_explicit"]])),
wneuper@59406
    82
    (Specify.prep_pbt thy "pbl_fun_max_newvar" [] Celem.e_pblID
wneuper@59406
    83
      (["by_new_variable","make","function"],
s1210629013@55339
    84
        [("#Given" ,["functionOf f_f","boundVariable v_v","equalities eqs"]),
s1210629013@55339
    85
          (*WN.12.5.03: precond for distinction still missing*)
s1210629013@55339
    86
          ("#Find"  ,["functionEq f_1"])],
wneuper@59416
    87
      Rule.e_rls, NONE, [["DiffApp","make_fun_by_new_variable"]])),
wneuper@59406
    88
    (Specify.prep_pbt thy "pbl_fun_max_interv" [] Celem.e_pblID
wneuper@59406
    89
      (["on_interval","maximum_of","function"],
s1210629013@55339
    90
        [("#Given" ,["functionEq t_t","boundVariable v_v","interval i_tv"]),
s1210629013@55339
    91
          (*WN.12.5.03: precond for distinction still missing*)
s1210629013@55339
    92
          ("#Find"  ,["maxArgument v_0"])],
wneuper@59416
    93
      Rule.e_rls, NONE, [])),
wneuper@59406
    94
    (Specify.prep_pbt thy "pbl_tool" [] Celem.e_pblID
wneuper@59416
    95
      (["tool"], [], Rule.e_rls, NONE, [])),
wneuper@59406
    96
    (Specify.prep_pbt thy "pbl_tool_findvals" [] Celem.e_pblID
wneuper@59406
    97
      (["find_values","tool"],
s1210629013@55339
    98
        [("#Given" ,["maxArgument m_ax","functionEq f_f","boundVariable v_v"]),
s1210629013@55339
    99
          ("#Find"  ,["valuesFor v_ls"]),
s1210629013@55339
   100
          ("#Relate",["additionalRels r_s"])],
wneuper@59472
   101
      Rule.e_rls, NONE, []))]\<close>
s1210629013@55380
   102
neuper@37954
   103
neuper@37954
   104
(** methods, scripts not yet implemented **)
wneuper@59472
   105
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   106
    [Specify.prep_met thy "met_diffapp" [] Celem.e_metID
s1210629013@55373
   107
      (["DiffApp"], [],
wneuper@59416
   108
        {rew_ord'="tless_true", rls'=Atools_erls,calc = [], srls = Rule.e_rls, prls = Rule.e_rls,
s1210629013@55373
   109
          crls = Atools_erls, errpats = [], nrls = norm_Rational (*, asm_rls=[],asm_thm=[]*)},
wneuper@59545
   110
        @{thm refl})]
wneuper@59473
   111
\<close>
wneuper@59545
   112
wneuper@59504
   113
partial_function (tailrec) maximum_value ::
wneuper@59504
   114
  "bool list \<Rightarrow> real \<Rightarrow> bool list \<Rightarrow> real \<Rightarrow> real set \<Rightarrow> bool \<Rightarrow> bool list"
wneuper@59504
   115
  where
wneuper@59504
   116
"maximum_value f_ix m_m r_s v_v itv_v e_rr =
wneuper@59504
   117
 (let e_e = (hd o (filterVar m_m)) r_s;
wneuper@59504
   118
      t_t = if 1 < LENGTH r_s
wneuper@59504
   119
            then SubProblem (''DiffApp'', [''make'', ''function''],[''no_met''])
wneuper@59504
   120
                   [REAL m_m, REAL v_v, BOOL_LIST r_s]
wneuper@59504
   121
            else (hd r_s);
wneuper@59504
   122
      m_x = SubProblem (''DiffApp'', [''on_interval'', ''maximum_of'', ''function''],
wneuper@59504
   123
                [''DiffApp'', ''max_on_interval_by_calculus''])
wneuper@59504
   124
              [BOOL t_t, REAL v_v, REAL_SET itv_v]
wneuper@59504
   125
 in SubProblem (''DiffApp'',[''find_values'', ''tool''], [''Isac'', ''find_values''])
wneuper@59504
   126
      [REAL m_x, REAL (rhs t_t), REAL v_v, REAL m_m, BOOL_LIST (dropWhile (ident e_e) r_s)])"
wneuper@59473
   127
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   128
    [Specify.prep_met thy "met_diffapp_max" [] Celem.e_metID
wneuper@59406
   129
      (["DiffApp","max_by_calculus"],
s1210629013@55373
   130
        [("#Given" ,["fixedValues f_ix","maximum m_m","relations r_s", "boundVariable v_v",
s1210629013@55373
   131
              "interval i_tv","errorBound e_rr"]),
s1210629013@55373
   132
          ("#Find"  ,["valuesFor v_s"]),
s1210629013@55373
   133
          ("#Relate",[])],
wneuper@59416
   134
      {rew_ord'="tless_true",rls'=eval_rls,calc=[],srls=list_rls,prls=Rule.e_rls, crls = eval_rls,
s1210629013@55373
   135
        errpats = [], nrls = norm_Rational (*,  asm_rls=[],asm_thm=[]*)},
wneuper@59551
   136
      @{thm maximum_value.simps})]
wneuper@59473
   137
\<close>
wneuper@59545
   138
wneuper@59504
   139
partial_function (tailrec) make_fun_by_new_variable :: "real => real => bool list => bool"
wneuper@59504
   140
  where
wneuper@59504
   141
"make_fun_by_new_variable f_f v_v eqs =
wneuper@59504
   142
  (let h_h = (hd o (filterVar f_f)) eqs;
wneuper@59504
   143
       e_s = dropWhile (ident h_h) eqs;
wneuper@59504
   144
       v_s = dropWhile (ident f_f) (Vars h_h);
wneuper@59504
   145
       v_1 = NTH 1 v_s;
wneuper@59504
   146
       v_2 = NTH 2 v_s;
wneuper@59504
   147
       e_1 = (hd o (filterVar v_1)) e_s;
wneuper@59504
   148
       e_2 = (hd o (filterVar v_2)) e_s;
wneuper@59504
   149
       s_1 = SubProblem (''DiffApp'', [''univariate'', ''equation''], [''no_met''])
wneuper@59504
   150
                [BOOL e_1, REAL v_1];
wneuper@59504
   151
       s_2 = SubProblem (''DiffApp'', [''univariate'', ''equation''], [''no_met''])
wneuper@59504
   152
                [BOOL e_2, REAL v_2]
wneuper@59504
   153
  in Substitute [(v_1 = (rhs o hd) s_1), (v_2 = (rhs o hd) s_2)] h_h)"
wneuper@59473
   154
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   155
    [Specify.prep_met thy "met_diffapp_funnew" [] Celem.e_metID
wneuper@59406
   156
      (["DiffApp","make_fun_by_new_variable"],
s1210629013@55373
   157
        [("#Given" ,["functionOf f_f","boundVariable v_v","equalities eqs"]),
s1210629013@55373
   158
          ("#Find"  ,["functionEq f_1"])],
wneuper@59416
   159
        {rew_ord'="tless_true",rls'=eval_rls,srls=list_rls,prls=Rule.e_rls, calc=[], crls = eval_rls,
s1210629013@55373
   160
          errpats = [], nrls = norm_Rational(*,asm_rls=[],asm_thm=[]*)},
wneuper@59551
   161
        @{thm make_fun_by_new_variable.simps})]
wneuper@59473
   162
\<close>
wneuper@59545
   163
wneuper@59504
   164
partial_function (tailrec) make_fun_by_explicit :: "real => real => bool list => bool"
wneuper@59504
   165
  where
wneuper@59504
   166
"make_fun_by_explicit f_f v_v eqs =                                          
wneuper@59504
   167
 (let h_h = (hd o (filterVar f_f)) eqs;                           
wneuper@59504
   168
      e_1 = hd (dropWhile (ident h_h) eqs);                       
wneuper@59504
   169
      v_s = dropWhile (ident f_f) (Vars h_h);                     
wneuper@59504
   170
      v_1 = hd (dropWhile (ident v_v) v_s);                       
wneuper@59504
   171
      s_1 = SubProblem(''DiffApp'', [''univariate'', ''equation''], [''no_met''])
wneuper@59504
   172
              [BOOL e_1, REAL v_1]
wneuper@59504
   173
 in Substitute [(v_1 = (rhs o hd) s_1)] h_h)                      "
wneuper@59473
   174
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   175
    [Specify.prep_met thy "met_diffapp_funexp" [] Celem.e_metID
wneuper@59406
   176
      (["DiffApp","make_fun_by_explicit"],
s1210629013@55373
   177
        [("#Given" ,["functionOf f_f","boundVariable v_v","equalities eqs"]),
s1210629013@55373
   178
          ("#Find"  ,["functionEq f_1"])],
wneuper@59416
   179
        {rew_ord'="tless_true",rls'=eval_rls,calc=[],srls=list_rls,prls=Rule.e_rls, crls = eval_rls,
s1210629013@55373
   180
          errpats = [], nrls = norm_Rational (*, asm_rls=[],asm_thm=[]*)},
wneuper@59551
   181
        @{thm make_fun_by_explicit.simps})]
wneuper@59473
   182
\<close>
wneuper@59473
   183
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   184
    [Specify.prep_met thy "met_diffapp_max_oninterval" [] Celem.e_metID
wneuper@59406
   185
      (["DiffApp","max_on_interval_by_calculus"],
s1210629013@55373
   186
        [("#Given" ,["functionEq t_t","boundVariable v_v","interval i_tv"(*, "errorBound e_rr"*)]),
s1210629013@55373
   187
          ("#Find"  ,["maxArgument v_0"])],
wneuper@59416
   188
      {rew_ord'="tless_true",rls'=eval_rls,calc=[],srls = Rule.e_rls,prls=Rule.e_rls, crls = eval_rls,
s1210629013@55373
   189
        errpats = [], nrls = norm_Rational (*, asm_rls=[],asm_thm=[]*)},
wneuper@59545
   190
      @{thm refl}),
wneuper@59406
   191
    Specify.prep_met thy "met_diffapp_findvals" [] Celem.e_metID
wneuper@59406
   192
      (["DiffApp","find_values"], [],
wneuper@59416
   193
        {rew_ord'="tless_true",rls'=eval_rls,calc=[],srls = Rule.e_rls,prls=Rule.e_rls, crls = eval_rls,
s1210629013@55373
   194
          errpats = [], nrls = norm_Rational(*, asm_rls = [], asm_thm = []*)},
wneuper@59545
   195
        @{thm refl})]
wneuper@59472
   196
\<close>
wneuper@59472
   197
ML \<open>
wneuper@59416
   198
val list_rls = Rule.append_rls "list_rls" list_rls
wneuper@59416
   199
  [Rule.Thm ("filterVar_Const", TermC.num_str @{thm filterVar_Const}),
wneuper@59416
   200
   Rule.Thm ("filterVar_Nil", TermC.num_str @{thm filterVar_Nil})];
wneuper@59472
   201
\<close>
wneuper@59472
   202
setup \<open>KEStore_Elems.add_rlss [("list_rls", (Context.theory_name @{theory}, list_rls))]\<close>
neuper@37906
   203
neuper@37906
   204
end