sign-0.4.2: Arithmetic over signs and sets of signs

Copyright(c) Masahiro Sakai 2013
LicenseBSD-style
Maintainermasahiro.sakai@gmail.com
Stabilityprovisional
Portabilitynon-portable (FlexibleInstances, DeriveDataTypeable, CPP)
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Sign

Contents

Description

This module provides arithmetic over signs (i.e. {-, 0, +}) and set of signs.

For the purpose of abstract interpretation, it might be convenient to use Lattice instance. See also lattices package (http://hackage.haskell.org/package/lattices).

Synopsis

The Sign data type

data Sign Source

Signs of real numbers.

Constructors

Neg

negative

Zero

zero

Pos

positive

Operations over signs

negate :: Sign -> Sign Source

Unary negation.

abs :: Sign -> Sign Source

Absolute value.

mult :: Sign -> Sign -> Sign Source

Multiplication.

recip :: Sign -> Sign Source

Reciprocal fraction.

div :: Sign -> Sign -> Sign Source

Fractional division.

pow :: Integral x => Sign -> x -> Sign Source

Exponentiation s^x.

Note that we define pow Zero 0 = Pos assuming 0^0 = 1.

signOf :: Real a => a -> Sign Source

Sign of a number.

symbol :: Sign -> String Source

Mnemonic symbol of a number.

This function returns "-", "0", "+" respectively for Neg, Zero, Pos.

Operations over sets of signs

Set Sign is equipped with instances of Num and Fractional. Therefore arithmetic operations can be applied to Set Sign.

Instances of Lattice and BoundedLattice are also provided for the purpose of abstract interpretation.