Bringing Temporal Reasoning to Mangle #83
Replies: 6 comments 5 replies
-
|
Thanks for starting this discussion. I need to look in more detail, but want to share a few thoughts right away. In general, I am all for adding time to Mangle datalog and enable temporal graph reasoning in a principle manner. I agree that the option of adding time values as columns according to convention loses semantics, even though we should appreciate that convention alone does enable time-travel queries. The syntax for intervals right, it matches the syntax used by the badwolf project which was an inspiration for Mangle. It overlaps a bit with Mangle syntax for list values [ e1, ..., en ] and map values [ k1: v1, ..., kn : vn ] but with the @ character that should be ok. The syntax of the operators is bit dense, maybe we can use suitable Unicode operators and/or box/diamond prefix, but I am sure we can figure something out. Semantics wise, adding time to semantics exposes us to the whole topic of absolute vs civic time, dates and timezones. See https://abseil.io/docs/cpp/guides/time It has been proposed to add time/date handling to Mangle's data model, which matches SQL. I want to carefully consider what happens when the mode of "native" handling of temporal reasoning gets mixed with some convention or date/time values appearing in source data. It's tempting to say "let's not do that" but when the language supports multiple modes it is almost inevitable that users will run into it. Finally, I need to get an understanding for decidability and performance. Mangle already crossed the Rubicon by extending datalog with features that lead to non-terminating programs, or using fact deletion in custom-lattice without checking that the user-defined relation is actually an ordering. Still, I want to help users (or agents) avoid generating non-terminating queries and give helpful error messages where possible. Besides a working implementation that covers expected queries/programs, it would help to have a characterisation of limitations and queries that can "go wrong". |
Beta Was this translation helpful? Give feedback.
-
|
@burakemir I opened PR #84 back up for a review after making some changes. I think my feature addition is incredibly useful and adds a powerful benefit natively to mangle. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the temporal reasoning PR (#84) - implementing DatalogMTL for Mangle is a great contribution! While reviewing the PR, I noticed an opportunity to simplify the implementation by adding first-class time and duration types to Mangle's core. I've implemented this foundation, which includes: New built-in types:
New predicates:
New functions:
I have this under review and expect to land this very soon (in the next days) - once landed would you mind rebasing your DatalogMTL implementation on top of this? It should allow you to remove custom time handling code and use the built-in facilities instead, making the temporal reasoning logic cleaner. A notable difference is the handling of durations. The work on parsing time and duration literals is important and needs some scrutiny. Would it be possible to split the parsing of time and duration values into a separate PR so I can review it separately? I would like to ask for the following: while for a duration datatype, it makes sense to support negative durations, it clearly does NOT make sense for DatalogMTL. So in the context of temporal queries/goals, we should detect and reject the use of negative durations, and document clearly that the operator determines direction. Duration Literal Grammar (EBNF) duration = [ sign ] component { component } ; Examples Notes
This is the exact format Go uses, so the implementation can simply delegate to time.ParseDuration(). |
Beta Was this translation helpful? Give feedback.
-
|
@danielostrow The time and duration types landed, see dd902ac |
Beta Was this translation helpful? Give feedback.
-
|
@burakemir #84 is dependent on #87. ready for review. |
Beta Was this translation helpful? Give feedback.
-
|
@burakemir the temporal graph is great stuff. Mangle is looking very attractive to use in a few of my projects. I’m very much interested in feedback from users. Do you suggest updating the main project readme to share this feature? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm drafting a PR #84 for a feature introducing temporal reasoning into Mangle.
Facts are stored, rules derive new facts. But currently all facts are "eternally true." Once
team_member(/alice, /engineering)is added, it's true forever. There's no way to express that Alice was in engineering from 2020-2023, but is now in management.Currently, to get historical context, you'd add
start_dateandend_dateas extra arguments to predicates, which is messy and loses the semantic meaning of time.I'm proposing we add an optional time dimension to Mangle's fact model, so facts can express when they were valid.
This design is inspired by DatalogMTL, an academic extension for metric temporal logic in Datalog.
We can tag facts with a time range using
@[start, end]:We can use new operators to ask questions about the past without complex joins.
<-: was this true at some point in the past?[-: was this true continuously for the whole duration?Example: Find employees who have been employed continuously for the last 365 days.
Use case: Compliance checking
"An employee can only operate equipment if they've been certified
for at least 30 days."
All existing Mangle programs work unchanged. Facts without
@[...]are treated as eternally valid (the current behavior).I need feedback.
I am aiming for a balance between power and simplicity. Before I start submitting PR's, I'd love to open a conversation on:
The Syntax: Does
fact(...)@[start, end]feel natural to write?Granularity: Do we need sub-second precision (milliseconds/nanoseconds) for your use cases?
Missing Pieces: Are there specific "time travel" queries you need to run that this doesn't cover?
Thanks!
Daniel
Beta Was this translation helpful? Give feedback.
All reactions