[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Adding a generic mathematical library
From: |
Shouran Ma |
Subject: |
Adding a generic mathematical library |
Date: |
Sat, 27 Jul 2024 16:57:04 +0200 |
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
- Re: Adding a generic mathematical library, (continued)
Adding a generic mathematical library,
Shouran Ma <=
Re: Adding a generic mathematical library, Shouran Ma, 2024/07/27
- 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