Skip to content

feat(Data/ZMod/Basic): unit characterization for ZMod (p ^ d)#38628

Open
tautschnig wants to merge 1 commit intoleanprover-community:masterfrom
tautschnig:zmod-pow-two-units
Open

feat(Data/ZMod/Basic): unit characterization for ZMod (p ^ d)#38628
tautschnig wants to merge 1 commit intoleanprover-community:masterfrom
tautschnig:zmod-pow-two-units

Conversation

@tautschnig
Copy link
Copy Markdown

Add two lemmas characterizing units in ZMod (p ^ d) for a prime p:

  • ZMod.isUnit_natCast_of_not_dvd_pow: a natural number not divisible by p is a unit in ZMod (p ^ d).
  • ZMod.prime_natCast_not_isUnit_pow: the prime p is not a unit in ZMod (p ^ d) when d ≥ 1.

These complement the existing isUnit_prime_iff_not_dvd (which characterizes when a prime is a unit in ZMod n) by characterizing when an arbitrary natural number is a unit in ZMod (p ^ d).

Motivation. Arithmetic verification over fixed-width bitvectors works in ZMod (2 ^ d). A Gröbner basis solver over this ring needs to know which constants are invertible: odd constants are units (enabling algebraic simplification), while even constants are not (requiring fallback to SAT). These lemmas formalize that characterization for any prime, not just 2.

Further work related to Gröbner basis will be published once #29203 (and, before that, #34873) have been merged.


Open in Gitpod

Add two lemmas characterizing units in `ZMod (p ^ d)` for a prime `p`:

* `ZMod.isUnit_natCast_of_not_dvd_pow`: a natural number not divisible
  by `p` is a unit in `ZMod (p ^ d)`.
* `ZMod.prime_natCast_not_isUnit_pow`: the prime `p` is not a unit in
  `ZMod (p ^ d)` when `d ≥ 1`.

These arise naturally in SAT-based bounded model checking, where
arithmetic verification over fixed-width bitvectors works in
`ZMod (2 ^ d)`. The unit structure determines which constants
can be inverted by a Gröbner basis solver: odd constants are
invertible (enabling algebraic simplification), while even
constants are not (requiring fallback to SAT).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 28, 2026 11:09
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Apr 28, 2026
@github-actions
Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions
Copy link
Copy Markdown

PR summary 04e84bf966

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ isUnit_natCast_of_not_dvd_pow
+ prime_natCast_not_isUnit_pow

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-data Data (lists, quotients, numbers, etc) label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant