<commit_before>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-|
    Module      :  Numeric.AERN.Basics.Interval.NumericOrder
    Description :  interval instances of numeric-ordered structures 
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    Interval instances of numeric-ordered structures.
    
    This is a hidden module reexported via its parent.
-}
module Numeric.AERN.Basics.Interval.NumericOrder where

import Prelude hiding (EQ, LT, GT)

import Numeric.AERN.Basics.Consistency
import Numeric.AERN.Basics.PartialOrdering

import Numeric.AERN.Basics.Interval.Basics
import Numeric.AERN.Basics.Interval.Consistency
import Numeric.AERN.Basics.Interval.Mutable

import Numeric.AERN.Misc.List

import qualified Numeric.AERN.Basics.NumericOrder as NumOrd

import Test.QuickCheck

import Data.Maybe

instance
    (NumOrd.PartialComparison e) => 
    (NumOrd.PartialComparison (Interval e))
    where
    type NumOrd.PartialCompareEffortIndicator (Interval e) = 
        NumOrd.PartialCompareEffortIndicator e 
    pCompareDefaultEffort (Interval l h) = NumOrd.pCompareDefaultEffort l
    pCompareEff effort i1@(Interval l1 h1) i2@(Interval l2 h2) =
            case (isConsistentEff effort i1, isConsistentEff effort i2) of
                (Just True, Just True) ->
                    case (h1 `leq` l2, h1 `less` l2, h2 `leq` l1, h2 `less` l1) of
                        (Just True, _, Just True, _) -> Just EQ
                        (_, Just True, _, _) -> Just LT
                        (Just True, _, _, _) -> Just LEE
                        (_, _, _, Just True) -> Just GT
                        (_, _, Just True, _) -> Just GEE
                        _ -> Nothing
                _ -> Nothing
            where
            leq = NumOrd.pLeqEff effort
            less = NumOrd.pLessEff effort
            
                
instance
    (NumOrd.RoundedLatticeEffort e) =>
    (NumOrd.OuterRoundedLatticeEffort (Interval e))
    where
    type NumOrd.MinmaxOuterEffortIndicator (Interval e) = NumOrd.MinmaxEffortIndicator e
    minmaxOuterDefaultEffort (Interval l h) = NumOrd.minmaxDefaultEffort l  

instance
    (NumOrd.RoundedLattice e) =>
    (NumOrd.OuterRoundedLattice (Interval e))
    where
    minOuterEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.minDnEff effort l1 l2) (NumOrd.minUpEff effort h1 h2)
    maxOuterEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.maxDnEff effort l1 l2) (NumOrd.maxUpEff effort h1 h2)

instance
    (NumOrd.RoundedLatticeEffort e) =>
    (NumOrd.InnerRoundedLatticeEffort (Interval e))
    where
    type NumOrd.MinmaxInnerEffortIndicator (Interval e) = NumOrd.MinmaxEffortIndicator e
    minmaxInnerDefaultEffort (Interval l h) = NumOrd.minmaxDefaultEffort l  
instance
    (NumOrd.RoundedLattice e) =>
    (NumOrd.InnerRoundedLattice (Interval e))
    where
    minInnerEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.minUpEff effort l1 l2) (NumOrd.minDnEff effort h1 h2)
    maxInnerEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.maxUpEff effort l1 l2) (NumOrd.maxDnEff effort h1 h2)

instance 
    (NumOrd.RoundedLattice e) => 
    (NumOrd.RefinementRoundedLattice (Interval e))

instance
    (NumOrd.RoundedLatticeInPlace e) =>
    (NumOrd.OuterRoundedLatticeInPlace (Interval e))
    where
    minOuterInPlaceEff (Interval sample _) effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.minDnInPlaceEff sample effort resLM l1M l2M
        NumOrd.minUpInPlaceEff sample effort resHM h1M h2M
    maxOuterInPlaceEff (Interval sample _) effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.maxDnInPlaceEff sample effort resLM l1M l2M
        NumOrd.maxUpInPlaceEff sample effort resHM h1M h2M


instance
    (NumOrd.RoundedLatticeInPlace e) =>
    (NumOrd.InnerRoundedLatticeInPlace (Interval e))
    where
    minInnerInPlaceEff (Interval sample _) effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.minUpInPlaceEff sample effort resLM l1M l2M
        NumOrd.minDnInPlaceEff sample effort resHM h1M h2M
    maxInnerInPlaceEff (Interval sample _) effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.maxUpInPlaceEff sample effort resLM l1M l2M
        NumOrd.maxDnInPlaceEff sample effort resHM h1M h2M

instance 
    (NumOrd.RoundedLatticeInPlace e) => <commit_msg>Eliminated sample parameter in ..Interval.NumericOrder<commit_after>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-|
    Module      :  Numeric.AERN.Basics.Interval.NumericOrder
    Description :  interval instances of numeric-ordered structures 
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    Interval instances of numeric-ordered structures.
    
    This is a hidden module reexported via its parent.
-}
module Numeric.AERN.Basics.Interval.NumericOrder where

import Prelude hiding (EQ, LT, GT)

import Numeric.AERN.Basics.Consistency
import Numeric.AERN.Basics.PartialOrdering

import Numeric.AERN.Basics.Interval.Basics
import Numeric.AERN.Basics.Interval.Consistency
import Numeric.AERN.Basics.Interval.Mutable

import Numeric.AERN.Misc.List

import qualified Numeric.AERN.Basics.NumericOrder as NumOrd

import Test.QuickCheck

import Data.Maybe

instance
    (NumOrd.PartialComparison e) => 
    (NumOrd.PartialComparison (Interval e))
    where
    type NumOrd.PartialCompareEffortIndicator (Interval e) = 
        NumOrd.PartialCompareEffortIndicator e 
    pCompareDefaultEffort (Interval l h) = NumOrd.pCompareDefaultEffort l
    pCompareEff effort i1@(Interval l1 h1) i2@(Interval l2 h2) =
            case (isConsistentEff effort i1, isConsistentEff effort i2) of
                (Just True, Just True) ->
                    case (h1 `leq` l2, h1 `less` l2, h2 `leq` l1, h2 `less` l1) of
                        (Just True, _, Just True, _) -> Just EQ
                        (_, Just True, _, _) -> Just LT
                        (Just True, _, _, _) -> Just LEE
                        (_, _, _, Just True) -> Just GT
                        (_, _, Just True, _) -> Just GEE
                        _ -> Nothing
                _ -> Nothing
            where
            leq = NumOrd.pLeqEff effort
            less = NumOrd.pLessEff effort
            
                
instance
    (NumOrd.RoundedLatticeEffort e) =>
    (NumOrd.OuterRoundedLatticeEffort (Interval e))
    where
    type NumOrd.MinmaxOuterEffortIndicator (Interval e) = NumOrd.MinmaxEffortIndicator e
    minmaxOuterDefaultEffort (Interval l h) = NumOrd.minmaxDefaultEffort l  

instance
    (NumOrd.RoundedLattice e) =>
    (NumOrd.OuterRoundedLattice (Interval e))
    where
    minOuterEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.minDnEff effort l1 l2) (NumOrd.minUpEff effort h1 h2)
    maxOuterEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.maxDnEff effort l1 l2) (NumOrd.maxUpEff effort h1 h2)

instance
    (NumOrd.RoundedLatticeEffort e) =>
    (NumOrd.InnerRoundedLatticeEffort (Interval e))
    where
    type NumOrd.MinmaxInnerEffortIndicator (Interval e) = NumOrd.MinmaxEffortIndicator e
    minmaxInnerDefaultEffort (Interval l h) = NumOrd.minmaxDefaultEffort l  
instance
    (NumOrd.RoundedLattice e) =>
    (NumOrd.InnerRoundedLattice (Interval e))
    where
    minInnerEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.minUpEff effort l1 l2) (NumOrd.minDnEff effort h1 h2)
    maxInnerEff effort (Interval l1 h1) (Interval l2 h2) =
        Interval (NumOrd.maxUpEff effort l1 l2) (NumOrd.maxDnEff effort h1 h2)

instance 
    (NumOrd.RoundedLattice e) => 
    (NumOrd.RefinementRoundedLattice (Interval e))

instance
    (NumOrd.RoundedLatticeInPlace e) =>
    (NumOrd.OuterRoundedLatticeInPlace (Interval e))
    where
    minOuterInPlaceEff effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.minDnInPlaceEff effort resLM l1M l2M
        NumOrd.minUpInPlaceEff effort resHM h1M h2M
    maxOuterInPlaceEff effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.maxDnInPlaceEff effort resLM l1M l2M
        NumOrd.maxUpInPlaceEff effort resHM h1M h2M


instance
    (NumOrd.RoundedLatticeInPlace e) =>
    (NumOrd.InnerRoundedLatticeInPlace (Interval e))
    where
    minInnerInPlaceEff effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.minUpInPlaceEff effort resLM l1M l2M
        NumOrd.minDnInPlaceEff effort resHM h1M h2M
    maxInnerInPlaceEff effort 
            (MInterval resLM resHM) (MInterval l1M h1M) (MInterval l2M h2M) =
        do
        NumOrd.maxUpInPlaceEff effort resLM l1M l2M
        NumOrd.maxDnInPlaceEff effort resHM h1M h2M

instance 
    (NumOrd.RoundedLatticeInPlace e) => 
{'fraction_non_alphanumeric': 0.07486344650315947, 'fraction_numerical': 0.017350326657384597, 'mean_word_length': 2.6677140612725845, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '16311', 'n_tokens_mistral': 3219, 'n_tokens_neox': 3142, 'n_words': 790}