Rules involving lists #2285
-
I'm new to logic programming, and as a learning project I've been using Soufflé to express constructs from music theory. I'm stuck on trying represent scales and chords as lists of notes separated by intervals. A simpler, equivalent problem would be this: Consider a list In invalid Souffle, which generates errors warning of ungrounded variables and records.:
How might one successfully express this problem in Soufflé? I'm sure this formulation betrays some fundamental misunderstandings of how Datalog and Soufflé work, so if there are no straightforward corrections to be made here, I would really appreciate some advice on how to learn more. For example, I'm struggling to understand what it means for a variable to be ungrounded, and I would love to spend some time with resources (textbooks, tutorials, etc) that would explain this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
.type List = [ head: number, tail: List]
.decl Intervals(x : List)
Intervals([1,[3,[4,nil]]]).
.decl SumIntervals(before:List, after: List)
SumIntervals(xs, xs) :- Intervals(xs).
SumIntervals(xs, [z + y, zs]) :-
SumIntervals([x, xs], [y, ys]), xs = [z, zs].
.output SumIntervals(IO=stdout)
.decl Result(before: List, after: List)
Result(xs, ys) :- SumIntervals(xs, ys), ys = [y, nil].
Result([x, xs], [y, zs]) :-
SumIntervals([x, xs], [y, ys]), Result(ys, zs).
.output Result(IO=stdout) After that, extract the longest list and add the value of |
Beta Was this translation helpful? Give feedback.
After that, extract the longest list and add the value of
Root
to each of the elements.I'm just unaware of any beginner-friendly textbook, all the textbooks I know for Datalog are all too theoreti…