Skip to content

Commit ac59629

Browse files
faster operations for integers (#1245)
Co-authored-by: Lorenzo Molena <[email protected]>
1 parent fe7b50e commit ac59629

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Cubical/Data/Int/Fast/Base.agda

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Cubical.Data.Int.Fast.Base where
2+
3+
open import Cubical.Foundations.Prelude
4+
open import Cubical.Data.Nat as ℕ hiding (_+_ ; _·_)
5+
open import Cubical.Data.Int.Base hiding (_ℕ-_ ; _+_ ; _-_ ; _·_) public
6+
7+
infixl 7 _·_
8+
infixl 6 _+_ _-_
9+
10+
ℕ-hlp :
11+
ℕ-hlp m-n@zero n-m = - (pos n-m)
12+
ℕ-hlp m-n@(suc _) n-m = pos m-n
13+
14+
_ℕ-_ :
15+
m ℕ- n = ℕ-hlp (m ℕ.∸ n) (n ℕ.∸ m)
16+
17+
_+_ :
18+
pos n + pos n₁ = pos (n ℕ.+ n₁)
19+
negsuc n + negsuc n₁ = negsuc (suc (n ℕ.+ n₁))
20+
pos n + negsuc n₁ = n ℕ- (suc n₁)
21+
negsuc n + pos n₁ = n₁ ℕ- (suc n)
22+
23+
_-_ :
24+
m - n = m + (- n)
25+
26+
_·_ :
27+
pos n · pos n₁ = pos (n ℕ.· n₁)
28+
pos zero · negsuc n₁ = pos zero
29+
pos (suc n) · negsuc n₁ = negsuc (predℕ (suc n ℕ.· suc n₁))
30+
negsuc n · pos zero = pos zero
31+
negsuc n · pos (suc n₁) = negsuc (predℕ (suc n ℕ.· suc n₁))
32+
negsuc n · negsuc n₁ = pos (suc n ℕ.· suc n₁)

0 commit comments

Comments
 (0)