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

// Test arithmetic on results of aggregation

.decl Element(value:number)

Element(1).
Element(2).
Element(7).
Element(25).
Element(104).


.decl TotalValue(value:number)
TotalValue(value) :-
	value= sum ElementValue : Element(ElementValue).
.output TotalValue()


.decl NumberOfelements(value:number)
NumberOfelements(value) :-
	value= count : Element(_).
.output NumberOfelements()



.decl Average(value:number)
Average(f/d) :-
	TotalValue(f), NumberOfelements(d).
.output Average()

