Aelve Codesearch

grep over package repositories
Please provide a string to search for.
3+ characters are required.
Index updated about an hour ago

total matches: more than 1000

Advise-me-0.1
27 matches
src/Bayes/Factor.hs
   rec [a,b] = multiply a b
   rec as  = rec (best:rest)
    where
      m:ms    = sortBy cmp as
      cmp x y = size x `compare` size y
      (best, rest) = minimumBy (\x y -> size (fst x) `compare` size (fst y)) $ map make [0 .. length ms-1]

      make i = (multiply m y, xs ++ ys)
       where

            
src/Bayes/NodeTypes.hs

mkNoisyAdder :: (String, Int) -> [(String, Int)] -> [Int] -> [Double] -> [Probability] -> Factor
mkNoisyAdder target vs dst ws params =
   mkNoisyAdder2 target (sort tups) (last ws, last pss)
 where
   -- dimensions for parents
   (ss, ns) = unzip vs
   -- parameters for each parent (and lastly, leak)
   pss = splitParameters ns params

            
src/Database/HumanAssessment.hs
   , readEvidence
   ) where

import Data.List ( sortBy )
import Data.Function ( on )
import Data.Maybe ( fromJust, isJust, fromMaybe )
import Data.Char ( isDigit )
import Data.Semigroup ( Semigroup, (<>) )
import Data.Text ( unpack )

            
src/Domain/Logic/GeneralizedRules.hs
   ]

