1:- module(utils_ssardina,
    2    [
    3        downcase_term/2,
    4        % MATH TOOLS
    5        round/3
    6    ]).
 downcase_term(+Term:term, -LowerTerm:term) is det
Recursively downcase all atoms in Term, including those nested within lists and dicts. Useful for normalizing identifiers to lowercase atoms in Prolog.
   14downcase_term(Term, LowerTerm) :- atom(Term), !,
   15    downcase_atom(Term, LowerTerm).
   16downcase_term(Term, Term) :- atomic(Term), !.
   17downcase_term(Term, LowerTerm) :-
   18	is_list(Term),
   19	!,
   20	maplist(downcase_term, Term, LowerTerm).
   21downcase_term(Term, LowerTerm) :-
   22    compound(Term),
   23	Term =.. [Functor|Args],
   24	maplist(downcase_term, Args, LowerArgs),
   25	LowerTerm =.. [Functor|LowerArgs].
   26downcase_term(Term, _) :-
   27    format(atom(Msg), 'Cannot downcase term: ~w', [Term]),
   28    throw(error(Msg)).
   29
   30
   31
   32/* ****************************************************************************
   33 MATH UTILITIES
   34 *************************************************************************** */
 round(+X:float, -R:float, +N:int) is det
R is X rounded to N decimal places.
   39round(X, R, N) :-
   40    E is 10^N,
   41	R is round(X * E) / E