JuliaBox は相変わらず Sorry, an unexpected error occured. Please try after some time. なので仕方なくANACONDA で Jupiter Notebook で Julia 0.6.2 を試してみるなど
JuliaBoxは相変わらず使えない。
色々気になっている事
- ANACONDA, Conda, Jupyter, Jupyter Notebook とは結局のところ何か
- Python 用なのに何故 julia でも使えるのか
- 名称での大文字と小文字の使い分けの意味合いは
があるけどまぁどうでも良いので使ってみよう。
- Rのように中身がぐちゃぐちゃでなく
- Rubyのように遅くなく
- Lispのように原始的またはエレファントでなく
- Prologのように変態的なところはなく
- ScalaやClojureについては Javaのように硬すぎることはなく
- Haskellのように抽象的すぎない
らしい。分かるような判らないような。
ただruby より高速とかLispやPrologが引き合いに出されるところが唆られる。
環境はMacBookProRatina13inch2015で未だSiera。
昨年ANACONDAやらJupyterやらjuliaやら諸々を整備済み。
昨日juliaの0.6.2をdmgでダウンロードして解凍してアプリケーションに入れる。
も,Jupyter Notebookでは0.6.2が選べずググった挙句 ターミナルで
Pkg.add("IJulia")
を施すと選べるようになった。(魔法の呪文)
- IJulia, IPython,... とは結局のところ何か。(使ってないけどIRもあるのか。)
- 名称での大文字と小文字の使い分けの意味合いは
- Package ってTeXでもパッケージという言い方が主流だけどどんな意味合い?
- それより何より,何がIJuliaというパッケージをどこに加えてるの?
- そもそも「加える」ってどんな意味合い?
などと再びモクモクと沸き起こる謎は傍に置いておこう。
- ANACONDAをLaunchpadから立ち上げる
- ターミナルの窓が勝手に開き何やらもごもごした挙句SafariがHomeというページを開く
- このHomeはlocalhost。つまりFinderみたいなもの(か)。
- Folderやらファイル名が列挙されてる。
- |Files / Running / Clusters / Nbextensions| という選択肢のうちのFilesが選ばれている状態。
- その状態で,右の方の |New▼| というメニュを開けると,僕の環境だと| Julia 0.5.2 / Julia 0.6.2 / Python 3 | が選べる。もちろん今回は | Julia 0.6.2 | を選ぶわけだ。
- するとSafariが別窓というかタブを開けて| untitled |というjuliaのインタプリタ的なnoteが開く。
- MathematicaやMapleなどの数式処理系に馴染みがあると何か誤解しそうなインターフェイス。
さてさてでは実際に動かしてみよう。
In[ ] :
と書いた小窓があるのでここに何かを打つ。
In[ ] :2^100
とか打ってみる。
そして shift+return する。
すると,0と表示される。あれ?と思うがこれを
In[ ] :2^60
に変えてshift+returnすれば,ちゃんと
In[ 2 ] : 2^60 Out[ 2 ] : 1152921504606846976
と正しそうな(なんせ確かめてないし覚えてもいない)値が返ってくる。
早速気になっている組み合わせや順列を試してみよう。
昨日はcombinations( lst , n )が通らなかった。
juliaとcombinationでググると出てくるArrays — Julia Language 0.4.8-pre documentation
を見たら,素っ気なく
combinations(array, n) Generate all combinations of n elements from an indexable object. Because the number of combinations can be very large, this function returns an iterator object. Use collect(combinations(array,n)) to get an array of all combinations.
と書いてあるのだけどエラーが出る。
そこで,
Pkg.add("Combinatorics")
をしておいた。これで組み合わせ関連のパッケージが付加されるらしい。
でも今日も矢張りエラーだ。
using Combinatorics
を先に実行しないとダメなようだ。
そこで,またもやググると Introducing Julia/Arrays and tuples - Wikibooks, open books for an open world が出てきた。ふむふむ。
There are functions in the Combinatorics.jl package that let you find combinations and permutations of arrays. combinations() finds all the possible combinations of elements in an array: you can specify how many elements in each combination:
julia> Pkg.add("Combinatorics") # (do this just once) julia> using Combinatoricshttps://en.wikibooks.org/wiki/Introducing_Julia/Arrays_and_tuples
そっか,どうもusing Combinatoricsを毎度施さないと駄目らしい。
ライブラリ感覚だなぁ。
そんなわけで,
In[ 3 ] : using Combinatorics
として shift+return すれば,
INFO: Precompiling module Combinatorics.
と INFO が表示され多分これで使えそうな雰囲気が醸し出される。
ではいよいよ。
In[ 4 ] : lst=[1,2,3,4] collect(combinations(lst, 3))
そうそう。一度に複数行入力できるよ。
そして shift+return する。
Out[ 4 ] : 4-element Array{Array{Int64,1},1}: [1, 2, 3] [1, 2, 4] [1, 3, 4] [2, 3, 4]
となる。なるほど。
こんな事もできる。所謂分割数の列挙だ。
In[ 5 ] : collect(partitions(6)) Out[ 5 ] : 11-element Array{Any,1}: [6] [5, 1] [4, 2] [4, 1, 1] [3, 3] [3, 2, 1] [3, 1, 1, 1] [2, 2, 2] [2, 2, 1, 1] [2, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1]
上のは6の分割の列挙だけど,次のようにArrayを直接複数のArrayに分割する事も楽々できるらしい。
In[ 6 ] : collect(partitions([1,2,4,7])) Out[ 6 ] : 15-element Array{Any,1}: Array{Int64,1}[[1, 2, 4, 7]] Array{Int64,1}[[1, 2, 4], [7]] Array{Int64,1}[[1, 2, 7], [4]] Array{Int64,1}[[1, 2], [4, 7]] Array{Int64,1}[[1, 2], [4], [7]] Array{Int64,1}[[1, 4, 7], [2]] Array{Int64,1}[[1, 4], [2, 7]] Array{Int64,1}[[1, 4], [2], [7]] Array{Int64,1}[[1, 7], [2, 4]] Array{Int64,1}[[1], [2, 4, 7]] Array{Int64,1}[[1], [2, 4], [7]] Array{Int64,1}[[1, 7], [2], [4]] Array{Int64,1}[[1], [2, 7], [4]] Array{Int64,1}[[1], [2], [4, 7]] Array{Int64,1}[[1], [2], [4], [7]]
そうなると同じ数を含んだArrayだとどうなるかきになるのだけど
In[ 7 ] : collect(partitions([1,4,4])) Out[ 7 ] : 5-element Array{Any,1}: Array{Int64,1}[[1, 4, 4]] Array{Int64,1}[[1, 4], [4]] Array{Int64,1}[[1, 4], [4]] Array{Int64,1}[[1], [4, 4]] Array{Int64,1}[[1], [4], [4]]
という感じで何というか期待したようにはならなかった。
まぁ分割の作法からは言えば当然かとは思う。
取り敢えずここまでにしておこう。