COMPLEX on union types gets incorrectly broken up

Bug #1734959 reported by Stas Boukarev
54
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Medium
Unassigned

Bug Description

(specifier-type '(complex bignum))
=>
#<UNION-TYPE (OR (COMPLEX (INTEGER * -4611686018427387905)) (COMPLEX (INTEGER 4611686018427387904)))>
Wouldn't match a complex when realpart and imagpart are of different sign.

Reported by Eric Marsden on sbcl-devel@

Tags: types
Revision history for this message
Stas Boukarev (stassats) wrote :

(typep (complex 1 4) '(or (complex (integer 1 2)) (complex (integer 3 4))))
returns T incorrectly.

tags: added: types
Revision history for this message
Stas Boukarev (stassats) wrote :

Negation types suffer as well

(sb-kernel:specifier-type '(not (complex (double-float 1d0 2d0)))) =>
(OR (NOT (COMPLEX DOUBLE-FLOAT)) (COMPLEX (DOUBLE-FLOAT * (1.0d0))) (COMPLEX (DOUBLE-FLOAT (2.0d0))))

(typep #c(1.0d0 3.0d0) '(not (complex (double-float 1.0d0 2.0d0)))) => NIL

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote :

the COMPLEX type is a bit weird, though: (COMPLEX <x>) means the complex type whose elements match <x>, and all other types of the same representation -- it's a bit like an array type. I'm not claiming that the COMPLEX type algebra is bug-free, but I don't think any of these examples is strictly speaking wrong.

Revision history for this message
Stas Boukarev (stassats) wrote :

> (COMPLEX <x>) means the complex type whose elements match <x>, and all other types of the same representation

But (complex bignum) doesn't match all complexes with bignums.

And we don't treat non-union complex types as "all other types of the same representation".

Revision history for this message
Stas Boukarev (stassats) wrote :

And our upgraded-complex-part-type doesn't upgrade anything, so it can't be claimed that it has the same representation.

And
(typep (complex 1 4) '(or (complex (integer 1 2)) (complex (integer 3 4))))
doesn't actually have union part-types, yet the result is different from

(or (typep (complex 1 4)
           '(complex (integer 3 4)))
    (typep (complex 1 4)
           '(complex (integer 1 2))))

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote :

OK, if we don't upgrade in upgraded-complex-part-type then yes things are wrong. Probably half of the system thinks that we do upgrade, and half doesn't (and another half is just confused).

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote :

Our representation of complex types is not (and I think has never been) able to represent

  (COMPLEX BIGNUM)

the way our TYPEP (and UPGRADED-COMPLEX-PART-TYPE) interprets complex types. NUMERIC-TYPE has a :COMPLEXP boolean, but NUMERIC-TYPE can only represent a single continuous range; so though we can represent (OR (COMPLEX <range1>) (COMPLEX <range2>)) we can't represent (COMPLEX (OR <range1> <range2>)).

Revision history for this message
Paul F. Dietz (paul-f-dietz) wrote :

This bug shows up in my RTP tests, so it would be nice if it were fixed, just to eliminate that noise. It doesn't show up with really high frequency, so it's not pressing.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.