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

// Program Minimisation 2
// Checks that singleton-relation reduction works

.decl A,B,C,D,E(x:number)
.decl F(x:number, y:number)
.decl G(x:number)


// these two are equivalent
F(0,0).
F(0,0).

// but not to this
F(1,2).

// these two are equivalent
A(a) :- F(a, _).
B(x) :- F(x, y).

// but not to this
C(a) :- F(_, a).

// these two are equivalent
D(x) :- F(x, x).
E(y) :- F(y, y).

// these two are equivalent
D(x) :- A(x), A(x), A(x), B(x).
D(x) :- B(x), A(x).

// these two are redundant
D(x) :- D(x).
D(x) :- D(x), x != 1, A(x).

// these two are equivalent
D(result) :- F(result,y), F(result,x), x != 3, x < y, !E(x), y > 3, E(y), !E(x), x < y.
D(x) :- F(x,alpha), alpha != 3, !E(alpha), F(x,beta), beta > 3, E(gamma), alpha < beta, gamma = beta, E(beta).

// but not to this
D(result) :- F(result,y), F(result,x), x != 3, x < y, !E(y), y > 3, E(y), E(x), x < y.

G(x) :- A(x).
G(x) :- B(x).
G(x) :- C(x).
G(x) :- D(x).
G(x) :- E(x).

.output G()
