Ticket #2569: trac2569-preparse-xor.patch

File trac2569-preparse-xor.patch, 1.2 kB (added by cwitty, 5 months ago)
  • a/sage/misc/preparser.py

    old new  
    586586    'ZZ = QQ[Integer(2)**(Integer(1)/Integer(3))]; (x,) = ZZ._first_ngens(Integer(1))' 
    587587    sage: QQ[2^(1/3)] 
    588588    Number Field in a with defining polynomial x^3 - 2 
     589 
     590    sage: preparse("a^b") 
     591    'a**b' 
     592    sage: preparse("a^^b") 
     593    'a^b' 
     594    sage: 8^1 
     595    8 
     596    sage: 8^^1 
     597    9 
     598    sage: 9^^1 
     599    8 
    589600    """ 
    590601    try: 
    591602        # [1,2,..,n] notation 
     
    839850            continue 
    840851        #     
    841852        ####### END CALCULUS ######## 
     853 
     854        # Since we use ^ for exponentiation (see below), we  
     855        # rewrite ^^ to ^ so that XOR is still accessible 
     856        elif line[i:i+2] == "^^" and not in_quote(): 
     857            line = line[:i] + "^" + line[i+2:] 
     858            i += 1 
     859            continue 
    842860 
    843861        # exponents can be either ^ or ** 
    844862        elif line[i] == "^" and not in_quote():