-- | computes the sentence for the constructors
freeCons :: GenAx -> [Named CASLFORMULA]
freeCons (sorts, rel, ops) =
    let sortList = Set.toList sorts
        opSyms = map ( \ c -> let iden = compId c in Qual_op_name iden
                      (toOP_TYPE $ compType c) $ posOfId iden) $ Set.toList ops
        injSyms = map ( \ (s, t) -> let p = posOfId s in
                        Qual_op_name (mkUniqueInjName s t)
                         (Op_type Total [s] t p) p)
                  $ Rel.toList $ Rel.irreflex rel
        allSyms = opSyms ++ injSyms
        resType _ (Op_name _) = False
        resType s (Qual_op_name _ t _) = res_OP_TYPE t == s
        getIndex s = fromMaybe (-1) $ elemIndex s sortList
        addIndices (Op_name _) =
          error "CASL/StaticAna: Internal error in function addIndices"
        addIndices os@(Qual_op_name _ t _) =
            (os, map getIndex $ args_OP_TYPE t)
        collectOps s =
          Constraint s (map addIndices $ filter (resType s) allSyms) s
        constrs = map collectOps sortList
        f = mkSort_gen_ax constrs True
 -- added by me:
        nonSub (Qual_op_name n _ _) = not $ isInjName n
        nonSub _ = error "use qualified names"
        consSymbs = map (filter nonSub . map fst . opSymbs) constrs
        toTuple (Qual_op_name n ot@(Op_type _ args _ _) _) =
                  (n, toOpType ot, map Sort args)
        toTuple _ = error "use qualified names"
        consSymbs' = map (map toTuple) consSymbs
        sortSymbs = map (filter (not . nonSub) . map fst . opSymbs) constrs
        getSubsorts (Qual_op_name _ (Op_type _ [ss] _ _) _) = ss
        getSubsorts _ = error "error in injSyms"
        sortSymbs' = map (\ l ->
                       case l of
                        Qual_op_name _ (Op_type _ _ rs _) _ : _ ->
                          (rs, map getSubsorts l)
                        _ -> error "empty list filtered")
                     $ filter (not . null) sortSymbs
        sortAx = concatMap (uncurry makeDisjSubsorts) sortSymbs'
        freeAx = concatMap (\ l -> makeDisjoint l ++
                              map makeInjective (
                                  filter (\ (_, _, x) -> not $ null x) l))
                   consSymbs'
        sameSort (Constraint s _ _) (Constraint s' _ _) = s == s'
        disjToSortAx = concatMap (\ ctors -> let
                         cs = map (map fst . opSymbs) ctors
                         cSymbs = concatMap (map toTuple
                                             . filter nonSub) cs
                         sSymbs = concatMap (map getSubsorts
                                      . filter (not . nonSub)) cs
                         in
                         concatMap (\ c -> map (makeDisjToSort c) sSymbs)
                                   cSymbs) $ groupBy sameSort constrs
    in case constrs of
     [] -> []
     _ -> [toSortGenNamed f sortList]
           ++ freeAx ++ sortAx ++ disjToSortAx

-- | given the signature in M the function computes the signature K
freeCons :: GenAx -> [Named CASLFORMULA]
freeCons (sorts, rel, ops) =
    let sortList = Set.toList sorts
        opSyms = map ( \ c -> let iden = compId c in Qual_op_name iden
                      (toOP_TYPE $ compType c) $ posOfId iden) $ Set.toList ops
        injSyms = map ( \ (s, t) -> let p = posOfId s in
                        Qual_op_name (mkUniqueInjName s t)
                         (Op_type Total [s] t p) p)
                  $ Rel.toList $ Rel.irreflex rel
        allSyms = opSyms ++ injSyms
        resType _ (Op_name _) = False
        resType s (Qual_op_name _ t _) = res_OP_TYPE t == s
        getIndex s = fromMaybe (-1) $ elemIndex s sortList
        addIndices (Op_name _) =
          error "CASL/StaticAna: Internal error in function addIndices"
        addIndices os@(Qual_op_name _ t _) =
            (os, map getIndex $ args_OP_TYPE t)
        collectOps s =
          Constraint s (map addIndices $ filter (resType s) allSyms) s
        constrs = map collectOps sortList
        f = mkSort_gen_ax constrs True
 -- added by me:
        nonSub (Qual_op_name n _ _) = not $ isInjName n
        nonSub _ = error "use qualified names"
        consSymbs = map (filter nonSub . map fst . opSymbs) constrs
        toTuple (Qual_op_name n ot@(Op_type _ args _ _) _) =
                  (n, toOpType ot, map Sort args)
        toTuple _ = error "use qualified names"
        consSymbs' = map (map toTuple) consSymbs
        sortSymbs = map (filter (not . nonSub) . map fst . opSymbs) constrs
        getSubsorts (Qual_op_name _ (Op_type _ [ss] _ _) _) = ss
        getSubsorts _ = error "error in injSyms"
        sortSymbs' = map (\ l ->
                       case l of
                        Qual_op_name _ (Op_type _ _ rs _) _ : _ ->
                          (rs, map getSubsorts l)
                        _ -> error "empty list filtered")
                     $ filter (not . null) sortSymbs
        sortAx = concatMap (uncurry makeDisjSubsorts) sortSymbs'
        freeAx = concatMap (\ l -> makeDisjoint l ++
                              map makeInjective (
                                  filter (\ (_, _, x) -> not $ null x) l))
                   consSymbs'
        sameSort (Constraint s _ _) (Constraint s' _ _) = s == s'
        disjToSortAx = concatMap (\ ctors -> let
                         cs = map (map fst . opSymbs) ctors
                         cSymbs = concatMap (map toTuple
                                             . filter nonSub) cs
                         sSymbs = concatMap (map getSubsorts
                                      . filter (not . nonSub)) cs
                         in
                         concatMap (\ c -> map (makeDisjToSort c) sSymbs)
                                   cSymbs) $ groupBy sameSort constrs
    in case constrs of
     [] -> []
     _ -> [toSortGenNamed f sortList]
           ++ freeAx ++ sortAx ++ disjToSortAx

-- | given the signature in M the function computes the signature K
freeCons (sorts, rel, ops) =
    let sortList = Set.toList sorts
        opSyms = map ( \ c -> let iden = compId c in Qual_op_name iden
                      (toOP_TYPE $ compType c) $ posOfId iden) $ Set.toList ops
        injSyms = map ( \ (s, t) -> let p = posOfId s in
                        Qual_op_name (mkUniqueInjName s t)
                         (Op_type Total [s] t p) p)
                  $ Rel.toList $ Rel.irreflex rel
        allSyms = opSyms ++ injSyms
        resType _ (Op_name _) = False
        resType s (Qual_op_name _ t _) = res_OP_TYPE t == s
        getIndex s = fromMaybe (-1) $ elemIndex s sortList
        addIndices (Op_name _) =
          error "CASL/StaticAna: Internal error in function addIndices"
        addIndices os@(Qual_op_name _ t _) =
            (os, map getIndex $ args_OP_TYPE t)
        collectOps s =
          Constraint s (map addIndices $ filter (resType s) allSyms) s
        constrs = map collectOps sortList
        f = mkSort_gen_ax constrs True
 -- added by me:
        nonSub (Qual_op_name n _ _) = not $ isInjName n
        nonSub _ = error "use qualified names"
        consSymbs = map (filter nonSub . map fst . opSymbs) constrs
        toTuple (Qual_op_name n ot@(Op_type _ args _ _) _) =
                  (n, toOpType ot, map Sort args)
        toTuple _ = error "use qualified names"
        consSymbs' = map (map toTuple) consSymbs
        sortSymbs = map (filter (not . nonSub) . map fst . opSymbs) constrs
        getSubsorts (Qual_op_name _ (Op_type _ [ss] _ _) _) = ss
        getSubsorts _ = error "error in injSyms"
        sortSymbs' = map (\ l ->
                       case l of
                        Qual_op_name _ (Op_type _ _ rs _) _ : _ ->
                          (rs, map getSubsorts l)
                        _ -> error "empty list filtered")
                     $ filter (not . null) sortSymbs
        sortAx = concatMap (uncurry makeDisjSubsorts) sortSymbs'
        freeAx = concatMap (\ l -> makeDisjoint l ++
                              map makeInjective (
                                  filter (\ (_, _, x) -> not $ null x) l))
                   consSymbs'
        sameSort (Constraint s _ _) (Constraint s' _ _) = s == s'
        disjToSortAx = concatMap (\ ctors -> let
                         cs = map (map fst . opSymbs) ctors
                         cSymbs = concatMap (map toTuple
                                             . filter nonSub) cs
                         sSymbs = concatMap (map getSubsorts
                                      . filter (not . nonSub)) cs
                         in
                         concatMap (\ c -> map (makeDisjToSort c) sSymbs)
                                   cSymbs) $ groupBy sameSort constrs
    in case constrs of
     [] -> []
     _ -> [toSortGenNamed f sortList]
           ++ freeAx ++ sortAx ++ disjToSortAx

-- | given the signature in M the function computes the signature K