// Souffle - A Datalog Compiler
// Copyright (c) 2017, 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

// Tests invalid negation inlining.

// If a negated predicate is inlined, and one or more of the
// inlined predicate's bodies introduces a new variable y,
// then y cannot be grounded, and so inlining cannot occur.

.decl c(x:number) inline
c(1).
c(2).
c(3).
c(4).
c(5).

.decl d(x:number, y:number) inline
d(1, 6).
d(1, 1).
d(2, 3).
d(4, 0).
d(1, 1).

.decl b(x:number) inline
b(x) :- d(x, y), !c(y).

.decl e(x:number) inline
e(x) :- d(x, x), c(x).

.decl a(x:number)
// Invalid - inlining b, but b introduces new variables
a(x) :- c(x), !b(x).

// Valid - inlining e, and e does not introduce any new variables in its clauses
a(x) :- c(x), !e(x).

// Invalid - inlining e, but using an underscore as an argument
a(x) :- c(x), !e(_).

.output a()
