// Souffle - A Datalog Compiler
// Copyright (c) 2016, The Souffle Developers. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt

// Compute the factorial function.

// fact(i, n) holds iff i! = n
.decl fact(i:number, n:number)
.output fact()

// Calculate only up to the lowest value satisfying lim(n)
.decl lim(n:number)
.input lim()

fact(I+1, N*(I+1)) :- fact(I, N), !lim(I).

// Ground Fact: 0! := 1
fact(0, 1).

