ProveCommands.hs revision 243447e8fc4475937609f5e8397058cb92f6cbb4
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovaModule :$Header$
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovaDescription : CMDL interface commands
097b7fb3f8f90e87120d30bf37a1d89fe0ddfaf0Kristina SojakovaCopyright : uni-bremen and DFKI
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaLicence : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaMaintainer : r.pascanu@jacobs-university.de
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaStability : provisional
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaPortability : portable
211c5fb252e0a776baad9a4857ab198659289a4aKristina SojakovaPGIP.ProveCommands contains all commands
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovarelated to prove mode
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ( shellTranslate
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellProveAll
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellSelectAxms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellSelectGoals
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellSetAxmsAll
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellSetGoalsAll
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellUnselectAxms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellUnselectGoals
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova , shellUnselectAxmsAll
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellUnselectGoalsAll
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , shellAddAxms
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova , shellAddGoals
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , shellUseThms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellDontUseThms
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , shellSave2File
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , shellDontSave2File
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova , shellEndScript
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellBeginScript
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , shellTimeLimit
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakovaimport qualified Common.OrderedMap as OMap
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakovaimport qualified Data.Map as Map
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakovaimport qualified Logic.Prover as P
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- apply comorphisms
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina SojakovashellTranslate :: String -> Sh CMDLState ()
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova = shellComWith cTranslate False False "translate"
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova-- select a prover
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina SojakovashellProver :: String -> Sh CMDLState ()
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova = shellComWith cProver False False "prover"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- | select comorphisms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovacTranslate::String -> CMDLState -> IO CMDLState
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovacTranslate input state =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case proveState state of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- nothing selected !
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing ->return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg="Nothing selected"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- parse the comorphism name
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova case lookupComorphism_in_LG $ trim input of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ Nothing -> return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg = "Wrong comorphism name"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ (Just cm) ->
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova case cComorphism pS of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- no comorphism used before
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return $ register2history ("translate "++input) $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova addToHistory (CComorphismChange $ cComorphism pS)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova proveState = Just pS {
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova cComorphism = Just cm
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return $ register2history ("translate "++input) $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova addToHistory (CComorphismChange $ cComorphism pS)
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova proveState = Just pS {
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina Sojakova cComorphism = compComorphism ocm cm
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetProversCMDLautomatic::[AnyComorphism]->[(G_prover,AnyComorphism)]
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovagetProversCMDLautomatic = foldl addProvers []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova where addProvers acc cm =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Comorphism cid -> acc ++
345d3dcc9f809776009851c446916fc770aa428dKristina Sojakova foldl (\ l p ->
345d3dcc9f809776009851c446916fc770aa428dKristina Sojakova then (G_prover (targetLogic cid)
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova (provers $ targetLogic cid)
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovaaddToHistory :: UndoRedoElem -> CMDLState -> CMDLState
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina SojakovaaddToHistory elm state =
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova case proveState state of
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova Nothing -> state
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova let hist = historyList pS
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova uhist = fst hist
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova rhist = snd hist
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova proveState = Just pS {
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova historyList = (elm:uhist,rhist)
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova-- | select a prover
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina SojakovacProver::String -> CMDLState -> IO CMDLState
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovacProver input state =
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova -- trimed input
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova let inp = trim input
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case proveState state of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing -> return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg = "Nothing selected"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- check that some theories are selected
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case elements pS of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova [] -> return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg="Nothing selected"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (Element z _):_ ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- see if any comorphism was used
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case cComorphism pS of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- if none use the theory of the first selected node
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- to find possible comorphisms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing-> case find (\(y,_)->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (getPName y)==inp) $
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova getProversCMDLautomatic $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova findComorphismPaths logicGraph $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova sublogicOfTh $ theory z of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing -> return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg="No applicable prover with"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ++" this name found"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just (p,_)->return $ register2history
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ("prover "++input) $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova addToHistory (ProverChange $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova proveState=Just pS {prover = Just p }
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- if yes, use the comorphism to find a list
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case find (\(y,_)-> (getPName y)==inp)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ getProversCMDLautomatic [x] of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case find (\(y,_) ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (getPName y)==inp) $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova getProversCMDLautomatic $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova findComorphismPaths logicGraph $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova sublogicOfTh $ theory z of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing -> return state {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg="No applicable prover with"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ++" this name found"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just (p,nCm@(Comorphism cid))->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return$ register2history ("prover " ++ input) $
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova addToHistory (ProverChange $ prover pS)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova errorMsg="Prover can't be used with the "
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ++"comorphism selected using translate"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ++" command. Using comorphism : "
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ++ language_name cid
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova , proveState = Just pS {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova cComorphism=Just nCm
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova ,prover = Just p
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just (p,_) -> return $ register2history ("prover "++input)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ addToHistory (ProverChange $ prover pS)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova proveState = Just pS {
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova prover = Just p
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- | Given a proofstatus the function does the actual call of the
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova --use theorems is subsequent proofs
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- save problem file for each goal
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- Tactic script
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- proofState of the node that needs proving
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- all theorems, goals and axioms should have
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- been selected before,but the theory should have
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- not beed recomputed
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova CMDLProofAbstractState->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- selected prover, if non one will be automatically
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Maybe G_prover ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- selected comorphism, if non one will be automatically
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Maybe AnyComorphism ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova MVar (Maybe ThreadId) ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova MVar (Maybe CMDLProofAbstractState) ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova MVar LibEnv ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- returns an error message if anything happen
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaproveNode useTh save2File sTxt ndpf mp mcm mThr mSt mlbE libname
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Element pf_st nd ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- recompute the theory (to make effective the selected axioms,
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova st <- recalculateSublogicAndSelectedTheory pf_st
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- compute a prover,comorphism pair to be used in preparing
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing -> lookupKnownProver st P.ProveCMDLautomatic
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Nothing-> lookupKnownProver st P.ProveCMDLautomatic
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just p' -> return (p',cm')
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- try to prepare the theory
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova prep <- case prepareForProving st p_cm of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ Nothing ->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova p_cm'@(_,acm') <-
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova lookupKnownProver st P.ProveCMDLautomatic
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return $ case prepareForProving st p_cm' of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ Nothing -> Nothing
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ (Just sm)-> Just (sm,acm')
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Result _ (Just sm) -> return $ Just (sm,acm)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- theory could not be computed
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return "No suitable prover and comorphism found"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just (G_theory_with_prover lid1 th p, cmp)->
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova return "Error obtaining the prover"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- mVar to poll the prover for results
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova answ <- newMVar (return [])
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova let st' = st { proverRunning= True}
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -- store initial input of the prover
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova swapMVar mSt $ Just $ Element st' nd
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova {- putStrLn ((theoryName st)++"\n"++
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (showDoc sign "") ++
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova show (vsep (map (print_named lid1)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova case selectedGoals st' of
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova [] -> return "No goals selected. Nothing to prove"
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova tmp <-fn useTh
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (theoryName st)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova swapMVar mThr $ Just $ fst tmp
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova pollForResults lid1 cmp (snd tmp) answ mSt []
MVar (Result [P.Proof_status proof_tree]) ->
[P.Proof_status proof_tree] ->
let toPrint ls=map(\x->let txt = "Goal "++(P.goalName x)++" is "
in case P.goalStatus x of
P.Open ->txt++"still open."
P.Disproved->txt++"disproved."
P.Proved _ ->txt++"proved.") ls
-- inspired from Proofs/InferBasic.hs
-- and GUI/ProofManagement.hs
let nwTh = G_theory lidT sigT indT (Map.union sensT gMap) 0
labNode' (safeContextDG "PGIP.ProveCommands"
-- kill the prove/prove-all thread
TypeGoal -> OMap.keys $ goalMap st
OMap.keys aMap
selectedGoals = OMap.keys $
includedAxioms = OMap.keys aMap,
includedTheorems = OMap.keys $