# Making practical use of Event Calculus + SCASP

**URL:** <https://swi-prolog.discourse.group/t/making-practical-use-of-event-calculus-scasp/6515>\
**Category:** Help!\
**Created:** [May 2, 2023, 9:31pm UTC](https://swi-prolog.discourse.group/t/making-practical-use-of-event-calculus-scasp/6515 "2023-05-02T21:31:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 2, 2023, 9:31pm UTC](https://swi-prolog.discourse.group/t/making-practical-use-of-event-calculus-scasp/6515/1 "2023-05-02T21:31:55Z")

</div>

I’m using: SWI-Prolog version 9.0.4

In [this very helpful thread](https://swi-prolog.discourse.group/t/advice-on-modeling-program-behavior-with-prolog/6479/4) I was pointed towards Event Calculus and sCASP as a potential tool for modeling system behavior in some other software. I’ve read [the BEC paper](https://arxiv.org/pdf/2106.14566.pdf), installed sCASP, and gotten the BEC code from [here](https://github.com/JanWielemaker/sCASP/blob/72028b02d57e51fe24c4be54234ab75767cd469f/examples/benchmark_EventCalculus/lopstr19/event-calculus/bec_theory.pl). Reading the papers, this appears to be exactly what I need, but I’m having trouble getting it to work

My first issue is loading the code! **(This is no longer an issue, please skip this part!)** I’m using Emacs. I’ve put the BEC code from the above link into a directory. I have my own source file next to it. At the top of my file I’ve got:

```prolog
:- use_module(library(scasp)).

consult[bec_theory].

```

If I then `consult` my own source file, I get a broken situation that starts with “Syntax error: Operator expected”, and I’m unable to query anything using sCASP’s query operators. I’ve also tried `#include 'bec_theory'` instead of `consult`, and also tried the modified version of bec\_theory.pl [here](https://swish.swi-prolog.org/p/sCASP%20Basic%20Event%20Calculus.swinb), with the `.<.` operators replaced with `#<`.

So far the only thing that works is to start by consulting the modified bec\_theory.pl file, then going to my own source file and consulting that as well. Obviously it would be great if I could just consult a single file and get going!

My own code is currently a dumb hello-wold-type setup, just to demonstrate it works. Eventually I’m hoping to model complex processing of multiple data streams that interact with each other in confusing ways, but for now I’m starting with this:

```prolog
happens(data_upload, 2).
initiallyN(data_in_db).
initiates(data_upload, data_in_db, T).

```

Then I’d like the system to tell me that `data_in_db` is false at T \< 2 and true at T \>= 2. The first query goes okay:

```prolog
? holdsAt(data_in_db, 1).
Warning: scasp_predicate `'user:terminates'/3' does not exist
Warning: scasp_predicate `'user:trajectory'/4' does not exist
Warning: scasp_predicate `'user:initiallyP'/1' does not exist
Warning: scasp_predicate `'user:releases'/3' does not exist
false.

```

But then:

```prolog
? holdsAt(data_in_db, 3).
Warning: scasp_predicate `'user:terminates'/3' does not exist
Warning: scasp_predicate `'user:trajectory'/4' does not exist
Warning: scasp_predicate `'user:initiallyP'/1' does not exist
Warning: scasp_predicate `'user:releases'/3' does not exist
% s(CASP) model
{ not initiallyN(_A), not initiates(_I,data_in_db,_J),
  initiallyN(data_in_db), not initiates(_K,_,_),
  not happens(data_upload,_B), not initiates(_L,data_in_db,_M),
  not happens(data_upload,_C), not initiates(data_upload,_N,_),
  not happens(data_upload,_D), initiates(data_upload,data_in_db,_B),
  happens(data_upload,2), initiates(data_upload,data_in_db,_C),
  not ¬ holdsAt(_,_E), initiates(data_upload,data_in_db,_D),
  not ¬ holdsAt(_A,_F), initiates(data_upload,data_in_db,2),
  not ¬ holdsAt(data_in_db,_G), startedIn(0,data_in_db,_G),
  ¬ holdsAt(data_in_db,_H), not startedIn(0,data_in_db,_H),
  holdsAt(data_in_db,3), not stoppedIn(2,data_in_db,3)
},
{_O>0, _=_E-_O, _P>0, _=_E-_P, _Q>0, _=_E-_Q, _R>=0, ... = ..., ... =< ...},
{_S>0, _=_F-_S, _T>0, _=_F-_T, _U>0, _=_F-_U, _V>=0, ... = ..., ... > ...},
_A ∉ [data_in_db],
{_W>0, _=2-_X-_W, _Y>0, _=2-_X-_Y, _Z>0, _= ... - ... - _Z, _A1>=0, ... = ..., ..., ...},
{_B1>0, _=_H-_B1, _C1>0, _=_H-_C1, _D1>0, _=_H-_D1, _E1>0, ... = ..., ..., ...},
_I ∉ [data_upload],
_K ∉ [data_upload],
_N ∉ [data_in_db],
_C ∉ [2],
_L ∉ [data_upload] 

```

Running `holdsAt(data_in_db, T)`, in expectations of getting something like `T #>= 2`, results in output like the above.

Obviously I’ve got something very basically wrong here, but I hope I’m just a few misconceptions away from being able make this work. Thanks in advance for any assistance!

---

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 2, 2023, 9:48pm UTC](https://swi-prolog.discourse.group/t/making-practical-use-of-event-calculus-scasp/6515/2 "2023-05-02T21:48:38Z")

</div>

Of course immediately after posting that I fixed the loading issue; it needed to start with

```prolog
:- use_module(library(scasp)).
:- consult(bec).

```

and not `#include` or `#consult` or anything like that. I still needed to use the “fixed” version of bec.pl (with the `#,` operators), and I’m still having the second issue with actually running the code!
