Codebase list swi-prolog / f17d375
Imported Upstream version 7.2.3+dfsg Lev Lamberov 8 years ago
34 changed file(s) with 0 addition(s) and 6912 deletion(s). Raw diff Collapse all Expand all
+0
-1
bench/.gitignore less more
0 .pl-history
+0
-16
bench/README less more
0 These are the `van Roy' benchmarks for Prolog. They are designed to
1 cover a large number of aspects, both small-scale and large(r) scale
2 programs. All benchmarks are pure Prolog; i.e., there are no
3 constraints, etc. Another problem with this data is that the programs
4 are rather old, generally not using modern libraries and often avoiding
5 GC because some old implementations did not provide it. Also many todays
6 application manage a lot of text, often using atoms. None of the
7 benchmarks is concerned with that.
8
9 Each test is a non-modular program that provides a single predicate
10 top/0. The driver run.pl loads all programs in their own module. I
11 modified most of the driver. The toplevel is run(+Factor). Each test is
12 callibrated to be run approximately the same time. Factor scales the
13 number of iterations. Factor=1 is callibrated for 1 second per benchmark
14 on an AMD 5400+ using SWI-Prolog 5.9.7 (Linux, gcc 4.4 -O2).
15
+0
-1774
bench/asm.pl less more
0 % File : asm.pl
1 % Author : Neng-Fa ZHOU
2 % Completed October 1993
3 % Updated: Febuary 1994
4 % Purpose: Assembler of NTOAM
5
6 /* asm.pl
7 this file translates instructions and symbols into byte code */
8
9
10 :-determinate([cmp_error/1,
11 name/2,
12 length/2,
13 asm_hash_value/2]).
14
15 asm_bp(Infile,Outfile) :-
16 true :
17 global_set('$asm_bp',0,1),
18 see(Infile),
19 asm_getaslist(Insts),
20 seen,
21 tell(Outfile),
22 asm0(Insts,Prog,Index,0,NIndex),
23 functor(Psctable,csym,255),
24 functor(Labeltable,lsym,255),
25 global_create('$sym_no',0,0),
26 % output_mess('==>asm_pass1'),
27 asm_pass1_bp(Prog,Index,Psctable,Labeltable,Ntext,Npsc),
28 asm_magic(3),
29 asm_putnum(Npsc, 4),
30 asm_putnum(Ntext, 4),
31 asm_putnum(NIndex, 4),
32 % output_mess('==>asm_pass2'),
33 asm_pass2(Prog, Index,Psctable, Labeltable),
34 asm_mark_eot,
35 global_del('$asm_bp',0),
36 told.
37
38 asm(Infile,Outfile) :-
39 true :
40 see(Infile),
41 asm_getaslist(Insts),
42 seen,
43 tell(Outfile),
44 asm0(Insts,Prog,Index,0,NIndex),
45 functor(Psctable,csym,255),
46 functor(Labeltable,lsym,255),
47 global_create('$sym_no',0,0),
48 % output_mess('==>asm_pass1'),
49 asm_pass1(Prog,Index,Psctable,Labeltable,Ntext,Npsc),
50 asm_magic(3),
51 asm_putnum(Npsc, 4),
52 asm_putnum(Ntext, 4),
53 asm_putnum(NIndex, 4),
54 % output_mess('==>asm_pass2'),
55 asm_pass2(Prog, Index,Psctable, Labeltable),
56 asm_mark_eot,
57 told.
58
59 asm_getaslist(Insts):-
60 true :
61 read(Inst),
62 asm_getaslist1(Inst,Insts).
63
64 asm_getaslist1(end_of_file,Insts):-
65 true :
66 Insts:=[].
67 asm_getaslist1(Inst,Insts):-
68 true :
69 Insts:=[Inst|Insts1],
70 read(Inst1),
71 asm_getaslist1(Inst1,Insts1).
72
73 asm(Insts):-
74 true :
75 asm0(Insts,Prog,Index,0,NIndex),
76 functor(Psctable,csym,255),
77 functor(Labeltable,lsym,255),
78 global_create('$sym_no',0,0),
79 % output_mess('==>asm_pass1'),
80 asm_pass1(Prog,Index,Psctable,Labeltable,Ntext,Npsc),
81 asm_magic(3),
82 asm_putnum(Npsc, 4),
83 asm_putnum(Ntext, 4),
84 asm_putnum(NIndex, 4),
85 % output_mess('==>asm_pass2'),
86 asm_pass2(Prog, Index,Psctable, Labeltable),
87 asm_mark_eot.
88
89 asm0([],Prog,Index,NIndex0,NIndex):-
90 true :
91 Prog:=[],
92 Index:=[],
93 NIndex:=NIndex0.
94 asm0([Inst|Insts],Prog,Index,NIndex0,NIndex):-
95 asm_index_inst(Inst,Size) :
96 NIndex1 is NIndex0+Size,
97 Index = [Inst|Index1],
98 asm0(Insts,Prog,Index1,NIndex1,NIndex).
99 asm0([Inst|Insts],Prog,Index,NIndex0,NIndex):-
100 true :
101 Prog:=[Inst|Prog1],
102 asm0(Insts,Prog1,Index,NIndex0,NIndex).
103
104 asm_pass1(AsmInsts, Index,Csym, Lsym, Ntext, Npsc) :-
105 true :
106 asm_pass11(AsmInsts,Lsym,Csym,0,Ntext),
107 asm_index_pass1(Index,Csym),
108 asmpass1_fillin(Lsym,255,Csym ),
109 asmpass1_setundef( Csym,255,0,Npsc).
110
111 asm_pass1_bp(AsmInsts, Index,Csym, Lsym, Ntext, Npsc) :-
112 true :
113 asm_pass11(AsmInsts,Lsym,Csym,0,Ntext),
114 asm_index_pass1(Index,Csym),
115 asmpass1_fillin_bp(Lsym,255,Csym ),
116 asmpass1_setundef( Csym,255,0,Npsc).
117
118 asm_pass11([],_,_,Lc,NLc):-
119 true : NLc:=Lc.
120 asm_pass11([Inst| Rest], Lsym, Csym, Lc, NLc):-
121 label(X)<=Inst,
122 lab_member1(lab(X, Lc), Lsym) :
123 asm_pass11(Rest, Lsym, Csym, Lc, NLc).
124 asm_pass11([Inst| Rest], Lsym, Csym, Lc, NLc):-
125 label(X)<=Inst :
126 error_double_define(X),
127 asm_pass11(Rest, Lsym, Csym, Lc, NLc).
128 asm_pass11([Inst| Rest], Lsym, Csym, Lc, NLc):-
129 true :
130 asm_pass12(Inst,Csym,N),
131 Lc0 is Lc + N,
132 asm_pass11(Rest, Lsym, Csym, Lc0, NLc).
133
134 error_double_define((Pred,Arity,_)):-
135 true : true.
136 error_double_define((Pred,Arity)):-
137 true :
138 cmp_error(['The predicate ', Pred/Arity, ' is doubly defined']).
139
140 asm_index_pass1([],_):-true : true.
141 asm_index_pass1([pred(_,_,_,_)|Rest], Csym) :-
142 true : asm_index_pass1(Rest, Csym).
143 asm_index_pass1([arglabel(T,Val,Label)|Rest],Csym) :-
144 T == c :
145 sym_member1(sym(Val, 0, _,_), Csym),
146 asm_index_pass1(Rest, Csym).
147 asm_index_pass1([arglabel(T,(Str,Ar),Label)|Rest],Csym) :-
148 T == s :
149 sym_member1(sym(Str, Ar, _,_), Csym),
150 asm_index_pass1(Rest, Csym).
151 asm_index_pass1([arglabel(T,Val,Label)|Rest],Csym) :-
152 true :
153 asm_index_pass1(Rest,Csym).
154
155 /* Fill in the values of any predicates which are defined within this module.*/
156 asmpass1_fillin(Lsym,N,_):-
157 N<1 :
158 true.
159 asmpass1_fillin(Lsym,N,Csym):-
160 true :
161 arg(N,Lsym,L),
162 asmpass1_fillin(L,Csym),
163 N1 is N-1,
164 asmpass1_fillin(Lsym,N1,Csym).
165
166 asmpass1_fillin(L, _):-var(L) : true.
167 asmpass1_fillin([lab((_,_,_),LcValue)|Rest], Table) :-
168 true :
169 asmpass1_fillin(Rest, Table).
170 asmpass1_fillin([lab((Name, Arity),LcValue)|Rest],Table) :-
171 true :
172 sym_member1(sym(Name, Arity, LcValue,_), Table),
173 asmpass1_fillin(Rest, Table).
174
175
176 asmpass1_fillin_bp(Lsym,N,_):-
177 N<1 :
178 true.
179 asmpass1_fillin_bp(Lsym,N,Csym):-
180 true :
181 arg(N,Lsym,L),
182 asmpass1_fillin_bp(L,Csym),
183 N1 is N-1,
184 asmpass1_fillin_bp(Lsym,N1,Csym).
185
186 asmpass1_fillin_bp(L, _):-var(L) : true.
187 asmpass1_fillin_bp([lab((_,_,_),LcValue)|Rest], Table) :-
188 true :
189 asmpass1_fillin_bp(Rest, Table).
190 asmpass1_fillin_bp([lab((Name, Arity),LcValue)|Rest],Table) :-
191 predefined(Name,Arity) :
192 sym_member1(sym(Name, Arity, LcValue,_), Table),
193 asmpass1_fillin_bp(Rest, Table).
194 asmpass1_fillin_bp([lab((Name, Arity),LcValue)|Rest],Table) :-
195 true :
196 asmpass1_fillin_bp(Rest, Table).
197
198 /*
199 asmpass1_fillin([lab((Name, Arity),LcValue)|Rest],Table) :-
200 true :
201 cmp_error(['the predicate ', Name/Arity, ' is doubly defined']),
202 asmpass1_fillin(Rest, Table).
203 */
204 /* Fill in the values of any symbols which have not been defined
205 with the value -2. */
206 asmpass1_setundef(Csym,N,S0,S):-
207 N<1 :
208 S=S0.
209 asmpass1_setundef(Csym,N,S0,S):-
210 true :
211 arg(N,Csym,L),
212 asmpass1_setundef(L,S0,S1),
213 N1 is N-1,
214 asmpass1_setundef(Csym,N1,S1,S).
215
216 asmpass1_setundef(Tab, S0,S):-
217 var(Tab) :
218 S=S0.
219 asmpass1_setundef([sym(Pred, Arity,Val,_)|Rest], S0,S):-
220 var(Val) :
221 Val := -2,
222 b_GET_LENGTH_cf(Pred,L),
223 S1 is S0+L+6,
224 asmpass1_setundef(Rest, S1,S).
225 asmpass1_setundef([sym(Pred, Arity, Val,_)|Rest],S0,S) :-
226 true :
227 b_GET_LENGTH_cf(Pred,L),
228 S1 is S0+L+6,
229 asmpass1_setundef(Rest, S1,S).
230
231 :-mode asm_pass12(c,d,f).
232 asm_pass12( label(_), _, 0).
233
234 /* Conditional Jump */
235 asm_pass12( jmp(_), _, 2).
236 asm_pass12( jmpn_eq_struct_x(_,(S,N),_,_),Csym, 5):-sym_member1(sym(S,N,_,_),Csym).
237 asm_pass12( jmpn_eq_struct_y(_,(S,N),_,_),Csym, 5):-sym_member1(sym(S,N,_,_),Csym).
238 asm_pass12( jmpn_eq_atom_x(_,C,_,_), Csym, 5):-sym_member1(sym(C,0,_,_),Csym).
239 asm_pass12( jmpn_eq_atom_y(_,C,_,_), Csym, 5):-sym_member1(sym(C,0,_,_),Csym).
240 asm_pass12( jmpn_nil_x(_,_,_), _, 4).
241 asm_pass12( jmpn_nil_y(_,_,_), _, 4).
242 asm_pass12( switch_list_x(_,_,_,_), _, 5).
243 asm_pass12( switch_list_y(_,_,_,_), _, 5).
244 asm_pass12( switch_list_yxx(_,_,_,_), _, 5).
245 asm_pass12( switch_list_yxy(_,_,_,_), _, 5).
246 asm_pass12( switch_list_yyx(_,_,_,_), _, 5).
247 asm_pass12( switch_list_yyy(_,_,_,_), _, 5).
248 asm_pass12( jmpn_eq_int_x(_,_,_,_), _, 5).
249 asm_pass12( jmpn_eq_int_y(_,_,_,_), _, 5).
250 asm_pass12( jmpn_eql(_,_,_), _, 4).
251 asm_pass12( jmp_eql(_,_,_), _, 4).
252 asm_pass12( jmp_eql_yy(_,_,_), _, 4).
253 asm_pass12( jmpn_gt(_,_,_), _, 4).
254 asm_pass12( jmpn_gt_yy(_,_,_), _, 4).
255 asm_pass12( jmpn_ge(_,_,_), _, 4).
256 asm_pass12( jmpn_ge_yy(_,_,_), _, 4).
257 asm_pass12( jmpn_id(_,_,_), _, 4).
258 asm_pass12( jmp_id(_,_,_), _, 4).
259 asm_pass12( jmpn_var_x(_,_), _, 3).
260 asm_pass12( jmpn_var_y(_,_), _, 3).
261 asm_pass12( jmp_var_x(_,_), _, 3).
262 asm_pass12( jmp_var_y(_,_), _, 3).
263 asm_pass12( jmpn_atom_x(_,_), _, 3).
264 asm_pass12( jmpn_atom_y(_,_), _, 3).
265 asm_pass12( jmpn_atomic_x(_,_), _, 3).
266 asm_pass12( jmpn_atomic_y(_,_), _, 3).
267 asm_pass12( jmpn_num_x(_,_), _, 3).
268 asm_pass12( jmpn_num_y(_,_), _, 3).
269 asm_pass12( jmpn_int_x(_,_), _, 3).
270 asm_pass12( jmpn_int_y(_,_), _, 3).
271 asm_pass12( jmpn_float_x(_,_), _, 3).
272 asm_pass12( jmpn_float_y(_,_), _, 3).
273 asm_pass12( hash_jmpn_nil(_), _, 2).
274 asm_pass12( hash_jmpn_list(_), _, 2).
275 asm_pass12( hash_jmpn_int(_,_), _, 3).
276 asm_pass12( hash_jmpn_atom(C,_), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
277 asm_pass12( hash_jmpn_struct((S,N),_), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
278 asm_pass12( hash_jmpn_struct_x((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
279 asm_pass12( hash_jmpn_struct_y((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
280 asm_pass12( hash_jmpn_struct_xx((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
281 asm_pass12( hash_jmpn_struct_xy((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
282 asm_pass12( hash_jmpn_struct_yx((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
283 asm_pass12( hash_jmpn_struct_yy((S,N),_),Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
284
285 /* Unify */
286 asm_pass12( unify_struct_x(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
287 asm_pass12( unify_struct_y(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
288 asm_pass12( unify_list_x(_), _, 2).
289 asm_pass12( unify_list_y(_), _, 2).
290 asm_pass12( unify_nil_x(_), _, 2).
291 asm_pass12( unify_nil_y(_), _, 2).
292 asm_pass12( unify_atom_x(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
293 asm_pass12( unify_atom_y(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
294 asm_pass12( unify_int_x(_,_), _, 3).
295 asm_pass12( unify_int_y(_,_), _, 3).
296 asm_pass12( unify_ux_ux(_,_), _, 3).
297 asm_pass12( unify_ux_uy(_,_), _, 3).
298 asm_pass12( unify_uy_uy(_,_), _, 3).
299 asm_pass12( unify_cons_x(_,_), _, 3).
300 asm_pass12( unify_cons_y(_,_), _, 3).
301
302 asm_pass12( fork_unify_struct_y(_,(S,N),_), Csym, 4):-sym_member1(sym(S,N,_,_),Csym).
303 asm_pass12( fork_unify_list_y(_,_), _, 3).
304 asm_pass12( fork_unify_nil_y(_,_), _, 3).
305 asm_pass12( fork_unify_atom_y(_,C,_), Csym, 4):-sym_member1(sym(C,0,_,_),Csym).
306 asm_pass12( fork_unify_int_y(_,_,_), _, 4).
307 asm_pass12( fork_unify_ux_uy(_,_,_), _, 4).
308 asm_pass12( fork_unify_uy_uy(_,_,_), _, 4).
309
310 asm_pass12( fork_unicut_struct_y(_,(S,N),_), Csym, 4):-sym_member1(sym(S,N,_,_),Csym).
311 asm_pass12( fork_unicut_list_y(_,_), _, 3).
312 asm_pass12( fork_unicut_nil_y(_,_), _, 3).
313 asm_pass12( fork_unicut_atom_y(_,C,_), Csym, 4):-sym_member1(sym(C,0,_,_),Csym).
314 asm_pass12( fork_unicut_int_y(_,_,_), _, 4).
315 asm_pass12( fork_unicut_ux_uy(_,_,_), _, 4).
316 asm_pass12( fork_unicut_uy_uy(_,_,_), _, 4).
317
318
319 asm_pass12( unify0_struct_y(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
320 asm_pass12( unify0_list_y(_), _, 2).
321 asm_pass12( unify0_nil_y(_), _, 2).
322 asm_pass12( unify0_atom_y(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
323 asm_pass12( unify0_int_y(_,_), _, 3).
324 asm_pass12( unify0_ux_uy(_,_), _, 3).
325 asm_pass12( unify0_uy_uy(_,_), _, 3).
326 asm_pass12( unicut_struct_y(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
327 asm_pass12( unicut_list_y(_), _, 2).
328 asm_pass12( unicut_nil_y(_), _, 2).
329 asm_pass12( unicut_atom_y(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
330 asm_pass12( unicut_int_y(_,_), _, 3).
331 asm_pass12( unicut_uy_uy(_,_), _, 3).
332 asm_pass12( unicut, _, 1).
333
334 /* Unify argument */
335 asm_pass12( unify_arg_nil, _, 1).
336 asm_pass12( unify_arg_atom(C), Csym, 2):-sym_member1(sym(C,0,_,_),Csym).
337 asm_pass12( unify_arg_int(_), _, 2).
338 asm_pass12( unify_arg_ux_ux(_,_), _, 3).
339 asm_pass12( unify_arg_ux(_), _, 2).
340 asm_pass12( unify_arg_ux_vy(_,_), _, 3).
341 asm_pass12( unify_arg_ux_vx(_,_), _, 3).
342 asm_pass12( unify_arg_uy_uy(_,_), _, 3).
343 asm_pass12( unify_arg_uy(_), _, 2).
344 asm_pass12( unify_arg_vx(_), _, 2).
345 asm_pass12( unify_arg_vy(_), _, 2).
346 asm_pass12( unify_arg_list, _, 1).
347 asm_pass12( unify_arg_struct((S,N)), Csym, 2):-sym_member1(sym(S,N,_,_),Csym).
348 asm_pass12( unify_arg_void_one, _, 1).
349 asm_pass12( unify_arg_void(_), _, 2).
350 asm_pass12( unify_arg_wy(_), _, 2).
351 asm_pass12( unify_arg_vx_vx(_,_), _, 3).
352 asm_pass12( unify_arg_vx_vy(_,_), _, 3).
353 asm_pass12( unify_arg_vx_ux(_,_), _, 3).
354 asm_pass12( unify_arg_vx_uy(_,_), _, 3).
355 asm_pass12( unify_arg_vy_vx(_,_), _, 3).
356 asm_pass12( unify_arg_vy_vy(_,_), _, 3).
357 asm_pass12( unify_arg_vy_ux(_,_), _, 3).
358 asm_pass12( unify_arg_vy_uy(_,_), _, 3).
359 asm_pass12( unify_arg_iii(_,_,_), _, 4).
360
361 /* Move */
362 asm_pass12( move_struct_x(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
363 asm_pass12( move_struct_y(_,(S,N)), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
364 asm_pass12( move_list_x(_), _, 2).
365 asm_pass12( move_list_y(_), _, 2).
366 asm_pass12( move_nil_x(_), _, 2).
367 asm_pass12( move_nil_y(_), _, 2).
368 asm_pass12( move_atom_x(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
369 asm_pass12( move_atom_y(_,C), Csym, 3):-sym_member1(sym(C,0,_,_),Csym).
370 asm_pass12( move_int_x(_,_), _, 3).
371 asm_pass12( move_int_y(_,_), _, 3).
372 asm_pass12( move_x_ux(_,_), _, 3).
373 asm_pass12( move_x_uy(_,_), _, 3).
374 asm_pass12( move_y_ux(_,_), _, 3).
375 asm_pass12( move_y_uy(_,_), _, 3).
376 asm_pass12( move_vx(_), _, 2).
377 asm_pass12( move_vy(_), _, 2).
378 asm_pass12( move_x_wy(_,_), _, 3).
379 asm_pass12( move_y_wy(_,_), _, 3).
380 asm_pass12( move_yy_yw(_,_,_,_), _, 5).
381 asm_pass12( move_yw_yy(_,_,_,_), _, 5).
382 asm_pass12( move_yy_yy(_,_,_,_), _, 5).
383 asm_pass12( move_yy_yy_yy(_,_,_,_,_,_), _, 7).
384
385 /* Numeric */
386 asm_pass12( and(_,_,_), _, 4).
387 asm_pass12( or(_,_,_), _, 4).
388 asm_pass12( lshiftl(_,_,_), _, 4).
389 asm_pass12( lshiftr(_,_,_), _, 4).
390 asm_pass12( complement(_,_), _, 3).
391 asm_pass12( add(_,_,_), _, 4).
392 asm_pass12( add1_y(_), _, 2).
393 asm_pass12( sub(_,_,_), _, 4).
394 asm_pass12( sub1_y(_), _, 2).
395 asm_pass12( mul(_,_,_), _, 4).
396 asm_pass12( div(_,_,_), _, 4).
397 asm_pass12( idiv(_,_,_), _, 4).
398 asm_pass12( mod(_,_,_), _, 4).
399
400 /*Parameter passing */
401 asm_pass12( para_struct((S,N)), Csym, 2):-sym_member1(sym(S,N,_,_),Csym).
402 asm_pass12( para_list, _, 1).
403 asm_pass12( para_nil, _, 1).
404 asm_pass12( para_atom(C), Csym, 2):-sym_member1(sym(C,0,_,_),Csym).
405 asm_pass12( para_int(_), _, 2).
406 asm_pass12( para_ux(_), _, 2).
407 asm_pass12( para_uy(_), _, 2).
408 asm_pass12( para_vx(_), _, 2).
409 asm_pass12( para_vy(_), _, 2).
410 asm_pass12( para_void_one, _, 1).
411 asm_pass12( para_void(_), _, 2).
412 asm_pass12( para_vy_vy(_,_), _, 3).
413 asm_pass12( para_vy_ux(_,_), _, 3).
414 asm_pass12( para_vy_uy(_,_), _, 3).
415 asm_pass12( para_ux_vy(_,_), _, 3).
416 asm_pass12( para_ux_ux(_,_), _, 3).
417 asm_pass12( para_ux_uy(_,_), _, 3).
418 asm_pass12( para_uy_vy(_,_), _, 3).
419 asm_pass12( para_uy_ux(_,_), _, 3).
420 asm_pass12( para_uy_uy(_,_), _, 3).
421 asm_pass12( para_ux_ux_ux(_,_,_), _, 4).
422 asm_pass12( para_ux_ux_uy(_,_,_), _, 4).
423 asm_pass12( para_ux_uy_ux(_,_,_), _, 4).
424 asm_pass12( para_ux_uy_uy(_,_,_), _, 4).
425 asm_pass12( para_uy_ux_ux(_,_,_), _, 4).
426 asm_pass12( para_uy_ux_uy(_,_,_), _, 4).
427 asm_pass12( para_uy_uy_ux(_,_,_), _, 4).
428 asm_pass12( para_uy_uy_uy(_,_,_), _, 4).
429 asm_pass12( para_uy_uy_uy_uy(_,_,_,_), _, 5).
430
431 /* Procedural */
432 asm_pass12( call((P,N)), Csym, 2):-asm_pass12_call(P,N,Csym).
433 asm_pass12(callv(_), _, 2).
434 asm_pass12( execute((P,N)), Csym, 2):-asm_pass12_call(P,N,Csym).
435 asm_pass12(executev(_), _, 2).
436 asm_pass12( return_a, _, 1).
437 asm_pass12( return_b, _, 1).
438 asm_pass12( jmpn_det(L), _, 2).
439 asm_pass12( save_ht_jmp(_,_), _, 3).
440
441 /* Allocate */
442 asm_pass12( allocate_flat(N), _, 2).
443 asm_pass12( allocate_nonflat(N), _, 2).
444 asm_pass12( allocate_nondet(N), _, 2).
445 asm_pass12( flat_to_nondet(N), _, 2).
446
447 /* Backtracking */
448 asm_pass12( fail, _, 1).
449 asm_pass12( fail0, _, 1).
450
451 asm_pass12( fork(_), _, 2).
452
453 asm_pass12( commit, _, 1).
454 asm_pass12( cut, _, 1).
455 asm_pass12( cut_fail, _, 1).
456 asm_pass12( cut_return, _, 1).
457 asm_pass12( save_b, _, 1).
458 asm_pass12(getbreg(_), _, 2).
459 asm_pass12(getpbreg(_), _, 2).
460 asm_pass12(putbreg(_), _, 2).
461
462 /* Hashing */
463 asm_pass12( hash_x(_,_), _, 5).
464 asm_pass12( hash_y(_,_), _, 5).
465 asm_pass12(tabsize(_), _, 2).
466
467 /* builtin */
468 asm_pass12( arg(_,_,_), _, 4).
469 asm_pass12( arg0(_,_,_), _, 4).
470 asm_pass12( setarg(_,_,_), _, 4).
471 asm_pass12( setarg0(_,_,_), _, 4).
472 asm_pass12(functor(_,_,_), _, 4).
473 asm_pass12(builtin0(_,_), _, 3).
474 asm_pass12(builtin1(_,_,_), _, 4).
475 asm_pass12(builtin2(_,_,_,_), _, 5).
476 asm_pass12(builtin3(_,_,_,_,_), _, 6).
477 asm_pass12(builtin4(_,_,_,_,_,_), _, 7).
478 asm_pass12(func_arity(_,_), _, 3).
479
480 /* Miscellaneous */
481 asm_pass12( halt, _, 1).
482 asm_pass12( endfile, _, 1).
483 asm_pass12( gethtreg(_,_), _, 3).
484 asm_pass12( puthtreg(_,_), _, 3).
485 asm_pass12( endfile, _, 1).
486 asm_pass12( get_ar_cps, _, 1).
487 asm_pass12( put_ar_cps(_), _, 2).
488 asm_pass12( move_ar_cps(_), _, 2).
489 asm_pass12( jmpn_det_get_ar_cps(L), _, 2).
490 asm_pass12( allocate_susp(N), _, 2).
491 asm_pass12( susp_var_x(_), _, 2).
492 asm_pass12( susp_var_y(_), _, 2).
493 asm_pass12( delay((S,N),_), Csym, 3):-sym_member1(sym(S,N,_,_),Csym).
494 asm_pass12( susp_var_delay(_,(S,N),_,_),Csym, 5):-sym_member1(sym(S,N,_,_),Csym).
495 asm_pass12( end_delay, _, 1).
496
497 asm_pass12( nondet(_), _, 2).
498 asm_pass12( jmp_susp(_), _, 2).
499 asm_pass12( jmpn_dvar_y(_,_), _, 3).
500 asm_pass12( susp_var2_delay(_,(S,N),_,_),Csym,5):-sym_member1(sym(S,N,_,_),Csym).
501 asm_pass12( domain_set_false_yy(_,_), _, 3).
502 asm_pass12( domain_set_false_yx(_,_), _, 3).
503 asm_pass12_call(P,N,Csym):-
504 isglobal('$asm_bp',0),
505 b_GET_SYM_TYPE_ccf(P,N,Type),
506 Type =\= 3 : /* no a call to a c function */
507 true.
508 asm_pass12_call(P,N,Csym):-
509 true :
510 sym_member1(sym(P,N,_,_),Csym).
511
512 /**/
513 /*
514 asm_pass12( Junk,_,N) :-
515 true :
516 N=0,
517 cmp_error(['*** Error in assembly: unknown opcode: ',Junk]).
518 */
519 /******************* Pass 2 **************************************/
520 asm_pass2(Prog,Index,Csym,Lsym) :-
521 true :
522 asm_rearange_csym(Csym,255,_,Csym1),
523 asm_symbol(Csym1),
524 asm_pass2a(Prog,Csym,Lsym),
525 asm_index(Index,Csym,Lsym).
526
527 asm_index([],_,_):-true : true.
528 asm_index([Inst|Index],Csym,Lsym) :-
529 true :
530 asm_proc_index(Inst, Csym, Lsym),
531 asm_index(Index,Csym,Lsym).
532
533 asm_proc_index(pred(HashLab,Op,Num,Alt), Csym, Lsym) :-
534 true :
535 x_or_y(Op,XY),
536 asm_lookup_ltab(HashLab,Lsym,Val1),
537 asm_lookup_ltab(Alt,Lsym,Val2),
538 b_ASPN4_cccc(Val1,XY,Num,Val2).
539 asm_proc_index(arglabel(T,Val,Label), Csym, Lsym) :-
540 T == c :
541 asm_lookup_ctab(Val,0,Csym,Nval),
542 asm_lookup_ltab(Label, Lsym,L),
543 writename(T),b_ASPN2_cc(Nval,L).
544 asm_proc_index(arglabel(T,Val,Label), Csym, Lsym) :-
545 T == s :
546 Val = (Str, Arity),
547 asm_lookup_ctab(Str, Arity,Csym, Nval),
548 asm_lookup_ltab(Label,Lsym, L),
549 writename(T),b_ASPN2_cc(Nval,L).
550 asm_proc_index(arglabel(T,Val,Label), Csym, Lsym) :-
551 true :
552 asm_lookup_ltab(Label, Lsym, L),
553 writename(T),b_ASPN2_cc(Val,L).
554
555 asm_pass2a([],_,_):-true : true.
556 asm_pass2a([Inst|Insts],Csym,Lsym) :-
557 true :
558 asm_pass2_inst(Inst,Csym,Lsym),
559 asm_pass2a(Insts,Csym,Lsym).
560
561
562 /*
563 asm_pass2_inst(X,_,_) :-
564 true ?
565 output_mess(X),
566 fail.
567 */
568 asm_pass2_inst(label(_),_,_) :-
569 true : true.
570 asm_pass2_inst(call(Lab),Csym,Lsym) :-
571 asm_lookup_ltab(Lab,Lsym,EPaddr) :
572 opcode(call_d,X),
573 b_ASPN2_cc(X,EPaddr).
574 asm_pass2_inst(call((P,N)),Csym,Lsym) :-
575 true :
576 (asm_lookup_ctab(P,N,Csym,Index) ->
577 opcode(call,X),
578 b_ASPN2_cc(X,Index);
579 warning([P/N,' is called but not defined'])).
580 asm_pass2_inst(execute(Lab),Csym,Lsym) :-
581 asm_lookup_ltab(Lab,Lsym,EPaddr) :
582 opcode(djmp,X),
583 b_ASPN2_cc(X,EPaddr).
584 asm_pass2_inst(execute((P,N)),Csym,Lsym) :-
585 true :
586 (asm_lookup_ctab(P,N,Csym,Index) ->
587 opcode(execute,X),
588 b_ASPN2_cc(X,Index);
589 warning([P/N,' is called but not defined'])).
590 asm_pass2_inst(jmp(L),Csym,Lsym) :-
591 asm_lookup_ltab(L,Lsym,Val) :
592 opcode(jmp,X),
593 b_ASPN2_cc(X,Val).
594 asm_pass2_inst(jmp_susp(L),Csym,Lsym) :-
595 asm_lookup_ltab(L,Lsym,Val) :
596 opcode(jmp_susp,X),
597 b_ASPN2_cc(X,Val).
598 asm_pass2_inst(jmpn_eq_struct_x(Op,(S,N),L1,L2),Csym,Lsym) :-
599 true :
600 asm_lookup_ctab(S,N,Csym,I),
601 asm_lookup_ltab(L1,Lsym,Val1),
602 asm_lookup_ltab(L2,Lsym,Val2),
603 opcode(jmpn_eq_struct_x,X),
604 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
605 asm_pass2_inst(jmpn_eq_struct_y(Op,(S,N),L1,L2),Csym,Lsym) :-
606 true :
607 asm_lookup_ctab(S,N,Csym,I),
608 asm_lookup_ltab(L1,Lsym,Val1),
609 asm_lookup_ltab(L2,Lsym,Val2),
610 opcode(jmpn_eq_struct_y,X),
611 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
612 asm_pass2_inst(jmpn_eq_atom_x(Op,C,L1,L2),Csym,Lsym) :-
613 true :
614 asm_lookup_ctab(C,0,Csym,I),
615 asm_lookup_ltab(L1,Lsym,Val1),
616 asm_lookup_ltab(L2,Lsym,Val2),
617 opcode(jmpn_eq_atom_x,X),
618 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
619 asm_pass2_inst(jmpn_eq_atom_y(Op,C,L1,L2),Csym,Lsym) :-
620 true :
621 asm_lookup_ctab(C,0,Csym,I),
622 asm_lookup_ltab(L1,Lsym,Val1),
623 asm_lookup_ltab(L2,Lsym,Val2),
624 opcode(jmpn_eq_atom_y,X),
625 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
626 asm_pass2_inst(jmpn_nil_x(Op,L1,L2),Csym,Lsym) :-
627 true :
628 asm_lookup_ltab(L1,Lsym,Val1),
629 asm_lookup_ltab(L2,Lsym,Val2),
630 opcode(jmpn_nil_x,X),
631 b_ASPN4_cccc(X,Op,Val1,Val2).
632 asm_pass2_inst(jmpn_nil_y(Op,L1,L2),Csym,Lsym) :-
633 true :
634 asm_lookup_ltab(L1,Lsym,Val1),
635 asm_lookup_ltab(L2,Lsym,Val2),
636 opcode(jmpn_nil_y,X),
637 b_ASPN4_cccc(X,Op,Val1,Val2).
638 asm_pass2_inst(switch_list_x(Op,L1,L2,L3),Csym,Lsym) :-
639 true :
640 asm_lookup_ltab(L1,Lsym,Val1),
641 asm_lookup_ltab(L2,Lsym,Val2),
642 asm_lookup_ltab(L3,Lsym,Val3),
643 opcode(switch_list_x,X),
644 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
645 asm_pass2_inst(switch_list_y(Op,L1,L2,L3),Csym,Lsym) :-
646 true :
647 asm_lookup_ltab(L1,Lsym,Val1),
648 asm_lookup_ltab(L2,Lsym,Val2),
649 asm_lookup_ltab(L3,Lsym,Val3),
650 opcode(switch_list_y,X),
651 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
652 asm_pass2_inst(switch_list_yxx(Op,L1,L2,L3),Csym,Lsym) :-
653 true :
654 asm_lookup_ltab(L1,Lsym,Val1),
655 asm_lookup_ltab(L2,Lsym,Val2),
656 asm_lookup_ltab(L3,Lsym,Val3),
657 opcode(switch_list_yxx,X),
658 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
659 asm_pass2_inst(switch_list_yxy(Op,L1,L2,L3),Csym,Lsym) :-
660 true :
661 asm_lookup_ltab(L1,Lsym,Val1),
662 asm_lookup_ltab(L2,Lsym,Val2),
663 asm_lookup_ltab(L3,Lsym,Val3),
664 opcode(switch_list_yxy,X),
665 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
666 asm_pass2_inst(switch_list_yyx(Op,L1,L2,L3),Csym,Lsym) :-
667 true :
668 asm_lookup_ltab(L1,Lsym,Val1),
669 asm_lookup_ltab(L2,Lsym,Val2),
670 asm_lookup_ltab(L3,Lsym,Val3),
671 opcode(switch_list_yyx,X),
672 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
673 asm_pass2_inst(switch_list_yyy(Op,L1,L2,L3),Csym,Lsym) :-
674 true :
675 asm_lookup_ltab(L1,Lsym,Val1),
676 asm_lookup_ltab(L2,Lsym,Val2),
677 asm_lookup_ltab(L3,Lsym,Val3),
678 opcode(switch_list_yyy,X),
679 b_ASPN4_cccc(X,Op,Val1,Val2),b_ASPN_c(Val3).
680 asm_pass2_inst(jmpn_eq_int_x(Op,I,L1,L2),Csym,Lsym) :-
681 true :
682 asm_lookup_ltab(L1,Lsym,Val1),
683 asm_lookup_ltab(L2,Lsym,Val2),
684 opcode(jmpn_eq_int_x,X),
685 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
686 asm_pass2_inst(jmpn_eq_int_y(Op,I,L1,L2),Csym,Lsym) :-
687 true :
688 asm_lookup_ltab(L1,Lsym,Val1),
689 asm_lookup_ltab(L2,Lsym,Val2),
690 opcode(jmpn_eq_int_y,X),
691 b_ASPN4_cccc(X,Op,I,Val1),b_ASPN_c(Val2).
692 asm_pass2_inst(jmpn_eql(Op1,Op2,L),Csym,Lsym) :-
693 true :
694 asm_lookup_ltab(L,Lsym,Val),
695 x_or_y(Op1,XY1),
696 x_or_y(Op2,XY2),
697 opcode(jmpn_eql,X),
698 b_ASPN4_cccc(X,XY1,XY2,Val).
699 asm_pass2_inst(jmp_eql(Op1,Op2,L),Csym,Lsym) :-
700 true :
701 asm_lookup_ltab(L,Lsym,Val),
702 x_or_y(Op1,XY1),
703 x_or_y(Op2,XY2),
704 opcode(jmp_eql,X),
705 b_ASPN4_cccc(X,XY1,XY2,Val).
706 asm_pass2_inst(jmp_eql_yy(Op1,Op2,L),Csym,Lsym) :-
707 true :
708 asm_lookup_ltab(L,Lsym,Val),
709 opcode(jmp_eql_yy,X),
710 b_ASPN4_cccc(X,Op1,Op2,Val).
711 asm_pass2_inst(jmpn_gt(Op1,Op2,L),Csym,Lsym) :-
712 true :
713 asm_lookup_ltab(L,Lsym,Val),
714 x_or_y(Op1,XY1),
715 x_or_y(Op2,XY2),
716 opcode(jmpn_gt,X),
717 b_ASPN4_cccc(X,XY1,XY2,Val).
718 asm_pass2_inst(jmpn_gt_yy(Op1,Op2,L),Csym,Lsym) :-
719 true :
720 asm_lookup_ltab(L,Lsym,Val),
721 opcode(jmpn_gt_yy,X),
722 b_ASPN4_cccc(X,Op1,Op2,Val).
723 asm_pass2_inst(jmpn_ge(Op1,Op2,L),Csym,Lsym) :-
724 true :
725 asm_lookup_ltab(L,Lsym,Val),
726 x_or_y(Op1,XY1),
727 x_or_y(Op2,XY2),
728 opcode(jmpn_ge,X),
729 b_ASPN4_cccc(X,XY1,XY2,Val).
730 asm_pass2_inst(jmpn_ge_yy(Op1,Op2,L),Csym,Lsym) :-
731 true :
732 asm_lookup_ltab(L,Lsym,Val),
733 opcode(jmpn_ge_yy,X),
734 b_ASPN4_cccc(X,Op1,Op2,Val).
735 asm_pass2_inst(jmpn_id(Op1,Op2,L),Csym,Lsym) :-
736 true :
737 asm_lookup_ltab(L,Lsym,Val),
738 x_or_y(Op1,XY1),
739 x_or_y(Op2,XY2),
740 opcode(jmpn_id,X),
741 b_ASPN4_cccc(X,XY1,XY2,Val).
742 asm_pass2_inst(jmp_id(Op1,Op2,L),Csym,Lsym) :-
743 true :
744 asm_lookup_ltab(L,Lsym,Val),
745 x_or_y(Op1,XY1),
746 x_or_y(Op2,XY2),
747 opcode(jmp_id,X),
748 b_ASPN4_cccc(X,XY1,XY2,Val).
749 asm_pass2_inst(jmpn_var_x(Op,L),Csym,Lsym) :-
750 true :
751 asm_lookup_ltab(L,Lsym,Val),
752 opcode(jmpn_var_x,X),
753 b_ASPN3_ccc(X,Op,Val).
754 asm_pass2_inst(jmpn_var_y(Op,L),Csym,Lsym) :-
755 true :
756 asm_lookup_ltab(L,Lsym,Val),
757 opcode(jmpn_var_y,X),
758 b_ASPN3_ccc(X,Op,Val).
759 asm_pass2_inst(jmp_var_x(Op,L),Csym,Lsym) :-
760 true :
761 asm_lookup_ltab(L,Lsym,Val),
762 opcode(jmp_var_x,X),
763 b_ASPN3_ccc(X,Op,Val).
764 asm_pass2_inst(jmp_var_y(Op,L),Csym,Lsym) :-
765 true :
766 asm_lookup_ltab(L,Lsym,Val),
767 opcode(jmp_var_y,X),
768 b_ASPN3_ccc(X,Op,Val).
769 asm_pass2_inst(jmpn_atom_x(Op,L),Csym,Lsym) :-
770 true :
771 asm_lookup_ltab(L,Lsym,Val),
772 opcode(jmpn_atom_x,X),
773 b_ASPN3_ccc(X,Op,Val).
774 asm_pass2_inst(jmpn_atom_y(Op,L),Csym,Lsym) :-
775 true :
776 asm_lookup_ltab(L,Lsym,Val),
777 opcode(jmpn_atom_y,X),
778 b_ASPN3_ccc(X,Op,Val).
779 asm_pass2_inst(jmpn_atomic_x(Op,L),Csym,Lsym) :-
780 true :
781 asm_lookup_ltab(L,Lsym,Val),
782 opcode(jmpn_atomic_x,X),
783 b_ASPN3_ccc(X,Op,Val).
784 asm_pass2_inst(jmpn_atomic_y(Op,L),Csym,Lsym) :-
785 true :
786 asm_lookup_ltab(L,Lsym,Val),
787 opcode(jmpn_atomic_y,X),
788 b_ASPN3_ccc(X,Op,Val).
789 asm_pass2_inst(jmpn_num_x(Op,L),Csym,Lsym) :-
790 true :
791 asm_lookup_ltab(L,Lsym,Val),
792 opcode(jmpn_num_x,X),
793 b_ASPN3_ccc(X,Op,Val).
794 asm_pass2_inst(jmpn_num_y(Op,L),Csym,Lsym) :-
795 true :
796 asm_lookup_ltab(L,Lsym,Val),
797 opcode(jmpn_num_y,X),
798 b_ASPN3_ccc(X,Op,Val).
799 asm_pass2_inst(jmpn_float_x(Op,L),Csym,Lsym) :-
800 true :
801 asm_lookup_ltab(L,Lsym,Val),
802 opcode(jmpn_float_x,X),
803 b_ASPN3_ccc(X,Op,Val).
804 asm_pass2_inst(jmpn_float_y(Op,L),Csym,Lsym) :-
805 true :
806 asm_lookup_ltab(L,Lsym,Val),
807 opcode(jmpn_float_y,X),
808 b_ASPN3_ccc(X,Op,Val).
809 asm_pass2_inst(jmpn_int_x(Op,L),Csym,Lsym) :-
810 true :
811 asm_lookup_ltab(L,Lsym,Val),
812 opcode(jmpn_int_x,X),
813 b_ASPN3_ccc(X,Op,Val).
814 asm_pass2_inst(jmpn_int_y(Op,L),Csym,Lsym) :-
815 true :
816 asm_lookup_ltab(L,Lsym,Val),
817 opcode(jmpn_int_y,X),
818 b_ASPN3_ccc(X,Op,Val).
819 asm_pass2_inst(hash_jmpn_nil(L),Csym,Lsym) :-
820 true :
821 asm_lookup_ltab(L,Lsym,Val),
822 opcode(hash_jmpn_nil,X),
823 b_ASPN2_cc(X,Val).
824 asm_pass2_inst(hash_jmpn_list(L),Csym,Lsym) :-
825 true :
826 asm_lookup_ltab(L,Lsym,Val),
827 opcode(hash_jmpn_list,X),
828 b_ASPN2_cc(X,Val).
829 asm_pass2_inst(hash_jmpn_int(I,L),Csym,Lsym) :-
830 true :
831 asm_lookup_ltab(L,Lsym,Val),
832 opcode(hash_jmpn_int,X),
833 b_ASPN3_ccc(X,I,Val).
834 asm_pass2_inst(hash_jmpn_atom(C,L),Csym,Lsym) :-
835 true :
836 asm_lookup_ctab(C,0,Csym,I),
837 asm_lookup_ltab(L,Lsym,Val),
838 opcode(hash_jmpn_atom,X),
839 b_ASPN3_ccc(X,I,Val).
840 asm_pass2_inst(hash_jmpn_struct((S,N),L),Csym,Lsym) :-
841 true :
842 asm_lookup_ctab(S,N,Csym,I),
843 asm_lookup_ltab(L,Lsym,Val),
844 opcode(hash_jmpn_struct,X),
845 b_ASPN3_ccc(X,I,Val).
846 asm_pass2_inst(hash_jmpn_struct_x((S,N),L),Csym,Lsym) :-
847 true :
848 asm_lookup_ctab(S,N,Csym,I),
849 asm_lookup_ltab(L,Lsym,Val),
850 opcode(hash_jmpn_struct_x,X),
851 b_ASPN3_ccc(X,I,Val).
852 asm_pass2_inst(hash_jmpn_struct_y((S,N),L),Csym,Lsym) :-
853 true :
854 asm_lookup_ctab(S,N,Csym,I),
855 asm_lookup_ltab(L,Lsym,Val),
856 opcode(hash_jmpn_struct_y,X),
857 b_ASPN3_ccc(X,I,Val).
858 asm_pass2_inst(hash_jmpn_struct_xx((S,N),L),Csym,Lsym) :-
859 true :
860 asm_lookup_ctab(S,N,Csym,I),
861 asm_lookup_ltab(L,Lsym,Val),
862 opcode(hash_jmpn_struct_xx,X),
863 b_ASPN3_ccc(X,I,Val).
864 asm_pass2_inst(hash_jmpn_struct_xy((S,N),L),Csym,Lsym) :-
865 true :
866 asm_lookup_ctab(S,N,Csym,I),
867 asm_lookup_ltab(L,Lsym,Val),
868 opcode(hash_jmpn_struct_xy,X),
869 b_ASPN3_ccc(X,I,Val).
870 asm_pass2_inst(hash_jmpn_struct_yx((S,N),L),Csym,Lsym) :-
871 true :
872 asm_lookup_ctab(S,N,Csym,I),
873 asm_lookup_ltab(L,Lsym,Val),
874 opcode(hash_jmpn_struct_yx,X),
875 b_ASPN3_ccc(X,I,Val).
876 asm_pass2_inst(hash_jmpn_struct_yy((S,N),L),Csym,Lsym) :-
877 true :
878 asm_lookup_ctab(S,N,Csym,I),
879 asm_lookup_ltab(L,Lsym,Val),
880 opcode(hash_jmpn_struct_yy,X),
881 b_ASPN3_ccc(X,I,Val).
882 asm_pass2_inst(jmpn_det(L),Csym,Lsym) :-
883 true :
884 asm_lookup_ltab(L,Lsym,Val),
885 opcode(jmpn_det,X),
886 b_ASPN2_cc(X,Val).
887 asm_pass2_inst(jmpn_det_get_ar_cps(L),Csym,Lsym) :-
888 true :
889 asm_lookup_ltab(L,Lsym,Val),
890 opcode(jmpn_det_get_ar_cps,X),
891 b_ASPN2_cc(X,Val).
892 asm_pass2_inst(save_ht_jmp(L1,L2),Csym,Lsym) :-
893 true :
894 asm_lookup_ltab(L1,Lsym,Val1),
895 asm_lookup_ltab(L2,Lsym,Val2),
896 opcode(save_ht_jmp,X),
897 b_ASPN3_ccc(X,Val1,Val2).
898 asm_pass2_inst(unify_struct_x(Op,(S,N)),Csym,Lsym):-
899 true :
900 asm_lookup_ctab(S,N,Csym,I),
901 opcode(unify_struct_x,X),
902 b_ASPN3_ccc(X,Op,I).
903 asm_pass2_inst(unify_struct_y(Op,(S,N)),Csym,Lsym):-
904 true :
905 asm_lookup_ctab(S,N,Csym,I),
906 opcode(unify_struct_y,X),
907 b_ASPN3_ccc(X,Op,I).
908 asm_pass2_inst(unify0_struct_y(Op,(S,N)),Csym,Lsym):-
909 true :
910 asm_lookup_ctab(S,N,Csym,I),
911 opcode(unify0_struct_y,X),
912 b_ASPN3_ccc(X,Op,I).
913 asm_pass2_inst(unicut_struct_y(Op,(S,N)),Csym,Lsym):-
914 true :
915 asm_lookup_ctab(S,N,Csym,I),
916 opcode(unicut_struct_y,X),
917 b_ASPN3_ccc(X,Op,I).
918 asm_pass2_inst(unify_atom_x(Op,C),Csym,Lsym):-
919 true :
920 asm_lookup_ctab(C,0,Csym,I),
921 opcode(unify_atom_x,X),
922 b_ASPN3_ccc(X,Op,I).
923 asm_pass2_inst(unify_atom_y(Op,C),Csym,Lsym):-
924 true :
925 asm_lookup_ctab(C,0,Csym,I),
926 opcode(unify_atom_y,X),
927 b_ASPN3_ccc(X,Op,I).
928 asm_pass2_inst(unify0_atom_y(Op,C),Csym,Lsym):-
929 true :
930 asm_lookup_ctab(C,0,Csym,I),
931 opcode(unify0_atom_y,X),
932 b_ASPN3_ccc(X,Op,I).
933 asm_pass2_inst(unicut_atom_y(Op,C),Csym,Lsym):-
934 true :
935 asm_lookup_ctab(C,0,Csym,I),
936 opcode(unicut_atom_y,X),
937 b_ASPN3_ccc(X,Op,I).
938 asm_pass2_inst(unify_arg_atom(C),Csym,Lsym):-
939 true :
940 asm_lookup_ctab(C,0,Csym,I),
941 opcode(unify_arg_atom,X),
942 b_ASPN2_cc(X,I).
943 asm_pass2_inst(unify_arg_struct((S,N)),Csym,Lsym):-
944 true :
945 asm_lookup_ctab(S,N,Csym,I),
946 opcode(unify_arg_struct,X),
947 b_ASPN2_cc(X,I).
948
949 asm_pass2_inst(move_struct_x(Op,(S,N)),Csym,Lsym):-
950 true :
951 asm_lookup_ctab(S,N,Csym,I),
952 opcode(move_struct_x,X),
953 b_ASPN3_ccc(X,Op,I).
954 asm_pass2_inst(move_struct_y(Op,(S,N)),Csym,Lsym):-
955 true :
956 asm_lookup_ctab(S,N,Csym,I),
957 opcode(move_struct_y,X),
958 b_ASPN3_ccc(X,Op,I).
959 asm_pass2_inst(move_atom_x(Op,C),Csym,Lsym):-
960 true :
961 asm_lookup_ctab(C,0,Csym,I),
962 opcode(move_atom_x,X),
963 b_ASPN3_ccc(X,Op,I).
964 asm_pass2_inst(move_atom_y(Op,C),Csym,Lsym):-
965 true :
966 asm_lookup_ctab(C,0,Csym,I),
967 opcode(move_atom_y,X),
968 b_ASPN3_ccc(X,Op,I).
969 asm_pass2_inst(and(Op1,Op2,Op3),Csym,Lsym):-
970 true :
971 x_or_y(Op1,XY1),
972 x_or_y(Op2,XY2),
973 x_or_y(Op3,XY3),
974 opcode(and,X),
975 b_ASPN4_cccc(X,XY1,XY2,XY3).
976 asm_pass2_inst(or(Op1,Op2,Op3),Csym,Lsym):-
977 true :
978 x_or_y(Op1,XY1),
979 x_or_y(Op2,XY2),
980 x_or_y(Op3,XY3),
981 opcode(or,X),
982 b_ASPN4_cccc(X,XY1,XY2,XY3).
983 asm_pass2_inst(lshiftl(Op1,Op2,Op3),Csym,Lsym):-
984 true :
985 x_or_y(Op1,XY1),
986 x_or_y(Op2,XY2),
987 x_or_y(Op3,XY3),
988 opcode(lshiftl,X),
989 b_ASPN4_cccc(X,XY1,XY2,XY3).
990 asm_pass2_inst(lshiftr(Op1,Op2,Op3),Csym,Lsym):-
991 true :
992 x_or_y(Op1,XY1),
993 x_or_y(Op2,XY2),
994 x_or_y(Op3,XY3),
995 opcode(lshiftr,X),
996 b_ASPN4_cccc(X,XY1,XY2,XY3).
997 asm_pass2_inst(complement(Op1,Op2),Csym,Lsym):-
998 true :
999 x_or_y(Op1,XY1),
1000 x_or_y(Op2,XY2),
1001 opcode(complement,X),
1002 b_ASPN3_ccc(X,XY1,XY2).
1003 asm_pass2_inst(add(Op1,Op2,Op3),Csym,Lsym):-
1004 true :
1005 x_or_y(Op1,XY1),
1006 x_or_y(Op2,XY2),
1007 x_or_y(Op3,XY3),
1008 opcode(add,X),
1009 b_ASPN4_cccc(X,XY1,XY2,XY3).
1010 asm_pass2_inst(sub(Op1,Op2,Op3),Csym,Lsym):-
1011 true :
1012 x_or_y(Op1,XY1),
1013 x_or_y(Op2,XY2),
1014 x_or_y(Op3,XY3),
1015 opcode(sub,X),
1016 b_ASPN4_cccc(X,XY1,XY2,XY3).
1017 asm_pass2_inst(mul(Op1,Op2,Op3),Csym,Lsym):-
1018 true :
1019 x_or_y(Op1,XY1),
1020 x_or_y(Op2,XY2),
1021 x_or_y(Op3,XY3),
1022 opcode(mul,X),
1023 b_ASPN4_cccc(X,XY1,XY2,XY3).
1024 asm_pass2_inst(div(Op1,Op2,Op3),Csym,Lsym):-
1025 true :
1026 x_or_y(Op1,XY1),
1027 x_or_y(Op2,XY2),
1028 x_or_y(Op3,XY3),
1029 opcode(div,X),
1030 b_ASPN4_cccc(X,XY1,XY2,XY3).
1031 asm_pass2_inst(idiv(Op1,Op2,Op3),Csym,Lsym):-
1032 true :
1033 x_or_y(Op1,XY1),
1034 x_or_y(Op2,XY2),
1035 x_or_y(Op3,XY3),
1036 opcode(idiv,X),
1037 b_ASPN4_cccc(X,XY1,XY2,XY3).
1038 asm_pass2_inst(mod(Op1,Op2,Op3),Csym,Lsym):-
1039 true :
1040 x_or_y(Op1,XY1),
1041 x_or_y(Op2,XY2),
1042 x_or_y(Op3,XY3),
1043 opcode(mod,X),
1044 b_ASPN4_cccc(X,XY1,XY2,XY3).
1045 asm_pass2_inst(para_struct((S,N)),Csym,Lsym):-
1046 true :
1047 asm_lookup_ctab(S,N,Csym,I),
1048 opcode(para_struct,X),
1049 b_ASPN2_cc(X,I).
1050 asm_pass2_inst(para_atom(C),Csym,Lsym):-
1051 true :
1052 asm_lookup_ctab(C,0,Csym,I),
1053 opcode(para_atom,X),
1054 b_ASPN2_cc(X,I).
1055 asm_pass2_inst(fork(L),Csym,Lsym) :-
1056 true :
1057 asm_lookup_ltab(L,Lsym,Val),
1058 opcode(fork,X),
1059 b_ASPN2_cc(X,Val).
1060 asm_pass2_inst(fork_unify_struct_y(Op,(S,N),L),Csym,Lsym):-
1061 true :
1062 asm_lookup_ltab(L,Lsym,Val),
1063 asm_lookup_ctab(S,N,Csym,I),
1064 opcode(fork_unify_struct_y,X),
1065 b_ASPN4_cccc(X,Op,I,Val).
1066 asm_pass2_inst(fork_unify_list_y(Op,L),Csym,Lsym) :-
1067 true :
1068 asm_lookup_ltab(L,Lsym,Val),
1069 opcode(fork_unify_list_y,X),
1070 b_ASPN3_ccc(X,Op,Val).
1071 asm_pass2_inst(fork_unify_nil_y(Op,L),Csym,Lsym) :-
1072 true :
1073 asm_lookup_ltab(L,Lsym,Val),
1074 opcode(fork_unify_nil_y,X),
1075 b_ASPN3_ccc(X,Op,Val).
1076 asm_pass2_inst(fork_unify_atom_y(Op,C,L),Csym,Lsym):-
1077 true :
1078 asm_lookup_ctab(C,0,Csym,I),
1079 asm_lookup_ltab(L,Lsym,Val),
1080 opcode(fork_unify_atom_y,X),
1081 b_ASPN4_cccc(X,Op,I,Val).
1082 asm_pass2_inst(fork_unify_int_y(Op1,Op2,L),Csym,Lsym) :-
1083 true :
1084 asm_lookup_ltab(L,Lsym,Val),
1085 opcode(fork_unify_int_y,X),
1086 b_ASPN4_cccc(X,Op1,Op2,Val).
1087 asm_pass2_inst(fork_unify_uy_uy(Op1,Op2,L),Csym,Lsym) :-
1088 true :
1089 asm_lookup_ltab(L,Lsym,Val),
1090 opcode(fork_unify_uy_uy,X),
1091 b_ASPN4_cccc(X,Op1,Op2,Val).
1092
1093 asm_pass2_inst(fork_unicut_struct_y(Op,(S,N),L),Csym,Lsym):-
1094 true :
1095 asm_lookup_ltab(L,Lsym,Val),
1096 asm_lookup_ctab(S,N,Csym,I),
1097 opcode(fork_unicut_struct_y,X),
1098 b_ASPN4_cccc(X,Op,I,Val).
1099 asm_pass2_inst(fork_unicut_list_y(Op,L),Csym,Lsym) :-
1100 true :
1101 asm_lookup_ltab(L,Lsym,Val),
1102 opcode(fork_unicut_list_y,X),
1103 b_ASPN3_ccc(X,Op,Val).
1104 asm_pass2_inst(fork_unicut_nil_y(Op,L),Csym,Lsym) :-
1105 true :
1106 asm_lookup_ltab(L,Lsym,Val),
1107 opcode(fork_unicut_nil_y,X),
1108 b_ASPN3_ccc(X,Op,Val).
1109 asm_pass2_inst(fork_unicut_atom_y(Op,C,L),Csym,Lsym):-
1110 true :
1111 asm_lookup_ctab(C,0,Csym,I),
1112 asm_lookup_ltab(L,Lsym,Val),
1113 opcode(fork_unicut_atom_y,X),
1114 b_ASPN4_cccc(X,Op,I,Val).
1115 asm_pass2_inst(fork_unicut_int_y(Op1,Op2,L),Csym,Lsym) :-
1116 true :
1117 asm_lookup_ltab(L,Lsym,Val),
1118 opcode(fork_unicut_int_y,X),
1119 b_ASPN4_cccc(X,Op1,Op2,Val).
1120 asm_pass2_inst(fork_unicut_ux_uy(Op1,Op2,L),Csym,Lsym) :-
1121 true :
1122 asm_lookup_ltab(L,Lsym,Val),
1123 opcode(fork_unicut_ux_uy,X),
1124 b_ASPN4_cccc(X,Op1,Op2,Val).
1125 asm_pass2_inst(fork_unicut_uy_uy(Op1,Op2,L),Csym,Lsym) :-
1126 true :
1127 asm_lookup_ltab(L,Lsym,Val),
1128 opcode(fork_unicut_uy_uy,X),
1129 b_ASPN4_cccc(X,Op1,Op2,Val).
1130
1131 asm_pass2_inst(hash_x(Op,L),Csym,Lsym):-
1132 true :
1133 opcode(hash_x,X),
1134 asm_lookup_ltab(L,Lsym,Val),
1135 b_ASPN4_cccc(X,Op,0,0),b_ASPN_c(Val).
1136 asm_pass2_inst(hash_y(Op,L),Csym,Lsym):-
1137 true :
1138 opcode(hash_y,X),
1139 asm_lookup_ltab(L,Lsym,Val),
1140 b_ASPN4_cccc(X,Op,0,0),b_ASPN_c(Val).
1141 asm_pass2_inst(callv(Op1),Csym,Lsym):-
1142 true :
1143 opcode(callv,X),
1144 x_or_y(Op1,XY1),
1145 b_ASPN2_cc(X,XY1).
1146 asm_pass2_inst(executev(Op1),Csym,Lsym):-
1147 true :
1148 opcode(executev,X),
1149 x_or_y(Op1,XY1),
1150 b_ASPN2_cc(X,XY1).
1151 asm_pass2_inst(functor(Op1,Op2,Op3),Csym,Lsym):-
1152 true :
1153 opcode(functor,X),
1154 x_or_y(Op1,XY1),
1155 x_or_y(Op2,XY2),
1156 x_or_y(Op3,XY3),
1157 b_ASPN4_cccc(X,XY1,XY2,XY3).
1158 asm_pass2_inst(func_arity(Op1,Op2),Csym,Lsym):-
1159 true :
1160 opcode(func_arity,X),
1161 x_or_y(Op1,XY1),
1162 x_or_y(Op2,XY2),
1163 b_ASPN3_ccc(X,XY1,XY2).
1164 asm_pass2_inst(arg0(Op1,Op2,Op3),Csym,Lsym):-
1165 integer(Op1) :
1166 opcode(arg0,X),
1167 x_or_y(Op2,XY2),
1168 x_or_y(Op3,XY3),
1169 b_ASPN4_cccc(X,Op1,XY2,XY3).
1170 asm_pass2_inst(arg(Op1,Op2,Op3),Csym,Lsym):-
1171 true :
1172 opcode(arg,X),
1173 x_or_y(Op1,XY1),
1174 x_or_y(Op2,XY2),
1175 x_or_y(Op3,XY3),
1176 b_ASPN4_cccc(X,XY1,XY2,XY3).
1177 asm_pass2_inst(setarg0(Op1,Op2,Op3),Csym,Lsym):-
1178 integer(Op1) :
1179 opcode(setarg0,X),
1180 x_or_y(Op2,XY2),
1181 x_or_y(Op3,XY3),
1182 b_ASPN4_cccc(X,Op1,XY2,XY3).
1183 asm_pass2_inst(setarg(Op1,Op2,Op3),Csym,Lsym):-
1184 true :
1185 opcode(setarg,X),
1186 x_or_y(Op1,XY1),
1187 x_or_y(Op2,XY2),
1188 x_or_y(Op3,XY3),
1189 b_ASPN4_cccc(X,XY1,XY2,XY3).
1190 asm_pass2_inst(builtin0(N,L),Csym,Lsym):-
1191 true :
1192 asm_lookup_ltab(L,Lsym,Val),
1193 opcode(builtin0,X),
1194 b_ASPN3_ccc(X,N,Val).
1195 asm_pass2_inst(builtin1(N,L,Op1),Csym,Lsym):-
1196 true :
1197 asm_lookup_ltab(L,Lsym,Val),
1198 opcode(builtin1,X),
1199 x_or_y(Op1,XY1),
1200 b_ASPN4_cccc(X,N,Val,XY1).
1201 asm_pass2_inst(builtin2(N,L,Op1,Op2),Csym,Lsym):-
1202 true :
1203 asm_lookup_ltab(L,Lsym,Val),
1204 opcode(builtin2,X),
1205 x_or_y(Op1,XY1),
1206 x_or_y(Op2,XY2),
1207 b_ASPN4_cccc(X,N,Val,XY1),b_ASPN_c(XY2).
1208 asm_pass2_inst(builtin3(N,L,Op1,Op2,Op3),Csym,Lsym):-
1209 true :
1210 asm_lookup_ltab(L,Lsym,Val),
1211 opcode(builtin3,X),
1212 x_or_y(Op1,XY1),
1213 x_or_y(Op2,XY2),
1214 x_or_y(Op3,XY3),
1215 b_ASPN4_cccc(X,N,Val,XY1),b_ASPN2_cc(XY2,XY3).
1216 asm_pass2_inst(builtin4(N,L,Op1,Op2,Op3,Op4),Csym,Lsym):-
1217 true :
1218 asm_lookup_ltab(L,Lsym,Val),
1219 opcode(builtin4,X),
1220 x_or_y(Op1,XY1),
1221 x_or_y(Op2,XY2),
1222 x_or_y(Op3,XY3),
1223 x_or_y(Op4,XY4),
1224 b_ASPN4_cccc(X,N,Val,XY1),b_ASPN3_ccc(XY2,XY3,XY4).
1225 asm_pass2_inst(getbreg(Op1),Csym,Lsym):-
1226 true :
1227 opcode(getbreg,X),
1228 x_or_y(Op1,XY1),
1229 b_ASPN2_cc(X,XY1).
1230 asm_pass2_inst(getpbreg(Op1),Csym,Lsym):-
1231 true :
1232 opcode(getpbreg,X),
1233 x_or_y(Op1,XY1),
1234 b_ASPN2_cc(X,XY1).
1235 asm_pass2_inst(putbreg(Op1),Csym,Lsym):-
1236 true :
1237 opcode(putbreg,X),
1238 x_or_y(Op1,XY1),
1239 b_ASPN2_cc(X,XY1).
1240 asm_pass2_inst(gethtreg(y(X1),y(X2)),Csym,Lsym):-
1241 true :
1242 opcode(gethtreg,X),
1243 b_ASPN3_ccc(X,X1,X2).
1244 asm_pass2_inst(puthtreg(y(X1),y(X2)),Csym,Lsym):-
1245 true :
1246 opcode(puthtreg,X),
1247 b_ASPN3_ccc(X,X1,X2).
1248 asm_pass2_inst(delay((S,N),L),Csym,Lsym) :-
1249 true :
1250 asm_lookup_ctab(S,N,Csym,I),
1251 asm_lookup_ltab(L,Lsym,Val),
1252 opcode(delay,X),
1253 b_ASPN3_ccc(X,I,Val).
1254 asm_pass2_inst(susp_var_delay(Op,(S,N),L1,L2),Csym,Lsym) :-
1255 true :
1256 asm_lookup_ctab(S,N,Csym,I),
1257 asm_lookup_ltab(L1,Lsym,Val1),
1258 asm_lookup_ltab(L2,Lsym,Val2),
1259 opcode(susp_var_delay,X),
1260 b_ASPN4_cccc(X,Op,I,Val1),
1261 b_ASPN_c(Val2).
1262 asm_pass2_inst(jmpn_dvar_y(Op,L),Csym,Lsym) :-
1263 true :
1264 asm_lookup_ltab(L,Lsym,Val),
1265 opcode(jmpn_dvar_y,X),
1266 b_ASPN3_ccc(X,Op,Val).
1267 asm_pass2_inst(susp_var2_delay(Op,(S,N),L1,L2),Csym,Lsym) :-
1268 true :
1269 asm_lookup_ctab(S,N,Csym,I),
1270 asm_lookup_ltab(L1,Lsym,Val1),
1271 asm_lookup_ltab(L2,Lsym,Val2),
1272 opcode(susp_var2_delay,X),
1273 b_ASPN4_cccc(X,Op,I,Val1),
1274 b_ASPN_c(Val2).
1275 asm_pass2_inst(Inst,Csym,Lsym):-
1276 functor(Inst,F,N),
1277 opcode(F,X) : b_ASPN_c(X), asm_pass2_inst_op(Inst,0,N).
1278 asm_pass2_inst(Inst,Csym,Lsym):-
1279 true :
1280 cmp_error(['error in asm pass2 :',Inst,'is not defined']).
1281
1282 asm_pass2_inst_op(Inst,N0,N1):-
1283 N0=:=N1 : true.
1284 asm_pass2_inst_op(Inst,N0,Nn):-
1285 true :
1286 N1 is N0+1,
1287 arg(N1,Inst,Op),
1288 b_ASPN_c(Op),
1289 asm_pass2_inst_op(Inst,N1,Nn).
1290
1291 asm_magic(N) :-
1292 true :
1293 asm_putnum(17,1),
1294 asm_putnum(18,1),
1295 asm_putnum(19,1),
1296 asm_putnum(N,1).
1297
1298 asm_index_inst(pred(_,_,_,_),Size):-
1299 true : Size=16.
1300 asm_index_inst(arglabel(i,_,_),N) :-
1301 true :
1302 N:=9.
1303 asm_index_inst(arglabel(c,_,_),N) :-
1304 true :
1305 N:=9.
1306 asm_index_inst(arglabel(s,_,_),N) :-
1307 true :
1308 N:=9.
1309
1310 asm_symbol(Tab):-var(Tab) : true.
1311 asm_symbol([sym(Pred,Arity,Val,_)|Symtab]) :-
1312 true :
1313 b_ASPN_c(Val),
1314 asm_putnum(Arity,1),
1315 b_GET_LENGTH_cf(Pred,L),
1316 asm_putnum(L,1),
1317 writename(Pred),
1318 asm_symbol(Symtab).
1319
1320 /* putnum(Number, Length) will write Number as a binary number
1321 which will be Length bytes long */
1322 /*
1323 b_ASPN2_cc(X,Y):-b_ASPN_c(X),b_ASPN_c(Y).
1324 b_ASPN3_ccc(X,Y,U):-b_ASPN_c(X),b_ASPN_c(Y),b_ASPN_c(U).
1325 b_ASPN4_cccc(X,Y,U,V):-b_ASPN_c(X),b_ASPN_c(Y),b_ASPN_c(U),b_ASPN_c(V).
1326 */
1327 /*
1328 aspn(X):-
1329 true :
1330 write((X,4)),nl.
1331
1332 asm_putnum(X,Bytes):-
1333 true :
1334 write((X,Bytes)),nl.
1335 */
1336
1337 /*
1338 aspn(Num):-
1339 true :
1340 asm_putnum(Num,4).
1341 */
1342
1343 asm_putnum(Num,NBytes) :-
1344 NBytes > 1 :
1345 Byte is Num /\ 255,
1346 Rest is Num >> 8,
1347 N is NBytes - 1,
1348 asm_putnum(Rest,N),
1349 put(Byte).
1350 asm_putnum(Num,NBytes):-
1351 % Num < 256 :
1352 true :
1353 put(Num).
1354
1355 asm_mark_eot:-
1356 true :
1357 opcode(endfile,X),
1358 b_ASPN2_cc(X,0).
1359
1360 /* local utilities */
1361
1362 sym_member1(Sym,Csym):-
1363 sym(F,N,Val,I)<=Sym :
1364 asm_hash_value(F,HashVal),
1365 Index is (HashVal+N) mod 255 + 1,
1366 arg(Index,Csym,L),
1367 sym_member1(F,N,Sym,L).
1368
1369 sym_member1(F,N,Sym,List):-
1370 var(List) :
1371 next_sym_no(I),
1372 arg(4,Sym,I),
1373 List:=[Sym|_].
1374 sym_member1(F,N,Sym,[sym(F,N,Val2,I)|List]):-
1375 true :
1376 Sym=sym(F,N,Val2,I).
1377 sym_member1(F,N,Sym,[X1|List]):-
1378 true :
1379 sym_member1(F,N,Sym,List).
1380
1381
1382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1383
1384 lab_member1(Lab,Lsym):-
1385 lab(X,Val)<=Lab :
1386 asm_hash_value(X,HashVal),
1387 Index is HashVal mod 255 + 1,
1388 % write(user,Index),nl(user),
1389 arg(Index,Lsym,L),
1390 lab_member1(X,Lab,L).
1391
1392 lab_member1(X,Lab,List):-
1393 var(List) :
1394 List:=[Lab|_].
1395 lab_member1(X,Lab,[lab(X,Val2)|List]):-
1396 true :
1397 Lab=lab(X,Val2).
1398 lab_member1(X,Lab,[_|List]):-
1399 true :
1400 lab_member1(X,Lab,List).
1401
1402
1403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1404
1405 asm_lookup_ltab(Lab,Lsym,Val1):-
1406 true :
1407 asm_hash_value(Lab,HashVal),
1408 Index is HashVal mod 255 + 1,
1409 arg(Index,Lsym,L),
1410 asm_lookup_ltab1(Lab,L,Val1).
1411
1412 asm_lookup_ltab1(Lab,Var,Val1):-
1413 var(Var) : fail.
1414 asm_lookup_ltab1(Lab,[lab(Lab,Val)|_],Val1):-
1415 true :
1416 Val1=Val.
1417 asm_lookup_ltab1(Lab,[_|Tab],Val):-
1418 true :
1419 asm_lookup_ltab1(Lab,Tab,Val).
1420
1421
1422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1423
1424 asm_lookup_ctab(F,N,Csym,I):-
1425 true :
1426 asm_hash_value(F,HashVal),
1427 Index is (HashVal+N) mod 255 + 1,
1428 arg(Index,Csym,L),
1429 asm_lookup_ctab1(F,N,L,I).
1430
1431 asm_lookup_ctab1(F,N,[sym(F,N,Val,I)|L],I1):-
1432 true :
1433 I1=I.
1434 asm_lookup_ctab1(F,N,[_|L],I):-
1435 true :
1436 asm_lookup_ctab1(F,N,L,I).
1437
1438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439 asm_rearange_csym(Csym,N,LCsym0,LCsym):-
1440 N<1 :
1441 LCsym=LCsym0.
1442 asm_rearange_csym(Csym,N,LCsym0,LCsym):-
1443 true :
1444 arg(N,Csym,L),
1445 asm_merge(L,LCsym0,LCsym1),
1446 N1 is N-1,
1447 asm_rearange_csym(Csym,N1,LCsym1,LCsym).
1448
1449 asm_merge(L1,L2,L3):-
1450 var(L1) :
1451 L3=L2.
1452 asm_merge(L1,L2,L3):-
1453 var(L2) :
1454 L3=L1.
1455 asm_merge(L1,L2,L3):-
1456 [Sym1|T1]<=L1,
1457 [Sym2|T2]<=L2,
1458 sym(F1,N1,Val1,I1)<=Sym1,
1459 sym(F2,N2,Val2,I2)<=Sym2,
1460 I1 < I2 :
1461 L3:=[Sym1|L4],
1462 asm_merge(T1,L2,L4).
1463 asm_merge(L1,L2,L3):-
1464 [Sym1|T1]<=L1,
1465 [Sym2|T2]<=L2 :
1466 L3:=[Sym2|L4],
1467 asm_merge(L1,T2,L4).
1468
1469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1470 /*
1471 asm_hash_value(F,N,HashVal):-
1472 true :
1473 name(F,L),
1474 asm_sum_list(L,0,Sum),
1475 HashVal is Sum+N.
1476
1477 asm_hash_value((F,N,No),HashVal):-
1478 true :
1479 name(F,L),
1480 asm_sum_list(L,0,Sum),
1481 HashVal is Sum+N+No.
1482 asm_hash_value((F,N),HashVal):-
1483 true :
1484 name(F,L),
1485 asm_sum_list(L,0,Sum),
1486 HashVal is Sum+N.
1487
1488 asm_sum_list([],Sum0,Sum):-
1489 true :
1490 Sum=Sum0.
1491 asm_sum_list([X|Xs],Sum0,Sum):-
1492 true :
1493 Sum1 is Sum0+X,
1494 asm_sum_list(Xs,Sum1,Sum).
1495 */
1496 next_sym_no(I):-
1497 true :
1498 global_get('$sym_no',0,I),
1499 I1 is I+1,
1500 global_set('$sym_no',0,I1).
1501
1502 x_or_y(vx(X),Code):- % xv
1503 true :
1504 Code is X<<3.
1505 x_or_y(x(X),Code):- % ux
1506 true :
1507 Code is X<<3+1.
1508 x_or_y(vy(Y),Code):- %vy
1509 true :
1510 Code is (Y<<3) \/ 2'11.
1511 x_or_y(y(Y),Code):-
1512 true :
1513 Code is (Y<<3) \/ 2'111.
1514 x_or_y(Op,Code):-
1515 true :
1516 Code is (Op<<2) \/ 2'10.
1517
1518 :-mode opcode(c,f).
1519 opcode(noop,0).
1520 opcode(jmp,1).
1521 opcode(djmp,2).
1522 opcode(jmpn_eq_struct_x,3).
1523 opcode(jmpn_eq_struct_y,4).
1524 opcode(jmpn_eq_atom_x,5).
1525 opcode(jmpn_eq_atom_y,6).
1526 opcode(jmpn_nil_x,7).
1527 opcode(jmpn_nil_y,8).
1528 opcode(switch_list_x,9).
1529 opcode(switch_list_y,10).
1530 opcode(switch_list_yxx,11).
1531 opcode(switch_list_yxy,12).
1532 opcode(switch_list_yyx,13).
1533 opcode(switch_list_yyy,14).
1534 opcode(jmpn_eq_int_x,15).
1535 opcode(jmpn_eq_int_y,16).
1536 opcode(jmpn_eql,17).
1537 opcode(jmp_eql,18).
1538 opcode(jmp_eql_yy,19).
1539 opcode(jmpn_gt,20).
1540 opcode(jmpn_gt_yy,21).
1541 opcode(jmpn_ge,22).
1542 opcode(jmpn_ge_yy,23).
1543 opcode(jmpn_id,24).
1544 opcode(jmp_id,25).
1545 opcode(jmpn_var_x,26).
1546 opcode(jmpn_var_y,27).
1547 opcode(jmp_var_x,28).
1548 opcode(jmp_var_y,29).
1549 opcode(jmpn_atom_x,30).
1550 opcode(jmpn_atom_y,31).
1551 opcode(jmpn_atomic_x,32).
1552 opcode(jmpn_atomic_y,33).
1553 opcode(jmpn_num_x,34).
1554 opcode(jmpn_num_y,35).
1555 opcode(jmpn_float_x,36).
1556 opcode(jmpn_float_y,37).
1557 opcode(jmpn_int_x,38).
1558 opcode(jmpn_int_y,39).
1559 opcode(hash_jmpn_nil,40).
1560 opcode(hash_jmpn_list,41).
1561 opcode(hash_jmpn_int,42).
1562 opcode(hash_jmpn_atom,43).
1563 opcode(hash_jmpn_struct,44).
1564 opcode(hash_jmpn_struct_x,45).
1565 opcode(hash_jmpn_struct_y,46).
1566 opcode(hash_jmpn_struct_xx,47).
1567 opcode(hash_jmpn_struct_xy,48).
1568 opcode(hash_jmpn_struct_yx,49).
1569 opcode(hash_jmpn_struct_yy,50).
1570 opcode(unify_struct_x,51).
1571 opcode(unify_struct_y,52).
1572 opcode(unify_list_x,53).
1573 opcode(unify_list_y,54).
1574 opcode(unify_nil_x,55).
1575 opcode(unify_nil_y,56).
1576 opcode(unify_atom_x,57).
1577 opcode(unify_int_x,58).
1578 opcode(unify_atom_y,59).
1579 opcode(unify_int_y,60).
1580 opcode(unify_ux_ux,61).
1581 opcode(unify_ux_uy,62).
1582 opcode(unify_uy_uy,63).
1583 opcode(unify_cons_x,64).
1584 opcode(unify_cons_y,65).
1585 opcode(fork_unify_struct_y,66).
1586 opcode(fork_unify_list_y,67).
1587 opcode(fork_unify_nil_y,68).
1588 opcode(fork_unify_atom_y,69).
1589 opcode(fork_unify_int_y,70).
1590 opcode(fork_unify_uy_uy,71).
1591 opcode(fork_unicut_struct_y,72).
1592 opcode(fork_unicut_list_y,73).
1593 opcode(fork_unicut_nil_y,74).
1594 opcode(fork_unicut_atom_y,75).
1595 opcode(fork_unicut_int_y,76).
1596 opcode(fork_unicut_uy_uy,77).
1597 opcode(unify0_struct_y,78).
1598 opcode(unify0_list_y,79).
1599 opcode(unify0_nil_y,80).
1600 opcode(unify0_atom_y,81).
1601 opcode(unify0_int_y,82).
1602 opcode(unify0_uy_uy,83).
1603 opcode(unicut_struct_y,84).
1604 opcode(unicut_list_y,85).
1605 opcode(unicut_nil_y,86).
1606 opcode(unicut_atom_y,87).
1607 opcode(unicut_int_y,88).
1608 opcode(unicut_uy_uy,89).
1609 opcode(unicut,90).
1610 opcode(unify_arg_nil,91).
1611 opcode(unify_arg_atom,92).
1612 opcode(unify_arg_int,93).
1613 opcode(unify_arg_ux_ux,94).
1614 opcode(unify_arg_ux,95).
1615 opcode(unify_arg_ux_vx,96).
1616 opcode(unify_arg_ux_vy,97).
1617 opcode(unify_arg_uy_uy,98).
1618 opcode(unify_arg_uy,99).
1619 opcode(unify_arg_wy,100).
1620 opcode(unify_arg_vx_vx,101).
1621 opcode(unify_arg_vx,102).
1622 opcode(unify_arg_vy_vy,103).
1623 opcode(unify_arg_vy,104).
1624 opcode(unify_arg_list,105).
1625 opcode(unify_arg_struct,106).
1626 opcode(unify_arg_void_one,107).
1627 opcode(unify_arg_void,108).
1628 opcode(unify_arg_vx_vy,109).
1629 opcode(unify_arg_vx_ux,110).
1630 opcode(unify_arg_vx_uy,111).
1631 opcode(unify_arg_vy_vx,112).
1632 opcode(unify_arg_vy_ux,113).
1633 opcode(unify_arg_vy_uy,114).
1634 opcode(unify_arg_iii,115).
1635 opcode(move_struct_x,116).
1636 opcode(move_struct_y,117).
1637 opcode(move_list_x,118).
1638 opcode(move_list_y,119).
1639 opcode(move_nil_x,120).
1640 opcode(move_nil_y,121).
1641 opcode(move_atom_x,122).
1642 opcode(move_int_x,123).
1643 opcode(move_atom_y,124).
1644 opcode(move_int_y,125).
1645 opcode(move_x_ux,126).
1646 opcode(move_x_uy,127).
1647 opcode(move_y_ux,128).
1648 opcode(move_yy_yy_yy,129).
1649 opcode(move_yy_yy,130).
1650 opcode(move_y_uy,131).
1651 opcode(move_vx,132).
1652 opcode(move_vy,133).
1653 opcode(move_x_wy,134).
1654 opcode(move_yy_yw,135).
1655 opcode(move_y_wy,136).
1656 opcode(move_yw_yy,137).
1657 opcode(and,138).
1658 opcode(or,139).
1659 opcode(lshiftl,140).
1660 opcode(lshiftr,141).
1661 opcode(complement,142).
1662 opcode(add,143).
1663 opcode(add1_y,144).
1664 opcode(sub,145).
1665 opcode(sub1_y,146).
1666 opcode(mul,147).
1667 opcode(div,148).
1668 opcode(idiv,149).
1669 opcode(mod,150).
1670 opcode(para_struct,151).
1671 opcode(para_list,152).
1672 opcode(para_nil,153).
1673 opcode(para_atom,154).
1674 opcode(para_int,155).
1675 opcode(para_ux_ux_ux,156).
1676 opcode(para_ux_ux,157).
1677 opcode(para_ux,158).
1678 opcode(para_uy_uy_uy_uy,159).
1679 opcode(para_uy_uy_uy,160).
1680 opcode(para_uy_uy,161).
1681 opcode(para_uy,162).
1682 opcode(para_vx,163).
1683 opcode(para_vy_vy,164).
1684 opcode(para_vy,165).
1685 opcode(para_void_one,166).
1686 opcode(para_void,167).
1687 opcode(para_vy_ux,168).
1688 opcode(para_vy_uy,169).
1689 opcode(para_ux_vy,170).
1690 opcode(para_ux_ux_uy,171).
1691 opcode(para_ux_uy,172).
1692 opcode(para_ux_uy_uy,173).
1693 opcode(para_uy_vy,174).
1694 opcode(para_ux_uy_ux,175).
1695 opcode(para_uy_ux,176).
1696 opcode(para_uy_ux_ux,177).
1697 opcode(para_uy_ux_uy,178).
1698 opcode(para_uy_uy_ux,179).
1699 opcode(call,180).
1700 opcode(call_d,181).
1701 opcode(callv,182).
1702 opcode(execute,183).
1703 opcode(executev,184).
1704 opcode(return_a,185).
1705 opcode(return_b,186).
1706 opcode(jmpn_det,187).
1707 opcode(save_ht_jmp,188).
1708 opcode(allocate_flat,189).
1709 opcode(allocate_nonflat,190).
1710 opcode(allocate_nondet,191).
1711 opcode(fail,192).
1712 opcode(fail0,193).
1713 opcode(fork,194).
1714 opcode(commit,195).
1715 opcode(cut,196).
1716 opcode(cut_fail,197).
1717 opcode(cut_return,198).
1718 opcode(save_b,199).
1719 opcode(getbreg,200).
1720 opcode(putbreg,201).
1721 opcode(getpbreg,202).
1722 opcode(hash_x,203).
1723 opcode(hash_y,204).
1724 opcode(arg,205).
1725 opcode(arg0,206).
1726 opcode(setarg,207).
1727 opcode(setarg0,208).
1728 opcode(functor,209).
1729 opcode(func_arity,210).
1730 opcode(get_ar_cps,211).
1731 opcode(put_ar_cps,212).
1732 opcode(move_ar_cps,213).
1733 opcode(jmpn_det_get_ar_cps,214).
1734 opcode(builtin0,215).
1735 opcode(builtin1,216).
1736 opcode(builtin2,217).
1737 opcode(builtin3,218).
1738 opcode(builtin4,219).
1739 opcode(allocate_susp,220).
1740 opcode(susp_var_x,221).
1741 opcode(susp_var_y,222).
1742 opcode(delay,223).
1743 opcode(susp_var_delay,224).
1744 opcode(end_delay,225).
1745 opcode(nondet,226).
1746 opcode(jmp_susp,227).
1747 opcode(jmpn_dvar_y,228).
1748 opcode(susp_var2_delay,229).
1749 opcode(domain_set_false_yy,230).
1750 opcode(domain_set_false_yx,231).
1751 opcode(halt,232).
1752 opcode(endfile,233).
1753 opcode(tabsize,234).
1754
1755 /*
1756 opcode(X,N):-
1757 true :
1758 cmp_error(['no this instruction : ',X]).
1759 */
1760 output_mess(Mess):-
1761 true :
1762 telling(X),
1763 tell(user),
1764 write(Mess),
1765 nl,
1766 tell(X).
1767
1768 is_unify_arg_inst(Inst):-
1769 true :
1770 functor(Inst,F,N),
1771 opcode(F,Code),
1772 Code>=91,Code=<115.
1773
+0
-397
bench/boyer.pl less more
0 % generated: 20 November 1989
1 % option(s):
2 %
3 % boyer
4 %
5 % Evan Tick (from Lisp version by R. P. Gabriel)
6 %
7 % November 1985
8 %
9 % prove arithmetic theorem
10
11 go:-
12 statistics(runtime,[_,_]),
13 wff(Wff),
14 rewrite(Wff,NewWff),
15 tautology(NewWff,[],[]),
16 statistics(runtime,[_,T]),
17 write('execution time is '),write(T), write(' milliseconds').
18
19 top :-
20 wff(Wff),
21 rewrite(Wff,NewWff),
22 tautology(NewWff,[],[]).
23
24 wff(implies(and(implies(X,Y),
25 and(implies(Y,Z),
26 and(implies(Z,U),
27 implies(U,W)))),
28 implies(X,W))) :-
29 X = f(myplus(myplus(a,b),myplus(c,zero))),
30 Y = f(times(times(a,b),myplus(c,d))),
31 Z = f(reverse(append(append(a,b),[]))),
32 U = equal(myplus(a,b),boyer_difference(x,y)),
33 W = lessp(remainder(a,b),boyer_member(a,length(b))).
34
35 tautology(Wff) :-
36 % write('rewriting...'),nl,
37 rewrite(Wff,NewWff),
38 % write('proving...'),nl,
39 tautology(NewWff,[],[]).
40
41 tautology(Wff,Tlist,Flist) :-
42 (truep(Wff,Tlist) -> true
43 ;falsep(Wff,Flist) -> fail
44 ;Wff = if(If,Then,Else) ->
45 (truep(If,Tlist) -> tautology(Then,Tlist,Flist)
46 ;falsep(If,Flist) -> tautology(Else,Tlist,Flist)
47 ;tautology(Then,[If|Tlist],Flist), % both must hold
48 tautology(Else,Tlist,[If|Flist])
49 )
50 ),!.
51
52
53 rewrite(Atom,Atom) :-
54 atomic(Atom),!.
55 rewrite(Old,New) :-
56 functor(Old,F,N),
57 functor(Mid,F,N),
58 rewrite_args(N,Old,Mid),
59 ( equal(Mid,Next), % should be ->, but is compiler smart
60 rewrite(Next,New) % enough to generate cut for -> ?
61 ; New=Mid
62 ),!.
63
64 rewrite_args(0,_,_) :- !.
65 rewrite_args(N,Old,Mid) :-
66 arg(N,Old,OldArg),
67 arg(N,Mid,MidArg),
68 rewrite(OldArg,MidArg),
69 N1 is N-1,
70 rewrite_args(N1,Old,Mid).
71
72 truep(t,_) :- !.
73 truep(Wff,Tlist) :- boyer_member(Wff,Tlist).
74
75 falsep(f,_) :- !.
76 falsep(Wff,Flist) :- boyer_member(Wff,Flist).
77
78 boyer_member(X,[X|_]) :- !.
79 boyer_member(X,[_|T]) :- boyer_member(X,T).
80
81
82 equal( and(P,Q),
83 if(P,if(Q,t,f),f)
84 ).
85 equal( append(append(X,Y),Z),
86 append(X,append(Y,Z))
87 ).
88 equal( assignment(X,append(A,B)),
89 if(assignedp(X,A),
90 assignment(X,A),
91 assignment(X,B))
92 ).
93 equal( assume_false(Var,Alist),
94 cons(cons(Var,f),Alist)
95 ).
96 equal( assume_true(Var,Alist),
97 cons(cons(Var,t),Alist)
98 ).
99 equal( boolean(X),
100 or(equal(X,t),equal(X,f))
101 ).
102 equal( car(gopher(X)),
103 if(listp(X),
104 car(flatten(X)),
105 zero)
106 ).
107 equal( compile(Form),
108 reverse(codegen(optimize(Form),[]))
109 ).
110 equal( count_list(Z,sort_lp(X,Y)),
111 myplus(count_list(Z,X),
112 count_list(Z,Y))
113 ).
114 equal( countps_(L,Pred),
115 countps_loop(L,Pred,zero)
116 ).
117 equal( boyer_difference(A,B),
118 C
119 ) :- boyer_difference(A,B,C).
120 equal( divides(X,Y),
121 zerop(remainder(Y,X))
122 ).
123 equal( dsort(X),
124 sort2(X)
125 ).
126 equal( eqp(X,Y),
127 equal(fix(X),fix(Y))
128 ).
129 equal( equal(A,B),
130 C
131 ) :- eq(A,B,C).
132 equal( even1(X),
133 if(zerop(X),t,odd(decr(X)))
134 ).
135 equal( exec(append(X,Y),Pds,Envrn),
136 exec(Y,exec(X,Pds,Envrn),Envrn)
137 ).
138 equal( exp(A,B),
139 C
140 ) :- exp(A,B,C).
141 equal( fact_(I),
142 fact_loop(I,1)
143 ).
144 equal( falsify(X),
145 falsify1(normalize(X),[])
146 ).
147 equal( fix(X),
148 if(numberp(X),X,zero)
149 ).
150 equal( flatten(cdr(gopher(X))),
151 if(listp(X),
152 cdr(flatten(X)),
153 cons(zero,[]))
154 ).
155 equal( gcd(A,B),
156 C
157 ) :- gcd(A,B,C).
158 equal( get(J,set(I,Val,Mem)),
159 if(eqp(J,I),Val,get(J,Mem))
160 ).
161 equal( greatereqp(X,Y),
162 not(lessp(X,Y))
163 ).
164 equal( greatereqpr(X,Y),
165 not(lessp(X,Y))
166 ).
167 equal( greaterp(X,Y),
168 lessp(Y,X)
169 ).
170 equal( if(if(A,B,C),D,E),
171 if(A,if(B,D,E),if(C,D,E))
172 ).
173 equal( iff(X,Y),
174 and(implies(X,Y),implies(Y,X))
175 ).
176 equal( implies(P,Q),
177 if(P,if(Q,t,f),t)
178 ).
179 equal( last(append(A,B)),
180 if(listp(B),
181 last(B),
182 if(listp(A),
183 cons(car(last(A))),
184 B))
185 ).
186 equal( length(A),
187 B
188 ) :- mylength(A,B).
189 equal( lesseqp(X,Y),
190 not(lessp(Y,X))
191 ).
192 equal( lessp(A,B),
193 C
194 ) :- lessp(A,B,C).
195 equal( listp(gopher(X)),
196 listp(X)
197 ).
198 equal( mc_flatten(X,Y),
199 append(flatten(X),Y)
200 ).
201 equal( meaning(A,B),
202 C
203 ) :- meaning(A,B,C).
204 equal( boyer_member(A,B),
205 C
206 ) :- myboyer_member(A,B,C).
207 equal( not(P),
208 if(P,f,t)
209 ).
210 equal( nth(A,B),
211 C
212 ) :- nth(A,B,C).
213 equal( numberp(greatest_factor(X,Y)),
214 not(and(or(zerop(Y),equal(Y,1)),
215 not(numberp(X))))
216 ).
217 equal( or(P,Q),
218 if(P,t,if(Q,t,f),f)
219 ).
220 equal( myplus(A,B),
221 C
222 ) :- myplus(A,B,C).
223 equal( power_eval(A,B),
224 C
225 ) :- power_eval(A,B,C).
226 equal( prime(X),
227 and(not(zerop(X)),
228 and(not(equal(X,add1(zero))),
229 prime1(X,decr(X))))
230 ).
231 equal( prime_list(append(X,Y)),
232 and(prime_list(X),prime_list(Y))
233 ).
234 equal( quotient(A,B),
235 C
236 ) :- quotient(A,B,C).
237 equal( remainder(A,B),
238 C
239 ) :- remainder(A,B,C).
240 equal( reverse_(X),
241 reverse_loop(X,[])
242 ).
243 equal( reverse(append(A,B)),
244 append(reverse(B),reverse(A))
245 ).
246 equal( reverse_loop(A,B),
247 C
248 ) :- reverse_loop(A,B,C).
249 equal( samefringe(X,Y),
250 equal(flatten(X),flatten(Y))
251 ).
252 equal( sigma(zero,I),
253 quotient(times(I,add1(I)),2)
254 ).
255 equal( sort2(delete(X,L)),
256 delete(X,sort2(L))
257 ).
258 equal( tautology_checker(X),
259 tautologyp(normalize(X),[])
260 ).
261 equal( times(A,B),
262 C
263 ) :- times(A,B,C).
264 equal( times_list(append(X,Y)),
265 times(times_list(X),times_list(Y))
266 ).
267 equal( value(normalize(X),A),
268 value(X,A)
269 ).
270 equal( zerop(X),
271 or(equal(X,zero),not(numberp(X)))
272 ).
273
274 boyer_difference(X, X, zero) :- !.
275 boyer_difference(myplus(X,Y), X, fix(Y)) :- !.
276 boyer_difference(myplus(Y,X), X, fix(Y)) :- !.
277 boyer_difference(myplus(X,Y), myplus(X,Z), boyer_difference(Y,Z)) :- !.
278 boyer_difference(myplus(B,myplus(A,C)), A, myplus(B,C)) :- !.
279 boyer_difference(add1(myplus(Y,Z)), Z, add1(Y)) :- !.
280 boyer_difference(add1(add1(X)), 2, fix(X)).
281
282 eq(myplus(A,B), zero, and(zerop(A),zerop(B))) :- !.
283 eq(myplus(A,B), myplus(A,C), equal(fix(B),fix(C))) :- !.
284 eq(zero, boyer_difference(X,Y),not(lessp(Y,X))) :- !.
285 eq(X, boyer_difference(X,Y),and(numberp(X),
286 and(or(equal(X,zero),
287 zerop(Y))))) :- !.
288 eq(times(X,Y), zero, or(zerop(X),zerop(Y))) :- !.
289 eq(append(A,B), append(A,C), equal(B,C)) :- !.
290 eq(flatten(X), cons(Y,[]), and(nlistp(X),equal(X,Y))) :- !.
291 eq(greatest_factor(X,Y),zero, and(or(zerop(Y),equal(Y,1)),
292 equal(X,zero))) :- !.
293 eq(greatest_factor(X,_),1, equal(X,1)) :- !.
294 eq(Z, times(W,Z), and(numberp(Z),
295 or(equal(Z,zero),
296 equal(W,1)))) :- !.
297 eq(X, times(X,Y), or(equal(X,zero),
298 and(numberp(X),equal(Y,1)))) :- !.
299 eq(times(A,B), 1, and(not(equal(A,zero)),
300 and(not(equal(B,zero)),
301 and(numberp(A),
302 and(numberp(B),
303 and(equal(decr(A),zero),
304 equal(decr(B),zero))))))) :- !.
305 eq(boyer_difference(X,Y), boyer_difference(Z,Y),if(lessp(X,Y),
306 not(lessp(Y,Z)),
307 if(lessp(Z,Y),
308 not(lessp(Y,X)),
309 equal(fix(X),fix(Z))))) :- !.
310 eq(lessp(X,Y), Z, if(lessp(X,Y),
311 equal(t,Z),
312 equal(f,Z))).
313
314 exp(I, myplus(J,K), times(exp(I,J),exp(I,K))) :- !.
315 exp(I, times(J,K), exp(exp(I,J),K)).
316
317 gcd(X, Y, gcd(Y,X)) :- !.
318 gcd(times(X,Z), times(Y,Z), times(Z,gcd(X,Y))).
319
320 mylength(reverse(X),length(X)).
321 mylength(cons(_,cons(_,cons(_,cons(_,cons(_,cons(_,X7)))))),
322 myplus(6,length(X7))).
323
324 lessp(remainder(_,Y), Y, not(zerop(Y))) :- !.
325 lessp(quotient(I,J), I, and(not(zerop(I)),
326 or(zerop(J),
327 not(equal(J,1))))) :- !.
328 lessp(remainder(X,Y), X, and(not(zerop(Y)),
329 and(not(zerop(X)),
330 not(lessp(X,Y))))) :- !.
331 lessp(myplus(X,Y), myplus(X,Z), lessp(Y,Z)) :- !.
332 lessp(times(X,Z), times(Y,Z), and(not(zerop(Z)),
333 lessp(X,Y))) :- !.
334 lessp(Y, myplus(X,Y), not(zerop(X))) :- !.
335 lessp(length(delete(X,L)), length(L), boyer_member(X,L)).
336
337 meaning(plus_tree(append(X,Y)),A,
338 myplus(meaning(plus_tree(X),A),
339 meaning(plus_tree(Y),A))) :- !.
340 meaning(plus_tree(plus_fringe(X)),A,
341 fix(meaning(X,A))) :- !.
342 meaning(plus_tree(delete(X,Y)),A,
343 if(boyer_member(X,Y),
344 boyer_difference(meaning(plus_tree(Y),A),
345 meaning(X,A)),
346 meaning(plus_tree(Y),A))).
347
348 myboyer_member(X,append(A,B),or(boyer_member(X,A),boyer_member(X,B))) :- !.
349 myboyer_member(X,reverse(Y),boyer_member(X,Y)) :- !.
350 myboyer_member(A,intersect(B,C),and(boyer_member(A,B),boyer_member(A,C))).
351
352 nth(zero,_,zero).
353 nth([],I,if(zerop(I),[],zero)).
354 nth(append(A,B),I,append(nth(A,I),nth(B,boyer_difference(I,length(A))))).
355
356 myplus(myplus(X,Y),Z,
357 myplus(X,myplus(Y,Z))) :- !.
358 myplus(remainder(X,Y),
359 times(Y,quotient(X,Y)),
360 fix(X)) :- !.
361 myplus(X,add1(Y),
362 if(numberp(Y),
363 add1(myplus(X,Y)),
364 add1(X))).
365
366 power_eval(big_plus1(L,I,Base),Base,
367 myplus(power_eval(L,Base),I)) :- !.
368 power_eval(power_rep(I,Base),Base,
369 fix(I)) :- !.
370 power_eval(big_plus(X,Y,I,Base),Base,
371 myplus(I,myplus(power_eval(X,Base),
372 power_eval(Y,Base)))) :- !.
373 power_eval(big_plus(power_rep(I,Base),
374 power_rep(J,Base),
375 zero,
376 Base),
377 Base,
378 myplus(I,J)).
379
380 quotient(myplus(X,myplus(X,Y)),2,myplus(X,quotient(Y,2))).
381 quotient(times(Y,X),Y,if(zerop(Y),zero,fix(X))).
382
383 remainder(_, 1,zero) :- !.
384 remainder(X, X,zero) :- !.
385 remainder(times(_,Z),Z,zero) :- !.
386 remainder(times(Y,_),Y,zero).
387
388 reverse_loop(X,Y, append(reverse(X),Y)) :- !.
389 reverse_loop(X,[], reverse(X) ).
390
391 times(X, myplus(Y,Z), myplus(times(X,Y),times(X,Z)) ) :- !.
392 times(times(X,Y),Z, times(X,times(Y,Z)) ) :- !.
393 times(X, boyer_difference(C,W),boyer_difference(times(C,X),times(W,X))) :- !.
394 times(X, add1(Y), if(numberp(Y),
395 myplus(X,times(X,Y)),
396 fix(X)) ).
+0
-100
bench/browse.pl less more
0 % generated: 19 June 1990
1 % option(s):
2 %
3 % browse
4 %
5 % Tep Dobry (from Lisp version by R. P. Gabriel)
6 %
7 % (modified January 1987 by Herve' Touati)
8
9 top :-
10 init(100,10,4,
11 [[a,a,a,b,b,b,b,a,a,a,a,a,b,b,a,a,a],
12 [a,a,b,b,b,b,a,a,[a,a],[b,b]],
13 [a,a,a,b,[b,a],b,a,b,a]
14 ],
15 Symbols),
16 randomize(Symbols,RSymbols,21),!,
17 investigate(RSymbols,
18 [[star(SA),B,star(SB),B,a,star(SA),a,star(SB),star(SA)],
19 [star(SA),star(SB),star(SB),star(SA),[star(SA)],[star(SB)]],
20 [_,_,star(_),[b,a],star(_),_,_]
21 ]).
22
23
24 init(N,M,Npats,Ipats,Result) :- init(N,M,M,Npats,Ipats,Result).
25
26 init(0,_,_,_,_,_) :- !.
27 init(N,I,M,Npats,Ipats,[Symb|Rest]) :-
28 fill(I,[],L),
29 get_pats(Npats,Ipats,Ppats),
30 J is M - I,
31 fill(J,[pattern(Ppats)|L],Symb),
32 N1 is N - 1,
33 (I =:= 0 -> I1 is M; I1 is I - 1),
34 init(N1,I1,M,Npats,Ipats,Rest).
35
36 fill(0,L,L) :- !.
37 fill(N,L,[dummy([])|Rest]) :-
38 N1 is N - 1,
39 fill(N1,L,Rest).
40
41 randomize([],[],_) :- !.
42 randomize(In,[X|Out],Rand) :-
43 length(In,Lin),
44 Rand1 is (Rand * 17) mod 251,
45 N is Rand1 mod Lin,
46 split(N,In,X,In1),
47 randomize(In1,Out,Rand1).
48
49 split(0,[X|Xs],X,Xs) :- !.
50 split(N,[X|Xs],RemovedElt,[X|Ys]) :-
51 N1 is N - 1,
52 split(N1,Xs,RemovedElt,Ys).
53
54 investigate([],_) :- !.
55 investigate([U|Units],Patterns) :-
56 property(U,pattern,Data),
57 p_investigate(Data,Patterns),
58 investigate(Units,Patterns).
59
60 get_pats(Npats,Ipats,Result) :- get_pats(Npats,Ipats,Result,Ipats).
61
62 get_pats(0,_,[],_) :- !.
63 get_pats(N,[X|Xs],[X|Ys],Ipats) :-
64 N1 is N - 1,
65 get_pats(N1,Xs,Ys,Ipats).
66 get_pats(N,[],Ys,Ipats) :-
67 get_pats(N,Ipats,Ys,Ipats).
68
69 property([],_,_) :- fail. /* don't really need this */
70 property([Prop|_],P,Val) :-
71 functor(Prop,P,_),!,
72 arg(1,Prop,Val).
73 property([_|RProps],P,Val) :-
74 property(RProps,P,Val).
75
76 p_investigate([],_).
77 p_investigate([D|Data],Patterns) :-
78 p_match(Patterns,D),
79 p_investigate(Data,Patterns).
80
81 p_match([],_).
82 p_match([P|Patterns],D) :-
83 (match(D,P),fail; true),
84 p_match(Patterns,D).
85
86 match([],[]) :- !.
87 match([X|PRest],[Y|SRest]) :-
88 var(Y),!,X = Y,
89 match(PRest,SRest).
90 match(List,[Y|Rest]) :-
91 nonvar(Y),Y = star(X),!,
92 '$concat'(X,SRest,List),
93 match(SRest,Rest).
94 match([X|PRest],[Y|SRest]) :-
95 (atom(X) -> X = Y; match(X,Y)),
96 match(PRest,SRest).
97
98 '$concat'([],L,L).
99 '$concat'([X|L1],L2,[X|L3]) :- '$concat'(L1,L2,L3).
+0
-1182
bench/chat_parser.pl less more
0 % generated: 19 November 1989
1 % option(s):
2 %
3 % chat_parser
4 %
5 % Fernando C. N. Pereira and David H. D. Warren
6
7 top:-
8 chat_parser.
9
10 go:-
11 statistics(runtime,[_,_]),
12 chat_parser,
13 statistics(runtime,[_,T]),
14 write('execution time is '),write(T), write(milliseconds).
15
16 chat_parser :-
17 my_string(X),
18 determinate_say(X,_),
19 fail.
20 chat_parser.
21
22
23 % query set
24
25 my_string([what,rivers,are,there,?]).
26 my_string([does,afghanistan,border,china,?]).
27 my_string([what,is,the,capital,of,upper_volta,?]).
28 my_string([where,is,the,largest,country,?]).
29 my_string([which,country,'~',s,capital,is,london,?]).
30 my_string([which,countries,are,european,?]).
31 my_string([how,large,is,the,smallest,american,country,?]).
32 my_string([what,is,the,ocean,that,borders,african,countries,
33 and,that,borders,asian,countries,?]).
34 my_string([what,are,the,capitals,of,the,countries,bordering,the,baltic,?]).
35 my_string([which,countries,are,bordered,by,two,seas,?]).
36 my_string([how,many,countries,does,the,danube,flow,through,?]).
37 my_string([what,is,the,total,area,of,countries,south,of,the,equator,
38 and,not,in,australasia,?]).
39 my_string([what,is,the,average,area,of,the,countries,in,each,continent,?]).
40 my_string([is,there,more,than,one,country,in,each,continent,?]).
41 my_string([is,there,some,ocean,that,does,not,border,any,country,?]).
42 my_string([what,are,the,countries,from,which,a,river,flows,
43 into,the,black_sea,?]).
44
45
46 % determinate_say
47
48 determinate_say(X,Y) :-
49 say(X,Y), !.
50
51
52 %-----------------------------------------------------------------------------
53 %
54 % xgrun
55 %
56 %-----------------------------------------------------------------------------
57
58 terminal(T,S,S,x(_,terminal,T,X),X).
59 terminal(T,[T|S],S,X,X) :-
60 gap(X).
61
62 gap(x(gap,_,_,_)).
63 gap([]).
64
65 virtual(NT,x(_,nonterminal,NT,X),X).
66
67
68 %----------------------------------------------------------------------------
69 %
70 % clotab
71 %
72 %----------------------------------------------------------------------------
73
74 % normal form masks
75
76 is_pp(#(1,_,_,_)).
77
78 is_pred(#(_,1,_,_)).
79
80 is_trace(#(_,_,1,_)).
81
82 is_adv(#(_,_,_,1)).
83
84 trace1(#(_,_,1,_),#(0,0,0,0)).
85
86 trace1(#(0,0,1,0)).
87
88 adv(#(0,0,0,1)).
89
90 empty(#(0,0,0,0)).
91
92 np_all(#(1,1,1,0)).
93
94 s_all(#(1,0,1,1)).
95
96 np_no_trace(#(1,1,0,0)).
97
98 % mask operations
99
100 myplus(#(B1,B2,B3,B4),#(C1,C2,C3,C4),#(D1,D2,D3,D4)) :-
101 or(B1,C1,D1),
102 or(B2,C2,D2),
103 or(B3,C3,D3),
104 or(B4,C4,D4).
105
106 minus(#(B1,B2,B3,B4),#(C1,C2,C3,C4),#(D1,D2,D3,D4)) :-
107 anot(B1,C1,D1),
108 anot(B2,C2,D2),
109 anot(B3,C3,D3),
110 anot(B4,C4,D4).
111
112 or(1,_,1).
113 or(0,1,1).
114 or(0,0,0).
115
116 anot(X,0,X).
117 anot(X,1,0).
118
119 % noun phrase position features
120
121 role(subj,_,#(1,0,0)).
122 role(compl,_,#(0,_,_)).
123 role(undef,main,#(_,0,_)).
124 role(undef,aux,#(0,_,_)).
125 role(undef,decl,_).
126 role(nil,_,_).
127
128 subj_case(#(1,0,0)).
129 verb_case(#(0,1,0)).
130 prep_case(#(0,0,1)).
131 compl_case(#(0,_,_)).
132
133
134 %----------------------------------------------------------------------------
135 %
136 % newg
137 %
138 %----------------------------------------------------------------------------
139
140 say(X,Y) :-
141 sentence(Y,X,[],[],[]).
142
143
144 sentence(B,C,D,E,F) :-
145 declarative(B,C,G,E,H),
146 terminator(.,G,D,H,F).
147 sentence(B,C,D,E,F) :-
148 wh_question(B,C,G,E,H),
149 terminator(?,G,D,H,F).
150 sentence(B,C,D,E,F) :-
151 topic(C,G,E,H),
152 wh_question(B,G,I,H,J),
153 terminator(?,I,D,J,F).
154 sentence(B,C,D,E,F) :-
155 yn_question(B,C,G,E,H),
156 terminator(?,G,D,H,F).
157 sentence(B,C,D,E,F) :-
158 imperative(B,C,G,E,H),
159 terminator(!,G,D,H,F).
160
161
162 pp(B,C,D,E,F,F,G,H) :-
163 virtual(pp(B,C,D,E),G,H).
164 pp(pp(B,C),D,E,F,G,H,I,J) :-
165 prep(B,G,K,I,L),
166 prep_case(M),
167 np(C,N,M,O,D,E,F,K,H,L,J).
168
169
170 topic(B,C,D,x(gap,nonterminal,pp(E,compl,F,G),H)) :-
171 pp(E,compl,F,G,B,I,D,J),
172 opt_comma(I,C,J,H).
173
174
175 opt_comma(B,C,D,E) :-
176 ~(',',B,C,D,E).
177 opt_comma(B,B,C,C).
178
179
180 declarative(decl(B),C,D,E,F) :-
181 s(B,G,C,D,E,F).
182
183
184 wh_question(whq(B,C),D,E,F,G) :-
185 variable_q(B,H,I,J,D,K,F,L),
186 question(I,J,C,K,E,L,G).
187
188
189 np(B,C,D,E,F,G,H,I,I,J,K) :-
190 virtual(np(B,C,D,E,F,G,H),J,K).
191 np(np(B,C,[]),B,D,def,E,F,G,H,I,J,K) :-
192 is_pp(F),
193 pers_pron(C,B,L,H,I,J,K),
194 empty(G),
195 role(L,decl,D).
196 np(np(B,C,D),B,E,F,G,H,I,J,K,L,M) :-
197 is_pp(H),
198 np_head(C,B,F+N,O,D,J,P,L,Q),
199 np_all(R),
200 np_compls(N,B,G,O,R,I,P,K,Q,M).
201 np(part(B,C),3+D,E,indef,F,G,H,I,J,K,L) :-
202 is_pp(G),
203 determiner(B,D,indef,I,M,K,N),
204 ~(of,M,O,N,P),
205 s_all(Q),
206 prep_case(R),
207 np(C,3+plu,R,def,F,Q,H,O,J,P,L).
208
209
210 variable_q(B,C,D,E,F,G,H,x(gap,nonterminal,np(I,C,E,J,K,L,M),N)) :-
211 whq(B,C,I,D,F,G,H,N),
212 trace1(L,M).
213 variable_q(B,C,compl,D,E,F,G,x(gap,nonterminal,pp(pp(H,I),compl,J,K),L)) :-
214 prep(H,E,M,G,N),
215 whq(B,C,I,O,M,F,N,L),
216 trace1(J,K),
217 compl_case(D).
218 variable_q(B,C,compl,D,E,F,G,x(gap,nonterminal,
219 adv_phrase(pp(H,np(C,np_head(int_det(B),[],I),[])),J,K),L)) :-
220 context_pron(H,I,E,F,G,L),
221 trace1(J,K),
222 verb_case(D).
223 variable_q(B,C,compl,D,E,F,G,
224 x(gap,nonterminal,predicate(adj,value(H,wh(B)),I),J)) :-
225 ~(how,E,K,G,L),
226 adj(quant,H,K,F,L,J),
227 empty(I),
228 verb_case(D).
229
230
231 adv_phrase(B,C,D,E,E,F,G) :-
232 virtual(adv_phrase(B,C,D),F,G).
233 adv_phrase(pp(B,C),D,E,F,G,H,I) :-
234 loc_pred(B,F,J,H,K),
235 pp(pp(prep(of),C),compl,D,E,J,G,K,I).
236
237
238 predicate(B,C,D,E,E,F,G) :-
239 virtual(predicate(B,C,D),F,G).
240 predicate(B,C,D,E,F,G,H) :-
241 adj_phrase(C,D,E,F,G,H).
242 predicate(neg,B,C,D,E,F,G) :-
243 s_all(H),
244 pp(B,compl,H,C,D,E,F,G).
245 predicate(B,C,D,E,F,G,H) :-
246 s_all(I),
247 adv_phrase(C,I,D,E,F,G,H).
248
249
250 whq(B,C,D,undef,E,F,G,H) :-
251 int_det(B,C,E,I,G,J),
252 s_all(K),
253 np(D,C,L,M,subj,K,N,I,F,J,H).
254 whq(B,3+C,np(3+C,wh(B),[]),D,E,F,G,H) :-
255 int_pron(D,E,F,G,H).
256
257
258 int_det(B,3+C,D,E,F,G) :-
259 whose(B,C,D,E,F,G).
260 int_det(B,3+C,D,E,F,G) :-
261 int_art(B,C,D,E,F,G).
262
263
264 gen_marker(B,B,C,D) :-
265 virtual(gen_marker,C,D).
266 gen_marker(B,C,D,E) :-
267 ~('~',B,F,D,G),
268 an_s(F,C,G,E).
269
270
271 whose(B,C,D,E,F,x(nogap,nonterminal,np_head0(wh(B),C,proper),
272 x(nogap,nonterminal,gen_marker,G))) :-
273 ~(whose,D,E,F,G).
274
275
276 question(B,C,D,E,F,G,H) :-
277 subj_question(B),
278 role(subj,I,C),
279 s(D,J,E,F,G,H).
280 question(B,C,D,E,F,G,H) :-
281 fronted_verb(B,C,E,I,G,J),
282 s(D,K,I,F,J,H).
283
284
285 det(B,C,D,E,E,F,G) :-
286 virtual(det(B,C,D),F,G).
287 det(det(B),C,D,E,F,G,H) :-
288 terminal(I,E,F,G,H),
289 det(I,C,B,D).
290 det(generic,B,generic,C,C,D,D).
291
292
293 int_art(B,C,D,E,F,x(nogap,nonterminal,det(G,C,def),H)) :-
294 int_art(B,C,G,D,E,F,H).
295
296
297 subj_question(subj).
298 subj_question(undef).
299
300
301 yn_question(q(B),C,D,E,F) :-
302 fronted_verb(nil,G,C,H,E,I),
303 s(B,J,H,D,I,F).
304
305
306 verb_form(B,C,D,E,F,F,G,H) :-
307 virtual(verb_form(B,C,D,E),G,H).
308 verb_form(B,C,D,E,F,G,H,I) :-
309 terminal(J,F,G,H,I),
310 verb_form(J,B,C,D).
311
312
313 neg(B,C,D,D,E,F) :-
314 virtual(neg(B,C),E,F).
315 neg(aux+B,neg,C,D,E,F) :-
316 ~(not,C,D,E,F).
317 neg(B,pos,C,C,D,D).
318
319
320 fronted_verb(B,C,D,E,F,x(gap,nonterminal,verb_form(G,H,I,J),
321 x(nogap,nonterminal,neg(K,L),M))) :-
322 verb_form(G,H,I,N,D,O,F,P),
323 verb_type(G,aux+Q),
324 role(B,J,C),
325 neg(R,L,O,E,P,M).
326
327
328 imperative(imp(B),C,D,E,F) :-
329 imperative_verb(C,G,E,H),
330 s(B,I,G,D,H,F).
331
332
333 imperative_verb(B,C,D,x(nogap,terminal,you,x(nogap,nonterminal,
334 verb_form(E,imp+fin,2+sin,main),F))) :-
335 verb_form(E,inf,G,H,B,C,D,F).
336
337
338 s(s(B,C,D,E),F,G,H,I,J) :-
339 subj(B,K,L,G,M,I,N),
340 verb(C,K,L,O,M,P,N,Q),
341 empty(R),
342 s_all(S),
343 verb_args(L,O,D,R,T,P,U,Q,V),
344 minus(S,T,W),
345 myplus(S,T,X),
346 verb_mods(E,W,X,F,U,H,V,J).
347
348
349 subj(there,B,C+be,D,E,F,G) :-
350 ~(there,D,E,F,G).
351 subj(B,C,D,E,F,G,H) :-
352 s_all(I),
353 subj_case(J),
354 np(B,C,J,K,subj,I,L,E,F,G,H).
355
356
357 np_head(B,C,D,E,F,G,H,I,J) :-
358 np_head0(K,L,M,G,N,I,O),
359 possessive(K,L,M,P,P,B,C,D,E,F,N,H,O,J).
360
361
362 np_head0(B,C,D,E,E,F,G) :-
363 virtual(np_head0(B,C,D),F,G).
364 np_head0(name(B),3+sin,def+proper,C,D,E,F) :-
365 name(B,C,D,E,F).
366 np_head0(np_head(B,C,D),3+E,F+common,G,H,I,J) :-
367 determiner(B,E,F,G,K,I,L),
368 adjs(C,K,M,L,N),
369 noun(D,E,M,H,N,J).
370 np_head0(B,C,def+proper,D,E,F,x(nogap,nonterminal,gen_marker,G)) :-
371 poss_pron(B,C,D,E,F,G).
372 np_head0(np_head(B,[],C),3+sin,indef+common,D,E,F,G) :-
373 quantifier_pron(B,C,D,E,F,G).
374
375
376 np_compls(proper,B,C,[],D,E,F,F,G,G) :-
377 empty(E).
378 np_compls(common,B,C,D,E,F,G,H,I,J) :-
379 np_all(K),
380 np_mods(B,C,L,D,E,M,K,N,G,O,I,P),
381 relative(B,L,M,N,F,O,H,P,J).
382
383
384 possessive(B,C,D,[],E,F,G,H,I,J,K,L,M,N) :-
385 gen_case(K,O,M,P),
386 np_head0(Q,R,S,O,T,P,U),
387 possessive(Q,R,S,V,[pp(poss,np(C,B,E))|V],F,G,H,I,J,T,L,U,N).
388 possessive(B,C,D,E,F,B,C,D,E,F,G,G,H,H).
389
390
391 gen_case(B,C,D,x(nogap,terminal,the,E)) :-
392 gen_marker(B,C,D,E).
393
394
395 an_s(B,C,D,E) :-
396 ~(s,B,C,D,E).
397 an_s(B,B,C,C).
398
399
400 determiner(B,C,D,E,F,G,H) :-
401 det(B,C,D,E,F,G,H).
402 determiner(B,C,D,E,F,G,H) :-
403 quant_phrase(B,C,D,E,F,G,H).
404
405
406 quant_phrase(quant(B,C),D,E,F,G,H,I) :-
407 quant(B,E,F,J,H,K),
408 number(C,D,J,G,K,I).
409
410
411 quant(B,indef,C,D,E,F) :-
412 neg_adv(G,B,C,H,E,I),
413 comp_adv(G,H,J,I,K),
414 ~(than,J,D,K,F).
415 quant(B,indef,C,D,E,F) :-
416 ~(at,C,G,E,H),
417 sup_adv(I,G,D,H,F),
418 sup_op(I,B).
419 quant(the,def,B,C,D,E) :-
420 ~(the,B,C,D,E).
421 quant(same,indef,B,B,C,C).
422
423
424 neg_adv(B,not+B,C,D,E,F) :-
425 ~(not,C,D,E,F).
426 neg_adv(B,B,C,C,D,D).
427
428
429 sup_op(least,not+less).
430 sup_op(most,not+more).
431
432
433 np_mods(B,C,D,[E|F],G,H,I,J,K,L,M,N) :-
434 np_mod(B,C,E,G,O,K,P,M,Q),
435 trace1(R),
436 myplus(R,O,S),
437 minus(G,S,T),
438 myplus(O,G,U),
439 np_mods(B,C,D,F,T,H,U,J,P,L,Q,N).
440 np_mods(B,C,D,D,E,E,F,F,G,G,H,H).
441
442
443 np_mod(B,C,D,E,F,G,H,I,J) :-
444 pp(D,C,E,F,G,H,I,J).
445 np_mod(B,C,D,E,F,G,H,I,J) :-
446 reduced_relative(B,D,E,F,G,H,I,J).
447
448
449 verb_mods([B|C],D,E,F,G,H,I,J) :-
450 verb_mod(B,D,K,G,L,I,M),
451 trace1(N),
452 myplus(N,K,O),
453 minus(D,O,P),
454 myplus(K,D,Q),
455 verb_mods(C,P,Q,F,L,H,M,J).
456 verb_mods([],B,C,C,D,D,E,E).
457
458
459 verb_mod(B,C,D,E,F,G,H) :-
460 adv_phrase(B,C,D,E,F,G,H).
461 verb_mod(B,C,D,E,F,G,H) :-
462 is_adv(C),
463 adverb(B,E,F,G,H),
464 empty(D).
465 verb_mod(B,C,D,E,F,G,H) :-
466 pp(B,compl,C,D,E,F,G,H).
467
468
469 adjs([B|C],D,E,F,G) :-
470 pre_adj(B,D,H,F,I),
471 adjs(C,H,E,I,G).
472 adjs([],B,B,C,C).
473
474
475 pre_adj(B,C,D,E,F) :-
476 adj(G,B,C,D,E,F).
477 pre_adj(B,C,D,E,F) :-
478 sup_phrase(B,C,D,E,F).
479
480
481 sup_phrase(sup(most,B),C,D,E,F) :-
482 sup_adj(B,C,D,E,F).
483 sup_phrase(sup(B,C),D,E,F,G) :-
484 sup_adv(B,D,I,F,J),
485 adj(quant,C,I,E,J,G).
486
487
488 comp_phrase(comp(B,C,D),E,F,G,H,I) :-
489 comp(B,C,F,J,H,K),
490 np_no_trace(L),
491 prep_case(M),
492 np(D,N,M,O,compl,L,E,J,G,K,I).
493
494
495 comp(B,C,D,E,F,G) :-
496 comp_adv(B,D,H,F,I),
497 adj(quant,C,H,J,I,K),
498 ~(than,J,E,K,G).
499 comp(more,B,C,D,E,F) :-
500 rel_adj(B,C,G,E,H),
501 ~(than,G,D,H,F).
502 comp(same,B,C,D,E,F) :-
503 ~(as,C,G,E,H),
504 adj(quant,B,G,I,H,J),
505 ~(as,I,D,J,F).
506
507
508 relative(B,[C],D,E,F,G,H,I,J) :-
509 is_pred(D),
510 rel_conj(B,K,C,F,G,H,I,J).
511 relative(B,[],C,D,D,E,E,F,F).
512
513
514 rel_conj(B,C,D,E,F,G,H,I) :-
515 rel(B,J,K,F,L,H,M),
516 rel_rest(B,C,J,D,K,E,L,G,M,I).
517
518
519 rel_rest(B,C,D,E,F,G,H,I,J,K) :-
520 conj(C,L,D,M,E,H,N,J,O),
521 rel_conj(B,L,M,G,N,I,O,K).
522 rel_rest(B,C,D,D,E,E,F,F,G,G).
523
524
525 rel(B,rel(C,D),E,F,G,H,I) :-
526 myopen(F,J,H,K),
527 variable(B,C,J,L,K,M),
528 s(D,N,L,O,M,P),
529 trace1(Q),
530 minus(N,Q,E),
531 close(O,G,P,I).
532
533
534 variable(B,C,D,E,F,x(gap,nonterminal,np(np(B,wh(C),[]),B,G,H,I,J,K),L)) :-
535 ~(that,D,E,F,L),
536 trace1(J,K).
537 variable(B,C,D,E,F,x(gap,nonterminal,np(G,H,I,J,K,L,M),N)) :-
538 wh(C,B,G,H,I,D,E,F,N),
539 trace1(L,M).
540 variable(B,C,D,E,F,x(gap,nonterminal,pp(pp(G,H),compl,I,J),K)) :-
541 prep(G,D,L,F,M),
542 wh(C,B,H,N,O,L,E,M,K),
543 trace1(I,J),
544 compl_case(O).
545
546
547 wh(B,C,np(C,wh(B),[]),C,D,E,F,G,H) :-
548 rel_pron(I,E,F,G,H),
549 role(I,decl,D).
550 wh(B,C,np(D,E,[pp(F,G)]),D,H,I,J,K,L) :-
551 np_head0(E,D,M+common,I,N,K,O),
552 prep(F,N,P,O,Q),
553 wh(B,C,G,R,S,P,J,Q,L).
554 wh(B,C,D,E,F,G,H,I,J) :-
555 whose(B,C,G,K,I,L),
556 s_all(M),
557 np(D,E,F,def,subj,M,N,K,H,L,J).
558
559
560 reduced_relative(B,C,D,E,F,G,H,I) :-
561 is_pred(D),
562 reduced_rel_conj(B,J,C,E,F,G,H,I).
563
564
565 reduced_rel_conj(B,C,D,E,F,G,H,I) :-
566 reduced_rel(B,J,K,F,L,H,M),
567 reduced_rel_rest(B,C,J,D,K,E,L,G,M,I).
568
569
570 reduced_rel_rest(B,C,D,E,F,G,H,I,J,K) :-
571 conj(C,L,D,M,E,H,N,J,O),
572 reduced_rel_conj(B,L,M,G,N,I,O,K).
573 reduced_rel_rest(B,C,D,D,E,E,F,F,G,G).
574
575
576 reduced_rel(B,reduced_rel(C,D),E,F,G,H,I) :-
577 myopen(F,J,H,K),
578 reduced_wh(B,C,J,L,K,M),
579 s(D,N,L,O,M,P),
580 trace1(Q),
581 minus(N,Q,E),
582 close(O,G,P,I).
583
584
585 reduced_wh(B,C,D,E,F,x(nogap,nonterminal,
586 np(np(B,wh(C),[]),B,G,H,I,J,K),x(nogap,nonterminal,
587 verb_form(be,pres+fin,B,main),x(nogap,nonterminal,
588 neg(L,M),x(nogap,nonterminal,predicate(M,N,O),P))))) :-
589 neg(Q,M,D,R,F,S),
590 predicate(M,N,O,R,E,S,P),
591 trace1(J,K),
592 subj_case(G).
593 reduced_wh(B,C,D,E,F,x(nogap,nonterminal,
594 np(np(B,wh(C),[]),B,G,H,I,J,K),x(nogap,nonterminal,
595 verb(L,M,N,O),P))) :-
596 participle(L,N,O,D,E,F,P),
597 trace1(J,K),
598 subj_case(G).
599 reduced_wh(B,C,D,E,F,x(nogap,nonterminal,
600 np(G,H,I,J,K,L,M),x(gap,nonterminal,
601 np(np(B,wh(C),[]),B,N,O,P,Q,R),S))) :-
602 s_all(T),
603 subj_case(I),
604 verb_case(N),
605 np(G,H,U,J,subj,T,V,D,E,F,S),
606 trace1(L,M),
607 trace1(Q,R).
608
609
610 verb(B,C,D,E,F,F,G,H) :-
611 virtual(verb(B,C,D,E),G,H).
612 verb(verb(B,C,D+fin,E,F),G,H,C,I,J,K,L) :-
613 verb_form(M,D+fin,G,N,I,O,K,P),
614 verb_type(M,Q),
615 neg(Q,F,O,R,P,S),
616 rest_verb(N,M,B,C,E,R,J,S,L),
617 verb_type(B,H).
618
619
620 rest_verb(aux,have,B,C,[perf|D],E,F,G,H) :-
621 verb_form(I,past+part,J,K,E,L,G,M),
622 have(I,B,C,D,L,F,M,H).
623 rest_verb(aux,be,B,C,D,E,F,G,H) :-
624 verb_form(I,J,K,L,E,M,G,N),
625 be(J,I,B,C,D,M,F,N,H).
626 rest_verb(aux,do,B,active,[],C,D,E,F) :-
627 verb_form(B,inf,G,H,C,D,E,F).
628 rest_verb(main,B,B,active,[],C,C,D,D).
629
630
631 have(be,B,C,D,E,F,G,H) :-
632 verb_form(I,J,K,L,E,M,G,N),
633 be(J,I,B,C,D,M,F,N,H).
634 have(B,B,active,[],C,C,D,D).
635
636
637 be(past+part,B,B,passive,[],C,C,D,D).
638 be(pres+part,B,C,D,[prog],E,F,G,H) :-
639 passive(B,C,D,E,F,G,H).
640
641
642 passive(be,B,passive,C,D,E,F) :-
643 verb_form(B,past+part,G,H,C,D,E,F),
644 verb_type(B,I),
645 passive(I).
646 passive(B,B,active,C,C,D,D).
647
648
649 participle(verb(B,C,inf,D,E),F,C,G,H,I,J) :-
650 neg(K,E,G,L,I,M),
651 verb_form(B,N,O,P,L,H,M,J),
652 participle(N,C,D),
653 verb_type(B,F).
654
655
656 passive(B+trans).
657 passive(B+ditrans).
658
659
660 participle(pres+part,active,[prog]).
661 participle(past+part,passive,[]).
662
663
664 close(B,B,C,D) :-
665 virtual(close,C,D).
666
667
668 myopen(B,B,C,x(gap,nonterminal,close,C)).
669
670
671 verb_args(B+C,D,E,F,G,H,I,J,K) :-
672 advs(E,L,M,H,N,J,O),
673 verb_args(C,D,L,F,G,N,I,O,K).
674 verb_args(trans,active,[arg(dir,B)],C,D,E,F,G,H) :-
675 verb_arg(np,B,D,E,F,G,H).
676 verb_args(ditrans,B,[arg(C,D)|E],F,G,H,I,J,K) :-
677 verb_arg(np,D,L,H,M,J,N),
678 object(C,E,L,G,M,I,N,K).
679 verb_args(be,B,[void],C,C,D,E,F,G) :-
680 terminal(there,D,E,F,G).
681 verb_args(be,B,[arg(predicate,C)],D,E,F,G,H,I) :-
682 pred_conj(J,C,E,F,G,H,I).
683 verb_args(be,B,[arg(dir,C)],D,E,F,G,H,I) :-
684 verb_arg(np,C,E,F,G,H,I).
685 verb_args(have,active,[arg(dir,B)],C,D,E,F,G,H) :-
686 verb_arg(np,B,D,E,F,G,H).
687 verb_args(B,C,[],D,D,E,E,F,F) :-
688 no_args(B).
689
690
691 object(B,C,D,E,F,G,H,I) :-
692 adv(J),
693 minus(J,D,K),
694 advs(C,L,K,F,M,H,N),
695 obj(B,L,D,E,M,G,N,I).
696
697
698 obj(ind,[arg(dir,B)],C,D,E,F,G,H) :-
699 verb_arg(np,B,D,E,F,G,H).
700 obj(dir,[],B,B,C,C,D,D).
701
702
703 pred_conj(B,C,D,E,F,G,H) :-
704 predicate(I,J,K,E,L,G,M),
705 pred_rest(B,J,C,K,D,L,F,M,H).
706
707
708 pred_rest(B,C,D,E,F,G,H,I,J) :-
709 conj(B,K,C,L,D,G,M,I,N),
710 pred_conj(K,L,F,M,H,N,J).
711 pred_rest(B,C,C,D,D,E,E,F,F).
712
713
714 verb_arg(np,B,C,D,E,F,G) :-
715 s_all(H),
716 verb_case(I),
717 np(B,J,I,K,compl,H,C,D,E,F,G).
718
719
720 advs([B|C],D,E,F,G,H,I) :-
721 is_adv(E),
722 adverb(B,F,J,H,K),
723 advs(C,D,E,J,G,K,I).
724 advs(B,B,C,D,D,E,E).
725
726
727 adj_phrase(B,C,D,E,F,G) :-
728 adj(H,B,D,E,F,G),
729 empty(C).
730 adj_phrase(B,C,D,E,F,G) :-
731 comp_phrase(B,C,D,E,F,G).
732
733
734 no_args(trans).
735 no_args(ditrans).
736 no_args(intrans).
737
738
739 conj(conj(B,C),conj(B,D),E,F,conj(B,E,F),G,H,I,J) :-
740 conj(B,C,D,G,H,I,J).
741
742
743 noun(B,C,D,E,F,G) :-
744 terminal(H,D,E,F,G),
745 noun_form(H,B,C).
746
747
748 adj(B,adj(C),D,E,F,G) :-
749 terminal(C,D,E,F,G),
750 adj(C,B).
751
752
753 prep(prep(B),C,D,E,F) :-
754 terminal(B,C,D,E,F),
755 prep(B).
756
757
758 rel_adj(adj(B),C,D,E,F) :-
759 terminal(G,C,D,E,F),
760 rel_adj(G,B).
761
762
763 sup_adj(adj(B),C,D,E,F) :-
764 terminal(G,C,D,E,F),
765 sup_adj(G,B).
766
767
768 comp_adv(less,B,C,D,E) :-
769 ~(less,B,C,D,E).
770 comp_adv(more,B,C,D,E) :-
771 ~(more,B,C,D,E).
772
773
774 sup_adv(least,B,C,D,E) :-
775 ~(least,B,C,D,E).
776 sup_adv(most,B,C,D,E) :-
777 ~(most,B,C,D,E).
778
779
780 rel_pron(B,C,D,E,F) :-
781 terminal(G,C,D,E,F),
782 rel_pron(G,B).
783
784
785 name(B,C,D,E,F) :-
786 opt_the(C,G,E,H),
787 terminal(B,G,D,H,F),
788 name(B).
789
790
791 int_art(B,plu,quant(same,wh(B)),C,D,E,F) :-
792 ~(how,C,G,E,H),
793 ~(many,G,D,H,F).
794 int_art(B,C,D,E,F,G,H) :-
795 terminal(I,E,F,G,H),
796 int_art(I,B,C,D).
797
798
799 int_pron(B,C,D,E,F) :-
800 terminal(G,C,D,E,F),
801 int_pron(G,B).
802
803
804 adverb(adv(B),C,D,E,F) :-
805 terminal(B,C,D,E,F),
806 adverb(B).
807
808
809 poss_pron(pronoun(B),C+D,E,F,G,H) :-
810 terminal(I,E,F,G,H),
811 poss_pron(I,B,C,D).
812
813
814 pers_pron(pronoun(B),C+D,E,F,G,H,I) :-
815 terminal(J,F,G,H,I),
816 pers_pron(J,B,C,D,E).
817
818
819 quantifier_pron(B,C,D,E,F,G) :-
820 terminal(H,D,E,F,G),
821 quantifier_pron(H,B,C).
822
823
824 context_pron(prep(in),place,B,C,D,E) :-
825 ~(where,B,C,D,E).
826 context_pron(prep(at),time,B,C,D,E) :-
827 ~(when,B,C,D,E).
828
829
830 number(nb(B),C,D,E,F,G) :-
831 terminal(H,D,E,F,G),
832 number(H,B,C).
833
834
835 terminator(B,C,D,E,F) :-
836 terminal(G,C,D,E,F),
837 terminator(G,B).
838
839
840 opt_the(B,B,C,C).
841 opt_the(B,C,D,E) :-
842 ~(the,B,C,D,E).
843
844
845 conj(B,list,list,C,D,E,F) :-
846 terminal(',',C,D,E,F).
847 conj(B,list,'end',C,D,E,F) :-
848 terminal(B,C,D,E,F),
849 conj(B).
850
851
852 loc_pred(B,C,D,E,F) :-
853 terminal(G,C,D,E,F),
854 loc_pred(G,B).
855
856
857 ~(B,C,D,E,F) :-
858 terminal(B,C,D,E,F),
859 ~(B).
860
861
862 %----------------------------------------------------------------------------
863 %
864 % newdic
865 %
866 %----------------------------------------------------------------------------
867
868 word(Word) :- ~(Word).
869 word(Word) :- conj(Word).
870 word(Word) :- adverb(Word).
871 word(Word) :- sup_adj(Word,_).
872 word(Word) :- rel_adj(Word,_).
873 word(Word) :- adj(Word,_).
874 word(Word) :- name(Word).
875 word(Word) :- terminator(Word,_).
876 word(Word) :- pers_pron(Word,_,_,_,_).
877 word(Word) :- poss_pron(Word,_,_,_).
878 word(Word) :- rel_pron(Word,_).
879 word(Word) :- verb_form(Word,_,_,_).
880 word(Word) :- noun_form(Word,_,_).
881 word(Word) :- prep(Word).
882 word(Word) :- quantifier_pron(Word,_,_).
883 word(Word) :- number(Word,_,_).
884 word(Word) :- det(Word,_,_,_).
885 word(Word) :- int_art(Word,_,_,_).
886 word(Word) :- int_pron(Word,_).
887 word(Word) :- loc_pred(Word,_).
888
889 ~(how).
890 ~(whose).
891 ~(there).
892 ~(of).
893 ~('~'). % use ~ instead of ' to help assembler
894 ~(',').
895 ~(s).
896 ~(than).
897 ~(at).
898 ~(the).
899 ~(not).
900 ~(as).
901 ~(that).
902 ~(less).
903 ~(more).
904 ~(least).
905 ~(most).
906 ~(many).
907 ~(where).
908 ~(when).
909
910 conj(and).
911 conj(or).
912
913 int_pron(what,undef).
914 int_pron(which,undef).
915 int_pron(who,subj).
916 int_pron(whom,compl).
917
918 int_art(what,X,_,int_det(X)).
919 int_art(which,X,_,int_det(X)).
920
921 det(the,No,the(No),def).
922 det(a,sin,a,indef).
923 det(an,sin,a,indef).
924 det(every,sin,every,indef).
925 det(some,_,some,indef).
926 det(any,_,any,indef).
927 det(all,plu,all,indef).
928 det(each,sin,each,indef).
929 det(no,_,no,indef).
930
931 number(W,I,Nb) :-
932 tr_number(W,I),
933 ag_number(I,Nb).
934
935 tr_number(nb(I),I).
936 tr_number(one,1).
937 tr_number(two,2).
938 tr_number(three,3).
939 tr_number(four,4).
940 tr_number(five,5).
941 tr_number(six,6).
942 tr_number(seven,7).
943 tr_number(eight,8).
944 tr_number(nine,9).
945 tr_number(ten,10).
946
947 ag_number(1,sin).
948 ag_number(N,plu) :- N>1.
949
950 quantifier_pron(everybody,every,person).
951 quantifier_pron(everyone,every,person).
952 quantifier_pron(everything,every,thing).
953 quantifier_pron(somebody,some,person).
954 quantifier_pron(someone,some,person).
955 quantifier_pron(something,some,thing).
956 quantifier_pron(anybody,any,person).
957 quantifier_pron(anyone,any,person).
958 quantifier_pron(anything,any,thing).
959 quantifier_pron(nobody,no,person).
960 quantifier_pron(nothing,no,thing).
961
962 prep(as).
963 prep(at).
964 prep(of).
965 prep(to).
966 prep(by).
967 prep(with).
968 prep(in).
969 prep(on).
970 prep(from).
971 prep(into).
972 prep(through).
973
974 noun_form(Plu,Sin,plu) :- noun_plu(Plu,Sin).
975 noun_form(Sin,Sin,sin) :- noun_sin(Sin).
976 noun_form(proportion,proportion,_).
977 noun_form(percentage,percentage,_).
978
979 root_form(1+sin).
980 root_form(2+_).
981 root_form(1+plu).
982 root_form(3+plu).
983
984 verb_root(be).
985 verb_root(have).
986 verb_root(do).
987 verb_root(border).
988 verb_root(contain).
989 verb_root(drain).
990 verb_root(exceed).
991 verb_root(flow).
992 verb_root(rise).
993
994 regular_pres(have).
995 regular_pres(do).
996 regular_pres(rise).
997 regular_pres(border).
998 regular_pres(contain).
999 regular_pres(drain).
1000 regular_pres(exceed).
1001 regular_pres(flow).
1002
1003 regular_past(had,have).
1004 regular_past(bordered,border).
1005 regular_past(contained,contain).
1006 regular_past(drained,drain).
1007 regular_past(exceeded,exceed).
1008 regular_past(flowed,flow).
1009
1010 rel_pron(who,subj).
1011 rel_pron(whom,compl).
1012 rel_pron(which,undef).
1013
1014 poss_pron(my,_,1,sin).
1015 poss_pron(your,_,2,_).
1016 poss_pron(his,masc,3,sin).
1017 poss_pron(her,fem,3,sin).
1018 poss_pron(its,neut,3,sin).
1019 poss_pron(our,_,1,plu).
1020 poss_pron(their,_,3,plu).
1021
1022 pers_pron(i,_,1,sin,subj).
1023 pers_pron(you,_,2,_,_).
1024 pers_pron(he,masc,3,sin,subj).
1025 pers_pron(she,fem,3,sin,subj).
1026 pers_pron(it,neut,3,sin,_).
1027 pers_pron(we,_,1,plu,subj).
1028 pers_pron(them,_,3,plu,subj).
1029 pers_pron(me,_,1,sin,compl(_)).
1030 pers_pron(him,masc,3,sin,compl(_)).
1031 pers_pron(her,fem,3,sin,compl(_)).
1032 pers_pron(us,_,1,plu,compl(_)).
1033 pers_pron(them,_,3,plu,compl(_)).
1034
1035 terminator(.,_).
1036 terminator(?,?).
1037 terminator(!,!).
1038
1039 name(_).
1040
1041 % ===========================================================================
1042
1043 % specialised dictionary
1044
1045 loc_pred(east,prep(eastof)).
1046 loc_pred(west,prep(westof)).
1047 loc_pred(north,prep(northof)).
1048 loc_pred(south,prep(southof)).
1049
1050 adj(minimum,restr).
1051 adj(maximum,restr).
1052 adj(average,restr).
1053 adj(total,restr).
1054 adj(african,restr).
1055 adj(american,restr).
1056 adj(asian,restr).
1057 adj(european,restr).
1058 adj(great,quant).
1059 adj(big,quant).
1060 adj(small,quant).
1061 adj(large,quant).
1062 adj(old,quant).
1063 adj(new,quant).
1064 adj(populous,quant).
1065
1066 rel_adj(greater,great).
1067 rel_adj(less,small).
1068 rel_adj(bigger,big).
1069 rel_adj(smaller,small).
1070 rel_adj(larger,large).
1071 rel_adj(older,old).
1072 rel_adj(newer,new).
1073
1074 sup_adj(biggest,big).
1075 sup_adj(smallest,small).
1076 sup_adj(largest,large).
1077 sup_adj(oldest,old).
1078 sup_adj(newest,new).
1079
1080 noun_sin(average).
1081 noun_sin(total).
1082 noun_sin(sum).
1083 noun_sin(degree).
1084 noun_sin(sqmile).
1085 noun_sin(ksqmile).
1086 noun_sin(thousand).
1087 noun_sin(million).
1088 noun_sin(time).
1089 noun_sin(place).
1090 noun_sin(area).
1091 noun_sin(capital).
1092 noun_sin(city).
1093 noun_sin(continent).
1094 noun_sin(country).
1095 noun_sin(latitude).
1096 noun_sin(longitude).
1097 noun_sin(ocean).
1098 noun_sin(person).
1099 noun_sin(population).
1100 noun_sin(region).
1101 noun_sin(river).
1102 noun_sin(sea).
1103 noun_sin(seamass).
1104 noun_sin(number).
1105
1106 noun_plu(averages,average).
1107 noun_plu(totals,total).
1108 noun_plu(sums,sum).
1109 noun_plu(degrees,degree).
1110 noun_plu(sqmiles,sqmile).
1111 noun_plu(ksqmiles,ksqmile).
1112 noun_plu(million,million).
1113 noun_plu(thousand,thousand).
1114 noun_plu(times,time).
1115 noun_plu(places,place).
1116 noun_plu(areas,area).
1117 noun_plu(capitals,capital).
1118 noun_plu(cities,city).
1119 noun_plu(continents,continent).
1120 noun_plu(countries,country).
1121 noun_plu(latitudes,latitude).
1122 noun_plu(longitudes,longitude).
1123 noun_plu(oceans,ocean).
1124 noun_plu(persons,person). noun_plu(people,person).
1125 noun_plu(populations,population).
1126 noun_plu(regions,region).
1127 noun_plu(rivers,river).
1128 noun_plu(seas,sea).
1129 noun_plu(seamasses,seamass).
1130 noun_plu(numbers,number).
1131
1132 verb_form(V,V,inf,_) :- verb_root(V).
1133 verb_form(V,V,pres+fin,Agmt) :-
1134 regular_pres(V),
1135 root_form(Agmt),
1136 verb_root(V).
1137 verb_form(Past,Root,past+_,_) :-
1138 regular_past(Past,Root).
1139
1140 verb_form(am,be,pres+fin,1+sin).
1141 verb_form(are,be,pres+fin,2+sin).
1142 verb_form(is,be,pres+fin,3+sin).
1143 verb_form(are,be,pres+fin,_+plu).
1144 verb_form(was,be,past+fin,1+sin).
1145 verb_form(were,be,past+fin,2+sin).
1146 verb_form(was,be,past+fin,3+sin).
1147 verb_form(were,be,past+fin,_+plu).
1148 verb_form(been,be,past+part,_).
1149 verb_form(being,be,pres+part,_).
1150 verb_form(has,have,pres+fin,3+sin).
1151 verb_form(having,have,pres+part,_).
1152 verb_form(does,do,pres+fin,3+sin).
1153 verb_form(did,do,past+fin,_).
1154 verb_form(doing,do,pres+part,_).
1155 verb_form(done,do,past+part,_).
1156 verb_form(flows,flow,pres+fin,3+sin).
1157 verb_form(flowing,flow,pres+part,_).
1158 verb_form(rises,rise,pres+fin,3+sin).
1159 verb_form(rose,rise,past+fin,_).
1160 verb_form(risen,rise,past+part,_).
1161 verb_form(borders,border,pres+fin,3+sin).
1162 verb_form(bordering,border,pres+part,_).
1163 verb_form(contains,contain,pres+fin,3+sin).
1164 verb_form(containing,contain,pres+part,_).
1165 verb_form(drains,drain,pres+fin,3+sin).
1166 verb_form(draining,drain,pres+part,_).
1167 verb_form(exceeds,exceed,pres+fin,3+sin).
1168 verb_form(exceeding,exceed,pres+part,_).
1169
1170 verb_type(have,aux+have).
1171 verb_type(be,aux+be).
1172 verb_type(do,aux+ditrans).
1173 verb_type(rise,main+intrans).
1174 verb_type(border,main+trans).
1175 verb_type(contain,main+trans).
1176 verb_type(drain,main+intrans).
1177 verb_type(exceed,main+trans).
1178 verb_type(flow,main+intrans).
1179
1180 adverb(yesterday).
1181 adverb(tomorrow).
+0
-84
bench/crypt.pl less more
0
1 % Cryptomultiplication:
2 % Find the unique answer to:
3 % OEE
4 % EE
5 % ---
6 % EOEE
7 % EOE
8 % ----
9 % OOEE
10 %
11 % where E=even, O=odd.
12 % This program generalizes easily to any such problem.
13 % Written by Peter Van Roy
14
15 top:-
16 odd(A), even(B), even(C),
17 even(E),
18 mult([C,B,A], E, [I,H,G,F|X]),
19 lefteven(F), odd(G), even(H), even(I), zero(X),
20 lefteven(D),
21 mult([C,B,A], D, [L,K,J|Y]),
22 lefteven(J), odd(K), even(L), zero(Y),
23 sum([I,H,G,F], [0,L,K,J], [P,O,N,M|Z]),
24 odd(M), odd(N), even(O), even(P), zero(Z).
25 % write(' '), write(A), write(B), write(C), nl,
26 % write(' '), write(D), write(E), nl,
27 % write(F), write(G), write(H), write(I), nl,
28 % write(J), write(K), write(L), nl,
29 % write(M), write(N), write(O), write(P), nl.
30
31 % Addition of two numbers
32 sum(AL, BL, CL) :- sum(AL, BL, 0, CL).
33
34 sum([A|AL], [B|BL], Carry, [C|CL]) :- !,
35 X is (A+B+Carry),
36 C is X mod 10,
37 NewCarry is X // 10,
38 sum(AL, BL, NewCarry, CL).
39 sum([], BL, 0, BL) :- !.
40 sum(AL, [], 0, AL) :- !.
41 sum([], [B|BL], Carry, [C|CL]) :- !,
42 X is B+Carry,
43 NewCarry is X // 10,
44 C is X mod 10,
45 sum([], BL, NewCarry, CL).
46 sum([A|AL], [], Carry, [C|CL]) :- !,
47 X is A+Carry,
48 NewCarry is X // 10,
49 C is X mod 10,
50 sum([], AL, NewCarry, CL).
51 sum([], [], Carry, [Carry]).
52
53 % Multiplication
54 mult(AL, D, BL) :- mult(AL, D, 0, BL).
55
56 mult([A|AL], D, Carry, [B|BL] ) :-
57 X is A*D+Carry,
58 B is X mod 10,
59 NewCarry is X // 10,
60 mult(AL, D, NewCarry, BL).
61 mult([], _, Carry, [C,Cend]) :-
62 C is Carry mod 10,
63 Cend is Carry // 10.
64
65 zero([]).
66 zero([0|L]) :- zero(L).
67
68 odd(1).
69 odd(3).
70 odd(5).
71 odd(7).
72 odd(9).
73
74 even(0).
75 even(2).
76 even(4).
77 even(6).
78 even(8).
79
80 lefteven(2).
81 lefteven(4).
82 lefteven(6).
83 lefteven(8).
+0
-39
bench/derive.pl less more
0 % generated: 25 October 1989
1 % option(s):
2 %
3 % (deriv) ops8
4 %
5 % David H. D. Warren
6 %
7 % symbolic derivative of (x+1)*((^(x,2)+2)*(^(x,3)+3))
8
9 top:-ops8,log10,divide10.
10
11 ops8 :- d((x+1)*((^(x,2)+2)*(^(x,3)+3)),x,_).
12 log10 :- d(log(log(log(log(log(log(log(log(log(log(x)))))))))),x,_).
13 divide10 :- d(((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x,x,_).
14
15 d(U+V,X,DU+DV) :- !,
16 d(U,X,DU),
17 d(V,X,DV).
18 d(U-V,X,DU-DV) :- !,
19 d(U,X,DU),
20 d(V,X,DV).
21 d(U*V,X,DU*V+U*DV) :- !,
22 d(U,X,DU),
23 d(V,X,DV).
24 d(U/V,X,(DU*V-U*DV)/(^(V,2))) :- !,
25 d(U,X,DU),
26 d(V,X,DV).
27 d(^(U,N),X,DU*N*(^(U,N1))) :- !,
28 integer(N),
29 N1 is N-1,
30 d(U,X,DU).
31 d(-U,X,-DU) :- !,
32 d(U,X,DU).
33 d(exp(U),X,exp(U)*DU) :- !,
34 d(U,X,DU).
35 d(log(U),X,DU/U) :- !,
36 d(U,X,DU).
37 d(X,X,1) :- !.
38 d(_,_,0).
+0
-38
bench/divide10.pl less more
0 % generated: 7 March 1990
1 % option(s):
2 %
3 % (deriv) divide10
4 %
5 % David H. D. Warren
6 %
7 % symbolic derivative of ((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x
8
9 top:-divide10.
10
11
12 divide10 :- d(((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x,x,_).
13
14 d(U+V,X,DU+DV) :- !,
15 d(U,X,DU),
16 d(V,X,DV).
17 d(U-V,X,DU-DV) :- !,
18 d(U,X,DU),
19 d(V,X,DV).
20 d(U*V,X,DU*V+U*DV) :- !,
21 d(U,X,DU),
22 d(V,X,DV).
23 d(U/V,X,(DU*V-U*DV)/(^(V,2))) :- !,
24 d(U,X,DU),
25 d(V,X,DV).
26 d(^(U,N),X,DU*N*(^(U,N1))) :- !,
27 integer(N),
28 N1 is N-1,
29 d(U,X,DU).
30 d(-U,X,-DU) :- !,
31 d(U,X,DU).
32 d(exp(U),X,exp(U)*DU) :- !,
33 d(U,X,DU).
34 d(log(U),X,DU/U) :- !,
35 d(U,X,DU).
36 d(X,X,1) :- !.
37 d(_,_,0).
+0
-100
bench/fast_mu.pl less more
0 %
1 % The MU-puzzle
2 % from Hofstadter's "Godel, Escher, Bach" (pp. 33-6).
3 % written by Bruce Holmer
4 %
5 % To find a derivation type, for example:
6 % theorem([m,u,i,i,u]).
7 % Also try 'miiiii' (uses all rules) and 'muui' (requires 11 steps).
8 % Note that it can be shown that (# of i's) cannot be a multiple
9 % of three (which includes 0).
10 % Some results:
11 %
12 % string # steps
13 % ------ -------
14 % miui 8
15 % muii 8
16 % muui 11
17 % muiiu 6
18 % miuuu 9
19 % muiuu 9
20 % muuiu 9
21 % muuui 9
22
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25 top :- theorem([m,u,i,i,u]).
26
27 % First break goal atom into a list of characters,
28 % find the derivation, and then print the results.
29 theorem(G) :-
30 length(G, GL1),
31 GL is GL1 - 1,
32 derive([m,i], G, 1, GL, Derivation, 0).
33 % nl, print_results([rule(0,[m,i])|Derivation], 0).
34
35 % derive(StartString, GoalString, StartStringLength, GoalStringLength,
36 % Derivation, InitBound).
37 derive(S, G, SL, GL, D, B) :-
38 % B1 is B + 1,
39 % write('depth '), write(B1), nl,
40 derive2(S, G, SL, GL, 1, D, B).
41 derive(S, G, SL, GL, D, B) :-
42 B1 is B + 1,
43 derive(S, G, SL, GL, D, B1).
44
45 % derive2(StartString, GoalString, StartStringLength, GoalStringLength,
46 % ScanPointer, Derivation, NumRemainingSteps).
47 derive2(S, S, SL, SL, _, [], _).
48 derive2(S, G, SL, GL, Pin, [rule(N,I)|D], R) :-
49 lower_bound(SL, GL, B),
50 R >= B,
51 R1 is R - 1,
52 rule(S, I, SL, IL, Pin, Pout, N),
53 derive2(I, G, IL, GL, Pout, D, R1).
54
55 rule([m|T1], [m|T2], L1, L2, Pin, Pout, N) :-
56 rule(T1, T2, L1, L2, Pin, Pout, 1, i, N, X, X).
57
58 % rule(InitialString, FinalString, InitStrLength, FinStrLength,
59 % ScanPtrIn, ScanPtrOut, StrPosition, PreviousChar,
60 % RuleNumber, DiffList, DiffLink).
61 % The difference list is used for doing a list concatenate in rule 2.
62 rule([i], [i,u], L1, L2, Pin, Pout, Pos, _, 1, _, _) :-
63 Pos >= Pin,
64 Pout is Pos - 2,
65 L2 is L1 + 1.
66 rule([], L, L1, L2, _, 1, _, _, 2, L, []) :-
67 L2 is L1 + L1.
68 rule([i,i,i|T], [u|T], L1, L2, Pin, Pout, Pos, _, 3, _, _) :-
69 Pos >= Pin,
70 Pout is Pos - 1,
71 L2 is L1 - 2.
72 rule([u,u|T], T, L1, L2, Pin, Pout, Pos, i, 4, _, _) :-
73 Pos >= Pin,
74 Pout is Pos - 2,
75 L2 is L1 - 2.
76 rule([H|T1], [H|T2], L1, L2, Pin, Pout, Pos, _, N, L, [H|X]) :-
77 Pos1 is Pos + 1,
78 rule(T1, T2, L1, L2, Pin, Pout, Pos1, H, N, L, X).
79
80 % print_results([], _).
81 % print_results([rule(N,G)|T], M) :-
82 % M1 is M + 1,
83 % write(M1), write(' '), print_rule(N), write(G), nl,
84 % print_results(T, M1).
85 %
86 % print_rule(0) :- write('axiom ').
87 % print_rule(N) :- N =\= 0, write('rule '), write(N), write(' ').
88 %
89 lower_bound(N, M, 1) :- N < M.
90 lower_bound(N, N, 2).
91 lower_bound(N, M, B) :-
92 N > M,
93 Diff is N - M,
94 P is Diff/\1, % use and to do even test
95 (P =:= 0 ->
96 B is Diff >> 1; % use shifts to divide by 2
97 B is ((Diff + 1) >> 1) + 1).
98
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+0
-184
bench/flatten.pl less more
0 % preprocessing phase to eliminate disjunctions from the code
1
2 % takes a list of clauses of the form source(Name,Clause)
3 % returns these clauses with disjunctions replaced by dummy calls
4 % and a list of NewClauses corresponding to those dummy calls
5 % Link is the uninstantiated last cdr of this list
6
7 top:-
8 eliminate_disjunctions([(a(A,B,C):-(b(A);c(C)))],X,Y,[]),
9 inst_vars((X,Y)).
10 % write((X,Y)), nl,
11 % (X,Y) == ([(a:-'_dummy_0')],[('_dummy_0':-b),('_dummy_0':-c)]),
12 % write(ok), nl.
13 top :- true.
14 %write(wrong), nl.
15
16 eliminate_disjunctions(OneProc,NewProc,NewClauses,Link) :-
17 gather_disj(OneProc,NewProc,Disj,[]),
18 treat_disj(Disj,NewClauses,Link).
19
20 gather_disj([],[],Link,Link).
21 gather_disj([C|Cs],NewProc,Disj,Link) :-
22 extract_disj(C, NewC, Disj, Rest),
23 NewProc = [NewC|NewCs],
24 gather_disj(Cs,NewCs,Rest,Link).
25
26 % given a clause, find in Disj the list of disj((A;B),N,X,C)
27 % where N is a unique ID, X is a var that takes the place of
28 % (A;B) in the code, NewC is the clause modified in such a way that
29 % the disjunctions are replaced by the corresponding vars
30 % Link is the last (uninstantiated) cdr of the list Disj.
31 % do the work of pretrans for nots, -> etc...
32 % put all those guys inside disjunctions
33 extract_disj(C, (Head:-NewBody), Disj, Link) :-
34 C = (Head:-Body), !,
35 CtrIn = 0,
36 extract_disj(Body, NewBody, Disj, Link, C, CtrIn, CtrOut).
37 extract_disj(Head, Head, Link, Link).
38
39 extract_disj((C1,C2), (NewC1,NewC2), Disj, Link, C, CtrIn, CtrOut) :-
40 extract_disj(C1, NewC1, Disj, Link1, C, CtrIn, Ctr),
41 extract_disj(C2, NewC2, Link1, Link, C, Ctr, CtrOut).
42
43 extract_disj(Goal, X, Disj, Link, C, CtrIn, CtrOut) :-
44 is_disj(Goal,NewGoal), !,
45 Disj = [disj(NewGoal,CtrIn,X,C)|Link],
46 CtrOut is CtrIn + 1.
47 extract_disj(Goal, Goal, Link, Link, _, CtrIn, CtrIn).
48
49 is_disj(((C1 -> C2); C3),((C1, !, C2); C3)) :- !.
50 is_disj((C1;C2),(C1;C2)).
51 is_disj(not(C),((C,!,fail);true)).
52 is_disj(\+(C),((C,!,fail);true)).
53 is_disj(\=(C1,C2),((C1 = C2,!,fail);true)).
54
55 % given a list of disj((A;B),N,X,C), for each, do the following:
56 % 1) find vars in (A;B)
57 % 2) find the vars in C
58 % 3) intersect the two sets of vars into one list
59 % 4) make a predicate name using N as a part of it ('dummy_disjN')
60 % 5) put a structure with that name and those vars as args
61 % 6) binds X to this call
62 % 7) add new clauses [(dummy:-A)),(dummy:-B))]
63 treat_disj([], Link, Link).
64 treat_disj([disj((A;B),N,X,C)|Disjs], DummyClauses, Link) :-
65 find_vars((A;B),Vars),
66 find_vars(C,CVars),
67 intersect_vars(Vars,CVars,Args),
68 make_dummy_name(N,Name),
69 X =.. [Name|Args],
70 make_dummy_clauses((A;B),X,DummyClauses,Rest),
71 treat_disj(Disjs, Rest, Link).
72
73 make_dummy_clauses((A;B),X,[NewC|Cs],Link) :-
74 !,
75 copy((X:-A), NewC),
76 make_dummy_clauses(B,X,Cs,Link).
77 make_dummy_clauses(A,X,[NewC|Link],Link) :- copy((X:-A),NewC).
78
79 find_vars(X,Y) :- find_vars(X,Y,Link), Link = [].
80
81 find_vars(Var,[Var|Link],Link) :- var(Var), !.
82 find_vars(Cst,Link,Link) :- atomic(Cst), !.
83 find_vars([T|Ts],Vars,NewLink) :- !,
84 find_vars(T,Vars,Link),
85 find_vars(Ts,Link,NewLink).
86 find_vars(Term,Vars,Link) :-
87 Term =.. [_|Args],
88 find_vars(Args,Vars,Link).
89
90 intersect_vars(V1,V2,Out) :-
91 sort_vars(V1,Sorted1),
92 sort_vars(V2,Sorted2),
93 intersect_sorted_vars(Sorted1,Sorted2,Out).
94
95 make_dummy_name(N,Name) :-
96 name('_dummy_',L1),
97 name(N,L2),
98 append(L1,L2,L),
99 name(Name,L).
100
101 append([], L, L).
102 append([H|L1], L2, [H|Res]) :- append(L1, L2, Res).
103
104 % copy_term using a symbol table.
105 copy(Term1, Term2) :-
106 varset(Term1, Set), make_sym(Set, Sym),
107 copy2(Term1, Term2, Sym), !.
108
109 copy2(V1, V2, Sym) :- var(V1), !, retrieve_sym(V1, Sym, V2).
110 copy2(X1, X2, Sym) :- nonvar(X1), !,
111 functor(X1,Name,Arity),
112 functor(X2,Name,Arity),
113 copy2(X1, X2, Sym, 1, Arity).
114
115 copy2(_X1,_X2,_Sym, N, Arity) :- N>Arity, !.
116 copy2(X1, X2, Sym, N, Arity) :- N=<Arity, !,
117 arg(N, X1, Arg1),
118 arg(N, X2, Arg2),
119 copy2(Arg1, Arg2, Sym),
120 N1 is N+1,
121 copy2(X1, X2, Sym, N1, Arity).
122
123 retrieve_sym(V, [p(W,X)|_Sym], X) :- V==W, !.
124 retrieve_sym(V, [_|Sym], X) :- retrieve_sym(V, Sym, X).
125
126 make_sym([], []).
127 make_sym([V|L], [p(V,_)|S]) :- make_sym(L, S).
128
129 % *** Gather all variables used in a term: (in a set or a bag)
130 varset(Term, VarSet) :- varbag(Term, VB),
131 sort(VB, VarSet).
132 varbag(Term, VarBag) :- varbag(Term, VarBag, []).
133
134 varbag(Var) --> {var(Var)}, !, [Var].
135 varbag(Str) --> {nonvar(Str), !, functor(Str,_,Arity)}, varbag(Str, 1, Arity).
136
137 varbag(_Str, N, Arity) --> {N>Arity}, !.
138 varbag(Str, N, Arity) --> {N=<Arity}, !,
139 {arg(N, Str, Arg)}, varbag(Arg),
140 {N1 is N+1},
141 varbag(Str, N1, Arity).
142
143 inst_vars(Term) :-
144 varset(Term, Vars),
145 [A]="A",
146 inst_vars_list(Vars, A).
147
148 inst_vars_list([], _).
149 inst_vars_list([T|L], N) :-
150 name(T, [N]),
151 N1 is N+1,
152 inst_vars_list(L, N1).
153
154 sort_vars(V,Out) :- sort_vars(V,Out,[]).
155 sort_vars([],Link,Link).
156 sort_vars([V|Vs],Result,Link) :-
157 split_vars(Vs,V,Smaller,Bigger),
158 sort_vars(Smaller,Result,[V|SLink]),
159 sort_vars(Bigger,SLink,Link).
160
161 intersect_sorted_vars([],_,[]) :- !.
162 intersect_sorted_vars(_,[],[]).
163 intersect_sorted_vars([X|Xs],[Y|Ys],[X|Rs]) :-
164 X == Y, !,
165 intersect_sorted_vars(Xs,Ys,Rs).
166 intersect_sorted_vars([X|Xs],[Y|Ys],Rs) :-
167 X @< Y, !,
168 intersect_sorted_vars(Xs,[Y|Ys],Rs).
169 intersect_sorted_vars([X|Xs],[Y|Ys],Rs) :-
170 X @> Y, !,
171 intersect_sorted_vars([X|Xs],Ys,Rs).
172
173
174 split_vars([],_,[],[]).
175 split_vars([V|Vs],A,[V|Ss],Bs) :-
176 V @< A, !,
177 split_vars(Vs,A,Ss,Bs).
178 split_vars([V|Vs],A,Ss,Bs) :-
179 V == A, !,
180 split_vars(Vs,A,Ss,Bs).
181 split_vars([V|Vs],A,Ss,[V|Bs]) :-
182 V @> A, !,
183 split_vars(Vs,A,Ss,Bs).
+0
-37
bench/log10.pl less more
0 % generated: 25 October 1989
1 % option(s):
2 %
3 % (deriv) log10
4 %
5 % David H. D. Warren
6 %
7 % symbolic derivative of log(log(log(log(log(log(log(log(log(log(x))))))))))
8
9 top:-log10.
10
11 log10 :- d(log(log(log(log(log(log(log(log(log(log(x)))))))))),x,_).
12
13 d(U+V,X,DU+DV) :- !,
14 d(U,X,DU),
15 d(V,X,DV).
16 d(U-V,X,DU-DV) :- !,
17 d(U,X,DU),
18 d(V,X,DV).
19 d(U*V,X,DU*V+U*DV) :- !,
20 d(U,X,DU),
21 d(V,X,DV).
22 d(U/V,X,(DU*V-U*DV)/(^(V,2))) :- !,
23 d(U,X,DU),
24 d(V,X,DV).
25 d(^(U,N),X,DU*N*(^(U,N1))) :- !,
26 integer(N),
27 N1 is N-1,
28 d(U,X,DU).
29 d(-U,X,-DU) :- !,
30 d(U,X,DU).
31 d(exp(U),X,exp(U)*DU) :- !,
32 d(U,X,DU).
33 d(log(U),X,DU/U) :- !,
34 d(U,X,DU).
35 d(X,X,1) :- !.
36 d(_,_,0).
+0
-104
bench/meta_qsort.pl less more
0 % generated: 8 March 1990
1 % option(s):
2 %
3 % meta_qsort
4 %
5 % Ralph M. Haygood
6 %
7 % meta-interpret Warren benchmark qsort
8 %
9 % For any meta-variable ~X~, interpret(~X~) behaves as if
10 %
11 % interpret(~X~) :- ~X~.
12 %
13 % Thus, for example, interpret((foo(X), bar(X), !)) behaves as if
14 %
15 % interpret((foo(X), bar(X), !)) :- foo(X), bar(X), !.
16 %
17 % Note that though ~X~ may contain cuts, those cuts cannot escape from
18 % interpret(~X~) to effect the parent goal; interpret(!) is equivalent
19 % to true.
20 %
21 % Cuts inside ~X~ are executed according to the rule that conjunction,
22 % disjunction, and if-then-else are transparent to cuts, and any other
23 % form is transparent to cuts if and only if it can be macro-expanded
24 % into a form involving only these three without interpret/1. If-then
25 % and negation are the only such other forms currently recognized; ( A
26 % -> B) is equivalent to ( A -> B ; fail ), and \+ A is equivalent to
27 % ( A -> fail ; true ).
28
29 top:-meta_qsort.
30
31 meta_qsort :- interpret(qsort).
32
33 interpret(Goal) :-
34 interpret(Goal, Rest),
35 ( nonvar(Rest), !,
36 interpret(Rest)
37 ; true
38 ).
39
40 interpret(G, _) :-
41 var(G), !,
42 fail.
43 interpret((A, B), Rest) :- !,
44 interpret(A, Rest0),
45 ( nonvar(Rest0) ->
46 Rest = (Rest0, B)
47 ; interpret(B, Rest)
48 ).
49 interpret((A ; B), Rest) :- !,
50 interpret_disjunction(A, B, Rest).
51 interpret((A -> B), Rest) :- !,
52 interpret_disjunction((A -> B), fail, Rest).
53 interpret(\+A, Rest) :- !,
54 interpret_disjunction((A -> fail), true, Rest).
55 interpret(!, true) :- !.
56 interpret(G, _) :-
57 number(G), !,
58 fail.
59 interpret(G, _) :-
60 is_built_in(G), !,
61 interpret_built_in(G).
62 interpret(G, _) :-
63 define(G, Body),
64 interpret(Body).
65
66 interpret_disjunction((A -> B), _, Rest) :-
67 interpret(A, Rest0), !,
68 ( nonvar(Rest0) ->
69 Rest = (Rest0 -> B)
70 ; interpret(B, Rest)
71 ).
72 interpret_disjunction((_ -> _), C, Rest) :- !,
73 interpret(C, Rest).
74 interpret_disjunction(A, _, Rest) :-
75 interpret(A, Rest).
76 interpret_disjunction(_, B, Rest) :-
77 interpret(B, Rest).
78
79 is_built_in(true).
80 is_built_in(_=<_).
81
82 interpret_built_in(true).
83 interpret_built_in(X=<Y) :- X =< Y.
84
85 define(qsort,(
86 qsort([27,74,17,33,94,18,46,83,65, 2,
87 32,53,28,85,99,47,28,82, 6,11,
88 55,29,39,81,90,37,10, 0,66,51,
89 7,21,85,27,31,63,75, 4,95,99,
90 11,28,61,74,18,92,40,53,59, 8],_,[]))).
91
92 define(qsort([X|L],R,R0),(
93 partition(L,X,L1,L2),
94 qsort(L2,R1,R0),
95 qsort(L1,R,[X|R1]))).
96 define(qsort([],R,R),true).
97
98 define(partition([X|L],Y,[X|L1],L2),(
99 X=<Y,!,
100 partition(L,Y,L1,L2))).
101 define(partition([X|L],Y,L1,[X|L2]),(
102 partition(L,Y,L1,L2))).
103 define(partition([],_,[],[]),true).
+0
-43
bench/mu.pl less more
0 % generated: 9 November 1989
1 % option(s):
2 %
3 % mu
4 %
5 % derived from Douglas R. Hofstadter, "Godel, Escher, Bach," pages 33-35.
6 %
7 % prove "mu-math" theorem muiiu
8
9 top:-mu.
10
11 mu :- theorem([m,u,i,i,u], 5, _), !.
12
13 theorem([m,i], _, [[a|[m,i]]]).
14 theorem(R, Depth, [[N|R]|P]) :-
15 Depth > 0,
16 D is Depth-1,
17 theorem(S, D, P),
18 rule(N, S, R).
19
20 rule(1, S, R) :- rule1(S, R).
21 rule(2, S, R) :- rule2(S, R).
22 rule(3, S, R) :- rule3(S, R).
23 rule(4, S, R) :- rule4(S, R).
24
25 rule1([i], [i,u]).
26 rule1([H|X], [H|Y]) :-
27 rule1(X, Y).
28
29 rule2([m|X], [m|Y]) :-
30 append(X, X, Y).
31
32 rule3([i,i,i|X], [u|X]).
33 rule3([H|X], [H|Y]) :-
34 rule3(X, Y).
35
36 rule4([u,u|X], X).
37 rule4([H|X], [H|Y]) :-
38 rule4(X, Y).
39
40 append([], X, X).
41 append([A|B], X, [A|B1]) :-
42 append(B, X, B1).
+0
-562
bench/nand.pl less more
0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1 %
2 % This is a rough approximation to the algorithm presented in:
3 %
4 % "An Algorithm for NAND Decomposition Under Network Constraints,"
5 % IEEE Trans. Comp., vol C-18, no. 12, Dec. 1969, p. 1098
6 % by E. S. Davidson.
7 %
8 % Written by Bruce Holmer
9 %
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 %
12 % I have used the paper's terminology for names used in the program.
13 %
14 % The data structure for representing functions and variables is
15 % function(FunctionNumber, TrueSet, FalseSet,
16 % ConceivableInputs,
17 % ImmediatePredecessors, ImmediateSuccessors,
18 % Predecessors, Successors)
19 %
20 %
21 % Common names used in the program:
22 %
23 % NumVars number of variables (signal inputs)
24 % NumGs current number of variables and functions
25 % Gs list of variable and function data
26 % Gi,Gj,Gk,Gl individual variable or function--letter corresponds to
27 % the subscript in the paper (most of the time)
28 % Vector,V vector from a function's true set
29 %
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
32 top:-main(0).
33
34 main(N) :-
35 init_state(N, NumVars, NumGs, Gs),
36 add_necessary_functions(NumVars, NumGs, Gs, NumGs2, Gs2),
37 test_bounds(NumVars, NumGs2, Gs2),
38 search(NumVars, NumGs2, Gs2).
39 main(_).
40 % write('Search completed'), nl.
41
42 % Test input
43 % init_state(circuit(NumInputs, NumOutputs, FunctionList))
44 init_state(0, 2, 3, [ % 2 input xor
45 function(2, [1,2], [0,3], [], [], [], [], []),
46 function(1, [2,3], [0,1], [], [], [], [], []),
47 function(0, [1,3], [0,2], [], [], [], [], [])
48 ]) :-
49 update_bounds(_, 100, _).
50 init_state(1, 3, 4, [ % carry circuit
51 function(3, [3,5,6,7], [0,1,2,4], [], [], [], [], []),
52 function(2, [4,5,6,7], [0,1,2,3], [], [], [], [], []),
53 function(1, [2,3,6,7], [0,1,4,5], [], [], [], [], []),
54 function(0, [1,3,5,7], [0,2,4,6], [], [], [], [], [])
55 ]) :-
56 update_bounds(_, 100, _).
57 init_state(2, 3, 4, [ % example in paper
58 function(3, [1,2,4,6,7], [0,3,5], [], [], [], [], []),
59 function(2, [4,5,6,7], [0,1,2,3], [], [], [], [], []),
60 function(1, [2,3,6,7], [0,1,4,5], [], [], [], [], []),
61 function(0, [1,3,5,7], [0,2,4,6], [], [], [], [], [])
62 ]) :-
63 update_bounds(_, 100, _).
64 init_state(3, 3, 4, [ % sum (3 input xor)
65 function(3, [1,2,4,7], [0,3,5,6], [], [], [], [], []),
66 function(2, [4,5,6,7], [0,1,2,3], [], [], [], [], []),
67 function(1, [2,3,6,7], [0,1,4,5], [], [], [], [], []),
68 function(0, [1,3,5,7], [0,2,4,6], [], [], [], [], [])
69 ]) :-
70 update_bounds(_, 100, _).
71 init_state(4, 3, 5, [ % do sum and carry together
72 function(4, [3,5,6,7], [0,1,2,4], [], [], [], [], []),
73 function(3, [1,2,4,7], [0,3,5,6], [], [], [], [], []),
74 function(2, [4,5,6,7], [0,1,2,3], [], [], [], [], []),
75 function(1, [2,3,6,7], [0,1,4,5], [], [], [], [], []),
76 function(0, [1,3,5,7], [0,2,4,6], [], [], [], [], [])
77 ]) :-
78 update_bounds(_, 100, _).
79 init_state(5, 5, 8, [ % 2 bit full adder
80 function(7, % A2 (output)
81 [1,3,4,6,9,11,12,14,16,18,21,23,24,26,29,31],
82 [0,2,5,7,8,10,13,15,17,19,20,22,25,27,28,30],
83 [], [], [], [], []),
84 function(6, % B2 (output)
85 [2,3,5,6,8,9,12,15,17,18,20,21,24,27,30,31],
86 [0,1,4,7,10,11,13,14,16,19,22,23,25,26,28,29],
87 [], [], [], [], []),
88 function(5, % carry-out (output)
89 [7,10,11,13,14,15,19,22,23,25,26,27,28,29,30,31],
90 [0,1,2,3,4,5,6,8,9,12,16,17,18,20,21,24],
91 [], [], [], [], []),
92 function(4, % carry-in
93 [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],
94 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
95 [], [], [], [], []),
96 function(3, % B1 input
97 [8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31],
98 [0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23],
99 [], [], [], [], []),
100 function(2, % B0 input
101 [4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31],
102 [0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27],
103 [], [], [], [], []),
104 function(1, % A1 input
105 [2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31],
106 [0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29],
107 [], [], [], [], []),
108 function(0, % A0 input
109 [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31],
110 [0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30],
111 [], [], [], [], [])
112 ]) :-
113 update_bounds(_, 21, _).
114
115
116 % Iterate over all the TRUE vectors that need to be covered.
117 % If no vectors remain to be covered (select_vector fails), then
118 % the circuit is complete (printout results, update bounds, and
119 % continue search for a lower cost circuit).
120 search(NumVars, NumGsIn, GsIn) :-
121 select_vector(NumVars, NumGsIn, GsIn, Gj, Vector), !,
122 cover_vector(NumVars, NumGsIn, GsIn, Gj, Vector, NumGs, Gs),
123 add_necessary_functions(NumVars, NumGs, Gs, NumGsOut, GsOut),
124 test_bounds(NumVars, NumGsOut, GsOut),
125 search(NumVars, NumGsOut, GsOut).
126 search(NumVars, NumGs, Gs) :-
127 % output_results(NumVars, NumGs, Gs),
128 update_bounds(NumVars, NumGs, Gs),
129 fail.
130
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 % Given the current solution, pick the best uncovered TRUE vector
133 % for covering next.
134 % The selected vector is specified by its vector number and function.
135 % Select_vector fails if all TRUE vectors are covered.
136 % Select_vector is determinant (gives only one solution).
137 select_vector(NumVars, NumGs, Gs, Gj, Vector) :-
138 select_vector(Gs, NumVars, NumGs, Gs,
139 dummy, 0, nf, 999, Gj, Vector, Type, _), !,
140 \+ Type = cov,
141 \+ Type = nf.
142
143 % loop over functions
144 select_vector([Gk|_], NumVars, _, _, Gj, V, Type, N, Gj, V, Type, N) :-
145 function_number(Gk, K),
146 K < NumVars.
147 select_vector([Gk|Gks], NumVars, NumGs, Gs,
148 GjIn, Vin, TypeIn, Nin, GjOut, Vout, TypeOut, Nout) :-
149 function_number(Gk, K),
150 K >= NumVars,
151 true_set(Gk, Tk),
152 select_vector(Tk, Gk, NumVars, NumGs, Gs,
153 GjIn, Vin, TypeIn, Nin, Gj, V, Type, N),
154 select_vector(Gks, NumVars, NumGs, Gs,
155 Gj, V, Type, N, GjOut, Vout, TypeOut, Nout).
156
157 % loop over vectors
158 select_vector([], _, _, _, _, Gj, V, Type, N, Gj, V, Type, N).
159 select_vector([V|Vs], Gk, NumVars, NumGs, Gs,
160 GjIn, Vin, TypeIn, Nin, GjOut, Vout, TypeOut, Nout) :-
161 vector_cover_type(NumVars, Gs, Gk, V, Type, N),
162 best_vector(GjIn, Vin, TypeIn, Nin,
163 Gk, V, Type, N,
164 Gj2, V2, Type2, N2),
165 select_vector(Vs, Gk, NumVars, NumGs, Gs,
166 Gj2, V2, Type2, N2, GjOut, Vout, TypeOut, Nout).
167
168 vector_cover_type(NumVars, Gs, Gj, Vector, Type, NumCovers) :-
169 immediate_predecessors(Gj, IPs),
170 conceivable_inputs(Gj, CIs),
171 false_set(Gj, Fj),
172 cover_type1(IPs, Gs, Vector, nf, 0, T, N),
173 cover_type2(CIs, Gs, NumVars, Fj, Vector, T, N, Type, NumCovers).
174
175 cover_type1([], _, _, T, N, T, N).
176 cover_type1([I|IPs], Gs, V, TypeIn, Nin, TypeOut, Nout) :-
177 function(I, Gs, Gi),
178 true_set(Gi, Ti),
179 \+ set_member(V, Ti), !,
180 false_set(Gi, Fi),
181 (set_member(V, Fi) ->
182 max_type(TypeIn, cov, Type);
183 max_type(TypeIn, exp, Type)),
184 N is Nin + 1,
185 cover_type1(IPs, Gs, V, Type, N, TypeOut, Nout).
186 cover_type1([_|IPs], Gs, V, TypeIn, Nin, TypeOut, Nout) :-
187 cover_type1(IPs, Gs, V, TypeIn, Nin, TypeOut, Nout).
188
189 cover_type2([], _, _, _, _, T, N, T, N).
190 cover_type2([I|CIs], Gs, NumVars, Fj, V, TypeIn, Nin, TypeOut, Nout) :-
191 I < NumVars,
192 function(I, Gs, Gi),
193 false_set(Gi, Fi),
194 set_member(V, Fi), !,
195 max_type(TypeIn, var, Type),
196 N is Nin + 1,
197 cover_type2(CIs, Gs, NumVars, Fj, V, Type, N, TypeOut, Nout).
198 cover_type2([I|CIs], Gs, NumVars, Fj, V, TypeIn, Nin, TypeOut, Nout) :-
199 I >= NumVars,
200 function(I, Gs, Gi),
201 true_set(Gi, Ti),
202 \+ set_member(V, Ti), !,
203 false_set(Gi, Fi),
204 (set_member(V, Fi) ->
205 (set_subset(Fj, Ti) ->
206 max_type(TypeIn, fcn, Type);
207 max_type(TypeIn, mcf, Type));
208 (set_subset(Fj, Ti) ->
209 max_type(TypeIn, exf, Type);
210 max_type(TypeIn, exmcf, Type))),
211 N is Nin + 1,
212 cover_type2(CIs, Gs, NumVars, Fj, V, Type, N, TypeOut, Nout).
213 cover_type2([_|CIs], Gs, NumVars, Fj, V, TypeIn, Nin, TypeOut, Nout) :-
214 cover_type2(CIs, Gs, NumVars, Fj, V, TypeIn, Nin, TypeOut, Nout).
215
216 % The best vector to cover is the one with worst type, or, if types
217 % are equal, with the least number of possible covers.
218 best_vector(dummy, _, _, _, Gj2, V2, Type2, N2, Gj2, V2, Type2, N2) :- !.
219 best_vector(Gj1, V1, Type1, N1, dummy, _, _, _, Gj1, V1, Type1, N1) :- !.
220 best_vector(Gj1, V1, Type, N1, Gj2, _, Type, N2, Gj1, V1, Type, N1) :-
221 function_number(Gj1, J), function_number(Gj2, J),
222 N1 < N2, !.
223 best_vector(Gj1, _, Type, N1, Gj2, V2, Type, N2, Gj2, V2, Type, N2) :-
224 function_number(Gj1, J), function_number(Gj2, J),
225 N1 >= N2, !.
226 best_vector(Gj1, V1, Type, N1, Gj2, _, Type, _, Gj1, V1, Type, N1) :-
227 (Type = exp ; Type = var),
228 function_number(Gj1, J1), function_number(Gj2, J2),
229 J1 > J2, !.
230 best_vector(Gj1, _, Type, _, Gj2, V2, Type, N2, Gj2, V2, Type, N2) :-
231 (Type = exp ; Type = var),
232 function_number(Gj1, J1), function_number(Gj2, J2),
233 J1 < J2, !.
234 best_vector(Gj1, V1, Type, N1, Gj2, _, Type, _, Gj1, V1, Type, N1) :-
235 \+ (Type = exp ; Type = var),
236 function_number(Gj1, J1), function_number(Gj2, J2),
237 J1 < J2, !.
238 best_vector(Gj1, _, Type, _, Gj2, V2, Type, N2, Gj2, V2, Type, N2) :-
239 \+ (Type = exp ; Type = var),
240 function_number(Gj1, J1), function_number(Gj2, J2),
241 J1 > J2, !.
242 best_vector(Gj1, V1, Type1, N1, _, _, Type2, _, Gj1, V1, Type1, N1) :-
243 type_order(Type2, Type1), !.
244 best_vector(_, _, Type1, _, Gj2, V2, Type2, N2, Gj2, V2, Type2, N2) :-
245 type_order(Type1, Type2), !.
246
247 max_type(T1, T2, T1) :- type_order(T1, T2), !.
248 max_type(T1, T2, T2) :- \+ type_order(T1, T2), !.
249
250 % Order of types
251
252 type_order(cov, exp).
253 type_order(cov, var).
254 type_order(cov, fcn).
255 type_order(cov, mcf).
256 type_order(cov, exf).
257 type_order(cov, exmcf).
258 type_order(cov, nf).
259 type_order(exp, var).
260 type_order(exp, fcn).
261 type_order(exp, mcf).
262 type_order(exp, exf).
263 type_order(exp, exmcf).
264 type_order(exp, nf).
265 type_order(var, fcn).
266 type_order(var, mcf).
267 type_order(var, exf).
268 type_order(var, exmcf).
269 type_order(var, nf).
270 type_order(fcn, mcf).
271 type_order(fcn, exf).
272 type_order(fcn, exmcf).
273 type_order(fcn, nf).
274 type_order(mcf, exf).
275 type_order(mcf, exmcf).
276 type_order(mcf, nf).
277 type_order(exf, exmcf).
278 type_order(exf, nf).
279 type_order(exmcf, nf).
280
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282
283 % Cover_vector will cover the specified vector and
284 % generate new circuit information.
285 % Using backtracking, all possible coverings are generated.
286 % The ordering of the possible coverings is approximately that
287 % given in Davidson's paper, but has been simplified.
288
289 cover_vector(NumVars, NumGsIn, GsIn, Gj, Vector, NumGsOut, GsOut) :-
290 immediate_predecessors(Gj, IPs),
291 conceivable_inputs(Gj, CIs),
292 vector_types(Type),
293 cover_vector(Type, IPs, CIs, Gj, Vector, NumVars, NumGsIn, GsIn,
294 NumGsOut, GsOut).
295
296 vector_types(var).
297 vector_types(exp).
298 vector_types(fcn).
299 vector_types(mcf).
300 vector_types(exf).
301 vector_types(exmcf).
302 vector_types(nf).
303
304 cover_vector(exp, [I|_], _, Gj, V, _, NumGs, GsIn, NumGs, GsOut) :-
305 function(I, GsIn, Gi),
306 true_set(Gi, Ti),
307 \+ set_member(V, Ti),
308 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
309 cover_vector(exp, [_|IPs], _, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
310 cover_vector(exp, IPs, _, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
311 cover_vector(var, _, [I|_], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
312 I < NumVars,
313 function(I, GsIn, Gi),
314 false_set(Gi, Fi),
315 set_member(V, Fi),
316 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
317 cover_vector(var, _, [_|CIs], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
318 cover_vector(var, _, CIs, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
319 cover_vector(fcn, _, [I|_], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
320 I >= NumVars,
321 function(I, GsIn, Gi),
322 false_set(Gi, Fi),
323 set_member(V, Fi),
324 true_set(Gi, Ti),
325 false_set(Gj, Fj),
326 set_subset(Fj, Ti),
327 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
328 cover_vector(fcn, _, [_|CIs], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
329 cover_vector(fcn, _, CIs, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
330 cover_vector(mcf, _, [I|_], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
331 I >= NumVars,
332 function(I, GsIn, Gi),
333 false_set(Gi, Fi),
334 set_member(V, Fi),
335 true_set(Gi, Ti),
336 false_set(Gj, Fj),
337 \+ set_subset(Fj, Ti),
338 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
339 cover_vector(mcf, _, [_|CIs], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
340 cover_vector(mcf, _, CIs, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
341 cover_vector(exf, _, [I|_], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
342 I >= NumVars,
343 function(I, GsIn, Gi),
344 false_set(Gi, Fi),
345 \+ set_member(V, Fi),
346 true_set(Gi, Ti),
347 \+ set_member(V, Ti),
348 false_set(Gj, Fj),
349 set_subset(Fj, Ti),
350 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
351 cover_vector(exf, _, [_|CIs], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
352 cover_vector(exf, _, CIs, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
353 cover_vector(exmcf, _, [I|_], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
354 I >= NumVars,
355 function(I, GsIn, Gi),
356 false_set(Gi, Fi),
357 \+ set_member(V, Fi),
358 true_set(Gi, Ti),
359 \+ set_member(V, Ti),
360 false_set(Gj, Fj),
361 \+ set_subset(Fj, Ti),
362 update_circuit(GsIn, Gi, Gj, V, GsIn, GsOut).
363 cover_vector(exmcf, _, [_|CIs], Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut) :-
364 cover_vector(exmcf, _, CIs, Gj, V, NumVars, NumGs, GsIn, NumGs, GsOut).
365 cover_vector(nf, _, _, Gj, V, NumVars, NumGsIn, GsIn, NumGsOut, GsOut) :-
366 NumGsOut is NumGsIn + 1,
367 false_set(Gj, Fj),
368 new_function_CIs(GsIn,
369 function(NumGsIn,Fj,[V],[],[],[],[],[]),
370 NumVars, Gs, Gi),
371 update_circuit(Gs, Gi, Gj, V, Gs, GsOut).
372
373
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375
376 update_circuit([], _, _, _, _, []).
377 update_circuit([function(K,Tk,Fk,CIk,IPk,ISk,Pk,Sk)|GsIn],
378 Gi, Gj, V, Gs,
379 [function(K,Tko,Fko,CIko,IPko,ISko,Pko,Sko)|GsOut]) :-
380 Gi = function(I,_,Fi,_,IPi,ISi,Pi,_),
381 Gj = function(J,_,Fj,_,_,_,_,Sj),
382 set_union([I], Pi, PiI),
383 set_union([J], Sj, SjJ),
384 (K = J ->
385 set_union(Tk, Fi, Tk2);
386 Tk2 = Tk),
387 (K = I ->
388 set_union(Tk2, Fj, Tk3);
389 Tk3 = Tk2),
390 ((set_member(K, IPi); set_member(K, ISi)) ->
391 set_union(Tk3, [V], Tko);
392 Tko = Tk3),
393 (K = I ->
394 set_union(Fk, [V], Fko);
395 Fko = Fk),
396 ((set_member(K, Pi); K = I) ->
397 set_difference(CIk, SjJ, CIk2);
398 CIk2 = CIk),
399 ((set_member(I, CIk), set_member(V, Fk)) ->
400 set_difference(CIk2, [I], CIk3);
401 CIk3 = CIk2),
402 (K = I ->
403 exclude_if_vector_in_false_set(CIk3, Gs, V, CIk4);
404 CIk4 = CIk3),
405 (K = J ->
406 set_difference(CIk4, [I], CIko);
407 CIko = CIk4),
408 (K = J ->
409 set_union(IPk, [I], IPko);
410 IPko = IPk),
411 (K = I ->
412 set_union(ISk, [J], ISko);
413 ISko = ISk),
414 (set_member(K, SjJ) ->
415 set_union(Pk, PiI, Pko);
416 Pko = Pk),
417 (set_member(K, PiI) ->
418 set_union(Sk, SjJ, Sko);
419 Sko = Sk),
420 update_circuit(GsIn, Gi, Gj, V, Gs, GsOut).
421
422 exclude_if_vector_in_false_set([], _, _, []).
423 exclude_if_vector_in_false_set([K|CIsIn], Gs, V, CIsOut) :-
424 function(K, Gs, Gk),
425 false_set(Gk, Fk),
426 set_member(V, Fk), !,
427 exclude_if_vector_in_false_set(CIsIn, Gs, V, CIsOut).
428 exclude_if_vector_in_false_set([K|CIsIn], Gs, V, [K|CIsOut]) :-
429 exclude_if_vector_in_false_set(CIsIn, Gs, V, CIsOut).
430
431
432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433
434 add_necessary_functions(NumVars, NumGsIn, GsIn, NumGsOut, GsOut) :-
435 add_necessary_functions(NumVars, NumVars, NumGsIn, GsIn,
436 NumGsOut, GsOut).
437
438 add_necessary_functions(NumGs, _, NumGs, Gs, NumGs, Gs) :- !.
439 add_necessary_functions(K, NumVars, NumGsIn, GsIn, NumGsOut, GsOut) :-
440 function(K, GsIn, Gk),
441 function_type(NumVars, NumGsIn, GsIn, Gk, nf, V), !,
442 false_set(Gk, Fk),
443 new_function_CIs(GsIn,
444 function(NumGsIn,Fk,[V],[],[],[],[],[]),
445 NumVars, Gs, Gl),
446 function(K, Gs, Gk1),
447 update_circuit(Gs, Gl, Gk1, V, Gs, Gs1),
448 NumGs1 is NumGsIn + 1,
449 K1 is K + 1,
450 add_necessary_functions(K1, NumVars, NumGs1, Gs1, NumGsOut, GsOut).
451 add_necessary_functions(K, NumVars, NumGsIn, GsIn, NumGsOut, GsOut) :-
452 K1 is K + 1,
453 add_necessary_functions(K1, NumVars, NumGsIn, GsIn, NumGsOut, GsOut).
454
455 new_function_CIs(GsIn, function(L,Tl,Fl,_,IPl,ISl,Pl,Sl), NumVars,
456 [GlOut|GsOut], GlOut) :-
457 new_function_CIs(GsIn, L, Fl, NumVars, GsOut, [], CIlo),
458 GlOut = function(L,Tl,Fl,CIlo,IPl,ISl,Pl,Sl).
459
460 new_function_CIs([], _, _, _, [], CIl, CIl).
461 new_function_CIs([function(K,Tk,Fk,CIk,IPk,ISk,Pk,Sk)|GsIn], L, Fl, NumVars,
462 [function(K,Tk,Fk,CIko,IPk,ISk,Pk,Sk)|GsOut], CIlIn, CIlOut) :-
463 set_intersection(Fl, Fk, []), !,
464 (K >= NumVars ->
465 set_union(CIk, [L], CIko);
466 CIko = CIk),
467 new_function_CIs(GsIn, L, Fl, NumVars, GsOut, [K|CIlIn], CIlOut).
468 new_function_CIs([Gk|GsIn], L, Fl, NumVars, [Gk|GsOut], CIlIn, CIlOut) :-
469 new_function_CIs(GsIn, L, Fl, NumVars, GsOut, CIlIn, CIlOut).
470
471 function_type(NumVars, NumGs, Gs, Gk, Type, Vector) :-
472 true_set(Gk, Tk),
473 select_vector(Tk, Gk, NumVars, NumGs, Gs,
474 dummy, 0, nf, 999, _, Vector, Type, _).
475
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 % Cost and constraint predicates:
478
479 % very simple bound for now
480
481 test_bounds(_, NumGs, _) :-
482 access(bound, Bound),
483 NumGs < Bound.
484
485 update_bounds(_, NumGs, _) :-
486 set(bound, NumGs).
487
488 % set and access for systems that don't support them
489 set(N, A) :-
490 (recorded(N, _, Ref) -> erase(Ref) ; true),
491 recorda(N, A, _).
492
493 access(N, A) :-
494 recorded(N, A, _).
495
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 % Output predicates:
498
499 % for now just dump everything
500
501 %output_results(NumVars, NumGs, Gs) :-
502 % NumGates is NumGs - NumVars,
503 % write(NumGates), write(' gates'), nl,
504 % write_gates(Gs), nl,
505 % write('searching for a better solution...'), nl, nl.
506
507 write_gates([]).
508 write_gates([Gi|Gs]) :-
509 function_number(Gi, I),
510 write('gate #'), write(I), write(' inputs: '),
511 immediate_predecessors(Gi, IPi),
512 write(IPi), nl,
513 write_gates(Gs).
514
515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516
517 % Retrieve the specified function from the function list.
518 % function(FunctionNumber, FunctionList, Function).
519 function(I, [Gi|_], Gi) :- function_number(Gi, I), !.
520 function(I, [_|Gs], Gi) :- function(I, Gs, Gi).
521
522 function_number( function(I,_,_,_,_,_,_,_), I).
523 true_set( function(_,T,_,_,_,_,_,_), T).
524 false_set( function(_,_,F,_,_,_,_,_), F).
525 conceivable_inputs( function(_,_,_,CI,_,_,_,_), CI).
526 immediate_predecessors( function(_,_,_,_,IP,_,_,_), IP).
527 immediate_successors( function(_,_,_,_,_,IS,_,_), IS).
528 predecessors( function(_,_,_,_,_,_,P,_), P).
529 successors( function(_,_,_,_,_,_,_,S), S).
530
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 % Set operations assume that the sets are represented by an ordered list
533 % of integers.
534
535 set_union([], [], []).
536 set_union([], [X|L2], [X|L2]).
537 set_union([X|L1], [], [X|L1]).
538 set_union([X|L1], [X|L2], [X|L3]) :- set_union(L1, L2, L3).
539 set_union([X|L1], [Y|L2], [X|L3]) :- X < Y, set_union(L1, [Y|L2], L3).
540 set_union([X|L1], [Y|L2], [Y|L3]) :- X > Y, set_union([X|L1], L2, L3).
541
542 set_intersection([], [], []).
543 set_intersection([], [_|_], []).
544 set_intersection([_|_], [], []).
545 set_intersection([X|L1], [X|L2], [X|L3]) :- set_intersection(L1, L2, L3).
546 set_intersection([X|L1], [Y|L2], L3) :- X < Y, set_intersection(L1, [Y|L2], L3).
547 set_intersection([X|L1], [Y|L2], L3) :- X > Y, set_intersection([X|L1], L2, L3).
548
549 set_difference([], [], []).
550 set_difference([], [_|_], []).
551 set_difference([X|L1], [], [X|L1]).
552 set_difference([X|L1], [X|L2], L3) :- set_difference(L1, L2, L3).
553 set_difference([X|L1], [Y|L2], [X|L3]) :- X < Y, set_difference(L1, [Y|L2], L3).
554 set_difference([X|L1], [Y|L2], L3) :- X > Y, set_difference([X|L1], L2, L3).
555
556 set_subset([], _).
557 set_subset([X|L1], [X|L2]) :- set_subset(L1, L2).
558 set_subset([X|L1], [Y|L2]) :- X > Y, set_subset([X|L1], L2).
559
560 set_member(X, [X|_]).
561 set_member(X, [Y|T]) :- X > Y, set_member(X, T).
+0
-20
bench/nreverse.pl less more
0 % generated: 25 October 1989
1 % option(s):
2 %
3 % nreverse
4 %
5 % David H. D. Warren
6 %
7 % "naive"-reverse a list of 30 integers
8
9 top:-nreverse.
10
11 nreverse :- nreverse([1,2,3,4,5,6,7,8,9,10,11,12,
12 13,14,15,16,17,18,19,20,21,
13 22,23,24,25,26,27,28,29,30],_).
14
15 nreverse([X|L0],L) :- nreverse(L0,L1), concatenate(L1,[X],L).
16 nreverse([],[]).
17
18 concatenate([X|L1],L2,[X|L3]) :- concatenate(L1,L2,L3).
19 concatenate([],L,L).
+0
-37
bench/ops8.pl less more
0 % generated: 25 October 1989
1 % option(s):
2 %
3 % (deriv) ops8
4 %
5 % David H. D. Warren
6 %
7 % symbolic derivative of (x+1)*((^(x,2)+2)*(^(x,3)+3))
8
9 top:-ops8.
10
11 ops8 :- d((x+1)*((^(x,2)+2)*(^(x,3)+3)),x,_).
12
13 d(U+V,X,DU+DV) :- !,
14 d(U,X,DU),
15 d(V,X,DV).
16 d(U-V,X,DU-DV) :- !,
17 d(U,X,DU),
18 d(V,X,DV).
19 d(U*V,X,DU*V+U*DV) :- !,
20 d(U,X,DU),
21 d(V,X,DV).
22 d(U/V,X,(DU*V-U*DV)/(^(V,2))) :- !,
23 d(U,X,DU),
24 d(V,X,DV).
25 d(^(U,N),X,DU*N*(^(U,N1))) :- !,
26 integer(N),
27 N1 is N-1,
28 d(U,X,DU).
29 d(-U,X,-DU) :- !,
30 d(U,X,DU).
31 d(exp(U),X,exp(U)*DU) :- !,
32 d(U,X,DU).
33 d(log(U),X,DU/U) :- !,
34 d(U,X,DU).
35 d(X,X,1) :- !.
36 d(_,_,0).
+0
-93
bench/perfect.pl less more
0 %Create perfect numbers
1
2 top :-
3 findall(C, perfect(100, C), X),
4 ok(X).
5
6 ok([ 3213876088517980551083924184681057554444177758164088967397376,
7 12554203470773361527671578846336104669690446551334525075456,
8 191561942608236107294793378084303638130997321548169216,
9 46768052394588893382517909811217778170473142550528,
10 182687704666362864775460301858080473799697891328,
11 44601490397061246283066714178813853366747136,
12 2787593149816327892690784192460327776944128,
13 10889035741470030830754200461521744560128,
14 2658455991569831744654692615953842176,
15 166153499473114483824745506383331328,
16 40564819207303336344294875201536,
17 9903520314282971830448816128,
18 38685626227663735544086528,
19 2417851639228158837784576,
20 9444732965670570950656,
21 2305843008139952128,
22 144115187807420416,
23 35184367894528,
24 137438691328,
25 8589869056,
26 33550336,
27 2096128,
28 8128,
29 496,
30 28,
31 6
32 ]).
33
34 %divisible(10, 2).
35 divisible(X, Y) :-
36 N is Y*Y,
37 N =< X,
38 X mod Y =:= 0.
39 divisible(X, Y) :-
40 Y < X,
41 Y1 is Y + 1,
42 divisible(X, Y1).
43
44
45 %isprime([3], Z).
46 isprime([X|_], X) :-
47 Y is 2,
48 X > 1,
49 \+ divisible(X, Y).
50 isprime([_|T], Z) :-
51 isprime(T, Z).
52
53
54 %Calculate the power of one number
55 %ie power(2, 10, R)
56 power(_, 0, 1) :- !.
57 power(N, K, R) :-
58 K1 is K-1,
59 power(N, K1, R1),
60 R is R1*N.
61
62
63 %formula of perfect numbers 2^(p-1)*(2^p-1)
64 %ie calc(2, 10, R)
65 calc(2, K, R) :-
66 power(2, K, X),
67 R1 is X-1,
68 power(2, K-1, R2),
69 R is R1 * R2.
70
71 %using lists
72 %ie calc([2, 3, 4], R).
73 listperf([K|_], R) :-
74 calc(2, K, R).
75 listperf([_|T], Z) :-
76 listperf(T, Z).
77
78
79 %generate one list of N numbers.
80 %genList(10, L).
81 generateList(0, []).
82 generateList(N, [X|Xs]) :-
83 N > 0,
84 X is N+1,
85 N1 is N-1, generateList(N1, Xs).
86
87 %list of N perfect numbers
88 %perfect(100, C)
89 perfect(N, C) :-
90 generateList(N, R),
91 findall(L, isprime(R, L), P),
92 listperf(P, C).
+0
-103
bench/poly_10.pl less more
0 % generated: 8 March 1990
1 % option(s): NO_TERM_COMPARE
2 %
3 % (poly) poly_10
4 %
5 % Ralph Haygood (based on Prolog version by Rick McGeer
6 % based on Lisp version by R. P. Gabriel)
7 %
8 % raise a polynomial (1+x+y+z) to the 10th power (symbolically)
9
10 :-op(700,xfx,less_than).
11
12 top:-poly_10.
13
14 poly_10 :- test_poly(P), poly_exp(10, P, _).
15
16 % test polynomial definition
17
18 test_poly(P) :-
19 poly_add(poly(x,[term(0,1),term(1,1)]),poly(y,[term(1,1)]),Q),
20 poly_add(poly(z,[term(1,1)]),Q,P).
21
22 % 'less_than'/2 for x, y, z
23
24 x less_than y.
25 y less_than z.
26 x less_than z.
27
28 % polynomial addition
29
30 poly_add(poly(Var,Terms1), poly(Var,Terms2), poly(Var,Terms)) :- !,
31 term_add(Terms1, Terms2, Terms).
32 poly_add(poly(Var1,Terms1), poly(Var2,Terms2), poly(Var1,Terms)) :-
33 Var1 less_than Var2, !,
34 add_to_order_zero_term(Terms1, poly(Var2,Terms2), Terms).
35 poly_add(Poly, poly(Var,Terms2), poly(Var,Terms)) :- !,
36 add_to_order_zero_term(Terms2, Poly, Terms).
37 poly_add(poly(Var,Terms1), C, poly(Var,Terms)) :- !,
38 add_to_order_zero_term(Terms1, C, Terms).
39 poly_add(C1, C2, C) :-
40 C is C1+C2.
41
42 % term addition
43
44 term_add([], X, X) :- !.
45 term_add(X, [], X) :- !.
46 term_add([term(E,C1)|Terms1], [term(E,C2)|Terms2], [term(E,C)|Terms]) :- !,
47 poly_add(C1, C2, C),
48 term_add(Terms1, Terms2, Terms).
49 term_add([term(E1,C1)|Terms1], [term(E2,C2)|Terms2], [term(E1,C1)|Terms]) :-
50 E1 < E2, !,
51 term_add(Terms1, [term(E2,C2)|Terms2], Terms).
52 term_add(Terms1, [term(E2,C2)|Terms2], [term(E2,C2)|Terms]) :-
53 term_add(Terms1, Terms2, Terms).
54
55 add_to_order_zero_term([term(0,C1)|Terms], C2, [term(0,C)|Terms]) :- !,
56 poly_add(C1, C2, C).
57 add_to_order_zero_term(Terms, C, [term(0,C)|Terms]).
58
59 % polynomial exponentiation
60
61 poly_exp(0, _, 1) :- !.
62 poly_exp(N, Poly, Result) :-
63 M is N>>1,
64 N is M<<1, !,
65 poly_exp(M, Poly, Part),
66 poly_mul(Part, Part, Result).
67 poly_exp(N, Poly, Result) :-
68 M is N-1,
69 poly_exp(M, Poly, Part),
70 poly_mul(Poly, Part, Result).
71
72 % polynomial multiplication
73
74 poly_mul(poly(Var,Terms1), poly(Var,Terms2), poly(Var,Terms)) :- !,
75 term_mul(Terms1, Terms2, Terms).
76 poly_mul(poly(Var1,Terms1), poly(Var2,Terms2), poly(Var1,Terms)) :-
77 Var1 less_than Var2, !,
78 mul_through(Terms1, poly(Var2,Terms2), Terms).
79 poly_mul(P, poly(Var,Terms2), poly(Var,Terms)) :- !,
80 mul_through(Terms2, P, Terms).
81 poly_mul(poly(Var,Terms1), C, poly(Var,Terms)) :- !,
82 mul_through(Terms1, C, Terms).
83 poly_mul(C1, C2, C) :-
84 C is C1*C2.
85
86 term_mul([], _, []) :- !.
87 term_mul(_, [], []) :- !.
88 term_mul([Term|Terms1], Terms2, Terms) :-
89 single_term_mul(Terms2, Term, PartA),
90 term_mul(Terms1, Terms2, PartB),
91 term_add(PartA, PartB, Terms).
92
93 single_term_mul([], _, []) :- !.
94 single_term_mul([term(E1,C1)|Terms1], term(E2,C2), [term(E,C)|Terms]) :-
95 E is E1+E2,
96 poly_mul(C1, C2, C),
97 single_term_mul(Terms1, term(E2,C2), Terms).
98
99 mul_through([], _, []) :- !.
100 mul_through([term(E,Term)|Terms], Poly, [term(E,NewTerm)|NewTerms]) :-
101 poly_mul(Term, Poly, NewTerm),
102 mul_through(Terms, Poly, NewTerms).
+0
-99
bench/prover.pl less more
0 % generated: 30 October 1989
1 % option(s):
2 %
3 % prover
4 %
5 % Richard A. O'Keefe
6 %
7 % Prolog theorem prover
8 %
9 % from "Prolog Compared with Lisp?," SIGPLAN Notices, v. 18 #5, May 1983
10
11 % op/3 directives
12
13 top:-prover.
14
15
16 :- op(950, xfy, #). % disjunction
17 :- op(850, xfy, &). % conjunction
18 :- op(500, fx, +). % assertion
19 :- op(500, fx, -). % denial
20
21 prover :- problem(_, P, C),
22 implies(P, C),
23 fail.
24 prover.
25
26 % problem set
27
28 problem( 1, -a, +a).
29
30 problem( 2, +a, -a & -a).
31
32 problem( 3, -a, +to_be # -to_be).
33
34 problem( 4, -a & -a, -a).
35
36 problem( 5, -a, +b # -a).
37
38 problem( 6, -a & -b, -b & -a).
39
40 problem( 7, -a, -b # (+b & -a)).
41
42 problem( 8, -a # (-b # +c), -b # (-a # +c)).
43
44 problem( 9, -a # +b, (+b & -c) # (-a # +c)).
45
46 problem( 10, (-a # +c) & (-b # +c), (-a & -b) # +c).
47
48 % Prolog theorem prover
49
50 implies(Premise, Conclusion) :-
51 opposite(Conclusion, Denial),
52 add_conjunction(Premise, Denial, fs([],[],[],[])).
53
54 opposite(F0 & G0, F1 # G1) :- !,
55 opposite(F0, F1),
56 opposite(G0, G1).
57 opposite(F1 # G1, F0 & G0) :- !,
58 opposite(F1, F0),
59 opposite(G1, G0).
60 opposite(+Atom, -Atom) :- !.
61 opposite(-Atom, +Atom).
62
63 add_conjunction(F, G, Set) :-
64 expand(F, Set, Mid),
65 expand(G, Mid, New),
66 refute(New).
67
68 expand(_, refuted, refuted) :- !.
69 expand(F & G, fs(D,_,_,_), refuted) :-
70 includes(D, F & G), !.
71 expand(F & G, fs(D,C,P,N), fs(D,C,P,N)) :-
72 includes(C, F & G), !.
73 expand(F & G, fs(D,C,P,N), New) :- !,
74 expand(F, fs(D,[F & G|C],P,N), Mid),
75 expand(G, Mid, New).
76 expand(F # G, fs(D,C,P,N), Set) :- !,
77 opposite(F # G, Conj),
78 extend(Conj, D, C, D1, fs(D1,C,P,N), Set).
79 expand(+Atom, fs(D,C,P,N), Set) :- !,
80 extend(Atom, P, N, P1, fs(D,C,P1,N), Set).
81 expand(-Atom, fs(D,C,P,N), Set) :-
82 extend(Atom, N, P, N1, fs(D,C,P,N1), Set).
83
84 includes([Head|_], Head) :- !.
85 includes([_|Tail], This) :- includes(Tail, This).
86
87 extend(Exp, _, Neg, _, _, refuted) :- includes(Neg, Exp), !.
88 extend(Exp, Pos, _, Pos, Set, Set) :- includes(Pos, Exp), !.
89 extend(Exp, Pos, _, [Exp|Pos], Set, Set).
90
91 refute(refuted) :- !.
92 refute(fs([F1 & G1|D], C, P, N)) :-
93 opposite(F1, F0),
94 opposite(G1, G0),
95 Set = fs(D, C, P, N),
96 add_conjunction(F0, G1, Set),
97 add_conjunction(F0, G0, Set),
98 add_conjunction(F1, G0, Set).
+0
-29
bench/qsort.pl less more
0 % generated: 16 November 1989
1 % option(s): SOURCE_TRANSFORM_1
2 %
3 % qsort
4 %
5 % David H. D. Warren
6 %
7 % quicksort a list of 50 integers
8
9 top:-qsort.
10
11 qsort :- qsort([27,74,17,33,94,18,46,83,65, 2,
12 32,53,28,85,99,47,28,82, 6,11,
13 55,29,39,81,90,37,10, 0,66,51,
14 7,21,85,27,31,63,75, 4,95,99,
15 11,28,61,74,18,92,40,53,59, 8],_,[]).
16
17 qsort([X|L],R,R0) :-
18 partition(L,X,L1,L2),
19 qsort(L2,R1,R0),
20 qsort(L1,R,[X|R1]).
21 qsort([],R,R).
22
23 partition([X|L],Y,[X|L1],L2) :-
24 X =< Y, !,
25 partition(L,Y,L1,L2).
26 partition([X|L],Y,L1,[X|L2]) :-
27 partition(L,Y,L1,L2).
28 partition([],_,[],[]).
+0
-66
bench/queens_8.pl less more
0 % generated: 10 November 1989
1 % option(s):
2 %
3 % (queens) queens_8
4 %
5 % from Sterling and Shapiro, "The Art of Prolog," page 211.
6 %
7 % solve the 8 queens problem
8
9
10 % This program solves the N queens problem: place N pieces on an N
11 % by N rectangular board so that no two pieces are on the same line
12 % - horizontal, vertical, or diagonal. (N queens so placed on an N
13 % by N chessboard are unable to attack each other in a single move
14 % under the rules of chess.) The strategy is incremental generate-
15 % and-test.
16 %
17 % A solution is specified by a permutation of the list of numbers 1 to
18 % N. The first element of the list is the row number for the queen in
19 % the first column, the second element is the row number for the queen
20 % in the second column, et cetera. This scheme implicitly incorporates
21 % the observation that any solution of the problem has exactly one queen
22 % in each column.
23 %
24 % The program distinguishes symmetric solutions. For example,
25 %
26 % ?- queens(4, Qs).
27 %
28 % produces
29 %
30 % Qs = [3,1,4,2] ;
31 %
32 % Qs = [2,4,1,3]
33
34 top:-queens(8,Qs),fail.
35 top.
36
37 queens(N,Qs) :-
38 range(1,N,Ns),
39 queens(Ns,[],Qs).
40
41 queens([],Qs,Qs).
42 queens(UnplacedQs,SafeQs,Qs) :-
43 select(UnplacedQs,UnplacedQs1,Q),
44 not_attack(SafeQs,Q),
45 queens(UnplacedQs1,[Q|SafeQs],Qs).
46
47 not_attack(Xs,X) :-
48 not_attack(Xs,X,1).
49
50 not_attack([],_,_) :- !.
51 not_attack([Y|Ys],X,N) :-
52 X =\= Y+N, X =\= Y-N,
53 N1 is N+1,
54 not_attack(Ys,X,N1).
55
56 select([X|Xs],Xs,X).
57 select([Y|Ys],[Y|Zs],X) :- select(Ys,Zs,X).
58
59 range(N,N,[N]) :- !.
60 range(M,N,[M|Ns]) :-
61 M < N,
62 M1 is M+1,
63 range(M1,N,Ns).
64
65
+0
-81
bench/query.pl less more
0 % generated: 17 November 1989
1 % option(s): SOURCE_TRANSFORM_1
2 %
3 % query
4 %
5 % David H. D. Warren
6 %
7 % query population and area database to find coun-
8 % tries of approximately equal population density
9
10 top:-query.
11
12 query :- query(_), fail.
13 query.
14
15 query([C1,D1,C2,D2]) :-
16 density(C1,D1),
17 density(C2,D2),
18 D1 > D2,
19 T1 is 20*D1,
20 T2 is 21*D2,
21 T1 < T2.
22
23 density(C,D) :-
24 pop(C,P),
25 area(C,A),
26 D is (P*100)//A.
27
28 % populations in 100000's
29 pop(china, 8250).
30 pop(india, 5863).
31 pop(ussr, 2521).
32 pop(usa, 2119).
33 pop(indonesia, 1276).
34 pop(japan, 1097).
35 pop(brazil, 1042).
36 pop(bangladesh, 750).
37 pop(pakistan, 682).
38 pop(w_germany, 620).
39 pop(nigeria, 613).
40 pop(mexico, 581).
41 pop(uk, 559).
42 pop(italy, 554).
43 pop(france, 525).
44 pop(philippines, 415).
45 pop(thailand, 410).
46 pop(turkey, 383).
47 pop(egypt, 364).
48 pop(spain, 352).
49 pop(poland, 337).
50 pop(s_korea, 335).
51 pop(iran, 320).
52 pop(ethiopia, 272).
53 pop(argentina, 251).
54
55 % areas in 1000's of square miles
56 area(china, 3380).
57 area(india, 1139).
58 area(ussr, 8708).
59 area(usa, 3609).
60 area(indonesia, 570).
61 area(japan, 148).
62 area(brazil, 3288).
63 area(bangladesh, 55).
64 area(pakistan, 311).
65 area(w_germany, 96).
66 area(nigeria, 373).
67 area(mexico, 764).
68 area(uk, 86).
69 area(italy, 116).
70 area(france, 213).
71 area(philippines, 90).
72 area(thailand, 200).
73 area(turkey, 296).
74 area(egypt, 386).
75 area(spain, 190).
76 area(poland, 121).
77 area(s_korea, 37).
78 area(iran, 628).
79 area(ethiopia, 350).
80 area(argentina, 1080).
+0
-388
bench/reducer.pl less more
0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1
2 % A Graph Reducer for T-Combinators:
3 % Reduces a T-combinator expression to a final answer. Recognizes
4 % the combinators I,K,S,B,C,S',B',C', cond, apply, arithmetic, tests,
5 % basic list operations, and function definitions in the data base stored
6 % as facts of the form t_def(_func, _args, _expr).
7 % Written by Peter Van Roy
8
9 % Uses write/1, compare/3, functor/3, arg/3.
10 top :-
11 try(fac(3), _ans1),
12 % write(_ans1), nl,
13 try(quick([3,1,2]), _ans2).
14 % write(_ans2), nl.
15
16 try(_inpexpr, _anslist) :-
17 listify(_inpexpr, _list),
18 curry(_list, _curry),
19 t_reduce(_curry, _ans),
20 make_list(_ans, _anslist).
21
22 %% SWI-Prolog V7 compatibility hacks.
23
24 end(X) :- atom(X), !.
25 end(X) :- X == [].
26
27 list_functor_name(Name) :-
28 functor([_|_], Name, _).
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
32 % Examples of applicative functions which can be compiled & executed.
33 % This test version compiles them just before each execution.
34
35 % Factorial function:
36 t_def(fac, [N], cond(N=0, 1, N*fac(N-1))).
37
38 % Quicksort:
39 t_def(quick, [_l], cond(_l=[], [],
40 cond(tl(_l)=[], _l,
41 quick2(split(hd(_l),tl(_l)))))).
42 t_def(quick2, [_l], append(quick(hd(_l)), quick(tl(_l)))).
43
44 t_def(split, [_e,_l], cond(_l=[], [[_e]|[]],
45 cond(hd(_l)=<_e, inserthead(hd(_l),split(_e,tl(_l))),
46 inserttail(hd(_l),split(_e,tl(_l)))))).
47 t_def(inserthead, [_e,_l], [[_e|hd(_l)]|tl(_l)]).
48 t_def(inserttail, [_e,_l], [hd(_l)|[_e|tl(_l)]]).
49
50 t_def(append, [_a,_b], cond(_a=[], _b, [hd(_a)|append(tl(_a),_b)])).
51
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 % Full reduction:
55 % A dot '.' is printed for each reduction step.
56
57 t_reduce(_expr, _ans) :-
58 atomic(_expr), !,
59 _ans=_expr.
60 % The reduction of '$cons' must be here to avoid an infinite loop
61 t_reduce([_y,_x|LF], [_yr,_xr|LF]) :-
62 list_functor_name(LF),
63 t_reduce(_x, _xr),
64 !,
65 t_reduce(_y, _yr),
66 !.
67 t_reduce(_expr, _ans) :-
68 t_append(_next, _red, _form, _expr),
69 % write('.'),
70 t_redex(_form, _red),
71 !,
72 t_reduce(_next, _ans),
73 !.
74
75 t_append(_link, _link, _l, _l).
76 t_append([_a|_l1], _link, _l2, [_a|_l3]) :- t_append(_l1, _link, _l2, _l3).
77
78 % One step of the reduction:
79
80 % Combinators:
81 t_redex([_x,_g,_f,_k|sp], [[_xr|_g],[_xr|_f]|_k]) :- t_reduce(_x, _xr).
82 t_redex([_x,_g,_f,_k|bp], [[_x|_g],_f|_k]).
83 t_redex([_x,_g,_f,_k|cp], [_g,[_x|_f]|_k]).
84 t_redex([_x,_g,_f|s], [[_xr|_g]|[_xr|_f]]) :- t_reduce(_x, _xr).
85 t_redex([_x,_g,_f|b], [[_x|_g]|_f]).
86 t_redex([_x,_g,_f|c], [_g,_x|_f]).
87 t_redex([_y,_x|k], _x).
88 t_redex([_x|i], _x).
89
90 % Conditional:
91 t_redex([_elsepart,_ifpart,_cond|cond], _ifpart) :-
92 t_reduce(_cond, _bool), _bool=true, !.
93 % Does NOT work if _bool is substituted in the call!
94 t_redex([_elsepart,_ifpart,_cond|cond], _elsepart).
95
96 % Apply:
97 t_redex([_f|apply], _fr) :-
98 t_reduce(_f, _fr).
99
100 % List operations:
101 t_redex([_arg|hd], _x) :-
102 list_functor_name(LF),
103 t_reduce(_arg, [_y,_x|LF]).
104 t_redex([_arg|tl], _y) :-
105 list_functor_name(LF),
106 t_reduce(_arg, [_y,_x|LF]).
107
108 % Arithmetic:
109 t_redex([_y,_x|_op], _res) :-
110 end(_op),
111 member(_op, ['+', '-', '*', '//', 'mod']),
112 t_reduce(_x, _xres),
113 t_reduce(_y, _yres),
114 number(_xres), number(_yres),
115 eval(_op, _res, _xres, _yres).
116
117 % Tests:
118 t_redex([_y,_x|_test], _res) :-
119 end(_test),
120 member(_test, [<, >, =<, >=, =\=, =:=]),
121 t_reduce(_x, _xres),
122 t_reduce(_y, _yres),
123 number(_xres), number(_yres),
124 (relop(_test, _xres, _yres)
125 -> _res=true
126 ; _res=false
127 ), !.
128
129 % Equality:
130 t_redex([_y,_x|=], _res) :-
131 t_reduce(_x, _xres),
132 t_reduce(_y, _yres),
133 (_xres=_yres -> _res=true; _res=false), !.
134
135 % Arithmetic functions:
136 t_redex([_x|_op], _res) :-
137 end(_op),
138 member(_op, ['-']),
139 t_reduce(_x, _xres),
140 number(_xres),
141 eval1(_op, _t, _xres).
142
143 % Definitions:
144 % Assumes a fact t_def(_func,_def) in the database for every
145 % defined function.
146 t_redex(_in, _out) :-
147 append(_par,_func,_in),
148 end(_func),
149 t_def(_func, _args, _expr),
150 t(_args, _expr, _def),
151 append(_par,_def,_out).
152
153 % Basic arithmetic and relational operators:
154
155 eval( +, C, A, B) :- C is A + B.
156 eval( -, C, A, B) :- C is A - B.
157 eval( *, C, A, B) :- C is A * B.
158 eval( //, C, A, B) :- C is A // B.
159 eval(mod, C, A, B) :- C is A mod B.
160
161 eval1(-, C, A) :- C is -A.
162
163 relop( <, A, B) :- A<B.
164 relop( >, A, B) :- A>B.
165 relop( =<, A, B) :- A=<B.
166 relop( >=, A, B) :- A>=B.
167 relop(=\=, A, B) :- A=\=B.
168 relop(=:=, A, B) :- A=:=B.
169
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 % Scheme T:
173 % A Translation Scheme for T-Combinators
174
175 % Translate an expression to combinator form
176 % by abstracting out all variables in _argvars:
177 t(_argvars, _expr, _trans) :-
178 listify(_expr, _list),
179 curry(_list, _curry),
180 t_argvars(_argvars, _curry, _trans), !.
181
182 t_argvars([], _trans, _trans).
183 t_argvars([_x|_argvars], _in, _trans) :-
184 t_argvars(_argvars, _in, _mid),
185 t_vars(_mid, _vars), % calculate variables in each subexpression
186 t_trans(_x, _mid, _vars, _trans). % main translation routine
187
188 % Curry the original expression:
189 % This converts an applicative expression of any number
190 % of arguments and any depth of nesting into an expression
191 % where all functions are curried, i.e. all function
192 % applications are to one argument and have the form
193 % [_arg|_func] where _func & _arg are also of that form.
194 % Input is a nested function application in list form.
195 % Currying makes t_trans faster.
196 curry(_a, _a) :- (var(_a); atomic(_a)), !.
197 curry([_func|_args], _cargs) :-
198 currylist(_args, _cargs, _func).
199
200 % Transform [_a1, ..., _aN] to [_cN, ..., _c1|_link]-_link
201 currylist([], _link, _link) :- !.
202 currylist([_a|_args], _cargs, _link) :-
203 curry(_a, _c),
204 currylist(_args, _cargs, [_c|_link]).
205
206 % Calculate variables in each subexpression:
207 % To any expression a list of the form
208 % [_vexpr, _astr, _fstr] is matched.
209 % If the expression is a variable or an atom
210 % then this list only has the first element.
211 % _vexpr = List of all variables in the expression.
212 % _astr, _fstr = Similar structures for argument & function.
213 t_vars(_v, [[_v]]) :- var(_v), !.
214 t_vars(_a, [[]]) :- atomic(_a), !.
215 t_vars([_func], [[]]) :- atomic(_func), !.
216 t_vars([_arg|_func], [_g,[_g1|_af1],[_g2|_af2]]) :-
217 t_vars(_arg, [_g1|_af1]),
218 t_vars(_func, [_g2|_af2]),
219 unionv(_g1, _g2, _g).
220
221 % The main translation routine:
222 % trans(_var, _curriedexpr, _varexpr, _result)
223 % The translation scheme T in the article is followed literally.
224 % A good example of Prolog as a specification language.
225 t_trans(_x, _a, _, [_a|k]) :- (atomic(_a); var(_a), _a\==_x), !.
226 t_trans(_x, _y, _, i) :- _x==_y, !.
227 t_trans(_x, _e, [_ve|_], [_e|k]) :- notinv(_x, _ve).
228 t_trans(_x, [_f|_e], [_vef,_sf,_se], _res) :-
229 _sf=[_vf|_],
230 _se=[_ve|_other],
231 (end(_e); _other=[_,[_ve1|_]], _ve1\==[]),
232 t_rule1(_x, _e, _ve, _se, _f, _vf, _sf, _res).
233 t_trans(_x, [_g|[_f|_e]], [_vefg,_sg,_sef], _res) :-
234 _sg=[_vg|_],
235 _sef=[_vef,_sf,_se],
236 _se=[_ve|_],
237 _sf=[_vf|_],
238 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, _res).
239
240 % First complex rule of translation scheme T:
241 t_rule1(_x, _e, _ve, _se, _f, _vf, _sf, _e) :-
242 notinv(_x, _ve), _x==_f, !.
243 t_rule1(_x, _e, _ve, _se, _f, _vf, _sf, [_resf,_e|b]) :-
244 notinv(_x, _ve), inv(_x, _vf), _x\==_f, !,
245 t_trans(_x, _f, _sf, _resf).
246 t_rule1(_x, _e, _ve, _se, _f, _vf, _sf, [_f,_rese|c]) :-
247 /* inv(_x, _ve), */
248 notinv(_x, _vf), !,
249 t_trans(_x, _e, _se, _rese).
250 t_rule1(_x, _e, _ve, _se, _f, _vf, _sf, [_resf,_rese|s]) :-
251 /* inv(_x, _ve), inv(_x, _vf), */
252 t_trans(_x, _e, _se, _rese),
253 t_trans(_x, _f, _sf, _resf).
254
255 % Second complex rule of translation scheme T:
256 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_g,_e|c]) :-
257 _x==_f, notinv(_x, _vg), !.
258 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_resg,_e|s]) :-
259 _x==_f, /* inv(_x, _vg), */ !,
260 t_trans(_x, _g, _sg, _resg).
261 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_g,_resf,_e|cp]) :-
262 /* _x\==_f, */ inv(_x, _vf), notinv(_x, _vg), !,
263 t_trans(_x, _f, _sf, _resf).
264 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_resg,_resf,_e|sp]) :-
265 /* _x\==_f, */ inv(_x, _vf), /* inv(_x, _vg), */ !,
266 t_trans(_x, _f, _sf, _resf),
267 t_trans(_x, _g, _sg, _resg).
268 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_f|_e]) :-
269 /* notinv(_x, _vf), */ _x==_g, !.
270 t_rule2(_x, _e, _f, _vf, _sf, _g, _vg, _sg, [_resg,_f,_e|bp]) :-
271 /* notinv(_x, _vf), inv(_x, _vg), _x\==_g, */
272 t_trans(_x, _g, _sg, _resg).
273
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275
276 % List utilities:
277
278 % Convert curried list into a regular list:
279 make_list(_a, _a) :- atomic(_a).
280 make_list([_b,_a|LF], [_a|_rb]) :-
281 list_functor_name(LF),
282 make_list(_b, _rb).
283
284 listify(_X, _X) :-
285 (var(_X); atomic(_X)), !.
286 listify(_Expr, [_Op|_LArgs]) :-
287 functor(_Expr, _Op, N),
288 listify_list(1, N, _Expr, _LArgs).
289
290 listify_list(I, N, _, []) :- I>N, !.
291 listify_list(I, N, _Expr, [_LA|_LArgs]) :- I=<N, !,
292 arg(I, _Expr, _A),
293 listify(_A, _LA),
294 I1 is I+1,
295 listify_list(I1, N, _Expr, _LArgs).
296
297 member(X, [X|_]).
298 member(X, [_|L]) :- member(X, L).
299
300 append([], L, L).
301 append([X|L1], L2, [X|L3]) :- append(L1, L2, L3).
302
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304
305 % Set utilities:
306 % Implementation inspired by R. O'Keefe, Practical Prolog.
307 % Sets are represented as sorted lists without duplicates.
308 % Predicates with 'v' suffix work with sets containing uninstantiated vars.
309
310 % *** Intersection
311 intersectv([], _, []).
312 intersectv([A|S1], S2, S) :- intersectv_2(S2, A, S1, S).
313
314 intersectv_2([], _, _, []).
315 intersectv_2([B|S2], A, S1, S) :-
316 compare(Order, A, B),
317 intersectv_3(Order, A, S1, B, S2, S).
318
319 intersectv_3(<, _, S1, B, S2, S) :- intersectv_2(S1, B, S2, S).
320 intersectv_3(=, A, S1, _, S2, [A|S]) :- intersectv(S1, S2, S).
321 intersectv_3(>, A, S1, _, S2, S) :- intersectv_2(S2, A, S1, S).
322
323 intersectv_list([], []).
324 intersectv_list([InS|Sets], OutS) :- intersectv_list(Sets, InS, OutS).
325
326 intersectv_list([]) --> [].
327 intersectv_list([S|Sets]) --> intersectv(S), intersectv_list(Sets).
328
329 % *** Difference
330 diffv([], _, []).
331 diffv([A|S1], S2, S) :- diffv_2(S2, A, S1, S).
332
333 diffv_2([], A, S1, [A|S1]).
334 diffv_2([B|S2], A, S1, S) :-
335 compare(Order, A, B),
336 diffv_3(Order, A, S1, B, S2, S).
337
338 diffv_3(<, A, S1, B, S2, [A|S]) :- diffv(S1, [B|S2], S).
339 diffv_3(=, A, S1, _, S2, S) :- diffv(S1, S2, S).
340 diffv_3(>, A, S1, _, S2, S) :- diffv_2(S2, A, S1, S).
341
342 % *** Union
343 unionv([], S2, S2).
344 unionv([A|S1], S2, S) :- unionv_2(S2, A, S1, S).
345
346 unionv_2([], A, S1, [A|S1]).
347 unionv_2([B|S2], A, S1, S) :-
348 compare(Order, A, B),
349 unionv_3(Order, A, S1, B, S2, S).
350
351 unionv_3(<, A, S1, B, S2, [A|S]) :- unionv_2(S1, B, S2, S).
352 unionv_3(=, A, S1, _, S2, [A|S]) :- unionv(S1, S2, S).
353 unionv_3(>, A, S1, B, S2, [B|S]) :- unionv_2(S2, A, S1, S).
354
355 % *** Subset
356 subsetv([], _).
357 subsetv([A|S1], [B|S2]) :-
358 compare(Order, A, B),
359 subsetv_2(Order, A, S1, S2).
360
361 subsetv_2(=, _, S1, S2) :- subsetv(S1, S2).
362 subsetv_2(>, A, S1, S2) :- subsetv([A|S1], S2).
363
364 % For unordered lists S1:
365 small_subsetv([], _).
366 small_subsetv([A|S1], S2) :- inv(A, S2), small_subsetv(S1, S2).
367
368 % *** Membership
369 inv(A, [B|S]) :-
370 compare(Order, A, B),
371 inv_2(Order, A, S).
372
373 inv_2(=, _, _).
374 inv_2(>, A, S) :- inv(A, S).
375
376 % *** Non-membership
377 notinv(A, S) :- notinv_2(S, A).
378
379 notinv_2([], _).
380 notinv_2([B|S], A) :-
381 compare(Order, A, B),
382 notinv_3(Order, A, S).
383
384 notinv_3(<, _, _).
385 notinv_3(>, A, S) :- notinv_2(S, A).
386
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+0
-169
bench/run.pl less more
0 :- style_check(-singleton).
1
2 run(F) :-
3 run(current_output, F).
4
5 run(S, F):-
6 compile_programs,
7 format(S, '~p~t~18| ~t~w~25| ~t~w~32|~n', ['Program', 'Time', 'GC']),
8 format(S, '~`=t~32|~n', []),
9 forall(program(P, N, F),
10 run_program(P, N, S)).
11
12 :- ( file_search_path(bench, _)
13 -> true
14 ; prolog_load_context(directory, Dir),
15 assert(user:file_search_path(bench, Dir))
16 ).
17
18 compile_programs :-
19 style_check(-singleton),
20 forall(program(P, _),
21 load_files(P:bench(P), [silent(true), if(changed)])).
22
23 run_program(Program, N, S) :-
24 ntimes(Program, N, Time, GC), !,
25 format(S, '~p~t~18| ~t~3f~25| ~t~3f~32|~n', [Program, Time, GC]).
26
27 :- if(statistics(gctime, _)).
28 get_performance_stats(GC, T):-
29 statistics(gctime, GC), % SWI-Prolog
30 statistics(cputime, T).
31 :- else.
32 get_performance_stats(GC, T):-
33 statistics(garbage_collection, [_,_,TGC]),
34 statistics(cputime, [TT,_]),
35 GC is TGC / 1000,
36 T is TT / 1000.
37 :- endif.
38
39 ntimes(M, N, T, GC):-
40 get_performance_stats(GC0, T0),
41 ntimes(M, N),
42 get_performance_stats(GC1, T1),
43 ntimes_dummy(N),
44 get_performance_stats(GC2, T2),
45 T is (T1-T0) - (T2-T1),
46 GC is (GC1-GC0) - (GC2-GC1).
47
48 ntimes(_, N) :- N=:=0, !.
49 ntimes(M, N) :- not_not_top(M), !, N1 is N-1, ntimes(M, N1).
50
51 ntimes_dummy(N) :- N=:=0, !.
52 ntimes_dummy(N) :- not_not_dummy, !, N1 is N-1, ntimes_dummy(N1).
53
54 not_not_top(M) :- not_top(M), !, fail.
55 not_not_top(_).
56
57 not_top(M) :- M:top, !, fail.
58 not_top(_).
59
60 not_not_dummy :- not_dummy, !, fail.
61 not_not_dummy.
62
63 not_dummy :- dummy, !, fail.
64 not_dummy.
65
66 dummy.
67
68 %% tune_counts
69 %
70 % Write the program/2 table below, tuning all counts such that the
71 % test runs for about 1 second.
72
73 tune_counts :-
74 forall(program(P, _),
75 ( tune_count(P, C),
76 format('~q.~n', [program(P, C)]))).
77
78 tune_count(Program, Count) :-
79 between(1, 100, I),
80 C is 1<<I,
81 ntimes(Program, C, T, _),
82 T > 0.5, !,
83 Count is round(C * (1/T)).
84
85 program(P, N, F) :-
86 program(P, N0),
87 N is max(1, round(N0*F)).
88
89 %% program(?Program, ?Times)
90 %
91 % Times are tuned on Jan 24, 2010, using SWI-Prolog 5.9.7 on
92 % AMD 5400+ (gcc 4.4.1; AMD64 mode)
93
94 program(boyer, 8).
95 program(browse, 7).
96 program(chat_parser, 46).
97 program(crypt, 868).
98 program(fast_mu, 4819).
99 program(flatten, 8275).
100 program(meta_qsort, 966).
101 program(mu, 6827).
102 program(nreverse, 11378).
103 program(poly_10, 105).
104 program(prover, 6400).
105 program(qsort, 8445).
106 program(queens_8, 63).
107 program(query, 1219).
108 program(reducer, 164).
109 program(sendmore, 44).
110 program(simple_analyzer, 320).
111 program(tak, 35).
112 program(zebra, 166).
113
114
115 /*******************************
116 * INTERLEAVED *
117 *******************************/
118
119 :- dynamic rni/0.
120
121 run_interleaved(F) :-
122 compile_programs,
123 findall(N-P, program(P, N, F), Pairs),
124 phrase(seq_interleaved(Pairs), Sequence),
125 seq_clause(Sequence, Body),
126 retractall(rni),
127 assert((rni :- Body), Ref),
128 garbage_collect,
129 time(rni),
130 erase(Ref).
131
132 seq_interleaved([]) --> !.
133 seq_interleaved(Pairs) -->
134 seq_interleaved(Pairs, Rest),
135 seq_interleaved(Rest).
136
137 seq_interleaved([], []) -->
138 [].
139 seq_interleaved([1-P|T0], T) --> !,
140 [P],
141 seq_interleaved(T0, T).
142 seq_interleaved([N-P|T0], [N1-P|T]) -->
143 [P],
144 { N1 is N - 1 },
145 seq_interleaved(T0, T).
146
147 seq_clause([], true).
148 seq_clause([H|T], (\+ \+ H:top, G)) :-
149 seq_clause(T, G).
150
151 run_non_interleaved(F) :-
152 compile_programs,
153 findall(N-P, program(P, N, F), Pairs),
154 phrase(seq_non_interleaved(Pairs), Sequence),
155 seq_clause(Sequence, Body),
156 assert((rni :- Body), Ref),
157 garbage_collect,
158 time(rni),
159 erase(Ref).
160
161 seq_non_interleaved([]) -->
162 [].
163 seq_non_interleaved([0-_|T]) --> !,
164 seq_non_interleaved(T).
165 seq_non_interleaved([N-P|T]) -->
166 [P],
167 { N1 is N - 1 },
168 seq_non_interleaved([N1-P|T]).
+0
-322
bench/sdda.pl less more
0 % Sdda3 5-Oct-86
1 % For use on simulator
2
3 %% To do: (look for '%%')
4 %% recursion - keep list of call procedures, ignore recursive calls
5 %% problem: doesn't work for typical procedure working on a list,
6 %% since the list is smaller (different) each time.
7 %% possible optimization: "recognize" base case & skip to it
8 %% follow atoms, g is 'any atom', all others unique, does it work?
9 %% stats - write heapused, cputime to files (as comments)
10 %% worst_case - handle ground terms (copy unify, modify atomic)
11 %% handle disjunction - needs worst_case
12 %% add cuts where possible to save space
13 %% fill in rest of built-ins
14 %% how to handle op?
15 %% Handle assert/retract? call? (If given ground terms- ok, vars- no)
16 %% must have ground functor, definite number of args!
17
18 % Front end for simulator use
19 top :-
20 do_sdda(test,A,B,C).
21
22 % Does the sdda on FileName, instantiates Exitmodes to list of exit modes,
23 % ExitModes structure: [[Funtor/Arity, Activation, Exit], ... ],
24 % e.g. [[a/2, [g,X], [g,g]]
25 do_sdda(FileName, ExitModes, BackList, PredList) :-
26 %%see(FileName),
27 read_procedures(Procs, ExitModes, Entries), % collect all procedures
28 %%seen,
29 % write('Procedures '), nl, write_list(Procs), nl,
30 % write('Entry points '), nl, write_list(Entries), nl,
31 % (nonvar(ExitModes) -> % Don't mention there
32 % (write('Declared exit modes '), nl, % aren't any
33 % write_list(ExitModes), nl) ;
34 % true),
35 entry_exit_modes_list(Procs, ExitModes, Entries).
36 % write('Exit modes '), nl, write_list(ExitModes), nl.
37
38 %%% !!! Hard code in read for test:
39 % sdda_entry(c(A,B,C)).
40 % a(X, Y).
41 % a(X, X).
42 % c(A,B,C) :- a(A,B).
43
44 read_procedures([[a/2,a(_109,_110),a(_148,_148)|_184],
45 [c/3,(c(_191,_192,_193):-a(_191,_192))|_238]|_239],
46 _68,[c(_76,_77,_78)|_102]) :- !.
47
48 % For each entry point in Entries do sdda, building Known, an unbound-tail list
49 % Known structure: [[Name/Arity, ActivationModes, ExitModes], ...|_],
50 % where ActivationModes and ExitModes are lists of variables and the atom 'g'.
51 % 'g' represents a ground element and variables represent equivalence classes.
52 entry_exit_modes_list(_, _, Entries) :- % Done
53 var(Entries).
54 entry_exit_modes_list(ProcList, Known, [Entry|Entries]) :-
55 Entry =.. [Functor|Act], % Get functor/arity & activation
56 length(Act, Arity), % from entry declaration
57 proc_exit_mode(ProcList, Known, [], Functor/Arity, Act, _), % No invoc.
58 entry_exit_modes_list(ProcList, Known, Entries).
59
60 % Do sdda on procedure Functor/Arity, given activation mode Act. Instantiates
61 % Known to known exit modes and Act to exit modes for Functor/Arity under Act
62 proc_exit_mode(_, _, _, Functor/Arity, Act, Exit) :-
63 built_in(Functor/Arity, Act, Exit). % This is a built-in
64 proc_exit_mode(_, Known, _, Functor/Arity, Act, Exit) :-
65 look_up_act([Functor/Arity, Act, Exit], Known). % Already did this
66 proc_exit_mode(ProcList, Known, Invocations, Functor/Arity, Act, Exit) :-
67 umember([Functor/Arity|Clauses], ProcList), % Look up definition
68 dup(Clauses, ClausesCopy), % Don't munge original
69 clause_exit_modes_list(ProcList, Known, Invocations,
70 ClausesCopy, Act, Exits),
71 (Exits=[] -> fail ; true), % didn't find any => fail
72 worst_case(Exits, Exit), % assume the worst
73 dup(Act, ActCopy), % Need copy because Body
74 add_to_list([Functor/Arity, ActCopy, Exit], Known). % binds Act & Exit
75 proc_exit_mode(_, Known, _, Functor/Arity, Act, Exit) :-
76 % write('No such procedure at compile time '),
77 Activation=..[Functor|Act],
78 % write(Activation), nl,
79 all_shared(Act, Exit), % return worst possible - all shared
80 add_to_list([Functor/Arity, Act, Exit], Known).
81
82 % Analyze all clauses for this procedure, instantiate Exits to all exit modes
83 clause_exit_modes_list(_, _, _, Clauses, _, []) :-
84 var(Clauses), !. % No more clauses => done
85 clause_exit_modes_list(ProcList, Known, Invocations,
86 [Clause|Clauses], Act, Exits) :-
87 eqmember([Clause, Act], Invocations), % This is a recursive
88 % write('skipping clause exit mode for '),
89 % write(Clause), write(' '), write(Act), nl,
90 clause_exit_modes_list(ProcList, Known, Invocations, % call, ignore
91 Clauses, Act, Exits). % it
92 clause_exit_modes_list(ProcList, Known, Invocations,
93 [Clause|Clauses], Act, [Exit|Exits]) :-
94 dup(Act, Exit), % We'll bind Exit
95 clause_exit_mode(ProcList, Known, [[Clause, Act]|Invocations],
96 Clause, Exit), % Record invocation
97 clause_exit_modes_list(ProcList, Known, Invocations,
98 Clauses, Act, Exits).
99 clause_exit_modes_list(ProcList, Known, Invocations,
100 [Clause|Clauses], Act, Exits) :- % Unify failed
101 clause_exit_modes_list(ProcList, Known, Invocations,
102 Clauses, Act, Exits).
103
104 % Given activation modes for this clause, return its exit modes
105 clause_exit_mode(ProcList, Known, Invocations, Clause, Act) :-
106 (Clause = ':-'(Head, Body) ; Clause=Head, Body=true), % Decompose it
107 Head =.. [_|Args], % Bind the head
108 unify(Args, Act), % to activation
109 body_exit_mode(ProcList, Known, Invocations, Body). % do the body
110
111 body_exit_mode(ProcList, Known, Invocations, ','(Goal, Goals)) :- % Conjunction
112 body_exit_mode(ProcList, Known, Invocations, Goal), % Do 1st
113 body_exit_mode(ProcList, Known, Invocations, Goals). % & rest
114 body_exit_mode(ProcList, Known, Invocation, Goal) :-
115 functor(Goal, Functor, Arity),
116 Goal =.. [Functor|Act],
117 proc_exit_mode(ProcList, Known, Invocation, Functor/Arity, Act, Exit),
118 unify(Act, Exit).
119
120 % Unifies Left and Right with the special case that the atom 'g' matches
121 % any atom (except [])
122 unify(Left, Left) :- !. % Try standard unify first
123 unify(Left, g) :- % else, is it special case
124 atomic(Left), !,
125 \+ Left=[].
126 unify(g, Right) :-
127 atomic(Right), !,
128 \+ Right=[].
129 unify([LeftHead|LeftTail], [RightHead|RightTail]) :- % or list
130 !, unify(LeftHead, RightHead),
131 unify(LeftTail, RightTail).
132 unify(Left, Right) :- % or structure
133 Left =.. [Functor|LeftArgs],
134 Right =.. [Functor|RightArgs],
135 unify(LeftArgs, RightArgs).
136
137 % Succeed if Left and Right are equivalent, i.e. they are the exact same
138 % with variables renamed
139 equiv(Left, Right) :-
140 equiv(Left, Right, _).
141 equiv(Left, Right, _) :-
142 Left==Right, !.
143 equiv(g, Right, _) :-
144 atomic(Right), !,
145 \+ Right=[].
146 equiv(Left, g, _) :-
147 atomic(Left), !,
148 \+ Left=[].
149 equiv(Left, Right, Bindings) :-
150 var(Left), !,
151 var(Right),
152 equiv_vars(Left, Right, Bindings).
153 equiv(Left, Right, Bindings) :-
154 var(Right), !,
155 var(Left),
156 equiv_vars(Left, Right, Bindings).
157 equiv([LeftHead|LeftTail], [RightHead|RightTail], Bindings) :-
158 !, equiv(LeftHead, RightHead, Bindings),
159 equiv(LeftTail, RightTail, Bindings).
160 equiv(Left, Right, Bindings) :-
161 Left=..[Functor|LeftArgs],
162 Right=..[Functor|RightArgs],
163 equiv(LeftArgs, RightArgs, Bindings).
164
165 equiv_vars(Left, Right, Bindings) :-
166 var(Bindings), !,
167 Bindings=[[Left, Right]|_].
168 equiv_vars(Left, Right, [[AnyVar, AnyBinding]|_]) :-
169 Left==AnyVar, !,
170 Right==AnyBinding.
171 equiv_vars(Left, Right, [[AnyVar, AnyBinding]|_]) :-
172 Right==AnyBinding, !,
173 Left==AnyVar.
174 equiv_vars(Left, Right, [ _|Bindings]) :-
175 equiv_vars(Left, Right, Bindings).
176
177 % Make a copy of Orig with new vars. Copy must be a variable.
178 % E.g. dup([A,s(A,B),[B,C]], New) binds New to [X,s(X,Y),[Y,Z]]
179 dup(Orig, Copy) :-
180 dup(Orig, Copy, _).
181 dup(Orig, Copy, Bindings) :-
182 var(Orig), !,
183 dup_var(Orig, Copy, Bindings).
184 dup(Orig, Orig, _) :- % Atoms, including []
185 atomic(Orig), !.
186 dup([OrigHead|OrigTail], [CopyHead|CopyTail], Bindings) :-
187 !, dup(OrigHead, CopyHead, Bindings),
188 dup(OrigTail, CopyTail, Bindings).
189 dup(Orig, Copy, Bindings) :-
190 Orig=..[Functor|OrigArgs],
191 dup(OrigArgs, CopyArgs, Bindings),
192 Copy=..[Functor|CopyArgs].
193
194 dup_var(Orig, Copy, Bindings) :-
195 var(Bindings), !,
196 Bindings=[[Orig, Copy]|_].
197 dup_var(Orig, Copy, [[AnyVar, Copy]|_]) :-
198 Orig==AnyVar, !.
199 dup_var(Orig, Copy, [_|Bindings]) :-
200 dup_var(Orig, Copy, Bindings).
201
202 % ----- Built-ins ----- %
203
204 built_in(true/0, [], []). % No change
205 built_in(fail/0, [], []). % No change
206 built_in('='/2, [X, Y], [g, g]) :-
207 (atomic(X) ; atomic(Y)). % Ground both if either atomic
208 built_in('='/2, [X, Y], [X, X]). % else bind them
209 built_in(/('+',2), [X, Y], [X, Y]). % No change
210 built_in(/('-',2), [X, Y], [X, Y]). % No change
211 built_in(/('*',2), [X, Y], [X, Y]). % No change
212 built_in(/('/',2), [X, Y], [X, Y]). % No change
213 built_in(/('>=',2), [X, Y], [X, Y]). % No change
214 built_in(/('<',2), [X, Y], [X, Y]). % No change
215 built_in(is/2, [X, Y], [g, Y]). % Ground result
216
217 % ----- Utilities ----- %
218
219 worst_case([], _). %% Doesn't work if any Exits
220 worst_case([Exit|Exits], Worst) :- %% fail to match, e.g.
221 unify(Exit, Worst), %% [[s(1)], [f(1)]].
222 worst_case(Exits, Worst).
223
224 look_up_act(_, Known) :-
225 var(Known),
226 !, fail.
227 look_up_act([Functor/Arity, Act, Exit], [[Functor/Arity, KnownAct, Exit]|_]) :-
228 equiv(Act, KnownAct).
229 look_up_act([Functor/Arity, Act, Exit], [_|Known]) :-
230 look_up_act([Functor/Arity, Act, Exit], Known).
231
232 all_shared(Act, Exit) :- %% Wrong
233 unify(Act, _, VarModesList),
234 bind_all(_, VarModesList),
235 unify(Act, Exit, VarModesList).
236
237 bind_all(_, VarModesList) :-
238 var(VarModesList).
239 bind_all(Mode, [[Var, Mode]|VarModesList]) :-
240 var(Mode),
241 bind_all(Mode, VarModesList).
242 bind_all(Mode, [[_, _]|VarModesList]) :-
243 bind_all(Mode, VarModesList).
244
245
246 % Adds Element to the tail of List, an unbound-tail list
247 add_to_list(Element, List) :-
248 var(List),
249 List=[Element|_].
250 add_to_list(Element, [_|List]) :-
251 add_to_list(Element, List).
252
253 % Membership relation for unbound-tail lists
254 umember(_, List) :-
255 var(List), !, fail.
256 umember(Element, [Element|_]).
257 umember(Element, [_|Tail]) :- umember(Element, Tail).
258
259 % Strict membership relation for unbound-tail lists
260 sumember(_, List) :-
261 var(List), !, fail.
262 sumember(Element, [AnyElement|_]) :- Element==AnyElement.
263 sumember(Element, [_|Tail]) :- sumember(Element, Tail).
264
265 % Membership relation for standard nil-tail lists
266 member(X, [X|_]).
267 member(X, [_|T]) :- member(X, T).
268
269 % Strict membership relation for standard nil-tail lists
270 smember(X, [Y|_]) :- X==Y.
271 smember(X, [_|T]) :- smember(X, T).
272
273 % Equiv membership relation for standard nil-tail lists
274 eqmember(X, [Y|_]) :- equiv(X, Y).
275 eqmember(X, [_|T]) :- eqmember(X, T).
276
277 % Our old favorite
278 concat([], L, L).
279 concat([X|L1], L2, [X|L3]) :- concat(L1, L2, L3).
280
281 % Pretty prints unbound-tail lists -- dies on NIL tail lists
282 %write_list(List) :-
283 % dup(List, NewList),
284 % (var(NewList) -> (name_vars(NewList, 0, _));
285 % write(NewList)) ;
286 % (write('['),
287 % write_list2(NewList, 0, _),
288 % write('|_].'))), % write('].') to write nil tails
289 nl.
290 write_list2([H|T], NextName, NewNextName) :-
291 name_vars(H, NextName, TempNextName),
292 write(H),
293 (nonvar(T) -> (write(','), nl,
294 write(' '),
295 write_list2(T, TempNextName, NewNextName)) ;
296 NewNextName = TempNextName).
297
298 name_vars(Term, NextName, NewNextName) :-
299 var(Term), !,
300 make_name(NextName, Term),
301 NewNextName is NextName + 1.
302 name_vars(Term, NextName, NextName) :-
303 atom(Term), !.
304 name_vars([TermHead|TermTail], NextName, NewNextName) :-
305 !, name_vars(TermHead, NextName, TempNextName),
306 name_vars(TermTail, TempNextName, NewNextName).
307 name_vars(Term, NextName, NewNextName) :-
308 Term =.. [_|TermArgs],
309 name_vars(TermArgs, NextName, NewNextName).
310
311 make_name(IntName, Variable) :-
312 Count is IntName // 26,
313 NewIntName is IntName mod 26 + "A",
314 build_name(Count, NewIntName, Name),
315 name(Variable, Name).
316
317 build_name(0, IntName, [IntName]) :- !.
318 build_name(Count, IntName, [IntName|Rest]) :- Count>0,
319 NewCount is Count - 1,
320 build_name(NewCount, IntName, Rest).
321
+0
-54
bench/sendmore.pl less more
0
1 % Cryptoaddition:
2 % Find the unique answer to:
3 % SEND
4 % +MORE
5 % -----
6 % MONEY
7 % where each letter is a distinct digit.
8
9 top:-
10 digit(D), digit(E), D=\=E,
11 sumdigit(0, D, E, Y, C1),
12 digit(N), N=\=Y, N=\=E, N=\=D,
13 digit(R), R=\=N, R=\=Y, R=\=E, R=\=D,
14 sumdigit(C1,N, R, E, C2),
15 digit(O), O=\=R, O=\=N, O=\=Y, O=\=E, O=\=D,
16 sumdigit(C2,E, O, N, C3),
17 leftdigit(S), S=\=O, S=\=R, S=\=N, S=\=Y, S=\=E, S=\=D,
18 leftdigit(M), M=\=S, M=\=O, M=\=R, M=\=N, M=\=Y, M=\=E, M=\=D,
19 sumdigit(C3,S, M, O, M),
20 % write(' '),write(S),write(E),write(N),write(D),nl,
21 % write('+'),write(M),write(O),write(R),write(E),nl,
22 % write('-----'),nl,
23 % write(M),write(O),write(N),write(E),write(Y),nl,nl,
24 fail.
25 top.
26
27 sumdigit(C, A, B, S, D) :-
28 X is (C+A+B),
29 (X<10
30 -> S=X, D=0
31 ; S is X-10, D=1
32 ).
33
34 digit(0).
35 digit(1).
36 digit(2).
37 digit(3).
38 digit(4).
39 digit(5).
40 digit(6).
41 digit(7).
42 digit(8).
43 digit(9).
44
45 leftdigit(1).
46 leftdigit(2).
47 leftdigit(3).
48 leftdigit(4).
49 leftdigit(5).
50 leftdigit(6).
51 leftdigit(7).
52 leftdigit(8).
53 leftdigit(9).
+0
-40
bench/serialise.pl less more
0 % generated: 17 November 1989
1 % option(s):
2 %
3 % serialise
4 %
5 % David H. D. Warren
6 %
7 % itemize (pick a "serial number" for each
8 % unique integer in) a list of 25 integers
9
10 top:-serialise.
11
12 serialise :- serialise("ABLE WAS I ERE I SAW ELBA",_).
13
14 serialise(L,R) :-
15 pairlists(L,R,A),
16 arrange(A,T),
17 numbered(T,1,_).
18
19 pairlists([X|L],[Y|R],[pair(X,Y)|A]) :- pairlists(L,R,A).
20 pairlists([],[],[]).
21
22 arrange([X|L],tree(T1,X,T2)) :-
23 split(L,X,L1,L2),
24 arrange(L1,T1),
25 arrange(L2,T2).
26 arrange([],void).
27
28 split([X|L],X,L1,L2) :- !, split(L,X,L1,L2).
29 split([X|L],Y,[X|L1],L2) :- before(X,Y), !, split(L,Y,L1,L2).
30 split([X|L],Y,L1,[X|L2]) :- before(Y,X), !, split(L,Y,L1,L2).
31 split([],_,[],[]).
32
33 before(pair(X1,_),pair(X2,_)) :- X1 < X2.
34
35 numbered(tree(T1,pair(_,N1),T2),N0,N) :-
36 numbered(T1,N0,N1),
37 N2 is N1+1,
38 numbered(T2,N2,N).
39 numbered(void,N,N).
+0
-481
bench/simple_analyzer.pl less more
0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1 % Copyright (C) 1990 Peter Van Roy and Regents of the University of California.
2 % All rights reserved. This program may be freely used and modified for
3 % non-commercial purposes provided this copyright notice is kept unchanged.
4 % Written by Peter Van Roy as a part of the Aquarius project.
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6
7 % Benchmark based on the Aquarius compiler flow analyzer version 1.
8 % This program does a dataflow analysis of quicksort using abstract
9 % interpretation. The lattice has two useful values: uninit and ground.
10 % Analysis takes three passes (it prints three 'x' characters).
11 % Builtins used: compare/3, arg/3, functor/3, sort/2, keysort/2, ==/2, \==/2.
12
13 top :- main(_).
14 % main :- main(Table), write(Table), nl.
15
16 main(Table) :-
17 analyze_strees(
18 [stree(main/0,
19 (main:-
20 (qsort([1,2],L,[]),true
21 ;fail
22 )),
23 (main:-true),[],1),
24 stree(qsort/3,
25 (qsort(U,P,Q):-
26 (U=[N|O],part(O,N,R,S),qsort(S,T,Q),qsort(R,P,[N|T]),true
27 ;U=[],Q=P,true
28 ;fail
29 )),
30 (qsort(_,_,_):-true),[],1),
31 stree(part/4,
32 (part(W,X,Y,Z):-
33 ('$cut_load'(A1),'$cut_part/4_1'(W,X,Y,Z,A1),true
34 ;fail
35 )),
36 (part(_,_,_,_):-true),
37 [stree('$cut_part/4_1'/5,
38 ('$cut_part/4_1'(I1,E1,F1,G1,H1):-
39 (I1=[C1|D1],'$fac_$cut_part/4_1/5_2'(D1,E1,F1,G1,H1,C1),true
40 ;I1=[],F1=[],G1=[],true
41 ;fail
42 )),
43 ('$cut_part/4_1'(_,_,_,_,_):-true),
44 [stree('$fac_$cut_part/4_1/5_2'/6,
45 ('$fac_$cut_part/4_1/5_2'(K1,L1,Q1,O1,P1,M1):-
46 (Q1=[M1|N1],M1=<L1,'$cut_shallow'(P1),part(K1,L1,N1,O1),true
47 ;O1=[M1|R1],part(K1,L1,Q1,R1),true
48 ;fail
49 )),
50 ('$fac_$cut_part/4_1/5_2'(_,_,_,_,_,_):-true),[],1)
51 ],1)
52 ],1)
53 ], Table).
54
55 analyze_strees(Strees, OutTable) :-
56 init_strees(Strees, _, Table),
57 seal(Table),
58 analyze_closure(Strees, Table, OutTable).
59
60 % Repeat traversal step until there are no more changes:
61 analyze_closure(Strees, InTable, OutTable) :-
62 traverse_strees(Strees, InTable, MidTable, 0, Changes),
63 % Mark an analysis pass:
64 % put("x"), nl,
65 analyze_closure(Strees, MidTable, OutTable, Changes).
66
67 analyze_closure(Strees, InTable, InTable, N) :- N=<0, !.
68 analyze_closure(Strees, InTable, OutTable, N) :- N>0, !,
69 analyze_closure(Strees, InTable, OutTable).
70
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
73 % Initialize the table of call lattice values:
74
75 init_strees([],_4,_4) :-
76 true.
77 init_strees([_12|_13],_4,_5) :-
78 _12=stree(_14,(_15:-_16),_17,_18,_19),
79 bottom_call(_14,_20),
80 table_command(get(_14,_20),_4,_23),
81 init_disj(_16,_23,_24),
82 init_strees(_18,_24,_25),
83 init_strees(_13,_25,_5),
84 true.
85
86 init_conj(true,_4,_4) :-
87 true.
88 init_conj((_12,_13),_4,_5) :-
89 init_goal(_12,_4,_16),
90 init_conj(_13,_16,_5),
91 true.
92
93 init_disj(fail,_4,_4) :-
94 true.
95 init_disj((_12;_13),_4,_5) :-
96 init_conj(_12,_4,_16),
97 init_disj(_13,_16,_5),
98 true.
99
100 init_goal(_3,_4,_5) :-
101 call_p(_3),
102 !,
103 functor(_3,_12,_13),
104 bottom_call(_12/_13,_14),
105 table_command(get(_12/_13,_14),_4,_5),
106 true.
107 init_goal(_3,_4,_4) :-
108 unify_p(_3),
109 !,
110 true.
111
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 traverse_strees([],_4,_4,_6,_6) :-
115 true.
116 traverse_strees([_14|_15],_4,_5,_6,_7) :-
117 _14=stree(_16,(_17:-_18),_19,_20,_21),
118 traverse_disj(_17,_18,_4,_26,_6,_27),
119 traverse_strees(_20,_26,_28,_27,_29),
120 traverse_strees(_15,_28,_5,_29,_7),
121 true.
122
123 traverse_disj(_3,fail,_5,_5,_7,_7) :-
124 true.
125 traverse_disj(_3,(_15;_16),_5,_6,_7,_8) :-
126 traverse_conj(_3,_15,_5,_22,_7,_23),
127 traverse_disj(_3,_16,_22,_6,_23,_8),
128 true.
129
130 traverse_conj(_3,_4,_5,_6,_7,_8) :-
131 varset(_3,_24),
132 functor(_3,_15,_16),
133 table_command(get(_15/_16,_17),_5,_25),
134 get_entry_modes(uninit,_3,_17,_26),
135 get_entry_modes(ground,_3,_17,_27),
136 traverse_conj(_4,_25,_6,_7,_8,_27,_28,_26,_29,_24,_30),
137 true.
138
139 traverse_conj(true,_4,_4,_6,_6,_8,_8,_10,_10,_12,_12) :-
140 true.
141 traverse_conj((_20,_21),_4,_5,_6,_7,_8,_9,_10,_11,_12,_13) :-
142 varset(_20,_32),
143 update_goal(_20,_32,_4,_33,_6,_34,_8,_35,_10,_36,_12,_37),
144 unionv(_32,_37,_38),
145 traverse_conj(_21,_33,_5,_34,_7,_35,_9,_36,_11,_38,_13),
146 true.
147
148 update_goal(_3,_4,_5,_5,_7,_7,_9,_10,_11,_12,_13,_13) :-
149 split_unify(_3,_21,_27),
150 var(_21),
151 nonvar(_27),
152 varset(_27,_28),
153 subsetv(_28,_9),
154 !,
155 set_command(add(_21),_9,_10),
156 set_command(sub(_21),_11,_12),
157 true.
158 update_goal(_3,_4,_5,_5,_7,_7,_9,_9,_11,_12,_13,_13) :-
159 split_unify(_3,_21,_30),
160 var(_21),
161 nonvar(_30),
162 inv(_21,_11),
163 !,
164 diffv(_4,_13,_31),
165 diffv(_31,_9,_22),
166 set_command(add_set(_22),_11,_32),
167 set_command(sub(_21),_32,_33),
168 intersectv(_4,_13,_23),
169 set_command(sub_set(_23),_33,_12),
170 true.
171 update_goal(_3,_4,_5,_5,_7,_7,_9,_10,_11,_12,_13,_13) :-
172 split_unify(_3,_27,_28),
173 var(_27),
174 inv(_27,_9),
175 !,
176 set_command(add_set(_4),_9,_10),
177 set_command(sub_set(_4),_11,_12),
178 true.
179 update_goal(_3,_4,_5,_5,_7,_7,_9,_9,_11,_12,_13,_13) :-
180 unify_p(_3),
181 !,
182 set_command(sub_set(_4),_11,_12),
183 true.
184 update_goal(_3,_4,_5,_6,_7,_8,_9,_9,_11,_12,_13,_13) :-
185 call_p(_3),
186 !,
187 goal_dupset(_3,_33),
188 var_args(_3,_34),
189 functor(_3,_22,_23),
190 functor(_35,_22,_23),
191 create_new_call(1,_23,_9,_34,_33,_11,_13,_3,_35),
192 update_table(_22/_23,_35,_5,_6,_7,_8),
193 set_command(sub_set(_4),_11,_12),
194 true.
195
196 update_table(_15/_16,_4,_5,_6,_7,_8) :-
197 table_command(get(_15/_16,_18),_5,_24),
198 lub_call(_18,_4,_19),
199 _18\==_19,
200 !,
201 table_command(set(_15/_16,_19),_24,_6),
202 _8 is _7+1,
203 true.
204 update_table(_15/_16,_4,_5,_5,_7,_7).
205
206 create_new_call(I, Ar, _, _, _, _, _, _, _) :- I>Ar, !.
207 create_new_call(I, Ar, Gnd, VarArgs, DupVars, Uni, SoFar, Goal, Call) :-
208 I=<Ar,
209 !,
210 arg(I, Goal, X),
211 arg(I, Call, Y),
212 ground_flag(X, Gnd, Gf),
213 membership_flag(X, VarArgs, Vf),
214 membership_flag(X, DupVars, Df),
215 membership_flag(X, Uni, Uf),
216 membership_flag(X, SoFar, Sf),
217 create_argument(Gf, Vf, Df, Uf, Sf, Y),
218 I1 is I+1,
219 create_new_call(I1, Ar, Gnd, VarArgs, DupVars, Uni, SoFar, Goal, Call).
220
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222
223 % Lattice utilities:
224
225 lub(unknown, X, X) :- !.
226 lub( X, unknown, X) :- !.
227 lub( any, _, any) :- !.
228 lub( _, any, any) :- !.
229 lub( uninit, uninit, uninit) :- !.
230 lub( ground, ground, ground) :- !.
231 lub( uninit, ground, any) :- !.
232 lub( ground, uninit, any) :- !.
233
234 bottom(unknown).
235
236 create_argument(yes, _, _, _, _, ground) :- !. % Ground argument.
237 create_argument( no, yes, no, yes, _, uninit) :- !. % Non-duplicated uninit.
238 create_argument( no, yes, no, _, no, uninit) :- !. % First occurrence.
239 create_argument( no, yes, _, no, yes, any) :- !. % Already initialized.
240 create_argument( no, yes, yes, _, _, any) :- !. % Duplicated argument.
241 create_argument( no, no, _, _, _, any) :- !. % Non-variable argument.
242
243 lub_call(Call1, Call2, Lub) :-
244 functor(Call1, Na, Ar),
245 functor(Call2, Na, Ar),
246 functor(Lub, Na, Ar),
247 lub_call(1, Ar, Call1, Call2, Lub).
248
249 lub_call(I, Ar, _, _, _) :- I>Ar, !.
250 lub_call(I, Ar, Call1, Call2, Lub) :- I=<Ar, !,
251 arg(I, Call1, X1),
252 arg(I, Call2, X2),
253 arg(I, Lub, X),
254 lub(X1, X2, X),
255 I1 is I+1,
256 lub_call(I1, Ar, Call1, Call2, Lub).
257
258 bottom_call(Na/Ar, Bottom) :-
259 functor(Bottom, Na, Ar),
260 bottom_call(1, Ar, Bottom).
261
262 bottom_call(I, Ar, Bottom) :- I>Ar, !.
263 bottom_call(I, Ar, Bottom) :- I=<Ar, !,
264 bottom(B),
265 arg(I, Bottom, B),
266 I1 is I+1,
267 bottom_call(I1, Ar, Bottom).
268
269 lattice_modes_call(Na/Ar, Table, (Head:-Formula)) :-
270 functor(Head, Na, Ar),
271 get(Table, Na/Ar, Value),
272 lattice_modes_call(1, Ar, Value, Head, Formula, true).
273
274 lattice_modes_call(I, Ar, _, _, Link, Link) :- I>Ar, !.
275 lattice_modes_call(I, Ar, Value, Head, Formula, Link) :- I=<Ar, !,
276 arg(I, Value, T),
277 arg(I, Head, X),
278 lattice_modes_arg(T, X, Formula, Mid),
279 I1 is I+1,
280 lattice_modes_call(I1, Ar, Value, Head, Mid, Link).
281
282 lattice_modes_arg(uninit, X, (uninit(X),Link), Link) :- !.
283 lattice_modes_arg(ground, X, (ground(X),Link), Link) :- !.
284 lattice_modes_arg( Other, X, Link, Link).
285
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287
288 % Table utilities:
289
290 % This code implements a mutable array, represented as a binary tree.
291
292 % Access a value in logarithmic time and constant space:
293 % This predicate can be used to create the array incrementally.
294 get(node(N,W,L,R), I, V) :- get(N, W, L, R, I, V).
295
296 get(N, V, _, _, I, V) :- I=N, !.
297 get(N, _, L, R, I, V) :-
298 compare(Order, I, N),
299 get(Order, I, V, L, R).
300
301 get(<, I, V, L, _) :- get(L, I, V).
302 get(>, I, V, _, R) :- get(R, I, V).
303
304 set(leaf, I, V, node(I,V,leaf,leaf)).
305 set(node(N,W,L,R), I, V, node(N,NW,NL,NR)) :-
306 compare(Order, I, N),
307 set_2(Order, I, V, W, L, R, NW, NL, NR).
308
309 set_2(<, I, V, W, L, R, W, NL, R) :- set(L, I, V, NL).
310 set_2(=, I, V, _, L, R, V, L, R).
311 set_2(>, I, V, W, L, R, W, L, NR) :- set(R, I, V, NR).
312
313 % Prevent any further insertions in the array:
314 seal(leaf).
315 seal(node(_,_,L,R)) :- seal(L), seal(R).
316
317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318
319 % General utilities:
320
321 membership_flag(X, Set, yes) :- inv(X, Set), !.
322 membership_flag(X, Set, no).
323
324 ground_flag(X, Ground, yes) :- varset(X, Set), subsetv(Set, Ground), !.
325 ground_flag(X, Ground, no).
326
327 get_entry_modes(Type, Head, Value, TypeSet) :-
328 functor(Head, Na, Ar),
329 get_entry_modes(Type, 1, Ar, Head, Value, Bag),
330 sort(Bag, TypeSet).
331
332 get_entry_modes(_, I, Ar, _, _, []) :- I>Ar, !.
333 get_entry_modes(T, I, Ar, Head, Value, [X|Bag]) :- I=<Ar, arg(I, Value, T), !,
334 arg(I, Head, X),
335 I1 is I+1,
336 get_entry_modes(T, I1, Ar, Head, Value, Bag).
337 get_entry_modes(T, I, Ar, Head, Value, Bag) :- I=<Ar, !,
338 I1 is I+1,
339 get_entry_modes(T, I1, Ar, Head, Value, Bag).
340
341 var_args(Goal, Set) :-
342 functor(Goal, _, Ar),
343 filter_vars(Ar, Goal, Bag),
344 sort(Bag, Set).
345
346 filter_vars(Ar, Goal, Vs) :- filter_vars(Ar, Goal, Vs, []).
347
348 filter_vars(N, Goal) --> {N=<0}, !.
349 filter_vars(N, Goal) --> {N>0}, !,
350 {arg(N, Goal, V)},
351 filter_vars_arg(N, Goal, V).
352
353 filter_vars_arg(N, Goal, V) --> {var(V)}, !, [V],
354 {N1 is N-1},
355 filter_vars(N1, Goal).
356 filter_vars_arg(N, Goal, V) --> {nonvar(V)}, !,
357 {N1 is N-1},
358 filter_vars(N1, Goal).
359
360 goal_dupset(Goal, DupSet) :-
361 goal_dupset_varbag(Goal, DupSet, _).
362
363 goal_dupset_varset(Goal, DupSet, VarSet) :-
364 goal_dupset_varbag(Goal, DupSet, VarBag),
365 sort(VarBag, VarSet).
366
367 goal_dupset_varbag(Goal, DupSet, VarBag) :-
368 varbag(Goal, VarBag),
369 make_key(VarBag, KeyBag),
370 keysort(KeyBag, KeySet),
371 filter_dups(KeySet, DupSet).
372
373 make_key([], []).
374 make_key([V|Bag], [V-dummy|KeyBag]) :- make_key(Bag, KeyBag).
375
376 filter_dups(KeySet, Set) :- filter_dups(KeySet, Set, []).
377
378 filter_dups([]) --> !.
379 filter_dups([V1-_,V2-_,V3-_|KeySet]) --> {V1==V2,V2==V3}, !,
380 filter_dups([V2-_,V3-_|KeySet]).
381 filter_dups([V1-_,V2-_|KeySet]) --> {V1==V2}, !,
382 [V1], filter_dups(KeySet).
383 filter_dups([V1-_|KeySet]) --> !,
384 filter_dups(KeySet).
385
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
388 % Low-level utilities:
389
390 set_command(sub(X), In, Out) :- diffv(In, [X], Out).
391 set_command(add(X), In, Out) :- includev(X, In, Out).
392 set_command(sub_set(X), In, Out) :- diffv(In, X, Out).
393 set_command(add_set(X), In, Out) :- unionv(X, In, Out).
394
395 table_command(get(I,Val), In, In) :- get(In, I, Val).
396 table_command(set(I,Val), In, Out) :- set(In, I, Val, Out).
397
398 % Set utilities inspired by R. O'Keefe in Practical Prolog:
399 inv(A, [B|S]) :-
400 compare(Order, A, B),
401 inv_2(Order, A, S).
402
403 inv_2(=, _, _).
404 inv_2(>, A, S) :- inv(A, S).
405
406 intersectv([], _, []).
407 intersectv([A|S1], S2, S) :- intersectv_2(S2, A, S1, S).
408
409 intersectv_2([], A, S1, []).
410 intersectv_2([B|S2], A, S1, S) :-
411 compare(Order, A, B),
412 intersectv_3(Order, A, S1, B, S2, S).
413
414 intersectv_3(<, A, S1, B, S2, S) :- intersectv_2(S1, B, S2, S).
415 intersectv_3(=, A, S1, _, S2, [A|S]) :- intersectv(S1, S2, S).
416 intersectv_3(>, A, S1, B, S2, S) :- intersectv_2(S2, A, S1, S).
417
418 diffv([], _, []).
419 diffv([A|S1], S2, S) :- diffv_2(S2, A, S1, S).
420
421 diffv_2([], A, S1, [A]).
422 diffv_2([B|S2], A, S1, S) :-
423 compare(Order, A, B),
424 diffv_3(Order, A, S1, B, S2, S).
425
426 diffv_3(<, A, S1, B, S2, [A|S]) :- diffv(S1, [B|S2], S).
427 diffv_3(=, A, S1, _, S2, S) :- diffv(S1, S2, S).
428 diffv_3(>, A, S1, _, S2, S) :- diffv_2(S2, A, S1, S).
429
430 unionv([], S2, S2).
431 unionv([A|S1], S2, S) :- unionv_2(S2, A, S1, S).
432
433 unionv_2([], A, S1, [A|S1]).
434 unionv_2([B|S2], A, S1, S) :-
435 compare(Order, A, B),
436 unionv_3(Order, A, S1, B, S2, S).
437
438 unionv_3(<, A, S1, B, S2, [A|S]) :- unionv_2(S1, B, S2, S).
439 unionv_3(=, A, S1, _, S2, [A|S]) :- unionv(S1, S2, S).
440 unionv_3(>, A, S1, B, S2, [B|S]) :- unionv_2(S2, A, S1, S).
441
442 includev(A, S1, S) :- includev_2(S1, A, S).
443
444 includev_2([], A, [A]).
445 includev_2([B|S1], A, S) :-
446 compare(Order, A, B),
447 includev_3(Order, A, B, S1, S).
448
449 includev_3(<, A, B, S1, [A,B|S1]).
450 includev_3(=, _, B, S1, [B|S1]).
451 includev_3(>, A, B, S1, [B|S]) :- includev_2(S1, A, S).
452
453 subsetv([], _).
454 subsetv([A|S1], [B|S2]) :-
455 compare(Order, A, B),
456 subsetv_2(Order, A, S1, S2).
457
458 subsetv_2(=, A, S1, S2) :- subsetv(S1, S2).
459 subsetv_2(>, A, S1, S2) :- subsetv([A|S1], S2).
460
461 varset(Term, VarSet) :- varbag(Term, VB), sort(VB, VarSet).
462 varbag(Term, VarBag) :- varbag(Term, VarBag, []).
463
464 varbag(Var) --> {var(Var)}, !, [Var].
465 varbag(Str) --> {nonvar(Str), !, functor(Str,_,Arity)}, varbag(Str, 1, Arity).
466
467 varbag(_Str, N, Arity) --> {N>Arity}, !.
468 varbag(Str, N, Arity) --> {N=<Arity}, !,
469 {arg(N, Str, Arg)}, varbag(Arg),
470 {N1 is N+1},
471 varbag(Str, N1, Arity).
472
473 unify_p(_=_).
474
475 call_p(G) :- \+unify_p(G).
476
477 split_unify(X=Y, X, Y).
478 split_unify(Y=X, X, Y).
479
480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+0
-25
bench/tak.pl less more
0 % generated: 17 November 1989
1 % option(s): SOURCE_TRANSFORM_1
2 %
3 % tak
4 %
5 % Evan Tick (from Lisp version by R. P. Gabriel)
6 %
7 % (almost) Takeuchi function (recursive arithmetic)
8
9 top:-tak.
10
11 tak :- tak(18,12,6,_).
12
13 tak(X,Y,Z,A) :-
14 X =< Y,
15 Z = A.
16 tak(X,Y,Z,A) :-
17 X > Y,
18 X1 is X - 1,
19 tak(X1,Y,Z,A1),
20 Y1 is Y - 1,
21 tak(Y1,Z,X,A2),
22 Z1 is Z - 1,
23 tak(Z1,X,Y,A3),
24 tak(A1,A2,A3,A).
+0
-37
bench/times10.pl less more
0 % generated: 7 March 1990
1 % option(s):
2 %
3 % (deriv) times10
4 %
5 % David H. D. Warren
6 %
7 % symbolic derivative of ((((((((x*x)*x)*x)*x)*x)*x)*x)*x)*x
8
9 top:-times10.
10
11 times10 :- d(((((((((x*x)*x)*x)*x)*x)*x)*x)*x)*x,x,_).
12
13 d(U+V,X,DU+DV) :- !,
14 d(U,X,DU),
15 d(V,X,DV).
16 d(U-V,X,DU-DV) :- !,
17 d(U,X,DU),
18 d(V,X,DV).
19 d(U*V,X,DU*V+U*DV) :- !,
20 d(U,X,DU),
21 d(V,X,DV).
22 d(U/V,X,(DU*V-U*DV)/(^(V,2))) :- !,
23 d(U,X,DU),
24 d(V,X,DV).
25 d(^(U,N),X,DU*N*(^(U,N1))) :- !,
26 integer(N),
27 N1 is N-1,
28 d(U,X,DU).
29 d(-U,X,-DU) :- !,
30 d(U,X,DU).
31 d(exp(U),X,exp(U)*DU) :- !,
32 d(U,X,DU).
33 d(log(U),X,DU/U) :- !,
34 d(U,X,DU).
35 d(X,X,1) :- !.
36 d(_,_,0).
+0
-158
bench/unify.pl less more
0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1 % Copyright (C) 1990 Regents of the University of California.
2 % All rights reserved. This program may be freely used and modified for
3 % non-commercial purposes provided this copyright notice is kept unchanged.
4 % Written by Peter Van Roy as a part of the Aquarius project.
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6
7 % Benchmark based on part of Aquarius Prolog compiler
8 % Compiling unification into abstract machine code.
9
10 top :- main(X).
11 %, write(X), nl.
12
13 main(Size) :- u(X, [1,Y], [X], Code), size(Code, 0, Size).
14
15 % Unify variable X with term T and write the result:
16 u(X, T, In, Code) :- unify(X, T, In, _, Code, []).
17
18 % Unify the variable X with the term T, given that
19 % In = set of variables initialized before the unification.
20 % Returns the intermediate code for the unification and
21 % Out = set of variables initialized after the unification.
22 unify(X, T, In, Out) --> {\+myin(X, In)}, !, uninit(X, T, In, Out).
23 unify(X, T, In, Out) --> {myin(X, In)}, !, init(X, T, In, Out, nonlast, _).
24
25 %**** Uninit assumes X has not yet been initialized:
26 uninit(X, T, In, Out) --> {my_compound(T)}, !, [move(Tag^h, X)],
27 {termtag(T, Tag)}, unify_block(nonlast, T, _, In, Mid, _), {incl(X, Mid, Out)}.
28 uninit(X, T, In, Out) --> {atomic(T)}, !, [move(tatm^T, X)], {incl(X, In, Out)}.
29 uninit(X, T, In, Out) --> {var(T)}, !, unify_var(X, T, In, Out).
30
31 %**** Init assumes X has already been initialized:
32 init(X, T, In, Out, Last, LLbls) --> {nonvar(T)}, !,
33 {termtag(T,Tag)}, [deref(X), switch(Tag,X,[trail(X) | Write],Read,fail)],
34 {unify_writemode(X, T, In, Last, LLbls, Write, [])},
35 {unify_readmode(X, T, In, Out, LLbls, Read, [])}.
36 init(X, T, In, Out, _, _) --> {var(T)}, !, unify_var(X, T, In, Out).
37
38 %**** Unifying two variables together:
39 unify_var(X, Y, In, In) --> { myin(X, In), myin(Y, In)}, !, [unify(X,Y,fail)].
40 unify_var(X, Y, In, Out) --> { myin(X, In), \+myin(Y, In)}, !, [move(X,Y)], {incl(Y, In, Out)}.
41 unify_var(X, Y, In, Out) --> {\+myin(X, In), myin(Y, In)}, !, [move(Y,X)], {incl(X, In, Out)}.
42 unify_var(X, Y, In, Out) --> {\+myin(X, In), \+myin(Y, In)}, !,
43 [move(tvar^h,X), move(tvar^h,Y), add(1,h), move(Y,[h-1])],
44 {incl(X, In, Mid), incl(Y, Mid, Out)}.
45
46 %**** Unify_readmode assumes X is a dereferenced nonvariable
47 % at run-time and T is a nonvariable at compile-time.
48 unify_readmode(X, T, In, Out, LLbls) --> {structure(T)}, !, [equal([X],tatm^(F/N),fail)],
49 {functor(T, F, N)}, unify_args(1, N, T, In, Out, 0, X, LLbls).
50 unify_readmode(X, T, In, Out, LLbls) --> {cons(T)}, !,
51 unify_args(1, 2, T, In, Out, -1, X, LLbls).
52 unify_readmode(X, T, In, In, _) --> {atomic(T)}, !, [equal(X,tatm^T,fail)].
53
54 unify_args(I, N, _, In, In, _, _, _) --> {I>N}, !.
55 unify_args(I, N, T, In, Out, D, X, [ _ | LLbls]) --> {I=N}, !,
56 unify_arg(I, T, In, Out, D, X, last, LLbls).
57 unify_args(I, N, T, In, Out, D, X, LLbls) --> {I<N}, !,
58 unify_arg(I, T, In, Mid, D, X, nonlast, _),
59 {I1 is I+1}, unify_args(I1, N, T, Mid, Out, D, X, LLbls).
60
61 unify_arg(I, T, In, Out, D, X, Last, LLbls) --> [move([X+ID],Y)],
62 {ID is I+D, incl(Y, In, Mid), arg(I, T, A)},
63 init(Y, A, Mid, Out, Last, LLbls).
64
65
66
67 %**** Unify_writemode assumes X is a dereferenced unbound
68 % variable at run-time and T is a nonvariable at compile-time.
69 unify_writemode(X, T, In, Last, LLbls) --> {my_compound(T)}, !, [move(Tag^h,[X])],
70 {termtag(T, Tag)}, unify_block(Last, T, _, In, _, LLbls).
71 unify_writemode(X, T, _, _, _) --> {atomic(T)}, !, [move(tatm^T,[X])].
72
73
74 %**** Generate a minimal sequence of moves to create T on the heap:
75 unify_block( last, T, Size, In, In, [Lbl | _ ]) --> !, [add(Size,h), jump(Lbl)],
76 {size(T, 0, Size)}.
77 unify_block(nonlast, T, Size, In, Out, [ _ | LLbls]) --> !, [add(Size,h)],
78 {size(T, 0, Size), Offset is -Size}, block(T, Offset, 0, In, Out, LLbls).
79
80 block(T, Inf, Outf, In, Out, LLbls) --> {structure(T)}, !, [move(tatm^(F/N), [h+Inf])],
81 {functor(T, F, N), Midf is Inf+N+1, S is Inf+1},
82 make_slots(1, N, T, S, Offsets, In, Mid),
83 block_args(1, N, T, Midf, Outf, Offsets, Mid, Out, LLbls).
84 block(T, Inf, Outf, In, Out, LLbls) --> {cons(T)}, !,
85 {Midf is Inf+2},
86 make_slots(1, 2, T, Inf, Offsets, In, Mid),
87 block_args(1, 2, T, Midf, Outf, Offsets, Mid, Out, LLbls).
88 block(T, Inf, Inf, In, In, []) --> {atomic(T)}, !.
89 block(T, Inf, Inf, In, In, []) --> {var(T)}, !.
90
91 block_args(I, N, _, Inf, Inf, [], In, In, []) --> {I>N}, !.
92 block_args(I, N, T, Inf, Outf, [Inf], In, Out, [Lbl | LLbls]) --> {I=N}, !, [label(Lbl)],
93 {arg(I, T, A)}, block(A, Inf, Outf, In, Out, LLbls).
94 block_args(I, N, T, Inf, Outf, [Inf | Offsets], In,Out,LLbls) --> {I<N}, !,
95 {arg(I, T, A)}, block(A, Inf, Midf, In, Mid, _), {I1 is I+1},
96 block_args(I1, N, T, Midf, Outf, Offsets, Mid, Out, LLbls).
97
98 make_slots(I, N, _, _, [], In, In) --> {I>N}, !.
99 make_slots(I, N, T, S, [Off | Offsets], In, Out) --> {I=<N}, !,
100 {arg(I, T, A)}, init_var(A, S, In),
101 {incl(A, In, Mid), make_word(A, Off, Word)}, [move(Word,[h+S])],
102 {S1 is S+1, I1 is I+1},
103 make_slots(I1, N, T, S1, Offsets, Mid, Out).
104
105
106 % Initialize first-time variables in write mode:
107 init_var(V, I, In) --> {var(V), \+myin(V, In)}, !, [move(tvar^(h+I),V)].
108 init_var(V, _, In) --> {var(V), myin(V, In)}, !.
109 init_var(V, _, _) --> {nonvar(V)}, !.
110
111 make_word(C, Off, Tag^(h+Off)) :- my_compound(C), !, termtag(C, Tag).
112 make_word(V, _, V) :- var(V), !.
113 make_word(A, _, tatm^A) :- atomic(A), !.
114
115 % Calculate the size of T on the heap:
116 size(T) --> {structure(T)}, !, {functor(T, _, N)}, add(1), add(N), size_args(1, N, T).
117 size(T) --> {cons(T)}, !, add(2), size_args(1, 2, T).
118 size(T) --> {atomic(T)}, !.
119 size(T) --> {var(T)}, !.
120
121 size_args(I, N, _) --> {I>N}, !.
122 size_args(I, N, T) --> {I=<N}, !, {arg(I, T, A)}, size(A), {I1 is I+1}, size_args(I1, N, T).
123
124 %**** Utility routines:
125
126 add(I, X, Y) :- Y is X+I.
127
128 myin(A, [B|S]) :-
129 compare(Order, A, B),
130 in_2(Order, A, S).
131
132 in_2(=, _, _).
133 in_2(>, A, S) :- myin(A, S).
134
135 incl(A, S1, S) :- incl_2(S1, A, S).
136
137 incl_2([], A, [A]).
138 incl_2([B|S1], A, S) :-
139 compare(Order, A, B),
140 incl_3(Order, A, B, S1, S).
141
142 incl_3(<, A, B, S1, [A,B|S1]).
143 incl_3(=, _, B, S1, [B|S1]).
144 incl_3(>, A, B, S1, [B|S]) :- incl_2(S1, A, S).
145
146 my_compound(X) :- nonvar(X), \+atomic(X).
147 cons(X) :- nonvar(X), X=[_|_].
148 structure(X) :- my_compound(X), \+X=[_|_].
149
150 termtag(T, tstr) :- structure(T).
151 termtag(T, tlst) :- cons(T).
152 termtag(T, tatm) :- atomic(T).
153 termtag(T, tvar) :- var(T).
154
155
156
157
+0
-44
bench/zebra.pl less more
0 % Where does the zebra live?
1 % Puzzle solution written by Claude Sammut.
2 top:-
3 houses(Houses),
4 member(house(red, english, _, _, _), Houses),
5 member(house(_, spanish, dog, _, _), Houses),
6 member(house(green, _, _, coffee, _), Houses),
7 member(house(_, ukrainian, _, tea, _), Houses),
8 right_of(house(green,_,_,_,_), house(ivory,_,_,_,_), Houses),
9 member(house(_, _, snails, _, winstons), Houses),
10 member(house(yellow, _, _, _, kools), Houses),
11 Houses = [_, _, house(_, _, _, milk, _), _,_],
12 Houses = [house(_, norwegian, _, _, _)|_],
13 next_to(house(_,_,_,_,chesterfields), house(_,_,fox,_,_), Houses),
14 next_to(house(_,_,_,_,kools), house(_,_,horse,_,_), Houses),
15 member(house(_, _, _, orange_juice, lucky_strikes), Houses),
16 member(house(_, japanese, _, _, parliaments), Houses),
17 next_to(house(_,norwegian,_,_,_), house(blue,_,_,_,_), Houses),
18 member(house(_, _, zebra, _, _), Houses),
19 member(house(_, _, _, water, _), Houses).
20 % print_houses(Houses).
21
22 houses([
23 house(_, _, _, _, _),
24 house(_, _, _, _, _),
25 house(_, _, _, _, _),
26 house(_, _, _, _, _),
27 house(_, _, _, _, _)
28 ]).
29
30 right_of(A, B, [B, A | _]).
31 right_of(A, B, [_ | Y]) :- right_of(A, B, Y).
32
33 next_to(A, B, [A, B | _]).
34 next_to(A, B, [B, A | _]).
35 next_to(A, B, [_ | Y]) :- next_to(A, B, Y).
36
37 member(X, [X|_]).
38 member(X, [_|Y]) :- member(X, Y).
39
40 print_houses([A|B]) :- !,
41 write(A), nl,
42 print_houses(B).
43 print_houses([]).
+0
-5
packages/http/web/js/jquery-1.11.3.min.js less more
0 /*! jQuery v1.11.3 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */
1 !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.3",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)+1>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b="length"in a&&a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,aa=/[+~]/,ba=/'|\\/g,ca=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),da=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ea=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fa){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(ba,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+ra(o[l]);w=aa.test(a)&&pa(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",ea,!1):e.attachEvent&&e.attachEvent("onunload",ea)),p=!f(g),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="<a id='"+u+"'></a><select id='"+u+"-\f]' msallowcapture=''><option selected=''></option></select>",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?la(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(ca,da),a[3]=(a[3]||a[4]||a[5]||"").replace(ca,da),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(ca,da).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(ca,da),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return W.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(ca,da).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:oa(function(){return[0]}),last:oa(function(a,b){return[b-1]}),eq:oa(function(a,b,c){return[0>c?c+b:c]}),even:oa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:oa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:oa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:oa(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=ma(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=na(b);function qa(){}qa.prototype=d.filters=d.pseudos,d.setFilters=new qa,g=ga.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){(!c||(e=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?ga.error(a):z(a,i).slice(0)};function ra(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function sa(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function ta(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ua(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function va(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wa(a,b,c,d,e,f){return d&&!d[u]&&(d=wa(d)),e&&!e[u]&&(e=wa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ua(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:va(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=va(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=va(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xa(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sa(function(a){return a===b},h,!0),l=sa(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sa(ta(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wa(i>1&&ta(m),i>1&&ra(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xa(a.slice(i,e)),f>e&&xa(a=a.slice(e)),f>e&&ra(a))}m.push(c)}return ta(m)}function ya(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=va(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&ga.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xa(b[c]),f[u]?d.push(f):e.push(f);f=A(a,ya(e,d)),f.selector=a}return f},i=ga.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(ca,da),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(ca,da),aa.test(j[0].type)&&pa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&ra(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,aa.test(a)&&pa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ja(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;
2
3 return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h;if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?m.queue(this[0],a):void 0===b?this:this.each(function(){var c=m.queue(this,a,b);m._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&m.dequeue(this,a)})},dequeue:function(a){return this.each(function(){m.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=m.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=m._data(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var S=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=["Top","Right","Bottom","Left"],U=function(a,b){return a=b||a,"none"===m.css(a,"display")||!m.contains(a.ownerDocument,a)},V=m.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===m.type(c)){e=!0;for(h in c)m.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,m.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(m(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav></:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="<input type='radio' checked='checked' name='t'/>",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function aa(){return!0}function ba(){return!1}function ca(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},fix:function(a){if(a[m.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=Z.test(e)?this.mouseHooks:Y.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new m.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=f.srcElement||y),3===a.target.nodeType&&(a.target=a.target.parentNode),a.metaKey=!!a.metaKey,g.filter?g.filter(a,f):a},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button,g=b.fromElement;return null==a.pageX&&null!=b.clientX&&(d=a.target.ownerDocument||y,e=d.documentElement,c=d.body,a.pageX=b.clientX+(e&&e.scrollLeft||c&&c.scrollLeft||0)-(e&&e.clientLeft||c&&c.clientLeft||0),a.pageY=b.clientY+(e&&e.scrollTop||c&&c.scrollTop||0)-(e&&e.clientTop||c&&c.clientTop||0)),!a.relatedTarget&&g&&(a.relatedTarget=g===a.target?b.toElement:g),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==ca()&&this.focus)try{return this.focus(),!1}catch(a){}},delegateType:"focusin"},blur:{trigger:function(){return this===ca()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return m.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):void 0},_default:function(a){return m.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=m.extend(new m.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?m.event.trigger(e,null,b):m.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},m.removeEvent=y.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){var d="on"+b;a.detachEvent&&(typeof a[d]===K&&(a[d]=null),a.detachEvent(d,c))},m.Event=function(a,b){return this instanceof m.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?aa:ba):this.type=a,b&&m.extend(this,b),this.timeStamp=a&&a.timeStamp||m.now(),void(this[m.expando]=!0)):new m.Event(a,b)},m.Event.prototype={isDefaultPrevented:ba,isPropagationStopped:ba,isImmediatePropagationStopped:ba,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=aa,a&&(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=aa,a&&(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=aa,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},m.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){m.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!m.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.submitBubbles||(m.event.special.submit={setup:function(){return m.nodeName(this,"form")?!1:void m.event.add(this,"click._submit keypress._submit",function(a){var b=a.target,c=m.nodeName(b,"input")||m.nodeName(b,"button")?b.form:void 0;c&&!m._data(c,"submitBubbles")&&(m.event.add(c,"submit._submit",function(a){a._submit_bubble=!0}),m._data(c,"submitBubbles",!0))})},postDispatch:function(a){a._submit_bubble&&(delete a._submit_bubble,this.parentNode&&!a.isTrigger&&m.event.simulate("submit",this.parentNode,a,!0))},teardown:function(){return m.nodeName(this,"form")?!1:void m.event.remove(this,"._submit")}}),k.changeBubbles||(m.event.special.change={setup:function(){return X.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(m.event.add(this,"propertychange._change",function(a){"checked"===a.originalEvent.propertyName&&(this._just_changed=!0)}),m.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1),m.event.simulate("change",this,a,!0)})),!1):void m.event.add(this,"beforeactivate._change",function(a){var b=a.target;X.test(b.nodeName)&&!m._data(b,"changeBubbles")&&(m.event.add(b,"change._change",function(a){!this.parentNode||a.isSimulated||a.isTrigger||m.event.simulate("change",this.parentNode,a,!0)}),m._data(b,"changeBubbles",!0))})},handle:function(a){var b=a.target;return this!==b||a.isSimulated||a.isTrigger||"radio"!==b.type&&"checkbox"!==b.type?a.handleObj.handler.apply(this,arguments):void 0},teardown:function(){return m.event.remove(this,"._change"),!X.test(this.nodeName)}}),k.focusinBubbles||m.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){m.event.simulate(b,a.target,m.event.fix(a),!0)};m.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=m._data(d,b);e||d.addEventListener(a,c,!0),m._data(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=m._data(d,b)-1;e?m._data(d,b,e):(d.removeEventListener(a,c,!0),m._removeData(d,b))}}}),m.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(f in a)this.on(f,b,c,a[f],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=ba;else if(!d)return this;return 1===e&&(g=d,d=function(a){return m().off(a),g.apply(this,arguments)},d.guid=g.guid||(g.guid=m.guid++)),this.each(function(){m.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,m(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return(b===!1||"function"==typeof b)&&(c=b,b=void 0),c===!1&&(c=ba),this.each(function(){m.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){m.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?m.event.trigger(a,b,c,!0):void 0}});function da(a){var b=ea.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}var ea="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",fa=/ jQuery\d+="(?:null|\d+)"/g,ga=new RegExp("<(?:"+ea+")[\\s/>]","i"),ha=/^\s+/,ia=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,ja=/<([\w:]+)/,ka=/<tbody/i,la=/<|&#?\w+;/,ma=/<(?:script|style|link)/i,na=/checked\s*(?:[^=]|=\s*.checked.)/i,oa=/^$|\/(?:java|ecma)script/i,pa=/^true\/(.*)/,qa=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,ra={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:k.htmlSerialize?[0,"",""]:[1,"X<div>","</div>"]},sa=da(y),ta=sa.appendChild(y.createElement("div"));ra.optgroup=ra.option,ra.tbody=ra.tfoot=ra.colgroup=ra.caption=ra.thead,ra.th=ra.td;function ua(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ua(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function va(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wa(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xa(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function ya(a){var b=pa.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function za(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Aa(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Ba(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xa(b).text=a.text,ya(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!ga.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(ta.innerHTML=a.outerHTML,ta.removeChild(f=ta.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ua(f),h=ua(a),g=0;null!=(e=h[g]);++g)d[g]&&Ba(e,d[g]);if(b)if(c)for(h=h||ua(a),d=d||ua(f),g=0;null!=(e=h[g]);g++)Aa(e,d[g]);else Aa(a,f);return d=ua(f,"script"),d.length>0&&za(d,!i&&ua(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=da(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(la.test(f)){h=h||o.appendChild(b.createElement("div")),i=(ja.exec(f)||["",""])[1].toLowerCase(),l=ra[i]||ra._default,h.innerHTML=l[1]+f.replace(ia,"<$1></$2>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&ha.test(f)&&p.push(b.createTextNode(ha.exec(f)[0])),!k.tbody){f="table"!==i||ka.test(f)?"<table>"!==l[1]||ka.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ua(p,"input"),va),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ua(o.appendChild(f),"script"),g&&za(h),c)){e=0;while(f=h[e++])oa.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wa(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wa(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ua(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&za(ua(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ua(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fa,""):void 0;if(!("string"!=typeof a||ma.test(a)||!k.htmlSerialize&&ga.test(a)||!k.leadingWhitespace&&ha.test(a)||ra[(ja.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ia,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ua(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ua(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&na.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ua(i,"script"),xa),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ua(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,ya),j=0;f>j;j++)d=g[j],oa.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qa,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Ca,Da={};function Ea(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fa(a){var b=y,c=Da[a];return c||(c=Ea(a,b),"none"!==c&&c||(Ca=(Ca||m("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=(Ca[0].contentWindow||Ca[0].contentDocument).document,b.write(),b.close(),c=Ea(a,b),Ca.detach()),Da[a]=c),c}!function(){var a;k.shrinkWrapBlocks=function(){if(null!=a)return a;a=!1;var b,c,d;return c=y.getElementsByTagName("body")[0],c&&c.style?(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:1px;width:1px;zoom:1",b.appendChild(y.createElement("div")).style.width="5px",a=3!==b.offsetWidth),c.removeChild(d),a):void 0}}();var Ga=/^margin/,Ha=new RegExp("^("+S+")(?!px)[a-z%]+$","i"),Ia,Ja,Ka=/^(top|right|bottom|left)$/;a.getComputedStyle?(Ia=function(b){return b.ownerDocument.defaultView.opener?b.ownerDocument.defaultView.getComputedStyle(b,null):a.getComputedStyle(b,null)},Ja=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Ia(a),g=c?c.getPropertyValue(b)||c[b]:void 0,c&&(""!==g||m.contains(a.ownerDocument,a)||(g=m.style(a,b)),Ha.test(g)&&Ga.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0===g?g:g+""}):y.documentElement.currentStyle&&(Ia=function(a){return a.currentStyle},Ja=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Ia(a),g=c?c[b]:void 0,null==g&&h&&h[b]&&(g=h[b]),Ha.test(g)&&!Ka.test(b)&&(d=h.left,e=a.runtimeStyle,f=e&&e.left,f&&(e.left=a.currentStyle.left),h.left="fontSize"===b?"1em":g,g=h.pixelLeft+"px",h.left=d,f&&(e.left=f)),void 0===g?g:g+""||"auto"});function La(a,b){return{get:function(){var c=a();if(null!=c)return c?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d,e,f,g,h;if(b=y.createElement("div"),b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",d=b.getElementsByTagName("a")[0],c=d&&d.style){c.cssText="float:left;opacity:.5",k.opacity="0.5"===c.opacity,k.cssFloat=!!c.cssFloat,b.style.backgroundClip="content-box",b.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===b.style.backgroundClip,k.boxSizing=""===c.boxSizing||""===c.MozBoxSizing||""===c.WebkitBoxSizing,m.extend(k,{reliableHiddenOffsets:function(){return null==g&&i(),g},boxSizingReliable:function(){return null==f&&i(),f},pixelPosition:function(){return null==e&&i(),e},reliableMarginRight:function(){return null==h&&i(),h}});function i(){var b,c,d,i;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),b.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",e=f=!1,h=!0,a.getComputedStyle&&(e="1%"!==(a.getComputedStyle(b,null)||{}).top,f="4px"===(a.getComputedStyle(b,null)||{width:"4px"}).width,i=b.appendChild(y.createElement("div")),i.style.cssText=b.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",i.style.marginRight=i.style.width="0",b.style.width="1px",h=!parseFloat((a.getComputedStyle(i,null)||{}).marginRight),b.removeChild(i)),b.innerHTML="<table><tr><td></td><td>t</td></tr></table>",i=b.getElementsByTagName("td"),i[0].style.cssText="margin:0;border:0;padding:0;display:none",g=0===i[0].offsetHeight,g&&(i[0].style.display="",i[1].style.display="none",g=0===i[0].offsetHeight),c.removeChild(d))}}}(),m.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var Ma=/alpha\([^)]*\)/i,Na=/opacity\s*=\s*([^)]*)/,Oa=/^(none|table(?!-c[ea]).+)/,Pa=new RegExp("^("+S+")(.*)$","i"),Qa=new RegExp("^([+-])=("+S+")","i"),Ra={position:"absolute",visibility:"hidden",display:"block"},Sa={letterSpacing:"0",fontWeight:"400"},Ta=["Webkit","O","Moz","ms"];function Ua(a,b){if(b in a)return b;var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=Ta.length;while(e--)if(b=Ta[e]+c,b in a)return b;return d}function Va(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=m._data(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&U(d)&&(f[g]=m._data(d,"olddisplay",Fa(d.nodeName)))):(e=U(d),(c&&"none"!==c||!e)&&m._data(d,"olddisplay",e?c:m.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}function Wa(a,b,c){var d=Pa.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Xa(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=m.css(a,c+T[f],!0,e)),d?("content"===c&&(g-=m.css(a,"padding"+T[f],!0,e)),"margin"!==c&&(g-=m.css(a,"border"+T[f]+"Width",!0,e))):(g+=m.css(a,"padding"+T[f],!0,e),"padding"!==c&&(g+=m.css(a,"border"+T[f]+"Width",!0,e)));return g}function Ya(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=Ia(a),g=k.boxSizing&&"border-box"===m.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=Ja(a,b,f),(0>e||null==e)&&(e=a.style[b]),Ha.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Xa(a,b,c||(g?"border":"content"),d,f)+"px"}m.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Ja(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":k.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=m.camelCase(b),i=a.style;if(b=m.cssProps[h]||(m.cssProps[h]=Ua(i,h)),g=m.cssHooks[b]||m.cssHooks[h],void 0===c)return g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b];if(f=typeof c,"string"===f&&(e=Qa.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(m.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||m.cssNumber[h]||(c+="px"),k.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),!(g&&"set"in g&&void 0===(c=g.set(a,c,d)))))try{i[b]=c}catch(j){}}},css:function(a,b,c,d){var e,f,g,h=m.camelCase(b);return b=m.cssProps[h]||(m.cssProps[h]=Ua(a.style,h)),g=m.cssHooks[b]||m.cssHooks[h],g&&"get"in g&&(f=g.get(a,!0,c)),void 0===f&&(f=Ja(a,b,d)),"normal"===f&&b in Sa&&(f=Sa[b]),""===c||c?(e=parseFloat(f),c===!0||m.isNumeric(e)?e||0:f):f}}),m.each(["height","width"],function(a,b){m.cssHooks[b]={get:function(a,c,d){return c?Oa.test(m.css(a,"display"))&&0===a.offsetWidth?m.swap(a,Ra,function(){return Ya(a,b,d)}):Ya(a,b,d):void 0},set:function(a,c,d){var e=d&&Ia(a);return Wa(a,c,d?Xa(a,b,d,k.boxSizing&&"border-box"===m.css(a,"boxSizing",!1,e),e):0)}}}),k.opacity||(m.cssHooks.opacity={get:function(a,b){return Na.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=m.isNumeric(b)?"alpha(opacity="+100*b+")":"",f=d&&d.filter||c.filter||"";c.zoom=1,(b>=1||""===b)&&""===m.trim(f.replace(Ma,""))&&c.removeAttribute&&(c.removeAttribute("filter"),""===b||d&&!d.filter)||(c.filter=Ma.test(f)?f.replace(Ma,e):f+" "+e)}}),m.cssHooks.marginRight=La(k.reliableMarginRight,function(a,b){return b?m.swap(a,{display:"inline-block"},Ja,[a,"marginRight"]):void 0}),m.each({margin:"",padding:"",border:"Width"},function(a,b){m.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+T[d]+b]=f[d]||f[d-2]||f[0];return e}},Ga.test(a)||(m.cssHooks[a+b].set=Wa)}),m.fn.extend({css:function(a,b){return V(this,function(a,b,c){var d,e,f={},g=0;if(m.isArray(b)){for(d=Ia(a),e=b.length;e>g;g++)f[b[g]]=m.css(a,b[g],!1,d);return f}return void 0!==c?m.style(a,b,c):m.css(a,b)},a,b,arguments.length>1)},show:function(){return Va(this,!0)},hide:function(){return Va(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){U(this)?m(this).show():m(this).hide()})}});function Za(a,b,c,d,e){
4 return new Za.prototype.init(a,b,c,d,e)}m.Tween=Za,Za.prototype={constructor:Za,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(m.cssNumber[c]?"":"px")},cur:function(){var a=Za.propHooks[this.prop];return a&&a.get?a.get(this):Za.propHooks._default.get(this)},run:function(a){var b,c=Za.propHooks[this.prop];return this.options.duration?this.pos=b=m.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Za.propHooks._default.set(this),this}},Za.prototype.init.prototype=Za.prototype,Za.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=m.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){m.fx.step[a.prop]?m.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[m.cssProps[a.prop]]||m.cssHooks[a.prop])?m.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Za.propHooks.scrollTop=Za.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},m.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},m.fx=Za.prototype.init,m.fx.step={};var $a,_a,ab=/^(?:toggle|show|hide)$/,bb=new RegExp("^(?:([+-])=|)("+S+")([a-z%]*)$","i"),cb=/queueHooks$/,db=[ib],eb={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=bb.exec(b),f=e&&e[3]||(m.cssNumber[a]?"":"px"),g=(m.cssNumber[a]||"px"!==f&&+d)&&bb.exec(m.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,m.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function fb(){return setTimeout(function(){$a=void 0}),$a=m.now()}function gb(a,b){var c,d={height:a},e=0;for(b=b?1:0;4>e;e+=2-b)c=T[e],d["margin"+c]=d["padding"+c]=a;return b&&(d.opacity=d.width=a),d}function hb(a,b,c){for(var d,e=(eb[b]||[]).concat(eb["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function ib(a,b,c){var d,e,f,g,h,i,j,l,n=this,o={},p=a.style,q=a.nodeType&&U(a),r=m._data(a,"fxshow");c.queue||(h=m._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,n.always(function(){n.always(function(){h.unqueued--,m.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[p.overflow,p.overflowX,p.overflowY],j=m.css(a,"display"),l="none"===j?m._data(a,"olddisplay")||Fa(a.nodeName):j,"inline"===l&&"none"===m.css(a,"float")&&(k.inlineBlockNeedsLayout&&"inline"!==Fa(a.nodeName)?p.zoom=1:p.display="inline-block")),c.overflow&&(p.overflow="hidden",k.shrinkWrapBlocks()||n.always(function(){p.overflow=c.overflow[0],p.overflowX=c.overflow[1],p.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],ab.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(q?"hide":"show")){if("show"!==e||!r||void 0===r[d])continue;q=!0}o[d]=r&&r[d]||m.style(a,d)}else j=void 0;if(m.isEmptyObject(o))"inline"===("none"===j?Fa(a.nodeName):j)&&(p.display=j);else{r?"hidden"in r&&(q=r.hidden):r=m._data(a,"fxshow",{}),f&&(r.hidden=!q),q?m(a).show():n.done(function(){m(a).hide()}),n.done(function(){var b;m._removeData(a,"fxshow");for(b in o)m.style(a,b,o[b])});for(d in o)g=hb(q?r[d]:0,d,n),d in r||(r[d]=g.start,q&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function jb(a,b){var c,d,e,f,g;for(c in a)if(d=m.camelCase(c),e=b[d],f=a[c],m.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=m.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function kb(a,b,c){var d,e,f=0,g=db.length,h=m.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=$a||fb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:m.extend({},b),opts:m.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:$a||fb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=m.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(jb(k,j.opts.specialEasing);g>f;f++)if(d=db[f].call(j,a,k,j.opts))return d;return m.map(k,hb,j),m.isFunction(j.opts.start)&&j.opts.start.call(a,j),m.fx.timer(m.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}m.Animation=m.extend(kb,{tweener:function(a,b){m.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],eb[c]=eb[c]||[],eb[c].unshift(b)},prefilter:function(a,b){b?db.unshift(a):db.push(a)}}),m.speed=function(a,b,c){var d=a&&"object"==typeof a?m.extend({},a):{complete:c||!c&&b||m.isFunction(a)&&a,duration:a,easing:c&&b||b&&!m.isFunction(b)&&b};return d.duration=m.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in m.fx.speeds?m.fx.speeds[d.duration]:m.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){m.isFunction(d.old)&&d.old.call(this),d.queue&&m.dequeue(this,d.queue)},d},m.fn.extend({fadeTo:function(a,b,c,d){return this.filter(U).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=m.isEmptyObject(a),f=m.speed(b,c,d),g=function(){var b=kb(this,m.extend({},a),f);(e||m._data(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=m.timers,g=m._data(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&cb.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&m.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=m._data(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=m.timers,g=d?d.length:0;for(c.finish=!0,m.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),m.each(["toggle","show","hide"],function(a,b){var c=m.fn[b];m.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(gb(b,!0),a,d,e)}}),m.each({slideDown:gb("show"),slideUp:gb("hide"),slideToggle:gb("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){m.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),m.timers=[],m.fx.tick=function(){var a,b=m.timers,c=0;for($a=m.now();c<b.length;c++)a=b[c],a()||b[c]!==a||b.splice(c--,1);b.length||m.fx.stop(),$a=void 0},m.fx.timer=function(a){m.timers.push(a),a()?m.fx.start():m.timers.pop()},m.fx.interval=13,m.fx.start=function(){_a||(_a=setInterval(m.fx.tick,m.fx.interval))},m.fx.stop=function(){clearInterval(_a),_a=null},m.fx.speeds={slow:600,fast:200,_default:400},m.fn.delay=function(a,b){return a=m.fx?m.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a,b,c,d,e;b=y.createElement("div"),b.setAttribute("className","t"),b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",d=b.getElementsByTagName("a")[0],c=y.createElement("select"),e=c.appendChild(y.createElement("option")),a=b.getElementsByTagName("input")[0],d.style.cssText="top:1px",k.getSetAttribute="t"!==b.className,k.style=/top/.test(d.getAttribute("style")),k.hrefNormalized="/a"===d.getAttribute("href"),k.checkOn=!!a.value,k.optSelected=e.selected,k.enctype=!!y.createElement("form").enctype,c.disabled=!0,k.optDisabled=!e.disabled,a=y.createElement("input"),a.setAttribute("value",""),k.input=""===a.getAttribute("value"),a.value="t",a.setAttribute("type","radio"),k.radioValue="t"===a.value}();var lb=/\r/g;m.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=m.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,m(this).val()):a,null==e?e="":"number"==typeof e?e+="":m.isArray(e)&&(e=m.map(e,function(a){return null==a?"":a+""})),b=m.valHooks[this.type]||m.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=m.valHooks[e.type]||m.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(lb,""):null==c?"":c)}}}),m.extend({valHooks:{option:{get:function(a){var b=m.find.attr(a,"value");return null!=b?b:m.trim(m.text(a))}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],!(!c.selected&&i!==e||(k.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.parentNode.disabled&&m.nodeName(c.parentNode,"optgroup"))){if(b=m(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=m.makeArray(b),g=e.length;while(g--)if(d=e[g],m.inArray(m.valHooks.option.get(d),f)>=0)try{d.selected=c=!0}catch(h){d.scrollHeight}else d.selected=!1;return c||(a.selectedIndex=-1),e}}}}),m.each(["radio","checkbox"],function(){m.valHooks[this]={set:function(a,b){return m.isArray(b)?a.checked=m.inArray(m(a).val(),b)>=0:void 0}},k.checkOn||(m.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var mb,nb,ob=m.expr.attrHandle,pb=/^(?:checked|selected)$/i,qb=k.getSetAttribute,rb=k.input;m.fn.extend({attr:function(a,b){return V(this,m.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){m.removeAttr(this,a)})}}),m.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===K?m.prop(a,b,c):(1===f&&m.isXMLDoc(a)||(b=b.toLowerCase(),d=m.attrHooks[b]||(m.expr.match.bool.test(b)?nb:mb)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=m.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void m.removeAttr(a,b))},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(E);if(f&&1===a.nodeType)while(c=f[e++])d=m.propFix[c]||c,m.expr.match.bool.test(c)?rb&&qb||!pb.test(c)?a[d]=!1:a[m.camelCase("default-"+c)]=a[d]=!1:m.attr(a,c,""),a.removeAttribute(qb?c:d)},attrHooks:{type:{set:function(a,b){if(!k.radioValue&&"radio"===b&&m.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),nb={set:function(a,b,c){return b===!1?m.removeAttr(a,c):rb&&qb||!pb.test(c)?a.setAttribute(!qb&&m.propFix[c]||c,c):a[m.camelCase("default-"+c)]=a[c]=!0,c}},m.each(m.expr.match.bool.source.match(/\w+/g),function(a,b){var c=ob[b]||m.find.attr;ob[b]=rb&&qb||!pb.test(b)?function(a,b,d){var e,f;return d||(f=ob[b],ob[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,ob[b]=f),e}:function(a,b,c){return c?void 0:a[m.camelCase("default-"+b)]?b.toLowerCase():null}}),rb&&qb||(m.attrHooks.value={set:function(a,b,c){return m.nodeName(a,"input")?void(a.defaultValue=b):mb&&mb.set(a,b,c)}}),qb||(mb={set:function(a,b,c){var d=a.getAttributeNode(c);return d||a.setAttributeNode(d=a.ownerDocument.createAttribute(c)),d.value=b+="","value"===c||b===a.getAttribute(c)?b:void 0}},ob.id=ob.name=ob.coords=function(a,b,c){var d;return c?void 0:(d=a.getAttributeNode(b))&&""!==d.value?d.value:null},m.valHooks.button={get:function(a,b){var c=a.getAttributeNode(b);return c&&c.specified?c.value:void 0},set:mb.set},m.attrHooks.contenteditable={set:function(a,b,c){mb.set(a,""===b?!1:b,c)}},m.each(["width","height"],function(a,b){m.attrHooks[b]={set:function(a,c){return""===c?(a.setAttribute(b,"auto"),c):void 0}}})),k.style||(m.attrHooks.style={get:function(a){return a.style.cssText||void 0},set:function(a,b){return a.style.cssText=b+""}});var sb=/^(?:input|select|textarea|button|object)$/i,tb=/^(?:a|area)$/i;m.fn.extend({prop:function(a,b){return V(this,m.prop,a,b,arguments.length>1)},removeProp:function(a){return a=m.propFix[a]||a,this.each(function(){try{this[a]=void 0,delete this[a]}catch(b){}})}}),m.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!m.isXMLDoc(a),f&&(b=m.propFix[b]||b,e=m.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=m.find.attr(a,"tabindex");return b?parseInt(b,10):sb.test(a.nodeName)||tb.test(a.nodeName)&&a.href?0:-1}}}}),k.hrefNormalized||m.each(["href","src"],function(a,b){m.propHooks[b]={get:function(a){return a.getAttribute(b,4)}}}),k.optSelected||(m.propHooks.selected={get:function(a){var b=a.parentNode;return b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex),null}}),m.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){m.propFix[this.toLowerCase()]=this}),k.enctype||(m.propFix.enctype="encoding");var ub=/[\t\r\n\f]/g;m.fn.extend({addClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j="string"==typeof a&&a;if(m.isFunction(a))return this.each(function(b){m(this).addClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(E)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ub," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=m.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j=0===arguments.length||"string"==typeof a&&a;if(m.isFunction(a))return this.each(function(b){m(this).removeClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(E)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ub," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?m.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(m.isFunction(a)?function(c){m(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=m(this),f=a.match(E)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===K||"boolean"===c)&&(this.className&&m._data(this,"__className__",this.className),this.className=this.className||a===!1?"":m._data(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(ub," ").indexOf(b)>=0)return!0;return!1}}),m.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){m.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),m.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}});var vb=m.now(),wb=/\?/,xb=/(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;m.parseJSON=function(b){if(a.JSON&&a.JSON.parse)return a.JSON.parse(b+"");var c,d=null,e=m.trim(b+"");return e&&!m.trim(e.replace(xb,function(a,b,e,f){return c&&b&&(d=0),0===d?a:(c=e||b,d+=!f-!e,"")}))?Function("return "+e)():m.error("Invalid JSON: "+b)},m.parseXML=function(b){var c,d;if(!b||"string"!=typeof b)return null;try{a.DOMParser?(d=new DOMParser,c=d.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b))}catch(e){c=void 0}return c&&c.documentElement&&!c.getElementsByTagName("parsererror").length||m.error("Invalid XML: "+b),c};var yb,zb,Ab=/#.*$/,Bb=/([?&])_=[^&]*/,Cb=/^(.*?):[ \t]*([^\r\n]*)\r?$/gm,Db=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Eb=/^(?:GET|HEAD)$/,Fb=/^\/\//,Gb=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,Hb={},Ib={},Jb="*/".concat("*");try{zb=location.href}catch(Kb){zb=y.createElement("a"),zb.href="",zb=zb.href}yb=Gb.exec(zb.toLowerCase())||[];function Lb(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(E)||[];if(m.isFunction(c))while(d=f[e++])"+"===d.charAt(0)?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Mb(a,b,c,d){var e={},f=a===Ib;function g(h){var i;return e[h]=!0,m.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function Nb(a,b){var c,d,e=m.ajaxSettings.flatOptions||{};for(d in b)void 0!==b[d]&&((e[d]?a:c||(c={}))[d]=b[d]);return c&&m.extend(!0,a,c),a}function Ob(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===e&&(e=a.mimeType||b.getResponseHeader("Content-Type"));if(e)for(g in h)if(h[g]&&h[g].test(e)){i.unshift(g);break}if(i[0]in c)f=i[0];else{for(g in c){if(!i[0]||a.converters[g+" "+i[0]]){f=g;break}d||(d=g)}f=f||d}return f?(f!==i[0]&&i.unshift(f),c[f]):void 0}function Pb(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}m.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:zb,type:"GET",isLocal:Db.test(yb[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Jb,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":m.parseJSON,"text xml":m.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Nb(Nb(a,m.ajaxSettings),b):Nb(m.ajaxSettings,a)},ajaxPrefilter:Lb(Hb),ajaxTransport:Lb(Ib),ajax:function(a,b){"object"==typeof a&&(b=a,a=void 0),b=b||{};var c,d,e,f,g,h,i,j,k=m.ajaxSetup({},b),l=k.context||k,n=k.context&&(l.nodeType||l.jquery)?m(l):m.event,o=m.Deferred(),p=m.Callbacks("once memory"),q=k.statusCode||{},r={},s={},t=0,u="canceled",v={readyState:0,getResponseHeader:function(a){var b;if(2===t){if(!j){j={};while(b=Cb.exec(f))j[b[1].toLowerCase()]=b[2]}b=j[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return 2===t?f:null},setRequestHeader:function(a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this},overrideMimeType:function(a){return t||(k.mimeType=a),this},statusCode:function(a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this},abort:function(a){var b=a||u;return i&&i.abort(b),x(0,b),this}};if(o.promise(v).complete=p.add,v.success=v.done,v.error=v.fail,k.url=((a||k.url||zb)+"").replace(Ab,"").replace(Fb,yb[1]+"//"),k.type=b.method||b.type||k.method||k.type,k.dataTypes=m.trim(k.dataType||"*").toLowerCase().match(E)||[""],null==k.crossDomain&&(c=Gb.exec(k.url.toLowerCase()),k.crossDomain=!(!c||c[1]===yb[1]&&c[2]===yb[2]&&(c[3]||("http:"===c[1]?"80":"443"))===(yb[3]||("http:"===yb[1]?"80":"443")))),k.data&&k.processData&&"string"!=typeof k.data&&(k.data=m.param(k.data,k.traditional)),Mb(Hb,k,b,v),2===t)return v;h=m.event&&k.global,h&&0===m.active++&&m.event.trigger("ajaxStart"),k.type=k.type.toUpperCase(),k.hasContent=!Eb.test(k.type),e=k.url,k.hasContent||(k.data&&(e=k.url+=(wb.test(e)?"&":"?")+k.data,delete k.data),k.cache===!1&&(k.url=Bb.test(e)?e.replace(Bb,"$1_="+vb++):e+(wb.test(e)?"&":"?")+"_="+vb++)),k.ifModified&&(m.lastModified[e]&&v.setRequestHeader("If-Modified-Since",m.lastModified[e]),m.etag[e]&&v.setRequestHeader("If-None-Match",m.etag[e])),(k.data&&k.hasContent&&k.contentType!==!1||b.contentType)&&v.setRequestHeader("Content-Type",k.contentType),v.setRequestHeader("Accept",k.dataTypes[0]&&k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+Jb+"; q=0.01":""):k.accepts["*"]);for(d in k.headers)v.setRequestHeader(d,k.headers[d]);if(k.beforeSend&&(k.beforeSend.call(l,v,k)===!1||2===t))return v.abort();u="abort";for(d in{success:1,error:1,complete:1})v[d](k[d]);if(i=Mb(Ib,k,b,v)){v.readyState=1,h&&n.trigger("ajaxSend",[v,k]),k.async&&k.timeout>0&&(g=setTimeout(function(){v.abort("timeout")},k.timeout));try{t=1,i.send(r,x)}catch(w){if(!(2>t))throw w;x(-1,w)}}else x(-1,"No Transport");function x(a,b,c,d){var j,r,s,u,w,x=b;2!==t&&(t=2,g&&clearTimeout(g),i=void 0,f=d||"",v.readyState=a>0?4:0,j=a>=200&&300>a||304===a,c&&(u=Ob(k,v,c)),u=Pb(k,u,v,j),j?(k.ifModified&&(w=v.getResponseHeader("Last-Modified"),w&&(m.lastModified[e]=w),w=v.getResponseHeader("etag"),w&&(m.etag[e]=w)),204===a||"HEAD"===k.type?x="nocontent":304===a?x="notmodified":(x=u.state,r=u.data,s=u.error,j=!s)):(s=x,(a||!x)&&(x="error",0>a&&(a=0))),v.status=a,v.statusText=(b||x)+"",j?o.resolveWith(l,[r,x,v]):o.rejectWith(l,[v,x,s]),v.statusCode(q),q=void 0,h&&n.trigger(j?"ajaxSuccess":"ajaxError",[v,k,j?r:s]),p.fireWith(l,[v,x]),h&&(n.trigger("ajaxComplete",[v,k]),--m.active||m.event.trigger("ajaxStop")))}return v},getJSON:function(a,b,c){return m.get(a,b,c,"json")},getScript:function(a,b){return m.get(a,void 0,b,"script")}}),m.each(["get","post"],function(a,b){m[b]=function(a,c,d,e){return m.isFunction(c)&&(e=e||d,d=c,c=void 0),m.ajax({url:a,type:b,dataType:e,data:c,success:d})}}),m._evalUrl=function(a){return m.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},m.fn.extend({wrapAll:function(a){if(m.isFunction(a))return this.each(function(b){m(this).wrapAll(a.call(this,b))});if(this[0]){var b=m(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&1===a.firstChild.nodeType)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){return this.each(m.isFunction(a)?function(b){m(this).wrapInner(a.call(this,b))}:function(){var b=m(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=m.isFunction(a);return this.each(function(c){m(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){m.nodeName(this,"body")||m(this).replaceWith(this.childNodes)}).end()}}),m.expr.filters.hidden=function(a){return a.offsetWidth<=0&&a.offsetHeight<=0||!k.reliableHiddenOffsets()&&"none"===(a.style&&a.style.display||m.css(a,"display"))},m.expr.filters.visible=function(a){return!m.expr.filters.hidden(a)};var Qb=/%20/g,Rb=/\[\]$/,Sb=/\r?\n/g,Tb=/^(?:submit|button|image|reset|file)$/i,Ub=/^(?:input|select|textarea|keygen)/i;function Vb(a,b,c,d){var e;if(m.isArray(b))m.each(b,function(b,e){c||Rb.test(a)?d(a,e):Vb(a+"["+("object"==typeof e?b:"")+"]",e,c,d)});else if(c||"object"!==m.type(b))d(a,b);else for(e in b)Vb(a+"["+e+"]",b[e],c,d)}m.param=function(a,b){var c,d=[],e=function(a,b){b=m.isFunction(b)?b():null==b?"":b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};if(void 0===b&&(b=m.ajaxSettings&&m.ajaxSettings.traditional),m.isArray(a)||a.jquery&&!m.isPlainObject(a))m.each(a,function(){e(this.name,this.value)});else for(c in a)Vb(c,a[c],b,e);return d.join("&").replace(Qb,"+")},m.fn.extend({serialize:function(){return m.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=m.prop(this,"elements");return a?m.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!m(this).is(":disabled")&&Ub.test(this.nodeName)&&!Tb.test(a)&&(this.checked||!W.test(a))}).map(function(a,b){var c=m(this).val();return null==c?null:m.isArray(c)?m.map(c,function(a){return{name:b.name,value:a.replace(Sb,"\r\n")}}):{name:b.name,value:c.replace(Sb,"\r\n")}}).get()}}),m.ajaxSettings.xhr=void 0!==a.ActiveXObject?function(){return!this.isLocal&&/^(get|post|head|put|delete|options)$/i.test(this.type)&&Zb()||$b()}:Zb;var Wb=0,Xb={},Yb=m.ajaxSettings.xhr();a.attachEvent&&a.attachEvent("onunload",function(){for(var a in Xb)Xb[a](void 0,!0)}),k.cors=!!Yb&&"withCredentials"in Yb,Yb=k.ajax=!!Yb,Yb&&m.ajaxTransport(function(a){if(!a.crossDomain||k.cors){var b;return{send:function(c,d){var e,f=a.xhr(),g=++Wb;if(f.open(a.type,a.url,a.async,a.username,a.password),a.xhrFields)for(e in a.xhrFields)f[e]=a.xhrFields[e];a.mimeType&&f.overrideMimeType&&f.overrideMimeType(a.mimeType),a.crossDomain||c["X-Requested-With"]||(c["X-Requested-With"]="XMLHttpRequest");for(e in c)void 0!==c[e]&&f.setRequestHeader(e,c[e]+"");f.send(a.hasContent&&a.data||null),b=function(c,e){var h,i,j;if(b&&(e||4===f.readyState))if(delete Xb[g],b=void 0,f.onreadystatechange=m.noop,e)4!==f.readyState&&f.abort();else{j={},h=f.status,"string"==typeof f.responseText&&(j.text=f.responseText);try{i=f.statusText}catch(k){i=""}h||!a.isLocal||a.crossDomain?1223===h&&(h=204):h=j.text?200:404}j&&d(h,i,j,f.getAllResponseHeaders())},a.async?4===f.readyState?setTimeout(b):f.onreadystatechange=Xb[g]=b:b()},abort:function(){b&&b(void 0,!0)}}}});function Zb(){try{return new a.XMLHttpRequest}catch(b){}}function $b(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}m.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return m.globalEval(a),a}}}),m.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),m.ajaxTransport("script",function(a){if(a.crossDomain){var b,c=y.head||m("head")[0]||y.documentElement;return{send:function(d,e){b=y.createElement("script"),b.async=!0,a.scriptCharset&&(b.charset=a.scriptCharset),b.src=a.url,b.onload=b.onreadystatechange=function(a,c){(c||!b.readyState||/loaded|complete/.test(b.readyState))&&(b.onload=b.onreadystatechange=null,b.parentNode&&b.parentNode.removeChild(b),b=null,c||e(200,"success"))},c.insertBefore(b,c.firstChild)},abort:function(){b&&b.onload(void 0,!0)}}}});var _b=[],ac=/(=)\?(?=&|$)|\?\?/;m.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=_b.pop()||m.expando+"_"+vb++;return this[a]=!0,a}}),m.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(ac.test(b.url)?"url":"string"==typeof b.data&&!(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&ac.test(b.data)&&"data");return h||"jsonp"===b.dataTypes[0]?(e=b.jsonpCallback=m.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(ac,"$1"+e):b.jsonp!==!1&&(b.url+=(wb.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||m.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,_b.push(e)),g&&m.isFunction(f)&&f(g[0]),g=f=void 0}),"script"):void 0}),m.parseHTML=function(a,b,c){if(!a||"string"!=typeof a)return null;"boolean"==typeof b&&(c=b,b=!1),b=b||y;var d=u.exec(a),e=!c&&[];return d?[b.createElement(d[1])]:(d=m.buildFragment([a],b,e),e&&e.length&&m(e).remove(),m.merge([],d.childNodes))};var bc=m.fn.load;m.fn.load=function(a,b,c){if("string"!=typeof a&&bc)return bc.apply(this,arguments);var d,e,f,g=this,h=a.indexOf(" ");return h>=0&&(d=m.trim(a.slice(h,a.length)),a=a.slice(0,h)),m.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(f="POST"),g.length>0&&m.ajax({url:a,type:f,dataType:"html",data:b}).done(function(a){e=arguments,g.html(d?m("<div>").append(m.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,e||[a.responseText,b,a])}),this},m.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){m.fn[b]=function(a){return this.on(b,a)}}),m.expr.filters.animated=function(a){return m.grep(m.timers,function(b){return a===b.elem}).length};var cc=a.document.documentElement;function dc(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1}m.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=m.css(a,"position"),l=m(a),n={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=m.css(a,"top"),i=m.css(a,"left"),j=("absolute"===k||"fixed"===k)&&m.inArray("auto",[f,i])>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),m.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(n.top=b.top-h.top+g),null!=b.left&&(n.left=b.left-h.left+e),"using"in b?b.using.call(a,n):l.css(n)}},m.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){m.offset.setOffset(this,a,b)});var b,c,d={top:0,left:0},e=this[0],f=e&&e.ownerDocument;if(f)return b=f.documentElement,m.contains(b,e)?(typeof e.getBoundingClientRect!==K&&(d=e.getBoundingClientRect()),c=dc(f),{top:d.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:d.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):d},position:function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===m.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),m.nodeName(a[0],"html")||(c=a.offset()),c.top+=m.css(a[0],"borderTopWidth",!0),c.left+=m.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-m.css(d,"marginTop",!0),left:b.left-c.left-m.css(d,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||cc;while(a&&!m.nodeName(a,"html")&&"static"===m.css(a,"position"))a=a.offsetParent;return a||cc})}}),m.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);m.fn[a]=function(d){return V(this,function(a,d,e){var f=dc(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?m(f).scrollLeft():e,c?e:m(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}),m.each(["top","left"],function(a,b){m.cssHooks[b]=La(k.pixelPosition,function(a,c){return c?(c=Ja(a,b),Ha.test(c)?m(a).position()[b]+"px":c):void 0})}),m.each({Height:"height",Width:"width"},function(a,b){m.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){m.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return V(this,function(b,c,d){var e;return m.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?m.css(b,c,g):m.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),m.fn.size=function(){return this.length},m.fn.andSelf=m.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return m});var ec=a.jQuery,fc=a.$;return m.noConflict=function(b){return a.$===m&&(a.$=fc),b&&a.jQuery===m&&(a.jQuery=ec),m},typeof b===K&&(a.jQuery=a.$=m),m});