GNU bug report logs - #35374
Calc; Div by 0 in solving system

Previous Next

Package: emacs;

Reported by: Christopher Howard <christopher.howard <at> qlfiles.net>

Date: Mon, 22 Apr 2019 05:38:01 UTC

Severity: normal

Tags: confirmed, fixed, patch

Fixed in version 26.4

Done: Mattias Engdegård <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35374 in the body.
You can then email your comments to 35374 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35374; Package emacs. (Mon, 22 Apr 2019 05:38:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Howard <christopher.howard <at> qlfiles.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 22 Apr 2019 05:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Howard <christopher.howard <at> qlfiles.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Calc; Div by 0 in solving system
Date: Sun, 21 Apr 2019 21:20:00 -0800
[Message part 1 (text/plain, inline)]
Place this on stack with algebriac mode:

[2 * x - 3 * y + z = 5, x + y - 2 * z = 0, -x + 2 * y + 3 * z = -3]

run command 'a S x,y,z'

Receive error 'Division by zero: 1'

I enabled Debug on Error but could not find the backtrace

Emacs  : GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-09-14, modified by Debian
Package: Calc

-- 
Christopher Howard
p: +1 (907) 374-0257
w: https://librehacker.com
xmpp: creationist <at> member.fsf.org
otr: E9685B53 01F038DD D29281C9 30FDA71E BD0095D4
gnupg: 23FD5CC5 (keys.gnupg.net)
radio: KL1TL
featured: https://emailselfdefense.fsf.org/en/ id="-x-evo-selection-
start-marker">
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35374; Package emacs. (Tue, 23 Apr 2019 14:36:01 GMT) Full text and rfc822 format available.

Message #8 received at 35374 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Christopher Howard <christopher.howard <at> qlfiles.net>
Cc: 35374 <at> debbugs.gnu.org
Subject: Re: Calc; Div by 0 in solving system
Date: Tue, 23 Apr 2019 16:34:58 +0200
21 apr. 2019 kl. 17.37 skrev Christopher Howard <christopher.howard <at> qlfiles.net>:

> I enabled Debug on Error but could not find the backtrace

Reproduced in 26.1. Backtrace below.

I quickly got lost in calcalg2.el, but it looks like the equation

  2(z - 1.0) - (5 + 3(z - 1.0) - z) / 2 + 3z + 3 = 0,

isn't solved properly by math-try-solve-for: math-decompose-poly returns the correct decomposition of the LHS, (4) * z, but then the code decides to find a root of the polynomial (4) which of course doesn't exist and nothing good comes out of it. I'm not sure why the floating-point numbers (float 1 0) are there in the first place.

Maybe someone more knowledgeable about Calc can help further.

* math-reject-arg((float 1 0) "*Division by zero")
 math-div-by-zero((float 1 0) 0)
 math-div((float 1 0) 0)
 math-float((frac 1 0))
 math-mul((frac 1 0) (float 138629436111989 -14))
 math-mul-objects-fancy((frac 1 0) (cplx (float 138629436111989 -14) (float 314159265358979 -14)))
 math-mul((frac 1 0) (cplx (float 138629436111989 -14) (float 314159265358979 -14)))
 math-pow-fancy(-4 (frac 1 0))
 math-pow(-4 (frac 1 0))
 math-poly-laguerre-root((4) 0 t)
 math-poly-any-root((4) 0 t)
 math-try-solve-for((+ (+ (- (* 2 (- (var z var-z) (float 1 0))) (/ (- (+ 5 (* 3 (- (var z var-z) (float 1 0)))) (var z var-z)) 2)) (* 3 (var z var-z))) 3) 0 nil nil)
 math-try-solve-for((calcFunc-eq (+ (- (* 2 (- (var z var-z) (float 1 0))) (/ (- (+ 5 (* 3 (- (var z var-z) (float 1 0)))) (var z var-z)) 2)) (* 3 (var z var-z))) -3) 0 nil)
 math-solve-for((calcFunc-eq (+ (- (* 2 (- (var z var-z) (float 1 0))) (/ (- (+ 5 (* 3 (- (var z var-z) (float 1 0)))) (var z var-z)) 2)) (* 3 (var z var-z))) -3) 0 (var z var-z) nil)
 math-solve-system-rec((((calcFunc-eq (+ (- (* 2 (- (var z var-z) (float 1 0))) (/ (- (+ 5 (* 3 (- (var z var-z) (float 1 0)))) (var z var-z)) 2)) (* 3 (var z var-z))) -3))) ((var z var-z)) (((var y var-y) (- (var z var-z) (float 1 0))) ((var x var-x) (/ (- (+ 5 (* 3 (- (var z var-z) (float 1 0)))) (var z var-z)) 2))))
 math-solve-system-rec((((calcFunc-eq (- (+ (/ (- (+ 5 (* 3 (var y var-y))) (var z var-z)) 2) (var y var-y)) (* 2 (var z var-z))) 0)) ((calcFunc-eq (+ (- (* 2 (var y var-y)) (/ (- (+ 5 (* 3 (var y var-y))) (var z var-z)) 2)) (* 3 (var z var-z))) -3))) ((var y var-y) (var z var-z)) (((var x var-x) (/ (- (+ 5 (* 3 (var y var-y))) (var z var-z)) 2))))
 math-solve-system-rec((((calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5)) ((calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0)) ((calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3))) ((var x var-x) (var y var-y) (var z var-z)) nil)
 math-solve-system((vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z)) nil)
 calcFunc-solve((vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z)))
 apply(calcFunc-solve ((vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 math-normalize((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 math-simplify((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 calc-normalize-fancy((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 calc-normalize((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 math-evaluate-expr((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z))))
 mapcar(math-evaluate-expr ((calcFunc-solve (vec (calcFunc-eq (+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z)) 5) (calcFunc-eq (- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z))) 0) (calcFunc-eq (+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z))) -3)) (vec (var x var-x) (var y var-y) (var z var-z)))))
 #f(compiled-function () #<bytecode 0x4a71afd9>)()
 calc-do(#f(compiled-function () #<bytecode 0x4a71afd9>) 126)
 calc-evaluate(1)
 funcall-interactively(calc-evaluate 1)
 call-interactively(calc-evaluate nil nil)
 command-execute(calc-evaluate)





Added tag(s) confirmed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 06 May 2019 01:28:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35374; Package emacs. (Sun, 22 Sep 2019 17:35:02 GMT) Full text and rfc822 format available.

Message #13 received at 35374 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: 35374 <at> debbugs.gnu.org
Cc: Christopher Howard <christopher.howard <at> qlfiles.net>
Subject: Re: Calc; Div by 0 in solving system
Date: Sun, 22 Sep 2019 19:34:45 +0200
[Message part 1 (text/plain, inline)]
tags 35374 patch
stop

> Maybe someone more knowledgeable about Calc can help further.

Much to our surprise, very few people volunteered their service. Now, despite being grossly under-qualified for the task, I did give it a go. After all, we can't have it fail on simple linear equation systems now can we.

Please try this patch.

[0001-Fix-linear-equation-system-solving-in-Calc-bug-35374.patch (application/octet-stream, attachment)]

Added tag(s) patch. Request was from Mattias Engdegård <mattiase <at> acm.org> to control <at> debbugs.gnu.org. (Sun, 22 Sep 2019 17:35:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35374; Package emacs. (Mon, 23 Sep 2019 10:12:02 GMT) Full text and rfc822 format available.

Message #18 received at 35374 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Christopher Howard <christopher.howard <at> qlfiles.net>
Cc: 35374 <at> debbugs.gnu.org
Subject: Re: Calc; Div by 0 in solving system
Date: Mon, 23 Sep 2019 12:11:01 +0200
tags 35374 fixed
close 35374 26.4
stop

23 sep. 2019 kl. 07.28 skrev Christopher Howard <christopher.howard <at> qlfiles.net>:
> 
> I am now using Emacs 26.2 (through Guix) but am able to reproduce the
> original error in 26.2. I patched just this function (math-try-solve-
> for) and reloaded it. The error went away, and the correct solution was generated.

Thanks for verifying! Pushed to emacs-26.





Added tag(s) fixed. Request was from Mattias Engdegård <mattiase <at> acm.org> to control <at> debbugs.gnu.org. (Mon, 23 Sep 2019 10:12:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.4, send any further explanations to 35374 <at> debbugs.gnu.org and Christopher Howard <christopher.howard <at> qlfiles.net> Request was from Mattias Engdegård <mattiase <at> acm.org> to control <at> debbugs.gnu.org. (Mon, 23 Sep 2019 10:12:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35374; Package emacs. (Mon, 23 Sep 2019 14:32:01 GMT) Full text and rfc822 format available.

Message #25 received at 35374 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Howard <christopher.howard <at> qlfiles.net>
To: Mattias Engdegård <mattiase <at> acm.org>, 
 35374 <at> debbugs.gnu.org
Subject: Re: Calc; Div by 0 in solving system
Date: Sun, 22 Sep 2019 21:28:32 -0800
I am now using Emacs 26.2 (through Guix) but am able to reproduce the
original error in 26.2. I patched just this function (math-try-solve-
for) and reloaded it. The error went away, and the correct solution was generated.

I did not try running the tests.

-- 
https://librehacker.com
Christopher Howard
p: +1 (907) 374-0257
social feed: https://gnusocial.club/librehacker
xmpp: creationist <at> member.fsf.org
otr: E9685B53 01F038DD D29281C9 30FDA71E BD0095D4
gnupg: 23FD5CC5 (keys.gnupg.net)
radio: KL1TL
featured: https://emailselfdefense.fsf.org/en/

On Sun, 2019-09-22 at 19:34 +0200, Mattias Engdegård wrote:
> tags 35374 patch
> stop
> 
> > Maybe someone more knowledgeable about Calc can help further.
> 
> Much to our surprise, very few people volunteered their service. Now,
> despite being grossly under-qualified for the task, I did give it a
> go. After all, we can't have it fail on simple linear equation
> systems now can we.
> 
> Please try this patch.
> 






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 22 Oct 2019 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 159 days ago.

Previous Next


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