# ------------------------------------
# Calculate pi using Nilakantha series
# ------------------------------------
#
# See http://www.wikihow.com/Calculate-Pi

@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/#>.

# components
_:bng_1 log:isImpliedBy _:bng_2.

_:bng_1 {
    (var:N var:Pi) :pi true.
}

_:bng_2 {
    (1 var:N 0 var:P 1) :pi true.
    (4 var:P) math:product var:A.
    (3 var:A) math:sum var:Pi.
}

_:bng_3 log:isImpliedBy true.

_:bng_3 {
    (var:N var:N var:P var:P var:S) :pi true.
}

_:bng_4 log:isImpliedBy _:bng_5.

_:bng_4 {
    (var:K var:N var:P0 var:P var:S) :pi true.
 }

_:bng_5 {
    var:K math:notEqualTo var:N.
    (var:K 1) math:sum var:K1.
    (2 var:K) math:product var:K2.
    (var:K2 1) math:sum var:A.
    (var:K2 2) math:sum var:B.
    (var:K2 var:A var:B) math:product var:C.
    (var:S var:C) math:quotient var:D.
    (var:P0 var:D) math:sum var:P1.
    var:S math:negation var:S1.
    (var:K1 var:N var:P1 var:P var:S1) :pi true.
}

# query
_:bng_6 log:impliesAnswer _:bng_6.

_:bng_6 {
    (1000 var:Pi) :pi true.
}
