From 6e94b77de3fe911a02701d5d1c0ae7974e244e0d Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 1 Mar 2024 20:00:22 +0100 Subject: [PATCH 1/2] remove 'contains' function --- src/init_LazySets.jl | 18 +++++------------- test/Aqua.jl | 4 +--- test/LazySets.jl | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/init_LazySets.jl b/src/init_LazySets.jl index ea7eb28..21a6bdd 100644 --- a/src/init_LazySets.jl +++ b/src/init_LazySets.jl @@ -1,10 +1,6 @@ -export SetAtom, contains, is_contained_in, is_disjoint_from, intersects +export SetAtom, is_contained_in, is_disjoint_from, intersects import .LazySets: dim, project -@static if VERSION >= v"1.5" - import Base: contains -end - using .LazySets: LazySet, ⊆, isdisjoint """ @@ -64,7 +60,7 @@ function project(sa::SetAtom, vars::AbstractVector{Int}) end # fallback -function project(p::Predicate, vars::AbstractVector{Int}) +function project(p::Predicate, ::AbstractVector{Int}) throw(ArgumentError("`project` cannot be applied to a `$(typeof(p))`; " * "use a `SetAtom` instead")) end @@ -89,13 +85,9 @@ function project(d::Disjunction, vars::AbstractVector{Int}) return Disjunction(disjuncts) end -# ========================================== -# Convenience functions to create predicates -# ========================================== - -function contains(X::LazySet) - return SetAtom(X, ⊆) -end +# ===================================================== +# Convenience functions to create common set predicates +# ===================================================== function is_contained_in(X::LazySet) return SetAtom(X, (X, Y) -> Y ⊆ X) diff --git a/test/Aqua.jl b/test/Aqua.jl index 36cf238..19e2e9a 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -2,7 +2,5 @@ using MathematicalPredicates, Test import Aqua @testset "Aqua tests" begin - Aqua.test_all(MathematicalPredicates; - # `contains` is a known piracy - piracies=(treat_as_own=Function[contains],)) + Aqua.test_all(MathematicalPredicates) end diff --git a/test/LazySets.jl b/test/LazySets.jl index 243c5fd..20f79c2 100644 --- a/test/LazySets.jl +++ b/test/LazySets.jl @@ -10,7 +10,7 @@ B2_proj = project(B2, [1]) P1 = is_contained_in(B1) @test P1(S) && P1(B1) && !P1(B2) -P2 = contains(S) +P2 = SetAtom(S, ⊆) @test P2(S) && P2(B1) && !P2(B2) # dim is only available for SetAtom types From 40861dc39cb75564dcf53c938041bc43562aedc0 Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 2 Mar 2024 08:10:13 +0100 Subject: [PATCH 2/2] rename set functions --- src/init_LazySets.jl | 18 +++++++++++------- test/LazySets.jl | 8 ++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/init_LazySets.jl b/src/init_LazySets.jl index 21a6bdd..a9e65f7 100644 --- a/src/init_LazySets.jl +++ b/src/init_LazySets.jl @@ -1,4 +1,4 @@ -export SetAtom, is_contained_in, is_disjoint_from, intersects +export SetAtom, X_superset_of, X_subset_of, X_disjoint_from, X_intersects_with import .LazySets: dim, project using .LazySets: LazySet, ⊆, isdisjoint @@ -89,14 +89,18 @@ end # Convenience functions to create common set predicates # ===================================================== -function is_contained_in(X::LazySet) - return SetAtom(X, (X, Y) -> Y ⊆ X) +function X_superset_of(Y::LazySet) + return SetAtom(Y, ⊆) end -function is_disjoint_from(X::LazySet) - return SetAtom(X, isdisjoint) +function X_subset_of(Y::LazySet) + return SetAtom(Y, (Y, X) -> X ⊆ Y) end -function intersects(X::LazySet) - return Negation(is_disjoint_from(X)) +function X_disjoint_from(Y::LazySet) + return SetAtom(Y, isdisjoint) +end + +function X_intersects_with(Y::LazySet) + return Negation(X_disjoint_from(Y)) end diff --git a/test/LazySets.jl b/test/LazySets.jl index 20f79c2..6288a33 100644 --- a/test/LazySets.jl +++ b/test/LazySets.jl @@ -7,10 +7,10 @@ S_proj = project(S, [1]) B1_proj = project(B1, [1]) B2_proj = project(B2, [1]) -P1 = is_contained_in(B1) +P1 = X_subset_of(B1) @test P1(S) && P1(B1) && !P1(B2) -P2 = SetAtom(S, ⊆) +P2 = X_superset_of(S) @test P2(S) && P2(B1) && !P2(B2) # dim is only available for SetAtom types @@ -39,7 +39,7 @@ Pd = Disjunction([P1, P2]) @test project(Pc, [1]) == Conjunction([P1_proj, P2_proj]) @test project(Pd, [1]) == Disjunction([P1_proj, P2_proj]) -P1 = is_disjoint_from(S) -P2 = intersects(S) +P1 = X_disjoint_from(S) +P2 = X_intersects_with(S) @test !P1(S) && !P1(B1) && P1(B2) @test P2(S) && P2(B1) && !P2(B2)