Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial evaluation for distinct #254

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,27 @@
go _ [] = False
go x (y : ys) = x == y || go x ys

getAllConcrete :: [Term a] -> Maybe [a]
getAllConcrete [] = return []
getAllConcrete (ConTerm _ _ _ _ x : xs) = (x :) <$> getAllConcrete xs
getAllConcrete _ = Nothing

checkConcreteDistinct :: (Eq t) => [t] -> Bool
checkConcreteDistinct [] = True
checkConcreteDistinct (x : xs) = check0 x xs && checkConcreteDistinct xs
where
check0 _ [] = True
check0 x (y : ys) = x /= y && check0 x ys

pevalGeneralDistinct ::
(SupportedNonFuncPrim a) => NonEmpty (Term a) -> Term Bool
pevalGeneralDistinct (_ :| []) = conTerm True
pevalGeneralDistinct (a :| [b]) = pevalNotTerm $ pevalEqTerm a b
pevalGeneralDistinct l | pairwiseHasConcreteEqual $ toList l = conTerm False
pevalGeneralDistinct l = distinctTerm l
pevalGeneralDistinct l =
case getAllConcrete (toList l) of
Nothing -> distinctTerm l
Just xs -> conTerm $ checkConcreteDistinct xs

instance SupportedPrim Integer where
pformatCon = show
Expand Down Expand Up @@ -257,7 +272,13 @@
pevalEqTerm (ConTerm _ _ _ _ l) (ConTerm _ _ _ _ r) = conTerm $ l == r
pevalEqTerm l@ConTerm {} r = pevalEqTerm r l
pevalEqTerm l r = eqTerm l r
pevalDistinctTerm = distinctTerm
pevalDistinctTerm (_ :| []) = conTerm True
pevalDistinctTerm (a :| [b]) = pevalNotTerm $ pevalEqTerm a b
pevalDistinctTerm l =
case getAllConcrete (toList l) of
Nothing -> distinctTerm l
Just xs | any isNaN xs -> distinctTerm l
Just xs -> conTerm $ checkConcreteDistinct xs

Check warning on line 281 in src/Grisette/Internal/SymPrim/Prim/Internal/Instances/SupportedPrim.hs

View check run for this annotation

Codecov / codecov/patch

src/Grisette/Internal/SymPrim/Prim/Internal/Instances/SupportedPrim.hs#L280-L281

Added lines #L280 - L281 were not covered by tests
conSBVTerm (FP fp) = SBV.literal fp
symSBVName symbol _ = show symbol
symSBVTerm name = sbvFresh name
Expand Down
Loading