TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Concise algorithms written in Julia

207 点作者 thetwentyone将近 4 年前

17 条评论

fgdelcueto将近 4 年前
They are indeed concise and beautiful, but some of the implementations I checked are quite naïve. They&#x27;re great for academic purposes and for some simple problems they will work just fine, but I would advise against using them for real-world problems.<p>For instance, for some of the regression algorithms the pseudo-inverse of the matrix is used to solve the normal equations. Again, for small, well-behaved problems it is OK, but for larger scale, less well-behaved problems, it is actually dangerous (numerical instabilities and other issues). There are better, faster, more stable approaches. (PhD in Applied Math here)<p>BTW, I have been using Julia for work for several years now and I think it is a fantastic language for scientific computing. For those who use Matlab&#x2F;Numpy regularly, you should definitely check it out.
评论 #27785277 未加载
评论 #27795023 未加载
todd8将近 4 年前
My first degree was in math. I&#x27;ve frequently discovered that I don&#x27;t understand the notation in math papers. What does the paper mean by the harpoon (↼ arrow with half its arrowhead) and how is it different than the waved arrow (⬿ arrow with a wavy shaft)? Each discipline has its own conventions, is the backslash a set difference operator or is it matrix division. Is alpha, α, an angle in some trig equation or is it the minimum assured score value in alpha-beta pruning? It takes a bit of time to dive into a math paper. Even the universally understood symbol for integration (∫) can mean different things. Is it Riemann integration or is it Lebesgue integration? Is it symbolic or is it a numerical approximation. It depends upon context, and the context is communicated between mathematicians by the subject of the course, the preceding results in or paper, or just a few asides by a professor giving a lecture.<p>Computer scientists (I&#x27;ve been one for roughly 50 years) introduce their own academic notations. Is circled plus, ⊕, a boolean exclusive-or or is it bitwise exclusive-or. Take a look at Knuth Vol 4A, it&#x27;s chock full of mathematical notations embedded in algorithms. He uses superscripts that are themselves superscripts, how are those supposed to be entered with our text editors?. What about sequence notations like 1, 4, 9, 16, ... we might suppose that it is just the integer squares, but the <i>On-line Encyclopedia of Integer Sequences</i> lists 187 other possibilities. Is the compiler supposed to guess what this is?<p>Well, if mathematicians use these concise notations, why shouldn&#x27;t programmers? I believe it is because mathematicians don&#x27;t want or need to take the time and space needed to spell out these operators, variables, and functions in their papers. It&#x27;s not necessary for mathematicians. Other specialists in their field can figure out what the symbols mean while reading their papers. Their students can understand what a blackboard capital F (𝔽), likely a field in a class on abstract algebra.<p>Programmers are doing something different. Their programs are going to be a lot longer than most math papers or lecture expositions. The programs have to deal with data, networks, business rules, hardware limits, etc. And everything in a program must be unambiguous and precise. Programs are large and can be edited many times by many people. For these reasons, I&#x27;m inclined to favor programing in plain language with plain ascii.<p>See:<p>Knuth, <i>The Art of Computer Programming Vol 4A, Combinatorial Algorithms</i><p><i>The on-line encyclopedia of integer sequences</i>, <a href="https:&#x2F;&#x2F;oeis.org" rel="nofollow">https:&#x2F;&#x2F;oeis.org</a>
评论 #27787588 未加载
评论 #27788938 未加载
FabHK将近 4 年前
Not a Julia expert, but these snippets don’t strike me as very idiomatic or algorithmically sound [1].<p>What they seem to do, instead, is to demonstrate that you can write code in Julia that is quite close to the mathematical notation. (Whether you should do so is another question).<p>[1] for example, adding a row of ones to a matrix by using array comprehension:<p><pre><code> 𝐗 = [j==0 ? 1.0 : X[i][j] for i in 1:m, j in 0:n] </code></pre> or solving a linear system by multiplying with the (pseudo-)inverse:<p><pre><code> 𝛉 = pinv(𝐗)\*y</code></pre>
gugagore将近 4 年前
I do think Julia is uniquely poised to provide a new kind of trade-off between concision, performance, understandability, etc. because of multiple dispatch, and great syntax for things like broadcasting.<p>Sometimes a practical algorithm does not look like a textbook algorithm, because they&#x27;re different algorithms, but I think the main reason that there is such a discrepancy is:<p>1. math notation is many times quite ambiguous<p>2. there are a bunch of performance optimizations that end up being unsightly<p>I am not claiming it&#x27;s easy work, but I think it&#x27;s nice to try to find abstractions so that at least somewhere, the algorithm looks simple.<p>I don&#x27;t, however, think that these code examples really make that shine <i>at all</i>. There are also choices I disagree with. For example, there is (paraphrasing) `map(vⱼ -&gt; g(x, vⱼ), V)`. the `j` subscript is meaningless to me, and is an awkward combination of &quot;point free&quot; &#x2F; &quot;index free&quot; notation with a higher-order function, and a more traditional spelling. Math texts love to do things like V = [v_1, ... , v_n]. That doesn&#x27;t make sense to do in a programming language. instead of writing v_j, you just do V[j].
评论 #27785639 未加载
评论 #27786101 未加载
评论 #27785577 未加载
rmah将近 4 年前
I think it&#x27;s very interesting how some people are repulsed by the use of mathematical symbols in the sample code. While others love it.<p>The vast majority of the code I write is not mathy. But I do write a fair bit of mathy code because of the field I operate in. Because of this, I&#x27;d side with the ones that hate it for some of these algos: the various sorts, for example. But for others, the use of mathematical symbols brings clarity, IMO. Assuming you already know the algo.<p>I&#x27;ve had to translate mathematical notation from a set of papers into code before. When I first picked up Julia, I re-did something I had previously done in Python&#x2F;pandas&#x2F;numpy. I used mathy notation... and julia code, ended up both MUCH clearer and quite a bit faster. I call that a win in my book.
评论 #27788958 未加载
aimor将近 4 年前
One of the things I like about code is that it&#x27;s usually very easy to read. There are problems with characters like 1 l I 0 O i j etc that are addressed by font choices. But even with those problems I find it much easier to read the ASCII letters than math notation with subscripts and superscripts, Greek letters and script letters, bold and doubled, and so on.<p>People might deny having the same problem, but I&#x27;ve seen it hundreds of times where a mistake is made because two symbols were conflated or a subscript was overlooked, or a symbol with multiple uses in different contexts was assumed to be one thing when really it was another. That said it&#x27;s still neat to see code using common symbols with what you&#x27;d find in textbooks.
chairmanwow1将近 4 年前
I&#x27;m not sure I understand the premise here. One letter variable and function names do not strike me as beautiful, but needlessly obtuse.
评论 #27784582 未加载
评论 #27784540 未加载
评论 #27786786 未加载
评论 #27784984 未加载
DNF2将近 4 年前
Obviously, these code samples are meant only for aesthetic display, not for their pedagogical value. The criticisms being leveled by some here could be valid if their target had a different purpose. As it is, they miss the purpose and their mark.
cs702将近 4 年前
Beautiful indeed, even though the screenshots generated by Carbon do not look right on Firefox 89.0.2 64-bit on Ubuntu 20.04.
la_fayette将近 4 年前
Hm, looks like math formulas... You could use any programming language and use one letter UTF-8 variable names and try to fit everything in one line...
generalizations将近 4 年前
By the way, on the subject of single-character variables, is there a list somewhere of the single-letter math symbols that julia supports? (e.g. multiply, divide, sigma, etc)
评论 #27785429 未加载
andi999将近 4 年前
&quot;A bunch of algorithms, never used.&quot; - E.Hemingway
taeric将近 4 年前
The image for Huffman coding has, I assume, a bug.
评论 #27785102 未加载
jstx1将近 4 年前
- one-letter variable names<p>- Greek letters<p>- glyphs with obscure latex codes<p>The last one in particular - how do you read this in your mind if you don&#x27;t already know the name of the character? - &quot;Hmm, that&#x27;s a curly handwritten A&quot;. It&#x27;s so disruptive to the thought process of the reader of your code if they don&#x27;t already know the notation.<p>I really think that this is the opposite of beautiful. Code is about communicating with other people too. I also think that mixing code and math notation is liked by a vocal minority of Julia users but in the long term is harming the adoption of the language by beginners.
评论 #27784999 未加载
评论 #27785006 未加载
评论 #27784912 未加载
评论 #27785280 未加载
评论 #27784965 未加载
评论 #27785474 未加载
评论 #27785892 未加载
评论 #27785746 未加载
评论 #27785341 未加载
评论 #27786027 未加载
jdeaton将近 4 年前
Gross.
papito将近 4 年前
It&#x27;s like Perl, only horrible &#x2F;s
thom将近 4 年前
Well, now I can at least understand what it feels like to look at Lisp and hate all the parentheses, so I&#x27;m trying to temper my immediate repulsion a little. But no, absolutely not. I would code a pre-commit hook to reject these on the first attempt, and send you your P45 on the second, sorry.
评论 #27799897 未加载