%% Arithmetic in DeAL % Schema %------- database({b(integer, integer)}). %Derivated predicates and rules %------------------------------ result(X) <- b(A, B), X = A/B. export result(X). % Schema %------- database({city(Name:string, State:string, Population:integer), distance(City1:string, City2:string, Distance:float) }). %Derivated predicates and rules %------------------------------ % User may try % query distance_feet('Austin', 'Bastrop', Z) % system would return % distance_feet('Austin', 'Bastrop', 158400). % -- 1 solution distance_feet1(X, Z, W) <- distance(X, Z, Y), W = 5280 * Y. distance_feet(X, Z, 5280 * Y) <- distance(X, Z, Y). export distance_feet1($X, $Z, Y). export distance_feet($X, $Z, Y). % ``List all cities which are within 100 miles of Austin''. % User may try % query close( 'Austin', City, 100) % System would return % close('Austin', 'San_antonio', 100). % close('Austin', 'Bastrop', 100). % -- 2 solutions % % The query form: export close($X, Y, Z) will not compile % because it is not safe. % Also % close1(X, Y, Z) <- W < Z, distance(X, Y, W). % export close1($X, Y, $Z). % is not safe either. close(X, Y, Z) <- distance(X, Y, W), W < Z. export close($X, Y, $Z).