I happened to find a bug (?) on compound_name_arity zero terms in ‘term_facotized/3’.
% ?- term_factorized(f(q()), S, E).
%@ S = f(q()),
%@ E = [].
% ?- term_factorized(f(q(), q()), S, E).
%@ ERROR: Domain error: `compound_non_zero_arity' expected, found `q()'
%@ ERROR: In:
%@ ERROR: [14] functor(q(),_7688,_7690)
%@ ERROR: [13] terms:mk_subst([... - _7738],[_7748=_7750|_7744],t(black('',_7762,_7764,''),black(...,...,_7774,...))) at /Users/cantor/lib/swipl/library/terms.pl:309
%@ ERROR: [11] toplevel_call(pt_mincoa:pt_mincoa: ...) at /Users/cantor/lib/swipl/boot/toplevel.pl:1678
%@ ERROR:
I wanted to compare my version of ‘term_factoirzed’/3 via minimum coalgebra
representation, which shows statistics below ( imac intel 2020, macOS 26 Swiprolog latest ).
I hope it would be marginal compared with the builtin ‘term_foctorized/3’.
% ?-N=100000, time(forall(between(1, N, _), pt_term_factorize_test)).
%@ % 30,222,332 inferences, 2.885 CPU in 2.890 seconds (100% CPU, 10475896 Lips)
%@ N = 100000.
pt_term_factorize_test :-
random_term(R),
pt_term_coa([R], [I], Coa),
pt_term_factorize(I, Coa, _, _).