Skip to content

Commit c5255d0

Browse files
Algebra fixity (#2386)
* put the fixity recommendations into the style guide * mixing fixity declaration * was missing a case * use the new case * add fixities for everything in Algebra * incorporate some suggestions for extra cases
1 parent e25f9d8 commit c5255d0

File tree

11 files changed

+78
-1
lines changed

11 files changed

+78
-1
lines changed

doc/README/Design/Fixity.agda

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ module README.Design.Fixity where
3434
-- type formers:
3535
-- product-like infixr 2 _×_ _-×-_ _-,-_
3636
-- sum-like infixr 1 _⊎_
37+
-- binary properties infix 4 _Absorbs_

doc/style-guide.md

+60
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,66 @@ word within a compound word is capitalized except for the first word.
525525
* Any exceptions to these conventions should be flagged on the GitHub
526526
`agda-stdlib` issue tracker in the usual way.
527527

528+
#### Fixity
529+
530+
All functions and operators that are not purely prefix (typically
531+
anything that has a `_` in its name) should have an explicit fixity
532+
declared for it. The guidelines for these are as follows:
533+
534+
General operations and relations:
535+
536+
* binary relations of all kinds are `infix 4`
537+
538+
* unary prefix relations `infix 4 ε∣_`
539+
540+
* unary postfix relations `infixr 8 _∣0`
541+
542+
* multiplication-like: `infixl 7 _*_`
543+
544+
* addition-like `infixl 6 _+_`
545+
546+
* arithmetic prefix minus-like `infix 8 -_`
547+
548+
* arithmetic infix binary minus-like `infixl 6 _-_`
549+
550+
* and-like `infixr 7 _∧_`
551+
552+
* or-like `infixr 6 _∨_`
553+
554+
* negation-like `infix 3 ¬_`
555+
556+
* post-fix inverse `infix 8 _⁻¹`
557+
558+
* bind `infixl 1 _>>=_`
559+
560+
* list concat-like `infixr 5 _∷_`
561+
562+
* ternary reasoning `infix 1 _⊢_≈_`
563+
564+
* composition `infixr 9 _∘_`
565+
566+
* application `infixr -1 _$_ _$!_`
567+
568+
* combinatorics `infixl 6.5 _P_ _P′_ _C_ _C′_`
569+
570+
* pair `infixr 4 _,_`
571+
572+
Reasoning:
573+
574+
* QED `infix 3 _∎`
575+
576+
* stepping `infixr 2 _≡⟨⟩_ step-≡ step-≡˘`
577+
578+
* begin `infix 1 begin_`
579+
580+
Type formers:
581+
582+
* product-like `infixr 2 _×_ _-×-_ _-,-_`
583+
584+
* sum-like `infixr 1 _⊎_`
585+
586+
* binary properties `infix 4 _Absorbs_`
587+
528588
#### Functions and relations over specific datatypes
529589

530590
* When defining a new relation `P` over a datatype `X` in a `Data.X.Relation` module,

src/Algebra/Bundles.agda

+1
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ record NonAssociativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
917917
using () renaming (magma to *-magma; identity to *-identity)
918918

919919
record Nearring c ℓ : Set (suc (c ⊔ ℓ)) where
920+
infix 8 -_
920921
infixl 7 _*_
921922
infixl 6 _+_
922923
infix 4 _≈_

src/Algebra/Definitions.agda

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ RightConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → y ≈ e
9797
Conical : A Op₂ A Set _
9898
Conical e ∙ = (LeftConical e ∙) × (RightConical e ∙)
9999

100+
infix 4 _DistributesOverˡ_ _DistributesOverʳ_ _DistributesOver_
101+
100102
_DistributesOverˡ_ : Op₂ A Op₂ A Set _
101103
_*_ DistributesOverˡ _+_ =
102104
x y z (x * (y + z)) ≈ ((x * y) + (x * z))
@@ -108,6 +110,8 @@ _*_ DistributesOverʳ _+_ =
108110
_DistributesOver_ : Op₂ A Op₂ A Set _
109111
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +)
110112

