# -----------------
# Fibonacci numbers
# -----------------
#
# See https://en.wikipedia.org/wiki/Fibonacci_number

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix var: <http://www.w3.org/2000/10/swap/var#>.
@prefix : <http://example.org/#>.

# backward rules
_:bng_1 log:isImpliedBy _:bng_2.

_:bng_1 {
    var:X :fibonacci var:Y.
}

_:bng_2 {
    (var:X 0 1) :fib var:Y.
}

_:bng_3 log:isImpliedBy true.

_:bng_3 {
    (0 var:A var:B) :fib var:A.
}

_:bng_4 log:isImpliedBy true.

_:bng_4 {
    (1 var:A var:B) :fib var:B.
}

_:bng_5 log:isImpliedBy _:bng_6.

_:bng_5 {
    (var:X var:A var:B) :fib var:Y.
}

_:bng_6 {
    var:X math:greaterThan 1.
    (var:X 1) math:difference var:C.
    (var:A var:B) math:sum var:D.
    (var:C var:B var:D) :fib var:Y.
}

# query
_:bng_7 log:impliesAnswer _:bng_7.

_:bng_7 {
    [] rdf:value 0; :fibonacci var:F1.
    [] rdf:value 1; :fibonacci var:F2.
    [] rdf:value 6; :fibonacci var:F3.
    [] rdf:value 91; :fibonacci var:F4.
    [] rdf:value 283; :fibonacci var:F5.
    #[] rdf:value 3674; :fibonacci var:F6.
}
