diff -r b98cd131e2b5 -r 5b5656a63bd6 src/HOL/ex/Parallel_Example.thy --- a/src/HOL/ex/Parallel_Example.thy Tue Oct 06 17:46:07 2015 +0200 +++ b/src/HOL/ex/Parallel_Example.thy Tue Oct 06 17:47:28 2015 +0200 @@ -1,23 +1,23 @@ -section {* A simple example demonstrating parallelism for code generated towards Isabelle/ML *} +section \A simple example demonstrating parallelism for code generated towards Isabelle/ML\ theory Parallel_Example imports Complex_Main "~~/src/HOL/Library/Parallel" "~~/src/HOL/Library/Debug" begin -subsection {* Compute-intensive examples. *} +subsection \Compute-intensive examples.\ -subsubsection {* Fragments of the harmonic series *} +subsubsection \Fragments of the harmonic series\ definition harmonic :: "nat \ rat" where "harmonic n = listsum (map (\n. 1 / of_nat n) [1..The sieve of Erathostenes\ -text {* +text \ The attentive reader may relate this ad-hoc implementation to the arithmetic notion of prime numbers as a little exercise. -*} +\ primrec mark :: "nat \ nat \ bool list \ bool list" where "mark _ _ [] = []" @@ -34,7 +34,7 @@ | p#ps' \ let n = m - length ps' in takeWhile Not ps @ p # sieve m (mark n n ps'))" by pat_completeness auto -termination -- {* tuning of this proof is left as an exercise to the reader *} +termination -- \tuning of this proof is left as an exercise to the reader\ apply (relation "measure (length \ snd)") apply rule apply (auto simp add: length_dropWhile_le) @@ -56,7 +56,7 @@ "list_primes (Suc n) = natify 1 (sieve n (False # replicate n True))" -subsubsection {* Naive factorisation *} +subsubsection \Naive factorisation\ function factorise_from :: "nat \ nat \ nat list" where "factorise_from k n = (if 1 < k \ k \ n @@ -67,7 +67,7 @@ else [])" by pat_completeness auto -termination factorise_from -- {* tuning of this proof is left as an exercise to the reader *} +termination factorise_from -- \tuning of this proof is left as an exercise to the reader\ term measure apply (relation "measure (\(k, n). 2 * n - k)") apply (auto simp add: prod_eq_iff) @@ -80,7 +80,7 @@ "factorise n = factorise_from 2 n" -subsection {* Concurrent computation via futures *} +subsection \Concurrent computation via futures\ definition computation_harmonic :: "unit \ rat" where "computation_harmonic _ = Debug.timing (STR ''harmonic example'') harmonic 300"