laurelang icon indicating copy to clipboard operation
laurelang copied to clipboard

Feature: smart context query reorderer

Open timoniq opened this issue 3 years ago • 2 comments

Consider a predicate flatten non trivial:

: ?flatten_nt(int[][]) -> int[].
?flatten_nt([]) -> [].
?flatten_nt([x]) -> x.
?flatten_nt(array) -> flattened {
    flattened = append<int>(x, y);
    y = flatten_nt(t);
    linked(x, t) = array;
}

Predicate will fail if we try to instantiate array from flattened:

?- flatten_nt(x) = [1,2,3]
* too broad error *

to change this behaviour queries should be reordered

?flatten_nt(array) -> flattened {
    linked(x, t) = array;
    y = flatten_nt(t);
    flattened = append<int>(x, y);
}

the idea is to do that automatically

qcontext may have order field (a vector with order calculated on scope entering)

[2, 1, 0]

timoniq avatar Jul 22 '22 10:07 timoniq

Reorderings for each case can be generated during predfinal generation. (Body linking for each arguments I/U permutation)

timoniq avatar Jul 24 '22 10:07 timoniq

there is a room for improvement in adding support for unify, unify all, quantor statements

timoniq avatar Aug 18 '22 14:08 timoniq