split4 :: [a] -> [([a], [a], [a], [a])]
split4 as = sortBy (compare `on` smallContext)
   [ (xs1, xs2, ys1, ys2) 
   | (xs, ys) <- split as
   , (xs1, xs2) <- split xs
   , not (null xs2)
   , (ys1, ys2) <- split ys

            
src/Domain/Logic/Generator.hs
equalLogicACI p q = rec p == rec q
 where
   rec a@(_ :&&: _) =
      let xs = filter (/=T) $ nub $ sort $ conjunctions a
      in if F `elem` xs then F else ands (map rec xs)
   rec a@(_ :||: _) =
      let xs = filter (/=F) $ nub $ sort $ disjunctions a
      in if T `elem` xs then T else ors (map rec xs)
   rec a = descend rec a

-----------------------------------------------------------
-- Logic generator

            
src/Domain/Logic/Strategies.hs
-- p \/ q \/ ~p  ~> reorder p and ~p
-- p \/ q \/ p   ~> reorder p's
groupLiteralsOr :: Rule SLogic
groupLiteralsOr = siblingOf groupCommutativity $ ruleMaybe "ComplOr.sort" $ \p -> do
   let xs = disjunctions p
       ys = sortLiterals xs
   guard (xs /= ys)
   return (ors ys)

-- p /\ q /\ ~p  ~> reorder p and ~p
-- p /\ q /\ p   ~> reorder p's

            
src/Domain/Logic/Strategies.hs
-- p /\ q /\ ~p  ~> reorder p and ~p
-- p /\ q /\ p   ~> reorder p's
groupLiteralsAnd :: Rule SLogic
groupLiteralsAnd = siblingOf groupCommutativity $ ruleMaybe "ComplAnd.sort" $ \p -> do
   let xs = conjunctions p
       ys = sortLiterals xs
   guard (xs /= ys)
   return (ands ys)

sortLiterals :: [SLogic] -> [SLogic]
sortLiterals [] = []
sortLiterals (p:ps) = p : ys ++ sortLiterals zs
 where
   (ys, zs) = partition (\x -> x == p || x `isNegated` p) ps
   isNegated (Not x) y = y `elem` [x, Not (Not x)]
   isNegated x y       = y == Not x


            
src/Domain/Math/CleanUp.hs
-- normalize expr with associativity and commutative rules for + and *
assocExpr, acExpr :: Expr -> Expr
assocExpr = normExpr id
acExpr    = normExpr sort

normExpr :: ([Expr] -> [Expr]) -> Expr -> Expr
normExpr f = rec
 where
   rec expr =

            
src/Domain/Math/CleanUp.hs
   g    = isNothing . fromSquareRoot . snd
   f xs = do
      ys <- mapM make xs
      return $ map fst $ sortBy (comparing g) $ zip xs ys

smart :: Expr -> Expr
smart (a :*: b) = a .*. b
smart (a :/: b) = a ./. b
smart expr@(Sym s [x, y])

            
src/Domain/Math/Polynomial/LeastCommonMultiple.hs

equalFactors :: Expr -> Expr -> Bool
equalFactors x y = f x == f y
 where f = simplifyWith (second sort) powerProductView

            
src/Domain/Math/Polynomial/Rules.hs

   -- return numbers under sqrt symbol
   f :: Expr -> Maybe [Rational]
   f e = sort <$> sequence [ match rationalView a | Sqrt a <- universe e ]

cancelTerms :: Rule (Equation Expr)
cancelTerms = describe "Cancel terms" $
   makeRule (quadreq, "cancel") $ \(lhs :==: rhs) -> do
   xs <- match sumView lhs

            
src/Domain/Math/Polynomial/Rules.hs
conditionVarsRHS :: Equation Expr -> Bool
conditionVarsRHS (lhs :==: rhs) = hasSomeVar rhs && hasNoVar lhs

-- Afterwards, merge and sort
moveToLeft :: Rule (Equation Expr)
moveToLeft = describe "Move to left" $
   ruleMaybe (quadreq, "move-left") $ \(lhs :==: rhs) -> do
      guard (rhs /= 0 && hasSomeVar lhs && (hasSomeVar rhs || isComplex lhs))
      return (collectLikeTerms (sorted (lhs - rhs)) :==: 0)

            
src/Domain/Math/Polynomial/Rules.hs
moveToLeft = describe "Move to left" $
   ruleMaybe (quadreq, "move-left") $ \(lhs :==: rhs) -> do
      guard (rhs /= 0 && hasSomeVar lhs && (hasSomeVar rhs || isComplex lhs))
      return (collectLikeTerms (sorted (lhs - rhs)) :==: 0)
 where
   isComplex = maybe False ((>= 2) . length . filter hasSomeVar)
             . match sumView . applyD merge

   -- high exponents first, non power-factor terms at the end

            
src/Domain/Math/Polynomial/Rules.hs
             . match sumView . applyD merge

   -- high exponents first, non power-factor terms at the end
   sorted = simplifyWith (sortBy (comparing toPF)) sumView
   toPF   = fmap (negate . thd3) . match powerFactorView

ruleApproximate :: Rule (Relation Expr)
ruleApproximate = describe "Approximate irrational number" $
   makeRule (quadreq, "approx") $ \relation -> do

            
src/Domain/Math/Power/Utils.hs

-- | Common functions ---------------------------------------------------------

sortExpr :: Expr -> Expr
sortExpr = transform $ simplifyWith (sort . map sortProd) sumView
  where sortProd = simplifyWith (fmap sort) productView

sortEquation :: Equation Expr -> Equation Expr
sortEquation (x :==: y) = if x < y then eq else flipSides eq
  where eq = sortExpr x :==: sortExpr y

sortOrList :: OrList (Equation Expr) -> OrList (Equation Expr)
sortOrList = toOrList . sort . map sortEquation . toList

-- Semantic equivalence
class SemEq a where
    (===), (=/=) :: a -> a -> Bool
    x =/= y = not (x === y)

            
src/Domain/Math/Simplification.hs
mergeAlike a =
   case (match sumView a, match productView a) of
      (Just xs, _) | length xs > 1 ->
         build sumView (sort $ mergeAlikeSum $ map mergeAlike xs)
      (_, Just (b, ys)) | length (filter (/= 1) ys) > 1 ->
         build productView (b, sort $ mergeAlikeProduct $ map mergeAlike ys)
      _ -> a

mergeAlikeProduct :: [Expr] -> [Expr]
mergeAlikeProduct ys = f [ (match rationalView y, y) | y <- ys ]
 where

            
src/Main/Diagnose.hs
    f (d, n) = d ++ ": " ++ show n ++ percPar n nrTotal

count :: Ord a => [a] -> [(a, Int)]
count = map f . group . sort
  where
    f xs = (head xs, length xs)

percPar :: Integral a => a -> a -> String
percPar x y = " (" ++ perc x y ++ ")"

            
src/Recognize/Expr/Normalform.hs
      _ ->
         case (from sumView expr, from productView expr) of
            (xs, _) | length xs > 1 ->
               to sumView $ sortBy (compare `on` nf) (map nfComAssoc xs)
            (_, (b, xs)) | length xs > 1 ->
               to productView (b, sortBy (compare `on` nf) (map nfComAssoc xs))
            _ ->
               descend nfComAssoc expr

-- | normal form for commutativity +/*
nfCom :: Expr -> Expr

            
src/Recognize/Expr/Normalform.hs
nfCom :: Expr -> Expr
nfCom = cached "nfCom" $ \expr ->
   case expr of
      _ :+: _ -> sum (sort (map nfCom (collect expr)))
       where
         collect (x :+: y) = collect x ++ collect y
         collect (x :-: y) = collect x ++ map neg (collect y)
         collect (Negate x) = map neg (collect x)
         collect a = [a]

            
src/Recognize/Parsing/Interpretation.hs
                 case safeHead steps of
                   Nothing -> empty
                   Just s@(Step i (v,_) _) -> if length steps == 1 then return s
                                        else return (bigStep i (v,sort $ nub $ concatMap (\(Step _ (_,ats) _) -> ats) steps) steps)

-- | @pNamedStep n a@ represents an Interpretation that can be named (L = ..), but still requires the concept
-- to be explicitly written down. (e.g. @pNamedStep (interpret (Var "L")) (interpret (3+1)) succeeds on "3+1", "L=3+1", "L=4" but not on "L"
pNamedStep :: Id -> Interpretation -> Interpretation -> InterpretationParser Step
pNamedStep i a xs = pStepEq i a xs

            
src/Recognize/SubExpr/Compare.hs

-- | Normalizes both expressions and compares them for equality.
--
-- Normalizing here entails sorting on commutativity and associativity, simplifying fractions and applying distributivity.
--
-- We return the first expression and rewrites (simpler fractions, distribution) of the first expression minus the rewrites of the second expression.
pCompareByNormalize :: Expr -> Expr -> SEParser (Expr, [Attribute])
pCompareByNormalize e1 e2 = do
  pLog $ "pCompareByNormalize " ++ show e1 ++ " " ++ show e2

            
src/Task/AreaAndExpression.hs
          yss <- (mapM (\(fs,c) -> ((,) fs <$> match naturalView c) ) . M.toAscList . multivariatePolynomialToMap) yp
          xss <- (mapM (\(fs,c) -> ((,) fs <$> match naturalView c) ) . M.toAscList . multivariatePolynomialToMap) xp
          return (g xss yss)
  g :: [(Factors,Integer)] -- ^ The sorted (by factors) representation of factors and coefficients of the input term
    -> [(Factors,Integer)] -- ^ The sorted representation of factors and coefficients of the solution.
    -> [Attribute]
  g ((xf,xc) : xs) [] = Other (show (Nat xc :*: fromFactors xf) ++ " is incorrect") : g xs []
  g [] ((yf,yc) : ys) = Other (show (Nat yc :*: fromFactors yf) ++ " is missing") : g [] ys
  g xss@((xf,xc):xs) yss@((yf,yc):ys)
     | yf == xf , yc == xc = g xs ys  -- equivalent factors and terms

            
src/Util/List.hs
   ) where

import Data.Function (on)
import Data.List (elemIndex, sortBy, groupBy)
import Control.Arrow (second, (&&&))

safeHead :: [a] -> Maybe a
safeHead [] = Nothing
safeHead (x:_) = Just x

            
src/Util/List.hs



-- | Alternative to 'Data.List.groupBy', in which the list is sorted and grouped
-- on a certain attribute, and each group is labelled with said attribute.
orderBy :: (Ord b) => (a->b) -> [a] -> [(b,[a])]
orderBy attribute
   = map (fst . head &&& map snd)
   . groupBy ((==) `on` fst) 

            
src/Util/List.hs
orderBy attribute
   = map (fst . head &&& map snd)
   . groupBy ((==) `on` fst) 
   . sortBy (compare `on` fst)
   . map (attribute &&& id)

            
src/Util/NumberRange.hs
import Data.Semigroup
import Util.String (split)
import Util.List (groupBy')
import Data.List (sort, nub, intercalate)
import Database.HDBC (SqlValue, fromSql, toSql)
import Data.Convertible.Base (Convertible, safeConvert, convError)
import Ideas.Utils.Prelude (readM)

newtype NumberRange = NumberRange [Int]

            
src/Util/NumberRange.hs
      = intercalate "," 
      . map f 
      . groupBy' (\x y -> abs (x - y) == 1) 
      . sort
      $ range
  
      where 
      f [] = show ""
      f [x] = show x

            
Agda-2.6.0.1
3 matches
src/full/Agda/Auto/Auto.hs
           Just score -> Just (prettyShow cn, score)
         ) modnames

      let sorthits = List.sortBy (\(_, (pa1, pb1)) (_, (pa2, pb2)) -> case compare pa2 pa1 of {EQ -> compare pb1 pb2; o -> o}) hits
      if listmode || pick == (-1) then
        let pick' = max 0 pick
        in if pick' >= length sorthits then
             stopWithMsg $ insuffcands $ length sorthits
            else
             let showhits = take 10 $ drop pick' sorthits
             in stopWithMsg $ "Listing candidate(s) " ++ show pick' ++ "-" ++ show (pick' + length showhits - 1) ++ " (found " ++ show (length sorthits) ++ " in total)\n" ++
                           unlines (map (\(i, (cn, _)) -> show i ++ "  " ++ cn) (zip [pick'..pick' + length showhits - 1] showhits))
       else
        if pick >= length sorthits then
         stopWithMsg $ insuffcands $ length sorthits
        else
         return $ AutoResult (Refinement $ fst $ sorthits !! pick) Nothing
  where
    agsyinfo ticks = ""

-- Get the functions and axioms defined in the same module as @def@.
autohints :: AutoHintMode -> I.MetaId -> Maybe AN.QName -> TCM [Hint]

            
src/full/Agda/Compiler/Backend.hs
      "No backend called '" ++ name ++ "' " ++
      "(installed backends: " ++
      List.intercalate ", "
        (List.sort $ otherBackends ++
                     [ backendName b | Backend b <- backends ]) ++
      ")"

-- | Backends that are not included in the state, but still available
--   to the user.

            
src/full/Agda/Compiler/Backend.hs
  case r of
    Skip m         -> return m
    Recompile menv -> do
      defs <- map snd . sortDefs <$> curDefs
      res  <- mapM (compileDef' backend env menv isMain <=< instantiateFull) defs
      postModule backend env menv isMain (iModuleName i) res

compileDef' :: Backend' opts env menv mod def -> env -> menv -> IsMain -> Definition -> TCM def
compileDef' backend env menv isMain def = setCurrentRange (defName def) $ compileDef backend env menv isMain def