From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Shouran Ma Newsgroups: gmane.emacs.devel Subject: Adding a generic mathematical library Date: Sat, 27 Jul 2024 16:57:04 +0200 Message-ID: <87r0bekhmn.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11541"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: "Christopher Dimech" , "Stefan Kangas" , "Emanuel Berg" , "Eli Zaretskii" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 27 17:38:18 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 1sXjUv-0002op-RL for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jul 2024 17:38:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sXjU6-0006wp-Vf; Sat, 27 Jul 2024 11:37:27 -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 1sXirA-0001OS-LV for emacs-devel@gnu.org; Sat, 27 Jul 2024 10:57:14 -0400 Original-Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sXir8-00035Y-AQ; Sat, 27 Jul 2024 10:57:12 -0400 Original-Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52f015ea784so306958e87.1; Sat, 27 Jul 2024 07:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722092228; x=1722697028; darn=gnu.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=bkJZr7cbpmrJ2eaQzH1uWOKg7lQLcM4avE24A5iRUT0=; b=KGV5uEW/7XRDp1GylrgLpNMtYwZxquEnj/5V/TpZN+kDTOyWwk+DOEhnyZLr3YgAO3 yePpuh2U2FyCqDbYTa0BhZtZyYF/3E2jrQxPcAUi6fw3UiKdThnvR74lPqp/EOTKBsud MaSbVxuAParL6GKti3klRorTC5BKAi2ci1SNKtf3ICMg67fxUM1BdEpeH8hlNIwPDAXC WMUXMY9SJJF0hOFN8yS8v+hMEoDP5z3p/AWKMFYuzSv8S9Wk7vmcPxIKIv1vjCgRhoL5 F9mPHjTBzRADUbJ6RR+35qD5h2+tSvV8lzsvSaHF1uOHeIOxVSSw0RjWHjpEgW6yUmNj a5UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722092228; x=1722697028; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bkJZr7cbpmrJ2eaQzH1uWOKg7lQLcM4avE24A5iRUT0=; b=QxZnd2jCmt1fMopHyYkzGNwY3xlfl9JEpZjBxc9lDVgxs8J0AxM0rDkL/As5p0MUgL et8K5kFm9ZtRN9X/48UcVyq3CnosgRSpn/YWQiwrn4hfEfPWS0/bx0gTm44704VPf/FD C1iReGImXUoFnEH1tPXzN+kpbWKfJDjffjCxUKzth4EFj5bn5pcpL9TbvZfhDFWSzCLf ztapP6cBbyJPBc2J/ROGpzBxr601EhKjniB4ZKS5jrR2z+rVt03z1YEeyjpqNXf3/qLY dWEoXHNEttcbihlpg5ccQfELHKf6f2EbL15cOcXy5wTEP80Tdo1N6SJ9DA0TF23Nd/E4 z1PQ== X-Forwarded-Encrypted: i=1; AJvYcCWrnPet/RKeS6zA3khm/ukanUFaZClDbFYOVpKjcfcfe1jaz+0ccSyXEKoAleTZq5JLDY0QydnuFXrNug4= X-Gm-Message-State: AOJu0Yx+xPLhNFQq/bMEDO3EDesPlGDra0I5kaIT6RgIFVgPz1ntfZLn eMPR/vxN5FhgfqBX4rr2NRVLAq1TMn7XZd6OvQN0ixAe5bqk1jKD4FvKZlZj X-Google-Smtp-Source: AGHT+IHRCCwGLx8ft0y/XWMY1+7uIWJdy/pAQXqZ0odWd2K17Fj8wca/yNbhNLufJj3g6cefc/D3vg== X-Received: by 2002:a05:6512:68b:b0:52e:ccf4:c222 with SMTP id 2adb3069b0e04-52fd5351eb0mr3163273e87.9.1722092227117; Sat, 27 Jul 2024 07:57:07 -0700 (PDT) Original-Received: from ThinkPad-T470s (81-235-157-129-no600.tbcn.telia.com. [81.235.157.129]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52fd5c2bcefsm781427e87.246.2024.07.27.07.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 07:57:06 -0700 (PDT) In-Reply-To: trinity-f4c0def2-8706-4061-8ff0-7a92b845d079-1721907153761@3c-app-mailcom-bs10 Received-SPF: pass client-ip=2a00:1450:4864:20::130; envelope-from=shouran.ma@gmail.com; helo=mail-lf1-x130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 27 Jul 2024 11:37:24 -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:322129 Archived-At: 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" > 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" > > 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" 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" > > 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" > > 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" > > 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