all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Adding a generic mathematical library
@ 2024-07-27 19:07 Shouran Ma
  2024-07-27 19:23 ` Christopher Dimech
                   ` (2 more replies)
  0 siblings, 3 replies; 103+ messages in thread
From: Shouran Ma @ 2024-07-27 19:07 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: emacs-devel, Sergey Kostyaev, Philip Kaludercic


> 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



^ permalink raw reply	[flat|nested] 103+ messages in thread
* Adding a generic mathematical library
@ 2024-07-27 14:57 Shouran Ma
  2024-07-27 15:49 ` Emanuel Berg
  0 siblings, 1 reply; 103+ messages in thread
From: Shouran Ma @ 2024-07-27 14:57 UTC (permalink / raw)
  To: Christopher Dimech, Stefan Kangas, Emanuel Berg, Eli Zaretskii
  Cc: emacs-devel


Glad to see that there is an active discussion on Emacs Math library.

0. Readiness of becoming one of the maintainers

> Sent: Thursday, July 25, 2024 at 17:34 +0200
> From: "Christopher Dimech" <dimech@gmx.com>
> There might be concerns about readiness because potential maintainers
> often gain experience by working closely with current maintainers.
> This apprenticeship-like model helps them understand the responsibilities,
> workflows, and expectations involved in maintaining a GNU package.

I would like to be one of a maintainers.



1. Introduction

I looked inside the Calc subsystem in the past days. In this mail I will
summarize several wishing features and potential problems during
developing.

Calc provides several types, c.f. calc-prog.el the "calcFunc-typeof"
function. I will talk about the members in this function.

About my experiments involve Common-Lisp (CL), my settings is, connect to
sbcl and open lisp-mode for a buffer, then put the cursor after the
expression and hit "C-x C-e" to view the result at *Messages* buffer.



2. Wish-list: Extend the basic number types: frac & cplx

Although basic number types are even not a part of a math library, but
that's crucial that do not set a barriers for the users especially at
such fundamental things. For example, we can include the rational type
(frac) and complex type (cplx) as the basic Elisp number types.
Especially, CL has implemented this feature.

Tasks would involve how to INTERPRET the slash "/" and small groups of
numbers, , e.g., in CL,
- (type-of 5/2)          ; => TATIO
- (type-of 5 / 2)        ; => invalid number of arguments: 3
- (type-of #C(1.0 1.0))  ; => (COMPLEX (SINGLE-FLOAT 1.0 1.0))
- (type-of #C(5/2 1/5))  ; => (COMPLEX (RATIONAL 1/5 5/2))

We should figure out a unified way to represent the rational and complex.

After that, we should implement eGCD and overload the "+ - * % < >" to
include the rational number arithmetics. This would be a huge workload
to expand the number group.

For eGCD we can look into NTL library for more efficient impl.



3. Wish-list: Pretty output format for integers and rationals

In Emacs, hit "M-:" to "Eval: " 100, we get
100 (#o144, #x64, ?d)
In CL, put the cursor after 100 and "C-x C-e" we get
=> 100 (7 bits, #x64, #o144, #b1100100)
Similarly for the number "5/2", we get
=> 5/2 (2.5)
But for the number "5 / 2" (separated by space) we get
=> 2 (2 bits, #x2, #o2, #b10)

It's obviously that CL's style is more friendly to the user. We can
improve the representation of the Elisp result to:
=> 100 (7 bits, #x64, #o144, #b1100100, ?d)



4. Problem of representing the vectors/lists and the corresponding funcs

In Calc, the vector types are prefixed with a "vec" symbol in this way:
(vec 1 2 3)
so that in Calc, things in vectors are indexed from 1, not from 0 (like
many other languages). This is a bad way to index a vector and would
cause a nightmare for the potential developers who will use Emacs-Math.

Besides (vec 1 2 3), there are many other ways to represent an array-like
object, c.f.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Sequences-Arrays-Vectors.html
- cons/list type: (1 2 3 4 5)
- vector type: [1 2 3 4 5]

However, WE DON'T EVEN HAVE A UNIFIED WAY TO REPRESENTING A VECTOR.

As for my knowledge, vector type in Emacs support random access while
list/cons type is accessed by "link-list" search way. However, there are
many builtin functions to handle the list type, but too few to handle
the vector type. If you try to rewrite "calcFunc-diag" (in calc-vec.el)
you would know the feeling.

So if we want to use the builtin vector type to represent vectors and
handle vectors, we must first of all complete the corresponding
vector-handling functions, for example, "slice".



5. Functions in GNU C library, and power (expt)

> Sent: Sunday, July 21, 2024 at 17:33 +0200
> From: "Eli Zaretskii" <eliz@gnu.org>
>
> I don't know what math-sin-cos-raw is about, but as for math-hypot,
> there's no need to implement anything, since this function is standard
> in any C libm, and we can easily expose it to Lisp if we need to.

> Send: Sunday, July 21, 2024 at 14:46 +0200
> From: "Emanuel Berg" <incal@dataswamp.org>

Here is the full list of the functions from GNU C library:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Numbers.html

If new data types (especially the complex) are introduced, functions in
this list should be carefully overloaded to the complex number case.

Besides, where is the origin of the "expt" for the power? (CL use this
name, though).

Personally, I would suggest to add "powm" or "exptm" or such name, to
implement the power-mod.



6. Problem of inclusion the statistical functions

> Sent: Sunday, July 21, 2024 at 09:27 +0200
> From: "Christopher Dimech" <dimech@gmx.com>
>
> We should ask the community what tools they would like to use,
> whether combinatorics, random numbers (Gaussian, Bernoulli, Binomial),
> ...

> Sent: Sunday, July 21, 2024 at 17:49 +0200
> From: "Eli Zaretskii" <eliz@gnu.org>
>
> The original issue was not about Calc, it was about a standalone math
> library.  For that, we should first define the scope.  One possibility
> is to expose to Lisp everything in a typical libm, but is that needed?
> Another possibility is to provide a statistical library (average,
> median, standard deviation, t-Student, F-test, chi-square, etc.) --
> but do we need this?  Etc. etc. -- "math library" can be interpreted
> in many different ways.

Mean and variance are the most frequently used statistical functions,
but before this, we should solve bullet 4, after that, we can then
considering to generate an VECTOR that subjected to Gaussian, Bernoulli,
Binomial distribution.



7. Symbolic functions and suggestion of inclusion math library as a
minor mode

> Sent: Sunday, July 21, 2024 at 09:27 +0200
> From: "Christopher Dimech" <dimech@gmx.com>
>
> May I suggest "Units and Conversions".  "Symbolic Simplification"
> could also be a candidate.

From a user aspect, If I want to use symbolic calculus, I would do so:
- "M-x" to open "math-symbolic-mode"
- Input "(sin x)" will just return the expression "(sin x)", not void-variable
- Input "(math-read-expr "(x+1)*(x+2)")" gives "(* (+ x 1) (+ x 2))"
instead of "(* (+ (var x var-x) 1) (+ (var x var-x) 2))"

That means, in such "math-symbolic-mode" (the minor mode), symbol "x" is
just symbol "x", not "void-variable", so that things would look prettier
in the returned expression instead of "(var x var-x)".



8. Summary

The first four bullets are not even involve the affairs of implementing
a math library or transferring the codes from Calc. But that would be a
great start for the further work if we implementing the mentioned
features.


-- 
Best Regards,
Shouran MA



^ permalink raw reply	[flat|nested] 103+ messages in thread
* Adding a generic mathematical library
@ 2024-07-23 20:00 Kepa
  2024-07-25  4:19 ` Emanuel Berg
  0 siblings, 1 reply; 103+ messages in thread
