# Des 6.7 requiring SWI-Prolog 7.4

**URL:** <https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392>\
**Category:** General\
**Created:** [September 6, 2021, 7:13am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392 "2021-09-06T07:13:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 6, 2021, 7:13am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/1 "2021-09-06T07:13:31Z")

</div>

Hi Fernando,

DES is getting more and more complete! I was wondering about sticking to SWI-Prolog 7.4. Looking at the SourceForge download it is claimed it is unlikely to work with 8.x. Why is this? Version 7 introduced serious incompatibilities, but 8 is pretty compatible to 7. I tried to load it under 8.3.29. That seems to work fine, except for some “Illegal multibyte Sequence” messages which seems to be mostly caused by non-ASCII code used in comments. Is there a test suite?

I was also wondering whether tabling would make a significant simplification and possible speedup for processing Datalog?

```
 Cheers --- Jan

```

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 8:54am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/2 "2021-09-06T08:54:52Z")

</div>

Hi Jan,

> DES is getting more and more complete!

Thanks!

> I was wondering about sticking to SWI-Prolog 7.4. Looking at the SourceForge download it is claimed it is unlikely to work with 8.x. Why is this?

Maybe the disclaimer was too strong since most tests will work. However, some tweaks to the DES code should be done to make all them work. For example, the representation of rationals. In its current state, for the fuzzy part of the system, one can get:

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/8/89ea1a7f9d04d28d3539eb71909655cd36e97951.png)

Background coloured in red is what is expected, while yellow is what is get.

In addition, there was an issue with the ODBC driver:

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/1/1c3a5ea77ec6345e2ad1ee29719805343e7be886.png)

> Is there a test suite?

Yes, but not in the common way. I run a batch file with inputs such as those above and its output is compared to a valid output with the windiff tool, which highlights differences.

> I was also wondering whether tabling would make a significant simplification and possible speedup for processing Datalog?

Tabling is an awesome addition to SWI-Prolog (great work!). While speedup would be undoubtedly and hugely improved if using it, I see two drawbacks: First, there are some features (nulls, duplicates, top-n solutions…) that might not be directly mapped to tabling, though I did not dig enough into SWI-Prolog tabling to be completely sure. I think that (some of) those features needs the tabling engine to be aware of them. Second, it would be an implementation targeted at SWI-Prolog which would not work with SICStus Prolog, and two interfaces should be developed (as an aside note, Ciao Prolog and GNU Prolog were also supported and might be recovered in the future).

All the best,  
Fernando

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 6, 2021, 9:28am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/3 "2021-09-06T09:28:53Z")

</div>

