On Sun, Dec 07, 2025 at 04:12:21PM +0100, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> Hi Waldek,
>
> I am about to design a function that depends on a domain and a few other
> parameters.
>
> Cat: Category == with
> foo?: Integer -> Boolean
> ..
> D1: Cat == add ...
> D2: Cat == add ...
>
> Dom(): with
> bar?: (Cat, Integer) -> Integer
> add
> blah(x: %): Integer == ...
> bar(D: Cat, n: Integer, x: %): Integer ==
> k: Integer := blah(x, n)
> if (foo? $ D)(k) then 1 else 0
>
> I am pretty sure that this is possible. I just want to ask whether from your
> point of view this causes any speed penalties?
Yes. Normally result of lookup for functions are cached. But such
construct means that before each call insted of actually calling
'foo?' FriCAS runtime will first need to do full lookup, which costs
you some milliseconds. or tens of milliseconds. Negligible if you
do a single call. Perfomance killer if done in a tight loop.
Theoretically there is still some possibility for caching, but
currently variable domain is Spad means full lookup for each call.
> In my current idea I would not want to put that dependency into the
> arguments of Dom. It is rather that "bar" counts as an additional feature
> that is not so important. I also don't want to move bar to a separate
> package.
>
> Thank you in advance
> Ralf
--
Waldek Hebisch