Skip to content

Binomial of integer (mod n) returns integer #12179

@sagetrac-scotts

Description

@sagetrac-scotts
sage: R = Integers(6)
sage: binomial(R(5), R(2))
10
sage: binomial(R(5), R(2)).parent()
Integer Ring

But binomial(R(5), R(2)) is nonsense, both as an element of ZZ and as an element of R:

sage: binomial(5, 2)
10
sage: binomial(11, 2)
55
sage: binomial(5, 8)
0

On input binomial(x, y), what Sage should do instead is the following:

  • If the parent of y is Zmod(n) rather than ZZ, a TypeError should be raised.

  • (This seems to be fixed by Cleanup in rings.arith and rings.integer #17852) If factorial(y) is zero or a zero-divisor in the parent of x, a ZeroDivisionError should be raised. This is automatic if one computes binomial(x, y) simply as

    x.parent()(prod([x-k for k in range(y)]) / factorial(y))
    

Apply:

Component: basic arithmetic

Keywords: binomial coefficient modulo sd35

Stopgaps: todo

Author: Sam Scott, Marco Streng

Reviewer: Colton Pauderis, Johan Bosman, Marco Streng

Issue created by migration from https://trac.sagemath.org/ticket/12179

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions