// 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

// 1. Check that new knowledge generated by inserting into an eqrel is not lost.
// 2. Issue #2176

.decl notEqrel(x:number,y:number)
.decl isEqrel(x:number, y:number) eqrel
.decl a__(a:number, b:number)
.decl b__(a:number)
.decl c__(a:number, b:number)

.output c__, isEqrel, notEqrel // Output relation

notEqrel(x, y) :- isEqrel(x, y).
isEqrel(x, y) :- notEqrel(x, y).
isEqrel(0,1).
notEqrel(1,2).

a__(b, b) :- notEqrel(b, b).
a__(b, b) :- isEqrel(a, b), !isEqrel(a, b).  // new rule

b__(b) :- isEqrel(b, a).

c__(a, c) :- a__(e, g), a__(a, e), b__(e), b__(c).
c__(b, b) :- b__(b).
