Theory MLTL_Language_Partition_Codegen

theory MLTL_Language_Partition_Codegen

imports MLTL_Language_Partition_Algorithm Show.Shows_Literal

begin

section ‹Pretty Parsing›

fun nat_to_string:: "nat  string" where 
"nat_to_string n = String.explode (Shows_Literal.showl n)"

fun mltl_to_literal_aux:: "nat mltl  string" where 
  "mltl_to_literal_aux Truem = ''true''"
| "mltl_to_literal_aux Falsem = ''false''"
| "mltl_to_literal_aux (Propm (p)) = ''p''@(nat_to_string p)"
| "mltl_to_literal_aux (Notm φ) = ''(!''@(mltl_to_literal_aux φ)@'')''"
| "mltl_to_literal_aux (φ Andm ψ) = ''('' @ (mltl_to_literal_aux φ) @ '' & '' @ (mltl_to_literal_aux ψ) @ '')''"
| "mltl_to_literal_aux (φ Orm ψ) = ''('' @ (mltl_to_literal_aux φ) @ '' | '' @ (mltl_to_literal_aux ψ) @ '')''"
| "mltl_to_literal_aux (Gm [a,b] φ) = ''(G['' @ (nat_to_string a) @ '','' @ (nat_to_string b) @ ''] '' @ (mltl_to_literal_aux φ) @ '')''"
| "mltl_to_literal_aux (Fm [a,b] φ) = ''(F['' @ (nat_to_string a) @ '','' @ (nat_to_string b) @ ''] '' @ (mltl_to_literal_aux φ) @ '')''"
| "mltl_to_literal_aux (φ Rm [a,b] ψ) = ''('' @ (mltl_to_literal_aux φ) @ '' R['' @ (nat_to_string a) @ '','' @ (nat_to_string b) @ ''] '' @ (mltl_to_literal_aux ψ) @ '')''"
| "mltl_to_literal_aux (φ Um [a,b] ψ) = ''('' @ (mltl_to_literal_aux φ) @ '' U['' @ (nat_to_string a) @ '','' @ (nat_to_string b) @ ''] '' @ (mltl_to_literal_aux ψ) @ '')''"

fun mltl_to_literal:: "nat mltl  String.literal"
  where "mltl_to_literal φ = String.implode (mltl_to_literal_aux φ)"

value "mltl_to_literal ((Propm (3) Andm Truem) Um[3,4] Falsem) = 
       STR ''((p3 & true) U[3,4] false)''"

section "Code Export"

export_code LP_mltl mltl_to_literal in Haskell module_name LP_mltl

end