Date handling inside s(CASP)?

I’ve been looking at using s(CASP) inside SWI-Prolog for the purpose of doing encodings of statutes and regulations.

I created a little toy library with code like the following:

#pred add(X,Y,Z) :: "the sum of @(X) and @(Y) is @(Z)".
add(X,Y,Z) :-
    Z is X + Y.

This just adds explanations for mathematical calculations to s(CASP)'s justifications and models, but that’s an important feature if we are encoding benefit laws, for example.

What I would like is to do something similar with dates and times. I’m aware SWI-Prolog has its own library for dates, but I understand it isn’t available inside s(CASP). s(CASP)'s implementation also does not seem to have any ability to deal with timestamps built-in.

I’m thinking it would be possible to take the existing SWI-Prolog date library, for example, and re-implement it as an s(CASP) library.

I’m wondering if that’s feasible, and if there is another, easier way to get where I need to go. I know there has been some discussion about being able to call Prolog from inside s(CASP) code. Is that something we’re expecting to see soon? Would that work smoothly with s(CASP)'s other capabilities? In particular, I’d like to be able to take advantage of how s(CASP) treats constraints, have it deal with constraints expressed as numerical time stamps, and then translate those back to dates, etc., for the purpose of explaining the conclusions to the user. I’m worried that if the date calculations are happening outside of s(CASP), s(CASP) won’t have access to that information when generating explanations, and the explanations would need to be post-processed to convert timestamps back into dates, or what have you.

For context, I’m not an experienced Prolog software developer. I’ve mostly done legal knowledge representation work in various declarative logic languages. I did write a date-subtract predicate for Flora-2 last year, to be able to add that feature to So it wouldn’t be the first time I have touched date math in a Prolog-like language. But converting an entire library, especially considering how weird dates are, might be a heavy lift.

I appreciate everyone’s thoughts.

1 Like

Integration with Prolog is a hot topic. Roughly two options are what we explore right now. One is to let Prolog do its thing, assembling a s(CASP) program to make s(CASP) do its part of the job. The other thing being considered is to allow s(CASP) to call out to Prolog. This probably means the user is responsible for providing the dual rule: a predicate that performs the constructive negation of a goal. In a very simple case,


creates a dual that, when we call not p(X), claims this is true for every X that is not a.

In the situation in which Prolog is “doing its thing”, what does that mean in terms of how you would access date capabilities? Would it be similar to the way is works right now, and I could wrap those calls for the purpose of generating explanations like I am doing now for math?

And if either of those methods of integration are going to happen, how soon should we realistically expect them? If it’s going to take a while, I might need to generate my own date library in order to do tech demonstrations in the meantime.

I’m afraid I do not know. Similar issues are under discussion with a commercial user. So far I have little clue what the final outcome will be or when it will happen.

Fair. Thank you.