src/HOL/Factorial.thy
changeset 67399 eab6ce8368fa
parent 66806 a4e82b58d833
child 67411 3f4b0c84630f
equal deleted inserted replaced
67398:5eb932e604a2 67399:eab6ce8368fa
   387 
   387 
   388 
   388 
   389 subsection \<open>Misc\<close>
   389 subsection \<open>Misc\<close>
   390 
   390 
   391 lemma fact_code [code]:
   391 lemma fact_code [code]:
   392   "fact n = (of_nat (fold_atLeastAtMost_nat (op *) 2 n 1) :: 'a::semiring_char_0)"
   392   "fact n = (of_nat (fold_atLeastAtMost_nat (( * )) 2 n 1) :: 'a::semiring_char_0)"
   393 proof -
   393 proof -
   394   have "fact n = (of_nat (\<Prod>{1..n}) :: 'a)"
   394   have "fact n = (of_nat (\<Prod>{1..n}) :: 'a)"
   395     by (simp add: fact_prod)
   395     by (simp add: fact_prod)
   396   also have "\<Prod>{1..n} = \<Prod>{2..n}"
   396   also have "\<Prod>{1..n} = \<Prod>{2..n}"
   397     by (intro prod.mono_neutral_right) auto
   397     by (intro prod.mono_neutral_right) auto
   398   also have "\<dots> = fold_atLeastAtMost_nat (op *) 2 n 1"
   398   also have "\<dots> = fold_atLeastAtMost_nat (( * )) 2 n 1"
   399     by (simp add: prod_atLeastAtMost_code)
   399     by (simp add: prod_atLeastAtMost_code)
   400   finally show ?thesis .
   400   finally show ?thesis .
   401 qed
   401 qed
   402 
   402 
   403 lemma pochhammer_code [code]:
   403 lemma pochhammer_code [code]: