sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.43k stars 478 forks source link

Infinity norm of real interval vectors #17728

Open fph opened 9 years ago

fph commented 9 years ago

As documented in http://www.sagemath.org/doc/reference/rings_numerical/sage/rings/real_mpfi.html#sage.rings.real_mpfi.RealIntervalFieldElement.max, max(I,J) does not do the correct thing for real intervals, and I.max(J) has to be used instead.

When computing the infinity norm of a vector of real intervals, the wrong version of max gets used, though:

sage: x = RIF(1,2)
sage: y = RIF(0,4)
sage: print "Wrong max: ", max(x,y).endpoints()
Wrong max:  (1.00000000000000, 2.00000000000000)
sage: print "Correct max: ", x.max(y).endpoints()
Correct max:  (1.00000000000000, 4.00000000000000)
sage: 
sage: v = vector([x,y])
sage: print "Computed infinity norm: ", v.norm(Infinity).endpoints()
Computed infinity norm:  (1.00000000000000, 2.00000000000000)

CC: @sagetrac-jakobkroeker

Component: linear algebra

Stopgaps: wrongAnswerMarker

Issue created by migration from https://trac.sagemath.org/ticket/17728

fph commented 9 years ago
comment:1

Random thought: would it be possible to alter the behaviour of max(x,y), to have it do the right thing or at least return error? It's a Python built-in, so I suspect the answer is "no, or we would have done it long ago".

ea1d0bf8-c27a-4548-8cb7-de0b1d02441a commented 7 years ago
comment:3

If the behaviour of max cannot be changed, can it be forbidden in sage (e.g. by preparsing or whatever) to use pythons max()?

ea1d0bf8-c27a-4548-8cb7-de0b1d02441a commented 7 years ago

Stopgaps: wrongAnswerMarker

terencode commented 8 months ago

I remember having this issue a long time ago. I had then made the following fix which seemed to work after some quick local tests :

diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx
index 3492dbf2eb..23e06326fd 100644
--- a/src/sage/modules/free_module_element.pyx
+++ b/src/sage/modules/free_module_element.pyx
@@ -1753,9 +1753,11 @@ cdef class FreeModuleElement(Vector):   # abstract base class
             sage: v.norm(int(2))                                                        # needs sage.symbolic
             sqrt(5)
         """
+        from sage.functions.min_max import max_symbolic
+
         abs_self = [abs(x) for x in self]
         if p == Infinity:
-            return max(abs_self)
+            return max_symbolic(abs_self)
         if p < 1:
             raise ValueError("%s is not greater than or equal to 1" % p)

Could this be a solution ?