Dear Waldek,

thank you for your answer.

How is the situation for a definition

  baz?: Cat -> Integer -> Integer
  baz?(D: Cat): Integer -> Integer ==
   (n: Integer, x: %): Integer +->
      k: Integer := blah(x, n)
      if (foo? $ D)(k) then 1 else 0

and in places where I use baz?, I do it like this

  fun: (%, Integer) -> Integer := baz?(D1)
  for i in 1..10 repeat res := res + fun(x, i)

would that still cost more or do I (with this assignment) prevent the multiple lookups of foo? $ D1. I think

Ralf

On 12/7/25 18:33, Waldek Hebisch wrote:
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


--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/f30877d3-9ba0-49c9-b240-3f3fd8fc02fb%40hemmecke.org.

Reply via email to