[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding a generic mathematical library
From: |
Shouran Ma |
Subject: |
Re: Adding a generic mathematical library |
Date: |
Sat, 27 Jul 2024 21:07:33 +0200 |
> Sent: Saturday, July 27, 2024 at 16:57 +0200
> From: "Shouran Ma" <shouran.ma@gmail.com>
>
> However, WE DON'T EVEN HAVE A UNIFIED WAY TO REPRESENTING A VECTOR.
I need to elaborate this statement, otherwise it cause confusion to
others.
Elisp provides "List" and "Vector" as an array of numbers:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Sequences-Arrays-Vectors.html
To express an array of numbers, a developer would either use two of them
- (setq x '(1 2 3 4)) ; (type-of x) => cons
- (setq x [1 2 3 4]) ; (type-of x) => vector
"cons" (or "list") is the first thing that everybody would choose, for
example, in Sergey's elisa:
https://github.com/s-kostyaev/elisa/blob/main/elisa.el
In the function "elisa--distances", Sergey puts "head" and "(car tail)"
as arguments to "elisa-cosine-distance", this means Sergey uses
cons/list to organize array of numbers.
However, Elisp also has "array" types:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Arrays.html
> An array object has slots that hold a number of other Lisp objects,
> called the elements of the array. Any element of an array MAY BE
> ACCESSED IN CONSTANT TIME. In contrast, the time to access an element
> of a list is proportional to the position of that element in the list.
cons/list is something like "linked list" which is not accessed in const
time, but vector support this, e.g. it takes more time to access the
last element if we use cons/list, but less time if use vector.
However, Elisp provides too few functions on operating the vector type,
for example, to slice a vector like the way in python: array[2:4].
So my saying "don't even have a unified way to representing a vector", I
mean, to organize/represent a MATHEMATICAL vector
- I would prefer to choose the object that support const time access,
i.e. the BUILTIN vector type, over the cons/list.
- However, the BUILTIN vector type supports quite a few functions, which
forces me to change my mind to organize/represent the MATHEMATICAL
vectors by cons/list.
This is the dilemma during developing my own math libraries.
Besides, in the Calc subroutine, the MATHEMATICAL vectors are
represented by cons/list in this way
(vec 3 5 2 1 0) ; not (3 5 2 1 0) or [3 5 2 1 0]
i.e. a symbol "vec" is placed at the beginning of the list, in order to
simplify the predication. But this leads to the indexing problem, that
elements are indexed since 1, not 0. Such an indexing scheme would cause
a nightmare to the developer who want to use our math subroutine to do
further development.
In summary, if the builtin vector type is preferred way to represent the
MATHEMATICAL vector, we should first of all complete the fundamental
vector operations, like vector slicing etc. And of course, we should
take a look at how sbcl
https://git.code.sf.net/p/sbcl/sbcl
organize their vector and their vector functions.
>From my side, I don't want to touch the vector things so far, but instead
the rational number (the bullet 2 & 3 in my previous mail).
Finally,
> Sent: Saturday, July 27, 2024 at 17:49 +0200
> From: "Emanuel Berg" <incal@dataswamp.org>
>
> However it used to be even worse, when we didn't even have clocks!
If the "clock" you said is the clock to measure how long a function
runs, we have, it is "benchmark-run".
--
Best Regards,
Shouran Ma
Adding a generic mathematical library, Shouran Ma, 2024/07/27
Re: Adding a generic mathematical library,
Shouran Ma <=
- Re: Adding a generic mathematical library, Christopher Dimech, 2024/07/27
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/28
- Re: Adding a generic mathematical library, Christopher Dimech, 2024/07/28
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/28
- Re: Adding a generic mathematical library, Christopher Dimech, 2024/07/28
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/28
Re: Adding a generic mathematical library, Richard Stallman, 2024/07/29
Adding a generic mathematical library, Christopher Dimech, 2024/07/30
Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/30
Adding a generic mathematical library, Christopher Dimech, 2024/07/30