On Thu, Jul 03, 2025 at 07:46:22AM +0200, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> On 7/3/25 03:15, Waldek Hebisch wrote:
> > You are exploring land of bugs.
>
> As usual. ;-)
>
> I don't even know whether such a construction is specified to work even in
> Aldor.
I would say that from general point of view code looks OK.
It is just question what in implemented in the respective compiler.
> The following compiles
> >
> > )abbrev package RHX RHx
> > RHx(R: Ring, POL: R -> UnivariatePolynomialCategory R): with
> > var: () -> OutputForm
> > == add
> > fT := POL(R)
> > mon ==> monomial$fT
> > var(): OutputForm == mon(1$R, 1$NonNegativeInteger)::OutputForm
> >
> > but generated code is wrong.
> >
> > In general, your code here is quite different than current algebra
> > code. That is normally caller would evaluate POL(R) nad RHx would
> > use its value.
>
> Hmmm... but that seems to tell my that I would have to make a part of the
> respective (RHx) package explicit to the caller.
>
> Actually, I oversimplified. What I really want inside RHx is calling
> functions from POL(Matrix R), i.e., I should have given
>
> RHx(R: Ring, POL: (X:Ring) -> UnivariatePolynomialCategory X): with
>
> as the initial line of definition. In my current setup the respective POL
> constructor would even have a second parameter that depends on X.
> I wanted to hide the (respective) "Matrix" constructur from the caller as
> implementation detail.
You need to specify them somewhere. Old Spad way it to pass all
such thing down trough intermediate constructors. Some things
may be hidden by using categores: category specifies what needs
to be visible to users of a package, package may have more arguments
or more specific arguments. You may look at amodgcd.spad.
ModularAlgebraicGcdOperations specifies things in terms of abstrat
types and users of packages of this category only see abstrat
things, but unneeded specifics are hidden. Only package gets
full details.
Also, there is question of efficiency. Your 'var' is probably
rather uncritical, but in amodgcd.spad I wanted as efficient code
as possible. Giving specific types to packages (and in fact
"hardcoding" some details inside packages) lead to efficient
code inside. With code as you wrote there is ususaly expensive
call to package/domain that is specified only at runtime. My
modification above which compiles moved place where POL(R) is
fully specified to place that is run only once (that is at
package instationation time). Theoretically Spad compiler could
automatically do such transformantions, but I do not think
that this is done now.
There is related issue. To get better efficiency Spad compiler
normally caches types, that is types is instantiated once and
reused after that. But if type depends on runtime values, then
it must be dully recomputed. Spad functions may produce different
value on each call, even if arguments are the same, so your
use disallows caching. My modification explicitely caches type
value.
One extra remark: I do not know how to implement such calls
efficiently. This means that usually I would prefer different
construct. This limits my motivation to implement them
(which currently seem to require substantial work).
--
Waldek Hebisch