> [@fsaenzperez](#):
>
> n its current state, for the fuzzy part of the system, one can get:

That is a bit odd. If the Prolog flag `prefer_rationals` is set to `false` (which is the default), 9/50 evaluates to 0.18. Only if this flag is set to `true` the result is `9r50`. Could it be that you set this to true in your personal init file? I do 🙂

> [@fsaenzperez](#):
>
> In addition, there was an issue with the ODBC driver:

This should be fixed. Not a lot happened to the ODBC driver. Can you describe how to reproduce this? I’d prefer to have this fixed …

> [@fsaenzperez](#):
>
> First, there are some features (nulls, duplicates, top-n solutions…) that might not be directly mapped to tabling,

Possibly. We’ve seen some discussion here on the semantics of `null` 🙂 Although tabling gives you basically the same advantages over plain Prolog as Datalog in terms of termination and well founded semantics (if you support that), there could be details that are hard to match.

> [@fsaenzperez](#):
>
> targeted at SWI-Prolog

Portability ☹ I fear we stay with the ISO limitations forever ☹ Ciao has tabling these days (but no well founded semantics AFAIK).

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [September 6, 2021, 9:34am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/4 "2021-09-06T09:34:24Z")

</div>

> [@fsaenzperez](#):
>
> In addition, there was an issue with the ODBC driver:

I also have an interest in this as I try to keep the Wiki topic

> [@SWI-Prolog connecting to PostgreSQL via ODBC](https://swi-prolog.discourse.group/t/swi-prolog-connecting-to-postgresql-via-odbc/2404):
>
> Note: This is a topic for learning how to connect SWI-Prolog to PostgreSQL via ODBC. If you have [Trust level](https://blog.discourse.org/2018/06/understanding-discourse-trust-levels/): [Basic](https://swi-prolog.discourse.group/badges/1/basic) you can edit this by clicking on the edit icon in the lower right. [Capture] Note: Do not reply to this topic; questions, concerns, comments, etc. are to be handled in [Wiki Discussion: SWI-Prolog connecting to PostgreSQL via ODBC](https://swi-prolog.discourse.group/t/wiki-discussion-swi-prolog-connecting-to-postgresql-via-odbc/2405) SWI-Prolog connecting to [PostgreSQL](https://www.postgresql.org/) via [ODBC](https://en.wikipedia.org/wiki/Open_Database_Connectivity) Ubuntu Installation Instructions Language agnostic steps 1. Install PostgreSQL (If not currently…

correct.

As that is a Wiki topic you can change it/add to it or make a separate version for use with DES. Also if you see a need to have a change or addition made let me know. That topic is actually used more often than I anticipated.

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 9:56am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/5 "2021-09-06T09:56:06Z")

</div>

> [@jan](#):
>
> prefer\_rationals

I think I used the default configuration for this flag. Anyway, I explicitly changed this but the outcome was the same:

```prolog
DES> /system_mode fuzzy

FDES> /c examples/fuzzy/near

Info: 0 rules consulted.
Info: 3 equations consulted.

FDES> madrid near lisboa

Info: Processing:
  answer :-
    madrid near lisboa.
{
  answer(3r25)
}
Info: 1 tuple computed.          

FDES> /t

?- current_prolog_flag(prefer_rationals,X).
X = 'false'.

```

Anyway, I think that, with time to dig into it, this can be addressed (I’m starting the new academic course…)

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 9:57am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/6 "2021-09-06T09:57:28Z")

</div>

P.S. With respect to the ODBC issue, I will prepare a reproducible case.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 6, 2021, 11:26am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/7 "2021-09-06T11:26:50Z")

</div>

I see. A quick scan comes with this stack:

```prolog
     [52] _593524 is rationalize(1.0)
     [51] 'nf_q':nf_number(1.0, _593522)
     [49] 'nf_q':nf(1.0*1.0, _593520)
     [48] 'nf_q':nf(- (1.0*1.0), _593518)
     [47] 'nf_q':nf(_593476-1.0*1.0, _593486)
     [46] 'nf_q':{_593476=1.0*1.0}
     [45] clpq_solve(1.0*1.0, _593458)
     [42] t_norm_aux([1.0, 1.0], 'product', _593454)
     [40] t_norm_matrix_j(1, 1, 1, 2, 'near', vector(vector('$mutable'(1.0, '$mutable'(0.0, _593412)), '$mutable'(0.6, '$mutable'(0.0, _593418))), vector('$mutable'(0.6, '$mutable'(0.0, _593424)), '$mutable'(1.0, '$mutable'(0.0, _593430)))), _593434)

```

Now I’m not an expert in this. I always lived under the impression that clpq is clp for rational numbers and clpr is mostly the same for real numbers. But then, I find in des\_fuzzy.pl this, which suggests you really want clpq.

```prolog
   clpq_solve(Degree-MaxResDegree,NewDegree), % Do not lose precision due to floating point calculations

```

Doesn’t look like hard to fix. I think in q\_to\_number/2 add a clause like this provides a portable fix:

```prolog
:- if(current_predicate(rational/1)).
q_to_number(Rat, Num) :-
   rational(Rat),
   !,
   Num is float(Rat).
:- endif.

```

Note that both SICStus and SWI support `:- if(Cond).` … `:- else.` … `:- endif.` blocks that allow you to use the same code with both systems. Both also implement the flag `version_data` to get the dialect and version. Testing features rather than versions provides better portability!

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 11:53am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/8 "2021-09-06T11:53:50Z")

</div>

Many thanks, Jan! I’ll try this fix.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [September 6, 2021, 4:18pm UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/9 "2021-09-06T16:18:55Z")

</div>

> [@fsaenzperez](#):
>
> there are some features (nulls, duplicates, top-n solutions…) that might not be directly mapped to tabling

Duplicates would be an issue only if you’re using multisets and care about execution order. As I recall, Datalog allows both bottom-up and top-down execution (e.g., magic sets and tabling), so why would duplicates be an issue?

And nulls are weird in SQL, so if you have Relational Algebra and SQL in DES, how do you resolve the differences?

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 5:21pm UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/10 "2021-09-06T17:21:58Z")

</div>

> Duplicates would be an issue only if you’re using multisets and care about execution order. As I recall, Datalog allows both bottom-up and top-down execution (e.g., magic sets and tabling), so why would duplicates be an issue?

Indeed, DES can use both multisets and sets (selectable with the commands `/duplicates on` and `/duplicates off`, respectively), and order is also handled (with the metapredicate `order_by`). Both features were intended to be able to translate SQL into Datalog.

Execution order is relevant for the semantics for the combination of metapredicates, such as in the query `top(1,order_by(t(X),[X]))`, which retrieves the first solution of `t(X)` when it is sorted in ascending order. Again, this was driven by dealing with SQL.

> And nulls are weird in SQL, so if you have Relational Algebra and SQL in DES, how do you resolve the differences?

Yes they are. DES implements an approximation to nulls in SQL that behaves the same as current SQL implementation in most use cases for teaching basic SQL. The following paper describes some aspects of the implementation of outer join operations:

[[Sae12a](http://dx.doi.org/10.1016/j.entcs.2011.12.007)] [[BibTeX](http://www.fdi.ucm.es/profesor/fernan/FSP/Sae12a.bib)] F. Sáenz-Pérez, “Outer Joins in a Deductive Database System”, Electronic Notes in Theoretical Computer Science, vol. 282, pp. 73-88, May, 2012.

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 6, 2021, 5:35pm UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/11 "2021-09-06T17:35:44Z")

</div>

The fix passed all the tests! Thanks again, Jan.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 7, 2021, 7:07am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/12 "2021-09-07T07:07:54Z")

</div>

I guess not the ODBC one, no? Or was that caused by rational numbers that don’t cross the ODBC interface well? Would be nice if we can donate version 7.4 to the museum 🙂

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [September 7, 2021, 8:58am UTC](https://swi-prolog.discourse.group/t/des-6-7-requiring-swi-prolog-7-4/4392/13 "2021-09-07T08:58:07Z")

</div>

> I guess not the ODBC one, no?

Only fixed the rational numbers issue. For the ODBC connection, the error raises with the following version of SQL Server (default configuration):

`Microsoft SQL Server 2014 - 12.0.2269.0 (X64) Jun 10 2015 03:35:45 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3 <X64> (Build 19043: )`

For a database “test” with a table “dual” including a single column “void” with type “int”:

![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/6/6c8a599c39f5972823c7da12a056921eab9fcf43.png)

By debugging the connection to this database and extracting its metadata, it seems that the issue comes from the call to `odbc_column`/3 (`library/odbc.pl` in the SWI-Prolog installation) in:

```prolog
table_column(Connection, Table, Column, Tuple) :-
( var(Table)
-> odbc_current_table(Connection, Table)
; true
),
( ground(Column) % force determinism
-> odbc_column(Connection, Table, Tuple),
arg(4, Tuple, Column), !
; odbc_column(Connection, Table, Tuple),
arg(4, Tuple, Column)
).

```

SWI-Prolog Version 7.4.2:

```prolog
Call: (58) 'odbc':odbc_column('$odbc_connection'(6028676), 'dual', _55912) ? creep
Exit: (58) 'odbc':odbc_column('$odbc_connection'(6028676), 'dual', row('test', 'dbo', 'dual', 'void', 4, 'int', 10, 4, 0, 10, 1, '$null$', '$null$', 4, '$null$', '$null$', 1, 'YES', 0, 0, 0, 0, '$null$', '$null$', '$null$', '$null$', '$null$', '$null$', 38)) ?

```

SWI-Prolog Version 8.2.4-1:

```prolog
* Call: (62) 'odbc':odbc_column('$odbc_connection'(145719600), 'dual', _110658) ? skip
* Exception: (61) 'odbc':table_column('$odbc_connection'(145719600), 'dual', _110264, _110734) ?

```

And the ODBC configuration is as follows:

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/2/2fc094471a53888b6943a0ab79fba4d38ee8f936.png)

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/2/2a2926005a80f64b0dadbd7c7a0f33132e998c84.png)

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/b/b43afdd66706806e61b06c182005068138908e4f.png)

 ![image.png](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/c/ce60d71494ebbd81b65de1ef122168e239b80f14.png)

Other ODBC connections seem to work well in version 8.2.4-1 (Access, PostgreSQL, MySQL, Oracle, DB2).
