[m-users.] Cartesian product of two sets of things.
Julien Fischer
jfischer at opturion.com
Wed Oct 11 14:50:48 AEDT 2023
On Wed, 11 Oct 2023, Zoltan Somogyi wrote:
>
> On 2023-10-10 21:02 +11:00 AEDT, "Julien Fischer" <jfischer at opturion.com> wrote:
>> A big part of the difference would be that the nondet version sorts
>> the elements and (redundantly) attempt to remove duplicates, whereas the
>> det version just constructs the elements in reverse order directly.
>
> Another source of difference is that its lowest level operations
> are tail recursive, while the lowest level operations in the nondet version
> can't be tail recursive, because you can't recover a nondet stack frame
> while the values of the variables it contains may be needed to find
> another solution.
>
> You should note that even the det version in cproduct.m is not
> as fast as it could be, because it adds each new item to the cross product
> using a higher order call. Converting the sets to sorted lists and iterating
> over the lists directly could replace those higher order calls with simple
> unifications, which would make that version even faster.
Granted, although with --intermod -O3 the compiler will do that for you
with the det version as it is written.
Julien.
More information about the users
mailing list