<style> .reveal, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6 { font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, "Microsoft JhengHei", Meiryo, sans-serif; } h1, h2, h3, h4, h5, h6 { text-transform: none !important; } .color-yellow{ color: yellow; } .alert { padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; text-align: left; padding: 10px 0; } .alert-info { color: #31708f; background-color: #d9edf7; border-color: #bce8f1; } .alert-success { color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; } .alert-danger { color: #a94442; background-color: #f2dede; border-color: #ebccd1; } .reveal .slides span { text-align: left; display: inline-block; } p, li { font-size: 0.88em !important; } li>p { font-size: 1em !important; } </style> # JuliaTokai #15 (2023/06/25) ###### tags: `JuliaTokai` `prezentation` --- # IntervalSets.jlの話 [堀川 由人, ほりたみゅ, @Hyrodium](https://hyrodium.github.io/ja) ---- ### おしながき * 自己紹介 * IntervalSets.jlの概要 * IntervalSets.jlの不満点 * 今後の開発予定 * まとめ --- ## 自己紹介 Juliaのパッケージの開発やってます * 自作パッケージ * [BasicBSpline.jl](https://github.com/hyrodium/BasicBSpline.jl) * [ImageClipboard.jl](https://github.com/hyrodium/ImageClipboard.jl) * メンテナンス権限もらっているもの * [FastGaussQuadrature.jl](https://github.com/JuliaApproximation/FastGaussQuadrature.jl) * [Rotations.jl](https://github.com/JuliaGeometry/Rotations.jl) * [IntervalSets.jl](https://github.com/JuliaMath/IntervalSets.jl) * [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) * [StaticArraysCore.jl](https://github.com/JuliaArrays/StaticArraysCore.jl) * [Quaternions.jl](https://github.com/JuliaGeometry/Quaternions.jl) * [Octonions.jl](https://github.com/JuliaGeometry/Octonions.jl) ---- 初めての[JuliaパッケージPR](https://github.com/JuliaMath/IntervalSets.jl/pull/62)がIntervalSets.jl ![](https://hackmd.io/_uploads/rJO4gVHdn.png =650x) (中略) ![](https://hackmd.io/_uploads/rJzSeNrO3.png =650x) --- ## IntervalSets.jlの概要 * コンストラクタ * `in` * `issubset` * `union`, `intersection` * その他 ---- ### コンストラクタ ```julia julia> 1..2 1..2 julia> OpenInterval(1,2) 1..2 (open) julia> Interval{:open, :closed}(1,2) 1..2 (open–closed) julia> typeof(1..2) ClosedInterval{Int64} (alias for Interval{:closed, :closed, Int64}) ``` ---- ### `in` 要素判定 ```julia julia> 1 in 1..2 true julia> 1 in OpenInterval(1..2) false ``` ---- ### `issubset` 部分集合 ```julia julia> 1..2 ⊆ 1..2 true julia> 1..2 ⊆ 1..3 true julia> -2..2 ⊆ 1..3 false ``` ---- ### `union`, `intesection` 和集合と積集合 ```julia julia> union(1..3, 2..5) 1..5 julia> (2..3) ∩ (1.2 .. 3.4) 2.0..3.0 julia> (2..3) ∩ (1.2..3.4) 2.0..3.0 julia> (1..3) ∩ (1.2..3.4) 1.2..3.0 ``` ---- ### その他 ```julia julia> mod(pi, 1..2) 1.1415926535897931 julia> isleftopen(1..2) false julia> isrightclosed(1..2) true julia> isempty(2..1) true julia> rand(3..4) 3.733701022595097 ``` --- ## IntervalSets.jlの不満点 * 順序構造の保証が無い * 型不安定性 * 連結な集合しか扱えない * `eltype`の謎 * Intervals.jlもある ---- ### 順序構造の保証が無い ```julia julia> 'a'..'h' a..h julia> 'c' in 'a'..'h' true julia> 'z' in 'a'..'h' false julia> (1+im)..2 1 + 1im..2 + 0im julia> 1 in (1+im)..2 ERROR: MethodError: no method matching isless(::Complex{Int64}, ::Int64) ``` `isless`が定義された型のみ許すコンストラクタが無い ---- ### 型不安定性 ```julia julia> (1..3) ∩ OpenInterval(1,2) 1..2 (open) julia> (1..2) ∩ OpenInterval(1,3) 1..2 (open–closed) julia> typeof((1..3) ∩ OpenInterval(1,2)) OpenInterval{Int64} (alias for Interval{:open, :open, Int64}) julia> typeof((1..2) ∩ OpenInterval(1,3)) Interval{:open, :closed, Int64} ``` 型パラメータに端点の開閉が含まれている ---- ### 有界かつ連結な区間しか扱えない ```julia julia> (1..2) ∪ (3..4) ERROR: ArgumentError: Cannot construct union of disjoint sets. Stacktrace: [1] union(d1::ClosedInterval{Int64}, d2::ClosedInterval{Int64}) @ IntervalSets ~/.julia/packages/IntervalSets/voJZA/src/interval.jl:127 [2] top-level scope @ REPL[43]:1 julia> 1..Inf # Infの無い型には適用不可能 1.0..Inf ``` ---- ### `eltype`の謎 ```julia julia> eltype(1..2) Int64 julia> 1.5 in 1..2 true ``` そもそも`eltype`は定義されない方が良いのでは…?:thinking_face: ---- ### Intervals.jlもある ![](https://hackmd.io/_uploads/SkuevErOn.png =500x) ![](https://hackmd.io/_uploads/r1VWvVHu2.png =500x) --- ### 今後の開発予定 * 無限区間への対応 ([#123](https://github.com/JuliaMath/IntervalSets.jl/issues/123)) * `setdiff`などの操作の追加 ([#106](https://github.com/JuliaMath/IntervalSets.jl/issues/106)) * 型パラメータから開閉を除いた型の追加 ([#143](https://github.com/JuliaMath/IntervalSets.jl/issues/143)) * Intervals.jlとの統合 ([#67](https://github.com/JuliaMath/IntervalSets.jl/issues/67)) * `eltype`の削除? ([#115](https://github.com/JuliaMath/IntervalSets.jl/issues/115)) --- ## まとめ * 区間を扱うだけでも考えることが色々ある * `Base`の関数にメソッドを追加する基準が謎 * とくに`eltype` * Julia・OSS活動楽しい! --- ## 宣伝 * JuliaCon2023 * 日程: 2023/07/25 - 2023/07/29 * 「Creating smooth surface models with ElasticSurfaceEmbedding.jl」というタイトルで発表予定です。 * [個別ページ](https://pretalx.com/juliacon2023/talk/RBHAER/), [イベントページ](https://juliacon.org/2023/) * 博物ふぇすてぃばる!9 * 日程: 2023/07/22 - 2023/07/23 * [螺鈿屋ロイローニ](https://twitter.com/loilouni)さんと共同出展で物販する予定です。(出展は土曜のみ) * [個別ページ](http://hakubutufesshoukai.blog.fc2.com/blog-entry-2623.html), [イベントページ](https://www.hakubutufes.info/) * 数学と物理におけるJuliaの活用 * 日程: 2023/07/10 - 2023/07/12 * 場所: 九州大学伊都キャンパス マス・フォア・インダストリ研究所 * 「BasicBSpline.jlで始めるB-spline」というタイトルで発表予定です。 * [イベントページ](https://akio-tomiya.github.io/julia_imi_workshop2023/)
{"title":"JuliaTokai#15","breaks":true,"lang":"ja","dir":"ltr","robots":"noindex, nofollow","slideOptions":"{\"theme\":\"white\",\"transition\":\"slide\"}","description":"堀川 由人, ほりたみゅ, @Hyrodium","contributors":"[{\"id\":\"41421433-16a1-4a57-ac11-6f7b7becb765\",\"add\":6095,\"del\":334}]"}
    227 views