Skip to content

make symbolic Range more canonical #21269

@smichr

Description

@smichr

Whereas a Range with numerical args is canonical, the Range containing symbols is not:

>>> [Range(3,j,2) for j in range(4,10)]
[Range(3, 5, 2), Range(3, 5, 2), Range(3, 7, 2), Range(3, 7, 2), Range(3, 9, 2), Range(3, 9, 2)]

vs

>>> [Range(i,i+j,5) for j in range(1,6)]
[Range(i, i + 1, 5), Range(i, i + 2, 5), Range(i, i + 3, 5), Range(i, i + 4, 5), Range(i, i + 5, 5)]

which could be

[Range(i, i + 1, 5), Range(i, i + 1, 5), Range(i, i + 1, 5), Range(i, i + 1, 5), Range(i, i + 1, 5)]

The incorrect results are based on the assumption that the instantiated Range is canonical:

>> r=Range(2, 2 + 3, 5)
>>> r.inf,r.reversed.sup
(2, 2)
>>> r = Range(k, k + 3, 5)
>>> r.inf,r.reversed.sup
(k, k - 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Wrong ResultThe output produced by SymPy is mathematically incorrect.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions