On Thu, Oct 29, 2020 at 09:10:44PM +0000, Neven Sajko wrote:
>
> While I am slowly learning Fricas, I noticed a pattern (or the lack of
> it) that struck me as odd. Namely, some data structure types of fixed
> size have constructors which take a parameter to define the size as
> part of the type (e.g., SquareMatrix), while others (like Vector) do
> not take a parameter that specifies the data structure's fixed length.
>
> Is this an oversight or a product of an intentional decision? Is it
> beneficial or detrimental? Is this important at all?
Sometimes fixed size is important to have needed mathematical
properties. For example, SquareMatrix with integer coefficients
has ring structure, in particulatr multiplicative 1. This is
only possible for fixed dimension. OTOH variable size
structure are much more convenient and preferable in
"programming" contexts.
>
> My guess would be that it would be better if Vector's constructor had
> a length parameter, because that would enable greater type safety
> (i.e. I couldn't pass a Vector of the wrong length to a function).
This is problematic. Length of result may be a complicated
function of arguments, then typechecking would be quite complicated.
In FriCAS there is another problem: types exist at runtime,
and it take time to create types and you need memory to store
them. Usually this is not a problem, but computations at
type level are orders of magnitude less efficient than
computations on ordinary values. So one really does not
want to create types at whim. For example, single 'Vector(Integer)'
replaces all types with specified length (wihich could be hundreds
of types in relalistic program).
There are also limits of typechecker: "obviously corrrect" types
mat be rejected by current FriCAS typechecker.
> Is there a way to define a function that takes a Vector of length 3 as
> input, so the input argument's length would be checked by Fricas
> automatically when calling the function?
In general is is quite easy to create fixed length type as
wrapper around variable size type. And efficientcy is quite
good. OTOH trying to create variable size type from
parametric family of fixed size types is quite problematic.
So it is natural to provide mainly variable size types and
create fixed size wrappers when needed. For example main
part of SquareMatrix is just wrapper around variable size
Matrix (but due to math SquareMatrix does not offer some
matrix operations and offers some operations not available
for general matrices).
--
Waldek Hebisch
--
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 on the web visit
https://groups.google.com/d/msgid/fricas-devel/20201101181959.GB29115%40math.uni.wroc.pl.