src/HOL/Multivariate_Analysis/normarith.ML
changeset 44454 6f28f96a09bf
parent 43333 2bdec7f430d3
child 46497 89ccf66aa73d
equal deleted inserted replaced
44453:082edd97ffe1 44454:6f28f96a09bf
    24      Const(@{const_name norm}, _) $ _ => insert (eq_pair bool_eq (op aconvc)) (b,Thm.dest_arg t) acc
    24      Const(@{const_name norm}, _) $ _ => insert (eq_pair bool_eq (op aconvc)) (b,Thm.dest_arg t) acc
    25    | _ => acc
    25    | _ => acc
    26  fun find_normedterms t acc = case term_of t of
    26  fun find_normedterms t acc = case term_of t of
    27     @{term "op + :: real => _"}$_$_ =>
    27     @{term "op + :: real => _"}$_$_ =>
    28             find_normedterms (Thm.dest_arg1 t) (find_normedterms (Thm.dest_arg t) acc)
    28             find_normedterms (Thm.dest_arg1 t) (find_normedterms (Thm.dest_arg t) acc)
    29       | @{term "op * :: real => _"}$_$n =>
    29       | @{term "op * :: real => _"}$_$_ =>
    30             if not (is_ratconst (Thm.dest_arg1 t)) then acc else
    30             if not (is_ratconst (Thm.dest_arg1 t)) then acc else
    31             augment_norm (dest_ratconst (Thm.dest_arg1 t) >=/ Rat.zero)
    31             augment_norm (dest_ratconst (Thm.dest_arg1 t) >=/ Rat.zero)
    32                       (Thm.dest_arg t) acc
    32                       (Thm.dest_arg t) acc
    33       | _ => augment_norm true t acc
    33       | _ => augment_norm true t acc
    34 
    34 
    37     if c =/ Rat.zero then FuncUtil.Ctermfunc.empty else FuncUtil.Ctermfunc.map (fn _ => fn x => x */ c) t
    37     if c =/ Rat.zero then FuncUtil.Ctermfunc.empty else FuncUtil.Ctermfunc.map (fn _ => fn x => x */ c) t
    38  fun cterm_lincomb_add l r = FuncUtil.Ctermfunc.combine (curry op +/) (fn x => x =/ Rat.zero) l r
    38  fun cterm_lincomb_add l r = FuncUtil.Ctermfunc.combine (curry op +/) (fn x => x =/ Rat.zero) l r
    39  fun cterm_lincomb_sub l r = cterm_lincomb_add l (cterm_lincomb_neg r)
    39  fun cterm_lincomb_sub l r = cterm_lincomb_add l (cterm_lincomb_neg r)
    40  fun cterm_lincomb_eq l r = FuncUtil.Ctermfunc.is_empty (cterm_lincomb_sub l r)
    40  fun cterm_lincomb_eq l r = FuncUtil.Ctermfunc.is_empty (cterm_lincomb_sub l r)
    41 
    41 
       
    42 (*
    42  val int_lincomb_neg = FuncUtil.Intfunc.map (K Rat.neg)
    43  val int_lincomb_neg = FuncUtil.Intfunc.map (K Rat.neg)
       
    44 *)
    43  fun int_lincomb_cmul c t =
    45  fun int_lincomb_cmul c t =
    44     if c =/ Rat.zero then FuncUtil.Intfunc.empty else FuncUtil.Intfunc.map (fn _ => fn x => x */ c) t
    46     if c =/ Rat.zero then FuncUtil.Intfunc.empty else FuncUtil.Intfunc.map (fn _ => fn x => x */ c) t
    45  fun int_lincomb_add l r = FuncUtil.Intfunc.combine (curry op +/) (fn x => x =/ Rat.zero) l r
    47  fun int_lincomb_add l r = FuncUtil.Intfunc.combine (curry op +/) (fn x => x =/ Rat.zero) l r
       
    48 (*
    46  fun int_lincomb_sub l r = int_lincomb_add l (int_lincomb_neg r)
    49  fun int_lincomb_sub l r = int_lincomb_add l (int_lincomb_neg r)
    47  fun int_lincomb_eq l r = FuncUtil.Intfunc.is_empty (int_lincomb_sub l r)
    50  fun int_lincomb_eq l r = FuncUtil.Intfunc.is_empty (int_lincomb_sub l r)
       
    51 *)
    48 
    52 
    49 fun vector_lincomb t = case term_of t of
    53 fun vector_lincomb t = case term_of t of
    50    Const(@{const_name plus}, _) $ _ $ _ =>
    54    Const(@{const_name plus}, _) $ _ $ _ =>
    51     cterm_lincomb_add (vector_lincomb (Thm.dest_arg1 t)) (vector_lincomb (Thm.dest_arg t))
    55     cterm_lincomb_add (vector_lincomb (Thm.dest_arg1 t)) (vector_lincomb (Thm.dest_arg t))
    52  | Const(@{const_name minus}, _) $ _ $ _ =>
    56  | Const(@{const_name minus}, _) $ _ $ _ =>
    80 fun replacenegnorms cv t = case term_of t of
    84 fun replacenegnorms cv t = case term_of t of
    81   @{term "op + :: real => _"}$_$_ => binop_conv (replacenegnorms cv) t
    85   @{term "op + :: real => _"}$_$_ => binop_conv (replacenegnorms cv) t
    82 | @{term "op * :: real => _"}$_$_ =>
    86 | @{term "op * :: real => _"}$_$_ =>
    83     if dest_ratconst (Thm.dest_arg1 t) </ Rat.zero then arg_conv cv t else Thm.reflexive t
    87     if dest_ratconst (Thm.dest_arg1 t) </ Rat.zero then arg_conv cv t else Thm.reflexive t
    84 | _ => Thm.reflexive t
    88 | _ => Thm.reflexive t
       
    89 (*
    85 fun flip v eq =
    90 fun flip v eq =
    86   if FuncUtil.Ctermfunc.defined eq v
    91   if FuncUtil.Ctermfunc.defined eq v
    87   then FuncUtil.Ctermfunc.update (v, Rat.neg (FuncUtil.Ctermfunc.apply eq v)) eq else eq
    92   then FuncUtil.Ctermfunc.update (v, Rat.neg (FuncUtil.Ctermfunc.apply eq v)) eq else eq
       
    93 *)
    88 fun allsubsets s = case s of
    94 fun allsubsets s = case s of
    89   [] => [[]]
    95   [] => [[]]
    90 |(a::t) => let val res = allsubsets t in
    96 |(a::t) => let val res = allsubsets t in
    91                map (cons a) res @ res end
    97                map (cons a) res @ res end
    92 fun evaluate env lin =
    98 fun evaluate env lin =
   176  val apply_pthc = rewrs_conv @{thms pth_c};
   182  val apply_pthc = rewrs_conv @{thms pth_c};
   177  val apply_pthd = try_conv (rewr_conv @{thm pth_d});
   183  val apply_pthd = try_conv (rewr_conv @{thm pth_d});
   178 
   184 
   179 fun headvector t = case t of
   185 fun headvector t = case t of
   180   Const(@{const_name plus}, _)$
   186   Const(@{const_name plus}, _)$
   181    (Const(@{const_name scaleR}, _)$l$v)$r => v
   187    (Const(@{const_name scaleR}, _)$_$v)$_ => v
   182  | Const(@{const_name scaleR}, _)$l$v => v
   188  | Const(@{const_name scaleR}, _)$_$v => v
   183  | _ => error "headvector: non-canonical term"
   189  | _ => error "headvector: non-canonical term"
   184 
   190 
   185 fun vector_cmul_conv ct =
   191 fun vector_cmul_conv ct =
   186    ((apply_pth5 then_conv arg1_conv Numeral_Simprocs.field_comp_conv) else_conv
   192    ((apply_pth5 then_conv arg1_conv Numeral_Simprocs.field_comp_conv) else_conv
   187     (apply_pth6 then_conv binop_conv vector_cmul_conv)) ct
   193     (apply_pth6 then_conv binop_conv vector_cmul_conv)) ct