A formatted text report of fruit quantities, prices and costs.
report-n3.n3 · output · proof · check · playground
The question
How can numeric calculations become an ordered text report?
What the program says
report-n3.n3:
# A text report: string:format and math:product build the lines, and
# log:outputString writes them in the order of their subjects.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix : <http://example.org/shop#>.
:apple :price 0.5; :qty 6.
:pear :price 0.75; :qty 4.
:a log:outputString "Order\n".
{ ?item :price ?p; :qty ?q.
(?p ?q) math:product ?cost.
?item log:uri ?u.
("- %s: %d x %.2f = %.2f\n" ?u ?q ?p ?cost) string:format ?line
} => { ?u log:outputString ?line }.
What eyemind concludes
The command writes these conclusions in its native output format:
Order
- http://example.org/shop#apple: 6 x 0.50 = 3.00
- http://example.org/shop#pear: 4 x 0.75 = 3.00
Both the apples and pears cost 3.00. string:format constructs each line; log:outputString orders the lines after the given heading. The saved output is text, while the proof certifies the two derived outputString triples.
The check report records the corresponding claims as JavaScript expressions:
// Checked answers: these follow from the input program and are every answer of its questions.
rdf(literal('http://example.org/shop#apple', datatype('http://www.w3.org/2001/XMLSchema#string')), iri('http://www.w3.org/2000/10/swap/log#outputString'), literal('- http://example.org/shop#apple: 6 x 0.50 = 3.00\n', datatype('http://www.w3.org/2001/XMLSchema#string')))
rdf(literal('http://example.org/shop#pear', datatype('http://www.w3.org/2001/XMLSchema#string')), iri('http://www.w3.org/2000/10/swap/log#outputString'), literal('- http://example.org/shop#pear: 4 x 0.75 = 3.00\n', datatype('http://www.w3.org/2001/XMLSchema#string')))
What the proof establishes
The saved report ends with verdict('checked').
The checker reads the clauses from the compiled program, not from the
proof, and never calls the reasoning engine. It answers the original
questions from the proof’s call tables, checking each table by expanding its
call one level against the program; it requires each derived listing to be
closed under the forward rules; and it replays the recorded firing of each
listed fact, computing primitives again. A step, table or listing the check
does not use fails it.
The verdict establishes that the displayed claims follow from the compiled program and are every answer of its original questions.
Try it
From the repository root:
node bin/eyemind.js examples/report-n3.n3
node bin/eyemind.js --proof examples/report-n3.n3
node bin/eyemind.js --check-proof examples/proof/report-n3.js examples/report-n3.n3
