{-# LANGUAGE LambdaCase #-}
module Rzk.Check.Topes
(
Cube (..)
, Point (..)
, Tope (..)
, cubeOf
, pointFirst
, pointSecond
, topeAnd
, topeOr
, ModalTope (..)
, plainTope
, isAccessible
, TopeContext
, emptyTopeContext
, contextTopes
, accessibleTopes
, assume
, assumeDiscrete
, applyModality
, entails
, entailsBottom
, entailsUnion
, entailedBy
, disjoint
, equivalent
, topesEntail
, alternatives
, inAlternatives
) where
import Control.Monad.Foil (Name)
import Data.List (nub, tails)
import qualified Data.Set as Set
import Language.Rzk.Foil.Names (VarIdent)
import Rzk.Check.Modality
data Cube
= KUnit
| K2
| KI
| KProd Cube Cube
| KOther
deriving (Cube -> Cube -> Bool
(Cube -> Cube -> Bool) -> (Cube -> Cube -> Bool) -> Eq Cube
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cube -> Cube -> Bool
== :: Cube -> Cube -> Bool
$c/= :: Cube -> Cube -> Bool
/= :: Cube -> Cube -> Bool
Eq, Eq Cube
Eq Cube =>
(Cube -> Cube -> Ordering)
-> (Cube -> Cube -> Bool)
-> (Cube -> Cube -> Bool)
-> (Cube -> Cube -> Bool)
-> (Cube -> Cube -> Bool)
-> (Cube -> Cube -> Cube)
-> (Cube -> Cube -> Cube)
-> Ord Cube
Cube -> Cube -> Bool
Cube -> Cube -> Ordering
Cube -> Cube -> Cube
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 :: Cube -> Cube -> Ordering
compare :: Cube -> Cube -> Ordering
$c< :: Cube -> Cube -> Bool
< :: Cube -> Cube -> Bool
$c<= :: Cube -> Cube -> Bool
<= :: Cube -> Cube -> Bool
$c> :: Cube -> Cube -> Bool
> :: Cube -> Cube -> Bool
$c>= :: Cube -> Cube -> Bool
>= :: Cube -> Cube -> Bool
$cmax :: Cube -> Cube -> Cube
max :: Cube -> Cube -> Cube
$cmin :: Cube -> Cube -> Cube
min :: Cube -> Cube -> Cube
Ord, Int -> Cube -> ShowS
[Cube] -> ShowS
Cube -> String
(Int -> Cube -> ShowS)
-> (Cube -> String) -> ([Cube] -> ShowS) -> Show Cube
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cube -> ShowS
showsPrec :: Int -> Cube -> ShowS
$cshow :: Cube -> String
show :: Cube -> String
$cshowList :: [Cube] -> ShowS
showList :: [Cube] -> ShowS
Show)
data Point n
= PVar !(Name n) !Cube
| PStar
| P2_0
| P2_1
| PI_0
| PI_1
| PPair (Point n) (Point n)
| PFst (Point n)
| PSnd (Point n)
| PSup (Point n) (Point n)
| PInf (Point n) (Point n)
| PFlip (Point n)
| PUnflip (Point n)
| PModApp TModality (Point n)
| TModality TModality (Point n)
| PApp !Cube (Point n) (Point n)
| PHole (Maybe VarIdent)
| POpaque String
deriving (Point n -> Point n -> Bool
(Point n -> Point n -> Bool)
-> (Point n -> Point n -> Bool) -> Eq (Point n)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (n :: S). Point n -> Point n -> Bool
$c== :: forall (n :: S). Point n -> Point n -> Bool
== :: Point n -> Point n -> Bool
$c/= :: forall (n :: S). Point n -> Point n -> Bool
/= :: Point n -> Point n -> Bool
Eq, Eq (Point n)
Eq (Point n) =>
(Point n -> Point n -> Ordering)
-> (Point n -> Point n -> Bool)
-> (Point n -> Point n -> Bool)
-> (Point n -> Point n -> Bool)
-> (Point n -> Point n -> Bool)
-> (Point n -> Point n -> Point n)
-> (Point n -> Point n -> Point n)
-> Ord (Point n)
Point n -> Point n -> Bool
Point n -> Point n -> Ordering
Point n -> Point n -> Point n
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
forall (n :: S). Eq (Point n)
forall (n :: S). Point n -> Point n -> Bool
forall (n :: S). Point n -> Point n -> Ordering
forall (n :: S). Point n -> Point n -> Point n
$ccompare :: forall (n :: S). Point n -> Point n -> Ordering
compare :: Point n -> Point n -> Ordering
$c< :: forall (n :: S). Point n -> Point n -> Bool
< :: Point n -> Point n -> Bool
$c<= :: forall (n :: S). Point n -> Point n -> Bool
<= :: Point n -> Point n -> Bool
$c> :: forall (n :: S). Point n -> Point n -> Bool
> :: Point n -> Point n -> Bool
$c>= :: forall (n :: S). Point n -> Point n -> Bool
>= :: Point n -> Point n -> Bool
$cmax :: forall (n :: S). Point n -> Point n -> Point n
max :: Point n -> Point n -> Point n
$cmin :: forall (n :: S). Point n -> Point n -> Point n
min :: Point n -> Point n -> Point n
Ord, Int -> Point n -> ShowS
[Point n] -> ShowS
Point n -> String
(Int -> Point n -> ShowS)
-> (Point n -> String) -> ([Point n] -> ShowS) -> Show (Point n)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (n :: S). Int -> Point n -> ShowS
forall (n :: S). [Point n] -> ShowS
forall (n :: S). Point n -> String
$cshowsPrec :: forall (n :: S). Int -> Point n -> ShowS
showsPrec :: Int -> Point n -> ShowS
$cshow :: forall (n :: S). Point n -> String
show :: Point n -> String
$cshowList :: forall (n :: S). [Point n] -> ShowS
showList :: [Point n] -> ShowS
Show)
data Tope n
= TTop
| TBot
| TEq (Point n) (Point n)
| TLeq (Point n) (Point n)
| TAnd (Tope n) (Tope n)
| TOr (Tope n) (Tope n)
| TInv (Tope n)
| TUninv (Tope n)
| TModal TModality (Tope n)
| TModApp TModality (Tope n)
| TNeutral (Point n)
| THole (Maybe VarIdent)
deriving (Tope n -> Tope n -> Bool
(Tope n -> Tope n -> Bool)
-> (Tope n -> Tope n -> Bool) -> Eq (Tope n)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (n :: S). Tope n -> Tope n -> Bool
$c== :: forall (n :: S). Tope n -> Tope n -> Bool
== :: Tope n -> Tope n -> Bool
$c/= :: forall (n :: S). Tope n -> Tope n -> Bool
/= :: Tope n -> Tope n -> Bool
Eq, Eq (Tope n)
Eq (Tope n) =>
(Tope n -> Tope n -> Ordering)
-> (Tope n -> Tope n -> Bool)
-> (Tope n -> Tope n -> Bool)
-> (Tope n -> Tope n -> Bool)
-> (Tope n -> Tope n -> Bool)
-> (Tope n -> Tope n -> Tope n)
-> (Tope n -> Tope n -> Tope n)
-> Ord (Tope n)
Tope n -> Tope n -> Bool
Tope n -> Tope n -> Ordering
Tope n -> Tope n -> Tope n
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
forall (n :: S). Eq (Tope n)
forall (n :: S). Tope n -> Tope n -> Bool
forall (n :: S). Tope n -> Tope n -> Ordering
forall (n :: S). Tope n -> Tope n -> Tope n
$ccompare :: forall (n :: S). Tope n -> Tope n -> Ordering
compare :: Tope n -> Tope n -> Ordering
$c< :: forall (n :: S). Tope n -> Tope n -> Bool
< :: Tope n -> Tope n -> Bool
$c<= :: forall (n :: S). Tope n -> Tope n -> Bool
<= :: Tope n -> Tope n -> Bool
$c> :: forall (n :: S). Tope n -> Tope n -> Bool
> :: Tope n -> Tope n -> Bool
$c>= :: forall (n :: S). Tope n -> Tope n -> Bool
>= :: Tope n -> Tope n -> Bool
$cmax :: forall (n :: S). Tope n -> Tope n -> Tope n
max :: Tope n -> Tope n -> Tope n
$cmin :: forall (n :: S). Tope n -> Tope n -> Tope n
min :: Tope n -> Tope n -> Tope n
Ord, Int -> Tope n -> ShowS
[Tope n] -> ShowS
Tope n -> String
(Int -> Tope n -> ShowS)
-> (Tope n -> String) -> ([Tope n] -> ShowS) -> Show (Tope n)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (n :: S). Int -> Tope n -> ShowS
forall (n :: S). [Tope n] -> ShowS
forall (n :: S). Tope n -> String
$cshowsPrec :: forall (n :: S). Int -> Tope n -> ShowS
showsPrec :: Int -> Tope n -> ShowS
$cshow :: forall (n :: S). Tope n -> String
show :: Tope n -> String
$cshowList :: forall (n :: S). [Tope n] -> ShowS
showList :: [Tope n] -> ShowS
Show)
cubeOf :: Point n -> Cube
cubeOf :: forall (n :: S). Point n -> Cube
cubeOf = \case
PVar Name n
_ Cube
c -> Cube
c
Point n
PStar -> Cube
KUnit
Point n
P2_0 -> Cube
K2
Point n
P2_1 -> Cube
K2
Point n
PI_0 -> Cube
KI
Point n
PI_1 -> Cube
KI
PPair Point n
l Point n
r -> Cube -> Cube -> Cube
KProd (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l) (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r)
PFst Point n
p -> case Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
p of { KProd Cube
a Cube
_ -> Cube
a; Cube
_ -> Cube
KOther }
PSnd Point n
p -> case Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
p of { KProd Cube
_ Cube
b -> Cube
b; Cube
_ -> Cube
KOther }
PSup Point n
l Point n
r -> Cube -> Cube -> Cube
interval (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l) (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r)
PInf Point n
l Point n
r -> Cube -> Cube -> Cube
interval (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l) (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r)
PFlip Point n
_ -> Cube
KOther
PUnflip Point n
_ -> Cube
KOther
PModApp{} -> Cube
KOther
PModExtract{} -> Cube
KOther
PApp Cube
c Point n
_ Point n
_ -> Cube
c
PHole Maybe VarIdent
_ -> Cube
KOther
POpaque String
_ -> Cube
KOther
where
interval :: Cube -> Cube -> Cube
interval Cube
K2 Cube
K2 = Cube
K2
interval Cube
KI Cube
KI = Cube
KI
interval Cube
KI Cube
K2 = Cube
KI
interval Cube
K2 Cube
KI = Cube
KI
interval Cube
_ Cube
_ = Cube
KOther
pointFirst :: Point n -> Point n
pointFirst :: forall (n :: S). Point n -> Point n
pointFirst (PPair Point n
a Point n
_) = Point n
a
pointFirst Point n
p = Point n -> Point n
forall (n :: S). Point n -> Point n
PFst Point n
p
pointSecond :: Point n -> Point n
pointSecond :: forall (n :: S). Point n -> Point n
pointSecond (PPair Point n
_ Point n
b) = Point n
b
pointSecond Point n
p = Point n -> Point n
forall (n :: S). Point n -> Point n
PSnd Point n
p
topeAnd :: Tope n -> Tope n -> Tope n
topeAnd :: forall (n :: S). Tope n -> Tope n -> Tope n
topeAnd Tope n
TBot Tope n
_ = Tope n
forall (n :: S). Tope n
TBot
topeAnd Tope n
_ Tope n
TBot = Tope n
forall (n :: S). Tope n
TBot
topeAnd Tope n
TTop Tope n
r = Tope n
r
topeAnd Tope n
l Tope n
TTop = Tope n
l
topeAnd Tope n
l Tope n
r = Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd Tope n
l Tope n
r
topeOr :: Tope n -> Tope n -> Tope n
topeOr :: forall (n :: S). Tope n -> Tope n -> Tope n
topeOr Tope n
TBot Tope n
r = Tope n
r
topeOr Tope n
l Tope n
TBot = Tope n
l
topeOr Tope n
l Tope n
r = Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TOr Tope n
l Tope n
r
isLatticePoint :: Point n -> Bool
isLatticePoint :: forall (n :: S). Point n -> Bool
isLatticePoint PSup{} = Bool
True
isLatticePoint PInf{} = Bool
True
isLatticePoint Point n
_ = Bool
False
data ModalTope n = ModalTope
{ forall (n :: S). ModalTope n -> TModality
tModAccum :: TModality
, forall (n :: S). ModalTope n -> TModality
tModVar :: TModality
, forall (n :: S). ModalTope n -> Tope n
tTope :: Tope n
} deriving (ModalTope n -> ModalTope n -> Bool
(ModalTope n -> ModalTope n -> Bool)
-> (ModalTope n -> ModalTope n -> Bool) -> Eq (ModalTope n)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (n :: S). ModalTope n -> ModalTope n -> Bool
$c== :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
== :: ModalTope n -> ModalTope n -> Bool
$c/= :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
/= :: ModalTope n -> ModalTope n -> Bool
Eq, Eq (ModalTope n)
Eq (ModalTope n) =>
(ModalTope n -> ModalTope n -> Ordering)
-> (ModalTope n -> ModalTope n -> Bool)
-> (ModalTope n -> ModalTope n -> Bool)
-> (ModalTope n -> ModalTope n -> Bool)
-> (ModalTope n -> ModalTope n -> Bool)
-> (ModalTope n -> ModalTope n -> ModalTope n)
-> (ModalTope n -> ModalTope n -> ModalTope n)
-> Ord (ModalTope n)
ModalTope n -> ModalTope n -> Bool
ModalTope n -> ModalTope n -> Ordering
ModalTope n -> ModalTope n -> ModalTope n
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
forall (n :: S). Eq (ModalTope n)
forall (n :: S). ModalTope n -> ModalTope n -> Bool
forall (n :: S). ModalTope n -> ModalTope n -> Ordering
forall (n :: S). ModalTope n -> ModalTope n -> ModalTope n
$ccompare :: forall (n :: S). ModalTope n -> ModalTope n -> Ordering
compare :: ModalTope n -> ModalTope n -> Ordering
$c< :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
< :: ModalTope n -> ModalTope n -> Bool
$c<= :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
<= :: ModalTope n -> ModalTope n -> Bool
$c> :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
> :: ModalTope n -> ModalTope n -> Bool
$c>= :: forall (n :: S). ModalTope n -> ModalTope n -> Bool
>= :: ModalTope n -> ModalTope n -> Bool
$cmax :: forall (n :: S). ModalTope n -> ModalTope n -> ModalTope n
max :: ModalTope n -> ModalTope n -> ModalTope n
$cmin :: forall (n :: S). ModalTope n -> ModalTope n -> ModalTope n
min :: ModalTope n -> ModalTope n -> ModalTope n
Ord, Int -> ModalTope n -> ShowS
[ModalTope n] -> ShowS
ModalTope n -> String
(Int -> ModalTope n -> ShowS)
-> (ModalTope n -> String)
-> ([ModalTope n] -> ShowS)
-> Show (ModalTope n)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (n :: S). Int -> ModalTope n -> ShowS
forall (n :: S). [ModalTope n] -> ShowS
forall (n :: S). ModalTope n -> String
$cshowsPrec :: forall (n :: S). Int -> ModalTope n -> ShowS
showsPrec :: Int -> ModalTope n -> ShowS
$cshow :: forall (n :: S). ModalTope n -> String
show :: ModalTope n -> String
$cshowList :: forall (n :: S). [ModalTope n] -> ShowS
showList :: [ModalTope n] -> ShowS
Show)
plainTope :: Tope n -> ModalTope n
plainTope :: forall (n :: S). Tope n -> ModalTope n
plainTope = TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
Id TModality
Id
isAccessible :: ModalTope n -> Bool
isAccessible :: forall (n :: S). ModalTope n -> Bool
isAccessible ModalTope n
mt = TModality -> TModality -> Bool
coe (ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModVar ModalTope n
mt) (ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModAccum ModalTope n
mt)
filterAccessible :: [ModalTope n] -> [ModalTope n]
filterAccessible :: forall (n :: S). [ModalTope n] -> [ModalTope n]
filterAccessible = (ModalTope n -> Bool) -> [ModalTope n] -> [ModalTope n]
forall a. (a -> Bool) -> [a] -> [a]
filter ModalTope n -> Bool
forall (n :: S). ModalTope n -> Bool
isAccessible
partitionAccessible :: [ModalTope n] -> ([ModalTope n], [ModalTope n])
partitionAccessible :: forall (n :: S). [ModalTope n] -> ([ModalTope n], [ModalTope n])
partitionAccessible [ModalTope n]
topes = ((ModalTope n -> Bool) -> [ModalTope n] -> [ModalTope n]
forall a. (a -> Bool) -> [a] -> [a]
filter ModalTope n -> Bool
forall (n :: S). ModalTope n -> Bool
isAccessible [ModalTope n]
topes, (ModalTope n -> Bool) -> [ModalTope n] -> [ModalTope n]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ModalTope n -> Bool) -> ModalTope n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModalTope n -> Bool
forall (n :: S). ModalTope n -> Bool
isAccessible) [ModalTope n]
topes)
topesOf :: [ModalTope n] -> [Tope n]
topesOf :: forall (n :: S). [ModalTope n] -> [Tope n]
topesOf = (ModalTope n -> Tope n) -> [ModalTope n] -> [Tope n]
forall a b. (a -> b) -> [a] -> [b]
map ModalTope n -> Tope n
forall (n :: S). ModalTope n -> Tope n
tTope ([ModalTope n] -> [Tope n])
-> ([ModalTope n] -> [ModalTope n]) -> [ModalTope n] -> [Tope n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
filterAccessible
data TopeContext n = TopeContext
{ forall (n :: S). TopeContext n -> [ModalTope n]
tcTopes :: [ModalTope n]
, forall (n :: S). TopeContext n -> [ModalTope n]
tcDiscrete :: [ModalTope n]
, forall (n :: S). TopeContext n -> [[ModalTope n]]
tcAlternatives :: [[ModalTope n]]
, forall (n :: S). TopeContext n -> Bool
tcEntailsBottom :: Bool
, forall (n :: S). TopeContext n -> [[ModalTope n]]
tcSaturated :: [[ModalTope n]]
}
emptyTopeContext :: TopeContext n
emptyTopeContext :: forall (n :: S). TopeContext n
emptyTopeContext = TopeContext n -> TopeContext n
forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext
{ tcTopes :: [ModalTope n]
tcTopes =
[ TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
Id TModality
Id Tope n
forall (n :: S). Tope n
TTop
, TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
Id TModality
Flat Tope n
forall (n :: S). Tope n
TTop
, TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
Id TModality
Op Tope n
forall (n :: S). Tope n
TTop
, TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
Id TModality
Sharp Tope n
forall (n :: S). Tope n
TTop ]
, tcDiscrete :: [ModalTope n]
tcDiscrete = []
, tcAlternatives :: [[ModalTope n]]
tcAlternatives = []
, tcEntailsBottom :: Bool
tcEntailsBottom = Bool
False
, tcSaturated :: [[ModalTope n]]
tcSaturated = []
}
refresh :: TopeContext n -> TopeContext n
refresh :: forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext n
tc = TopeContext n
tc
{ tcAlternatives = alternativesOf (tcTopes tc)
, tcEntailsBottom = entailsFrom tc (tcTopes tc) TBot
, tcSaturated = saturateForEntailment (tcDiscrete tc) (tcTopes tc)
}
where
alternativesOf :: [ModalTope n] -> [[ModalTope n]]
alternativesOf [ModalTope n]
topes = ([ModalTope n] -> [ModalTope n])
-> [[ModalTope n]] -> [[ModalTope n]]
forall a b. (a -> b) -> [a] -> [b]
map [ModalTope n] -> [ModalTope n]
forall a. Eq a => [a] -> [a]
nub ([ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions [ModalTope n]
topes)
contextTopes :: TopeContext n -> [ModalTope n]
contextTopes :: forall (n :: S). TopeContext n -> [ModalTope n]
contextTopes = TopeContext n -> [ModalTope n]
forall (n :: S). TopeContext n -> [ModalTope n]
tcTopes
accessibleTopes :: TopeContext n -> [Tope n]
accessibleTopes :: forall (n :: S). TopeContext n -> [Tope n]
accessibleTopes = [ModalTope n] -> [Tope n]
forall (n :: S). [ModalTope n] -> [Tope n]
topesOf ([ModalTope n] -> [Tope n])
-> (TopeContext n -> [ModalTope n]) -> TopeContext n -> [Tope n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TopeContext n -> [ModalTope n]
forall (n :: S). TopeContext n -> [ModalTope n]
tcTopes
assume :: Tope n -> TopeContext n -> TopeContext n
assume :: forall (n :: S). Tope n -> TopeContext n -> TopeContext n
assume Tope n
tope TopeContext n
tc
| Bool
noNewInformation = TopeContext n
tc
| Bool
otherwise = TopeContext n -> TopeContext n
forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext n
tc { tcTopes = mt : tcTopes tc }
where
mt :: ModalTope n
mt = Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope Tope n
tope
noNewInformation :: Bool
noNewInformation = case Tope n
tope of
Tope n
TTop -> Bool
True
TEq Point n
x Point n
y | Point n
x Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y -> Bool
True
Tope n
_ -> ModalTope n
mt ModalTope n -> [ModalTope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` TopeContext n -> [ModalTope n]
forall (n :: S). TopeContext n -> [ModalTope n]
tcTopes TopeContext n
tc
assumeDiscrete :: Tope n -> TopeContext n -> TopeContext n
assumeDiscrete :: forall (n :: S). Tope n -> TopeContext n -> TopeContext n
assumeDiscrete Tope n
tope TopeContext n
tc = TopeContext n -> TopeContext n
forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext n
tc { tcDiscrete = plainTope tope : tcDiscrete tc }
applyModality :: TModality -> TopeContext n -> TopeContext n
applyModality :: forall (n :: S). TModality -> TopeContext n -> TopeContext n
applyModality TModality
Id TopeContext n
tc = TopeContext n
tc
applyModality TModality
md TopeContext n
tc = TopeContext n -> TopeContext n
forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext n
tc
{ tcTopes = map lock (tcTopes tc)
, tcDiscrete = map lock (tcDiscrete tc)
}
where
lock :: ModalTope n -> ModalTope n
lock ModalTope n
mt = ModalTope n
mt { tModAccum = comp (tModAccum mt) md }
entails :: TopeContext n -> Tope n -> Bool
entails :: forall (n :: S). TopeContext n -> Tope n -> Bool
entails TopeContext n
tc Tope n
goal = ([ModalTope n] -> Bool) -> [[ModalTope n]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ([ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
`solveRHS` Tope n
goal) (TopeContext n -> [[ModalTope n]]
forall (n :: S). TopeContext n -> [[ModalTope n]]
tcSaturated TopeContext n
tc)
entailsBottom :: TopeContext n -> Bool
entailsBottom :: forall (n :: S). TopeContext n -> Bool
entailsBottom = TopeContext n -> Bool
forall (n :: S). TopeContext n -> Bool
tcEntailsBottom
entailsUnion :: TopeContext n -> [Tope n] -> Bool
entailsUnion :: forall (n :: S). TopeContext n -> [Tope n] -> Bool
entailsUnion TopeContext n
tc [Tope n]
topes = TopeContext n -> Tope n -> Bool
forall (n :: S). TopeContext n -> Tope n -> Bool
entails TopeContext n
tc ((Tope n -> Tope n -> Tope n) -> Tope n -> [Tope n] -> Tope n
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
topeOr Tope n
forall (n :: S). Tope n
TBot [Tope n]
topes)
entailedBy :: TopeContext n -> Tope n -> Bool
entailedBy :: forall (n :: S). TopeContext n -> Tope n -> Bool
entailedBy TopeContext n
tc Tope n
tope = TopeContext n -> [ModalTope n] -> Tope n -> Bool
forall (n :: S). TopeContext n -> [ModalTope n] -> Tope n -> Bool
entailsFrom TopeContext n
tc [Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope Tope n
tope] ((Tope n -> Tope n -> Tope n) -> Tope n -> [Tope n] -> Tope n
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
topeAnd Tope n
forall (n :: S). Tope n
TTop (TopeContext n -> [Tope n]
forall (n :: S). TopeContext n -> [Tope n]
accessibleTopes TopeContext n
tc))
disjoint :: TopeContext n -> Tope n -> Bool
disjoint :: forall (n :: S). TopeContext n -> Tope n -> Bool
disjoint TopeContext n
tc Tope n
tope = TopeContext n -> [ModalTope n] -> Tope n -> Bool
forall (n :: S). TopeContext n -> [ModalTope n] -> Tope n -> Bool
entailsFrom TopeContext n
tc (Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope Tope n
tope ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: TopeContext n -> [ModalTope n]
forall (n :: S). TopeContext n -> [ModalTope n]
tcTopes TopeContext n
tc) Tope n
forall (n :: S). Tope n
TBot
equivalent :: TopeContext n -> Tope n -> Tope n -> Bool
equivalent :: forall (n :: S). TopeContext n -> Tope n -> Tope n -> Bool
equivalent TopeContext n
tc Tope n
l Tope n
r = Tope n
l Tope n -> Tope n -> Bool
forall a. Eq a => a -> a -> Bool
== Tope n
r Bool -> Bool -> Bool
|| (TopeContext n -> [Tope n] -> Tope n -> Bool
forall (n :: S). TopeContext n -> [Tope n] -> Tope n -> Bool
topesEntail TopeContext n
tc [Tope n
l] Tope n
r Bool -> Bool -> Bool
&& TopeContext n -> [Tope n] -> Tope n -> Bool
forall (n :: S). TopeContext n -> [Tope n] -> Tope n -> Bool
topesEntail TopeContext n
tc [Tope n
r] Tope n
l)
topesEntail :: TopeContext n -> [Tope n] -> Tope n -> Bool
topesEntail :: forall (n :: S). TopeContext n -> [Tope n] -> Tope n -> Bool
topesEntail TopeContext n
tc [Tope n]
topes = TopeContext n -> [ModalTope n] -> Tope n -> Bool
forall (n :: S). TopeContext n -> [ModalTope n] -> Tope n -> Bool
entailsFrom TopeContext n
tc ((Tope n -> ModalTope n) -> [Tope n] -> [ModalTope n]
forall a b. (a -> b) -> [a] -> [b]
map Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope [Tope n]
topes)
alternatives :: TopeContext n -> [TopeContext n]
alternatives :: forall (n :: S). TopeContext n -> [TopeContext n]
alternatives TopeContext n
tc = case TopeContext n -> [[ModalTope n]]
forall (n :: S). TopeContext n -> [[ModalTope n]]
tcAlternatives TopeContext n
tc of
[[ModalTope n]
_] -> []
[[ModalTope n]]
alts -> [ TopeContext n -> TopeContext n
forall (n :: S). TopeContext n -> TopeContext n
refresh TopeContext n
tc { tcTopes = alt } | [ModalTope n]
alt <- [[ModalTope n]]
alts ]
inAlternatives :: TopeContext n -> (TopeContext n -> Bool) -> Bool
inAlternatives :: forall (n :: S). TopeContext n -> (TopeContext n -> Bool) -> Bool
inAlternatives TopeContext n
tc TopeContext n -> Bool
check = case TopeContext n -> [TopeContext n]
forall (n :: S). TopeContext n -> [TopeContext n]
alternatives TopeContext n
tc of
[] -> TopeContext n -> Bool
check TopeContext n
tc
[TopeContext n]
alts -> (TopeContext n -> Bool) -> [TopeContext n] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all TopeContext n -> Bool
check [TopeContext n]
alts
entailsFrom :: TopeContext n -> [ModalTope n] -> Tope n -> Bool
entailsFrom :: forall (n :: S). TopeContext n -> [ModalTope n] -> Tope n -> Bool
entailsFrom TopeContext n
tc [ModalTope n]
modalTopes Tope n
goal =
([ModalTope n] -> Bool) -> [[ModalTope n]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ([ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
`solveRHS` Tope n
goal) ([ModalTope n] -> [ModalTope n] -> [[ModalTope n]]
forall (n :: S). [ModalTope n] -> [ModalTope n] -> [[ModalTope n]]
saturateForEntailment (TopeContext n -> [ModalTope n]
forall (n :: S). TopeContext n -> [ModalTope n]
tcDiscrete TopeContext n
tc) [ModalTope n]
modalTopes)
saturateForEntailment :: [ModalTope n] -> [ModalTope n] -> [[ModalTope n]]
saturateForEntailment :: forall (n :: S). [ModalTope n] -> [ModalTope n] -> [[ModalTope n]]
saturateForEntailment [ModalTope n]
discrete [ModalTope n]
modalTopes =
([ModalTope n] -> [ModalTope n])
-> [[ModalTope n]] -> [[ModalTope n]]
forall a b. (a -> b) -> [a] -> [b]
map ([ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateTopes ([ModalTope n] -> [ModalTope n])
-> ([ModalTope n] -> [ModalTope n])
-> [ModalTope n]
-> [ModalTope n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateBottom ([ModalTope n] -> [ModalTope n])
-> ([ModalTope n] -> [ModalTope n])
-> [ModalTope n]
-> [ModalTope n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateInv) [[ModalTope n]]
alts
where
alts :: [[ModalTope n]]
alts = [ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions ([ModalTope n] -> [ModalTope n]
forall a. Eq a => [a] -> [a]
nub ([ModalTope n]
modalTopes [ModalTope n] -> [ModalTope n] -> [ModalTope n]
forall a. Semigroup a => a -> a -> a
<> [ModalTope n]
discrete))
saturateTopes :: [ModalTope n] -> [ModalTope n]
saturateTopes :: forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateTopes [ModalTope n]
topes = [ModalTope n]
saturated [ModalTope n] -> [ModalTope n] -> [ModalTope n]
forall a. Semigroup a => a -> a -> a
<> [ModalTope n]
inaccessible
where
([ModalTope n]
accessible, [ModalTope n]
inaccessible) = [ModalTope n] -> ([ModalTope n], [ModalTope n])
forall (n :: S). [ModalTope n] -> ([ModalTope n], [ModalTope n])
partitionAccessible [ModalTope n]
topes
saturated :: [ModalTope n]
saturated = ([ModalTope n] -> [ModalTope n] -> [ModalTope n])
-> [ModalTope n] -> [ModalTope n]
forall a. Ord a => ([a] -> [a] -> [a]) -> [a] -> [a]
saturateWith
(\[ModalTope n]
new [ModalTope n]
old -> (Tope n -> ModalTope n) -> [Tope n] -> [ModalTope n]
forall a b. (a -> b) -> [a] -> [b]
map Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope ([Tope n] -> [Tope n] -> [Tope n]
forall (n :: S). [Tope n] -> [Tope n] -> [Tope n]
generateTopes ((ModalTope n -> Tope n) -> [ModalTope n] -> [Tope n]
forall a b. (a -> b) -> [a] -> [b]
map ModalTope n -> Tope n
forall (n :: S). ModalTope n -> Tope n
tTope [ModalTope n]
new) ((ModalTope n -> Tope n) -> [ModalTope n] -> [Tope n]
forall a b. (a -> b) -> [a] -> [b]
map ModalTope n -> Tope n
forall (n :: S). ModalTope n -> Tope n
tTope [ModalTope n]
old)))
[ModalTope n]
accessible
saturateInv :: [ModalTope n] -> [ModalTope n]
saturateInv :: forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateInv = [ModalTope n] -> [ModalTope n]
forall a. a -> a
id
saturateBottom :: [ModalTope n] -> [ModalTope n]
saturateBottom :: forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateBottom [ModalTope n]
modalTopes
| [TModality] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TModality]
droppedAccums = [ModalTope n]
modalTopes
| Bool
botDerivable = [ModalTope n]
modalTopes [ModalTope n] -> [ModalTope n] -> [ModalTope n]
forall a. Semigroup a => a -> a -> a
<> [ModalTope n]
forall {n :: S}. [ModalTope n]
fresh
| Bool
otherwise = [ModalTope n]
modalTopes
where
idAccessible :: [ModalTope n]
idAccessible = (ModalTope n -> Bool) -> [ModalTope n] -> [ModalTope n]
forall a. (a -> Bool) -> [a] -> [a]
filter (\ModalTope n
mt -> TModality -> TModality -> Bool
coe (ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModVar ModalTope n
mt) TModality
Id) [ModalTope n]
modalTopes
droppedAccums :: [TModality]
droppedAccums = [TModality] -> [TModality]
forall a. Eq a => [a] -> [a]
nub [ ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModAccum ModalTope n
mt | ModalTope n
mt <- [ModalTope n]
idAccessible, Bool -> Bool
not (ModalTope n -> Bool
forall (n :: S). ModalTope n -> Bool
isAccessible ModalTope n
mt) ]
saturatedId :: [Tope n]
saturatedId = ([Tope n] -> [Tope n] -> [Tope n]) -> [Tope n] -> [Tope n]
forall a. Ord a => ([a] -> [a] -> [a]) -> [a] -> [a]
saturateWith [Tope n] -> [Tope n] -> [Tope n]
forall (n :: S). [Tope n] -> [Tope n] -> [Tope n]
generateTopes ((ModalTope n -> Tope n) -> [ModalTope n] -> [Tope n]
forall a b. (a -> b) -> [a] -> [b]
map ModalTope n -> Tope n
forall (n :: S). ModalTope n -> Tope n
tTope [ModalTope n]
idAccessible)
botDerivable :: Bool
botDerivable = Tope n
forall (n :: S). Tope n
TBot Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
saturatedId
fresh :: [ModalTope n]
fresh = [ ModalTope n
forall {n :: S}. ModalTope n
mt
| TModality
acc <- [TModality]
droppedAccums
, let mt :: ModalTope n
mt = TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
acc TModality
acc Tope n
forall (n :: S). Tope n
TBot
, ModalTope n
forall {n :: S}. ModalTope n
mt ModalTope n -> [ModalTope n] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [ModalTope n]
modalTopes ]
saturateWith :: Ord a => ([a] -> [a] -> [a]) -> [a] -> [a]
saturateWith :: forall a. Ord a => ([a] -> [a] -> [a]) -> [a] -> [a]
saturateWith [a] -> [a] -> [a]
step [a]
zs = [a] -> [a] -> Set a -> [a]
go ([a] -> [a]
nubOrd [a]
zs) [] ([a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList [a]
zs)
where
go :: [a] -> [a] -> Set a -> [a]
go [a]
lastNew [a]
xs Set a
seen
| [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
new = [a]
lastNew
| Bool
otherwise = [a]
lastNew [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> [a] -> [a] -> Set a -> [a]
go [a]
new [a]
xs' Set a
seen'
where
xs' :: [a]
xs' = [a]
lastNew [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> [a]
xs
new :: [a]
new = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (a -> Set a -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.notMember` Set a
seen) ([a] -> [a]
nubOrd ([a] -> [a] -> [a]
step [a]
lastNew [a]
xs))
seen' :: Set a
seen' = (a -> Set a -> Set a) -> Set a -> [a] -> Set a
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> Set a -> Set a
forall a. Ord a => a -> Set a -> Set a
Set.insert Set a
seen [a]
new
nubOrd :: [a] -> [a]
nubOrd = Set a -> [a]
forall a. Set a -> [a]
Set.toList (Set a -> [a]) -> ([a] -> Set a) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList
generateTopes :: [Tope n] -> [Tope n] -> [Tope n]
generateTopes :: forall (n :: S). [Tope n] -> [Tope n] -> [Tope n]
generateTopes [Tope n]
newTopes [Tope n]
oldTopes
| Tope n
forall (n :: S). Tope n
TBot Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
newTopes = []
| Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
forall (n :: S). Point n
P2_0 Point n
forall (n :: S). Point n
P2_1 Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
newTopes = [Tope n
forall (n :: S). Tope n
TBot]
| Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
forall (n :: S). Point n
PI_0 Point n
forall (n :: S). Point n
PI_1 Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
newTopes = [Tope n
forall (n :: S). Tope n
TBot]
| [Tope n] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tope n]
oldTopes Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
100 = []
| Bool
otherwise = [[Tope n]] -> [Tope n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[
[ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y Point n
x | TEq Point n
x Point n
y <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
z
| TEq Point n
x Point n
y : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TEq Point n
y' Point n
z <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
z
| TEq Point n
y Point n
z : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TEq Point n
x Point n
y' <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TLeq Point n
x Point n
y : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TLeq Point n
y' Point n
z <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TLeq Point n
y Point n
z : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TLeq Point n
x Point n
y' <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
y
| TLeq Point n
x Point n
y : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TLeq Point n
y' Point n
x' <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y'
, Point n
x Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
x' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TEq Point n
y Point n
z : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TLeq Point n
x Point n
y' <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TEq Point n
x Point n
y : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TLeq Point n
y' Point n
z <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TLeq Point n
y Point n
z : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TEq Point n
x Point n
y' <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
z
| TLeq Point n
x Point n
y : [Tope n]
newTopes' <- [Tope n] -> [[Tope n]]
forall a. [a] -> [[a]]
tails [Tope n]
newTopes
, TEq Point n
y' Point n
z <- [Tope n]
newTopes' [Tope n] -> [Tope n] -> [Tope n]
forall a. Semigroup a => a -> a -> a
<> [Tope n]
oldTopes
, Point n
y Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
y' ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
y | TLeq Point n
x y :: Point n
y@Point n
P2_0 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
y | TLeq x :: Point n
x@Point n
P2_1 Point n
y <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
y | TLeq Point n
x y :: Point n
y@Point n
PI_0 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
y | TLeq x :: Point n
x@Point n
PI_1 Point n
y <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
forall (n :: S). Point n
PI_0 | TEq Point n
x Point n
P2_0 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
forall (n :: S). Point n
PI_0 Point n
x | TEq Point n
P2_0 Point n
x <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
forall (n :: S). Point n
PI_1 | TEq Point n
x Point n
P2_1 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
forall (n :: S). Point n
PI_1 Point n
x | TEq Point n
P2_1 Point n
x <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
forall (n :: S). Point n
PI_0 | TLeq Point n
x Point n
P2_0 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
forall (n :: S). Point n
PI_0 Point n
x | TLeq Point n
P2_0 Point n
x <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
forall (n :: S). Point n
PI_1 | TLeq Point n
x Point n
P2_1 <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
forall (n :: S). Point n
PI_1 Point n
x | TLeq Point n
P2_1 Point n
x <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
a Point n
c | TLeq (PSup Point n
a Point n
_) Point n
c <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
b Point n
c | TLeq (PSup Point n
_ Point n
b) Point n
c <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
c Point n
a | TLeq Point n
c (PInf Point n
a Point n
_) <- [Tope n]
newTopes ]
, [ Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
c Point n
b | TLeq Point n
c (PInf Point n
_ Point n
b) <- [Tope n]
newTopes ]
, [ Tope n
leq
| TEq Point n
x Point n
y <- [Tope n]
newTopes
, Point n -> Bool
forall (n :: S). Point n -> Bool
isLatticePoint Point n
x Bool -> Bool -> Bool
|| Point n -> Bool
forall (n :: S). Point n -> Bool
isLatticePoint Point n
y
, Tope n
leq <- [Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
y, Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
y Point n
x] ]
]
generateTopesForPoints :: [Point n] -> [Tope n]
generateTopesForPoints :: forall (n :: S). [Point n] -> [Tope n]
generateTopesForPoints [Point n]
points = [[Tope n]] -> [Tope n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Tope n]]
topes [[Tope n]] -> [[Tope n]] -> [[Tope n]]
forall a. Semigroup a => a -> a -> a
<> [[Tope n]]
stars)
where
endpoints :: [Point n]
endpoints = [Point n
forall (n :: S). Point n
P2_0, Point n
forall (n :: S). Point n
P2_1, Point n
forall (n :: S). Point n
PI_0, Point n
forall (n :: S). Point n
PI_1]
pairs :: [(Point n, Point n)]
pairs = [(Point n, Point n)] -> [(Point n, Point n)]
forall a. Eq a => [a] -> [a]
nub
[ (Point n
x, Point n
y)
| Point n
x : [Point n]
points' <- [Point n] -> [[Point n]]
forall a. [a] -> [[a]]
tails ((Point n -> Bool) -> [Point n] -> [Point n]
forall a. (a -> Bool) -> [a] -> [a]
filter (Point n -> [Point n] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Point n]
forall {n :: S}. [Point n]
endpoints) [Point n]
points)
, Point n
y <- [Point n]
points'
, Point n
x Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
/= Point n
y ]
stars :: [[Tope n]]
stars = [ [Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
forall (n :: S). Point n
PStar] | Point n
x <- [Point n]
points, Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
x Cube -> Cube -> Bool
forall a. Eq a => a -> a -> Bool
== Cube
KUnit ]
topes :: [[Tope n]]
topes =
[ [Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TOr (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
x Point n
y) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
y Point n
x)]
| (Point n
x, Point n
y) <- [(Point n, Point n)]
pairs
, Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
x Cube -> Cube -> Bool
forall a. Eq a => a -> a -> Bool
== Cube
K2, Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
y Cube -> Cube -> Bool
forall a. Eq a => a -> a -> Bool
== Cube
K2 ]
allTopePoints :: Tope n -> [Point n]
allTopePoints :: forall (n :: S). Tope n -> [Point n]
allTopePoints = [Point n] -> [Point n]
forall a. Eq a => [a] -> [a]
nub ([Point n] -> [Point n])
-> (Tope n -> [Point n]) -> Tope n -> [Point n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Point n -> [Point n]) -> [Point n] -> [Point n]
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Point n -> [Point n]
forall (n :: S). Point n -> [Point n]
subPoints ([Point n] -> [Point n])
-> (Tope n -> [Point n]) -> Tope n -> [Point n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Point n] -> [Point n]
forall a. Eq a => [a] -> [a]
nub ([Point n] -> [Point n])
-> (Tope n -> [Point n]) -> Tope n -> [Point n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
topePoints
topePoints :: Tope n -> [Point n]
topePoints :: forall (n :: S). Tope n -> [Point n]
topePoints = \case
TAnd Tope n
l Tope n
r -> Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
topePoints Tope n
l [Point n] -> [Point n] -> [Point n]
forall a. Semigroup a => a -> a -> a
<> Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
topePoints Tope n
r
TOr Tope n
l Tope n
r -> Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
topePoints Tope n
l [Point n] -> [Point n] -> [Point n]
forall a. Semigroup a => a -> a -> a
<> Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
topePoints Tope n
r
TEq Point n
x Point n
y -> [Point n
x, Point n
y]
TLeq Point n
x Point n
y -> [Point n
x, Point n
y]
Tope n
_ -> []
subPoints :: Point n -> [Point n]
subPoints :: forall (n :: S). Point n -> [Point n]
subPoints = \case
p :: Point n
p@(PPair Point n
x Point n
y) -> Point n
p Point n -> [Point n] -> [Point n]
forall a. a -> [a] -> [a]
: (Point n -> [Point n]) -> [Point n] -> [Point n]
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Point n -> [Point n]
forall (n :: S). Point n -> [Point n]
subPoints [Point n
x, Point n
y]
p :: Point n
p@PVar{} -> [Point n
p]
Point n
p -> case Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
p of
Cube
KUnit -> [Point n
p]
Cube
K2 -> [Point n
p]
Cube
_ -> []
simplifyLHSwithDisjunctions :: [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions :: forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions [ModalTope n]
topes = ([ModalTope n] -> [ModalTope n])
-> [[ModalTope n]] -> [[ModalTope n]]
forall a b. (a -> b) -> [a] -> [b]
map [ModalTope n] -> [ModalTope n]
forall a. Eq a => [a] -> [a]
nub ([[ModalTope n]] -> [[ModalTope n]])
-> [[ModalTope n]] -> [[ModalTope n]]
forall a b. (a -> b) -> a -> b
$ case [ModalTope n]
topes of
[] -> [[]]
ModalTope TModality
_ TModality
_ Tope n
TTop : [ModalTope n]
topes' -> [ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions [ModalTope n]
topes'
ModalTope TModality
mAcc TModality
mVar Tope n
TBot : [ModalTope n]
_ -> [[TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar Tope n
forall (n :: S). Tope n
TBot]]
ModalTope TModality
mAcc TModality
mVar (TAnd Tope n
l Tope n
r) : [ModalTope n]
topes' ->
[ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions (TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar Tope n
l ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar Tope n
r ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
topes')
ModalTope TModality
mAcc TModality
mVar (TOr Tope n
l Tope n
r) : [ModalTope n]
topes' ->
[ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions (TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar Tope n
l ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
topes')
[[ModalTope n]] -> [[ModalTope n]] -> [[ModalTope n]]
forall a. Semigroup a => a -> a -> a
<> [ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions (TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar Tope n
r ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
topes')
ModalTope TModality
mAcc TModality
mVar (TEq (PPair Point n
x Point n
y) (PPair Point n
x' Point n
y')) : [ModalTope n]
topes' ->
[ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions
(TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
x') ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc TModality
mVar (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y Point n
y') ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
topes')
ModalTope TModality
mAcc TModality
mVar (TModal TModality
md Tope n
inTope) : [ModalTope n]
topes' ->
[ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions (TModality -> TModality -> Tope n -> ModalTope n
forall (n :: S). TModality -> TModality -> Tope n -> ModalTope n
ModalTope TModality
mAcc (TModality -> TModality -> TModality
comp TModality
mVar TModality
md) Tope n
inTope ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
topes')
ModalTope n
t : [ModalTope n]
topes' -> ([ModalTope n] -> [ModalTope n])
-> [[ModalTope n]] -> [[ModalTope n]]
forall a b. (a -> b) -> [a] -> [b]
map (ModalTope n
t ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
:) ([ModalTope n] -> [[ModalTope n]]
forall {n :: S}. [ModalTope n] -> [[ModalTope n]]
simplifyLHSwithDisjunctions [ModalTope n]
topes')
solveRHS :: [ModalTope n] -> Tope n -> Bool
solveRHS :: forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes Tope n
goal =
let topes :: [Tope n]
topes = [ModalTope n] -> [Tope n]
forall (n :: S). [ModalTope n] -> [Tope n]
topesOf [ModalTope n]
modalTopes
in case Tope n
goal of
Tope n
_ | Tope n
forall (n :: S). Tope n
TBot Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
Tope n
TTop -> Bool
True
TModal TModality
md Tope n
inTope ->
let shifted :: [ModalTope n]
shifted = (ModalTope n -> ModalTope n) -> [ModalTope n] -> [ModalTope n]
forall a b. (a -> b) -> [a] -> [b]
map (\ModalTope n
mt -> ModalTope n
mt { tModAccum = comp (tModAccum mt) md }) [ModalTope n]
modalTopes
in [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS ([ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateInv ([ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateTopes [ModalTope n]
shifted)) Tope n
inTope
TEq (PPair Point n
x Point n
y) (PPair Point n
x' Point n
y') ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
x') (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y Point n
y'))
TEq l :: Point n
l@(PPair Point n
x Point n
y) Point n
r | KProd Cube
_ Cube
_ <- Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x (Point n -> Point n
forall (n :: S). Point n -> Point n
pointFirst Point n
r)) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y (Point n -> Point n
forall (n :: S). Point n -> Point n
pointSecond Point n
r)))
TEq Point n
l r :: Point n
r@(PPair Point n
x Point n
y) | KProd Cube
_ Cube
_ <- Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq (Point n -> Point n
forall (n :: S). Point n -> Point n
pointFirst Point n
l) Point n
x) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq (Point n -> Point n
forall (n :: S). Point n -> Point n
pointSecond Point n
l) Point n
y))
TEq Point n
P2_0 Point n
PI_0 -> Bool
True
TEq Point n
PI_0 Point n
P2_0 -> Bool
True
TEq Point n
P2_1 Point n
PI_1 -> Bool
True
TEq Point n
PI_1 Point n
P2_1 -> Bool
True
TEq Point n
l Point n
r
| Point n
l Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
r -> Bool
True
| Tope n
goal Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
| Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
l Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
| Bool
otherwise -> case (Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l, Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r) of
(Cube
KUnit, Cube
KUnit) -> Bool
True
(Cube, Cube)
_ | Point n -> Bool
forall (n :: S). Point n -> Bool
isLatticePoint Point n
l Bool -> Bool -> Bool
|| Point n -> Bool
forall (n :: S). Point n -> Bool
isLatticePoint Point n
r ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
l Point n
r) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
r Point n
l))
(Cube, Cube)
_ -> Bool
False
TLeq Point n
l Point n
r
| Point n
l Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
r -> Bool
True
| Tope n
goal Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
r) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
forall (n :: S). Point n
P2_0) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
forall (n :: S). Point n
PI_0) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
forall (n :: S). Point n
P2_1) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
forall (n :: S). Point n
PI_1) -> Bool
True
TLeq (PSup Point n
a Point n
b) Point n
r ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
a Point n
r) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
b Point n
r))
TLeq Point n
l (PInf Point n
a Point n
b) ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TAnd (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
l Point n
a) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
l Point n
b))
TLeq Point n
l (PSup Point n
a Point n
b) ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TOr (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
l Point n
a) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
l Point n
b))
TLeq (PInf Point n
a Point n
b) Point n
r ->
[ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes (Tope n -> Tope n -> Tope n
forall (n :: S). Tope n -> Tope n -> Tope n
TOr (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
a Point n
r) (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TLeq Point n
b Point n
r))
TAnd Tope n
l Tope n
r -> [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes Tope n
l Bool -> Bool -> Bool
&& [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes Tope n
r
Tope n
_ | Tope n
goal Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
TInv{} -> Bool
False
TUninv{} -> Bool
False
TOr Tope n
l Tope n
r
| [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes Tope n
l Bool -> Bool -> Bool
|| [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS [ModalTope n]
modalTopes Tope n
r -> Bool
True
| Bool
otherwise ->
let lems :: [Tope n]
lems = [ Tope n
lem | lem :: Tope n
lem@(TOr Tope n
t1 Tope n
t2) <- [Point n] -> [Tope n]
forall (n :: S). [Point n] -> [Tope n]
generateTopesForPoints (Tope n -> [Point n]
forall (n :: S). Tope n -> [Point n]
allTopePoints Tope n
goal)
, (Tope n -> Bool) -> [Tope n] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Tope n -> [Tope n] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Tope n]
topes) [Tope n
t1, Tope n
t2] ]
([ModalTope n]
accessible, [ModalTope n]
hidden) = [ModalTope n] -> ([ModalTope n], [ModalTope n])
forall (n :: S). [ModalTope n] -> ([ModalTope n], [ModalTope n])
partitionAccessible [ModalTope n]
modalTopes
withTope :: Tope n -> [ModalTope n]
withTope Tope n
t = [ModalTope n]
hidden [ModalTope n] -> [ModalTope n] -> [ModalTope n]
forall a. [a] -> [a] -> [a]
++ [ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
saturateTopes (Tope n -> ModalTope n
forall (n :: S). Tope n -> ModalTope n
plainTope Tope n
t ModalTope n -> [ModalTope n] -> [ModalTope n]
forall a. a -> [a] -> [a]
: [ModalTope n]
accessible)
in case [Tope n]
lems of
TOr Tope n
t1 Tope n
t2 : [Tope n]
_ -> [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS (Tope n -> [ModalTope n]
withTope Tope n
t1) Tope n
goal Bool -> Bool -> Bool
&& [ModalTope n] -> Tope n -> Bool
forall (n :: S). [ModalTope n] -> Tope n -> Bool
solveRHS (Tope n -> [ModalTope n]
withTope Tope n
t2) Tope n
goal
[Tope n]
_ -> Bool
False
Tope n
_ -> Bool
False
solveTopes :: [Tope n] -> Tope n -> Bool
solveTopes :: forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes Tope n
tope = case Tope n
tope of
Tope n
_ | Tope n
forall (n :: S). Tope n
TBot Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes -> Bool
True
Tope n
TTop -> Bool
True
TEq (PPair Point n
x Point n
y) (PPair Point n
x' Point n
y')
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x Point n
x') Bool -> Bool -> Bool
&& [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y Point n
y') -> Bool
True
TEq l :: Point n
l@(PPair Point n
x Point n
y) Point n
r
| KProd Cube
_ Cube
_ <- Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
l
, [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
x (Point n -> Point n
forall (n :: S). Point n -> Point n
pointFirst Point n
r))
, [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
y (Point n -> Point n
forall (n :: S). Point n -> Point n
pointSecond Point n
r)) -> Bool
True
TEq Point n
l r :: Point n
r@(PPair Point n
x Point n
y)
| KProd Cube
_ Cube
_ <- Point n -> Cube
forall (n :: S). Point n -> Cube
cubeOf Point n
r
, [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq (Point n -> Point n
forall (n :: S). Point n -> Point n
pointFirst Point n
l) Point n
x)
, [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq (Point n -> Point n
forall (n :: S). Point n -> Point n
pointSecond Point n
l) Point n
y) -> Bool
True
TEq Point n
P2_0 Point n
PI_0 -> Bool
True
TEq Point n
PI_0 Point n
P2_0 -> Bool
True
TEq Point n
P2_1 Point n
PI_1 -> Bool
True
TEq Point n
PI_1 Point n
P2_1 -> Bool
True
TEq Point n
l Point n
r -> [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or
[ Point n
l Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
r
, Tope n
tope Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes
, Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
l Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes ]
TLeq Point n
l Point n
r
| Point n
l Point n -> Point n -> Bool
forall a. Eq a => a -> a -> Bool
== Point n
r -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
r) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
forall (n :: S). Point n
P2_0) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
l Point n
forall (n :: S). Point n
PI_0) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
forall (n :: S). Point n
P2_1) -> Bool
True
| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes (Point n -> Point n -> Tope n
forall (n :: S). Point n -> Point n -> Tope n
TEq Point n
r Point n
forall (n :: S). Point n
PI_1) -> Bool
True
TAnd Tope n
l Tope n
r -> [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes Tope n
l Bool -> Bool -> Bool
&& [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes Tope n
r
TOr Tope n
l Tope n
r -> [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes Tope n
l Bool -> Bool -> Bool
|| [Tope n] -> Tope n -> Bool
forall (n :: S). [Tope n] -> Tope n -> Bool
solveTopes [Tope n]
topes Tope n
r
Tope n
_ -> Tope n
tope Tope n -> [Tope n] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Tope n]
topes