GNU bug report logs - #71890
31.0.50; Calc can't integrate 0

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Michael Heerdegen <michael_heerdegen@HIDDEN>; Keywords: patch; dated Tue, 2 Jul 2024 00:48:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 71890 <at> debbugs.gnu.org:


Received: (at 71890) by debbugs.gnu.org; 4 Mar 2025 01:41:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 03 20:41:37 2025
Received: from localhost ([127.0.0.1]:53356 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpHHt-0006oX-7r
	for submit <at> debbugs.gnu.org; Mon, 03 Mar 2025 20:41:37 -0500
Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:49488)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tpHHp-0006oG-1W
 for 71890 <at> debbugs.gnu.org; Mon, 03 Mar 2025 20:41:34 -0500
Received: by mail-ed1-x530.google.com with SMTP id
 4fb4d7f45d1cf-5e058ca6806so8280087a12.3
 for <71890 <at> debbugs.gnu.org>; Mon, 03 Mar 2025 17:41:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741052487; x=1741657287; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=MuJn54oDXOpfKkb32J6KgZyYbt/fsN0mpnyBSw9oFaI=;
 b=YDy4Z0a3EZeTzmQL+8Hmc0V0PABnp7FM3AcM/PaO2xifMOapxZ3vQFGDI90c88GU+k
 rekNX30kJMR/4dJIIOHgyGY07kkR1s4J6fI2sG+TvZxsVA0vRzgMyk46SGp/lCcDGZTi
 /CSVoP/P+Hxs51qjm1vCHxiIoJwcjNaqh2/EDrwVQMH45ZNyC2NifxBl7qgs4LmuYXAs
 guqh/yUqY/6yn//FY/rMrHEjN2B6a5CZQvkvbvFwgUBkDXWw7Vuu4hA+lPdpB4HnRHNZ
 RNEPFIUOl/KLLUCkHvELcmiaj6HkQJGAScPTjd4RyRUFr5JvP2699afiRCj116HCV4WK
 aOlg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741052487; x=1741657287;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=MuJn54oDXOpfKkb32J6KgZyYbt/fsN0mpnyBSw9oFaI=;
 b=KCPUYbR9I7CUuEZ0xD/CsPPJ6LX4dCNTTzfrnq3zkID9T+M61ewf2CBfgwb8k4mgEf
 6dYGshf3Ilw9gKNJoqqeeGYvaEZ5VlZWePiqWG7sXzecRiH37N9sdgh803bPqj9pMTiF
 Wlt2u1vKSewO7nll5z/RkRwKqtho7wAhsDitZ4vfcF9BGYJ3gJe651jW3RkzOUaciZqu
 1bpPfzNIw/T3TNkGJoZOJBG6LW6+gTeymemBe8B9TiZeURH2Jjl+dDfVK2QKzqMTrouv
 LWvi5LC8a0yzGRAXoWqhu8vkZ8lTehIDtr3YDTWDsDjxQB5/N+foDFjq+xSuT5fn6k6D
 /8JQ==
X-Gm-Message-State: AOJu0YzavGrc+lm/m22YndTzlQ+Qd+/e9tzvyrqxjQXG+EGVuFnFo/cU
 BwC5q5QnHvp8ZJralWMT+x7kWr/Rwj3REFopqaKls1ACaXRcHuZjPsHwvY4PHyoxpOKH7TUEb1d
 B43VNh+QXdMLY5a6rpvBanYD/ntQ=
X-Gm-Gg: ASbGnctNl0HXC8Ri4ecjTLIyWntsQp66ksJ9luZdL4P+XCniQyUi22Eo5546jqgnvom
 K1ouD3/gDJfwbPhmGt8zHpOpYbCqDywdqRE2vennIFWoMU2wofYuc8Xv+J7FDSmOBIhGM25tsKw
 EOzQmz6kzpyfvW/c+W5m7c++3Y8A==
X-Google-Smtp-Source: AGHT+IEQ7E9i2FkQwDxVYO8LMhmOSFn+l6JjJYNWp0BFs3+LOMoq7WhRUq2Ss5k2xeCwAwdrXacVozEzmeaooXhDo+g=
X-Received: by 2002:a05:6402:13d6:b0:5e4:d528:7a76 with SMTP id
 4fb4d7f45d1cf-5e4d6ad5106mr16777527a12.6.1741052486606; Mon, 03 Mar 2025
 17:41:26 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Mon, 3 Mar 2025 17:41:26 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <87cynwty9v.fsf@HIDDEN>
