Logic.hs revision 4f9fc8b01e3c01d538a12e6327241c8fc16bc102
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, DeriveDataTypeable
a78048ccbdb6256da15e6b0e7e95355e480c2301nd , FlexibleInstances, UndecidableInstances, ExistentialQuantification #-}
fd9abdda70912b99b24e3bf1a38f26fde908a74cndModule : $Header$
fd9abdda70912b99b24e3bf1a38f26fde908a74cndDescription : central interface (type class) for logics in Hets
a78048ccbdb6256da15e6b0e7e95355e480c2301ndCopyright : (c) Till Mossakowski, and Uni Bremen 2002-2006
a78048ccbdb6256da15e6b0e7e95355e480c2301ndLicense : GPLv2 or higher, see LICENSE.txt
a78048ccbdb6256da15e6b0e7e95355e480c2301ndMaintainer : till@informatik.uni-bremen.de
a78048ccbdb6256da15e6b0e7e95355e480c2301ndStability : provisional
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletcPortability : non-portable (various -fglasgow-exts extensions)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndCentral interface (type class) for logics in Hets
2e545ce2450a9953665f701bb05350f0d3f26275ndProvides data structures for logics (with symbols). Logics are
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen a type class with an /identity type/ (usually interpreted
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen by a singleton set) which serves to treat logics as
a78048ccbdb6256da15e6b0e7e95355e480c2301nd data. All the functions in the type class take the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd identity as first argument in order to determine the logic.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd For logic (co)morphisms see "Logic.Comorphism"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd This module uses multiparameter type classes with functional dependencies
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (<http://www.haskell.org/haskellwiki/Functional_dependencies>)
3f08db06526d6901aa08c110b5bc7dde6bc39905nd for defining an interface for the notion of logic. Multiparameter type
a78048ccbdb6256da15e6b0e7e95355e480c2301nd classes are needed because a logic consists of a collection of types,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd together with operations on these. Functional dependencies
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung are needed because no operation will involve all types of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd the multiparameter type class; hence we need a method to derive
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem the missing types. We chose an easy way: for each logic, we
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem introduce a new singleton type that is the name, or constitutes the identity
a78048ccbdb6256da15e6b0e7e95355e480c2301nd of the logic. All other types of the multiparameter type class
a78048ccbdb6256da15e6b0e7e95355e480c2301nd depend on this /identity constituting/ type, and all operations take
a78048ccbdb6256da15e6b0e7e95355e480c2301nd the 'identity constituting' type as first arguments. The value
a78048ccbdb6256da15e6b0e7e95355e480c2301nd of the argument of the /identity constituting/ type is irrelevant
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (note that there is only one value of such a type anyway).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Note that we tend to use @lid@ both for the /identity type/
a78048ccbdb6256da15e6b0e7e95355e480c2301nd of a logic, as well as for its unique inhabitant, i.e. @lid :: lid@.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd The other types involved in the definition of logic are as follows:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * sign: signatures, that is, contexts, or non-logical vocabularies,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd typically consisting of a set of declared sorts, predicates,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd function symbols, propositional letters etc., together with their
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * sentence: logical formulas.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * basic_spec: abstract syntax of basic specifications. The latter are
a78048ccbdb6256da15e6b0e7e95355e480c2301nd human-readable presentations of a signature together with some sentences.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * symbol: symbols that may occur in a signature, fully qualified
a78048ccbdb6256da15e6b0e7e95355e480c2301nd with their types
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * raw_symbol: symbols that may occur in a signature, possibly not
a78048ccbdb6256da15e6b0e7e95355e480c2301nd or partially qualified
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * morphism: maps between signatures (typically preserving the structure).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * symb_items: abstract syntax of symbol lists, used for declaring some
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symbols of a signature as hidden.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * symb_map_items: abstract syntax of symbol maps, i.e. human-readable
a78048ccbdb6256da15e6b0e7e95355e480c2301nd presentations of signature morphisms.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * sublogics: sublogics of the given logic. This type might be a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd record of Boolean flags, indicating whether some feature is
a78048ccbdb6256da15e6b0e7e95355e480c2301nd present in the sublogi of not.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * proof_tree: proof trees.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd References:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd J. A. Goguen and R. M. Burstall
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Institutions: Abstract Model Theory for Specification and
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Programming
a78048ccbdb6256da15e6b0e7e95355e480c2301nd JACM 39, p. 95-146, 1992
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (general notion of logic - model theory only)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd J. Meseguer
a78048ccbdb6256da15e6b0e7e95355e480c2301nd General Logics
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Logic Colloquium 87, p. 275-329, North Holland, 1989
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (general notion of logic - also proof theory;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd notion of logic representation, called map there)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd T. Mossakowski:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Specification in an arbitrary institution with symbols
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 14th WADT 1999, LNCS 1827, p. 252-270
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (treatment of symbols and raw symbols, see also CASL semantics
a78048ccbdb6256da15e6b0e7e95355e480c2301nd in the CASL reference manual)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd T. Mossakowski, B. Klin:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Institution Independent Static Analysis for CASL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 15h WADT 2001, LNCS 2267, p. 221-237, 2002.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (what is needed for static anaylsis)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd S. Autexier and T. Mossakowski
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Integrating HOLCASL into the Development Graph Manager MAYA
a78048ccbdb6256da15e6b0e7e95355e480c2301nd FroCoS 2002, LNCS 2309, p. 2-17, 2002.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (interface to provers)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd CoFI (ed.): CASL Reference Manual, LNCS 2960, Springer Verlag, 2004.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (static semantics of CASL structured and architectural specifications)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd T. Mossakowski
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Heterogeneous specification and the heterogeneous tool set
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Habilitation thesis, University of Bremen, 2005
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (the general picture of heterogeneous specification)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport Logic.Prover (Prover, ConsChecker, Theory (..))
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport Taxonomy.MMiSSOntology (MMiSSOntology)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport qualified OMDoc.DataTypes as OMDoc
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ( TCElement
a78048ccbdb6256da15e6b0e7e95355e480c2301nd , TCorOMElement
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport ATerm.Lib (ShATermConvertible)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport Common.Prec (PrecMap)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport qualified Data.Set as Set
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport qualified Data.Map as Map
a78048ccbdb6256da15e6b0e7e95355e480c2301ndimport Control.Monad (unless)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | Stability of logic implementations
a78048ccbdb6256da15e6b0e7e95355e480c2301nddata Stability = Stable | Testing | Unstable | Experimental
a78048ccbdb6256da15e6b0e7e95355e480c2301nd deriving (Eq, Show)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | shortcut for class constraints
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass ShATermConvertible a => Convertible a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinstance ShATermConvertible a => Convertible a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | shortcut for class constraints
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass (Pretty a, Convertible a) => PrintTypeConv a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinstance (Pretty a, Convertible a) => PrintTypeConv a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | shortcut for class constraints with equality
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass (Eq a, PrintTypeConv a) => EqPrintTypeConv a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinstance (Eq a, PrintTypeConv a) => EqPrintTypeConv a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | maps from a to a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtype EndoMap a = Map.Map a a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{- | the name of a logic.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Define instances like "data CASL = CASL deriving Show"
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass Show lid => Language lid where
a78048ccbdb6256da15e6b0e7e95355e480c2301nd language_name :: lid -> String
a78048ccbdb6256da15e6b0e7e95355e480c2301nd language_name = show
a78048ccbdb6256da15e6b0e7e95355e480c2301nd description :: lid -> String
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- default implementation
a78048ccbdb6256da15e6b0e7e95355e480c2301nd description _ = ""
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{- | Categories are given as usual: objects, morphisms, identities,
4aa603e6448b99f9371397d439795c91a93637eand domain, codomain and composition. The type id is the name, or
a78048ccbdb6256da15e6b0e7e95355e480c2301nd the identity of the category. It is an argument to all functions
a78048ccbdb6256da15e6b0e7e95355e480c2301nd of the type class, serving disambiguation among instances
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (via the functional dependency lid -> object morphism).
a78048ccbdb6256da15e6b0e7e95355e480c2301nd The types for objects and morphisms may be restricted to
a78048ccbdb6256da15e6b0e7e95355e480c2301nd subtypes, using legal_obj and legal_mor. For example, for the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd category of sets and injective maps, legal_mor would check
a78048ccbdb6256da15e6b0e7e95355e480c2301nd injectivity. Since Eq is a subclass of Category, it is also
a78048ccbdb6256da15e6b0e7e95355e480c2301nd possible to impose a quotient on the types for objects and morphisms.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Require Ord instances only for efficiency, i.e. in sets or maps.
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass (Ord object, Ord morphism)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Category object morphism | morphism -> object where
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | identity morphisms
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ide :: object -> morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {- | composition, in diagrammatic order,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if intermediate objects are equal (not checked!) -}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd composeMorphisms :: morphism -> morphism -> Result morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | domain and codomain of morphisms
a78048ccbdb6256da15e6b0e7e95355e480c2301nd dom, cod :: morphism -> object
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | the inverse of a morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd inverse :: morphism -> Result morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd inverse _ = fail "Logic.Logic.Category.inverse not implemented"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | test if the signature morphism an inclusion
a78048ccbdb6256da15e6b0e7e95355e480c2301nd isInclusion :: morphism -> Bool
a78048ccbdb6256da15e6b0e7e95355e480c2301nd isInclusion _ = False -- in general no inclusion
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | is a value of type morphism denoting a legal morphism?
a78048ccbdb6256da15e6b0e7e95355e480c2301nd legal_mor :: morphism -> Result ()
a78048ccbdb6256da15e6b0e7e95355e480c2301nd legal_mor _ = return ()
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | test if the signature morphism is the identity
a78048ccbdb6256da15e6b0e7e95355e480c2301ndisIdentity :: Category object morphism => morphism -> Bool
a78048ccbdb6256da15e6b0e7e95355e480c2301ndisIdentity m = isInclusion m && dom m == cod m
a78048ccbdb6256da15e6b0e7e95355e480c2301ndcomp :: Category object morphism => morphism -> morphism -> Result morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301ndcomp m1 m2 = if cod m1 == dom m2 then composeMorphisms m1 m2 else
a78048ccbdb6256da15e6b0e7e95355e480c2301nd fail "target of first and source of second morphism are different"
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinstance Ord sign => Category sign (DefaultMorphism sign) where
a78048ccbdb6256da15e6b0e7e95355e480c2301nd dom = domOfDefaultMorphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cod = codOfDefaultMorphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ide = ideOfDefaultMorphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd isInclusion = const True
a78048ccbdb6256da15e6b0e7e95355e480c2301nd composeMorphisms = compOfDefaultMorphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{- | Abstract syntax, parsing and printing.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd There are three types for abstract syntax:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd basic_spec is for basic specifications (see CASL RefMan p. 5ff.),
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symb_items is for symbol lists (see CASL RefMan p. 35ff.),
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symb_map_items is for symbol maps (see CASL RefMan p. 35ff.).
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass (Language lid, PrintTypeConv basic_spec, GetRange basic_spec,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Monoid basic_spec, -- for joining converted signatures and sentences
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Pretty symbol,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd EqPrintTypeConv symb_items,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd EqPrintTypeConv symb_map_items)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd | lid -> basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | parsers and printers
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parsersAndPrinters :: lid -> Map.Map String
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (PrefixMap -> AParser st basic_spec, basic_spec -> Doc)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parsersAndPrinters li = case parse_basic_spec li of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Just p -> makeDefault (p, pretty)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | parser for basic specifications
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_basic_spec :: lid -> Maybe (PrefixMap -> AParser st basic_spec)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | parser for symbol lists
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_symb_items :: lid -> Maybe (AParser st symb_items)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | parser for symbol maps
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_symb_map_items :: lid -> Maybe (AParser st symb_map_items)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd toItem :: lid -> basic_spec -> Item
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- default implementations
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_basic_spec _ = Nothing
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_symb_items _ = Nothing
a78048ccbdb6256da15e6b0e7e95355e480c2301nd parse_symb_map_items _ = Nothing
a78048ccbdb6256da15e6b0e7e95355e480c2301nd toItem _ bs = mkFlatItem ("Basicspec", pretty bs) $ getRangeSpan bs
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecParser :: Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Maybe IRI -> lid -> Maybe (PrefixMap -> AParser st basic_spec)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecParser sm = fmap fst . parserAndPrinter sm
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecPrinter :: Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Maybe IRI -> lid -> Maybe (basic_spec -> Doc)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecPrinter sm = fmap snd . parserAndPrinter sm
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecSyntaxes :: Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => lid -> [String]
a78048ccbdb6256da15e6b0e7e95355e480c2301ndbasicSpecSyntaxes = Map.keys . serializations . language_name
a78048ccbdb6256da15e6b0e7e95355e480c2301ndparserAndPrinter :: Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Maybe IRI -> lid -> Maybe (PrefixMap -> AParser st basic_spec,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd basic_spec -> Doc)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndparserAndPrinter sm l = lookupDefault l sm (parsersAndPrinters l)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | function to lookup parser or printer
a78048ccbdb6256da15e6b0e7e95355e480c2301ndlookupDefault :: Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => lid -> Maybe IRI -> Map.Map String b -> Maybe b
a78048ccbdb6256da15e6b0e7e95355e480c2301ndlookupDefault l im m = case im of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Just i -> do
a78048ccbdb6256da15e6b0e7e95355e480c2301nd let s = iriToStringUnsecure i
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ser <- if isSimple i then return s
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else lookupSerialization (language_name l) s
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Nothing -> if Map.size m == 1 then Just $ head $ Map.elems m
a78048ccbdb6256da15e6b0e7e95355e480c2301ndshowSyntax :: Language lid => lid -> Maybe IRI -> String
a78048ccbdb6256da15e6b0e7e95355e480c2301ndshowSyntax lid = (("logic " ++ language_name lid) ++)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd . maybe "" ((" serialization " ++) . iriToStringUnsecure)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndmakeDefault :: b -> Map.Map String b
a78048ccbdb6256da15e6b0e7e95355e480c2301ndmakeDefault = Map.singleton ""
a78048ccbdb6256da15e6b0e7e95355e480c2301ndaddSyntax :: String -> b -> Map.Map String b -> Map.Map String b
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{- | Sentences, provers and symbols.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Provers capture the entailment relation between sets of sentences
a78048ccbdb6256da15e6b0e7e95355e480c2301nd and sentences. They may return proof trees witnessing proofs.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Signatures are equipped with underlying sets of symbols
a78048ccbdb6256da15e6b0e7e95355e480c2301nd (such that the category of signatures becomes a concrete category),
a78048ccbdb6256da15e6b0e7e95355e480c2301nd see CASL RefMan p. 191ff.
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass (Language lid, Category sign morphism, Ord sentence,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Ord symbol, -- for efficient lookup
a78048ccbdb6256da15e6b0e7e95355e480c2301nd PrintTypeConv sign, PrintTypeConv morphism,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd GetRange sentence, GetRange symbol,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd PrintTypeConv sentence, PrintTypeConv symbol)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd => Sentences lid sentence sign morphism symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd | lid -> sentence sign morphism symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | sentence translation along a signature morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd map_sen :: lid -> morphism -> sentence -> Result sentence
a78048ccbdb6256da15e6b0e7e95355e480c2301nd map_sen l _ _ = statFail l "map_sen"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | simplification of sentences (leave out qualifications)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd simplify_sen :: lid -> sign -> sentence -> sentence
4aa603e6448b99f9371397d439795c91a93637eand simplify_sen _ _ = id
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | negation of a sentence for disproving
a78048ccbdb6256da15e6b0e7e95355e480c2301nd negation :: lid -> sentence -> Maybe sentence
a78048ccbdb6256da15e6b0e7e95355e480c2301nd negation _ _ = Nothing
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | modified signature printing when followed by sentences
a78048ccbdb6256da15e6b0e7e95355e480c2301nd print_sign :: lid -> sign -> Doc
a78048ccbdb6256da15e6b0e7e95355e480c2301nd print_sign _ = pretty
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | print a sentence with comments
a78048ccbdb6256da15e6b0e7e95355e480c2301nd print_named :: lid -> Named sentence -> Doc
a78048ccbdb6256da15e6b0e7e95355e480c2301nd print_named _ = printAnnoted (addBullet . pretty) . fromLabelledSen
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- --------------------- symbols ---------------------------
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | dependency ordered list of symbol sets for a signature
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sym_of :: lid -> sign -> [Set.Set symbol]
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sym_of _ _ = []
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {- | Dependency ordered list of a bigger symbol set for a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd signature. This function contains more symbols than those being subject
a78048ccbdb6256da15e6b0e7e95355e480c2301nd to hiding and renaming (given by 'sym_of') to better represent a
a78048ccbdb6256da15e6b0e7e95355e480c2301nd signature as a set of symbols given within xml files. At least for CASL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd additional symbols for (direct) subsorts will be created, but note, that
a78048ccbdb6256da15e6b0e7e95355e480c2301nd no symbol for a partial function will be created, if the signature
a78048ccbdb6256da15e6b0e7e95355e480c2301nd contains this function as total, although a signature with just that
a78048ccbdb6256da15e6b0e7e95355e480c2301nd partial function would be a subsignature. This function is supposed to
a78048ccbdb6256da15e6b0e7e95355e480c2301nd work over partial signatures created by 'signatureDiff'. -}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd mostSymsOf :: lid -> sign -> [symbol]
a78048ccbdb6256da15e6b0e7e95355e480c2301nd mostSymsOf l = concatMap Set.toList . sym_of l
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | symbol map for a signature morphism
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symmap_of :: lid -> morphism -> EndoMap symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symmap_of _ _ = Map.empty
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | symbols have a name, see CASL RefMan p. 192
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sym_name :: lid -> symbol -> Id
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sym_name l _ = statError l "sym_name"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | a logic dependent kind of a symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symKind :: lid -> symbol -> String
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symKind _ _ = ""
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | the symbols occuring in a sentence (any order)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symsOfSen :: lid -> sentence -> [symbol]
a78048ccbdb6256da15e6b0e7e95355e480c2301nd symsOfSen _ _ = []
a78048ccbdb6256da15e6b0e7e95355e480c2301nd -- | combine two symbols into another one
a78048ccbdb6256da15e6b0e7e95355e480c2301nd pair_symbols :: lid -> symbol -> symbol -> Result symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd pair_symbols _ s1 _ = return s1
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | makes a singleton list from the given value
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsingletonList :: a -> [a]
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsingletonList x = [x]
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | set of symbols for a signature
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsymset_of :: forall lid sentence sign morphism symbol .
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Sentences lid sentence sign morphism symbol =>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd lid -> sign -> Set.Set symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsymset_of lid sig = Set.unions $ sym_of lid sig
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | dependency ordered list of symbols for a signature
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsymlist_of :: forall lid sentence sign morphism symbol .
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Sentences lid sentence sign morphism symbol =>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd lid -> sign -> [symbol]
a78048ccbdb6256da15e6b0e7e95355e480c2301ndsymlist_of lid sig = concatMap Set.toList $ sym_of lid sig
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | a dummy static analysis function to allow type checking *.inline.hs files
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinlineAxioms :: StaticAnalysis lid
a78048ccbdb6256da15e6b0e7e95355e480c2301nd basic_spec sentence symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sign morphism symbol raw_symbol => lid -> String -> [Named sentence]
a78048ccbdb6256da15e6b0e7e95355e480c2301ndinlineAxioms _ _ = error "inlineAxioms"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | fail function for static analysis
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatFail :: (Language lid, Monad m) => lid -> String -> m a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatFail lid = fail . statErrMsg lid
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatError :: Language lid => lid -> String -> a
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatError lid = error . statErrMsg lid
a78048ccbdb6256da15e6b0e7e95355e480c2301nd-- | error message for static analysis
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatErrMsg :: Language lid => lid -> String -> String
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatErrMsg lid str =
a78048ccbdb6256da15e6b0e7e95355e480c2301nd "Logic." ++ str ++ " not implemented for: " ++ language_name lid
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{- static analysis
a78048ccbdb6256da15e6b0e7e95355e480c2301nd This type class provides the data needed for an institution with symbols,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd as explained in the structured specification semantics in the CASL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd reference manual, chapter III.4.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd The static analysis computes signatures from basic specifications,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd and signature morphisms from symbol lists and symbol maps. The latter
a78048ccbdb6256da15e6b0e7e95355e480c2301nd needs an intermediate stage, so-called raw symbols, which are possibly
a78048ccbdb6256da15e6b0e7e95355e480c2301nd unqualified symbols. Normal symbols are always fully qualified.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd In the CASL reference manual, our symbols are called "signature symbols",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd and our raw symbols are called "symbols". (Terminology should be adapted.)
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass ( Syntax lid basic_spec symbol symb_items symb_map_items
a78048ccbdb6256da15e6b0e7e95355e480c2301nd , Sentences lid sentence sign morphism symbol
a78048ccbdb6256da15e6b0e7e95355e480c2301nd , GetRange raw_symbol, Ord raw_symbol, Pretty raw_symbol
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung , Typeable raw_symbol)
727872d18412fc021f03969b8641810d8896820bhumbedooh => StaticAnalysis lid
0d0ba3a410038e179b695446bb149cce6264e0abnd basic_spec sentence symb_items symb_map_items
727872d18412fc021f03969b8641810d8896820bhumbedooh sign morphism symbol raw_symbol
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh | lid -> basic_spec sentence symb_items symb_map_items
0d0ba3a410038e179b695446bb149cce6264e0abnd sign morphism symbol raw_symbol
727872d18412fc021f03969b8641810d8896820bhumbedooh {- | static analysis of basic specifications and symbol maps.
0d0ba3a410038e179b695446bb149cce6264e0abnd The resulting bspec has analyzed axioms in it.
0d0ba3a410038e179b695446bb149cce6264e0abnd The resulting sign is an extension of the input sign
0d0ba3a410038e179b695446bb149cce6264e0abnd plus newly declared or redeclared symbols.
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh See CASL RefMan p. 138 ff. -}
0d0ba3a410038e179b695446bb149cce6264e0abnd basic_analysis :: lid
0d0ba3a410038e179b695446bb149cce6264e0abnd -> Maybe ((basic_spec, sign, GlobalAnnos)
0d0ba3a410038e179b695446bb149cce6264e0abnd -> Result (basic_spec, ExtSign sign symbol, [Named sentence]))
727872d18412fc021f03969b8641810d8896820bhumbedooh basic_analysis _ = Nothing
0d0ba3a410038e179b695446bb149cce6264e0abnd -- | Analysis of just sentences
0d0ba3a410038e179b695446bb149cce6264e0abnd sen_analysis :: lid
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh -> Maybe ((basic_spec, sign, sentence) -> Result sentence)
205f749042ed530040a4f0080dbcb47ceae8a374rjung sen_analysis _ = Nothing
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen -- | a basic analysis with additional arguments
0d0ba3a410038e179b695446bb149cce6264e0abnd extBasicAnalysis :: lid -> IRI -> LibName
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd -> basic_spec -> sign -> GlobalAnnos
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd -> Result (basic_spec, ExtSign sign symbol, [Named sentence])
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd extBasicAnalysis l _ _ b s g = case basic_analysis l of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Nothing -> statFail l "basic_analysis"
-> Result (sign, Map.Map Int morphism)
lid -> Set.Set symbol -> sign -> Result morphism
, pretty $ Set.difference (symset_of l s1) $ symset_of l s2 ]
-- | several provers can be provided. See module "Logic.Prover"
omdoc_metatheory :: lid -> Maybe OMDoc.OMCD
export_symToOmdoc :: lid -> OMDoc.NameMap symbol
-> symbol -> String -> Result OMDoc.TCElement
export_senToOmdoc :: lid -> OMDoc.NameMap symbol
-> sentence -> Result OMDoc.TCorOMElement
export_theoryToOmdoc :: lid -> OMDoc.SigMap symbol -> sign
-> [Named sentence] -> Result [OMDoc.TCElement]
addOMadtToTheory :: lid -> OMDoc.SigMapI symbol
-> (sign, [Named sentence]) -> [[OMDoc.OmdADT]]
addOmdocToTheory :: lid -> OMDoc.SigMapI symbol
-> (sign, [Named sentence]) -> [OMDoc.TCElement]
emptyTheory lid = Theory (empty_signature lid) Map.empty