From: Kepa @ 2024-07-23 20:00 UTC (permalink / raw)
  To: emacs-devel; +Cc: dimech

>"We should ask the community what tools they would like to use,
>whether combinatorics, random numbers (Gaussian, Bernoulli, Binomial), ...

>May I suggest "Units and Conversions".  "Symbolic Simplification"
>could also be a candidate."

Units are a differentiating element. I have found very few languages that use units and I consider myself lucky to have calc. Calc seems to have bugs when working with units though:
https://lists.gnu.org/archive/html/help-gnu-emacs/2024-02/msg00144.html

The embedded mode is also amazing: being able to write text, mixed with mathematical operations, variables and units.

Best regards




^ permalink raw reply	[flat|nested] 103+ messages in thread
* Add elisa to GNU ELPA
@ 2024-07-12 16:47 Sergey Kostyaev
  2024-07-16 12:54 ` Philip Kaludercic
  0 siblings, 1 reply; 103+ messages in thread
From: Sergey Kostyaev @ 2024-07-12 16:47 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

Hi all,

Please add https://github.com/s-kostyaev/elisa to GNU ELPA. This package implements RAG (Retrieval Augmented Generation) for `ellama'. Today I have released 1.0.0 with info manuals, web search and local files support.

Best regards,
Sergey Kostyaev

