From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.devel Subject: Re: Adding a generic mathematical library Date: Sun, 21 Jul 2024 07:19:02 +0200 Message-ID: <87ikwz5nll.fsf@dataswamp.org> References: <8734o9sdig.fsf@posteo.net> <87wmllqq66.fsf@posteo.net> <87plrdqnhc.fsf@posteo.net> <87le21qldj.fsf_-_@posteo.net> <878qy1at52.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19518"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:26+dbzWUZh8lU6BhOpHh5D0//ng= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 21 07:30:08 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 1sVP96-0004tO-Ft for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Jul 2024 07:30:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVP8n-0005Y3-9z; Sun, 21 Jul 2024 01:29:49 -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 1sVOyg-0002H1-8L for emacs-devel@gnu.org; Sun, 21 Jul 2024 01:19:22 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVOye-0006DW-BX for emacs-devel@gnu.org; Sun, 21 Jul 2024 01:19:22 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1sVOyZ-00047x-5S for emacs-devel@gnu.org; Sun, 21 Jul 2024 07:19:15 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 21 Jul 2024 01:29:47 -0400 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:321855 Archived-At: 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. 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