I am trying to use https://github.com/dominique-unruh/scala-isabelle for parsing and decomposing the Isabelle terms and I am trying to decompose term - function declaration - from the formalization of quicksort https://isabelle.in.tum.de/library/HOL/HOL-Imperative_HOL/Imperative_Quicksort.html - this Isabelle code:
function quicksort :: "'a::{heap,linorder} array ⇒ nat ⇒ nat ⇒ unit Heap"
where
"quicksort arr left right =
(if (right > left) then
do {
pivotNewIndex ← partition arr left right;
pivotNewIndex ← assert (λx. left ≤ x ∧ x ≤ right) pivotNewIndex;
quicksort arr left (pivotNewIndex - 1);
quicksort arr (pivotNewIndex + 1) right
}
else return ())"
by pat_completeness auto
I am trying to use in Scala/Isabelle:
println("Before qs term")
val qs_term = Term(ctxt, "quicksort arr left right =" +
" (if (right > left) then" +
" do {" +
" pivotNewIndex ← partition arr left right;" +
" pivotNewIndex ← assert (λx. left ≤ x ∧ x ≤ right) pivotNewIndex;" +
" quicksort arr left (pivotNewIndex - 1);" +
" quicksort arr (pivotNewIndex + 1) right" +
" }" +
" else return ())")
println("After qs term")
I am checking the documentation for the Term class: https://javadoc.io/doc/de.unruh/scala-isabelle_2.13/latest/de/unruh/isabelle/pure/Term.html and I see that there is Const constructor for this Term:
sealed abstract class Term
final case class Const(name: String, typ: Typ) // Corresponds to ML constructor 'Const'
...
My question is: is the Isabelle function declaration an instance of Term with class constructor Const? And how can I cast my qs_term to class Const with the aim to access fields that are specific to Const? My aim is to do tree-search (DFS, BFS) over the class (taking Const class as the root object) and in such way to construct AST for this function declaration.