Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
48f6528
feat: implement frac
markusdemedeiros Jun 22, 2025
9c714b3
Improved Frac
Shreyas4991 Jun 23, 2025
2111a2d
Salvage proofs. Optimisations later
Shreyas4991 Jun 23, 2025
7d13a47
Beginning of improving fractional class
Shreyas4991 Jun 23, 2025
2f0a1c0
fix le_antisymm
Shreyas4991 Jun 23, 2025
6a3a244
add to zero zero
Shreyas4991 Jun 23, 2025
4c54f7e
mark entries for removal
Shreyas4991 Jun 23, 2025
b56fb0b
More missing API lemma reveal themselves
Shreyas4991 Jun 23, 2025
bb27ec7
lt_order_compat
Shreyas4991 Jun 23, 2025
7e144e8
More API lemmas
Shreyas4991 Jun 23, 2025
c4fe041
Ordered Commutative Monoids are more useful for numbers. Fracs should…
Shreyas4991 Jun 24, 2025
4e95b0c
Merge branch 'master' into numbers
Shreyas4991 Jun 30, 2025
35941c2
Begin numbers CMRA
Shreyas4991 Jun 30, 2025
3c36394
remove positivity
Shreyas4991 Jun 30, 2025
24e39e1
Fix copyright header
Shreyas4991 Jul 1, 2025
0e100d2
Fixed API lemmas. allows negative numbers now. Next, fix the CMRA ins…
Shreyas4991 Jul 2, 2025
c6b63fa
Some errors taken out
Shreyas4991 Jul 8, 2025
9469141
Something is wrong with the CMRA definition
Shreyas4991 Jul 8, 2025
e788045
Merge branch 'master' of github.com:leanprover-community/iris-lean in…
Shreyas4991 Jul 8, 2025
81b07e0
Got rid of some errors
Shreyas4991 Jul 18, 2025
d467b87
First insert sorries. Then check what went wrong in validN
Shreyas4991 Jul 18, 2025
a5f719e
Update numbers
Shreyas4991 Aug 13, 2025
3079847
Merge branch 'master' into numbers
markusdemedeiros Jan 23, 2026
a22fc25
update
markusdemedeiros Jan 23, 2026
8f25991
some style fixes
markusdemedeiros Jan 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Iris/Algebra/LocalUpdates.lean
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ theorem cancel_local_update_unit (x y : α) [CMRA.Cancelable x] : (x • y, x) ~
have e : (x • y, x • CMRA.unit) ≡ (x • y, x) := ⟨.rfl, CMRA.unit_right_id⟩
.equiv_left _ e (.cancel x y CMRA.unit)

/-- Necessary and sufficient condition for a local update on a unital discrete leibniz CMRA
with trivial validity predicate -/
theorem leibniz_discrete_unital_triv_local_update [OFE.Leibniz α] [CMRA.Discrete α]
(Hv : ∀ x : α, ✓ x)
(H : ∀ {z : α}, x = y • z → x' = y' • z) :
(x,y) ~l~> (x', y') := by
refine (local_update_unital_discrete x y x' y').mpr fun _ _ He => ?_
refine ⟨Hv _, .of_eq <| H <| OFE.leibniz.mp He⟩

end UCMRA

theorem LocalUpdate.unit {x y x' y' : Unit} : (x, y) ~l~> (x', y') := .id ((), ())
Expand Down
181 changes: 181 additions & 0 deletions src/Iris/Algebra/Numbers.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/-
Copyright (c) 2025 Shreyas Srinivas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shreyas Srinivas, Markus de Medeiros
-/

import Iris.Algebra.CMRA
import Iris.Algebra.OFE
import Iris.Algebra.LocalUpdates

/-! ## Numbers CMRA
Simple CMRA's for commutative monoids.

There are three variants:
- "Constant core": the core is a fixed value such as 0 (eg. (ℕ, +))
- "Universal core": every element is a core (eg. (ℕ, max))
- "No core": there is no core (eg. (PNat, +))
-/

open Std

class IdentityFree (α : Type _) [Add α] where
id_free {a b : α} : ¬ Add.add a b = a

class LeftCancelAdd (α : Type _) [Add α] where
cancel_left {x₁ x₂ y : α} : y + x₁ = y + x₂ → x₁ = x₂

open Add Commutative in
theorem LeftCancelAdd.cancel_right {x₁ x₂ y : α} [Add α] [LeftCancelAdd α]
[Commutative (add (α := α))] (h : add x₁ y = add x₂ y) : x₁ = x₂ := by
refine cancel_left (y := y) ?_
rw [← add_eq_hAdd, comm (op := Add.add) y x₁, h, comm (op := Add.add)]

/- Constant core -/
namespace CommMonoidLike

open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA

variable [OFE α] [Discrete α] [Leibniz α]
variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))]
variable [Zero α] [LawfulLeftIdentity (add (α := α)) zero]
variable {x y x' y' : α}

