Break `abs` into two aspects

This two-step proposal suggests to alter the official Haskell 2010 standard. 1. Introduction: The `Num` typeclass effectively represents a ring. Yet it also has `abs` and `signum`. `abs` represents a norm, but its type is wrong: abs :: a -> a Mathematically, the return value must be a nonnegative real number. Yet there is no guarantee that the type `a` can have that value. This led us to have too strong restriction to `instance Num Complex`: instance RealFloat a => Num (Complex a) where ... I found a way for `abs` (and `signum`) to have much more mathematical place. 2. Step 1: First, I suggest to add the following variants of `abs` and `signum`: realAbs :: Real a => a -> a realAbs x = if x >= 0 then x else negate x realSignum :: Real a => a -> a realSignum x = case compare 0 x of LT -> -1 EQ -> 0 _ -> 1 These can replace `abs` and `signum` instances for integral and rational types. 3. Step 2: Second, I suggest to move `abs` and `signum` from `Num` to `Floating`: class Floating a where abs :: a -> a signum :: a -> a ... This exploits the fact that `Floating` represents a field with characteristic 0, regarding exponential and trigonometric functions are defined as Taylor series. The definition of convergence of series is defined using norms. 4. Conclusion: This enables us to implement rings (Num) and fields (Fractional) without concerning about norms. For example, Gaussian integers.

Rational is applicable the suggested new functions.
2020년 1월 28일 (화) 오후 7:49, Henning Thielemann
On Tue, 28 Jan 2020, Dannyu NDos wrote:
3. Step 2:
Second, I suggest to move `abs` and `signum` from `Num` to `Floating`:
class Floating a where abs :: a -> a signum :: a -> a ...
Rational is not Floating, but has reasonable abs and signum.

@Andrew, it's not clear how you are posing U(R) as "ring of units." It's a
multiplicative group, and is not closed under addition.
2020년 1월 28일 (화) 19:42, Dannyu NDos
This two-step proposal suggests to alter the official Haskell 2010 standard.
1. Introduction:
The `Num` typeclass effectively represents a ring. Yet it also has `abs` and `signum`. `abs` represents a norm, but its type is wrong:
abs :: a -> a
Mathematically, the return value must be a nonnegative real number. Yet there is no guarantee that the type `a` can have that value. This led us to have too strong restriction to `instance Num Complex`:
instance RealFloat a => Num (Complex a) where ...
I found a way for `abs` (and `signum`) to have much more mathematical place.
2. Step 1:
First, I suggest to add the following variants of `abs` and `signum`:
realAbs :: Real a => a -> a realAbs x = if x >= 0 then x else negate x realSignum :: Real a => a -> a realSignum x = case compare 0 x of LT -> -1 EQ -> 0 _ -> 1
These can replace `abs` and `signum` instances for integral and rational types.
3. Step 2:
Second, I suggest to move `abs` and `signum` from `Num` to `Floating`:
class Floating a where abs :: a -> a signum :: a -> a ...
This exploits the fact that `Floating` represents a field with characteristic 0, regarding exponential and trigonometric functions are defined as Taylor series. The definition of convergence of series is defined using norms.
4. Conclusion:
This enables us to implement rings (Num) and fields (Fractional) without concerning about norms. For example, Gaussian integers.

I think it's more mathematically clear to define `abs` by U(R) acting on R. U(R) acts on R via multiplication, which defines an equivalence relation on R called 'associatedness.'
participants (2)
-
Dannyu NDos
-
Henning Thielemann