[PATCH] fix '^' in Interval

5 views
Skip to first unread message

Qian Yun

unread,
May 7, 2026, 5:26:06 AM (2 days ago) May 7
to fricas-devel
(1) -> x := interval(-2.0,-1.0)$Interval Float

(1) [- 2.0, - 1.0]
Type: Interval(Float)
(2) -> x^(2/1)

(2) [0.0, 4.0000000000_000000001]
Type: Interval(Float)
(3) -> x^2

(3) [0.9999999999_9999999999, 4.0000000000_000000001]
Type: Interval(Float)


Notice that for the fractional power (2/1), the answer is wrong.

- Qian

diff --git a/src/algebra/interval.spad b/src/algebra/interval.spad
index 180b1c7b..8bd84ec1 100644
--- a/src/algebra/interval.spad
+++ b/src/algebra/interval.spad
@@ -429,7 +429,7 @@
error "fractional power only defined for x > 0"
even?(numer(n)) =>
hi < 0 =>
- interval(0, lo^n)
+ interval(hi^n, lo^n)
interval(0, max(lo^n, hi^n))
interval(lo^n, hi^n)
interval(lo^n, hi^n)

Ralf Hemmecke

unread,
May 7, 2026, 7:07:50 AM (2 days ago) May 7
to fricas...@googlegroups.com
Well, it depends what "interval" wants to express.

[0.0, 4.0] is correct in the sense that all values that lie in x their
square lies in [0.0, 4.0]. Maybe it is not the closest interval that is
possible. Given that the implementation of interval(a,b) rounds up and
down accordingly, your patch should be safe.

Ralf
Reply all
Reply to author
Forward
0 new messages