theory SASP_Semantics imports Main begin section \Semantics of Fast-Downward's Multi-Valued Planning Tasks Language\ subsection \Syntax\ type_synonym name = string type_synonym ast_variable = "name \ nat option \ name list" (* var name, axiom layer, atom names *) type_synonym ast_variable_section = "ast_variable list" type_synonym ast_initial_state = "nat list" type_synonym ast_goal = "(nat \ nat) list" type_synonym ast_precond = "(nat \ nat)" type_synonym ast_effect = "ast_precond list \ nat \ nat option \ nat" type_synonym ast_operator = "name \ ast_precond list \ ast_effect list \ nat" type_synonym ast_operator_section = "ast_operator list" type_synonym ast_problem = "ast_variable_section \ ast_initial_state \ ast_goal \ ast_operator_section" type_synonym plan = "name list" subsubsection \Well-Formedness\ locale ast_problem = fixes problem :: ast_problem begin definition astDom :: ast_variable_section (* TODO: Dom \ Vars, D \ X*) where "astDom \ case problem of (D,I,G,\) \ D" definition astI :: ast_initial_state where "astI \ case problem of (D,I,G,\) \ I" definition astG :: ast_goal where "astG \ case problem of (D,I,G,\) \ G" definition ast\ :: ast_operator_section where "ast\ \ case problem of (D,I,G,\) \ \" definition "numVars \ length astDom" definition "numVals x \ length (snd (snd (astDom!x)))" definition "wf_partial_state ps \ distinct (map fst ps) \ (\(x,v) \ set ps. x < numVars \ v < numVals x)" definition wf_operator :: "ast_operator \ bool" where "wf_operator \ \(name, pres, effs, cost). wf_partial_state pres \ distinct (map (\(_, v, _, _). v) effs) \ \This may be too restrictive\ \ (\(epres,x,vp,v)\set effs. wf_partial_state epres \ x < numVars \ v < numVals x \ (case vp of None \ True | Some v \ v \ \Initial state\ length astI = numVars \ (\x \Goal\ \ wf_partial_state astG \ \Operators\ \ (distinct (map fst ast\)) \ (\\\set ast\. wf_operator \) " end locale wf_ast_problem = ast_problem + assumes wf: well_formed begin lemma wf_initial: "length astI = numVars" "\x)" "\\\set ast\. wf_operator \" using wf unfolding well_formed_def by auto end subsection \Semantics as Transition System\ type_synonym state = "nat \ nat" type_synonym pstate = "nat \ nat" context ast_problem begin definition Dom :: "nat set" where "Dom = {0.. {0.. { s. dom s = Dom \ (\x\Dom. the (s x) \ range_of_var x) }" definition I :: state where "I v \ if v state set" where "subsuming_states partial \ { s\valid_states. partial \\<^sub>m s }" definition G :: "state set" where "G \ subsuming_states (map_of astG)" end definition implicit_pres :: "ast_effect list \ ast_precond list" where "implicit_pres effs \ map (\(_,v,vpre,_). (v,the vpre)) (filter (\(_,_,vpre,_). vpre\None) effs)" context ast_problem begin definition lookup_operator :: "name \ ast_operator option" where "lookup_operator name \ find (\(n,_,_,_). n=name) ast\" definition enabled :: "name \ state \ bool" where "enabled name s \ case lookup_operator name of Some (_,pres,effs,_) \ s\subsuming_states (map_of pres) \ s\subsuming_states (map_of (implicit_pres effs)) | None \ False" definition eff_enabled :: "state \ ast_effect \ bool" where "eff_enabled s \ \(pres,_,_,_). s\subsuming_states (map_of pres)" definition execute :: "name \ state \ state" where "execute name s \ case lookup_operator name of Some (_,_,effs,_) \ s ++ map_of (map (\(_,x,_,v). (x,v)) (filter (eff_enabled s) effs)) | None \ undefined " fun path_to where "path_to s [] s' \ s'=s" | "path_to s (\#\s) s' \ enabled \ s \ path_to (execute \ s) \s s'" definition valid_plan :: "plan \ bool" where "valid_plan \s \ \s'\G. path_to I \s s'" end (* Next steps: * well-formed stuff * Executable SAS+ validator (well_formed and execute function) *) subsubsection \Preservation of well-formedness\ context wf_ast_problem begin lemma I_valid: "I \ valid_states" using wf_initial unfolding valid_states_def Dom_def I_def range_of_var_def by (auto split:if_splits) lemma lookup_operator_wf: assumes "lookup_operator name = Some \" shows "wf_operator \" "fst \ = name" proof - obtain name' pres effs cost where [simp]: "\=(name',pres,effs,cost)" by (cases \) hence [simp]: "name'=name" and IN_AST: "(name,pres,effs,cost) \ set ast\" using assms unfolding lookup_operator_def apply - apply (metis (mono_tags, lifting) case_prodD find_Some_iff) by (metis (mono_tags, lifting) case_prodD find_Some_iff nth_mem) from IN_AST show WF: "wf_operator \" "fst \ = name" unfolding enabled_def using wf_operators by auto qed lemma execute_preserves_valid: assumes "s\valid_states" assumes "enabled name s" shows "execute name s \ valid_states" proof - from \enabled name s\ obtain name' pres effs cost where [simp]: "lookup_operator name = Some (name',pres,effs,cost)" unfolding enabled_def by (auto split: option.splits) from lookup_operator_wf[OF this] have WF: "wf_operator (name,pres,effs,cost)" by simp have X1: "s ++ m \ valid_states" if "\x v. m x = Some v \ x vs\valid_states\ by (auto simp: valid_states_def Dom_def range_of_var_def map_add_def dom_def split: option.splits) have X2: "x(_, x, _, y). (x, y)) (filter (eff_enabled s) effs)) x = Some v" for x v proof - from that obtain epres vp where "(epres,x,vp,v) \ set effs" by (auto dest!: map_of_SomeD) with WF show "xvalid_states" assumes "path_to s \s s'" shows "s'\valid_states" using assms by (induction s \s s' rule: path_to.induct) (auto simp: execute_preserves_valid) end end