From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Dimech Newsgroups: gmane.emacs.devel Subject: Adding a generic mathematical library Date: Sun, 21 Jul 2024 09:27:40 +0200 Message-ID: References: <8734o9sdig.fsf@posteo.net> <87wmllqq66.fsf@posteo.net> <87plrdqnhc.fsf@posteo.net> <87le21qldj.fsf_-_@posteo.net> <878qy1at52.fsf@dataswamp.org> <87ikwz5nll.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26924"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Emanuel Berg Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 21 09:28:59 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sVR05-0006kz-Dn for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Jul 2024 09:28:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVQzD-0003Fo-0w; Sun, 21 Jul 2024 03:28:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVQz8-0002vd-Lo for emacs-devel@gnu.org; Sun, 21 Jul 2024 03:27:58 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVQyz-0001cj-Ul for emacs-devel@gnu.org; Sun, 21 Jul 2024 03:27:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.com; s=s31663417; t=1721546860; x=1722151660; i=dimech@gmx.com; bh=X6gwrpdWZxngE6cdvSBzwxoPNQ7YrjJW9bZh+fT3t6E=; h=X-UI-Sender-Class:MIME-Version:Message-ID:From:To:Cc:Subject: Content-Type:Date:In-Reply-To:References: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=dANa/BNd2NxLoyBmZce9OpzGng2vCWqBMs7S57zwmwzBiD9V0ikLLY50SDpJWHD2 Ia+H2mnhicHIjAzxcQ/UwN/FMBKsOrFD13j4DwQV1C0sO4aoN3NFyNQXU2xgasDQm 1c2TbPxOg00HHGh6N2Gucm9+rl/g54KAaYASYZcpZPVVAWC4gfH4aQZ/Gb0kOKIKh GVKqpCExjTwri5ohhQted6Rr73vancs6XkvaW/d73QYQMl1Q1Z50eeDvTtHAUyN0m GaH9p6jcJ3otZibDOzI6QswiqbKghT+wAosEdKdj3hiYHBPXSEo1ww70IsPWu1lag HS73tLjPw9ALERbY2g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from [92.251.79.197] ([92.251.79.197]) by web-mail.gmx.net (3c-app-mailcom-bs10.server.lan [172.19.170.178]) (via HTTP); Sun, 21 Jul 2024 09:27:40 +0200 Importance: normal Sensitivity: Normal In-Reply-To: <87ikwz5nll.fsf@dataswamp.org> X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:gnDIDxNfBVvR0eztkO18qiVbHUnz82atUvqdRt2e1HymgKMv/hsMyy6+mpQKye1LTLBdD IOnLu1Qb7Dw8+zrYIFZw/jtgqucFC55ZjACCBZBYt10BOr0jnGBC2zR/mZiXR10/DyIOLuw//1Oi Gx8VQ2is+iOfxQcsIPFQpS2gTDZQd+ByAWJeE5+q9i2WN5ZVntIm8F4qegdCvOVjet5VW5/M32Z9 T8SfVtNXA67SqRTAYsKhkk4e3gyG7PmP5yufLYVA9jYgwTGZbyNGznrg8/WDAjbqOEEd7vv9v/Rp Zo= UI-OutboundReport: notjunk:1;M01:P0:o9TucXl6YJM=;qrmFdRCeMOlg4aZxdyYfqMgYwyp RoeJarvzEwwRsP72v3ISBuMXA4uR+VwAzDmG+nk4ItWYHPyUjbpqNXOoUOGeSpWbuzxXnlZCS e8e3UDVucuFDA8eOVENF4Zi7DJZkIluaELlfQAS/vqgOLsKqcxpNBMLycoIwXnNrPrBoyCEet pOEWfb6a8US9D8Ep0vP+lkxRVyEjiavKiKZaNpcCCM/0nuzDDY4dNXrYrq4eA2y/A4VK158Tz BNP6Ud0DhtDMMyXN0BDuG3tV9cBvNtxAyobDP4QJtU1R5vIT1tMCamOPApoe+OdW+OZwn+L0o z1EbuE8QDzqASnMzAvzJDQQMbtJIgf60TZpoYkrcS5NqORcho8e1DIXdqwGQjy+cJkfgY/Nn0 lRWVXZDZsDPIvbtoB124VKjryjZ+OaqhAo03PLSjS04tbro1fSZMR/5lLKWuUICJVDzfeFfLY Fc54L/eDOmq2Xw0TJLgehFwgjRyEoRvJSOXfL65cTFc0+Wnxf8A/FlMDmGCdPGwn4B6S6BmnJ e0NKkJ9rD+Vx02TOxssVRyZnUKe9n6lQsYKmBOyXvIzytqB72S/7Qbwj5H50Ne6BGxAc644Nb YLBqE8hVfAmOXoEHFizJI6kg5KgV532D4Jdf5xgprB+8dGKEasO+HeLT3e8LPLqXhf6QWl/ao 8/xDM6Dp+WazqLsKkLMPERbWpxN9eYZYw0js2q+KaA== Received-SPF: pass client-ip=212.227.15.18; envelope-from=dimech@gmx.com; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:321858 Archived-At: > Sent: Sunday, July 21, 2024 at 5:19 PM > From: "Emanuel Berg" > 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 =3D () > 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 =3D 0. (default: ni= l)" > (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 =3D 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 mi= n =3D 0 > ;; > ;; 10 example distributions for > ;; n =3D 10, sum =3D 100, and min =3D 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=3D "" 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 d= elim)) > (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 > > >