Go to the first, previous, next, last section, table of contents.


Funktionen

----------------------------------------------------------------------
> module Function       (  Ident(..), Function(..), Prim(..),
>                          constant,
>                          csplit, summands, factors, esplit,
>                          (+++), (***), summ, prod, minus,
>                          nat, zero, half, mhalf, one, mone, two, mtwo, ten
>                       )
> where
----------------------------------------------------------------------

----------------------------------------------------------------------
> import Prim           (  Ident(..), Prim(..)  )
----------------------------------------------------------------------
----------------------------------------------------------------------
> infixr 1 :.:
> infixr 2 +++
> infixr 3 ***
> infixr 5 :^:
----------------------------------------------------------------------

Darstellung von Funktionen

----------------------------------------------------------------------
> data Function         =  Ratio      Rational
>                       |  Const      Ident
>                       |  Prim       Prim
>                       |  Fun        Ident
>                       |  Derive Int Function
>                       |  Id
>                       |  Function :.: Function
>                       |  Summ [Function]
>                       |  Prod [Function]
>                       |  Function :^: Function
>                       deriving (Eq, Ord, Text)
----------------------------------------------------------------------

Testfunktionen

----------------------------------------------------------------------
> constant (Ratio n)    =  True
> constant (Const c)    =  True
> constant (f :.: g)    =  constant f || constant g
> constant (Summ fs)    =  all constant fs
> constant (Prod fs)    =  all constant fs
> constant (f :^: g)    =  constant f && constant g
> constant _            =  False
----------------------------------------------------------------------

Konstruktoren

----------------------------------------------------------------------
> summ []               =  zero
> summ [f]              =  f
> summ fs               =  Summ fs
----------------------------------------------------------------------

----------------------------------------------------------------------
> prod []               =  one
> prod [f]              =  f
> prod fs               =  Prod fs
----------------------------------------------------------------------

----------------------------------------------------------------------
> f +++ g               =  Summ [f, g]
> f *** g               =  Prod [f, g]
----------------------------------------------------------------------

----------------------------------------------------------------------
> minus f               =  Prod [mone, f]
----------------------------------------------------------------------

----------------------------------------------------------------------
> nat n                 =  Ratio (n % 1)
----------------------------------------------------------------------

----------------------------------------------------------------------
> zero                  =  nat    0
> half                  =  Ratio ( 1 % 2)
> mhalf                 =  Ratio (-1 % 2)
> one                   =  nat    1
> mone                  =  nat (-1)
> two                   =  nat    2
> mtwo                  =  nat (-2)
> ten                   =  nat   10
----------------------------------------------------------------------

Destruktoren

----------------------------------------------------------------------
> csplit (f :.: g)              =  (f, g)
> csplit f                      =  (f, Id)
----------------------------------------------------------------------

----------------------------------------------------------------------
> summands (Ratio m) | m == 0   =  []
> summands (Summ fs)            =  fs
> summands f                    =  [f]
----------------------------------------------------------------------

----------------------------------------------------------------------
> factors (Ratio m) | m == 1    =  []
> factors (Prod fs)             =  fs
> factors f                     =  [f]
----------------------------------------------------------------------

----------------------------------------------------------------------
> esplit (f :^: g)              =  (f, g)
> esplit f                      =  (f, one)
----------------------------------------------------------------------


Go to the first, previous, next, last section, table of contents.