-
Notifications
You must be signed in to change notification settings - Fork 16
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 in sol #373
Add in sol #373
Conversation
From doing in(item, collection) -> Bool
∈(item, collection) -> Bool
∋(collection, item) -> Bool
Determine whether an item is in the given collection, in the sense that it is == to one of the values generated by iterating over the collection. Returns a Bool value,
except if item is missing or collection contains missing but not item, in which case missing is returned (three-valued logic
(https://en.wikipedia.org/wiki/Three-valued_logic), matching the behavior of any and ==).
Some collections follow a slightly different definition. For example, Sets check whether the item isequal to one of the elements. Dicts look for key=>value pairs, and the
key is compared using isequal. To test for the presence of a key in a dictionary, use haskey or k in keys(dict). For these collections, the result is always a Bool and
never missing.
To determine whether an item is not in a given collection, see :∉. You may also negate the in by doing !(a in b) which is logically similar to "not in".
When broadcasting with in.(items, collection) or items .∈ collection, both item and collection are broadcasted over, which is often not what is intended. For example, if
both arguments are vectors (and the dimensions match), the result is a vector indicating whether each value in collection items is in the value at the corresponding
position in collection. To get a vector indicating whether each value in items is in collection, wrap collection in a tuple or a Ref like this: in.(items, Ref(collection))
or items .∈ Ref(collection). The point about julia> NaN ∈ [1, NaN]
false
julia> NaN ∈ Set([1, NaN])
true To help explain, I'll define my_in(element, collection) = any(==(element), collection) which perhaps is more clear as my_in(element, collection) = any( element == x for x in collection) and "consistency", and following the documentation of
If the definitions at ReachabilityAnalysis.jl/src/Flowpipes/solutions.jl Lines 88 to 99 in b877a7d
my_in will not error, and will return a different answer from in .
Note that a type does not need to define julia> in([0.0, 0.0], Hyperrectangle([0.0, 0.0], [1.0, 1.0]))
true
julia> my_in([0.0, 0.0], Hyperrectangle([0.0, 0.0], [1.0, 1.0]))
ERROR: MethodError: no method matching iterate(::Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}) There are some tricky cases where this consistency is broken for some other good. For example, for whatever reason (sometime I think it's good, sometimes I think it's the absolute worst) julia> collect(3)
0-dimensional Array{Int64,0}:
3
julia> 3 in 3
true
julia> length(3)
1 that itself doesn't pose a problem since julia> my_in(3, 3)
true But julia> supertypes(typeof(Interval(0,1)))
(Interval{Float64}, AbstractInterval{Float64}, Real, Number, Any) and so julia> in(0.5, Interval(0, 1))
true
julia> my_in(0.5, Interval(0, 1))
false Since the type in question here has no reason to be |
indeed, i acknowledge that implementing the iterator interface AND at the same time working with dense sets of R^n is prone to mistakes, and there was one fixed in this PR, because the on the other hand, there are many benefits of (conversation continued on gitter) |
Sorry if I am belaboring the point. I should probably open a separate issue to discuss this. Code like
and ReachabilityAnalysis.jl/src/Flowpipes/flowpipes.jl Lines 478 to 485 in cd24f50
makes me especially nervous to have a definition of The line
reads to me like
or but that is not what it really means. |
Here I don't see an issue with this definition. We should document uses of |
Thanks for catching the typo.
Yeah, there is nothing incorrect about the code, sorry if I communicated
otherwise. It's the punning on "in" that occurs in the same line of code
that is a conceptual issue, which can be more easily seen in the
[corrected] latex.
…On Thu, Nov 26, 2020, 6:36 AM Marcelo Forets ***@***.***> wrote:
Here ⊆(F::Flowpipe, X::LazySet) means that F is contained in X, and the
implementation relies on R ⊆ X which uses dispatch on a reach-set and a
set. Pleas note that there is a typo in the lef-hand side of the LaTeX
equation of your comment.
I don't see an issue with this definition. We should document uses of ∈
and ⊆ in the library though, that is still missing.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#373 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEN3M56TMSP3UNDYTLZNM3SRY4UZANCNFSM4UBLTHMA>
.
|
yes, indeed |
No description provided.