[Add] Division properties for Nat, Integer, and Rational#2962
Draft
aortega0703 wants to merge 18 commits intoagda:masterfrom
Draft
[Add] Division properties for Nat, Integer, and Rational#2962aortega0703 wants to merge 18 commits intoagda:masterfrom
aortega0703 wants to merge 18 commits intoagda:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I saw there weren't many properties for division outside of Naturals so I went ahead and proved some for (Unnormalised) Rationals and Integers (and Naturals too):
Data.Rational.Unnormalised:/-distribʳ-+: fractions with sums on the numerator can be "split" into sums of fractionsn/d≡[n/1]*[1/d]: this was more of a convenience to prove/-distribʳ-+but I thought it could be useful enough to add it separately (maybe not?)./-monoˡ-<,/-monoʳ-<-pos,/-monoʳ-<-neg,/-monoˡ-≤,/-monoʳ-≤-nonNeg, and/-monoʳ-≤-nonPos: InRationaldenominators areℕs, so there isn't a sign hell as withInteger.Data.Integer.DivMod:n<0⇒n/ℕd<0: there was already0≤n⇒0≤n/ℕdso I added "the other case".0/d≡0andn/1≡n(also for/ℕ).n/ℕd≡0⇒∣n∣<dandn/d≡0⇒∣n∣<∣d∣: the integer version ofm/n≡0⇒m<n.0≤n<d⇒n/d≡0(also/ℕ): the "converse" (not really), an int version ofm<n⇒m/n≡0./ℕ-monoˡ-≤(and helpers),/ℕ-monoʳ-≤-nonNegand/ℕ-monoʳ-≤-nonPos./-monoˡ-≤-posand/-monoˡ-≤-neg: I put a reduntantNonZeroto make_/_happy where onlyPositive/Negativeshould really suffice. I admit I tried deriving theNonZerobut I don't know how to do it without making the type too verbose/ugly./-monoʳ-≤-nonNeg-eq-signsand/-monoʳ-≤-nonPos-eq-signs: The proofs for these are basically the same, extremely so (just swapping the denominators names), but I can't figure a way to prove one with the other.(- n) / dand- (n / d)are not always equal so I can't just convert the numerator fromnonPostononNeg, but maybe there's another way?/-monoʳ-≤-nonNeg-op-signsand/-monoʳ-≤-nonPos-op-signs: I also noticed how/-monoʳ-≤-nonNeg-eq-signsand/-monoʳ-≤-nonPos-op-signshave basically the same type (their counterparts too) but I don't know If it's better to keep them separate or combine them and ask for something likesign (n * d₁ * d₂) ≡ Sign.+in the type.Data.Nat.DivMod:sn%d≡0⇒sn/d≡s[n/d]andsn%d>0⇒sn/d≡n/d: These really really (really) helped to reason about Integer division. Also, they are nice in that they describe whether the quotient increases with the dividend or it stays the same.%-pred-≡suc: This is "the other case" of%-pred-≡0, it says that the remainder increases on par with the dividend (exept for the jump at remainder 0). I don't like the name on this one but I retained the name style of%-pred-≡0.I have yet to translate the
Unnormalisedproofs to normalised Rationals and I'm not sure about the whole deal with the signs on the types for/-monoon Integers so it's a draft for now.