[-- Attachment #2: Type: text/html, Size: 576 bytes --]

^ permalink raw reply	[flat|nested] 103+ messages in thread

end of thread, other threads:[~2024-08-01  6:42 UTC | newest]

Thread overview: 103+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-27 19:07 Adding a generic mathematical library Shouran Ma
2024-07-27 19:23 ` Christopher Dimech
2024-07-28  0:29   ` Emanuel Berg
2024-07-28 10:58     ` Christopher Dimech
2024-07-28 11:39       ` Emanuel Berg
2024-07-28 12:28         ` Christopher Dimech
2024-07-28 13:02           ` Emanuel Berg
2024-07-30  2:53     ` Richard Stallman
2024-07-30  3:53       ` Emanuel Berg
2024-07-30  6:26       ` Christopher Dimech
2024-07-30  7:20         ` Emanuel Berg
2024-07-30 11:30           ` Christopher Dimech
2024-07-30 22:56             ` Emanuel Berg
2024-07-31 16:00               ` Michael Heerdegen via Emacs development discussions.
2024-07-31 21:15                 ` Emanuel Berg
2024-08-01  6:05                   ` Eli Zaretskii
2024-08-01  6:42                     ` Emanuel Berg
2024-07-31 21:26                 ` Emanuel Berg
2024-07-27 19:40 ` Christopher Dimech
2024-07-28  0:24   ` Emanuel Berg
2024-07-28 13:34   ` Immanuel Litzroth
2024-07-28 13:56     ` Christopher Dimech
2024-07-28 14:07       ` Emanuel Berg
2024-07-28 10:46 ` Emanuel Berg
  -- strict thread matches above, loose matches on Subject: below --
2024-07-27 14:57 Shouran Ma
2024-07-27 15:49 ` Emanuel Berg
2024-07-23 20:00 Kepa
2024-07-25  4:19 ` Emanuel Berg
2024-07-25 11:32   ` Christopher Dimech
2024-07-25 14:20     ` Stefan Kangas
2024-07-25 15:16       ` T.V Raman
2024-07-25 15:34       ` Christopher Dimech
2024-07-25 17:12         ` Emanuel Berg
2024-07-25 17:25       ` Emanuel Berg
2024-07-25 14:24     ` Emanuel Berg
2024-07-25 15:49       ` Christopher Dimech
2024-07-25 17:23         ` Emanuel Berg
2024-07-12 16:47 Add elisa to GNU ELPA Sergey Kostyaev
2024-07-16 12:54 ` Philip Kaludercic
2024-07-16 13:57   ` Sergey Kostyaev
2024-07-16 16:04     ` Philip Kaludercic
2024-07-16 16:41       ` Sergey Kostyaev
2024-07-16 17:02         ` Philip Kaludercic
2024-07-16 17:47           ` Adding a generic mathematical library Philip Kaludercic
2024-07-16 22:06             ` Emanuel Berg
2024-07-17  2:54               ` Christopher Dimech
2024-07-17  5:58                 ` Emanuel Berg
2024-07-19 16:16               ` Richard Stallman
2024-07-19 17:38                 ` Christopher Dimech
2024-07-21  5:20                   ` Emanuel Berg
2024-07-20 12:45                 ` Max Nikulin
2024-07-20 13:53                   ` Christopher Dimech
2024-07-21  5:19                 ` Emanuel Berg
2024-07-21  6:15                   ` Emanuel Berg
2024-07-21  7:40                     ` Emanuel Berg
2024-07-21  8:45                       ` Emanuel Berg
2024-07-21  8:29                     ` Emanuel Berg
2024-07-21  7:27                   ` Christopher Dimech
2024-07-21  8:03                     ` Emanuel Berg
2024-07-21  9:14                       ` Christopher Dimech
2024-07-21  9:48                         ` Emanuel Berg
2024-07-21 11:20                           ` Emanuel Berg
2024-07-21 11:53                             ` Christopher Dimech
2024-07-21 12:10                               ` Emanuel Berg
2024-07-21 12:27                                 ` Emanuel Berg
2024-07-21 12:46                                   ` Emanuel Berg
2024-07-21 13:03                                   ` Christopher Dimech
2024-07-21 13:17                                     ` Emanuel Berg
2024-07-21 14:33                                       ` Eli Zaretskii
2024-07-21 14:41                                         ` Christopher Dimech
2024-07-21 14:49                                           ` Eli Zaretskii
2024-07-21 14:58                                             ` Christopher Dimech
2024-07-21 15:02                                               ` Eli Zaretskii
2024-07-21 15:18                                                 ` Christopher Dimech
2024-07-21 13:18                                     ` Christopher Dimech
2024-07-21 13:26                                       ` Emanuel Berg
2024-07-21 14:35                                         ` Christopher Dimech
2024-07-21 19:28                                           ` Emanuel Berg
2024-07-21 19:33                                           ` Emanuel Berg
2024-07-21 19:51                                           ` Emanuel Berg
2024-07-21 20:01                                           ` Emanuel Berg
2024-07-21 20:17                                           ` Emanuel Berg
2024-07-21 12:41                                 ` Christopher Dimech
2024-07-21 13:13                                   ` Emanuel Berg
2024-07-21 13:41                                   ` Emanuel Berg
2024-07-21 12:20                               ` Emanuel Berg
2024-07-21 12:04                             ` Emanuel Berg
2024-07-17  7:09             ` Michael Heerdegen via Emacs development discussions.
2024-07-17  7:54               ` Philip Kaludercic
2024-07-17  7:56               ` Michael Heerdegen via Emacs development discussions.
2024-07-18  6:07                 ` Emanuel Berg
2024-07-18  6:45                   ` Christopher Dimech
2024-07-18  7:12                     ` Emanuel Berg
2024-07-18  7:49                       ` Christopher Dimech
2024-07-21  4:56                         ` Emanuel Berg
2024-07-18  7:29                   ` Eli Zaretskii
2024-07-18  7:57                     ` Emanuel Berg
2024-07-18  9:03                       ` Eli Zaretskii
2024-07-21  4:52                         ` Emanuel Berg
2024-07-18  8:15                     ` Emanuel Berg
2024-07-18  9:04                       ` Eli Zaretskii
2024-07-18  9:13                       ` Christopher Dimech
2024-07-21  4:59                         ` Emanuel Berg
2024-07-19 13:22                       ` Emanuel Berg
2024-07-19 16:12                         ` Christopher Dimech
2024-07-19 16:15                           ` Stefan Kangas
2024-07-19 16:29                             ` Christopher Dimech
2024-07-19 16:16               ` Richard Stallman
2024-07-19 18:00                 ` Christopher Dimech

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.