References: <87cynwty9v.fsf@HIDDEN>
MIME-Version: 1.0
Date: Mon, 3 Mar 2025 17:41:26 -0800
X-Gm-Features: AQ5f1Jp7MkRrKv3C-3dBt8vFG8fR0BcOUVxmtQA-Bx0-roXoHt3qR1YKej3wcEE
Message-ID: <CADwFkm=qz82sbOXcGCC87m8S=7oz6YsPdv=zoXAztRC3ocL1nw@HIDDEN>
Subject: Re: bug#71890: 31.0.50; Calc can't integrate 0
To: Michael Heerdegen <michael_heerdegen@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 71890
Cc: 71890 <at> debbugs.gnu.org,
 =?UTF-8?Q?Mattias_Engdeg=C3=A5rd?= <mattias.engdegard@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Michael Heerdegen <michael_heerdegen@HIDDEN> writes:

> Hello,
>
> Any Calc experts around?  emacs -Q:

I don't think we do, sadly.  Mattias has looked at it a little bit at
times in the past, maybe he could take a look?

>   M-x calc RET
>   0 RET
>   a i x RET
>
> is a way to integrate 0 using Calc (with integration variable x in this
> case).  Calc fails to solve it:
>
> The result Calc gives you is "integ(0, x)" - Calc leaves the integral
> unresolved, which is Calc's way to say "I can't solve this".  This
> is definitely not a feature or a way to represent an integration
> constant - (info "(calc) Integration"):
>
> | Also, any indefinite integral should be considered to have an
> | arbitrary constant of integration added to it, although Calc does not
> | write an explicit constant of integration in its result.
>
> So what is going on?  Other functions, including constants like 1 or a
> symbol work as expected.
>
> As far as I understand, Calc is internally perfectly able to solve this
> integral but at one place in the code the correct result is rejected
> because this case is so special that the authors forgot to make the code
> expect a result of such a simple form.  This small change helps:
>
> From a4351149314af2dab8f03715a9effeb2ee26490c Mon Sep 17 00:00:00 2001
> From: Michael Heerdegen <michael_heerdegen@HIDDEN>
> Date: Fri, 23 Jun 2023 04:44:34 +0200
> Subject: [PATCH] WIP: Try to fix integration of 0
>
> ---
>  lisp/calc/calcalg2.el | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/lisp/calc/calcalg2.el b/lisp/calc/calcalg2.el
> index 5e9ae8a3e5a..fafbd8418ef 100644
> --- a/lisp/calc/calcalg2.el
> +++ b/lisp/calc/calcalg2.el
> @@ -774,12 +774,13 @@ math-integral
>      (setq val math-cur-record)
>      (while (vectorp (nth 1 val))
>        (setq val (aref (nth 1 val) 0)))
> -    (setq val (if (memq (nth 1 val) '(parts parts2))
> -		  (progn
> -		    (setcar (cdr val) 'parts2)
> -		    (list 'var 'PARTS val))
> -		(and (consp (nth 1 val))
> -		     (nth 1 val))))
> +    (let ((val-1 (nth 1 val)))
> +      (setq val (if (memq val-1 '(parts parts2))
> +		    (progn
> +		      (setcar (cdr val) 'parts2)
> +		      (list 'var 'PARTS val))
> +		  (and (or (consp val-1) (equal val '(0 0)))
> +		       val-1))))
>      (math-tracing-integral "Integral of "
>  			   (math-format-value expr 1000)
>  			   "  is  "
> --
> 2.39.2
>
>
> The problem is: I found this fix by trial and error, someone who knows
> the code should verify that the fix is correct.  For example, I don't
> know whether 0 is always represented as list (0 0) at this point (given
> how many different settings there are...) and whether it is the correct
> code place to handle this case.

We have minimal or no unit tests in this area.

Maybe this would be a good opportunity to add more?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71890; Package emacs. Full text available.
Added tag(s) patch. Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 2 Jul 2024 00:47:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jul 01 20:47:16 2024
Received: from localhost ([127.0.0.1]:35181 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sORfw-0005pq-BX
	for submit <at> debbugs.gnu.org; Mon, 01 Jul 2024 20:47:16 -0400
Received: from lists.gnu.org ([209.51.188.17]:51586)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <michael_heerdegen@HIDDEN>) id 1sORfr-0005pg-OX
 for submit <at> debbugs.gnu.org; Mon, 01 Jul 2024 20:47:14 -0400
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 <michael_heerdegen@HIDDEN>)
 id 1sORfq-0005z0-LW
 for bug-gnu-emacs@HIDDEN; Mon, 01 Jul 2024 20:47:10 -0400
Received: from mout.web.de ([212.227.17.12])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <michael_heerdegen@HIDDEN>)
 id 1sORfo-0004PU-GV
 for bug-gnu-emacs@HIDDEN; Mon, 01 Jul 2024 20:47:10 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de;
 s=s29768273; t=1719881225; x=1720486025;
 i=michael_heerdegen@HIDDEN;
 bh=BrErjfZGzsx6HtECLdhuCSlrnGk3vMbm/mWErRJUVe0=;
 h=X-UI-Sender-Class:From:To:Subject:Date:Message-ID:MIME-Version:
 Content-Type:cc:content-transfer-encoding:content-type:date:from:
 message-id:mime-version:reply-to:subject:to;
 b=igbZJE0ksfLQQ7WPMNwgyg9jH+YUxhSpfBwIGh95zXJY2xmEJrWRG7nz3YGWrMEX
 ciqgAspZZYxnbIY/WVAAd603FlZlBUVP6tT8iVV6r7Mok6ez5hrboaPonIAtvw/E1
 8gJXahqgcxiAbKpKWL5M3xB4OpovZ2v5fD3Sf0dmMyfQMCbmMaDimltwwne7SMTyy
 KCBA+bV/DXoOrnzKpZCfyfIHAOMas9jtMh2OdbHiDyyo3JzbzNjNv1bVq87YF1z5v
 R7Ivs75o02JXQ+p1WTrTCEWCCocwyygfPgsuT5fZXJBMaJHKUHjafkr+sL2jLoAdx
 YvCVm4QuCuZO/FDzwA==
X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6
Received: from drachen.dragon ([84.59.210.113]) by smtp.web.de (mrweb106
 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MW9vU-1surju43VC-00N36E for
 <bug-gnu-emacs@HIDDEN>; Tue, 02 Jul 2024 02:47:05 +0200
From: Michael Heerdegen <michael_heerdegen@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.50; Calc can't integrate 0
X-Debbugs-Cc: 
Date: Tue, 02 Jul 2024 02:47:56 +0200
Message-ID: <87cynwty9v.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Provags-ID: V03:K1:p5IDLSnlWtI0HVYSI4/iJW8sSTRXwns/m9zRZQJgDhbVtXM9FQS
 BbbHchxq8QCB7sXwWJhdx1TbA3YcewTumEFBbAfJ8K8KnYW+8PVYj1czFeEwEiNWRf+xhrJ
 GKACO2DnH/H8Bn/DGSZu3RikaFJ+VIZF+tK59qJaO1q7Z/Uvb2k5/iZdZcUQ9/9IyJza8ei
 MOe1Flk5OXZvbFIIh0Hnw==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:pfCMBD/IY4k=;w4B3zfJFtPUIE43QV3tc51a++Tb
 AjWjZEI//R/YVEOFm6NB8xgvjUn/X/VDQgGi/wK9fEdX7tBaVseRJQM+tfj2TBdVkKN18q/5Q
 6L2UkUsa9my8S8uDAUKxZTrasIOt1ENdBQTG1gdD0/DTINfbdsA43sSNHIzN4IivqvwAL6Q9J
 Zez/o3DO9QsfnB8VGV5oFusYac2PlU+AWxTeZ1WEJMJUlw5DOyzV5bP0hgDRq54LMcCqggj3e
 du01aR4Rhd/bIHD+PRMSaT62HK6P3J7YeN4tjk4778CcpXDcnZoTlERDS56vL7mMQBGfX6k7U
 Ye8tk9bhKmzvGNUCXflfm6h/Y1lfurywqxPJuQ7yliTuyC8uu9C88e5JJQFXho3rCiuYsn5CF
 gZnTbNRzMKb58gxUINtvKnGGQaBHpF3CcYq2Y6Dl9DhPMydl2e6NeT+aeQVr/PqQxSmad1zqq
 EiTr+zZCNxJvYMRywPux+m0DPX6xyK8nZdMVgGktkogyT4sZesPWQhfj8qNiuNhFxR2emcoQf
 n+d5aXxJaOY8kE2HMkxiDrwe3+qgfPaT+B4cYhBBh0rAcaYuPvo5qG5FPmNcgLDCua0E6fYOY
 FWVpkzWF+AbxsluqikcOIn13X+Mz56WflAiIjQDBrF9pIbJ/U5e6rXKQr8ODfAwmPRxw6ICKI
 e3IcVfEJf9dD+TyewS0eiF2IexyLiiPjLsPd67I9EFMKVEDEzi3d0KWy8LvC7xD54QCa/ulw5
 5TVYRT+hqr++OVSICei0RZotuXWyqY/3lACwFpUg4JpdylSYW2IAP2b2/3vtRfYnraQaztArC
 XhwibcCYmUeadLLfG1AhfKe1S12F3EEUnEZUfPaT0qo6Y=
Received-SPF: pass client-ip=212.227.17.12;
 envelope-from=michael_heerdegen@HIDDEN; helo=mout.web.de
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_MSPIKE_H3=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-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--=-=-=
Content-Type: text/plain


Hello,

Any Calc experts around?  emacs -Q:

  M-x calc RET
  0 RET
  a i x RET

is a way to integrate 0 using Calc (with integration variable x in this
case).  Calc fails to solve it:

The result Calc gives you is "integ(0, x)" - Calc leaves the integral
unresolved, which is Calc's way to say "I can't solve this".  This
is definitely not a feature or a way to represent an integration
constant - (info "(calc) Integration"):

| Also, any indefinite integral should be considered to have an
| arbitrary constant of integration added to it, although Calc does not
| write an explicit constant of integration in its result.

So what is going on?  Other functions, including constants like 1 or a
symbol work as expected.

As far as I understand, Calc is internally perfectly able to solve this
integral but at one place in the code the correct result is rejected
because this case is so special that the authors forgot to make the code
expect a result of such a simple form.  This small change helps:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-WIP-Try-to-fix-integration-of-0.patch
Content-Transfer-Encoding: quoted-printable

=46rom a4351149314af2dab8f03715a9effeb2ee26490c Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@HIDDEN>
Date: Fri, 23 Jun 2023 04:44:34 +0200
Subject: [PATCH] WIP: Try to fix integration of 0

=2D--
 lisp/calc/calcalg2.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lisp/calc/calcalg2.el b/lisp/calc/calcalg2.el
index 5e9ae8a3e5a..fafbd8418ef 100644
=2D-- a/lisp/calc/calcalg2.el
+++ b/lisp/calc/calcalg2.el
@@ -774,12 +774,13 @@ math-integral
     (setq val math-cur-record)
     (while (vectorp (nth 1 val))
       (setq val (aref (nth 1 val) 0)))
-    (setq val (if (memq (nth 1 val) '(parts parts2))
-		  (progn
-		    (setcar (cdr val) 'parts2)
-		    (list 'var 'PARTS val))
-		(and (consp (nth 1 val))
-		     (nth 1 val))))
+    (let ((val-1 (nth 1 val)))
+      (setq val (if (memq val-1 '(parts parts2))
+		    (progn
+		      (setcar (cdr val) 'parts2)
+		      (list 'var 'PARTS val))
+		  (and (or (consp val-1) (equal val '(0 0)))
+		       val-1))))
     (math-tracing-integral "Integral of "
 			   (math-format-value expr 1000)
 			   "  is  "
=2D-
2.39.2


--=-=-=
Content-Type: text/plain


The problem is: I found this fix by trial and error, someone who knows
the code should verify that the fix is correct.  For example, I don't
know whether 0 is always represented as list (0 0) at this point (given
how many different settings there are...) and whether it is the correct
code place to handle this case.


TIA,

Michael.


In GNU Emacs 31.0.50 (build 15, x86_64-pc-linux-gnu, cairo version
 1.16.0) of 2024-07-02 built on drachen
Repository revision: 7b256c6118326a76e81cc004576c78ba5a475ffd
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-x-toolkit=no --with-native-compilation=no'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LCMS2
LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY OLDXMENU PDUMPER
PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF WEBP X11 XDBE XIM XINPUT2
XPM ZLIB

Important settings:
  value of $LC_ALL: de_DE.utf8
  value of $LC_COLLATE: C
  value of $LC_TIME: C
  value of $LANG: de_DE.utf8
  locale-coding-system: utf-8-unix


--=-=-=--




Acknowledgement sent to Michael Heerdegen <michael_heerdegen@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#71890; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Tue, 4 Mar 2025 01:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.