Skip to content

Improve support for nested floor division #27400

Open
@zq1997

Description

It appears that sympy currently does not adequately simplify floor integer division (i.e., Python's operator //).

Given var = sympy.Symbol('var', integer=True),
sympy.simplify(var // 2 // 3) results in floor(floor(var/2)/3) instead of floor(var/6).

Mathematically we can easily prove the following equation, so can we use it to simplify the above nested floor division?

$$ \lfloor\frac{\lfloor\frac{a}{b}\rfloor}{c}\rfloor = \lfloor\frac{a}{bc}\rfloor \quad(\forall a\in\mathbb{R},\ b \in \mathbb{Z},\ c\in\mathbb{Z}^+ \quad \text{and} \quad b \neq 0) $$

Update: There is a more general equation

$$ \lfloor\frac{\lfloor{m}\rfloor}{n}\rfloor = \lfloor\frac{m}{n}\rfloor \quad(\forall m\in\mathbb{R},\ n\in\mathbb{Z}^+) $$

Update: The ceil function has similar property.

$$ \lceil\frac{\lceil{m}\rceil}{n}\rceil = \lceil\frac{m}{n}\rceil \quad(\forall m\in\mathbb{R},\ n\in\mathbb{Z}^+) $$

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