34
35:- module(prolog_evaluable,
36 [ evaluable_property/2
37 ]). 38:- autoload(library(prolog_code), [most_general_goal/2]). 39:- autoload(library(error), [must_be/2]). 40
43
76
77evaluable_property(Templ, built_in), nonvar(Templ), \+ callable(Templ) =>
78 must_be(callable, Templ).
79evaluable_property(Templ, built_in) =>
80 current_arithmetic_function(Templ).
81evaluable_property(Templ, iso) =>
82 iso_function(Templ).
83evaluable_property(Templ, template(Term, Ret)) =>
84 most_general_goal(Templ, Term),
85 eval_type(Term, Ret).
86evaluable_property(Templ, Prop), var(Prop) =>
87 eval_prop(Prop),
88 evaluable_property(Templ, Prop).
89evaluable_property(_, _) => 90 fail. 91
92eval_prop(built_in).
93eval_prop(template(_,_)).
94eval_prop(iso).
95
96eval_type(float*_,float).
97eval_type(_*float,float).
98eval_type(rational*rational,rational).
99eval_type(float**_,float).
100eval_type(_**float,float).
101eval_type(rational**rational,rational).
102eval_type(rational**rational,float).
103eval_type(+Type,Type).
104eval_type(float+_,float).
105eval_type(_+float,float).
106eval_type(rational+rational,rational).
107eval_type(-Type,Type).
108eval_type(float-_,float).
109eval_type(_-float,float).
110eval_type(rational-rational,rational).
111eval_type(float/_,float).
112eval_type(_/float,float).
113eval_type(rational/rational,rational).
114eval_type(rational/rational,float).
115eval_type(_//_,integer).
116eval_type(integer/\integer,integer).
117eval_type(integer<<integer,integer).
118eval_type(integer>>integer,integer).
119eval_type(\integer,integer).
120eval_type(integer\/integer,integer).
121eval_type(float^_,float).
122eval_type(_^float,float).
123eval_type(rational^rational,rational).
124eval_type(rational^rational,float).
125eval_type(abs(Type),Type).
126eval_type(acos(_),float).
127eval_type(acosh(_),float).
128eval_type(asin(_),float).
129eval_type(asinh(_),float_).
130eval_type(atan(_),float).
131eval_type(atan(_,_),float).
132eval_type(atan2(_,_),float).
133eval_type(atanh(_),float).
134eval_type(ceil(_),integer).
135eval_type(ceiling(_),integer).
136eval_type(cmpr(_,_),integer).
137eval_type(copysign(Type,_),Type).
138eval_type(cos(_),float).
139eval_type(cosh(_),float).
140eval_type(cputime,float).
141eval_type(denominator(rational),integer).
142eval_type(_ div _,integer).
143eval_type(e,float).
144eval_type(epsilon,float).
145eval_type(erf(_),float).
146eval_type(erfc(_),float).
147eval_type(eval(Type),Type).
148eval_type(exp(_),float).
149eval_type(float(_),float).
150eval_type(float_fractional_part(Type),Type).
151eval_type(float_integer_part(Type),Type).
152eval_type(floor(_),integer).
153eval_type(gcd(integer,integer),integer).
154eval_type(getbit(integer,integer),integer).
155eval_type(inf,float).
156eval_type(integer(_),integer).
157eval_type(lcm(integer,integer),integer).
158eval_type(lgamma(_),float).
159eval_type(log(_),float).
160eval_type(log10(_),float).
161eval_type(lsb(integer),integer).
162eval_type(max(Type,_),Type).
163eval_type(max(_,Type),Type).
164eval_type(maxr(Type,_),Type).
165eval_type(maxr(_,Type),Type).
166eval_type(min(Type,_),Type).
167eval_type(min(_,Type),Type).
168eval_type(minr(Type,_),Type).
169eval_type(minr(_,Type),Type).
170eval_type(integer mod integer,integer).
171eval_type(msb(integer),integer).
172eval_type(nan,float).
173eval_type(nexttoward(_,_),float).
174eval_type(numerator(rational),integer).
175eval_type(pi,float).
176eval_type(popcount(integer),integer).
177eval_type(powm(integer,integer,integer),integer).
178eval_type(random(integer),integer).
179eval_type(random_float,float).
180eval_type(rational(_),rational).
181eval_type(rationalize(_),rational).
182eval_type(rational rdiv rational,rational).
183eval_type(integer rem integer,integer).
184eval_type(round(_),integer).
185eval_type(roundtoward(_,_),float).
186eval_type(sign(_),integer).
187eval_type(sin(_),float).
188eval_type(sinh(_),float).
189eval_type(sqrt(_),float).
190eval_type(tan(_),float).
191eval_type(tanh(_),float).
192eval_type(truncate(_),integer).
193eval_type(integer xor integer,integer_).
194
196iso_function(_+_).
197iso_function(_-_).
198iso_function(_*_).
199iso_function(_//_).
200iso_function(_/_).
201iso_function(rem(_,_)).
202iso_function(mod(_,_)).
203iso_function(-_).
204iso_function(abs(_)).
205iso_function(sign(_)).
206iso_function(float_integer_part(_)).
207iso_function(float_fractional_part(_)).
208iso_function(float(_)).
209iso_function(floor(_)).
210iso_function(truncate(_)).
211iso_function(round(_)).
212iso_function(ceiling(_)).
213iso_function(_**_).
214iso_function(sin(_)).
215iso_function(cos(_)).
216iso_function(atan(_)).
217iso_function(exp(_)).
218iso_function(log(_)).
219iso_function(sqrt(_)).
220iso_function(_>>_).
221iso_function(_<<_).
222iso_function(_/\_).
223iso_function(_\/_).
224iso_function(\_).
226iso_function(max(_,_)).
227iso_function(min(_,_)).
228iso_function(_^_).
229iso_function(asin(_)).
230iso_function(acos(_)).
231iso_function(atan(_,_)).
232iso_function(tan(_)).
233iso_function(pi).
234iso_function(xor(_,_))