[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Adding a generic mathematical library
From: |
Christopher Dimech |
Subject: |
Adding a generic mathematical library |
Date: |
Sun, 21 Jul 2024 09:27:40 +0200 |
> Sent: Sunday, July 21, 2024 at 5:19 PM
> From: "Emanuel Berg" <incal@dataswamp.org>
> To: emacs-devel@gnu.org
> Subject: Re: Adding a generic mathematical library
>
> Richard Stallman wrote:
>
> >> but I also have a math.el which I yank below if any of it
> >> can be used.
> >
> > Most of the fnctions in this library are very close
> > to trivial.
>
> Oh, my! Eli thinks they are so exotic only I use them, RMS
> thinks they are close to trivial.
>
> But I have many more files, I'll see what I have that can
> maybe impress you and Eli more.
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.
To promote a mathematical library in Emacs and ensure its broad adoption,
we can think of some things outside the realm of your libraries but which
others would appreciate.
> I have already showed you math.el and perm.el, here are two
> more. But I'll look thru it all some other day and make
> a directory with all of them.
>
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;; https://dataswamp.org/~incal/emacs-init/stats.el
>
> (require 'cl-lib)
>
> (defun decade ()
> (interactive)
> (cl-loop
> with entries = ()
> for d from 190 to 202
> do (push (how-many (format "^.\\{14\\}%d[[:digit:]]" d)) entries)
> finally (message "%s" (nreverse entries)) ))
>
> (defun random-distribution (n sum &optional min no-error)
> "Return a list of N random numbers.
> \nThe sum of the numbers is SUM.
> \nEvery number is at least MIN. (default: 0)
> \nIf NO-ERROR, recompute unsolvable systems with MIN = 0. (default: nil)"
> (or min (setq min 0))
> (let ((min-share (* n min)))
> (if (< sum min-share)
> (if no-error
> (random-distribution n sum)
> (error "Bogus indata, unsolvable") )
> (let ((vals (make-list n min))
> (pool (- sum min-share)) )
> (cl-loop while (< 0 pool)
> do (cl-incf (nth (random n) vals))
> (cl-decf pool) )
> vals) )))
>
> (defalias 'rd #'random-distribution)
>
> ;; (apply #'+ (rd 10 100 3)) ; sum is 100, OK
> ;; (rd 10 100) ; omitted/default min = 0, OK
> ;; (rd 10 100 10) ; border case, but OK
> ;; (rd 10 100 20) ; error: Bogus indata, unsolvable
> ;; (rd 10 100 20 t) ; unsolvable but no-error, recompute for min = 0
> ;;
> ;; 10 example distributions for
> ;; n = 10, sum = 100, and min = 3,
> ;; i.e. (rd 10 100 3):
> ;;
> ;; (12 8 8 10 7 6 19 9 7 14)
> ;; ( 8 12 7 12 9 10 9 9 12 12)
> ;; (14 6 15 11 9 9 6 8 11 11)
> ;; ( 8 12 7 9 10 9 10 13 10 12)
> ;; (12 12 15 6 10 8 6 10 14 7)
> ;; ( 9 7 10 8 11 10 9 10 13 13)
> ;; ( 7 13 13 10 13 10 5 13 5 11)
> ;; (13 8 6 9 13 8 11 7 10 15)
> ;; ( 7 10 5 6 17 14 8 10 14 9)
> ;; (11 10 8 9 11 10 14 11 8 8)
>
> (provide 'stats)
>
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; help from:
> ;; https://codereview.stackexchange.com/q/186840
> ;;
> ;; this file:
> ;; https://dataswamp.org/~incal/emacs-init/str-to-bits.el
>
> (require 'esh-util)
>
> (defun num-to-bits (num)
> (let ((s ""))
> (while (> num 0)
> (setq s (concat (number-to-string (logand num 1)) s))
> (setq num (ash num -1)) )
> (if (string= "" s)
> "0"
> s) ))
>
> (defalias 'dec2bits #'num-to-bits)
> (defalias 'char2bits #'num-to-bits)
>
> (defun str-to-bits (str &optional delim)
> (interactive "sString: ")
> (or delim (setq delim " "))
> (let ((bits))
> (dolist (c (string-to-list str) (mapconcat #'eshell-stringify bits delim))
> (push (num-to-bits c) bits) )))
>
> ;; (str-to-bits "What's up Emacs community?") ; 111111 1110000 1110101 [...]
>
> (provide 'str-to-bits)
>
> --
> underground experts united
> https://dataswamp.org/~incal
>
>
>
- Re: Adding a generic mathematical library, (continued)
- Re: Adding a generic mathematical library, Max Nikulin, 2024/07/20
- Adding a generic mathematical library, Christopher Dimech, 2024/07/20
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Adding a generic mathematical library,
Christopher Dimech <=
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Adding a generic mathematical library, Christopher Dimech, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Christopher Dimech, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Re: Adding a generic mathematical library, Emanuel Berg, 2024/07/21
- Adding a generic mathematical library, Christopher Dimech, 2024/07/21
- Adding a generic mathematical library, Christopher Dimech, 2024/07/21