src/HOL/ex/Execute_Choice.thy
changeset 49929 70300f1b6835
parent 44899 95a53c01ed61
child 58889 5b7a9633cfa8
equal deleted inserted replaced
49928:e3f0a92de280 49929:70300f1b6835
    24     let l = (SOME l. l \<in> Mapping.keys m) in the (Mapping.lookup m l) + valuesum (Mapping.delete l m))"
    24     let l = (SOME l. l \<in> Mapping.keys m) in the (Mapping.lookup m l) + valuesum (Mapping.delete l m))"
    25 proof (cases "Mapping.is_empty m")
    25 proof (cases "Mapping.is_empty m")
    26   case True then show ?thesis by (simp add: is_empty_def keys_def valuesum_def)
    26   case True then show ?thesis by (simp add: is_empty_def keys_def valuesum_def)
    27 next
    27 next
    28   case False
    28   case False
    29   then have l: "\<exists>l. l \<in> dom (Mapping.lookup m)" by (auto simp add: is_empty_def keys_def)
    29   then have l: "\<exists>l. l \<in> dom (Mapping.lookup m)" unfolding is_empty_def by transfer auto
    30   then have "(let l = SOME l. l \<in> dom (Mapping.lookup m) in
    30   then have "(let l = SOME l. l \<in> dom (Mapping.lookup m) in
    31      the (Mapping.lookup m l) + (\<Sum>k \<in> dom (Mapping.lookup m) - {l}. the (Mapping.lookup m k))) =
    31      the (Mapping.lookup m l) + (\<Sum>k \<in> dom (Mapping.lookup m) - {l}. the (Mapping.lookup m k))) =
    32        (\<Sum>k \<in> dom (Mapping.lookup m). the (Mapping.lookup m k))"
    32        (\<Sum>k \<in> dom (Mapping.lookup m). the (Mapping.lookup m k))"
    33   proof (rule someI2_ex)
    33   proof (rule someI2_ex)
    34     fix l
    34     fix l
    39     then show "(let l = l
    39     then show "(let l = l
    40         in the (Mapping.lookup m l) + (\<Sum>k \<in> dom (Mapping.lookup m) - {l}. the (Mapping.lookup m k))) =
    40         in the (Mapping.lookup m l) + (\<Sum>k \<in> dom (Mapping.lookup m) - {l}. the (Mapping.lookup m k))) =
    41         (\<Sum>k \<in> dom (Mapping.lookup m). the (Mapping.lookup m k))"
    41         (\<Sum>k \<in> dom (Mapping.lookup m). the (Mapping.lookup m k))"
    42       by simp
    42       by simp
    43    qed
    43    qed
    44   then show ?thesis by (simp add: keys_def valuesum_def is_empty_def)
    44   then show ?thesis unfolding is_empty_def valuesum_def by transfer simp
    45 qed
    45 qed
    46 
    46 
    47 text {*
    47 text {*
    48   In the context of the else-branch we can show that the exact choice is
    48   In the context of the else-branch we can show that the exact choice is
    49   irrelvant; in practice, finding this point where choice becomes irrelevant is the
    49   irrelvant; in practice, finding this point where choice becomes irrelevant is the
    52 
    52 
    53 lemma valuesum_choice:
    53 lemma valuesum_choice:
    54   "finite (Mapping.keys M) \<Longrightarrow> x \<in> Mapping.keys M \<Longrightarrow> y \<in> Mapping.keys M \<Longrightarrow>
    54   "finite (Mapping.keys M) \<Longrightarrow> x \<in> Mapping.keys M \<Longrightarrow> y \<in> Mapping.keys M \<Longrightarrow>
    55     the (Mapping.lookup M x) + valuesum (Mapping.delete x M) =
    55     the (Mapping.lookup M x) + valuesum (Mapping.delete x M) =
    56     the (Mapping.lookup M y) + valuesum (Mapping.delete y M)"
    56     the (Mapping.lookup M y) + valuesum (Mapping.delete y M)"
    57   by (simp add: valuesum_def keys_def setsum_diff)
    57   unfolding valuesum_def  by transfer (simp add: setsum_diff)
    58 
    58 
    59 text {*
    59 text {*
    60   Given @{text valuesum_rec} as initial description, we stepwise refine it to something executable;
    60   Given @{text valuesum_rec} as initial description, we stepwise refine it to something executable;
    61   first, we formally insert the constructor @{term Mapping} and split the one equation into two,
    61   first, we formally insert the constructor @{term Mapping} and split the one equation into two,
    62   where the second one provides the necessary context:
    62   where the second one provides the necessary context: