// Souffle - A Datalog Compiler
// Copyright (c) 2016, Oracle and/or its affiliates. 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

// test arithmetic expression in Souffle

// define tautology
.type B <: symbol
.decl is_true(s:B)
is_true("true").

// define expressions
.type txt <: symbol
.decl e(x:number, t:txt, y:number)
e(10 * 2, "10*2", 20) :- is_true(_).
e(10 + 2, "10+2", 12) :- is_true(_).
e(10 / 2, "10/2", 5) :- is_true(_).
e(1+10 * 2, "1+10*2", 21) :- is_true(_).
e(1+1+10 * 2, "1+1+10*2", 22) :- is_true(_).
e(1*3+1+10 * 2, "1*3+1+10*2", 24) :- is_true(_).
e(1+20/2/5, "1+20/2/5", 3 ) :- is_true(_).
e(3*40/2/5, "3*40/2/5", 12) :- is_true(_).
e(20/2/5+1, "20/2/5+1", 3) :- is_true(_).
e(-2*10, "-20", -20) :- is_true(_).
e(-2, "-2", -2) :- is_true(_).
e(--2, "--2", 2) :- is_true(_).
e(2 ^ 2 ^ 3 , "2^2^3", 256) :- is_true(_).
e(10 ^ 2 , "10^2", 100) :- is_true(_).
e(10 % 3, "10%3", 1) :- is_true(_).
e(2^4%13 , "2^4%13",3) :- is_true(_).

// compute whether arithmetic computation failed
.decl f(x:number, t:txt, y:number)
.output f()
f(x,t,y) :- e(x,t,y), x != y.
