Skip to content

Conversation

@Taneb
Copy link
Member

@Taneb Taneb commented Nov 23, 2025

Closes #2890 (eventually)

The proofs, while purely algebraic, are often very tedious, especially *-cong.

I've got basic arithmetic, ordering with addition, and divmod working!

record _≃_ (i j : ℤ) : Set where
constructor mk≃
field
eq : ℤ.minuend i ℕ.+ ℤ.subtrahend j ≡ ℤ.minuend j ℕ.+ ℤ.subtrahend i
Copy link
Contributor

@jamesmckinna jamesmckinna Nov 27, 2025

Choose a reason for hiding this comment

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

First observation from Properties: use of sym to flip rewrites in the RHS of such equations... so suggest instead

Suggested change
eq : ℤ.minuend i ℕ.+ ℤ.subtrahend j ≡ ℤ.minuend j ℕ.+ ℤ.subtrahend i
eq : ℤ.minuend i ℕ.+ ℤ.subtrahend j ≡ ℤ.subtrahend i ℕ.+ ℤ.minuend j

?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason I did it this way was so that reflexivity is exactly refl. But you're right, that doesn't seem to be worth the tradeoff

Comment on lines +52 to +54
1ℤ : ℤ
1ℤ = 1 ⊖ 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Also:

Suggested change
1ℤ :
1ℤ = 1 ⊖ 0
1ℤ :
1ℤ = 1 ⊖ 0
-1ℤ :
-1ℤ = 0 ⊖ 1

Copy link
Member Author

Choose a reason for hiding this comment

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

Easy enough, but does it pass the Fairbairn threshold? -1ℤ = - 1ℤ, after all

Comment on lines +67 to +73
infix 8 ⁻_ ⁺_

⁺_ : ℕ → ℤ
⁺ n = n ⊖ 0

⁻_ : ℕ → ℤ
⁻ n = 0 ⊖ n
Copy link
Contributor

Choose a reason for hiding this comment

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

The symbol is in particular quite hard to discern as distinct form -. Would it be better to use Sign here (and reimplement the corresponding signAbs/SignAbs plumbing)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mostly got annoyed at Agda not being able to tell if a section (x +_) was _+_ x or x (+_), so I wanted different symbols for them... the superscript-minus symbol is used in APL's number syntax for a negative, and that's what inspired the use of these here. I'm not attached to them, though.

a ℕ.% n ℕ.+ 0 ≡⟨ ℕ.+-identityʳ (a ℕ.% n) ⟩
a ℕ.% n ≡⟨ ℕ.m∸n+n≡m p ⟨
a ℕ.% n ℕ.∸ b ℕ.% n ℕ.+ b ℕ.% n ∎
... | no b%n≰a%n = ≃-trans property′ $ mk≃ $ begin
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. Tempting to use a (Semi)Ring solver here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do those work well when I'm using monus? Not that I ever really can manage to get them to work well for me...

open import Data.Product.Base
open import Function.Base
open import Relation.Binary.PropositionalEquality

Copy link
Contributor

Choose a reason for hiding this comment

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

is it easier to derive each of these properties from the 'adjoint equivalence'/'graph relation' forms:

fromINT i ≡ j  i ≃ toINT j
i ≃ toINT j  fromINT i ≡ j

(plus, perhaps, some additional lemmas to 'explain' these two graph relations)?
(I think even the congs follow from this, but I'd need to check that...)

Copy link
Member Author

Choose a reason for hiding this comment

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

The second one is easy enough, it's hidden in my surjective proof. I'll have a go at the first one later.

As weak evidence that the congs don't follow from this: they're separate fields in the IsInverse structure in Function.Structures

Copy link
Contributor

@jamesmckinna jamesmckinna left a comment

Choose a reason for hiding this comment

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

No proper review as yet, but some suggestions for consideration.
Also I need to look again at Landau.

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.

[ add ] INT view of Data.Integer.Base.ℤ

2 participants