scoped instance : CMRA α where
pcore _ := some zero
op := add
ValidN _ _ := True
Valid _ := True
op_ne.ne _ _ _ h := by rw [eq_of_eqv (discrete h)]
pcore_ne _ := dist_some ∘ Dist.of_eq
validN_ne _ _ := .intro
valid_iff_validN := .symm <| forall_const Nat
validN_succ := (·)
validN_op_left := id
assoc {_ _ _} := by rw [assoc (op := add)]
comm {_ _} := by rw [comm (op := add)]
pcore_op_left {_ _} := by rintro ⟨rfl⟩; rw [left_id (op := add) _]
pcore_idem := by simp
pcore_op_mono {_ _} := by
rintro ⟨rfl⟩ _
exists zero
rw [left_id (op := add) _]
extend _ h := ⟨_, _, discrete h, .rfl, .rfl⟩

scoped instance : CMRA.Discrete α where
discrete_valid := id

scoped instance : UCMRA α where
unit := zero
unit_valid := trivial
unit_left_id := pcore_op_left rfl
pcore_unit := .symm .rfl

scoped instance [LeftCancelAdd α] {a : α} : Cancelable a where
cancelableN {_ _ _} _ := .of_eq ∘ LeftCancelAdd.cancel_left ∘ eq_of_eqv ∘ discrete

/-- Sufficient condition for a local update on a LeftCancelAdd structure, such as (ℕ, +) -/
theorem leftCancelAdd_local_update [LeftCancelAdd α] (h : add x y' = add x' y) :
(x, y) ~l~> (x', y') := by
refine leibniz_discrete_unital_triv_local_update (fun _ => trivial) @fun z hz => ?_
refine LeftCancelAdd.cancel_right (y := y) ?_
calc
add x' y = add x y' := h.symm
_ = add (add y z) y' := by rw [hz]; rfl
_ = add y' (add y z) := by rw [comm (op := add)]
_ = add y' (add z y) := by rw [comm (op := add) z]
_ = add (add y' z) y := by rw [assoc (op := add)]

end CommMonoidLike

/- Universal core -/
namespace OrdCommMonoidLike

open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp

variable [OFE α] [OFE.Discrete α] [Leibniz α]
variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))]
variable [IdempotentOp (add (α := α))]
variable [Zero α]
variable {x y x' y' : α}

scoped instance : CMRA α where
pcore := some
op := add
ValidN _ _ := True
Valid _ := True
op_ne.ne _ _ _ h := by rw [eq_of_eqv (discrete h)]
pcore_ne {_ y _ _} h := by
rintro ⟨rfl⟩
exact ⟨y, congrArg _ <| leibniz.mp (discrete h.symm), .rfl⟩
validN_ne _ _ := .intro
valid_iff_validN := .symm <| forall_const Nat
validN_succ := (·)
validN_op_left := id
assoc {_ _ _} := by rw [assoc (op := add)]
comm {_ _} := by rw [comm (op := add)]
pcore_op_left {_ _} := by
rintro ⟨rfl⟩
refine .of_eq <| idempotent _
pcore_idem := by simp
pcore_op_mono {a b} := by
rintro ⟨rfl⟩ z
exists z
extend _ h := ⟨_, _, discrete h, .rfl, .rfl⟩

scoped instance : CMRA.Discrete α where
discrete_valid := id

scoped instance (a : α) : CMRA.CoreId a where
core_id := by simp [pcore]

scoped instance [LawfulLeftIdentity (add (α := α)) zero] : UCMRA α where
unit := zero
unit_valid := trivial
unit_left_id := .of_eq <| left_id _
pcore_unit := .symm .rfl

scoped instance [LeftCancelAdd α] {a : α} : Cancelable a where
cancelableN {_ _ _} _ := .of_eq ∘ LeftCancelAdd.cancel_left ∘ eq_of_eqv ∘ discrete

end OrdCommMonoidLike

/- NoCore core -/
namespace PosCommMonoidLike

open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp

variable [OFE α] [OFE.Discrete α] [Leibniz α]
variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))]
variable [IdempotentOp (add (α := α))]

variable {x y x' y' : α}

scoped instance : CMRA α where
pcore _ := none
op := add
ValidN _ _ := True
Valid _ := True
op_ne.ne _ _ _ h := by rw [eq_of_eqv (discrete h)]
pcore_ne _ := by rintro ⟨rfl⟩
validN_ne _ _ := .intro
valid_iff_validN := .symm <| forall_const Nat
validN_succ := (·)
validN_op_left := id
assoc {_ _ _} := by rw [assoc (op := add)]
comm {_ _} := by rw [comm (op := add)]
pcore_op_left {_ _} := by rintro ⟨rfl⟩
pcore_idem := by simp
pcore_op_mono {_ _} := by rintro ⟨rfl⟩
extend _ h := ⟨_, _, discrete h, .rfl, .rfl⟩

scoped instance : CMRA.Discrete α where
discrete_valid := id

scoped instance [LeftCancelAdd α] {a : α} : Cancelable a where
cancelableN {_ _ _} _ := .of_eq ∘ LeftCancelAdd.cancel_left ∘ eq_of_eqv ∘ discrete

scoped instance [IdentityFree α] {a : α} : CMRA.IdFree a where
id_free0_r _ _ h := IdentityFree.id_free (α := α) <| leibniz.mp (discrete h)

end PosCommMonoidLike