Skip to content

simplify(floor(x) + ceiling(-x)) doesn't simplify to 0 #30300

Description

@RudraDudhat2509

ceiling(-x) == -floor(x) is an exact identity for real x (no case split, unlike floor(x) + floor(-x) which is -1 for non-integer x and 0 for integer x). So floor(x) + ceiling(-x) should always simplify to 0.

>>> from sympy import Symbol, floor, ceiling, simplify
>>> x = Symbol('x', real=True)
>>> simplify(floor(x) + ceiling(-x))
ceiling(-x) + floor(x)

Expected: 0.

sympy already has the identity internally, simplify just isn't using it:

>>> ceiling(-x).rewrite(floor)
-floor(x)

Checked numerically for both integer and non-integer, positive and negative x, all give 0:

>>> [floor(v) + ceiling(-v) for v in (2.5, 0.3, -2.7, 3.0, -5)]
[0, 0, 0, 0, 0]

Related but distinct issues (checked before filing, none cover this case): #27564 (frac/floor/ceiling inequality simplification gaps), #27888 (general refine gaps), #9118 (solving floor+ceiling equations, not simplifying them).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions