RSS

What happens when you try 1 / 3 in different SPARQL processors? Meet the semantics of mathematics of the Semantic Web

20 Jul

Recently, Dr. Frithjof Dau from SAP Research has posed an interesting SPARQL question in the context of the CUBIST project that led to more questions and interesting discoveries as well as mathematical annoyances. For all those semantic web enthusiasts and SPARQL nerds out there, can you guess the results of the following SPARQL query, along with the associated types, but of course without actually running the query using a SPARQL engine?

After you are finished with your guesswork and noted your results (at least for a few of them, I don’t expect anybody except W3C standards documents writers and reviewers go through all of them) you may want to run and see if you have guessed correctly. In order to run the query above, you can use the latest versions of Jena, OpenRDF / Sesame, or TopBraid Composer.

Could you guess correctly? What was the results? But most important of all, which SPARQL implementation did you use? That is the most important of all because the results depend on the implementation. Normally, one would prefer to trust mathematics, standards and their implementations but apparently that is not the case here. Unfortunately what you get is the following situation:

Operation SESAME 2.6.5 Jena & Topbraid Composer
1 / 3 0 0.333333333333333333333333
xsd:float(1 /3) “0.0”^^xsd:float “0.333333333333333333333333”^^xsd:float
xsd:float(1) /3 “0.33333334”^^xsd:float “0.33333334”^^xsd:float
xsd:decimal(1 /3) 0 0.333333333333333333333333
xsd:decimal(1)/3 0 0.333333333333333333333333
1.0 / 3 0.3 0.333333333333333333333333
xsd:float(1.0 /3) “0.3”^^xsd:float “0.333333333333333333333333”^^xsd:float
xsd:float(1.0) /3 “0.33333334”^^xsd:float “0.33333334”^^xsd:float
xsd:decimal(1.0 /3) 0.3 0.333333333333333333333333
xsd:decimal(1.0) / 3 0.3 0.333333333333333333333333
1.00 / 3 0.33 0.333333333333333333333333
xsd:float(1.00 /3) “0.33”^^xsd:float “0.333333333333333333333333”^^xsd:float
xsd:float(1.00) /3 “0.33333334”^^xsd:float “0.33333334”^^xsd:float
xsd:decimal(1.00 /3) 0.33 0.333333333333333333333333
xsd:decimal(1.00) /3 0.33 0.333333333333333333333333

For a recent discussion on this topic with a slightly different query see this StackOverflow question. I’m glad that this led to http://www.openrdf.org/issues/browse/SES-1063. Hopefully, the next version of OpenRDF / Sesame will match the results of Jena and TopBraid Composer. Nevertheless this does not change the fact that W3C standards defining SPARQL and XPath leave room for such mathematically problematic interpretations for trivial arithmetical operations.

By the way, speaking of rationals, divisions, standards and programming languages, I think some old and “dead” languages (or do they just smell funny? ;-)) provides us with a better “programmer experience” out-of-the box:


$ clisp
  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I   `+' /  I      8         8           8     8        8    8
     `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Welcome to GNU CLISP 2.48 (2009-07-28) 

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2009

Type :h and hit Enter for context help.

[1]> ; A rational is a rational is a rational!
(/ 1 3)
1/3
[2]> ; Rationals should be treated with due respect!
(+ (/ 1 3) (/ 1 3) (/ 1 3))
1
[3]> ; But of course sometimes you may request imperfection, as in engineering
(/ 1.0 3)
0.33333334
[4]> ; which should not diminish your respect for proper rationals
(+ (/ 1.0 3) (/ 1.0 3) (/ 1.0 3))
1.0
[5]> ; no self-respecting system should decide based on the number of digits
(/ 1.000 3)
0.33333334
[6]> ; indeed!
(+ (/ 1.0000 3) (/ 1.00000000 3) (/ 1.000000000000 3.000000000000000))
1.0
[7]> ; 'nuff said!
(quit)
Bye.

It is also somewhat ironic that one of the three authors of the original Semantic Web article that appeared in Scientific American in 2001, Ora Lassila, happens to be a Common Lisp programmer who developed one of the first semantic web toolkits using Common Lisp back in 2001.

 
Leave a comment

Posted by on July 20, 2012 in Lisp, Math, Programlama

 

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: