From 78eae084be5d88bef4c127969fa7d554662196d4 Mon Sep 17 00:00:00 2001 From: Amade Nemes Date: Sun, 28 Jan 2024 20:32:09 +0100 Subject: [PATCH] Change replace/2 to operate an facts. Implement reachability check. --- README.md | 2 +- examples/telingo/transformer.lp | 20 +- src/renopro/asp/add-children.lp | 314 +++++++------- src/renopro/asp/ast.lp | 118 ++--- src/renopro/asp/ast2id.lp | 174 ++++++++ src/renopro/asp/ast_fact2id.lp | 174 ++++++++ src/renopro/asp/new_replace.lp | 1 - src/renopro/asp/reachable.lp | 13 - src/renopro/asp/replace.lp | 404 ------------------ src/renopro/asp/replace_id.lp | 240 +++++++++++ src/renopro/asp/transform.lp | 20 +- src/renopro/asp/transformed_ast_fact2id.lp | 60 --- src/renopro/utils/codegen.py | 30 +- .../meta-telingo/outputs/output-body.lp | 14 +- .../meta-telingo/outputs/output-head.lp | 16 +- .../meta-telingo/outputs/telingo-output.lp | 8 +- .../meta-telingo/transform-add-externals.lp | 10 +- .../meta-telingo/transform-subprogram.lp | 10 +- .../transform-theory-to-symbolic.lp | 45 +- .../transform/not_bad/transform-decompose.lp | 2 +- tests/asp/transform/not_bad/transform.lp | 2 +- .../transform/prev_to_timepoints/transform.lp | 12 +- .../parse-unparsed-theory-terms.lp | 19 +- 23 files changed, 915 insertions(+), 793 deletions(-) create mode 100644 src/renopro/asp/ast2id.lp create mode 100644 src/renopro/asp/ast_fact2id.lp delete mode 100644 src/renopro/asp/new_replace.lp delete mode 100644 src/renopro/asp/reachable.lp delete mode 100644 src/renopro/asp/replace.lp create mode 100644 src/renopro/asp/replace_id.lp delete mode 100644 src/renopro/asp/transformed_ast_fact2id.lp diff --git a/README.md b/README.md index 62ecf14..f88f5ca 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ to reified facts or a reflected program via --input-format/-i and --output-format/-o, respectively. ```shell -$ echo "ast_operation(delete(function(Id,a,Terms));add(function(Id,b,Terms))) :- function(Id,a,Terms)." > meta.lp +$ echo "ast(delete(function(Id,a,Terms));add(function(Id,b,Terms))) :- function(Id,a,Terms)." > meta.lp $ echo "a." | renopro transform -m meta.lp #program base. b. diff --git a/examples/telingo/transformer.lp b/examples/telingo/transformer.lp index dd542ed..2fef05a 100644 --- a/examples/telingo/transformer.lp +++ b/examples/telingo/transformer.lp @@ -42,14 +42,14 @@ first(M,A,F) :- chain(M,A,F,O), not chain(M,A,_,F). % ----- Prop -ast_operation( +ast( add(variable(time_variable(term(T)),"T"); terms(T,N+1,variable(time_variable(term(T)))))) :- symbolic_atom(A,function(F)), function(F,Name,terms(T)), not modal(Name), max_arg_index(T,N). % ----- Prev -ast_operation( +ast( delete(function(F,N,T1)); add(function(F,Name,terms(T2)); variable(time_variable(function(F)),"T"); @@ -60,7 +60,7 @@ ast_operation( function(O,Name,terms(T2)), max_arg_index(T2,I), num(prev,A,Num). % ----- Next -ast_operation( +ast( delete(function(F,N,T1)); add(function(F,Name,terms(T2)); variable(time_variable(function(F)),"T"); @@ -71,7 +71,7 @@ ast_operation( function(O,Name,terms(T2)), max_arg_index(T2,I), num(next,A,Num). % ----- Time steps as new fact with interval 0..horizon -ast_operation( +ast( add(number(time_number_0,0)); add(number(time_number_h,horizon)); add(interval(time_interval,number(time_number_0),number(time_number_h))); @@ -81,11 +81,11 @@ ast_operation( add(literal(time_literal,"pos",symbolic_atom(time_symbol))); add(rule(time_rule,literal(time_literal),body_literals(time_body_literals)))). -ast_operation(add(statements(S,X+1,rule(time_rule)))) +ast(add(statements(S,X+1,rule(time_rule)))) :- program("base",_,statements(S)), max_statement_index(S,X). % Add time(T) in all rules -ast_operation( +ast( add(variable(time_variable(R),"T")); add(terms(time_terms_var(R),0,variable(time_variable(R)))); add(function(time_function_var(R),time,terms(time_terms_var(R)))); @@ -96,7 +96,7 @@ ast_operation( :- rule(R,_,body_literals(B)), max_lit_index(B,MAX). % Add initially(0). -ast_operation( +ast( add(number(init_number,0)); add(terms(init_terms,0,number(init_number))); add(function(init_function,initially,terms(init_terms))); @@ -104,13 +104,13 @@ ast_operation( add(literal(init_literal,"pos",symbolic_atom(init_symbol))); add(rule(init_rule,literal(init_literal),body_literals(init_body_literals)))). -ast_operation(add(statements(S,X+2,rule(init_rule)))) +ast(add(statements(S,X+2,rule(init_rule)))) :- program("base",_,statements(S)), max_statement_index(S,X). % Add finally(horizon). -ast_operation( +ast( add(number(final_number,horizon)); add(terms(final_terms,0,number(final_number))); add(function(final_function,finally,terms(final_terms))); @@ -118,7 +118,7 @@ ast_operation( add(literal(final_literal,"pos",symbolic_atom(final_symbol))); add(rule(final_rule,literal(final_literal),body_literals(final_body_literals)))). -ast_operation(add(statements(S,X+3,rule(final_rule)))) +ast(add(statements(S,X+3,rule(final_rule)))) :- program("base",_,statements(S)), max_statement_index(S,X). diff --git a/src/renopro/asp/add-children.lp b/src/renopro/asp/add-children.lp index e731337..181bca3 100644 --- a/src/renopro/asp/add-children.lp +++ b/src/renopro/asp/add-children.lp @@ -1,236 +1,236 @@ -% Add child relations for facts added via ast_operation add. +% Add child relations for facts added via ast add. -ast_operation(add(child(unary_operation(X0),Child))) - :- ast_operation(add(unary_operation(X0,X1,Child))). +ast(add(child(unary_operation(X0),Child))) + :- ast(add(unary_operation(X0,X1,Child))). -ast_operation(add(child(binary_operation(X0),Child))) - :- ast_operation(add(binary_operation(X0,X1,Child,X3))). +ast(add(child(binary_operation(X0),Child))) + :- ast(add(binary_operation(X0,X1,Child,X3))). -ast_operation(add(child(binary_operation(X0),Child))) - :- ast_operation(add(binary_operation(X0,X1,X2,Child))). +ast(add(child(binary_operation(X0),Child))) + :- ast(add(binary_operation(X0,X1,X2,Child))). -ast_operation(add(child(interval(X0),Child))) - :- ast_operation(add(interval(X0,Child,X2))). +ast(add(child(interval(X0),Child))) + :- ast(add(interval(X0,Child,X2))). -ast_operation(add(child(interval(X0),Child))) - :- ast_operation(add(interval(X0,X1,Child))). +ast(add(child(interval(X0),Child))) + :- ast(add(interval(X0,X1,Child))). -ast_operation(add(child(terms(X0),Child))) - :- ast_operation(add(terms(X0,X1,Child))). +ast(add(child(terms(X0),Child))) + :- ast(add(terms(X0,X1,Child))). -ast_operation(add(child(function(X0),Child))) - :- ast_operation(add(function(X0,X1,Child))). +ast(add(child(function(X0),Child))) + :- ast(add(function(X0,X1,Child))). -ast_operation(add(child(external_function(X0),Child))) - :- ast_operation(add(external_function(X0,X1,Child))). +ast(add(child(external_function(X0),Child))) + :- ast(add(external_function(X0,X1,Child))). -ast_operation(add(child(pool(X0),Child))) - :- ast_operation(add(pool(X0,Child))). +ast(add(child(pool(X0),Child))) + :- ast(add(pool(X0,Child))). -ast_operation(add(child(theory_terms(X0),Child))) - :- ast_operation(add(theory_terms(X0,X1,Child))). +ast(add(child(theory_terms(X0),Child))) + :- ast(add(theory_terms(X0,X1,Child))). -ast_operation(add(child(theory_sequence(X0),Child))) - :- ast_operation(add(theory_sequence(X0,X1,Child))). +ast(add(child(theory_sequence(X0),Child))) + :- ast(add(theory_sequence(X0,X1,Child))). -ast_operation(add(child(theory_function(X0),Child))) - :- ast_operation(add(theory_function(X0,X1,Child))). +ast(add(child(theory_function(X0),Child))) + :- ast(add(theory_function(X0,X1,Child))). -ast_operation(add(child(theory_unparsed_term_elements(X0),Child))) - :- ast_operation(add(theory_unparsed_term_elements(X0,X1,Child,X3))). +ast(add(child(theory_unparsed_term_elements(X0),Child))) + :- ast(add(theory_unparsed_term_elements(X0,X1,Child,X3))). -ast_operation(add(child(theory_unparsed_term_elements(X0),Child))) - :- ast_operation(add(theory_unparsed_term_elements(X0,X1,X2,Child))). +ast(add(child(theory_unparsed_term_elements(X0),Child))) + :- ast(add(theory_unparsed_term_elements(X0,X1,X2,Child))). -ast_operation(add(child(theory_unparsed_term(X0),Child))) - :- ast_operation(add(theory_unparsed_term(X0,Child))). +ast(add(child(theory_unparsed_term(X0),Child))) + :- ast(add(theory_unparsed_term(X0,Child))). -ast_operation(add(child(guard(X0),Child))) - :- ast_operation(add(guard(X0,X1,Child))). +ast(add(child(guard(X0),Child))) + :- ast(add(guard(X0,X1,Child))). -ast_operation(add(child(guards(X0),Child))) - :- ast_operation(add(guards(X0,X1,Child))). +ast(add(child(guards(X0),Child))) + :- ast(add(guards(X0,X1,Child))). -ast_operation(add(child(comparison(X0),Child))) - :- ast_operation(add(comparison(X0,Child,X2))). +ast(add(child(comparison(X0),Child))) + :- ast(add(comparison(X0,Child,X2))). -ast_operation(add(child(comparison(X0),Child))) - :- ast_operation(add(comparison(X0,X1,Child))). +ast(add(child(comparison(X0),Child))) + :- ast(add(comparison(X0,X1,Child))). -ast_operation(add(child(symbolic_atom(X0),Child))) - :- ast_operation(add(symbolic_atom(X0,Child))). +ast(add(child(symbolic_atom(X0),Child))) + :- ast(add(symbolic_atom(X0,Child))). -ast_operation(add(child(literal(X0),Child))) - :- ast_operation(add(literal(X0,X1,Child))). +ast(add(child(literal(X0),Child))) + :- ast(add(literal(X0,X1,Child))). -ast_operation(add(child(literals(X0),Child))) - :- ast_operation(add(literals(X0,X1,Child))). +ast(add(child(literals(X0),Child))) + :- ast(add(literals(X0,X1,Child))). -ast_operation(add(child(conditional_literal(X0),Child))) - :- ast_operation(add(conditional_literal(X0,Child,X2))). +ast(add(child(conditional_literal(X0),Child))) + :- ast(add(conditional_literal(X0,Child,X2))). -ast_operation(add(child(conditional_literal(X0),Child))) - :- ast_operation(add(conditional_literal(X0,X1,Child))). +ast(add(child(conditional_literal(X0),Child))) + :- ast(add(conditional_literal(X0,X1,Child))). -ast_operation(add(child(aggregate_elements(X0),Child))) - :- ast_operation(add(aggregate_elements(X0,X1,Child))). +ast(add(child(aggregate_elements(X0),Child))) + :- ast(add(aggregate_elements(X0,X1,Child))). -ast_operation(add(child(aggregate(X0),Child))) - :- ast_operation(add(aggregate(X0,Child,X2,X3))). +ast(add(child(aggregate(X0),Child))) + :- ast(add(aggregate(X0,Child,X2,X3))). -ast_operation(add(child(aggregate(X0),Child))) - :- ast_operation(add(aggregate(X0,X1,Child,X3))). +ast(add(child(aggregate(X0),Child))) + :- ast(add(aggregate(X0,X1,Child,X3))). -ast_operation(add(child(aggregate(X0),Child))) - :- ast_operation(add(aggregate(X0,X1,X2,Child))). +ast(add(child(aggregate(X0),Child))) + :- ast(add(aggregate(X0,X1,X2,Child))). -ast_operation(add(child(theory_atom_elements(X0),Child))) - :- ast_operation(add(theory_atom_elements(X0,X1,Child,X3))). +ast(add(child(theory_atom_elements(X0),Child))) + :- ast(add(theory_atom_elements(X0,X1,Child,X3))). -ast_operation(add(child(theory_atom_elements(X0),Child))) - :- ast_operation(add(theory_atom_elements(X0,X1,X2,Child))). +ast(add(child(theory_atom_elements(X0),Child))) + :- ast(add(theory_atom_elements(X0,X1,X2,Child))). -ast_operation(add(child(theory_guard(X0),Child))) - :- ast_operation(add(theory_guard(X0,X1,Child))). +ast(add(child(theory_guard(X0),Child))) + :- ast(add(theory_guard(X0,X1,Child))). -ast_operation(add(child(theory_atom(X0),Child))) - :- ast_operation(add(theory_atom(X0,Child,X2,X3))). +ast(add(child(theory_atom(X0),Child))) + :- ast(add(theory_atom(X0,Child,X2,X3))). -ast_operation(add(child(theory_atom(X0),Child))) - :- ast_operation(add(theory_atom(X0,X1,Child,X3))). +ast(add(child(theory_atom(X0),Child))) + :- ast(add(theory_atom(X0,X1,Child,X3))). -ast_operation(add(child(theory_atom(X0),Child))) - :- ast_operation(add(theory_atom(X0,X1,X2,Child))). +ast(add(child(theory_atom(X0),Child))) + :- ast(add(theory_atom(X0,X1,X2,Child))). -ast_operation(add(child(body_aggregate_elements(X0),Child))) - :- ast_operation(add(body_aggregate_elements(X0,X1,Child,X3))). +ast(add(child(body_aggregate_elements(X0),Child))) + :- ast(add(body_aggregate_elements(X0,X1,Child,X3))). -ast_operation(add(child(body_aggregate_elements(X0),Child))) - :- ast_operation(add(body_aggregate_elements(X0,X1,X2,Child))). +ast(add(child(body_aggregate_elements(X0),Child))) + :- ast(add(body_aggregate_elements(X0,X1,X2,Child))). -ast_operation(add(child(body_aggregate(X0),Child))) - :- ast_operation(add(body_aggregate(X0,Child,X2,X3,X4))). +ast(add(child(body_aggregate(X0),Child))) + :- ast(add(body_aggregate(X0,Child,X2,X3,X4))). -ast_operation(add(child(body_aggregate(X0),Child))) - :- ast_operation(add(body_aggregate(X0,X1,X2,Child,X4))). +ast(add(child(body_aggregate(X0),Child))) + :- ast(add(body_aggregate(X0,X1,X2,Child,X4))). -ast_operation(add(child(body_aggregate(X0),Child))) - :- ast_operation(add(body_aggregate(X0,X1,X2,X3,Child))). +ast(add(child(body_aggregate(X0),Child))) + :- ast(add(body_aggregate(X0,X1,X2,X3,Child))). -ast_operation(add(child(body_literal(X0),Child))) - :- ast_operation(add(body_literal(X0,X1,Child))). +ast(add(child(body_literal(X0),Child))) + :- ast(add(body_literal(X0,X1,Child))). -ast_operation(add(child(body_literals(X0),Child))) - :- ast_operation(add(body_literals(X0,X1,Child))). +ast(add(child(body_literals(X0),Child))) + :- ast(add(body_literals(X0,X1,Child))). -ast_operation(add(child(head_aggregate_elements(X0),Child))) - :- ast_operation(add(head_aggregate_elements(X0,X1,Child,X3))). +ast(add(child(head_aggregate_elements(X0),Child))) + :- ast(add(head_aggregate_elements(X0,X1,Child,X3))). -ast_operation(add(child(head_aggregate_elements(X0),Child))) - :- ast_operation(add(head_aggregate_elements(X0,X1,X2,Child))). +ast(add(child(head_aggregate_elements(X0),Child))) + :- ast(add(head_aggregate_elements(X0,X1,X2,Child))). -ast_operation(add(child(head_aggregate(X0),Child))) - :- ast_operation(add(head_aggregate(X0,Child,X2,X3,X4))). +ast(add(child(head_aggregate(X0),Child))) + :- ast(add(head_aggregate(X0,Child,X2,X3,X4))). -ast_operation(add(child(head_aggregate(X0),Child))) - :- ast_operation(add(head_aggregate(X0,X1,X2,Child,X4))). +ast(add(child(head_aggregate(X0),Child))) + :- ast(add(head_aggregate(X0,X1,X2,Child,X4))). -ast_operation(add(child(head_aggregate(X0),Child))) - :- ast_operation(add(head_aggregate(X0,X1,X2,X3,Child))). +ast(add(child(head_aggregate(X0),Child))) + :- ast(add(head_aggregate(X0,X1,X2,X3,Child))). -ast_operation(add(child(conditional_literals(X0),Child))) - :- ast_operation(add(conditional_literals(X0,X1,Child))). +ast(add(child(conditional_literals(X0),Child))) + :- ast(add(conditional_literals(X0,X1,Child))). -ast_operation(add(child(disjunction(X0),Child))) - :- ast_operation(add(disjunction(X0,Child))). +ast(add(child(disjunction(X0),Child))) + :- ast(add(disjunction(X0,Child))). -ast_operation(add(child(rule(X0),Child))) - :- ast_operation(add(rule(X0,Child,X2))). +ast(add(child(rule(X0),Child))) + :- ast(add(rule(X0,Child,X2))). -ast_operation(add(child(rule(X0),Child))) - :- ast_operation(add(rule(X0,X1,Child))). +ast(add(child(rule(X0),Child))) + :- ast(add(rule(X0,X1,Child))). -ast_operation(add(child(definition(X0),Child))) - :- ast_operation(add(definition(X0,X1,Child,X3))). +ast(add(child(definition(X0),Child))) + :- ast(add(definition(X0,X1,Child,X3))). -ast_operation(add(child(show_term(X0),Child))) - :- ast_operation(add(show_term(X0,Child,X2))). +ast(add(child(show_term(X0),Child))) + :- ast(add(show_term(X0,Child,X2))). -ast_operation(add(child(show_term(X0),Child))) - :- ast_operation(add(show_term(X0,X1,Child))). +ast(add(child(show_term(X0),Child))) + :- ast(add(show_term(X0,X1,Child))). -ast_operation(add(child(minimize(X0),Child))) - :- ast_operation(add(minimize(X0,Child,X2,X3,X4))). +ast(add(child(minimize(X0),Child))) + :- ast(add(minimize(X0,Child,X2,X3,X4))). -ast_operation(add(child(minimize(X0),Child))) - :- ast_operation(add(minimize(X0,X1,Child,X3,X4))). +ast(add(child(minimize(X0),Child))) + :- ast(add(minimize(X0,X1,Child,X3,X4))). -ast_operation(add(child(minimize(X0),Child))) - :- ast_operation(add(minimize(X0,X1,X2,Child,X4))). +ast(add(child(minimize(X0),Child))) + :- ast(add(minimize(X0,X1,X2,Child,X4))). -ast_operation(add(child(minimize(X0),Child))) - :- ast_operation(add(minimize(X0,X1,X2,X3,Child))). +ast(add(child(minimize(X0),Child))) + :- ast(add(minimize(X0,X1,X2,X3,Child))). -ast_operation(add(child(statements(X0),Child))) - :- ast_operation(add(statements(X0,X1,Child))). +ast(add(child(statements(X0),Child))) + :- ast(add(statements(X0,X1,Child))). -ast_operation(add(child(constants(X0),Child))) - :- ast_operation(add(constants(X0,X1,Child))). +ast(add(child(constants(X0),Child))) + :- ast(add(constants(X0,X1,Child))). -ast_operation(add(child(program(X0),Child))) - :- ast_operation(add(program(X0,X1,Child,X3))). +ast(add(child(program(X0),Child))) + :- ast(add(program(X0,X1,Child,X3))). -ast_operation(add(child(program(X0),Child))) - :- ast_operation(add(program(X0,X1,X2,Child))). +ast(add(child(program(X0),Child))) + :- ast(add(program(X0,X1,X2,Child))). -ast_operation(add(child(external(X0),Child))) - :- ast_operation(add(external(X0,Child,X2,X3))). +ast(add(child(external(X0),Child))) + :- ast(add(external(X0,Child,X2,X3))). -ast_operation(add(child(external(X0),Child))) - :- ast_operation(add(external(X0,X1,Child,X3))). +ast(add(child(external(X0),Child))) + :- ast(add(external(X0,X1,Child,X3))). -ast_operation(add(child(edge(X0),Child))) - :- ast_operation(add(edge(X0,Child,X2,X3))). +ast(add(child(edge(X0),Child))) + :- ast(add(edge(X0,Child,X2,X3))). -ast_operation(add(child(edge(X0),Child))) - :- ast_operation(add(edge(X0,X1,Child,X3))). +ast(add(child(edge(X0),Child))) + :- ast(add(edge(X0,X1,Child,X3))). -ast_operation(add(child(edge(X0),Child))) - :- ast_operation(add(edge(X0,X1,X2,Child))). +ast(add(child(edge(X0),Child))) + :- ast(add(edge(X0,X1,X2,Child))). -ast_operation(add(child(heuristic(X0),Child))) - :- ast_operation(add(heuristic(X0,Child,X2,X3,X4,X5))). +ast(add(child(heuristic(X0),Child))) + :- ast(add(heuristic(X0,Child,X2,X3,X4,X5))). -ast_operation(add(child(heuristic(X0),Child))) - :- ast_operation(add(heuristic(X0,X1,Child,X3,X4,X5))). +ast(add(child(heuristic(X0),Child))) + :- ast(add(heuristic(X0,X1,Child,X3,X4,X5))). -ast_operation(add(child(heuristic(X0),Child))) - :- ast_operation(add(heuristic(X0,X1,X2,Child,X4,X5))). +ast(add(child(heuristic(X0),Child))) + :- ast(add(heuristic(X0,X1,X2,Child,X4,X5))). -ast_operation(add(child(heuristic(X0),Child))) - :- ast_operation(add(heuristic(X0,X1,X2,X3,Child,X5))). +ast(add(child(heuristic(X0),Child))) + :- ast(add(heuristic(X0,X1,X2,X3,Child,X5))). -ast_operation(add(child(heuristic(X0),Child))) - :- ast_operation(add(heuristic(X0,X1,X2,X3,X4,Child))). +ast(add(child(heuristic(X0),Child))) + :- ast(add(heuristic(X0,X1,X2,X3,X4,Child))). -ast_operation(add(child(project_atom(X0),Child))) - :- ast_operation(add(project_atom(X0,Child,X2))). +ast(add(child(project_atom(X0),Child))) + :- ast(add(project_atom(X0,Child,X2))). -ast_operation(add(child(project_atom(X0),Child))) - :- ast_operation(add(project_atom(X0,X1,Child))). +ast(add(child(project_atom(X0),Child))) + :- ast(add(project_atom(X0,X1,Child))). -ast_operation(add(child(theory_term_definitions(X0),Child))) - :- ast_operation(add(theory_term_definitions(X0,X1,X2,Child))). +ast(add(child(theory_term_definitions(X0),Child))) + :- ast(add(theory_term_definitions(X0,X1,X2,Child))). -ast_operation(add(child(theory_guard_definition(X0),Child))) - :- ast_operation(add(theory_guard_definition(X0,Child,X2))). +ast(add(child(theory_guard_definition(X0),Child))) + :- ast(add(theory_guard_definition(X0,Child,X2))). -ast_operation(add(child(theory_atom_definitions(X0),Child))) - :- ast_operation(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,Child))). +ast(add(child(theory_atom_definitions(X0),Child))) + :- ast(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,Child))). -ast_operation(add(child(theory_definition(X0),Child))) - :- ast_operation(add(theory_definition(X0,X1,Child,X3))). +ast(add(child(theory_definition(X0),Child))) + :- ast(add(theory_definition(X0,X1,Child,X3))). -ast_operation(add(child(theory_definition(X0),Child))) - :- ast_operation(add(theory_definition(X0,X1,X2,Child))). +ast(add(child(theory_definition(X0),Child))) + :- ast(add(theory_definition(X0,X1,X2,Child))). diff --git a/src/renopro/asp/ast.lp b/src/renopro/asp/ast.lp index fe97e63..9752b6d 100644 --- a/src/renopro/asp/ast.lp +++ b/src/renopro/asp/ast.lp @@ -1,61 +1,61 @@ % Rules to tag AST facts. -ast(string(X0,X1)) :- string(X0,X1). -ast(number(X0,X1)) :- number(X0,X1). -ast(variable(X0,X1)) :- variable(X0,X1). -ast(unary_operation(X0,X1,X2)) :- unary_operation(X0,X1,X2). -ast(binary_operation(X0,X1,X2,X3)) :- binary_operation(X0,X1,X2,X3). -ast(interval(X0,X1,X2)) :- interval(X0,X1,X2). -ast(terms(X0,X1,X2)) :- terms(X0,X1,X2). -ast(function(X0,X1,X2)) :- function(X0,X1,X2). -ast(external_function(X0,X1,X2)) :- external_function(X0,X1,X2). -ast(pool(X0,X1)) :- pool(X0,X1). -ast(theory_terms(X0,X1,X2)) :- theory_terms(X0,X1,X2). -ast(theory_sequence(X0,X1,X2)) :- theory_sequence(X0,X1,X2). -ast(theory_function(X0,X1,X2)) :- theory_function(X0,X1,X2). -ast(theory_operators(X0,X1,X2)) :- theory_operators(X0,X1,X2). -ast(theory_unparsed_term_elements(X0,X1,X2,X3)) :- theory_unparsed_term_elements(X0,X1,X2,X3). -ast(theory_unparsed_term(X0,X1)) :- theory_unparsed_term(X0,X1). -ast(guard(X0,X1,X2)) :- guard(X0,X1,X2). -ast(guards(X0,X1,X2)) :- guards(X0,X1,X2). -ast(comparison(X0,X1,X2)) :- comparison(X0,X1,X2). -ast(boolean_constant(X0,X1)) :- boolean_constant(X0,X1). -ast(symbolic_atom(X0,X1)) :- symbolic_atom(X0,X1). -ast(literal(X0,X1,X2)) :- literal(X0,X1,X2). -ast(literals(X0,X1,X2)) :- literals(X0,X1,X2). -ast(conditional_literal(X0,X1,X2)) :- conditional_literal(X0,X1,X2). -ast(aggregate_elements(X0,X1,X2)) :- aggregate_elements(X0,X1,X2). -ast(aggregate(X0,X1,X2,X3)) :- aggregate(X0,X1,X2,X3). -ast(theory_atom_elements(X0,X1,X2,X3)) :- theory_atom_elements(X0,X1,X2,X3). -ast(theory_guard(X0,X1,X2)) :- theory_guard(X0,X1,X2). -ast(theory_atom(X0,X1,X2,X3)) :- theory_atom(X0,X1,X2,X3). -ast(body_aggregate_elements(X0,X1,X2,X3)) :- body_aggregate_elements(X0,X1,X2,X3). -ast(body_aggregate(X0,X1,X2,X3,X4)) :- body_aggregate(X0,X1,X2,X3,X4). -ast(body_literal(X0,X1,X2)) :- body_literal(X0,X1,X2). -ast(body_literals(X0,X1,X2)) :- body_literals(X0,X1,X2). -ast(head_aggregate_elements(X0,X1,X2,X3)) :- head_aggregate_elements(X0,X1,X2,X3). -ast(head_aggregate(X0,X1,X2,X3,X4)) :- head_aggregate(X0,X1,X2,X3,X4). -ast(conditional_literals(X0,X1,X2)) :- conditional_literals(X0,X1,X2). -ast(disjunction(X0,X1)) :- disjunction(X0,X1). -ast(rule(X0,X1,X2)) :- rule(X0,X1,X2). -ast(definition(X0,X1,X2,X3)) :- definition(X0,X1,X2,X3). -ast(show_signature(X0,X1,X2,X3)) :- show_signature(X0,X1,X2,X3). -ast(defined(X0,X1,X2,X3)) :- defined(X0,X1,X2,X3). -ast(show_term(X0,X1,X2)) :- show_term(X0,X1,X2). -ast(minimize(X0,X1,X2,X3,X4)) :- minimize(X0,X1,X2,X3,X4). -ast(script(X0,X1,X2)) :- script(X0,X1,X2). -ast(statements(X0,X1,X2)) :- statements(X0,X1,X2). -ast(constants(X0,X1,X2)) :- constants(X0,X1,X2). -ast(program(X0,X1,X2,X3)) :- program(X0,X1,X2,X3). -ast(external(X0,X1,X2,X3)) :- external(X0,X1,X2,X3). -ast(edge(X0,X1,X2,X3)) :- edge(X0,X1,X2,X3). -ast(heuristic(X0,X1,X2,X3,X4,X5)) :- heuristic(X0,X1,X2,X3,X4,X5). -ast(project_atom(X0,X1,X2)) :- project_atom(X0,X1,X2). -ast(project_signature(X0,X1,X2,X3)) :- project_signature(X0,X1,X2,X3). -ast(theory_operator_definitions(X0,X1,X2,X3,X4)) :- theory_operator_definitions(X0,X1,X2,X3,X4). -ast(theory_term_definitions(X0,X1,X2,X3)) :- theory_term_definitions(X0,X1,X2,X3). -ast(theory_guard_definition(X0,X1,X2)) :- theory_guard_definition(X0,X1,X2). -ast(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6)) :- theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6). -ast(theory_definition(X0,X1,X2,X3)) :- theory_definition(X0,X1,X2,X3). -ast(location(X0,X1,X2)) :- location(X0,X1,X2). -ast(child(X0,X1)) :- child(X0,X1). +ast(fact(string(X0,X1))) :- string(X0,X1). +ast(fact(number(X0,X1))) :- number(X0,X1). +ast(fact(variable(X0,X1))) :- variable(X0,X1). +ast(fact(unary_operation(X0,X1,X2))) :- unary_operation(X0,X1,X2). +ast(fact(binary_operation(X0,X1,X2,X3))) :- binary_operation(X0,X1,X2,X3). +ast(fact(interval(X0,X1,X2))) :- interval(X0,X1,X2). +ast(fact(terms(X0,X1,X2))) :- terms(X0,X1,X2). +ast(fact(function(X0,X1,X2))) :- function(X0,X1,X2). +ast(fact(external_function(X0,X1,X2))) :- external_function(X0,X1,X2). +ast(fact(pool(X0,X1))) :- pool(X0,X1). +ast(fact(theory_terms(X0,X1,X2))) :- theory_terms(X0,X1,X2). +ast(fact(theory_sequence(X0,X1,X2))) :- theory_sequence(X0,X1,X2). +ast(fact(theory_function(X0,X1,X2))) :- theory_function(X0,X1,X2). +ast(fact(theory_operators(X0,X1,X2))) :- theory_operators(X0,X1,X2). +ast(fact(theory_unparsed_term_elements(X0,X1,X2,X3))) :- theory_unparsed_term_elements(X0,X1,X2,X3). +ast(fact(theory_unparsed_term(X0,X1))) :- theory_unparsed_term(X0,X1). +ast(fact(guard(X0,X1,X2))) :- guard(X0,X1,X2). +ast(fact(guards(X0,X1,X2))) :- guards(X0,X1,X2). +ast(fact(comparison(X0,X1,X2))) :- comparison(X0,X1,X2). +ast(fact(boolean_constant(X0,X1))) :- boolean_constant(X0,X1). +ast(fact(symbolic_atom(X0,X1))) :- symbolic_atom(X0,X1). +ast(fact(literal(X0,X1,X2))) :- literal(X0,X1,X2). +ast(fact(literals(X0,X1,X2))) :- literals(X0,X1,X2). +ast(fact(conditional_literal(X0,X1,X2))) :- conditional_literal(X0,X1,X2). +ast(fact(aggregate_elements(X0,X1,X2))) :- aggregate_elements(X0,X1,X2). +ast(fact(aggregate(X0,X1,X2,X3))) :- aggregate(X0,X1,X2,X3). +ast(fact(theory_atom_elements(X0,X1,X2,X3))) :- theory_atom_elements(X0,X1,X2,X3). +ast(fact(theory_guard(X0,X1,X2))) :- theory_guard(X0,X1,X2). +ast(fact(theory_atom(X0,X1,X2,X3))) :- theory_atom(X0,X1,X2,X3). +ast(fact(body_aggregate_elements(X0,X1,X2,X3))) :- body_aggregate_elements(X0,X1,X2,X3). +ast(fact(body_aggregate(X0,X1,X2,X3,X4))) :- body_aggregate(X0,X1,X2,X3,X4). +ast(fact(body_literal(X0,X1,X2))) :- body_literal(X0,X1,X2). +ast(fact(body_literals(X0,X1,X2))) :- body_literals(X0,X1,X2). +ast(fact(head_aggregate_elements(X0,X1,X2,X3))) :- head_aggregate_elements(X0,X1,X2,X3). +ast(fact(head_aggregate(X0,X1,X2,X3,X4))) :- head_aggregate(X0,X1,X2,X3,X4). +ast(fact(conditional_literals(X0,X1,X2))) :- conditional_literals(X0,X1,X2). +ast(fact(disjunction(X0,X1))) :- disjunction(X0,X1). +ast(fact(rule(X0,X1,X2))) :- rule(X0,X1,X2). +ast(fact(definition(X0,X1,X2,X3))) :- definition(X0,X1,X2,X3). +ast(fact(show_signature(X0,X1,X2,X3))) :- show_signature(X0,X1,X2,X3). +ast(fact(defined(X0,X1,X2,X3))) :- defined(X0,X1,X2,X3). +ast(fact(show_term(X0,X1,X2))) :- show_term(X0,X1,X2). +ast(fact(minimize(X0,X1,X2,X3,X4))) :- minimize(X0,X1,X2,X3,X4). +ast(fact(script(X0,X1,X2))) :- script(X0,X1,X2). +ast(fact(statements(X0,X1,X2))) :- statements(X0,X1,X2). +ast(fact(constants(X0,X1,X2))) :- constants(X0,X1,X2). +ast(fact(program(X0,X1,X2,X3))) :- program(X0,X1,X2,X3). +ast(fact(external(X0,X1,X2,X3))) :- external(X0,X1,X2,X3). +ast(fact(edge(X0,X1,X2,X3))) :- edge(X0,X1,X2,X3). +ast(fact(heuristic(X0,X1,X2,X3,X4,X5))) :- heuristic(X0,X1,X2,X3,X4,X5). +ast(fact(project_atom(X0,X1,X2))) :- project_atom(X0,X1,X2). +ast(fact(project_signature(X0,X1,X2,X3))) :- project_signature(X0,X1,X2,X3). +ast(fact(theory_operator_definitions(X0,X1,X2,X3,X4))) :- theory_operator_definitions(X0,X1,X2,X3,X4). +ast(fact(theory_term_definitions(X0,X1,X2,X3))) :- theory_term_definitions(X0,X1,X2,X3). +ast(fact(theory_guard_definition(X0,X1,X2))) :- theory_guard_definition(X0,X1,X2). +ast(fact(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6))) :- theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6). +ast(fact(theory_definition(X0,X1,X2,X3))) :- theory_definition(X0,X1,X2,X3). +ast(fact(location(X0,X1,X2))) :- location(X0,X1,X2). +ast(fact(child(X0,X1))) :- child(X0,X1). diff --git a/src/renopro/asp/ast2id.lp b/src/renopro/asp/ast2id.lp new file mode 100644 index 0000000..491091e --- /dev/null +++ b/src/renopro/asp/ast2id.lp @@ -0,0 +1,174 @@ +% map ast facts to their identifiers. + +ast2id(string(X0,X1),string(X0)) + :- ast(fact(string(X0,X1));add(string(X0,X1));delete(string(X0,X1))). + +ast2id(number(X0,X1),number(X0)) + :- ast(fact(number(X0,X1));add(number(X0,X1));delete(number(X0,X1))). + +ast2id(variable(X0,X1),variable(X0)) + :- ast(fact(variable(X0,X1));add(variable(X0,X1));delete(variable(X0,X1))). + +ast2id(unary_operation(X0,X1,X2),unary_operation(X0)) + :- ast(fact(unary_operation(X0,X1,X2));add(unary_operation(X0,X1,X2));delete(unary_operation(X0,X1,X2))). + +ast2id(binary_operation(X0,X1,X2,X3),binary_operation(X0)) + :- ast(fact(binary_operation(X0,X1,X2,X3));add(binary_operation(X0,X1,X2,X3));delete(binary_operation(X0,X1,X2,X3))). + +ast2id(interval(X0,X1,X2),interval(X0)) + :- ast(fact(interval(X0,X1,X2));add(interval(X0,X1,X2));delete(interval(X0,X1,X2))). + +ast2id(terms(X0,X1,X2),terms(X0)) + :- ast(fact(terms(X0,X1,X2));add(terms(X0,X1,X2));delete(terms(X0,X1,X2))). + +ast2id(function(X0,X1,X2),function(X0)) + :- ast(fact(function(X0,X1,X2));add(function(X0,X1,X2));delete(function(X0,X1,X2))). + +ast2id(external_function(X0,X1,X2),external_function(X0)) + :- ast(fact(external_function(X0,X1,X2));add(external_function(X0,X1,X2));delete(external_function(X0,X1,X2))). + +ast2id(pool(X0,X1),pool(X0)) + :- ast(fact(pool(X0,X1));add(pool(X0,X1));delete(pool(X0,X1))). + +ast2id(theory_terms(X0,X1,X2),theory_terms(X0)) + :- ast(fact(theory_terms(X0,X1,X2));add(theory_terms(X0,X1,X2));delete(theory_terms(X0,X1,X2))). + +ast2id(theory_sequence(X0,X1,X2),theory_sequence(X0)) + :- ast(fact(theory_sequence(X0,X1,X2));add(theory_sequence(X0,X1,X2));delete(theory_sequence(X0,X1,X2))). + +ast2id(theory_function(X0,X1,X2),theory_function(X0)) + :- ast(fact(theory_function(X0,X1,X2));add(theory_function(X0,X1,X2));delete(theory_function(X0,X1,X2))). + +ast2id(theory_operators(X0,X1,X2),theory_operators(X0)) + :- ast(fact(theory_operators(X0,X1,X2));add(theory_operators(X0,X1,X2));delete(theory_operators(X0,X1,X2))). + +ast2id(theory_unparsed_term_elements(X0,X1,X2,X3),theory_unparsed_term_elements(X0)) + :- ast(fact(theory_unparsed_term_elements(X0,X1,X2,X3));add(theory_unparsed_term_elements(X0,X1,X2,X3));delete(theory_unparsed_term_elements(X0,X1,X2,X3))). + +ast2id(theory_unparsed_term(X0,X1),theory_unparsed_term(X0)) + :- ast(fact(theory_unparsed_term(X0,X1));add(theory_unparsed_term(X0,X1));delete(theory_unparsed_term(X0,X1))). + +ast2id(guard(X0,X1,X2),guard(X0)) + :- ast(fact(guard(X0,X1,X2));add(guard(X0,X1,X2));delete(guard(X0,X1,X2))). + +ast2id(guards(X0,X1,X2),guards(X0)) + :- ast(fact(guards(X0,X1,X2));add(guards(X0,X1,X2));delete(guards(X0,X1,X2))). + +ast2id(comparison(X0,X1,X2),comparison(X0)) + :- ast(fact(comparison(X0,X1,X2));add(comparison(X0,X1,X2));delete(comparison(X0,X1,X2))). + +ast2id(boolean_constant(X0,X1),boolean_constant(X0)) + :- ast(fact(boolean_constant(X0,X1));add(boolean_constant(X0,X1));delete(boolean_constant(X0,X1))). + +ast2id(symbolic_atom(X0,X1),symbolic_atom(X0)) + :- ast(fact(symbolic_atom(X0,X1));add(symbolic_atom(X0,X1));delete(symbolic_atom(X0,X1))). + +ast2id(literal(X0,X1,X2),literal(X0)) + :- ast(fact(literal(X0,X1,X2));add(literal(X0,X1,X2));delete(literal(X0,X1,X2))). + +ast2id(literals(X0,X1,X2),literals(X0)) + :- ast(fact(literals(X0,X1,X2));add(literals(X0,X1,X2));delete(literals(X0,X1,X2))). + +ast2id(conditional_literal(X0,X1,X2),conditional_literal(X0)) + :- ast(fact(conditional_literal(X0,X1,X2));add(conditional_literal(X0,X1,X2));delete(conditional_literal(X0,X1,X2))). + +ast2id(aggregate_elements(X0,X1,X2),aggregate_elements(X0)) + :- ast(fact(aggregate_elements(X0,X1,X2));add(aggregate_elements(X0,X1,X2));delete(aggregate_elements(X0,X1,X2))). + +ast2id(aggregate(X0,X1,X2,X3),aggregate(X0)) + :- ast(fact(aggregate(X0,X1,X2,X3));add(aggregate(X0,X1,X2,X3));delete(aggregate(X0,X1,X2,X3))). + +ast2id(theory_atom_elements(X0,X1,X2,X3),theory_atom_elements(X0)) + :- ast(fact(theory_atom_elements(X0,X1,X2,X3));add(theory_atom_elements(X0,X1,X2,X3));delete(theory_atom_elements(X0,X1,X2,X3))). + +ast2id(theory_guard(X0,X1,X2),theory_guard(X0)) + :- ast(fact(theory_guard(X0,X1,X2));add(theory_guard(X0,X1,X2));delete(theory_guard(X0,X1,X2))). + +ast2id(theory_atom(X0,X1,X2,X3),theory_atom(X0)) + :- ast(fact(theory_atom(X0,X1,X2,X3));add(theory_atom(X0,X1,X2,X3));delete(theory_atom(X0,X1,X2,X3))). + +ast2id(body_aggregate_elements(X0,X1,X2,X3),body_aggregate_elements(X0)) + :- ast(fact(body_aggregate_elements(X0,X1,X2,X3));add(body_aggregate_elements(X0,X1,X2,X3));delete(body_aggregate_elements(X0,X1,X2,X3))). + +ast2id(body_aggregate(X0,X1,X2,X3,X4),body_aggregate(X0)) + :- ast(fact(body_aggregate(X0,X1,X2,X3,X4));add(body_aggregate(X0,X1,X2,X3,X4));delete(body_aggregate(X0,X1,X2,X3,X4))). + +ast2id(body_literal(X0,X1,X2),body_literal(X0)) + :- ast(fact(body_literal(X0,X1,X2));add(body_literal(X0,X1,X2));delete(body_literal(X0,X1,X2))). + +ast2id(body_literals(X0,X1,X2),body_literals(X0)) + :- ast(fact(body_literals(X0,X1,X2));add(body_literals(X0,X1,X2));delete(body_literals(X0,X1,X2))). + +ast2id(head_aggregate_elements(X0,X1,X2,X3),head_aggregate_elements(X0)) + :- ast(fact(head_aggregate_elements(X0,X1,X2,X3));add(head_aggregate_elements(X0,X1,X2,X3));delete(head_aggregate_elements(X0,X1,X2,X3))). + +ast2id(head_aggregate(X0,X1,X2,X3,X4),head_aggregate(X0)) + :- ast(fact(head_aggregate(X0,X1,X2,X3,X4));add(head_aggregate(X0,X1,X2,X3,X4));delete(head_aggregate(X0,X1,X2,X3,X4))). + +ast2id(conditional_literals(X0,X1,X2),conditional_literals(X0)) + :- ast(fact(conditional_literals(X0,X1,X2));add(conditional_literals(X0,X1,X2));delete(conditional_literals(X0,X1,X2))). + +ast2id(disjunction(X0,X1),disjunction(X0)) + :- ast(fact(disjunction(X0,X1));add(disjunction(X0,X1));delete(disjunction(X0,X1))). + +ast2id(rule(X0,X1,X2),rule(X0)) + :- ast(fact(rule(X0,X1,X2));add(rule(X0,X1,X2));delete(rule(X0,X1,X2))). + +ast2id(definition(X0,X1,X2,X3),definition(X0)) + :- ast(fact(definition(X0,X1,X2,X3));add(definition(X0,X1,X2,X3));delete(definition(X0,X1,X2,X3))). + +ast2id(show_signature(X0,X1,X2,X3),show_signature(X0)) + :- ast(fact(show_signature(X0,X1,X2,X3));add(show_signature(X0,X1,X2,X3));delete(show_signature(X0,X1,X2,X3))). + +ast2id(defined(X0,X1,X2,X3),defined(X0)) + :- ast(fact(defined(X0,X1,X2,X3));add(defined(X0,X1,X2,X3));delete(defined(X0,X1,X2,X3))). + +ast2id(show_term(X0,X1,X2),show_term(X0)) + :- ast(fact(show_term(X0,X1,X2));add(show_term(X0,X1,X2));delete(show_term(X0,X1,X2))). + +ast2id(minimize(X0,X1,X2,X3,X4),minimize(X0)) + :- ast(fact(minimize(X0,X1,X2,X3,X4));add(minimize(X0,X1,X2,X3,X4));delete(minimize(X0,X1,X2,X3,X4))). + +ast2id(script(X0,X1,X2),script(X0)) + :- ast(fact(script(X0,X1,X2));add(script(X0,X1,X2));delete(script(X0,X1,X2))). + +ast2id(statements(X0,X1,X2),statements(X0)) + :- ast(fact(statements(X0,X1,X2));add(statements(X0,X1,X2));delete(statements(X0,X1,X2))). + +ast2id(constants(X0,X1,X2),constants(X0)) + :- ast(fact(constants(X0,X1,X2));add(constants(X0,X1,X2));delete(constants(X0,X1,X2))). + +ast2id(program(X0,X1,X2,X3),program(X0)) + :- ast(fact(program(X0,X1,X2,X3));add(program(X0,X1,X2,X3));delete(program(X0,X1,X2,X3))). + +ast2id(external(X0,X1,X2,X3),external(X0)) + :- ast(fact(external(X0,X1,X2,X3));add(external(X0,X1,X2,X3));delete(external(X0,X1,X2,X3))). + +ast2id(edge(X0,X1,X2,X3),edge(X0)) + :- ast(fact(edge(X0,X1,X2,X3));add(edge(X0,X1,X2,X3));delete(edge(X0,X1,X2,X3))). + +ast2id(heuristic(X0,X1,X2,X3,X4,X5),heuristic(X0)) + :- ast(fact(heuristic(X0,X1,X2,X3,X4,X5));add(heuristic(X0,X1,X2,X3,X4,X5));delete(heuristic(X0,X1,X2,X3,X4,X5))). + +ast2id(project_atom(X0,X1,X2),project_atom(X0)) + :- ast(fact(project_atom(X0,X1,X2));add(project_atom(X0,X1,X2));delete(project_atom(X0,X1,X2))). + +ast2id(project_signature(X0,X1,X2,X3),project_signature(X0)) + :- ast(fact(project_signature(X0,X1,X2,X3));add(project_signature(X0,X1,X2,X3));delete(project_signature(X0,X1,X2,X3))). + +ast2id(theory_operator_definitions(X0,X1,X2,X3,X4),theory_operator_definitions(X0)) + :- ast(fact(theory_operator_definitions(X0,X1,X2,X3,X4));add(theory_operator_definitions(X0,X1,X2,X3,X4));delete(theory_operator_definitions(X0,X1,X2,X3,X4))). + +ast2id(theory_term_definitions(X0,X1,X2,X3),theory_term_definitions(X0)) + :- ast(fact(theory_term_definitions(X0,X1,X2,X3));add(theory_term_definitions(X0,X1,X2,X3));delete(theory_term_definitions(X0,X1,X2,X3))). + +ast2id(theory_guard_definition(X0,X1,X2),theory_guard_definition(X0)) + :- ast(fact(theory_guard_definition(X0,X1,X2));add(theory_guard_definition(X0,X1,X2));delete(theory_guard_definition(X0,X1,X2))). + +ast2id(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6),theory_atom_definitions(X0)) + :- ast(fact(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6));add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6));delete(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6))). + +ast2id(theory_definition(X0,X1,X2,X3),theory_definition(X0)) + :- ast(fact(theory_definition(X0,X1,X2,X3));add(theory_definition(X0,X1,X2,X3));delete(theory_definition(X0,X1,X2,X3))). + +ast2id(location(Id,Begin,End),Id) :- ast(fact(location(Id,Begin,End));add(location(Id,Begin,End));delete(location(Id,Begin,End))). diff --git a/src/renopro/asp/ast_fact2id.lp b/src/renopro/asp/ast_fact2id.lp new file mode 100644 index 0000000..b8e69d6 --- /dev/null +++ b/src/renopro/asp/ast_fact2id.lp @@ -0,0 +1,174 @@ +% map ast facts to their identifiers. + +ast_fact2id(string(X0,X1),string(X0)) + :- ast(fact(string(X0,X1));add(string(X0,X1));delete(string(X0,X1))). + +ast_fact2id(number(X0,X1),number(X0)) + :- ast(fact(number(X0,X1));add(number(X0,X1));delete(number(X0,X1))). + +ast_fact2id(variable(X0,X1),variable(X0)) + :- ast(fact(variable(X0,X1));add(variable(X0,X1));delete(variable(X0,X1))). + +ast_fact2id(unary_operation(X0,X1,X2),unary_operation(X0)) + :- ast(fact(unary_operation(X0,X1,X2));add(unary_operation(X0,X1,X2));delete(unary_operation(X0,X1,X2))). + +ast_fact2id(binary_operation(X0,X1,X2,X3),binary_operation(X0)) + :- ast(fact(binary_operation(X0,X1,X2,X3));add(binary_operation(X0,X1,X2,X3));delete(binary_operation(X0,X1,X2,X3))). + +ast_fact2id(interval(X0,X1,X2),interval(X0)) + :- ast(fact(interval(X0,X1,X2));add(interval(X0,X1,X2));delete(interval(X0,X1,X2))). + +ast_fact2id(terms(X0,X1,X2),terms(X0)) + :- ast(fact(terms(X0,X1,X2));add(terms(X0,X1,X2));delete(terms(X0,X1,X2))). + +ast_fact2id(function(X0,X1,X2),function(X0)) + :- ast(fact(function(X0,X1,X2));add(function(X0,X1,X2));delete(function(X0,X1,X2))). + +ast_fact2id(external_function(X0,X1,X2),external_function(X0)) + :- ast(fact(external_function(X0,X1,X2));add(external_function(X0,X1,X2));delete(external_function(X0,X1,X2))). + +ast_fact2id(pool(X0,X1),pool(X0)) + :- ast(fact(pool(X0,X1));add(pool(X0,X1));delete(pool(X0,X1))). + +ast_fact2id(theory_terms(X0,X1,X2),theory_terms(X0)) + :- ast(fact(theory_terms(X0,X1,X2));add(theory_terms(X0,X1,X2));delete(theory_terms(X0,X1,X2))). + +ast_fact2id(theory_sequence(X0,X1,X2),theory_sequence(X0)) + :- ast(fact(theory_sequence(X0,X1,X2));add(theory_sequence(X0,X1,X2));delete(theory_sequence(X0,X1,X2))). + +ast_fact2id(theory_function(X0,X1,X2),theory_function(X0)) + :- ast(fact(theory_function(X0,X1,X2));add(theory_function(X0,X1,X2));delete(theory_function(X0,X1,X2))). + +ast_fact2id(theory_operators(X0,X1,X2),theory_operators(X0)) + :- ast(fact(theory_operators(X0,X1,X2));add(theory_operators(X0,X1,X2));delete(theory_operators(X0,X1,X2))). + +ast_fact2id(theory_unparsed_term_elements(X0,X1,X2,X3),theory_unparsed_term_elements(X0)) + :- ast(fact(theory_unparsed_term_elements(X0,X1,X2,X3));add(theory_unparsed_term_elements(X0,X1,X2,X3));delete(theory_unparsed_term_elements(X0,X1,X2,X3))). + +ast_fact2id(theory_unparsed_term(X0,X1),theory_unparsed_term(X0)) + :- ast(fact(theory_unparsed_term(X0,X1));add(theory_unparsed_term(X0,X1));delete(theory_unparsed_term(X0,X1))). + +ast_fact2id(guard(X0,X1,X2),guard(X0)) + :- ast(fact(guard(X0,X1,X2));add(guard(X0,X1,X2));delete(guard(X0,X1,X2))). + +ast_fact2id(guards(X0,X1,X2),guards(X0)) + :- ast(fact(guards(X0,X1,X2));add(guards(X0,X1,X2));delete(guards(X0,X1,X2))). + +ast_fact2id(comparison(X0,X1,X2),comparison(X0)) + :- ast(fact(comparison(X0,X1,X2));add(comparison(X0,X1,X2));delete(comparison(X0,X1,X2))). + +ast_fact2id(boolean_constant(X0,X1),boolean_constant(X0)) + :- ast(fact(boolean_constant(X0,X1));add(boolean_constant(X0,X1));delete(boolean_constant(X0,X1))). + +ast_fact2id(symbolic_atom(X0,X1),symbolic_atom(X0)) + :- ast(fact(symbolic_atom(X0,X1));add(symbolic_atom(X0,X1));delete(symbolic_atom(X0,X1))). + +ast_fact2id(literal(X0,X1,X2),literal(X0)) + :- ast(fact(literal(X0,X1,X2));add(literal(X0,X1,X2));delete(literal(X0,X1,X2))). + +ast_fact2id(literals(X0,X1,X2),literals(X0)) + :- ast(fact(literals(X0,X1,X2));add(literals(X0,X1,X2));delete(literals(X0,X1,X2))). + +ast_fact2id(conditional_literal(X0,X1,X2),conditional_literal(X0)) + :- ast(fact(conditional_literal(X0,X1,X2));add(conditional_literal(X0,X1,X2));delete(conditional_literal(X0,X1,X2))). + +ast_fact2id(aggregate_elements(X0,X1,X2),aggregate_elements(X0)) + :- ast(fact(aggregate_elements(X0,X1,X2));add(aggregate_elements(X0,X1,X2));delete(aggregate_elements(X0,X1,X2))). + +ast_fact2id(aggregate(X0,X1,X2,X3),aggregate(X0)) + :- ast(fact(aggregate(X0,X1,X2,X3));add(aggregate(X0,X1,X2,X3));delete(aggregate(X0,X1,X2,X3))). + +ast_fact2id(theory_atom_elements(X0,X1,X2,X3),theory_atom_elements(X0)) + :- ast(fact(theory_atom_elements(X0,X1,X2,X3));add(theory_atom_elements(X0,X1,X2,X3));delete(theory_atom_elements(X0,X1,X2,X3))). + +ast_fact2id(theory_guard(X0,X1,X2),theory_guard(X0)) + :- ast(fact(theory_guard(X0,X1,X2));add(theory_guard(X0,X1,X2));delete(theory_guard(X0,X1,X2))). + +ast_fact2id(theory_atom(X0,X1,X2,X3),theory_atom(X0)) + :- ast(fact(theory_atom(X0,X1,X2,X3));add(theory_atom(X0,X1,X2,X3));delete(theory_atom(X0,X1,X2,X3))). + +ast_fact2id(body_aggregate_elements(X0,X1,X2,X3),body_aggregate_elements(X0)) + :- ast(fact(body_aggregate_elements(X0,X1,X2,X3));add(body_aggregate_elements(X0,X1,X2,X3));delete(body_aggregate_elements(X0,X1,X2,X3))). + +ast_fact2id(body_aggregate(X0,X1,X2,X3,X4),body_aggregate(X0)) + :- ast(fact(body_aggregate(X0,X1,X2,X3,X4));add(body_aggregate(X0,X1,X2,X3,X4));delete(body_aggregate(X0,X1,X2,X3,X4))). + +ast_fact2id(body_literal(X0,X1,X2),body_literal(X0)) + :- ast(fact(body_literal(X0,X1,X2));add(body_literal(X0,X1,X2));delete(body_literal(X0,X1,X2))). + +ast_fact2id(body_literals(X0,X1,X2),body_literals(X0)) + :- ast(fact(body_literals(X0,X1,X2));add(body_literals(X0,X1,X2));delete(body_literals(X0,X1,X2))). + +ast_fact2id(head_aggregate_elements(X0,X1,X2,X3),head_aggregate_elements(X0)) + :- ast(fact(head_aggregate_elements(X0,X1,X2,X3));add(head_aggregate_elements(X0,X1,X2,X3));delete(head_aggregate_elements(X0,X1,X2,X3))). + +ast_fact2id(head_aggregate(X0,X1,X2,X3,X4),head_aggregate(X0)) + :- ast(fact(head_aggregate(X0,X1,X2,X3,X4));add(head_aggregate(X0,X1,X2,X3,X4));delete(head_aggregate(X0,X1,X2,X3,X4))). + +ast_fact2id(conditional_literals(X0,X1,X2),conditional_literals(X0)) + :- ast(fact(conditional_literals(X0,X1,X2));add(conditional_literals(X0,X1,X2));delete(conditional_literals(X0,X1,X2))). + +ast_fact2id(disjunction(X0,X1),disjunction(X0)) + :- ast(fact(disjunction(X0,X1));add(disjunction(X0,X1));delete(disjunction(X0,X1))). + +ast_fact2id(rule(X0,X1,X2),rule(X0)) + :- ast(fact(rule(X0,X1,X2));add(rule(X0,X1,X2));delete(rule(X0,X1,X2))). + +ast_fact2id(definition(X0,X1,X2,X3),definition(X0)) + :- ast(fact(definition(X0,X1,X2,X3));add(definition(X0,X1,X2,X3));delete(definition(X0,X1,X2,X3))). + +ast_fact2id(show_signature(X0,X1,X2,X3),show_signature(X0)) + :- ast(fact(show_signature(X0,X1,X2,X3));add(show_signature(X0,X1,X2,X3));delete(show_signature(X0,X1,X2,X3))). + +ast_fact2id(defined(X0,X1,X2,X3),defined(X0)) + :- ast(fact(defined(X0,X1,X2,X3));add(defined(X0,X1,X2,X3));delete(defined(X0,X1,X2,X3))). + +ast_fact2id(show_term(X0,X1,X2),show_term(X0)) + :- ast(fact(show_term(X0,X1,X2));add(show_term(X0,X1,X2));delete(show_term(X0,X1,X2))). + +ast_fact2id(minimize(X0,X1,X2,X3,X4),minimize(X0)) + :- ast(fact(minimize(X0,X1,X2,X3,X4));add(minimize(X0,X1,X2,X3,X4));delete(minimize(X0,X1,X2,X3,X4))). + +ast_fact2id(script(X0,X1,X2),script(X0)) + :- ast(fact(script(X0,X1,X2));add(script(X0,X1,X2));delete(script(X0,X1,X2))). + +ast_fact2id(statements(X0,X1,X2),statements(X0)) + :- ast(fact(statements(X0,X1,X2));add(statements(X0,X1,X2));delete(statements(X0,X1,X2))). + +ast_fact2id(constants(X0,X1,X2),constants(X0)) + :- ast(fact(constants(X0,X1,X2));add(constants(X0,X1,X2));delete(constants(X0,X1,X2))). + +ast_fact2id(program(X0,X1,X2,X3),program(X0)) + :- ast(fact(program(X0,X1,X2,X3));add(program(X0,X1,X2,X3));delete(program(X0,X1,X2,X3))). + +ast_fact2id(external(X0,X1,X2,X3),external(X0)) + :- ast(fact(external(X0,X1,X2,X3));add(external(X0,X1,X2,X3));delete(external(X0,X1,X2,X3))). + +ast_fact2id(edge(X0,X1,X2,X3),edge(X0)) + :- ast(fact(edge(X0,X1,X2,X3));add(edge(X0,X1,X2,X3));delete(edge(X0,X1,X2,X3))). + +ast_fact2id(heuristic(X0,X1,X2,X3,X4,X5),heuristic(X0)) + :- ast(fact(heuristic(X0,X1,X2,X3,X4,X5));add(heuristic(X0,X1,X2,X3,X4,X5));delete(heuristic(X0,X1,X2,X3,X4,X5))). + +ast_fact2id(project_atom(X0,X1,X2),project_atom(X0)) + :- ast(fact(project_atom(X0,X1,X2));add(project_atom(X0,X1,X2));delete(project_atom(X0,X1,X2))). + +ast_fact2id(project_signature(X0,X1,X2,X3),project_signature(X0)) + :- ast(fact(project_signature(X0,X1,X2,X3));add(project_signature(X0,X1,X2,X3));delete(project_signature(X0,X1,X2,X3))). + +ast_fact2id(theory_operator_definitions(X0,X1,X2,X3,X4),theory_operator_definitions(X0)) + :- ast(fact(theory_operator_definitions(X0,X1,X2,X3,X4));add(theory_operator_definitions(X0,X1,X2,X3,X4));delete(theory_operator_definitions(X0,X1,X2,X3,X4))). + +ast_fact2id(theory_term_definitions(X0,X1,X2,X3),theory_term_definitions(X0)) + :- ast(fact(theory_term_definitions(X0,X1,X2,X3));add(theory_term_definitions(X0,X1,X2,X3));delete(theory_term_definitions(X0,X1,X2,X3))). + +ast_fact2id(theory_guard_definition(X0,X1,X2),theory_guard_definition(X0)) + :- ast(fact(theory_guard_definition(X0,X1,X2));add(theory_guard_definition(X0,X1,X2));delete(theory_guard_definition(X0,X1,X2))). + +ast_fact2id(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6),theory_atom_definitions(X0)) + :- ast(fact(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6));add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6));delete(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6))). + +ast_fact2id(theory_definition(X0,X1,X2,X3),theory_definition(X0)) + :- ast(fact(theory_definition(X0,X1,X2,X3));add(theory_definition(X0,X1,X2,X3));delete(theory_definition(X0,X1,X2,X3))). + +ast_fact2id(location(Id,Begin,End),Id) :- ast(fact(location(Id,Begin,End));add(location(Id,Begin,End));delete(location(Id,Begin,End))). diff --git a/src/renopro/asp/new_replace.lp b/src/renopro/asp/new_replace.lp deleted file mode 100644 index f6ed13d..0000000 --- a/src/renopro/asp/new_replace.lp +++ /dev/null @@ -1 +0,0 @@ -ast_operation(delete(A);add(A)) :- replace(A,B). diff --git a/src/renopro/asp/reachable.lp b/src/renopro/asp/reachable.lp deleted file mode 100644 index 748aebb..0000000 --- a/src/renopro/asp/reachable.lp +++ /dev/null @@ -1,13 +0,0 @@ -reach(program(P,Name,Params,Stms)) :- transformed(program(P,Name,Params,Stms)). - -reach(child(ParentId,ChildId);ChildFact) - :- reach(ParentFact), transformed_ast_fact2id(ParentFact,ParentId), - transformed(child(ParentId,ChildId)), transformed_ast_fact2id(ChildFact,ChildId). - -final(R) :- reach(R). - -%% #show log("warning", "{}",reach(F)) : reach(F). -%% #show log("warning", "{}",transformed(F)) : transformed(F), transformed_ast_fact2id(F,Id). -%% #show log("warning", "{}",final(F)) : final(F). -%% #show log("warning", "{}",ast(F)) : ast(F). -%% #show log("warning", "{}",ast_operation(F)) : ast_operation(F). diff --git a/src/renopro/asp/replace.lp b/src/renopro/asp/replace.lp deleted file mode 100644 index ee078fc..0000000 --- a/src/renopro/asp/replace.lp +++ /dev/null @@ -1,404 +0,0 @@ -% replace(A,B) replaces a child predicate identifier A -% with child predicate identifier B in each AST fact where A -% occurs as a term. - -ast_operation(add(unary_operation(X0,X1,B));delete(unary_operation(X0,X1,A))) - :- ast_operation(replace(A,B)), unary_operation(X0,X1,A). -ast_operation(add(unary_operation(X0,X1,B));delete(unary_operation(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(unary_operation(X0,X1,A))). - -ast_operation(add(binary_operation(X0,X1,B,X3));delete(binary_operation(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), binary_operation(X0,X1,A,X3). -ast_operation(add(binary_operation(X0,X1,B,X3));delete(binary_operation(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(binary_operation(X0,X1,A,X3))). - -ast_operation(add(binary_operation(X0,X1,X2,B));delete(binary_operation(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), binary_operation(X0,X1,X2,A). -ast_operation(add(binary_operation(X0,X1,X2,B));delete(binary_operation(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(binary_operation(X0,X1,X2,A))). - -ast_operation(add(interval(X0,B,X2));delete(interval(X0,A,X2))) - :- ast_operation(replace(A,B)), interval(X0,A,X2). -ast_operation(add(interval(X0,B,X2));delete(interval(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(interval(X0,A,X2))). - -ast_operation(add(interval(X0,X1,B));delete(interval(X0,X1,A))) - :- ast_operation(replace(A,B)), interval(X0,X1,A). -ast_operation(add(interval(X0,X1,B));delete(interval(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(interval(X0,X1,A))). - -ast_operation(add(terms(X0,X1,B));delete(terms(X0,X1,A))) - :- ast_operation(replace(A,B)), terms(X0,X1,A). -ast_operation(add(terms(X0,X1,B));delete(terms(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(terms(X0,X1,A))). - -ast_operation(add(function(X0,X1,B));delete(function(X0,X1,A))) - :- ast_operation(replace(A,B)), function(X0,X1,A). -ast_operation(add(function(X0,X1,B));delete(function(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(function(X0,X1,A))). - -ast_operation(add(external_function(X0,X1,B));delete(external_function(X0,X1,A))) - :- ast_operation(replace(A,B)), external_function(X0,X1,A). -ast_operation(add(external_function(X0,X1,B));delete(external_function(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(external_function(X0,X1,A))). - -ast_operation(add(pool(X0,B));delete(pool(X0,A))) - :- ast_operation(replace(A,B)), pool(X0,A). -ast_operation(add(pool(X0,B));delete(pool(X0,A))) - :- ast_operation(replace(A,B)), ast_operation(add(pool(X0,A))). - -ast_operation(add(theory_terms(X0,X1,B));delete(theory_terms(X0,X1,A))) - :- ast_operation(replace(A,B)), theory_terms(X0,X1,A). -ast_operation(add(theory_terms(X0,X1,B));delete(theory_terms(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_terms(X0,X1,A))). - -ast_operation(add(theory_sequence(X0,X1,B));delete(theory_sequence(X0,X1,A))) - :- ast_operation(replace(A,B)), theory_sequence(X0,X1,A). -ast_operation(add(theory_sequence(X0,X1,B));delete(theory_sequence(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_sequence(X0,X1,A))). - -ast_operation(add(theory_function(X0,X1,B));delete(theory_function(X0,X1,A))) - :- ast_operation(replace(A,B)), theory_function(X0,X1,A). -ast_operation(add(theory_function(X0,X1,B));delete(theory_function(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_function(X0,X1,A))). - -ast_operation(add(theory_unparsed_term_elements(X0,X1,B,X3));delete(theory_unparsed_term_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), theory_unparsed_term_elements(X0,X1,A,X3). -ast_operation(add(theory_unparsed_term_elements(X0,X1,B,X3));delete(theory_unparsed_term_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_unparsed_term_elements(X0,X1,A,X3))). - -ast_operation(add(theory_unparsed_term_elements(X0,X1,X2,B));delete(theory_unparsed_term_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), theory_unparsed_term_elements(X0,X1,X2,A). -ast_operation(add(theory_unparsed_term_elements(X0,X1,X2,B));delete(theory_unparsed_term_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_unparsed_term_elements(X0,X1,X2,A))). - -ast_operation(add(theory_unparsed_term(X0,B));delete(theory_unparsed_term(X0,A))) - :- ast_operation(replace(A,B)), theory_unparsed_term(X0,A). -ast_operation(add(theory_unparsed_term(X0,B));delete(theory_unparsed_term(X0,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_unparsed_term(X0,A))). - -ast_operation(add(guard(X0,X1,B));delete(guard(X0,X1,A))) - :- ast_operation(replace(A,B)), guard(X0,X1,A). -ast_operation(add(guard(X0,X1,B));delete(guard(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(guard(X0,X1,A))). - -ast_operation(add(guards(X0,X1,B));delete(guards(X0,X1,A))) - :- ast_operation(replace(A,B)), guards(X0,X1,A). -ast_operation(add(guards(X0,X1,B));delete(guards(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(guards(X0,X1,A))). - -ast_operation(add(comparison(X0,B,X2));delete(comparison(X0,A,X2))) - :- ast_operation(replace(A,B)), comparison(X0,A,X2). -ast_operation(add(comparison(X0,B,X2));delete(comparison(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(comparison(X0,A,X2))). - -ast_operation(add(comparison(X0,X1,B));delete(comparison(X0,X1,A))) - :- ast_operation(replace(A,B)), comparison(X0,X1,A). -ast_operation(add(comparison(X0,X1,B));delete(comparison(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(comparison(X0,X1,A))). - -ast_operation(add(symbolic_atom(X0,B));delete(symbolic_atom(X0,A))) - :- ast_operation(replace(A,B)), symbolic_atom(X0,A). -ast_operation(add(symbolic_atom(X0,B));delete(symbolic_atom(X0,A))) - :- ast_operation(replace(A,B)), ast_operation(add(symbolic_atom(X0,A))). - -ast_operation(add(literal(X0,X1,B));delete(literal(X0,X1,A))) - :- ast_operation(replace(A,B)), literal(X0,X1,A). -ast_operation(add(literal(X0,X1,B));delete(literal(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(literal(X0,X1,A))). - -ast_operation(add(literals(X0,X1,B));delete(literals(X0,X1,A))) - :- ast_operation(replace(A,B)), literals(X0,X1,A). -ast_operation(add(literals(X0,X1,B));delete(literals(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(literals(X0,X1,A))). - -ast_operation(add(conditional_literal(X0,B,X2));delete(conditional_literal(X0,A,X2))) - :- ast_operation(replace(A,B)), conditional_literal(X0,A,X2). -ast_operation(add(conditional_literal(X0,B,X2));delete(conditional_literal(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(conditional_literal(X0,A,X2))). - -ast_operation(add(conditional_literal(X0,X1,B));delete(conditional_literal(X0,X1,A))) - :- ast_operation(replace(A,B)), conditional_literal(X0,X1,A). -ast_operation(add(conditional_literal(X0,X1,B));delete(conditional_literal(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(conditional_literal(X0,X1,A))). - -ast_operation(add(aggregate_elements(X0,X1,B));delete(aggregate_elements(X0,X1,A))) - :- ast_operation(replace(A,B)), aggregate_elements(X0,X1,A). -ast_operation(add(aggregate_elements(X0,X1,B));delete(aggregate_elements(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(aggregate_elements(X0,X1,A))). - -ast_operation(add(aggregate(X0,B,X2,X3));delete(aggregate(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), aggregate(X0,A,X2,X3). -ast_operation(add(aggregate(X0,B,X2,X3));delete(aggregate(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(aggregate(X0,A,X2,X3))). - -ast_operation(add(aggregate(X0,X1,B,X3));delete(aggregate(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), aggregate(X0,X1,A,X3). -ast_operation(add(aggregate(X0,X1,B,X3));delete(aggregate(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(aggregate(X0,X1,A,X3))). - -ast_operation(add(aggregate(X0,X1,X2,B));delete(aggregate(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), aggregate(X0,X1,X2,A). -ast_operation(add(aggregate(X0,X1,X2,B));delete(aggregate(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(aggregate(X0,X1,X2,A))). - -ast_operation(add(theory_atom_elements(X0,X1,B,X3));delete(theory_atom_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), theory_atom_elements(X0,X1,A,X3). -ast_operation(add(theory_atom_elements(X0,X1,B,X3));delete(theory_atom_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom_elements(X0,X1,A,X3))). - -ast_operation(add(theory_atom_elements(X0,X1,X2,B));delete(theory_atom_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), theory_atom_elements(X0,X1,X2,A). -ast_operation(add(theory_atom_elements(X0,X1,X2,B));delete(theory_atom_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom_elements(X0,X1,X2,A))). - -ast_operation(add(theory_guard(X0,X1,B));delete(theory_guard(X0,X1,A))) - :- ast_operation(replace(A,B)), theory_guard(X0,X1,A). -ast_operation(add(theory_guard(X0,X1,B));delete(theory_guard(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_guard(X0,X1,A))). - -ast_operation(add(theory_atom(X0,B,X2,X3));delete(theory_atom(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), theory_atom(X0,A,X2,X3). -ast_operation(add(theory_atom(X0,B,X2,X3));delete(theory_atom(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom(X0,A,X2,X3))). - -ast_operation(add(theory_atom(X0,X1,B,X3));delete(theory_atom(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), theory_atom(X0,X1,A,X3). -ast_operation(add(theory_atom(X0,X1,B,X3));delete(theory_atom(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom(X0,X1,A,X3))). - -ast_operation(add(theory_atom(X0,X1,X2,B));delete(theory_atom(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), theory_atom(X0,X1,X2,A). -ast_operation(add(theory_atom(X0,X1,X2,B));delete(theory_atom(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom(X0,X1,X2,A))). - -ast_operation(add(body_aggregate_elements(X0,X1,B,X3));delete(body_aggregate_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), body_aggregate_elements(X0,X1,A,X3). -ast_operation(add(body_aggregate_elements(X0,X1,B,X3));delete(body_aggregate_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(body_aggregate_elements(X0,X1,A,X3))). - -ast_operation(add(body_aggregate_elements(X0,X1,X2,B));delete(body_aggregate_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), body_aggregate_elements(X0,X1,X2,A). -ast_operation(add(body_aggregate_elements(X0,X1,X2,B));delete(body_aggregate_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(body_aggregate_elements(X0,X1,X2,A))). - -ast_operation(add(body_aggregate(X0,B,X2,X3,X4));delete(body_aggregate(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), body_aggregate(X0,A,X2,X3,X4). -ast_operation(add(body_aggregate(X0,B,X2,X3,X4));delete(body_aggregate(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(body_aggregate(X0,A,X2,X3,X4))). - -ast_operation(add(body_aggregate(X0,X1,X2,B,X4));delete(body_aggregate(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), body_aggregate(X0,X1,X2,A,X4). -ast_operation(add(body_aggregate(X0,X1,X2,B,X4));delete(body_aggregate(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(body_aggregate(X0,X1,X2,A,X4))). - -ast_operation(add(body_aggregate(X0,X1,X2,X3,B));delete(body_aggregate(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), body_aggregate(X0,X1,X2,X3,A). -ast_operation(add(body_aggregate(X0,X1,X2,X3,B));delete(body_aggregate(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), ast_operation(add(body_aggregate(X0,X1,X2,X3,A))). - -ast_operation(add(body_literal(X0,X1,B));delete(body_literal(X0,X1,A))) - :- ast_operation(replace(A,B)), body_literal(X0,X1,A). -ast_operation(add(body_literal(X0,X1,B));delete(body_literal(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(body_literal(X0,X1,A))). - -ast_operation(add(body_literals(X0,X1,B));delete(body_literals(X0,X1,A))) - :- ast_operation(replace(A,B)), body_literals(X0,X1,A). -ast_operation(add(body_literals(X0,X1,B));delete(body_literals(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(body_literals(X0,X1,A))). - -ast_operation(add(head_aggregate_elements(X0,X1,B,X3));delete(head_aggregate_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), head_aggregate_elements(X0,X1,A,X3). -ast_operation(add(head_aggregate_elements(X0,X1,B,X3));delete(head_aggregate_elements(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(head_aggregate_elements(X0,X1,A,X3))). - -ast_operation(add(head_aggregate_elements(X0,X1,X2,B));delete(head_aggregate_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), head_aggregate_elements(X0,X1,X2,A). -ast_operation(add(head_aggregate_elements(X0,X1,X2,B));delete(head_aggregate_elements(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(head_aggregate_elements(X0,X1,X2,A))). - -ast_operation(add(head_aggregate(X0,B,X2,X3,X4));delete(head_aggregate(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), head_aggregate(X0,A,X2,X3,X4). -ast_operation(add(head_aggregate(X0,B,X2,X3,X4));delete(head_aggregate(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(head_aggregate(X0,A,X2,X3,X4))). - -ast_operation(add(head_aggregate(X0,X1,X2,B,X4));delete(head_aggregate(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), head_aggregate(X0,X1,X2,A,X4). -ast_operation(add(head_aggregate(X0,X1,X2,B,X4));delete(head_aggregate(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(head_aggregate(X0,X1,X2,A,X4))). - -ast_operation(add(head_aggregate(X0,X1,X2,X3,B));delete(head_aggregate(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), head_aggregate(X0,X1,X2,X3,A). -ast_operation(add(head_aggregate(X0,X1,X2,X3,B));delete(head_aggregate(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), ast_operation(add(head_aggregate(X0,X1,X2,X3,A))). - -ast_operation(add(conditional_literals(X0,X1,B));delete(conditional_literals(X0,X1,A))) - :- ast_operation(replace(A,B)), conditional_literals(X0,X1,A). -ast_operation(add(conditional_literals(X0,X1,B));delete(conditional_literals(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(conditional_literals(X0,X1,A))). - -ast_operation(add(disjunction(X0,B));delete(disjunction(X0,A))) - :- ast_operation(replace(A,B)), disjunction(X0,A). -ast_operation(add(disjunction(X0,B));delete(disjunction(X0,A))) - :- ast_operation(replace(A,B)), ast_operation(add(disjunction(X0,A))). - -ast_operation(add(rule(X0,B,X2));delete(rule(X0,A,X2))) - :- ast_operation(replace(A,B)), rule(X0,A,X2). -ast_operation(add(rule(X0,B,X2));delete(rule(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(rule(X0,A,X2))). - -ast_operation(add(rule(X0,X1,B));delete(rule(X0,X1,A))) - :- ast_operation(replace(A,B)), rule(X0,X1,A). -ast_operation(add(rule(X0,X1,B));delete(rule(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(rule(X0,X1,A))). - -ast_operation(add(definition(X0,X1,B,X3));delete(definition(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), definition(X0,X1,A,X3). -ast_operation(add(definition(X0,X1,B,X3));delete(definition(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(definition(X0,X1,A,X3))). - -ast_operation(add(show_term(X0,B,X2));delete(show_term(X0,A,X2))) - :- ast_operation(replace(A,B)), show_term(X0,A,X2). -ast_operation(add(show_term(X0,B,X2));delete(show_term(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(show_term(X0,A,X2))). - -ast_operation(add(show_term(X0,X1,B));delete(show_term(X0,X1,A))) - :- ast_operation(replace(A,B)), show_term(X0,X1,A). -ast_operation(add(show_term(X0,X1,B));delete(show_term(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(show_term(X0,X1,A))). - -ast_operation(add(minimize(X0,B,X2,X3,X4));delete(minimize(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), minimize(X0,A,X2,X3,X4). -ast_operation(add(minimize(X0,B,X2,X3,X4));delete(minimize(X0,A,X2,X3,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(minimize(X0,A,X2,X3,X4))). - -ast_operation(add(minimize(X0,X1,B,X3,X4));delete(minimize(X0,X1,A,X3,X4))) - :- ast_operation(replace(A,B)), minimize(X0,X1,A,X3,X4). -ast_operation(add(minimize(X0,X1,B,X3,X4));delete(minimize(X0,X1,A,X3,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(minimize(X0,X1,A,X3,X4))). - -ast_operation(add(minimize(X0,X1,X2,B,X4));delete(minimize(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), minimize(X0,X1,X2,A,X4). -ast_operation(add(minimize(X0,X1,X2,B,X4));delete(minimize(X0,X1,X2,A,X4))) - :- ast_operation(replace(A,B)), ast_operation(add(minimize(X0,X1,X2,A,X4))). - -ast_operation(add(minimize(X0,X1,X2,X3,B));delete(minimize(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), minimize(X0,X1,X2,X3,A). -ast_operation(add(minimize(X0,X1,X2,X3,B));delete(minimize(X0,X1,X2,X3,A))) - :- ast_operation(replace(A,B)), ast_operation(add(minimize(X0,X1,X2,X3,A))). - -ast_operation(add(statements(X0,X1,B));delete(statements(X0,X1,A))) - :- ast_operation(replace(A,B)), statements(X0,X1,A). -ast_operation(add(statements(X0,X1,B));delete(statements(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(statements(X0,X1,A))). - -ast_operation(add(constants(X0,X1,B));delete(constants(X0,X1,A))) - :- ast_operation(replace(A,B)), constants(X0,X1,A). -ast_operation(add(constants(X0,X1,B));delete(constants(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(constants(X0,X1,A))). - -ast_operation(add(program(X0,X1,B,X3));delete(program(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), program(X0,X1,A,X3). -ast_operation(add(program(X0,X1,B,X3));delete(program(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(program(X0,X1,A,X3))). - -ast_operation(add(program(X0,X1,X2,B));delete(program(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), program(X0,X1,X2,A). -ast_operation(add(program(X0,X1,X2,B));delete(program(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(program(X0,X1,X2,A))). - -ast_operation(add(external(X0,B,X2,X3));delete(external(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), external(X0,A,X2,X3). -ast_operation(add(external(X0,B,X2,X3));delete(external(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(external(X0,A,X2,X3))). - -ast_operation(add(external(X0,X1,B,X3));delete(external(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), external(X0,X1,A,X3). -ast_operation(add(external(X0,X1,B,X3));delete(external(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(external(X0,X1,A,X3))). - -ast_operation(add(edge(X0,B,X2,X3));delete(edge(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), edge(X0,A,X2,X3). -ast_operation(add(edge(X0,B,X2,X3));delete(edge(X0,A,X2,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(edge(X0,A,X2,X3))). - -ast_operation(add(edge(X0,X1,B,X3));delete(edge(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), edge(X0,X1,A,X3). -ast_operation(add(edge(X0,X1,B,X3));delete(edge(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(edge(X0,X1,A,X3))). - -ast_operation(add(edge(X0,X1,X2,B));delete(edge(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), edge(X0,X1,X2,A). -ast_operation(add(edge(X0,X1,X2,B));delete(edge(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(edge(X0,X1,X2,A))). - -ast_operation(add(heuristic(X0,B,X2,X3,X4,X5));delete(heuristic(X0,A,X2,X3,X4,X5))) - :- ast_operation(replace(A,B)), heuristic(X0,A,X2,X3,X4,X5). -ast_operation(add(heuristic(X0,B,X2,X3,X4,X5));delete(heuristic(X0,A,X2,X3,X4,X5))) - :- ast_operation(replace(A,B)), ast_operation(add(heuristic(X0,A,X2,X3,X4,X5))). - -ast_operation(add(heuristic(X0,X1,B,X3,X4,X5));delete(heuristic(X0,X1,A,X3,X4,X5))) - :- ast_operation(replace(A,B)), heuristic(X0,X1,A,X3,X4,X5). -ast_operation(add(heuristic(X0,X1,B,X3,X4,X5));delete(heuristic(X0,X1,A,X3,X4,X5))) - :- ast_operation(replace(A,B)), ast_operation(add(heuristic(X0,X1,A,X3,X4,X5))). - -ast_operation(add(heuristic(X0,X1,X2,B,X4,X5));delete(heuristic(X0,X1,X2,A,X4,X5))) - :- ast_operation(replace(A,B)), heuristic(X0,X1,X2,A,X4,X5). -ast_operation(add(heuristic(X0,X1,X2,B,X4,X5));delete(heuristic(X0,X1,X2,A,X4,X5))) - :- ast_operation(replace(A,B)), ast_operation(add(heuristic(X0,X1,X2,A,X4,X5))). - -ast_operation(add(heuristic(X0,X1,X2,X3,B,X5));delete(heuristic(X0,X1,X2,X3,A,X5))) - :- ast_operation(replace(A,B)), heuristic(X0,X1,X2,X3,A,X5). -ast_operation(add(heuristic(X0,X1,X2,X3,B,X5));delete(heuristic(X0,X1,X2,X3,A,X5))) - :- ast_operation(replace(A,B)), ast_operation(add(heuristic(X0,X1,X2,X3,A,X5))). - -ast_operation(add(heuristic(X0,X1,X2,X3,X4,B));delete(heuristic(X0,X1,X2,X3,X4,A))) - :- ast_operation(replace(A,B)), heuristic(X0,X1,X2,X3,X4,A). -ast_operation(add(heuristic(X0,X1,X2,X3,X4,B));delete(heuristic(X0,X1,X2,X3,X4,A))) - :- ast_operation(replace(A,B)), ast_operation(add(heuristic(X0,X1,X2,X3,X4,A))). - -ast_operation(add(project_atom(X0,B,X2));delete(project_atom(X0,A,X2))) - :- ast_operation(replace(A,B)), project_atom(X0,A,X2). -ast_operation(add(project_atom(X0,B,X2));delete(project_atom(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(project_atom(X0,A,X2))). - -ast_operation(add(project_atom(X0,X1,B));delete(project_atom(X0,X1,A))) - :- ast_operation(replace(A,B)), project_atom(X0,X1,A). -ast_operation(add(project_atom(X0,X1,B));delete(project_atom(X0,X1,A))) - :- ast_operation(replace(A,B)), ast_operation(add(project_atom(X0,X1,A))). - -ast_operation(add(theory_term_definitions(X0,X1,X2,B));delete(theory_term_definitions(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), theory_term_definitions(X0,X1,X2,A). -ast_operation(add(theory_term_definitions(X0,X1,X2,B));delete(theory_term_definitions(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_term_definitions(X0,X1,X2,A))). - -ast_operation(add(theory_guard_definition(X0,B,X2));delete(theory_guard_definition(X0,A,X2))) - :- ast_operation(replace(A,B)), theory_guard_definition(X0,A,X2). -ast_operation(add(theory_guard_definition(X0,B,X2));delete(theory_guard_definition(X0,A,X2))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_guard_definition(X0,A,X2))). - -ast_operation(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,B));delete(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A))) - :- ast_operation(replace(A,B)), theory_atom_definitions(X0,X1,X2,X3,X4,X5,A). -ast_operation(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,B));delete(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A))). - -ast_operation(add(theory_definition(X0,X1,B,X3));delete(theory_definition(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), theory_definition(X0,X1,A,X3). -ast_operation(add(theory_definition(X0,X1,B,X3));delete(theory_definition(X0,X1,A,X3))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_definition(X0,X1,A,X3))). - -ast_operation(add(theory_definition(X0,X1,X2,B));delete(theory_definition(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), theory_definition(X0,X1,X2,A). -ast_operation(add(theory_definition(X0,X1,X2,B));delete(theory_definition(X0,X1,X2,A))) - :- ast_operation(replace(A,B)), ast_operation(add(theory_definition(X0,X1,X2,A))). - -ast_operation(add(child(B,X1));delete(child(A,X1))) - :- ast_operation(replace(A,B)), child(A,X1). -ast_operation(add(child(B,X1));delete(child(A,X1))) - :- ast_operation(replace(A,B)), ast_operation(add(child(A,X1))). - -ast_operation(add(child(X0,B));delete(child(X0,A))) - :- ast_operation(replace(A,B)), child(X0,A). -ast_operation(add(child(X0,B));delete(child(X0,A))) - :- ast_operation(replace(A,B)), ast_operation(add(child(X0,A))). - diff --git a/src/renopro/asp/replace_id.lp b/src/renopro/asp/replace_id.lp new file mode 100644 index 0000000..7e1c671 --- /dev/null +++ b/src/renopro/asp/replace_id.lp @@ -0,0 +1,240 @@ +% replace(A,B) replaces a child predicate identifier A +% with child predicate identifier B in each AST fact where A +% occurs as a term. + +ast(add(unary_operation(X0,X1,B));delete(unary_operation(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(unary_operation(X0,X1,A));add(unary_operation(X0,X1,A))). + +ast(add(binary_operation(X0,X1,B,X3));delete(binary_operation(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(binary_operation(X0,X1,A,X3));add(binary_operation(X0,X1,A,X3))). + +ast(add(binary_operation(X0,X1,X2,B));delete(binary_operation(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(binary_operation(X0,X1,X2,A));add(binary_operation(X0,X1,X2,A))). + +ast(add(interval(X0,B,X2));delete(interval(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(interval(X0,A,X2));add(interval(X0,A,X2))). + +ast(add(interval(X0,X1,B));delete(interval(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(interval(X0,X1,A));add(interval(X0,X1,A))). + +ast(add(terms(X0,X1,B));delete(terms(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(terms(X0,X1,A));add(terms(X0,X1,A))). + +ast(add(function(X0,X1,B));delete(function(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(function(X0,X1,A));add(function(X0,X1,A))). + +ast(add(external_function(X0,X1,B));delete(external_function(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(external_function(X0,X1,A));add(external_function(X0,X1,A))). + +ast(add(pool(X0,B));delete(pool(X0,A))) + :- ast(_replace_id(A,B)), ast(fact(pool(X0,A));add(pool(X0,A))). + +ast(add(theory_terms(X0,X1,B));delete(theory_terms(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_terms(X0,X1,A));add(theory_terms(X0,X1,A))). + +ast(add(theory_sequence(X0,X1,B));delete(theory_sequence(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_sequence(X0,X1,A));add(theory_sequence(X0,X1,A))). + +ast(add(theory_function(X0,X1,B));delete(theory_function(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_function(X0,X1,A));add(theory_function(X0,X1,A))). + +ast(add(theory_unparsed_term_elements(X0,X1,B,X3));delete(theory_unparsed_term_elements(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(theory_unparsed_term_elements(X0,X1,A,X3));add(theory_unparsed_term_elements(X0,X1,A,X3))). + +ast(add(theory_unparsed_term_elements(X0,X1,X2,B));delete(theory_unparsed_term_elements(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_unparsed_term_elements(X0,X1,X2,A));add(theory_unparsed_term_elements(X0,X1,X2,A))). + +ast(add(theory_unparsed_term(X0,B));delete(theory_unparsed_term(X0,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_unparsed_term(X0,A));add(theory_unparsed_term(X0,A))). + +ast(add(guard(X0,X1,B));delete(guard(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(guard(X0,X1,A));add(guard(X0,X1,A))). + +ast(add(guards(X0,X1,B));delete(guards(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(guards(X0,X1,A));add(guards(X0,X1,A))). + +ast(add(comparison(X0,B,X2));delete(comparison(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(comparison(X0,A,X2));add(comparison(X0,A,X2))). + +ast(add(comparison(X0,X1,B));delete(comparison(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(comparison(X0,X1,A));add(comparison(X0,X1,A))). + +ast(add(symbolic_atom(X0,B));delete(symbolic_atom(X0,A))) + :- ast(_replace_id(A,B)), ast(fact(symbolic_atom(X0,A));add(symbolic_atom(X0,A))). + +ast(add(literal(X0,X1,B));delete(literal(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(literal(X0,X1,A));add(literal(X0,X1,A))). + +ast(add(literals(X0,X1,B));delete(literals(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(literals(X0,X1,A));add(literals(X0,X1,A))). + +ast(add(conditional_literal(X0,B,X2));delete(conditional_literal(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(conditional_literal(X0,A,X2));add(conditional_literal(X0,A,X2))). + +ast(add(conditional_literal(X0,X1,B));delete(conditional_literal(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(conditional_literal(X0,X1,A));add(conditional_literal(X0,X1,A))). + +ast(add(aggregate_elements(X0,X1,B));delete(aggregate_elements(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(aggregate_elements(X0,X1,A));add(aggregate_elements(X0,X1,A))). + +ast(add(aggregate(X0,B,X2,X3));delete(aggregate(X0,A,X2,X3))) + :- ast(_replace_id(A,B)), ast(fact(aggregate(X0,A,X2,X3));add(aggregate(X0,A,X2,X3))). + +ast(add(aggregate(X0,X1,B,X3));delete(aggregate(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(aggregate(X0,X1,A,X3));add(aggregate(X0,X1,A,X3))). + +ast(add(aggregate(X0,X1,X2,B));delete(aggregate(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(aggregate(X0,X1,X2,A));add(aggregate(X0,X1,X2,A))). + +ast(add(theory_atom_elements(X0,X1,B,X3));delete(theory_atom_elements(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom_elements(X0,X1,A,X3));add(theory_atom_elements(X0,X1,A,X3))). + +ast(add(theory_atom_elements(X0,X1,X2,B));delete(theory_atom_elements(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom_elements(X0,X1,X2,A));add(theory_atom_elements(X0,X1,X2,A))). + +ast(add(theory_guard(X0,X1,B));delete(theory_guard(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_guard(X0,X1,A));add(theory_guard(X0,X1,A))). + +ast(add(theory_atom(X0,B,X2,X3));delete(theory_atom(X0,A,X2,X3))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom(X0,A,X2,X3));add(theory_atom(X0,A,X2,X3))). + +ast(add(theory_atom(X0,X1,B,X3));delete(theory_atom(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom(X0,X1,A,X3));add(theory_atom(X0,X1,A,X3))). + +ast(add(theory_atom(X0,X1,X2,B));delete(theory_atom(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom(X0,X1,X2,A));add(theory_atom(X0,X1,X2,A))). + +ast(add(body_aggregate_elements(X0,X1,B,X3));delete(body_aggregate_elements(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(body_aggregate_elements(X0,X1,A,X3));add(body_aggregate_elements(X0,X1,A,X3))). + +ast(add(body_aggregate_elements(X0,X1,X2,B));delete(body_aggregate_elements(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(body_aggregate_elements(X0,X1,X2,A));add(body_aggregate_elements(X0,X1,X2,A))). + +ast(add(body_aggregate(X0,B,X2,X3,X4));delete(body_aggregate(X0,A,X2,X3,X4))) + :- ast(_replace_id(A,B)), ast(fact(body_aggregate(X0,A,X2,X3,X4));add(body_aggregate(X0,A,X2,X3,X4))). + +ast(add(body_aggregate(X0,X1,X2,B,X4));delete(body_aggregate(X0,X1,X2,A,X4))) + :- ast(_replace_id(A,B)), ast(fact(body_aggregate(X0,X1,X2,A,X4));add(body_aggregate(X0,X1,X2,A,X4))). + +ast(add(body_aggregate(X0,X1,X2,X3,B));delete(body_aggregate(X0,X1,X2,X3,A))) + :- ast(_replace_id(A,B)), ast(fact(body_aggregate(X0,X1,X2,X3,A));add(body_aggregate(X0,X1,X2,X3,A))). + +ast(add(body_literal(X0,X1,B));delete(body_literal(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(body_literal(X0,X1,A));add(body_literal(X0,X1,A))). + +ast(add(body_literals(X0,X1,B));delete(body_literals(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(body_literals(X0,X1,A));add(body_literals(X0,X1,A))). + +ast(add(head_aggregate_elements(X0,X1,B,X3));delete(head_aggregate_elements(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(head_aggregate_elements(X0,X1,A,X3));add(head_aggregate_elements(X0,X1,A,X3))). + +ast(add(head_aggregate_elements(X0,X1,X2,B));delete(head_aggregate_elements(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(head_aggregate_elements(X0,X1,X2,A));add(head_aggregate_elements(X0,X1,X2,A))). + +ast(add(head_aggregate(X0,B,X2,X3,X4));delete(head_aggregate(X0,A,X2,X3,X4))) + :- ast(_replace_id(A,B)), ast(fact(head_aggregate(X0,A,X2,X3,X4));add(head_aggregate(X0,A,X2,X3,X4))). + +ast(add(head_aggregate(X0,X1,X2,B,X4));delete(head_aggregate(X0,X1,X2,A,X4))) + :- ast(_replace_id(A,B)), ast(fact(head_aggregate(X0,X1,X2,A,X4));add(head_aggregate(X0,X1,X2,A,X4))). + +ast(add(head_aggregate(X0,X1,X2,X3,B));delete(head_aggregate(X0,X1,X2,X3,A))) + :- ast(_replace_id(A,B)), ast(fact(head_aggregate(X0,X1,X2,X3,A));add(head_aggregate(X0,X1,X2,X3,A))). + +ast(add(conditional_literals(X0,X1,B));delete(conditional_literals(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(conditional_literals(X0,X1,A));add(conditional_literals(X0,X1,A))). + +ast(add(disjunction(X0,B));delete(disjunction(X0,A))) + :- ast(_replace_id(A,B)), ast(fact(disjunction(X0,A));add(disjunction(X0,A))). + +ast(add(rule(X0,B,X2));delete(rule(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(rule(X0,A,X2));add(rule(X0,A,X2))). + +ast(add(rule(X0,X1,B));delete(rule(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(rule(X0,X1,A));add(rule(X0,X1,A))). + +ast(add(definition(X0,X1,B,X3));delete(definition(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(definition(X0,X1,A,X3));add(definition(X0,X1,A,X3))). + +ast(add(show_term(X0,B,X2));delete(show_term(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(show_term(X0,A,X2));add(show_term(X0,A,X2))). + +ast(add(show_term(X0,X1,B));delete(show_term(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(show_term(X0,X1,A));add(show_term(X0,X1,A))). + +ast(add(minimize(X0,B,X2,X3,X4));delete(minimize(X0,A,X2,X3,X4))) + :- ast(_replace_id(A,B)), ast(fact(minimize(X0,A,X2,X3,X4));add(minimize(X0,A,X2,X3,X4))). + +ast(add(minimize(X0,X1,B,X3,X4));delete(minimize(X0,X1,A,X3,X4))) + :- ast(_replace_id(A,B)), ast(fact(minimize(X0,X1,A,X3,X4));add(minimize(X0,X1,A,X3,X4))). + +ast(add(minimize(X0,X1,X2,B,X4));delete(minimize(X0,X1,X2,A,X4))) + :- ast(_replace_id(A,B)), ast(fact(minimize(X0,X1,X2,A,X4));add(minimize(X0,X1,X2,A,X4))). + +ast(add(minimize(X0,X1,X2,X3,B));delete(minimize(X0,X1,X2,X3,A))) + :- ast(_replace_id(A,B)), ast(fact(minimize(X0,X1,X2,X3,A));add(minimize(X0,X1,X2,X3,A))). + +ast(add(statements(X0,X1,B));delete(statements(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(statements(X0,X1,A));add(statements(X0,X1,A))). + +ast(add(constants(X0,X1,B));delete(constants(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(constants(X0,X1,A));add(constants(X0,X1,A))). + +ast(add(program(X0,X1,B,X3));delete(program(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(program(X0,X1,A,X3));add(program(X0,X1,A,X3))). + +ast(add(program(X0,X1,X2,B));delete(program(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(program(X0,X1,X2,A));add(program(X0,X1,X2,A))). + +ast(add(external(X0,B,X2,X3));delete(external(X0,A,X2,X3))) + :- ast(_replace_id(A,B)), ast(fact(external(X0,A,X2,X3));add(external(X0,A,X2,X3))). + +ast(add(external(X0,X1,B,X3));delete(external(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(external(X0,X1,A,X3));add(external(X0,X1,A,X3))). + +ast(add(edge(X0,B,X2,X3));delete(edge(X0,A,X2,X3))) + :- ast(_replace_id(A,B)), ast(fact(edge(X0,A,X2,X3));add(edge(X0,A,X2,X3))). + +ast(add(edge(X0,X1,B,X3));delete(edge(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(edge(X0,X1,A,X3));add(edge(X0,X1,A,X3))). + +ast(add(edge(X0,X1,X2,B));delete(edge(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(edge(X0,X1,X2,A));add(edge(X0,X1,X2,A))). + +ast(add(heuristic(X0,B,X2,X3,X4,X5));delete(heuristic(X0,A,X2,X3,X4,X5))) + :- ast(_replace_id(A,B)), ast(fact(heuristic(X0,A,X2,X3,X4,X5));add(heuristic(X0,A,X2,X3,X4,X5))). + +ast(add(heuristic(X0,X1,B,X3,X4,X5));delete(heuristic(X0,X1,A,X3,X4,X5))) + :- ast(_replace_id(A,B)), ast(fact(heuristic(X0,X1,A,X3,X4,X5));add(heuristic(X0,X1,A,X3,X4,X5))). + +ast(add(heuristic(X0,X1,X2,B,X4,X5));delete(heuristic(X0,X1,X2,A,X4,X5))) + :- ast(_replace_id(A,B)), ast(fact(heuristic(X0,X1,X2,A,X4,X5));add(heuristic(X0,X1,X2,A,X4,X5))). + +ast(add(heuristic(X0,X1,X2,X3,B,X5));delete(heuristic(X0,X1,X2,X3,A,X5))) + :- ast(_replace_id(A,B)), ast(fact(heuristic(X0,X1,X2,X3,A,X5));add(heuristic(X0,X1,X2,X3,A,X5))). + +ast(add(heuristic(X0,X1,X2,X3,X4,B));delete(heuristic(X0,X1,X2,X3,X4,A))) + :- ast(_replace_id(A,B)), ast(fact(heuristic(X0,X1,X2,X3,X4,A));add(heuristic(X0,X1,X2,X3,X4,A))). + +ast(add(project_atom(X0,B,X2));delete(project_atom(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(project_atom(X0,A,X2));add(project_atom(X0,A,X2))). + +ast(add(project_atom(X0,X1,B));delete(project_atom(X0,X1,A))) + :- ast(_replace_id(A,B)), ast(fact(project_atom(X0,X1,A));add(project_atom(X0,X1,A))). + +ast(add(theory_term_definitions(X0,X1,X2,B));delete(theory_term_definitions(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_term_definitions(X0,X1,X2,A));add(theory_term_definitions(X0,X1,X2,A))). + +ast(add(theory_guard_definition(X0,B,X2));delete(theory_guard_definition(X0,A,X2))) + :- ast(_replace_id(A,B)), ast(fact(theory_guard_definition(X0,A,X2));add(theory_guard_definition(X0,A,X2))). + +ast(add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,B));delete(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A));add(theory_atom_definitions(X0,X1,X2,X3,X4,X5,A))). + +ast(add(theory_definition(X0,X1,B,X3));delete(theory_definition(X0,X1,A,X3))) + :- ast(_replace_id(A,B)), ast(fact(theory_definition(X0,X1,A,X3));add(theory_definition(X0,X1,A,X3))). + +ast(add(theory_definition(X0,X1,X2,B));delete(theory_definition(X0,X1,X2,A))) + :- ast(_replace_id(A,B)), ast(fact(theory_definition(X0,X1,X2,A));add(theory_definition(X0,X1,X2,A))). + +ast(add(child(X0,B));delete(child(X0,A))) + :- ast(_replace_id(A,B)), ast(fact(child(X0,A));add(child(X0,A))). \ No newline at end of file diff --git a/src/renopro/asp/transform.lp b/src/renopro/asp/transform.lp index a8818af..0ff2786 100644 --- a/src/renopro/asp/transform.lp +++ b/src/renopro/asp/transform.lp @@ -1,17 +1,25 @@ #include "ast.lp". #include "defined.lp". -#include "replace.lp". +#include "replace_id.lp". #include "decompose.lp". #include "add-children.lp". +#include "ast_fact2id.lp". + +ast(delete(A);add(B)) :- ast(replace(A,B)). +ast(_replace_id(AId,BId)) :- ast(replace(A,B)), ast_fact2id(A,AId), ast_fact2id(B,BId). % delete stops inertia from old ast -transformed(A) :- ast(A), not ast_operation(delete(A)). +transformed(A) :- ast(fact(A)), not ast(delete(A)). % and even overrides adding of new ast -transformed(A) :- ast_operation(add(A)), not ast_operation(delete(A)). +transformed(A) :- ast(add(A)), not ast(delete(A)). + +transformed(ast_fact2id(Fact,FactId)) :- transformed(Fact), ast_fact2id(Fact,FactId). -#include "transformed_ast_fact2id.lp". -#include "reachable.lp". +final(program(P,Name,Params,Stms)) :- transformed(program(P,Name,Params,Stms)). -#defined ast_operation/1. +final(child(ParentId,ChildId);ChildFact) + :- final(ParentFact), transformed(ast_fact2id(ParentFact,ParentId)), + transformed(child(ParentId,ChildId)), transformed(ast_fact2id(ChildFact,ChildId)). #show final/1. + diff --git a/src/renopro/asp/transformed_ast_fact2id.lp b/src/renopro/asp/transformed_ast_fact2id.lp deleted file mode 100644 index 4cba998..0000000 --- a/src/renopro/asp/transformed_ast_fact2id.lp +++ /dev/null @@ -1,60 +0,0 @@ -% map ast facts to their identifiers. - -transformed_ast_fact2id(string(X0,X1),string(X0)) :- transformed(string(X0,X1)). -transformed_ast_fact2id(number(X0,X1),number(X0)) :- transformed(number(X0,X1)). -transformed_ast_fact2id(variable(X0,X1),variable(X0)) :- transformed(variable(X0,X1)). -transformed_ast_fact2id(unary_operation(X0,X1,X2),unary_operation(X0)) :- transformed(unary_operation(X0,X1,X2)). -transformed_ast_fact2id(binary_operation(X0,X1,X2,X3),binary_operation(X0)) :- transformed(binary_operation(X0,X1,X2,X3)). -transformed_ast_fact2id(interval(X0,X1,X2),interval(X0)) :- transformed(interval(X0,X1,X2)). -transformed_ast_fact2id(terms(X0,X1,X2),terms(X0)) :- transformed(terms(X0,X1,X2)). -transformed_ast_fact2id(function(X0,X1,X2),function(X0)) :- transformed(function(X0,X1,X2)). -transformed_ast_fact2id(external_function(X0,X1,X2),external_function(X0)) :- transformed(external_function(X0,X1,X2)). -transformed_ast_fact2id(pool(X0,X1),pool(X0)) :- transformed(pool(X0,X1)). -transformed_ast_fact2id(theory_terms(X0,X1,X2),theory_terms(X0)) :- transformed(theory_terms(X0,X1,X2)). -transformed_ast_fact2id(theory_sequence(X0,X1,X2),theory_sequence(X0)) :- transformed(theory_sequence(X0,X1,X2)). -transformed_ast_fact2id(theory_function(X0,X1,X2),theory_function(X0)) :- transformed(theory_function(X0,X1,X2)). -transformed_ast_fact2id(theory_operators(X0,X1,X2),theory_operators(X0)) :- transformed(theory_operators(X0,X1,X2)). -transformed_ast_fact2id(theory_unparsed_term_elements(X0,X1,X2,X3),theory_unparsed_term_elements(X0)) :- transformed(theory_unparsed_term_elements(X0,X1,X2,X3)). -transformed_ast_fact2id(theory_unparsed_term(X0,X1),theory_unparsed_term(X0)) :- transformed(theory_unparsed_term(X0,X1)). -transformed_ast_fact2id(guard(X0,X1,X2),guard(X0)) :- transformed(guard(X0,X1,X2)). -transformed_ast_fact2id(guards(X0,X1,X2),guards(X0)) :- transformed(guards(X0,X1,X2)). -transformed_ast_fact2id(comparison(X0,X1,X2),comparison(X0)) :- transformed(comparison(X0,X1,X2)). -transformed_ast_fact2id(boolean_constant(X0,X1),boolean_constant(X0)) :- transformed(boolean_constant(X0,X1)). -transformed_ast_fact2id(symbolic_atom(X0,X1),symbolic_atom(X0)) :- transformed(symbolic_atom(X0,X1)). -transformed_ast_fact2id(literal(X0,X1,X2),literal(X0)) :- transformed(literal(X0,X1,X2)). -transformed_ast_fact2id(literals(X0,X1,X2),literals(X0)) :- transformed(literals(X0,X1,X2)). -transformed_ast_fact2id(conditional_literal(X0,X1,X2),conditional_literal(X0)) :- transformed(conditional_literal(X0,X1,X2)). -transformed_ast_fact2id(aggregate_elements(X0,X1,X2),aggregate_elements(X0)) :- transformed(aggregate_elements(X0,X1,X2)). -transformed_ast_fact2id(aggregate(X0,X1,X2,X3),aggregate(X0)) :- transformed(aggregate(X0,X1,X2,X3)). -transformed_ast_fact2id(theory_atom_elements(X0,X1,X2,X3),theory_atom_elements(X0)) :- transformed(theory_atom_elements(X0,X1,X2,X3)). -transformed_ast_fact2id(theory_guard(X0,X1,X2),theory_guard(X0)) :- transformed(theory_guard(X0,X1,X2)). -transformed_ast_fact2id(theory_atom(X0,X1,X2,X3),theory_atom(X0)) :- transformed(theory_atom(X0,X1,X2,X3)). -transformed_ast_fact2id(body_aggregate_elements(X0,X1,X2,X3),body_aggregate_elements(X0)) :- transformed(body_aggregate_elements(X0,X1,X2,X3)). -transformed_ast_fact2id(body_aggregate(X0,X1,X2,X3,X4),body_aggregate(X0)) :- transformed(body_aggregate(X0,X1,X2,X3,X4)). -transformed_ast_fact2id(body_literal(X0,X1,X2),body_literal(X0)) :- transformed(body_literal(X0,X1,X2)). -transformed_ast_fact2id(body_literals(X0,X1,X2),body_literals(X0)) :- transformed(body_literals(X0,X1,X2)). -transformed_ast_fact2id(head_aggregate_elements(X0,X1,X2,X3),head_aggregate_elements(X0)) :- transformed(head_aggregate_elements(X0,X1,X2,X3)). -transformed_ast_fact2id(head_aggregate(X0,X1,X2,X3,X4),head_aggregate(X0)) :- transformed(head_aggregate(X0,X1,X2,X3,X4)). -transformed_ast_fact2id(conditional_literals(X0,X1,X2),conditional_literals(X0)) :- transformed(conditional_literals(X0,X1,X2)). -transformed_ast_fact2id(disjunction(X0,X1),disjunction(X0)) :- transformed(disjunction(X0,X1)). -transformed_ast_fact2id(rule(X0,X1,X2),rule(X0)) :- transformed(rule(X0,X1,X2)). -transformed_ast_fact2id(definition(X0,X1,X2,X3),definition(X0)) :- transformed(definition(X0,X1,X2,X3)). -transformed_ast_fact2id(show_signature(X0,X1,X2,X3),show_signature(X0)) :- transformed(show_signature(X0,X1,X2,X3)). -transformed_ast_fact2id(defined(X0,X1,X2,X3),defined(X0)) :- transformed(defined(X0,X1,X2,X3)). -transformed_ast_fact2id(show_term(X0,X1,X2),show_term(X0)) :- transformed(show_term(X0,X1,X2)). -transformed_ast_fact2id(minimize(X0,X1,X2,X3,X4),minimize(X0)) :- transformed(minimize(X0,X1,X2,X3,X4)). -transformed_ast_fact2id(script(X0,X1,X2),script(X0)) :- transformed(script(X0,X1,X2)). -transformed_ast_fact2id(statements(X0,X1,X2),statements(X0)) :- transformed(statements(X0,X1,X2)). -transformed_ast_fact2id(constants(X0,X1,X2),constants(X0)) :- transformed(constants(X0,X1,X2)). -transformed_ast_fact2id(program(X0,X1,X2,X3),program(X0)) :- transformed(program(X0,X1,X2,X3)). -transformed_ast_fact2id(external(X0,X1,X2,X3),external(X0)) :- transformed(external(X0,X1,X2,X3)). -transformed_ast_fact2id(edge(X0,X1,X2,X3),edge(X0)) :- transformed(edge(X0,X1,X2,X3)). -transformed_ast_fact2id(heuristic(X0,X1,X2,X3,X4,X5),heuristic(X0)) :- transformed(heuristic(X0,X1,X2,X3,X4,X5)). -transformed_ast_fact2id(project_atom(X0,X1,X2),project_atom(X0)) :- transformed(project_atom(X0,X1,X2)). -transformed_ast_fact2id(project_signature(X0,X1,X2,X3),project_signature(X0)) :- transformed(project_signature(X0,X1,X2,X3)). -transformed_ast_fact2id(theory_operator_definitions(X0,X1,X2,X3,X4),theory_operator_definitions(X0)) :- transformed(theory_operator_definitions(X0,X1,X2,X3,X4)). -transformed_ast_fact2id(theory_term_definitions(X0,X1,X2,X3),theory_term_definitions(X0)) :- transformed(theory_term_definitions(X0,X1,X2,X3)). -transformed_ast_fact2id(theory_guard_definition(X0,X1,X2),theory_guard_definition(X0)) :- transformed(theory_guard_definition(X0,X1,X2)). -transformed_ast_fact2id(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6),theory_atom_definitions(X0)) :- transformed(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6)). -transformed_ast_fact2id(theory_definition(X0,X1,X2,X3),theory_definition(X0)) :- transformed(theory_definition(X0,X1,X2,X3)). -transformed_ast_fact2id(location(Id,Begin,End),Id) :- transformed(location(Id,Begin,End)). diff --git a/src/renopro/utils/codegen.py b/src/renopro/utils/codegen.py index 8c8c0e4..11cb023 100644 --- a/src/renopro/utils/codegen.py +++ b/src/renopro/utils/codegen.py @@ -12,7 +12,7 @@ def generate_replace(): "% occurs as a term.\n\n" ) for predicate in preds.AstPreds: - if predicate is preds.Location: + if predicate is preds.Location or predicate is preds.Child: continue replacements = [] name = predicate.meta.name @@ -34,21 +34,19 @@ def generate_replace(): ["X" + str(i) if i != idx else "B" for i in range(arity)] ) program += ( - f"ast_operation(add({name}({new_args}));" - f"delete({name}({old_args})))\n :- " - f"ast_operation(replace(A,B)), {name}({old_args}).\n" - f"ast_operation(add({name}({new_args}));" + f"ast(add({name}({new_args}));" f"delete({name}({old_args})))\n :- " - f"ast_operation(replace(A,B)), ast_operation(add({name}({old_args}))).\n\n" + f"ast(_replace_id(A,B)), ast(fact({name}({old_args}));add({name}({old_args}))).\n\n" ) - Path("src", "renopro", "asp", "replace.lp").write_text(program) + program += "ast(add(child(X0,B));delete(child(X0,A)))\n :- ast(_replace_id(A,B)), ast(fact(child(X0,A));add(child(X0,A)))." + Path("src", "renopro", "asp", "replace_id.lp").write_text(program) def generate_add_child(): """Generate rules to create child relations for all facts added - via ast_operation add, and rules to replace identifiers via - ast_operation replace.""" - add_child_program = "% Add child relations for facts added via ast_operation add.\n\n" + via ast add, and rules to replace identifiers via + ast replace.""" + add_child_program = "% Add child relations for facts added via ast add.\n\n" for predicate in preds.AstPreds: if predicate is preds.Location or predicate is preds.Child: continue @@ -68,8 +66,8 @@ def generate_add_child(): ["X" + str(i) if i != idx else "Child" for i in range(arity)] ) add_child_program += ( - f"ast_operation(add(child({name}(X0),Child)))\n :- " - f"ast_operation(add({name}({add_child_args}))).\n\n" + f"ast(add(child({name}(X0),Child)))\n :- " + f"ast(add({name}({add_child_args}))).\n\n" ) Path("src", "renopro", "asp", "add-children.lp").write_text(add_child_program) @@ -80,7 +78,7 @@ def generate_ast_fact2id(): for predicate in preds.AstPreds: if predicate is preds.Location: location = "location(Id,Begin,End)" - program += f"transformed_ast_fact2id({location},Id) :- transformed({location}).\n" + program += f"ast_fact2id({location},Id) :- ast(fact({location});add({location});delete({location})).\n" continue if predicate is preds.Child: continue @@ -89,8 +87,8 @@ def generate_ast_fact2id(): args = ",".join(["X" + str(i) for i in range(arity)]) fact = f"{name}({args})" identifier = f"{name}(X0)" - program += f"transformed_ast_fact2id({fact},{identifier}) :- transformed({fact}).\n" - Path("src", "renopro", "asp", "transformed_ast_fact2id.lp").write_text(program) + program += f"ast_fact2id({fact},{identifier})\n :- ast(fact({fact});add({fact});delete({fact})).\n\n" + Path("src", "renopro", "asp", "ast_fact2id.lp").write_text(program) def generate_ast(): @@ -101,7 +99,7 @@ def generate_ast(): arity = predicate.meta.arity args = ",".join(["X" + str(i) for i in range(arity)]) fact = f"{name}({args})" - rule = f"ast({fact}) :- {fact}.\n" + rule = f"ast(fact({fact})) :- {fact}.\n" program += rule Path("src", "renopro", "asp", "ast.lp").write_text(program) diff --git a/tests/asp/transform/meta-telingo/outputs/output-body.lp b/tests/asp/transform/meta-telingo/outputs/output-body.lp index 1b77956..f320910 100644 --- a/tests/asp/transform/meta-telingo/outputs/output-body.lp +++ b/tests/asp/transform/meta-telingo/outputs/output-body.lp @@ -10,12 +10,12 @@ j(X) :- next(wprev(k(X))). #program base. #false :- final; n. #program base. -#external final. [false] -#external next(wprev(k(X))). [false] -#external until(c,prev(d)). [false] -#external prev(prev(b)). [false] +#external prev(h(Y)) : h(Y); i(X). [false] +#external next(d(Y)) : d(Y); e(X). [false] +#external until(b(X),next(c((X+Y)))) : d(Y); e(X). [false] #external initial. [false] #external initial. [false] -#external until(b(X),next(c((X+Y)))) : e(X); d(Y). [false] -#external next(d(Y)) : e(X); d(Y). [false] -#external prev(h(Y)) : i(X); h(Y). [false] +#external prev(prev(b)). [false] +#external until(c,prev(d)). [false] +#external next(wprev(k(X))). [false] +#external final. [false] diff --git a/tests/asp/transform/meta-telingo/outputs/output-head.lp b/tests/asp/transform/meta-telingo/outputs/output-head.lp index 1fa92bc..0bc3ba1 100644 --- a/tests/asp/transform/meta-telingo/outputs/output-head.lp +++ b/tests/asp/transform/meta-telingo/outputs/output-head.lp @@ -5,12 +5,12 @@ release(b(X),next(c((X+Y)))): wnext(d(Y)) :- e(X). 3 < #max { 1: next(j(X)): prev(h(Y)) } :- i(X). prev(wprev(k(X))) :- j(X). #program base. -#external c : a. [false] -#external b(X) : e(X). [false] -#external j(X) : i(X); h(Y). [false] -#external c((X+Y)) : e(X). [false] -#external d : a. [false] -#external k(X) : j(X). [false] -#external initial. [false] +#external prev(h(Y)) : h(Y); i(X). [false] #external wnext(d(Y)) : e(X). [false] -#external prev(h(Y)) : i(X); h(Y). [false] +#external initial. [false] +#external k(X) : j(X). [false] +#external d : a. [false] +#external c((X+Y)) : e(X). [false] +#external j(X) : h(Y); i(X). [false] +#external b(X) : e(X). [false] +#external c : a. [false] diff --git a/tests/asp/transform/meta-telingo/outputs/telingo-output.lp b/tests/asp/transform/meta-telingo/outputs/telingo-output.lp index 158af31..5eba9c0 100644 --- a/tests/asp/transform/meta-telingo/outputs/telingo-output.lp +++ b/tests/asp/transform/meta-telingo/outputs/telingo-output.lp @@ -26,11 +26,11 @@ firearm(gun). #show show(fail(X)) : fail(X). #show show(unloaded(X)) : unloaded(X). #program base. -#external fail(X) : shoot(X); unloaded(X); shoot(X). [false] -#external unloaded(X) : firearm(X). [false] +#external and(and(shoot(X),prev(eventually_before(shoot(X)))),always_before(unloaded(X))) : shoot(X); unloaded(X); shoot(X). [false] +#external and(initial,firearm(X)) : firearm(X). [false] #external shoot(X) : firearm(X). [false] #external unloaded(X) : firearm(X). [false] #external unloaded(X) : firearm(X). [false] #external shoot(X) : firearm(X). [false] -#external and(initial,firearm(X)) : firearm(X). [false] -#external and(and(shoot(X),prev(eventually_before(shoot(X)))),always_before(unloaded(X))) : shoot(X); unloaded(X); shoot(X). [false] +#external unloaded(X) : firearm(X). [false] +#external fail(X) : shoot(X); unloaded(X); shoot(X). [false] diff --git a/tests/asp/transform/meta-telingo/transform-add-externals.lp b/tests/asp/transform/meta-telingo/transform-add-externals.lp index 2a12efd..584deee 100644 --- a/tests/asp/transform/meta-telingo/transform-add-externals.lp +++ b/tests/asp/transform/meta-telingo/transform-add-externals.lp @@ -119,31 +119,31 @@ root_op2extern_cond(Func,Sign,Func'') root_op2safe_leaf_operand(Func',Func''). % create a base subprogram under which the external will be added. -ast_operation( +ast( add(program(externals,"base",constants(externals),statements(externals))) ). % head of external condition in head operator case. -ast_operation( +ast( add(statements(externals,0,external(Operand)); external(Operand,symbolic_atom(Operand),body_literals(Func),false); symbolic_atom(Operand,Operand))) :- head_root_op(Func), root_op2leaf_operand(Func,Operand). % head of external condition in body operator case. -ast_operation( +ast( add(statements(externals,0,external(Func)); external(Func,symbolic_atom(Func),body_literals(Func),false); symbolic_atom(Func,Func))) :- body_root_op(Func). % body of external condition in all cases but when we have a propositional body operator. -ast_operation( +ast( add(body_literals(Func,0,body_literal(Func')); body_literal(Func',Sign,symbolic_atom(Func')); symbolic_atom(Func',Func'))) :- root_operator(Func), root_op2extern_cond(Func,Sign,Func'), #false : not has_var(Func), body_root_op(Func). % body of external condition when we have a propositional body operator. -ast_operation( +ast( add(body_literals(Func,0,body_literal(Func')); body_literal(Func',Sign,symbolic_atom(Func')); symbolic_atom(Func',Func'))) diff --git a/tests/asp/transform/meta-telingo/transform-subprogram.lp b/tests/asp/transform/meta-telingo/transform-subprogram.lp index 55b5d65..8fa2250 100644 --- a/tests/asp/transform/meta-telingo/transform-subprogram.lp +++ b/tests/asp/transform/meta-telingo/transform-subprogram.lp @@ -2,7 +2,7 @@ % move all the temporal subprograms into the base subprogram -ast_operation( +ast( delete(program(P,X,constants(CS),statements(STS))); add(program(P,"base",constants(CS),statements(STS)))) :- program(P,X,constants(CS),statements(STS)), not constants(CS,_,_), @@ -13,7 +13,7 @@ body_program(BLS,X) :- program(_,X,constants(CS),statements(STS)), not constants(CS,_,_), statements(STS,_,Statement), child(Statement,body_literals(BLS)), X=("initial";"dynamic";"always";"final"). -ast_operation( +ast( add(body_literals(BLS,-1,body_literal(BLS)); body_literal(BLS,"pos",symbolic_atom(BLS)); symbolic_atom(BLS,function(BLS)); @@ -21,7 +21,7 @@ ast_operation( ) :- body_program(BLS,"initial"). -ast_operation( +ast( add(body_literals(BLS,-1,body_literal(BLS)); body_literal(BLS,"pos",symbolic_atom(BLS)); symbolic_atom(BLS,function(BLS)); @@ -29,7 +29,7 @@ ast_operation( ) :- body_program(BLS,"final"). -ast_operation( +ast( add(body_literals(BLS,-1,body_literal(BLS)); body_literal(BLS,"not",symbolic_atom(BLS)); symbolic_atom(BLS,function(BLS)); @@ -39,7 +39,7 @@ ast_operation( % since there will be a downstream meta-encoding, construct the % child relation for the new ast elements. -ast_operation( +ast( add(child(body_literals(BLS),body_literal(BLS)); child(body_literal(BLS),symbolic_atom(BLS)); child(symbolic_atom(BLS),function(BLS))) diff --git a/tests/asp/transform/meta-telingo/transform-theory-to-symbolic.lp b/tests/asp/transform/meta-telingo/transform-theory-to-symbolic.lp index 1aa4ae1..beb0ad8 100644 --- a/tests/asp/transform/meta-telingo/transform-theory-to-symbolic.lp +++ b/tests/asp/transform/meta-telingo/transform-theory-to-symbolic.lp @@ -16,7 +16,7 @@ tel_theory_atom_terms(TTS,Loc) % each tel theory atom element should should have a single function or % theory function in it's term tuple, as we rewrite elements as -% conditional literals, and these may only have one literal in their +% conditional literals or body literals, and these may only have one literal in their % head. #show log("error","{}: The term tuple of tel theory atom elements must contain a single (temporal) formula.",Loc) : tel_theory_atom_terms(TTS,Loc), theory_terms(TTS,0,X), #false: X=theory_function(_); @@ -39,23 +39,15 @@ tel_root_term_desc(Term,Child') :- tel_root_term_desc(Term,Child), child(Child,C % Due to the way theory parsing is implemented upstream, we know that % theory function names can syntactically be operators if they are % defined tel theory operators -ast_operation( - delete(theory_function(TF,Name,theory_terms(TTS)); - theory_terms(TTS,P,TT)); - add(function(TF,SName,terms(TTS)); - terms(TTS,P,TT)); - replace(theory_function(TF),function(TF)) +ast(replace(theory_function(TF,Name,theory_terms(TTS)),function(TF,SName,terms(TTS)); + theory_terms(TTS,P,TT),terms(TTS,P,TT)) ) :- tel_root_term_desc(Term,theory_function(TF)), theory_function(TF,Name,theory_terms(TTS)), theory_terms(TTS,P,TT), arity(TF,Arity), theory_opertor2symbol(Name,Arity,SName). -ast_operation( - delete(theory_function(TF,Name,theory_terms(TTS)); - theory_terms(TTS,P,TT)); - add(function(TF,Const,terms(TTS)); - terms(TTS,P,TT)); - replace(theory_function(TF),function(TF)) +ast(replace(theory_function(TF,Name,theory_terms(TTS)),function(TF,Const,terms(TTS)); + theory_terms(TTS,P,TT),terms(TTS,P,TT)) ) :- tel_root_term_desc(Term,theory_function(TF)), theory_function(TF,Name,theory_terms(TTS)), theory_terms(TTS,P,TT), @@ -71,10 +63,11 @@ ast_operation( theory_atom(A,_,theory_atom_elements(E),_), #count{ P: theory_atom_elements(E,P,_,_) } > 1. -ast_operation( - replace(body_literal(BL),conditional_literal((A,1))); - add(conditional_literal((A,1),literal((A,2)),literals(LS)); - literal((A,2),Sign,symbolic_atom((A,3))); +% body case + +ast(replace(body_literal(BL,Sign,theory_atom(A)), + conditional_literal((A,1),literal((A,2)),literals(LS))); + add(literal((A,2),Sign,symbolic_atom((A,3))); symbolic_atom((A,3),function(F))) ) :- body_literals(BLS,P,body_literal(BL)), @@ -84,10 +77,9 @@ ast_operation( theory_terms(TS,0,RootTerm), tel_root_term_id(RootTerm,F), literals(LS,_,_). -ast_operation( - delete(body_literal(BL,Sign,theory_atom(A))); - add(body_literal(BL,Sign,symbolic_atom((A,1))); - symbolic_atom((A,1),function(F))) +ast(replace(body_literal(BL,Sign,theory_atom(A)), + body_literal((A,0),Sign,symbolic_atom((A,1)))); + add(symbolic_atom((A,1),function(F))) ) :- body_literals(BLS,P,body_literal(BL)), body_literal(BL,Sign,theory_atom(A)), tel_theory_atom(A,_), @@ -96,15 +88,16 @@ ast_operation( theory_terms(TS,0,RootTerm), tel_root_term_id(RootTerm,F), not literals(LS,_,_). -ast_operation( - replace(theory_atom(A),disjunction((A,1))); - add(disjunction((A,1),conditional_literals((A,2))); - conditional_literals((A,2),P,conditional_literal((A,3,P))); +% head case + +ast(replace(theory_atom(A,Func,theory_atom_elements(E),Guard), + disjunction((A,1),conditional_literals((A,2)))); + add(conditional_literals((A,2),P,conditional_literal((A,3,P))); conditional_literal((A,3,P),literal((A,4,P)),literals(LS)); literal((A,4,P),"pos",symbolic_atom((A,5))); symbolic_atom((A,5),function(F))) ) :- rule(_,theory_atom(A),_), tel_theory_atom(A,_), - theory_atom(A,_,theory_atom_elements(E),_), + theory_atom(A,Func,theory_atom_elements(E),Guard), theory_atom_elements(E,P,theory_terms(TS),literals(LS)), theory_terms(TS,0,RootTerm), tel_root_term_id(RootTerm,F). diff --git a/tests/asp/transform/not_bad/transform-decompose.lp b/tests/asp/transform/not_bad/transform-decompose.lp index 1306eba..3aef67c 100644 --- a/tests/asp/transform/not_bad/transform-decompose.lp +++ b/tests/asp/transform/not_bad/transform-decompose.lp @@ -17,7 +17,7 @@ max_lit_index(LT,Idx) :- Idx = #max{ P : body_literals(LT,P,_); -1 }, rule(_,_,body_literals(LT)). -ast_operation(add( +ast(add( @decompose( body_literals_( LT,N+1,body_literal_( diff --git a/tests/asp/transform/not_bad/transform.lp b/tests/asp/transform/not_bad/transform.lp index a2bc85e..450c4d4 100644 --- a/tests/asp/transform/not_bad/transform.lp +++ b/tests/asp/transform/not_bad/transform.lp @@ -19,7 +19,7 @@ max_lit_index(LT,Idx) %% the transformation itself -ast_operation( +ast( add((body_literals(LT,N+1,body_literal(new_id(LT,0))); body_literal(new_id(LT,0),"not",symbolic_atom(new_id(LT,1))); symbolic_atom(new_id(LT,1),function(new_id(LT,2))); diff --git a/tests/asp/transform/prev_to_timepoints/transform.lp b/tests/asp/transform/prev_to_timepoints/transform.lp index aac29c9..c8b1b26 100644 --- a/tests/asp/transform/prev_to_timepoints/transform.lp +++ b/tests/asp/transform/prev_to_timepoints/transform.lp @@ -25,7 +25,7 @@ first_prev(A,F) :- prev_chain(A,F,O), not prev_chain(A,_,F). % when an symbolic_atom is not prev. % add time point constant as additional argument -ast_operation( +ast( add(terms(T,N+1,function(new_id(T))); function(new_id(T),t,terms(new_id(T))))) :- symbolic_atom(A,function(F)), function(F,Name,terms(T)), @@ -35,12 +35,12 @@ ast_operation( % replace function symbol of symbolic_atom with final operand, appending % appropriate time point as additional argument. -ast_operation( +ast( delete(function(F,N,T1)); add(function(F,Name,terms(T2)); - terms(T2,I+1,binary_operation(new_id(O))); - binary_operation(new_id(O),"-",function(new_id(O)),number(new_id(O))); - function(new_id(O),t,terms(new_id(O))); - number(new_id(O),Num))) + terms(T2,I+1,binary_operation(new_id(O))); + binary_operation(new_id(O),"-",function(new_id(O)),number(new_id(O))); + function(new_id(O),t,terms(new_id(O))); + number(new_id(O),Num))) :- first_prev(A,function(F)), function(F,N,T1), final_operand(A,function(O)), function(O,Name,terms(T2)), max_arg_index(T2,I), num_prevs(A,Num). diff --git a/tests/asp/transform/theory-parsing/parse-unparsed-theory-terms.lp b/tests/asp/transform/theory-parsing/parse-unparsed-theory-terms.lp index 2ef1675..c43d516 100644 --- a/tests/asp/transform/theory-parsing/parse-unparsed-theory-terms.lp +++ b/tests/asp/transform/theory-parsing/parse-unparsed-theory-terms.lp @@ -144,10 +144,23 @@ call(parse(0,T',T)) :- last(T), next(T',T). % Finally, add the output of out Pratt parser to the AST in the correct place -ast_operation( - add(@decompose(theory_function(UT,Name,Args))); - replace(theory_unparsed_term(UT),theory_function(UT))) + +parsed(@decompose(theory_function(UT,Name,Args))) :- return(parse(0,T',T),(_,theory_function_(Name,Args))), last(T), next(T',T), theory_unparsed_term_elements(E,_,_,T), theory_unparsed_term(UT,theory_unparsed_term_elements(E)). + +ast(add(A)) :- parsed(A). + +ast(replace(theory_unparsed_term(UT,theory_unparsed_term_elements(E)), + theory_function(UT,Name,A))) + :- return(parse(0,T',T),(_,theory_function_(Name,Args))), + last(T), next(T',T), + theory_unparsed_term_elements(E,_,_,T), + theory_unparsed_term(UT,theory_unparsed_term_elements(E)), + parsed(theory_function(UT,Name,A)). + +%% theory_unparsed_term(UT,theory_unparsed_term_elements(E)), +%% parsed(theory_function(UT,Name,A)). +