Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#7504 closed defect (fixed)

Magma booleans don't evaluate correctly in boolean contexts

Reported by: kedlaya Owned by: was
Priority: major Milestone: sage-4.3
Component: interfaces Keywords: magma, boolean context
Cc: Merged in: sage-4.3.alpha1
Authors: William Stein Reviewers: Kiran Kedlaya
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Compare the following results:

sage: bool(pari(False))
False
sage: bool(gap(False))
False
sage: bool(maxima(False))
False
sage: bool(maple(False))
False
sage: bool(mathematica(False))
False
sage: bool(magma(False))
True

This is in some sense the inverse problem to #845.

Attachments (1)

trac_7504.patch (1.4 KB) - added by was 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 13 years ago by GeorgSWeber

In "gap.py", in the "class GapElement?(ExpectElement?)", there is (lines 1058 ff):

    def bool(self):
        """
        EXAMPLES::
        
            sage: bool(gap(2))
            True
            sage: gap(0).bool()
            False
            sage: gap('false').bool()
            False
        """
        P = self._check_valid()
        return self != P(0) and repr(self) != 'false'

I didn't check maxima.py, ... but in magma.py, I couldn't find a counterpart in the class MagmaElement?. My first attempt to add this with the obvious minor modifications failed however (so I do not post the patch):

sage: magma(True).bool()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

/Users/georgweber/.sage/temp/susanne_webers_computer.local/15820/_Users_georgweber__sage_init_sage_0.py in <module>()

/Users/Shared/sage/sage-4.2.1/local/lib/python2.6/site-packages/sage/interfaces/magma.pyc in bool(self)
   2111         """
   2112         P = self._check_valid()
-> 2113         return self != P(0) and repr(self) != 'false'
   2114 
   2115     def __len__(self):

/Users/Shared/sage/sage-4.2.1/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.__richcmp__ (sage/structure/element.c:6484)()

/Users/Shared/sage/sage-4.2.1/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element._richcmp (sage/structure/element.c:6363)()

/Users/Shared/sage/sage-4.2.1/local/lib/python2.6/site-packages/sage/interfaces/expect.pyc in __cmp__(self, other)
   1521         P = self.parent()
   1522         if P.eval("%s %s %s"%(self.name(), P._equality_symbol(),
-> 1523                                  other.name())) == P._true_symbol():
   1524             return 0
   1525         elif P.eval("%s %s %s"%(self.name(), P._lessthan_symbol(), other.name())) == P._true_symbol():

/Users/Shared/sage/sage-4.2.1/local/lib/python2.6/site-packages/sage/interfaces/magma.pyc in eval(self, x, strip, **kwds)
    478         ans = Expect.eval(self, x, **kwds).replace('\\\n','')
    479         if 'Runtime error' in ans or 'User error' in ans:
--> 480             raise RuntimeError, "Error evaluating Magma code.\nIN:%s\nOUT:%s"%(x, ans)
    481         return ans
    482 

RuntimeError: Error evaluating Magma code.
IN:_sage_[3] eq _sage_[6];
OUT:
>> _sage_[3] eq _sage_[6];
             ^
Runtime error in 'eq': Bad argument types
Argument types given: BoolElt, RngIntElt

comment:2 Changed 13 years ago by GeorgSWeber

Ouch, I give up after experimenting further and getting (one and the same session!):

sage: magma(False).bool()
False
sage: bool(magma(False))
True

comment:3 Changed 13 years ago by mhansen

bool(f) calls f.__nonzero__()

comment:4 Changed 12 years ago by was

  • Report Upstream set to N/A
  • Status changed from new to needs_review

In Magma we have:

> false ne 0;

>> false ne 0;
         ^
Runtime error in 'ne': Bad argument types
Argument types given: BoolElt, RngIntElt

> 1 ne 0;    
true

I.e., comparing false to 0 is not allowed in Magma. So we need to add code to nonzero that also tests bools.

Changed 12 years ago by was

comment:5 Changed 12 years ago by kedlaya

  • Status changed from needs_review to positive_review

This applied against 4.2, fixed the issue for me, and doesn't appear to have caused any failures of optional doctests.

comment:6 Changed 12 years ago by mhansen

  • Authors set to William Stein
  • Merged in set to sage-4.3.alpha1
  • Resolution set to fixed
  • Reviewers set to Kiran Kedlaya
  • Status changed from positive_review to closed

comment:7 Changed 12 years ago by mvngu

  • Milestone set to sage-4.3
Note: See TracTickets for help on using tickets.