-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add atom fact. Represent constant as function. Add external fact.
- Loading branch information
Showing
16 changed files
with
263 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
% reified fact representation of program: | ||
% #program base. | ||
% #external a(X) : c(X); d(e(X)). | ||
|
||
program("base",constant_tuple(0),statement_tuple(1)). | ||
statement_tuple(1,0,external(2)). | ||
external(2,atom(3),literal_tuple(7),false). | ||
atom(3,function(4)). | ||
function(4,a,term_tuple(5)). | ||
term_tuple(5,0,variable(6)). | ||
variable(6,"X"). | ||
literal_tuple(7,0,literal(8)). | ||
literal(8,"pos",atom(9)). | ||
atom(9,function(10)). | ||
function(10,c,term_tuple(11)). | ||
term_tuple(11,0,variable(12)). | ||
variable(12,"X"). | ||
literal_tuple(7,1,literal(13)). | ||
literal(13,"pos",atom(14)). | ||
atom(14,function(15)). | ||
function(15,d,term_tuple(16)). | ||
term_tuple(16,0,function(17)). | ||
function(17,e,term_tuple(18)). | ||
term_tuple(18,0,variable(19)). | ||
variable(19,"X"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 38 additions & 52 deletions
90
src/renopro/asp/tests/transform/prev_to_timepoints/transform.lp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,47 @@ | ||
% auxiliary atoms | ||
max_index(T,Index) :- Index = #max{ Pos : term_tuple(T,Pos,_); -1 }, term_tuple(T,_,_). | ||
arity(F,N+1) :- function(F,_,term_tuple(T)), max_index(T,N). | ||
max_arg_index(TT,Idx) | ||
:- Idx = #max{ Pos : term_tuple(TT,Pos,_); -1 }, function(_,_,term_tuple(TT)). | ||
|
||
arity(F,N+1) :- function(F,_,term_tuple(T)), max_arg_index(T,N). | ||
|
||
% when a literal is not prev | ||
prev_chain(A,function(F),O) | ||
:- atom(A,function(F)), function(F,prev,term_tuple(T)), arity(F,1), | ||
term_tuple(T,0,O). | ||
|
||
% when atom of a literal is a predicate | ||
add((term_tuple(T,N+1,constant(new_id(T))); | ||
constant(new_id(T),t))) | ||
:- literal(L,_,function(F)), function(F,Name,term_tuple(T)), | ||
Name!=prev, max_index(T,N). | ||
prev_chain(A,function(F),O) | ||
:- prev_chain(A,_,function(F)), function(F,prev,term_tuple(T)), arity(F,1), | ||
term_tuple(T,0,O). | ||
|
||
% when atom of a literal is a propositional constant | ||
delete(literal(L,S,constant(F))) :- literal(L,S,constant(F)). | ||
add((literal(L,S,function(F)); | ||
function(F,Name,term_tuple(new_id(F))); | ||
term_tuple(new_id(F),0,constant(new_id(F))); | ||
constant(new_id(F),t))) | ||
:- literal(L,S,constant(F)), constant(F,Name). | ||
% final operand must be a constant or function, as e.g. prev(1) is not a prev operation | ||
final_operand(A,O) | ||
:- prev_chain(A,F,O), not prev_chain(A,O,_), | ||
O=function(_). | ||
|
||
num_prevs(A,N) :- N = #count{ F : prev_chain(A,F,_) }, prev_chain(A,_,_). | ||
|
||
prev_chain(L,function(F),O) | ||
:- literal(L,_,function(F)), function(F,prev,term_tuple(T)), arity(F,1), | ||
term_tuple(T,0,O). | ||
first_prev(A,F) :- prev_chain(A,F,O), not prev_chain(A,_,F). | ||
|
||
prev_chain(L,function(F),O) | ||
:- prev_chain(L,_,function(F)), function(F,prev,term_tuple(T)), arity(F,1), | ||
term_tuple(T,0,O). | ||
|
||
final_operand(L,O) | ||
:- prev_chain(L,F,O), not prev_chain(L,O,_), O=(constant(_);function(_)). | ||
|
||
first_prev(L,F) | ||
:- prev_chain(L,F,O), not prev_chain(L,_,F). | ||
|
||
num_prevs(L,N) | ||
:- N = #count{ F : prev_chain(L,F,_) }, prev_chain(L,_,_). | ||
|
||
% when final operand is a function | ||
replace(function(F,N,A),function(F,Name,term_tuple(T))) | ||
:- first_prev(L,function(F)), function(F,N,A), final_operand(L,function(O)), | ||
function(O,Name,term_tuple(T)). | ||
|
||
add(term_tuple(T,I+1,binary_operation(new_id(O))); | ||
binary_operation(new_id(O),"-",constant(new_id(O)),number(new_id(O))); | ||
constant(new_id(O),t); | ||
number(new_id(O),N)) | ||
:- final_operand(L,function(O)), function(O,_,term_tuple(T)), max_index(T,I), | ||
num_prevs(L,N). | ||
|
||
% when final operand is a constant | ||
replace(function(F,N,A),function(F,Name,term_tuple(new_id(O)))) | ||
:- first_prev(L,function(F)), function(F,N,A), final_operand(L,constant(O)), | ||
constant(O,Name). | ||
|
||
add(term_tuple(new_id(O),0,binary_operation(new_id(O))); | ||
binary_operation(new_id(O),"-",constant(new_id(O)),number(new_id(O))); | ||
constant(new_id(O),t); | ||
number(new_id(O),N)) | ||
:- final_operand(L,constant(O)), num_prevs(L,N). | ||
% when an atom is not prev. | ||
|
||
% add time point constant as additional argument | ||
add(term_tuple(T,N+1,function(new_id(T))); | ||
function(new_id(T),t,term_tuple(new_id(T)))) | ||
:- atom(A,function(F)), function(F,Name,term_tuple(T)), | ||
Name!=prev, max_arg_index(T,N). | ||
|
||
% when an atom is a prev. | ||
|
||
% replace function symbol of atom with final operand, appending | ||
% appropriate time point as additional argument. | ||
replace(function(F,N,T1),function(F,Name,term_tuple(T2))) | ||
:- first_prev(A,function(F)), function(F,N,T1), final_operand(A,function(O)), | ||
function(O,Name,term_tuple(T2)). | ||
|
||
add((term_tuple(T,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,term_tuple(new_id(O))); | ||
number(new_id(O),N))) | ||
:- final_operand(A,function(O)), function(O,_,term_tuple(T)), max_arg_index(T,I), | ||
num_prevs(A,N). | ||
|
2 changes: 1 addition & 1 deletion
2
src/renopro/asp/tests/transform/prev_to_timepoints/very_sad_input.lp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
very_sad(robot(X)) :- prev(sad(robot(X))), prev(prev(sad(robot(X)))). | ||
very_sad(robot(X)) :- prev(sad(robot(X))), prev(prev(sad(robot(X)))). |
Oops, something went wrong.