<commit_before>{-# LANGUAGE ScopedTypeVariables #-}
-- CompletelyDefined.hs ---
--
-- Filename: CompletelyDefined.hs
-- Description:
-- Author: <NAME>
-- Maintainer:
-- Created: Mon Jul 31 14:31:27 2017 (+0200)
-- Version:
-- Package-Requires: ()
-- Last-Updated:
--           By:
--     Update #: 232
-- URL:
-- Doc URL:
-- Keywords:
-- Compatibility:
--
--

-- Commentary:
--
--
--
--

-- Change Log:
--
--
--
--
--
--
--

-- Code:

module Data.Rewriting.ARA.CompletelyDefined
    ( mkCompletelyDefinedConds
    ) where

import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerCondition.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerCost.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerDatatype.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerSignature.Type
import           Data.Rewriting.ARA.ByInferenceRules.HelperFunctions
import           Data.Rewriting.ARA.ByInferenceRules.Operator.Type
import           Data.Rewriting.ARA.ByInferenceRules.TypeSignatures
import           Data.Rewriting.ARA.ByInferenceRules.Vector.Type
import           Data.Rewriting.ARA.Constants
import           Data.Rewriting.Typed.Datatype
import           Data.Rewriting.Typed.Problem
import           Data.Rewriting.Typed.Rule
import           Data.Rewriting.Typed.Signature

import           Control.Lens
import           Control.Monad.State
import           Data.Function                                              (on)
import           Data.List
import qualified Data.Map.Strict                                            as M
import           Data.Maybe
import qualified Data.Text                                                  as T
import           Text.PrettyPrint.ANSI.Leijen                               hiding ((<$>))

import           Debug.Trace


mkCompletelyDefinedConds :: (Ord f, Eq f, Show f, Show dt, Eq dt, Show v) =>
                            ProblemSig f v f dt dt f
                         -> (ACondition f v Int Int, ASigs dt f)
mkCompletelyDefinedConds p =
  -- trace ("grRls: " ++ show grRls)
  -- trace ("defSyms: " ++ show defSyms)
  -- trace ("allSyms: " ++ show allSyms)
  -- trace ("ctrSyms: " ++ show ctrSyms)
  -- trace ("lhss: " ++ show lhssChlds) $
  -- trace ("ctrArities: " ++ show ctrArities)
  trace ("nRules: " ++ show nRules)

  -- trace ("nSigs: " ++ show (addSig <$> signatures p))
  -- undefined
  -- p { rules = (rules p) { strictRules = strictRules (rules p) ++ concat nRules }
  --   , datatypes = addDt <$> datatypes p
  --   , signatures = addSig <$> signatures p
  --   }
  -- undefined

  ret


  where -- addDt = (++ [Datatype (read (show rhsBtmSym))
        --               [ Constructor (read $ show rhsBtmSym) []]])
        -- addSig = (++ [Signature (read (show rhsBtmSym)) [] (read (show rhsBtmSym))])
        ret = foldl mkSigCond (ACondition [] [] [] [] [], []) nRules
        mkSigCond acc [] =  acc
        mkSigCond (cond,sigs) (Rule (Fun _ lhss) (Fun f _):_) =
          ( cond { dtConditionsInt = dtConditionsInt cond ++
                    map (\p -> (SigRefParam "" (nr::Int) (p::Int) , Eq, 0))
                    [0..(length lhss-1)]
                 }

           , sigs ++ [(Signature (f,ACost (Vector1 0),False, False)
                       (map (\dt -> ActualCost False dt (ACost 0)) pDts)
                       (ActualCost False rDt (ACost 0))
                      , -1, "to make completely defined")]
           )
          where nr = length sigs
                sig = getDefSymSignatureByName' (fromJust $ signatures p) f
                pDts = map fst $ lhsSig sig
                rDt = fst $ rhsSig sig

        rls = allRules (rules p)
        rootTerm (Rule (Fun f _) _) = f
        rootTerm (Rule (Var v) _)   = error "not possible"

        grRls = groupBy ((==) `on` rootTerm) $
                sortBy (compare `on` rootTerm) rls<commit_msg>fix lowerbound completely defined (works)<commit_after>{-# LANGUAGE ScopedTypeVariables #-}
-- CompletelyDefined.hs ---
--
-- Filename: CompletelyDefined.hs
-- Description:
-- Author: <NAME>
-- Maintainer:
-- Created: Mon Jul 31 14:31:27 2017 (+0200)
-- Version:
-- Package-Requires: ()
-- Last-Updated:
--           By:
--     Update #: 235
-- URL:
-- Doc URL:
-- Keywords:
-- Compatibility:
--
--

-- Commentary:
--
--
--
--

-- Change Log:
--
--
--
--
--
--
--

-- Code:

module Data.Rewriting.ARA.CompletelyDefined
    ( mkCompletelyDefinedConds
    ) where

import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerCondition.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerCost.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerDatatype.Type
import           Data.Rewriting.ARA.ByInferenceRules.AnalyzerSignature.Type
import           Data.Rewriting.ARA.ByInferenceRules.HelperFunctions
import           Data.Rewriting.ARA.ByInferenceRules.Operator.Type
import           Data.Rewriting.ARA.ByInferenceRules.TypeSignatures
import           Data.Rewriting.ARA.ByInferenceRules.Vector.Type
import           Data.Rewriting.ARA.Constants
import           Data.Rewriting.Typed.Datatype
import           Data.Rewriting.Typed.Problem
import           Data.Rewriting.Typed.Rule
import           Data.Rewriting.Typed.Signature

import           Control.Lens
import           Control.Monad.State
import           Data.Function                                              (on)
import           Data.List
import qualified Data.Map.Strict                                            as M
import           Data.Maybe
import qualified Data.Text                                                  as T
import           Text.PrettyPrint.ANSI.Leijen                               hiding ((<$>))

import           Debug.Trace


mkCompletelyDefinedConds :: (Ord f, Eq f, Show f, Show dt, Eq dt, Show v) =>
                            ProblemSig f v f dt dt f
                         -> (ACondition f v Int Int, ASigs dt f)
mkCompletelyDefinedConds p =
  -- trace ("grRls: " ++ show grRls)
  -- trace ("defSyms: " ++ show defSyms)
  -- trace ("allSyms: " ++ show allSyms)
  -- trace ("ctrSyms: " ++ show ctrSyms)
  -- trace ("lhss: " ++ show lhssChlds) $
  -- trace ("ctrArities: " ++ show ctrArities)
  trace ("nRules: " ++ show nRules)

  -- trace ("nSigs: " ++ show (addSig <$> signatures p))
  -- undefined
  -- p { rules = (rules p) { strictRules = strictRules (rules p) ++ concat nRules }
  --   , datatypes = addDt <$> datatypes p
  --   , signatures = addSig <$> signatures p
  --   }
  -- undefined

  ret


  where -- addDt = (++ [Datatype (read (show rhsBtmSym))
        --               [ Constructor (read $ show rhsBtmSym) []]])
        -- addSig = (++ [Signature (read (show rhsBtmSym)) [] (read (show rhsBtmSym))])
        ret = foldl mkSigCond (ACondition [] [] [] [] [], []) nRules
        mkSigCond acc [] =  acc
        mkSigCond acc (Rule (Fun _ lhss) (Fun f _):_) =
          foldl (mkSigCond' f) acc (zip [0..] lhss)

        mkSigCond' f (cond,sigs) (pNr,lhs) = case lhs of
          Var _    ->
            ( cond { dtConditionsInt = dtConditionsInt cond ++
                     [(SigRefParam "" (nr::Int) (pNr::Int) , Eq, 0)] }
            , sigs ++ [(Signature (f,ACost (Vector1 0),False, False)
                        (map (\dt -> ActualCost False dt (ACost 0)) pDts)
                        (ActualCost False rDt (ACost 0))
                       , -1, "to make completely defined")]
            )
          Fun f' ch -> foldl (mkSigCond' f') (cond,sigs) (zip [0..] ch)

          where nr = length sigs
                sig = getDefSymSignatureByName' (fromJust $ signatures p) f
                pDts = map fst $ lhsSig sig
                rDt = fst $ rhsSig sig

        rls = allRules (rules p)
        rootTerm (Rule (Fun f _) _) = f
        rootTerm (Rule (Var v) _)   = error "not possible"

        grRls = groupBy ((==) `on` rootTerm) $
                sortBy (compare `on` rootTerm) rls
{'fraction_non_alphanumeric': 0.12648321131027518, 'fraction_numerical': 0.00681646048977531, 'mean_word_length': 1.740574195780007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550617', 'n_tokens_mistral': 2571, 'n_tokens_neox': 2456, 'n_words': 598}