-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement demand/magic sets transformation #24
Comments
In Masto conversations with Kris Micinski I was again reminded of how badly I want this feature for a number of examples. This whole thing would be vastly more clear, I think, written as follows:
Second example, CBV evaluation of lambda calculus Again, the program I want to be able to write is shorter and, I think, much clearer. The extra stuff needed to make this ^^ program work doesn't aid understanding at all.
|
Honestly, one of the reasons I've delayed on this is that I slightly regret the As a first step, I think |
Concrete proposal: add a
This directive
|
Correctness statements. Initial program is P, transformed program is P'. First statement: if P passes the modified mode checker, P' would pass an unmodified mode checker. Second statement: |
I need to better understand how this relates to the "demand" or "magic sets" transformation, but I really think the right move for Dusa is to declare certain predicates to be demand-driven, and then automatically do the magic-sets transformation on them.
In Dusa, it seems reasonable to connect this with the functional predicate transformation: for a predicate
d X Y is Z
, the only mode you get isd + + is -
. That is, the stuff to the left of the “is” is input, the stuff to the right of the “is” is output. It is not particularly orthogonal language design to tie functional predicates to a demand transformation like this, but, well, my hunch is that this will be a lot simpler, and my experience from Advent of Code was that this was the only version that it was painful to do without, and the only one that I wanted.As a example that's simple but silly because we already have integer addition, we might want to implement unary addition in Dusa:
This doesn't work for two reasons:
The demand/magic sets transformation introduces a new predicate,
needAdd
. It uses the invariant that we will only introduce a fact of the formadd t1 t2 is X
if the database already includes a fact of the formneedAdd t1 t2
. Uses of the demandedadd
relation in premises require us to add new rules that deriveneedAdd
:This transformation has the same vibe as the one that translates ASP to Dusa - a negated premise represents a "demand that this attribute potentially be ff"
Note on the literature: I thought "magic sets" and "demand transformation" were the same thing, but according to the "Datalog: concepts, history, and outlook" paper they are different. Possibly they're the same when restricted to operating with functional predicates in the way I'm proposing.
The text was updated successfully, but these errors were encountered: