|
From: Barton W. <wil...@us...> - 2025-11-27 12:41:25
|
--- **[bugs:#4636] signum(ind) is an error** **Status:** open **Group:** None **Labels:** extended real signum limit **Created:** Thu Nov 27, 2025 12:41 PM UTC by Barton Willis **Last Updated:** Thu Nov 27, 2025 12:41 PM UTC **Owner:** nobody Either a `signum` nounform or `ind` is a better result than an error: ~~~ (%i4) signum(ind); sign: sign of ind is undefined. ~~~ Should the general simplifier, or the one‑argument limit function, handle` F(extended-real)`? We’ve discussed this—do we have a consensus? --- Sent from sourceforge.net because max...@li... is subscribed to https://sourceforge.net/p/maxima/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |
|
From: Barton W. <wil...@us...> - 2025-11-28 13:01:45
|
I simple fix is to errcatch sign. I addition to a few minor edits, I used the fact that `complex-number-p` returns multiple values to make the complex number case a bit more efficient.
Let me know what you all think of this revision.
~~~
;; This is missing signum(x^n) = signsum(x)^n, where n is an integer--possibly should be restricted to a positive integer.
(def-simplifier signum (x)
(cond
;; Case: zero--this makes signum(0.0) -> 0.0 and signum(0.0b0) -> 0.0b0
((zerop1 x) x)
(t
(multiple-value-bind (is-complex-number re im)
(complex-number-p x #'mnump)
(cond
;; Case: complex number
(is-complex-number
($expand (div x (ftake 'mexpt (add (mul re re) (mul im im)) 1//2)) 1 0))
;; Idempotent: signum(signum(z)) = signum(z)
((and (consp x) (eq '%signum (caar x))) x)
(t
;; We use the errcatch to avoid signum(ind) throwing an error
(let ((sgn (car (errcatch ($csign x)))))
(cond
;; signum(negative) -> -1
((eq sgn '$neg) -1)
;; signum(zero) -> 0
((eq sgn '$zero) 0)
;; signum(positive) -> 1
((eq sgn '$pos) 1)
;; Multiplicative: signum(ab) = signum(a) * signum(b)
((mtimesp x)
(fapply 'mtimes (mapcar #'(lambda (s) (ftake '%signum s)) (cdr x))))
;; Reflection rule: signum(-x) -> -signum(x)
((great (neg x) x)
(neg (ftake '%signum (neg x))))
;; Give up
(t (give-up))))))))))
~~~
---
**[bugs:#4636] signum(ind) is an error**
**Status:** open
**Group:** None
**Labels:** extended real signum limit
**Created:** Thu Nov 27, 2025 12:41 PM UTC by Barton Willis
**Last Updated:** Thu Nov 27, 2025 12:41 PM UTC
**Owner:** nobody
Either a `signum` nounform or `ind` is a better result than an error:
~~~
(%i4) signum(ind);
sign: sign of ind is undefined.
~~~
Should the general simplifier, or the one‑argument limit function, handle` F(extended-real)`? We’ve discussed this—do we have a consensus?
---
Sent from sourceforge.net because max...@li... is subscribed to https://sourceforge.net/p/maxima/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |
|
From: Stavros M. <mac...@us...> - 2025-11-28 13:14:30
|
Not sure when this code got in here: ($expand (div x (ftake 'mexpt (add (mul re re) (mul im im)) 1//2)) 1 0)) but that seems like a silly way to handle the real case (and makes the rest of the code unnecessary for real numerical inputs). Presumably this should not be used when im=0. --- **[bugs:#4636] signum(ind) is an error** **Status:** open **Group:** None **Labels:** extended real signum limit **Created:** Thu Nov 27, 2025 12:41 PM UTC by Barton Willis **Last Updated:** Fri Nov 28, 2025 01:01 PM UTC **Owner:** nobody Either a `signum` nounform or `ind` is a better result than an error: ~~~ (%i4) signum(ind); sign: sign of ind is undefined. ~~~ Should the general simplifier, or the one‑argument limit function, handle` F(extended-real)`? We’ve discussed this—do we have a consensus? --- Sent from sourceforge.net because max...@li... is subscribed to https://sourceforge.net/p/maxima/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |
|
From: Barton W. <wil...@us...> - 2025-11-28 13:21:46
|
I inserted the code `($expand (div x ... ) 1 0)`. I didn't like it too much, but it I did it to avoid a check if the imaginary part was zero and make sure that the complex number case returns a number in rectangular form. I'll revise this bit of code. --- **[bugs:#4636] signum(ind) is an error** **Status:** open **Group:** None **Labels:** extended real signum limit **Created:** Thu Nov 27, 2025 12:41 PM UTC by Barton Willis **Last Updated:** Fri Nov 28, 2025 01:14 PM UTC **Owner:** nobody Either a `signum` nounform or `ind` is a better result than an error: ~~~ (%i4) signum(ind); sign: sign of ind is undefined. ~~~ Should the general simplifier, or the one‑argument limit function, handle` F(extended-real)`? We’ve discussed this—do we have a consensus? --- Sent from sourceforge.net because max...@li... is subscribed to https://sourceforge.net/p/maxima/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |
|
From: Barton W. <wil...@us...> - 2025-11-28 13:42:19
|
One more reason: I wanted to make `signum(2.0b0) = 1.0b0, signum(2/3) = 1, ...`. the silly code was an easy way to achieve that --- **[bugs:#4636] signum(ind) is an error** **Status:** open **Group:** None **Labels:** extended real signum limit **Created:** Thu Nov 27, 2025 12:41 PM UTC by Barton Willis **Last Updated:** Fri Nov 28, 2025 01:21 PM UTC **Owner:** nobody Either a `signum` nounform or `ind` is a better result than an error: ~~~ (%i4) signum(ind); sign: sign of ind is undefined. ~~~ Should the general simplifier, or the one‑argument limit function, handle` F(extended-real)`? We’ve discussed this—do we have a consensus? --- Sent from sourceforge.net because max...@li... is subscribed to https://sourceforge.net/p/maxima/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |