137 fun subst_v t' = map_aterms (fn t as Free (w, _) => if v = w then t' else t | t => t); |
137 fun subst_v t' = map_aterms (fn t as Free (w, _) => if v = w then t' else t | t => t); |
138 val t_rhs = lambda t_k proto_t_rhs; |
138 val t_rhs = lambda t_k proto_t_rhs; |
139 val eqs0 = [subst_v @{term "0::code_numeral"} eq, |
139 val eqs0 = [subst_v @{term "0::code_numeral"} eq, |
140 subst_v (@{term "Suc_code_numeral"} $ t_k) eq]; |
140 subst_v (@{term "Suc_code_numeral"} $ t_k) eq]; |
141 val eqs1 = map (Pattern.rewrite_term thy rew_ts []) eqs0; |
141 val eqs1 = map (Pattern.rewrite_term thy rew_ts []) eqs0; |
142 val ((_, eqs2), lthy') = Primrec.add_primrec_simple |
142 val ((_, (_, eqs2)), lthy') = Primrec.add_primrec_simple |
143 [((Binding.conceal (Binding.name random_aux), T), NoSyn)] eqs1 lthy; |
143 [((Binding.conceal (Binding.name random_aux), T), NoSyn)] eqs1 lthy; |
144 val cT_random_aux = inst pt_random_aux; |
144 val cT_random_aux = inst pt_random_aux; |
145 val cT_rhs = inst pt_rhs; |
145 val cT_rhs = inst pt_rhs; |
146 val rule = @{thm random_aux_rec} |
146 val rule = @{thm random_aux_rec} |
147 |> Drule.instantiate ([(aT, icT)], |
147 |> Drule.instantiate ([(aT, icT)], |
148 [(cT_random_aux, cert t_random_aux), (cT_rhs, cert t_rhs)]); |
148 [(cT_random_aux, cert t_random_aux), (cT_rhs, cert t_rhs)]); |
149 val tac = ALLGOALS (rtac rule) |
149 val tac = ALLGOALS (rtac rule) |
150 THEN ALLGOALS (simp_tac rew_ss) |
150 THEN ALLGOALS (simp_tac rew_ss) |
151 THEN (ALLGOALS (ProofContext.fact_tac (flat eqs2))) |
151 THEN (ALLGOALS (ProofContext.fact_tac eqs2)) |
152 val simp = Skip_Proof.prove lthy' [v] [] eq (K tac); |
152 val simp = Skip_Proof.prove lthy' [v] [] eq (K tac); |
153 in (simp, lthy') end; |
153 in (simp, lthy') end; |
154 |
154 |
155 end; |
155 end; |
156 |
156 |