Skip to content

feat: mono nat (algebra + bi)#409

Merged
Kaptch merged 51 commits into
leanprover-community:masterfrom
Kaptch:mono-nat
Jun 1, 2026
Merged

feat: mono nat (algebra + bi)#409
Kaptch merged 51 commits into
leanprover-community:masterfrom
Kaptch:mono-nat

Conversation

@Kaptch
Copy link
Copy Markdown
Collaborator

@Kaptch Kaptch commented May 25, 2026

Description

Fixes #269 and #282
I would like to try to push for heap lang proofs before the workshop, and its one of the dependencies.
It might require changes depending on whether #401 gets merged before or after.

Checklist

  • My code follows the mathlib naming and code style conventions
  • I have updated PORTING.md as appropriate
  • I have added my name to the authors section of any appropriate files

ayhon added 30 commits April 27, 2026 13:32
In the end, it seems like around `40` is quite a good precedence level.

If we look at `Notation.lean`, we see the precedence levels of various
notations.

```
@[inherit_doc] infixr:90 " ∘ "  => Function.comp
@[inherit_doc] infixr:35 " × "  => Prod
@[inherit_doc] infixr:35 " ×' " => PProd
@[inherit_doc]  infix:50 " ∣ " => Dvd.dvd
@[inherit_doc] infixl:55 " ||| " => HOr.hOr
@[inherit_doc] infixl:58 " ^^^ " => HXor.hXor
@[inherit_doc] infixl:60 " &&& " => HAnd.hAnd
@[inherit_doc] infixl:65 " + "   => HAdd.hAdd
@[inherit_doc] infixl:65 " - "   => HSub.hSub
@[inherit_doc] infixl:70 " * "   => HMul.hMul
@[inherit_doc] infixl:70 " / "   => HDiv.hDiv
@[inherit_doc] infixl:70 " % "   => HMod.hMod
@[inherit_doc] infixl:75 " <<< " => HShiftLeft.hShiftLeft
@[inherit_doc] infixl:75 " >>> " => HShiftRight.hShiftRight
@[inherit_doc] infixr:80 " ^ "   => HPow.hPow
@[inherit_doc] infixl:65 " ++ "  => HAppend.hAppend
@[inherit_doc] prefix:75 "-"     => Neg.neg
@[inherit_doc] prefix:100 "~~~"  => Complement.complement
@[inherit_doc] postfix:max "⁻¹"  => Inv.inv
@[inherit_doc] infixr:73 " • " => HSMul.hSMul
```

If we take further into account that the precedence of the
arrow `→` is `25`, then my earlier choice of `40` makes it
weaker than all other usual operators, but still stronger than
implication, which is roughly where I wanted to place it.
One actually cannot make the definition of `NSteps` use `Iterate`
because `Step` is a tagged relation, and `Iterate` does not
support merging the observations between `Step`s.
Actually, we can see `List Obs` to be the free monoid of `Obs`, so
we don't actually gain any expressivity by changing the definition.
Maybe it would make for a nicer API, but it doesn't warrant making
the change at this stage.
@Kaptch Kaptch marked this pull request as ready for review May 25, 2026 09:35
@alvinylt
Copy link
Copy Markdown
Contributor

Assuming there are no further changes to the IsOp implementation, the two instances should be fairly straightforward once #401 is merged:

set_option synthInstance.checkSynthOrder false in
@[rocq_alias mono_nat_auth_dfrac_is_op]
instance {dq dq1 dq2 : DFrac F} {n : MaxNat}
    [h : IsOp io1 dq io2 dq1 io3 dq2] :
    IsOp io1 (●MN{dq} n) io2 (●MN{dq1} n) io3 (●MN{dq2} n) where
  is_op := by rw [h.is_op]; apply auth_dfrac_op

@[rocq_alias mono_nat_lb_max_is_op]
instance {n n1 n2 : MaxNat}
    [h : IsOp io1 n io2 n1 io3 n2] :
    IsOp io1 (◯MN n : MonoNat F) io2 (◯MN n1) io3 (◯MN n2) where
  is_op := by rw [h.is_op]; .rfl

@lzy0505 lzy0505 self-requested a review May 29, 2026 08:03
Copy link
Copy Markdown
Collaborator

@lzy0505 lzy0505 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Kaptch Kaptch merged commit aa47755 into leanprover-community:master Jun 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port algebra/lib/mono_nat.v

5 participants