module Proofs.Freeness
( freeness
) where
import Logic.Logic
import Logic.Grothendieck
import Logic.Coerce
import Logic.Comorphism
import Logic.Prover (toNamedList, toThSens)
import Logic.ExtSign
import Static.ComputeTheory
import Static.GTheory
import Static.DevGraph
import Static.DgUtils
import Static.History
import Common.ExtSign
import Common.LibName
import Common.Result
import Data.Graph.Inductive.Graph as Graph
import qualified Data.Map as Map
import Control.Monad
import Data.List (nub)
import Data.Maybe (fromMaybe)
import Common.Lib.Graph
freenessRule :: DGRule
freenessRule :: DGRule
freenessRule = String -> DGRule
DGRule "Freeness"
freeness :: LibName -> LibEnv -> Result LibEnv
freeness :: LibName -> LibEnv -> Result LibEnv
freeness ln :: LibName
ln le :: LibEnv
le = do
let dg :: DGraph
dg = LibName -> LibEnv -> DGraph
lookupDGraph LibName
ln LibEnv
le
DGraph
newDg <- LibEnv -> LibName -> DGraph -> Result DGraph
freenessDG LibEnv
le LibName
ln DGraph
dg
LibEnv -> Result LibEnv
forall (m :: * -> *) a. Monad m => a -> m a
return (LibEnv -> Result LibEnv) -> LibEnv -> Result LibEnv
forall a b. (a -> b) -> a -> b
$ LibName -> DGraph -> LibEnv -> LibEnv
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert LibName
ln
(DGraph -> DGRule -> DGraph -> DGraph
groupHistory DGraph
dg DGRule
freenessRule DGraph
newDg) LibEnv
le
freenessDG :: LibEnv -> LibName -> DGraph -> Result DGraph
freenessDG :: LibEnv -> LibName -> DGraph -> Result DGraph
freenessDG le :: LibEnv
le ln :: LibName
ln dgraph :: DGraph
dgraph = (DGraph -> LEdge DGLinkLab -> Result DGraph)
-> DGraph -> [LEdge DGLinkLab] -> Result DGraph
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (LibEnv -> LibName -> DGraph -> LEdge DGLinkLab -> Result DGraph
handleEdge LibEnv
le LibName
ln) DGraph
dgraph ([LEdge DGLinkLab] -> Result DGraph)
-> [LEdge DGLinkLab] -> Result DGraph
forall a b. (a -> b) -> a -> b
$ DGraph -> [LEdge DGLinkLab]
labEdgesDG DGraph
dgraph
handleEdge :: LibEnv -> LibName -> DGraph -> LEdge DGLinkLab -> Result DGraph
handleEdge :: LibEnv -> LibName -> DGraph -> LEdge DGLinkLab -> Result DGraph
handleEdge libEnv :: LibEnv
libEnv ln :: LibName
ln dg :: DGraph
dg edge :: LEdge DGLinkLab
edge@(m :: Node
m, n :: Node
n, x :: DGLinkLab
x) =
case DGLinkLab -> DGLinkType
dgl_type DGLinkLab
x of
FreeOrCofreeDefLink _ _ -> do
let phi :: GMorphism
phi = DGLinkLab -> GMorphism
dgl_morphism DGLinkLab
x
mlab :: DGNodeLab
mlab = DGraph -> Node -> DGNodeLab
labDG DGraph
dg Node
m
gth :: G_theory
gth = G_theory -> Maybe G_theory -> G_theory
forall a. a -> Maybe a -> a
fromMaybe (DGNodeLab -> G_theory
dgn_theory (DGNodeLab -> G_theory) -> DGNodeLab -> G_theory
forall a b. (a -> b) -> a -> b
$ DGraph -> Node -> DGNodeLab
labDG DGraph
dg Node
m) (Maybe G_theory -> G_theory) -> Maybe G_theory -> G_theory
forall a b. (a -> b) -> a -> b
$ DGNodeLab -> Maybe G_theory
globalTheory DGNodeLab
mlab
case G_theory
gth of
G_theory lid :: lid
lid syn :: Maybe IRI
syn sig :: ExtSign sign symbol
sig _ sen :: ThSens sentence (AnyComorphism, BasicProof)
sen _ ->
case GMorphism
phi of
GMorphism cid :: cid
cid _ _ mor1 :: morphism2
mor1 _ -> do
morphism
mor <- lid2 -> lid -> String -> morphism2 -> Result morphism
forall lid1 sublogics1 basic_spec1 sentence1 symb_items1
symb_map_items1 sign1 morphism1 symbol1 raw_symbol1 proof_tree1
lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
sign2 morphism2 symbol2 raw_symbol2 proof_tree2 (m :: * -> *).
(Logic
lid1
sublogics1
basic_spec1
sentence1
symb_items1
symb_map_items1
sign1
morphism1
symbol1
raw_symbol1
proof_tree1,
Logic
lid2
sublogics2
basic_spec2
sentence2
symb_items2
symb_map_items2
sign2
morphism2
symbol2
raw_symbol2
proof_tree2,
MonadFail m) =>
lid1 -> lid2 -> String -> morphism1 -> m morphism2
coerceMorphism (cid -> lid2
forall cid lid1 sublogics1 basic_spec1 sentence1 symb_items1
symb_map_items1 sign1 morphism1 symbol1 raw_symbol1 proof_tree1
lid2 sublogics2 basic_spec2 sentence2 symb_items2 symb_map_items2
sign2 morphism2 symbol2 raw_symbol2 proof_tree2.
Comorphism
cid
lid1
sublogics1
basic_spec1
sentence1
symb_items1
symb_map_items1
sign1
morphism1
symbol1
raw_symbol1
proof_tree1
lid2
sublogics2
basic_spec2
sentence2
symb_items2
symb_map_items2
sign2
morphism2
symbol2
raw_symbol2
proof_tree2 =>
cid -> lid2
targetLogic cid
cid) lid
lid "free" morphism2
mor1
let res :: Result (sign, [Named sentence])
res = lid
-> morphism -> [Named sentence] -> Result (sign, [Named sentence])
forall lid basic_spec sentence symb_items symb_map_items sign
morphism symbol raw_symbol.
StaticAnalysis
lid
basic_spec
sentence
symb_items
symb_map_items
sign
morphism
symbol
raw_symbol =>
lid
-> morphism -> [Named sentence] -> Result (sign, [Named sentence])
quotient_term_algebra lid
lid morphism
mor ([Named sentence] -> Result (sign, [Named sentence]))
-> [Named sentence] -> Result (sign, [Named sentence])
forall a b. (a -> b) -> a -> b
$ ThSens sentence (AnyComorphism, BasicProof) -> [Named sentence]
forall a b. ThSens a b -> [Named a]
toNamedList ThSens sentence (AnyComorphism, BasicProof)
sen
case Result (sign, [Named sentence]) -> Maybe (sign, [Named sentence])
forall a. Result a -> Maybe a
maybeResult Result (sign, [Named sentence])
res of
Just (sigK :: sign
sigK, axK :: [Named sentence]
axK) -> do
let thK :: G_theory
thK = lid
-> Maybe IRI
-> ExtSign sign symbol
-> SigId
-> ThSens sentence (AnyComorphism, BasicProof)
-> ThId
-> G_theory
forall lid sublogics basic_spec sentence symb_items symb_map_items
sign morphism symbol raw_symbol proof_tree.
Logic
lid
sublogics
basic_spec
sentence
symb_items
symb_map_items
sign
morphism
symbol
raw_symbol
proof_tree =>
lid
-> Maybe IRI
-> ExtSign sign symbol
-> SigId
-> ThSens sentence (AnyComorphism, BasicProof)
-> ThId
-> G_theory
G_theory lid
lid Maybe IRI
syn (lid -> sign -> ExtSign sign symbol
forall lid sublogics basic_spec sentence symb_items symb_map_items
sign morphism symbol raw_symbol proof_tree.
Logic
lid
sublogics
basic_spec
sentence
symb_items
symb_map_items
sign
morphism
symbol
raw_symbol
proof_tree =>
lid -> sign -> ExtSign sign symbol
makeExtSign lid
lid sign
sigK)
SigId
startSigId ([Named sentence] -> ThSens sentence (AnyComorphism, BasicProof)
forall a b. Ord a => [Named a] -> ThSens a b
toThSens [Named sentence]
axK) ThId
startThId
morphism
incl <- lid -> sign -> sign -> Result morphism
forall lid basic_spec sentence symb_items symb_map_items sign
morphism symbol raw_symbol.
StaticAnalysis
lid
basic_spec
sentence
symb_items
symb_map_items
sign
morphism
symbol
raw_symbol =>
lid -> sign -> sign -> Result morphism
subsig_inclusion lid
lid (ExtSign sign symbol -> sign
forall sign symbol. ExtSign sign symbol -> sign
plainSign ExtSign sign symbol
sig) sign
sigK
let inclM :: GMorphism
inclM = G_morphism -> GMorphism
gEmbed (G_morphism -> GMorphism) -> G_morphism -> GMorphism
forall a b. (a -> b) -> a -> b
$ lid -> morphism -> G_morphism
forall lid sublogics basic_spec sentence symb_items symb_map_items
sign morphism symbol raw_symbol proof_tree.
Logic
lid
sublogics
basic_spec
sentence
symb_items
symb_map_items
sign
morphism
symbol
raw_symbol
proof_tree =>
lid -> morphism -> G_morphism
mkG_morphism lid
lid morphism
incl
nodelab :: DGNodeLab
nodelab = DGraph -> Node -> DGNodeLab
labDG DGraph
dg Node
m
info :: DGNodeInfo
info = DGNodeLab -> DGNodeInfo
nodeInfo DGNodeLab
nodelab
ConsStatus c :: Conservativity
c _ _ = DGNodeInfo -> ConsStatus
node_cons_status DGNodeInfo
info
k :: Node
k = DGraph -> Node
getNewNodeDG DGraph
dg
labelK :: DGNodeLab
labelK = NodeName -> DGNodeInfo -> G_theory -> DGNodeLab
newInfoNodeLab
(String -> NodeName -> NodeName
extName "Freeness" (NodeName -> NodeName) -> NodeName -> NodeName
forall a b. (a -> b) -> a -> b
$ DGNodeLab -> NodeName
dgn_name DGNodeLab
nodelab)
DGNodeInfo
info
{ node_origin :: DGOrigin
node_origin = Node -> DGOrigin
DGNormalForm Node
m
, node_cons_status :: ConsStatus
node_cons_status = Conservativity -> ConsStatus
mkConsStatus Conservativity
c }
G_theory
thK
insK :: DGChange
insK = LNode DGNodeLab -> DGChange
InsertNode (Node
k, DGNodeLab
labelK)
insE :: [DGChange]
insE = [ LEdge DGLinkLab -> DGChange
InsertEdge (Node
m, Node
k, GMorphism -> DGLinkOrigin -> DGLinkLab
globDefLink GMorphism
inclM DGLinkOrigin
DGLinkProof)
, LEdge DGLinkLab -> DGChange
InsertEdge (Node
k, Node
n, GMorphism -> DGLinkType -> DGLinkOrigin -> DGLinkLab
defDGLink GMorphism
inclM DGLinkType
HidingDefLink
DGLinkOrigin
DGLinkProof)]
del :: DGChange
del = LEdge DGLinkLab -> DGChange
DeleteEdge LEdge DGLinkLab
edge
allChanges :: [DGChange]
allChanges = DGChange
del DGChange -> [DGChange] -> [DGChange]
forall a. a -> [a] -> [a]
: DGChange
insK DGChange -> [DGChange] -> [DGChange]
forall a. a -> [a] -> [a]
: [DGChange]
insE
newDG :: DGraph
newDG = DGraph -> [DGChange] -> DGraph
changesDGH DGraph
dg [DGChange]
allChanges
labelN :: DGNodeLab
labelN = DGraph -> Node -> DGNodeLab
labDG DGraph
dg Node
n
succs :: [LNode DGNodeLab]
succs = (Node -> LNode DGNodeLab) -> [Node] -> [LNode DGNodeLab]
forall a b. (a -> b) -> [a] -> [b]
map (\ y :: Node
y -> (Node
y, DGraph -> Node -> DGNodeLab
labDG DGraph
dg Node
y)) ([Node] -> [LNode DGNodeLab]) -> [Node] -> [LNode DGNodeLab]
forall a b. (a -> b) -> a -> b
$ Gr DGNodeLab DGLinkLab -> Node -> [Node]
forall a b. Gr a b -> Node -> [Node]
descs (DGraph -> Gr DGNodeLab DGLinkLab
dgBody DGraph
dg) Node
n
labCh :: [DGChange]
labCh = [DGNodeLab -> LNode DGNodeLab -> DGChange
SetNodeLab DGNodeLab
labelK (Node
k, DGNodeLab
labelK
{ globalTheory :: Maybe G_theory
globalTheory = LibEnv -> LibName -> DGraph -> LNode DGNodeLab -> Maybe G_theory
computeLabelTheory LibEnv
libEnv LibName
ln DGraph
newDG
(Node
k, DGNodeLab
labelK) }),
DGNodeLab -> LNode DGNodeLab -> DGChange
SetNodeLab DGNodeLab
labelN (Node
n, DGNodeLab
labelN
{ globalTheory :: Maybe G_theory
globalTheory = LibEnv -> LibName -> DGraph -> LNode DGNodeLab -> Maybe G_theory
computeLabelTheory LibEnv
libEnv LibName
ln DGraph
newDG
(Node
n, DGNodeLab
labelN)
, labelHasHiding :: Bool
labelHasHiding = Bool
True })
] [DGChange] -> [DGChange] -> [DGChange]
forall a. [a] -> [a] -> [a]
++
(LNode DGNodeLab -> DGChange) -> [LNode DGNodeLab] -> [DGChange]
forall a b. (a -> b) -> [a] -> [b]
map (\ (y :: Node
y, ly :: DGNodeLab
ly) -> DGNodeLab -> LNode DGNodeLab -> DGChange
SetNodeLab DGNodeLab
ly
(Node
y, DGNodeLab
ly {labelHasHiding :: Bool
labelHasHiding = Bool
True})) [LNode DGNodeLab]
succs
DGraph -> Result DGraph
forall (m :: * -> *) a. Monad m => a -> m a
return (DGraph -> Result DGraph) -> DGraph -> Result DGraph
forall a b. (a -> b) -> a -> b
$ DGraph -> [DGChange] -> DGraph
changesDGH DGraph
newDG [DGChange]
labCh
_ -> DGraph -> Result DGraph
forall (m :: * -> *) a. Monad m => a -> m a
return DGraph
dg
_ -> DGraph -> Result DGraph
forall (m :: * -> *) a. Monad m => a -> m a
return DGraph
dg
descs :: Gr a b -> Node -> [Node]
descs :: Gr a b -> Node -> [Node]
descs graph :: Gr a b
graph node :: Node
node = let
d :: [Node] -> [Node] -> [Node]
d nList :: [Node]
nList descList :: [Node]
descList =
case [Node]
nList of
[] -> [Node]
descList
_ -> let
newDescs :: [Node]
newDescs = (Node -> [Node]) -> [Node] -> [Node]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Gr a b -> Node -> [Node]
forall (gr :: * -> * -> *) a b.
Graph gr =>
gr a b -> Node -> [Node]
suc Gr a b
graph) [Node]
nList
nList' :: [Node]
nList' = (Node -> Bool) -> [Node] -> [Node]
forall a. (a -> Bool) -> [a] -> [a]
filter (\ x :: Node
x -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (Node
x Node -> [Node] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Node]
nList) Bool -> Bool -> Bool
||
(Node
x Node -> [Node] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Node]
descList))
[Node]
newDescs
descList' :: [Node]
descList' = [Node] -> [Node]
forall a. Eq a => [a] -> [a]
nub ([Node] -> [Node]) -> [Node] -> [Node]
forall a b. (a -> b) -> a -> b
$ [Node]
descList [Node] -> [Node] -> [Node]
forall a. [a] -> [a] -> [a]
++ [Node]
newDescs
in [Node] -> [Node] -> [Node]
d [Node]
nList' [Node]
descList'
in [Node] -> [Node] -> [Node]
d [Node
node] []