Extract abstract mathematical models from functional code (Haskell, OCaml, F#) for formal reasoning in Isabelle/HOL. Use when users need to: (1) Convert functional programs to Isabelle definitions, (2) Extract high-level algorithm essence from implementation code, (3) Generate formal specifications and properties from code, (4) Create verification-ready models that capture mathematical properties while abstracting away implementation details. Focuses on structural recursion, algebraic data types, higher-order functions, and invariant extraction.
92
91%
Does it follow best practices?
Impact
98%
1.11xAverage score across 3 eval scenarios
Passed
No findings from the security scan
Extract high-level mathematical models from functional code for formal reasoning in Isabelle/HOL.
This skill transforms functional programs (Haskell, OCaml, F#) into abstract mathematical models suitable for formal verification in Isabelle/HOL. The extraction focuses on the algorithm's mathematical essence—capturing core properties, invariants, and structural patterns while abstracting away language-specific implementation details.
Identify key elements:
Convert source language types to Isabelle datatypes:
-- Haskell
data Tree a = Leaf | Node a (Tree a) (Tree a)(* Isabelle *)
datatype 'a tree = Leaf | Node "'a" "'a tree" "'a tree"Choose the appropriate Isabelle construct:
For primitive recursion (terminates obviously):
fun length :: "'a list ⇒ nat" where
"length [] = 0" |
"length (x # xs) = 1 + length xs"For general recursion (needs termination proof):
function gcd :: "nat ⇒ nat ⇒ nat" where
"gcd m n = (if n = 0 then m else gcd n (m mod n))"
by pat_completeness auto
termination by (relation "measure snd") autoFor non-recursive definitions:
definition compose :: "('b ⇒ 'c) ⇒ ('a ⇒ 'b) ⇒ ('a ⇒ 'c)" where
"compose f g = (λx. f (g x))"Extract and formalize key properties as lemmas:
lemma length_append: "length (xs @ ys) = length xs + length ys"
lemma quicksort_permutes: "mset (quicksort xs) = mset xs"
lemma quicksort_sorted: "sorted (quicksort xs)"For stateful or accumulator-based functions, state what holds during computation:
fun sum_acc :: "int ⇒ int list ⇒ int" where
"sum_acc acc [] = acc" |
"sum_acc acc (x # xs) = sum_acc (acc + x) xs"
lemma sum_acc_correct: "sum_acc acc xs = acc + sum_list xs"Source: Recursive list operations Model: Isabelle list functions with length/permutation properties See: extraction_patterns.md
Source: Comparison-based sorting
Model: Functions with sorted and mset (permutation) properties
See: extraction_patterns.md
Source: Recursive tree traversals and folds Model: Isabelle datatypes with structural recursion See: extraction_patterns.md
Source: map, filter, fold, composition Model: Isabelle higher-order definitions with fusion lemmas See: extraction_patterns.md
Source: Functions that may fail (division, lookup) Model: Option types with case analysis See: extraction_patterns.md
Source: Accumulator-based functions Model: Functions with accumulator correctness lemmas See: extraction_patterns.md
Focus on high-level mathematical essence:
✓ Do extract:
✗ Don't extract:
Source (Haskell):
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (p:xs) = quicksort lesser ++ [p] ++ quicksort greater
where lesser = filter (< p) xs
greater = filter (>= p) xsExtracted Model (Isabelle):
fun quicksort :: "'a::linorder list ⇒ 'a list" where
"quicksort [] = []" |
"quicksort (p # xs) =
quicksort (filter (λx. x < p) xs) @ [p] @
quicksort (filter (λx. x ≥ p) xs)"
(* Key properties *)
lemma quicksort_permutes: "mset (quicksort xs) = mset xs"
lemma quicksort_sorted: "sorted (quicksort xs)"
lemma quicksort_correct:
"sorted (quicksort xs) ∧ mset (quicksort xs) = mset xs"Explanation:
Ord a to 'a::linordermset (multisets) to express permutation properties elegantlyArabelaTso/Skills-4-SE
4f38503
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.