File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import GHC.Natural (naturalToInteger)
18
18
import GHC.TypeNats (natVal )
19
19
import Protolude as P hiding (Semiring , natVal , rem )
20
20
import Test.QuickCheck (Arbitrary (.. ), choose )
21
- import Text.PrettyPrint.Leijen.Text (Pretty (.. ))
21
+ import Text.PrettyPrint.Leijen.Text (Pretty (.. ), text )
22
22
23
23
-------------------------------------------------------------------------------
24
24
-- Data types
@@ -103,7 +103,14 @@ instance (KnownNat p) => Integral (Prime p) where
103
103
104
104
-- Prime fields are pretty.
105
105
instance (KnownNat p ) => Pretty (Prime p ) where
106
- pretty (P x) = pretty $ naturalToInteger $ unMod x
106
+ pretty (f :: Prime p ) =
107
+ let p = toInteger (natVal $ Proxy @ p )
108
+ cutoff = p `div` 2
109
+ x = fromP f
110
+ in if x < cutoff
111
+ then pretty x
112
+ else text " -" <> pretty (abs (x - p))
113
+
107
114
108
115
-- Prime fields are random.
109
116
instance (KnownNat p ) => Random (Prime p ) where
You can’t perform that action at this time.
0 commit comments