N3 scoped negation

Settle every possible hold before deciding which orders can ship.

N3 source · output · proof · check · playground


The question

Orders 1 and 2 are paid. Order 2 has an unverified address, which creates a hold. Order 3 is still open. A paid order ships only when no hold can be found in this program’s store. Which order ships?


Historical background

Database reasoning has long distinguished a record’s absence from a positive assertion. Reiter made absence-based reasoning explicit in his work on the closed-world assumption. Here N3’s scoped test searches for a hold after the positive rules have had the chance to derive one. Reiter, On Closed World Data Bases · Notation3 log vocabulary


What the N3 says

@prefix : <https://example.org/orders#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .

:order1 :status :paid .
:order2 :status :paid ; :address :unverified .
:order3 :status :open .

{
  ?order :status :paid .
  [] log:notIncludes { ?order :hold ?reason } .
} => { ?order :action :ship } .

{ ?order :address :unverified } => { ?order :hold :addressCheck } .

[] selects the current store as the scope of log:notIncludes. The paid-order premise binds ?order before the absence test. ?reason appears only inside that test, so it means any reason: there must be no hold of any kind for this order.


Why rule order does not ship order 2

eyemind compiles the absence test to not(...), with the local reason variable anonymous. eyemind assigns the rule deriving holds a lower stratum than the shipping rule. It finishes deriving holds before it tests their absence, even though the shipping rule is written first.

Dependencies compare full terms, including the RDF property IRI. Holds and shipping actions share rdf/3, but use different properties and can have different ranks. A dependency cycle through negation would be rejected.


What eyemind concludes

The check report records these answers as terms:

// Checked answers: these follow from the input program and are every answer of its questions.
rdf(iri('https://example.org/orders#order2'), iri('https://example.org/orders#hold'), iri('https://example.org/orders#addressCheck'))
rdf(iri('https://example.org/orders#order1'), iri('https://example.org/orders#action'), iri('https://example.org/orders#ship'))

Converted back to N3, they read:

@prefix : <https://example.org/orders#> .

:order2 :hold :addressCheck .
:order1 :action :ship .

Order 2 is blocked by the derived hold. Order 3 does not meet the paid condition. Order 1 ships because no hold matches it within this store. That absence is relative to this document and its rules.


What the proof establishes

Order 1 ships because no hold is recorded for it. Replaying that firing takes the absence from the proof’s call table for the search, as it stood when the negation ran; the call table is itself checked against the derived/2 listing of rdf/3. The listing must be closed under the forward rules, including the rule that derives the hold for order 2, so simply omitting that hold from the certificate fails the check.

The report ends with verdict('checked'). The listing is supported by replayed firings and closed, and the rule’s negation is decided by the listed facts alone, so the claims are exactly what the questions return.


Try it

node bin/eyemind.js examples/scoped-negation-n3.n3
node bin/eyemind.js --to eyemind examples/scoped-negation-n3.n3
node bin/eyemind.js --check-proof examples/proof/scoped-negation-n3.js examples/scoped-negation-n3.n3

To inspect a fresh compilation:

node bin/eyemind.js --program examples/scoped-negation-n3.n3 > /tmp/scoped-negation.js
node bin/eyemind.js --proof /tmp/scoped-negation.js

Remove the unverified-address fact in a copy of the N3 source and recompile: both paid orders ship. Add a hold for order 1 instead: neither paid order ships.