Skip to content

Commit

Permalink
fix: Fix about Gcd1/Lcm1
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Aug 7, 2021
1 parent 68f23ca commit 12e974e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Jikka/CPlusPlus/Language/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ data Monoid'
MonoidIntMin
| -- | \((\mathrm{int64\_t}, \max, \mathrm{INT64\_MIN})\)
MonoidIntMax
| MonoidIntGcd
| MonoidIntLcm
| -- | \((\mathbb{Z}, \gcd, 0)\)
MonoidIntGcd
| -- | \((\mathbb{Z}, \mathrm{lcm}, 1)\)
MonoidIntLcm
deriving (Eq, Ord, Show, Read)

data Literal
Expand Down
4 changes: 4 additions & 0 deletions src/Jikka/Core/Evaluate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ segmentTreeGetRange semigrp segtree l r
SemigroupIntPlus -> sum slice
SemigroupIntMin -> minimum slice
SemigroupIntMax -> maximum slice
SemigroupIntGcd -> foldl gcd 0 slice
SemigroupIntLcm -> foldl lcm 1 slice

build :: MonadError Error m => (V.Vector Value -> m Value) -> V.Vector Value -> Integer -> m (V.Vector Value)
build _ _ n | n < 0 = throwRuntimeError $ "negative length: " ++ show n
Expand Down Expand Up @@ -223,6 +225,8 @@ callBuiltin builtin ts args = wrapError' ("while calling builtin " ++ formatBuil
Max1 -> go1 valueToList id (V.maximumBy compareValues')
ArgMin -> go1 valueToList ValInt $ \xs -> snd (minimumBy (\(x, i) (y, j) -> compareValues' x y <> compare i j) (zip (V.toList xs) [0 ..]))
ArgMax -> go1 valueToList ValInt $ \xs -> snd (maximumBy (\(x, i) (y, j) -> compareValues' x y <> compare i j) (zip (V.toList xs) [0 ..]))
Gcd1 -> go1 valueToIntList ValInt (foldl gcd 0)
Lcm1 -> go1 valueToIntList ValInt (foldl lcm 1)
All -> go1 valueToBoolList ValBool and
Any -> go1 valueToBoolList ValBool or
Sorted -> go1 valueToList ValList sortVector
Expand Down
2 changes: 2 additions & 0 deletions src/Jikka/Core/Language/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ isConstantTimeBuiltin = \case
Max1 -> False
ArgMin -> False
ArgMax -> False
Gcd1 -> False
Lcm1 -> False
All -> False
Any -> False
Sorted -> False
Expand Down

0 comments on commit 12e974e

Please sign in to comment.