113+
infix 4 _MiddleFourExchange_ _IdempotentOn_ _Absorbs_
114+
111115
_MiddleFourExchange_ : Op₂ A Op₂ A Set _
112116
_*_ MiddleFourExchange _+_ =
113117
w x y z ((w + x) * (y + z)) ≈ ((w + y) * (x + z))

src/Algebra/Definitions/RawMagma.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open RawMagma M renaming (Carrier to A)
2525
------------------------------------------------------------------------
2626
-- Divisibility
2727

28-
infix 5 _∣ˡ_ _∤ˡ_ _∣ʳ_ _∤ʳ_ _∣_ _∤_
28+
infix 5 _∣ˡ_ _∤ˡ_ _∣ʳ_ _∤ʳ_ _∣_ _∤_ _∣∣_ _∤∤_
2929

3030
-- Divisibility from the left.
3131
--

src/Algebra/Module/Bundles.agda

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ record Bimodule (R-ring : Ring r ℓr) (S-ring : Ring s ℓs) m ℓm
279279
module R = Ring R-ring
280280
module S = Ring S-ring
281281

282+
infix 8 -ᴹ_
282283
infixr 7 _*ₗ_
283284
infixl 7 _*ᵣ_
284285
infixl 6 _+ᴹ_

src/Algebra/Module/Definitions/Left.agda

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ LeftIdentity a _∙ᴮ_ = ∀ m → (a ∙ᴮ m) ≈ m
3131
Associative : Op₂ A Opₗ A B Set _
3232
Associative _∙ᴬ_ _∙ᴮ_ = x y m ((x ∙ᴬ y) ∙ᴮ m) ≈ (x ∙ᴮ (y ∙ᴮ m))
3333

34+
infix 4 _DistributesOverˡ_ _DistributesOverʳ_⟶_
35+
3436
_DistributesOverˡ_ : Opₗ A B Op₂ B Set _
3537
_*_ DistributesOverˡ _+_ =
3638
x m n (x * (m + n)) ≈ ((x * m) + (x * n))

src/Algebra/Module/Definitions/Right.agda

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ RightIdentity a _∙ᴮ_ = ∀ m → (m ∙ᴮ a) ≈ m
3131
Associative : Op₂ A Opᵣ A B Set _
3232
Associative _∙ᴬ_ _∙ᴮ_ = m x y ((m ∙ᴮ x) ∙ᴮ y) ≈ (m ∙ᴮ (x ∙ᴬ y))
3333

34+
infix 4 _DistributesOverʳ_ _DistributesOverˡ_⟶_
35+
3436
_DistributesOverˡ_⟶_ : Opᵣ A B Op₂ A Op₂ B Set _
3537
_*_ DistributesOverˡ _+ᴬ_ ⟶ _+ᴮ_ =
3638
m x y (m * (x +ᴬ y)) ≈ ((m * x) +ᴮ (m * y))

src/Algebra/Properties/Monoid/Divisibility.agda

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ open import Algebra.Properties.Semigroup.Divisibility semigroup public
2626
------------------------------------------------------------------------
2727
-- Additional properties
2828

29+
infix 4 ε∣_
30+
2931
ε∣_ : x ε ∣ x
3032
ε∣ x = x , identityʳ x
3133

src/Algebra/Properties/Semiring/Divisibility.agda

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ open MonoidDivisibility *-monoid public
2525
------------------------------------------------------------------------
2626
-- Divisibility properties specific to semirings.
2727

28+
infixr 8 _∣0
29+
2830
_∣0 : x x ∣ 0#
2931
x ∣0 = 0# , zeroˡ x
3032

src/Algebra/Solver/Ring/AlmostCommutativeRing.agda

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ record AlmostCommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
7676
------------------------------------------------------------------------
7777
-- Homomorphisms
7878

79+
infix 4 _-Raw-AlmostCommutative⟶_
80+
7981
record _-Raw-AlmostCommutative⟶_
8082
{r₁ r₂ r₃ r₄}
8183
(From : RawRing r₁ r₄)

0 commit comments

Comments
 (0)