{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Lattices.UnitIntervalStructures.Lukasiewicz(
    UILukasiewicz(UILukasiewicz),
    BoundedLattice(..),
    mkLukasiewiczUnitInterval,
    fromLukasiewiczUnitInterval
) where

import Lattices.ResiduatedLattice
import Lattices.UnitInterval

newtype UILukasiewicz = UILukasiewicz UnitInterval 
    deriving (UILukasiewicz -> UILukasiewicz -> Bool
(UILukasiewicz -> UILukasiewicz -> Bool)
-> (UILukasiewicz -> UILukasiewicz -> Bool) -> Eq UILukasiewicz
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UILukasiewicz -> UILukasiewicz -> Bool
== :: UILukasiewicz -> UILukasiewicz -> Bool
$c/= :: UILukasiewicz -> UILukasiewicz -> Bool
/= :: UILukasiewicz -> UILukasiewicz -> Bool
Eq, Eq UILukasiewicz
Eq UILukasiewicz =>
(UILukasiewicz -> UILukasiewicz -> Ordering)
-> (UILukasiewicz -> UILukasiewicz -> Bool)
-> (UILukasiewicz -> UILukasiewicz -> Bool)
-> (UILukasiewicz -> UILukasiewicz -> Bool)
-> (UILukasiewicz -> UILukasiewicz -> Bool)
-> (UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> Ord UILukasiewicz
UILukasiewicz -> UILukasiewicz -> Bool
UILukasiewicz -> UILukasiewicz -> Ordering
UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UILukasiewicz -> UILukasiewicz -> Ordering
compare :: UILukasiewicz -> UILukasiewicz -> Ordering
$c< :: UILukasiewicz -> UILukasiewicz -> Bool
< :: UILukasiewicz -> UILukasiewicz -> Bool
$c<= :: UILukasiewicz -> UILukasiewicz -> Bool
<= :: UILukasiewicz -> UILukasiewicz -> Bool
$c> :: UILukasiewicz -> UILukasiewicz -> Bool
> :: UILukasiewicz -> UILukasiewicz -> Bool
$c>= :: UILukasiewicz -> UILukasiewicz -> Bool
>= :: UILukasiewicz -> UILukasiewicz -> Bool
$cmax :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
max :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
$cmin :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
min :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
Ord, Integer -> UILukasiewicz
UILukasiewicz -> UILukasiewicz
UILukasiewicz -> UILukasiewicz -> UILukasiewicz
(UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz)
-> (Integer -> UILukasiewicz)
-> Num UILukasiewicz
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
+ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
$c- :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
- :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
$c* :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
* :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
$cnegate :: UILukasiewicz -> UILukasiewicz
negate :: UILukasiewicz -> UILukasiewicz
$cabs :: UILukasiewicz -> UILukasiewicz
abs :: UILukasiewicz -> UILukasiewicz
$csignum :: UILukasiewicz -> UILukasiewicz
signum :: UILukasiewicz -> UILukasiewicz
$cfromInteger :: Integer -> UILukasiewicz
fromInteger :: Integer -> UILukasiewicz
Num, Num UILukasiewicz
Ord UILukasiewicz
(Num UILukasiewicz, Ord UILukasiewicz) =>
(UILukasiewicz -> Rational) -> Real UILukasiewicz
UILukasiewicz -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: UILukasiewicz -> Rational
toRational :: UILukasiewicz -> Rational
Real, Fractional UILukasiewicz
Real UILukasiewicz
(Real UILukasiewicz, Fractional UILukasiewicz) =>
(forall b. Integral b => UILukasiewicz -> (b, UILukasiewicz))
-> (forall b. Integral b => UILukasiewicz -> b)
-> (forall b. Integral b => UILukasiewicz -> b)
-> (forall b. Integral b => UILukasiewicz -> b)
-> (forall b. Integral b => UILukasiewicz -> b)
-> RealFrac UILukasiewicz
forall b. Integral b => UILukasiewicz -> b
forall b. Integral b => UILukasiewicz -> (b, UILukasiewicz)
forall a.
(Real a, Fractional a) =>
(forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
$cproperFraction :: forall b. Integral b => UILukasiewicz -> (b, UILukasiewicz)
properFraction :: forall b. Integral b => UILukasiewicz -> (b, UILukasiewicz)
$ctruncate :: forall b. Integral b => UILukasiewicz -> b
truncate :: forall b. Integral b => UILukasiewicz -> b
$cround :: forall b. Integral b => UILukasiewicz -> b
round :: forall b. Integral b => UILukasiewicz -> b
$cceiling :: forall b. Integral b => UILukasiewicz -> b
ceiling :: forall b. Integral b => UILukasiewicz -> b
$cfloor :: forall b. Integral b => UILukasiewicz -> b
floor :: forall b. Integral b => UILukasiewicz -> b
RealFrac, Num UILukasiewicz
Num UILukasiewicz =>
(UILukasiewicz -> UILukasiewicz -> UILukasiewicz)
-> (UILukasiewicz -> UILukasiewicz)
-> (Rational -> UILukasiewicz)
-> Fractional UILukasiewicz
Rational -> UILukasiewicz
UILukasiewicz -> UILukasiewicz
UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
/ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
$crecip :: UILukasiewicz -> UILukasiewicz
recip :: UILukasiewicz -> UILukasiewicz
$cfromRational :: Rational -> UILukasiewicz
fromRational :: Rational -> UILukasiewicz
Fractional)

instance BoundedLattice UILukasiewicz where
    /\ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
(/\) (UILukasiewicz UnitInterval
x) (UILukasiewicz UnitInterval
y) = UnitInterval -> UILukasiewicz
UILukasiewicz (UnitInterval
x UnitInterval -> UnitInterval -> UnitInterval
forall l. BoundedLattice l => l -> l -> l
/\ UnitInterval
y)
    \/ :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
(\/) (UILukasiewicz UnitInterval
x) (UILukasiewicz UnitInterval
y) = UnitInterval -> UILukasiewicz
UILukasiewicz (UnitInterval
x UnitInterval -> UnitInterval -> UnitInterval
forall l. BoundedLattice l => l -> l -> l
\/ UnitInterval
y)
    bot :: UILukasiewicz
bot = UnitInterval -> UILukasiewicz
UILukasiewicz UnitInterval
forall l. BoundedLattice l => l
bot
    top :: UILukasiewicz
top = UnitInterval -> UILukasiewicz
UILukasiewicz UnitInterval
forall l. BoundedLattice l => l
top
    mkLattice :: Double -> UILukasiewicz
mkLattice = Double -> UILukasiewicz
mkLukasiewiczUnitInterval

-- | Łukasiewicz structure of truth values

instance ResiduatedLattice UILukasiewicz where
    tnorm :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
tnorm UILukasiewicz
a UILukasiewicz
b = (UILukasiewicz
a UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a. Num a => a -> a -> a
+ UILukasiewicz
b UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a. Num a => a -> a -> a
- UILukasiewicz
forall l. BoundedLattice l => l
top) UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall l. BoundedLattice l => l -> l -> l
\/ UILukasiewicz
forall l. BoundedLattice l => l
bot
    UILukasiewicz
a --> :: UILukasiewicz -> UILukasiewicz -> UILukasiewicz
--> UILukasiewicz
b = (UILukasiewicz
forall l. BoundedLattice l => l
top UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a. Num a => a -> a -> a
- UILukasiewicz
a UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall a. Num a => a -> a -> a
+ UILukasiewicz
b) UILukasiewicz -> UILukasiewicz -> UILukasiewicz
forall l. BoundedLattice l => l -> l -> l
/\ UILukasiewicz
forall l. BoundedLattice l => l
top

instance Show UILukasiewicz where 
    show :: UILukasiewicz -> String
show (UILukasiewicz UnitInterval
x) = UnitInterval -> String
forall a. Show a => a -> String
show UnitInterval
x

mkLukasiewiczUnitInterval :: Double -> UILukasiewicz
mkLukasiewiczUnitInterval :: Double -> UILukasiewicz
mkLukasiewiczUnitInterval Double
x = UnitInterval -> UILukasiewicz
UILukasiewicz (UnitInterval -> UILukasiewicz) -> UnitInterval -> UILukasiewicz
forall a b. (a -> b) -> a -> b
$ Double -> UnitInterval
mkUnitInterval Double
x

fromLukasiewiczUnitInterval :: UILukasiewicz -> Double
fromLukasiewiczUnitInterval :: UILukasiewicz -> Double
fromLukasiewiczUnitInterval (UILukasiewicz (UnitInterval Double
x)) = Double
x