refactor query procedure and print proof as inference dag in prolog syntax

Signed-off-by: Andrey Rybalchenko <rybal@microsoft.com>