Re: [Factor-talk] Let's fix yosefk's tricky code
Interesting! But what does the (x.) and (-.) words do? Multiply and subtract in floating point. Factor obviates such distinctions with dynamic typing. -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Let's fix yosefk's tricky code
It seems like most of the overhead comes from fixed-point arithmetic, actually. Here’s a translation to Kitten with locals: On Wed, Aug 13, 2014 at 12:09 PM, Björn Lindqvist bjou...@gmail.com wrote: Hello everybody, Here is an interesting blog post from yosefk about Forth and stack machines: http://yosefk.com/blog/my-history-with-forth-stack-machines.html It contains a lot of interesting stuff but one part in particular got my interest. He is trying to write a word to compute the mean and the standard deviation of a vector given the sum of its elements, the sum of their squares, and the inverse of its length and what he produces to solve it is: : mean_std ( sum2 sum inv_len -- mean std ) \ precise_mean = sum * inv_len; tuck u* \ sum2 inv_len precise_mean \ mean = precise_mean FRAC; dup FRAC rshift -rot3 \ mean sum2 inv_len precise_mean \ var = (((unsigned long long)sum2 * inv_len) FRAC) - (precise_mean * precise_mean (FRAC*2)); dup um* nip FRAC 2 * 32 - rshift -rot \ mean precise_mean^2 sum2 inv_len um* 32 FRAC - lshift swap FRAC rshift or \ mean precise_mean^2 sum*inv_len swap - isqrt \ mean std ; So his code is hideous and I'm wondering if we can do it better in Factor? I'd love to take a stab at it myself but I have no idea what mathematical formula he is implementing. Anyone knows? As far as I understand, given three scalar values: the sum of all elements in a vector, the sum of all elements squared and the inverse of the length, you should be able to calculate the mean of the vector and the standard deviation. -- mvh/best regards Björn Lindqvist -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Let's fix yosefk's tricky code
Sigh. The formatting button in Gmail is directly next to the “Send” button. Apologies, list. It seems like most of the overhead comes from fixed-point arithmetic, actually. Here’s a translation to Kitten with locals: def meanStd (float float float → float float): → sum2 sum invLen; sum ×. invLen → μ; μ (sum2 ×. invLen −. μ square) sqrt You can write this in postfix: def meanStd (float float float → float float): → sum2 sum invLen; sum invLen (×.) → μ; μ sum2 invLen (×.) μ square (−.) sqrt Then easily eliminate μ: def meanStd (float float float → float float): → sum2 sum invLen; sum invLen (×.) dup { sum2 invLen (×.) } dip square (−.) sqrt I see no need to eliminate the named parameters, and if this were using fixed-point arithmetic, I would make separate arithmetic words to handle the shifting. It’s worth noting that swapping “sum” and “sum2” could give a nicer translation, since “sum” is used first; and that multiplying by the inverse-length is repeated. Also, not all Kitten is so Unicode-heavy, but in toy code, why not? :) -- ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Status of Factor
I was a little astonished that there is no book etc. available, since the language is now also a couple of years out there. These things take time, effort, and expertise. The intersection of people will all these things is small. So there’s no book (yet!) because nobody happens to have written one. Though Factor does have a chapter in the upcoming “Seven More Languages in Seven Weeks”[1]. My question would be is Factor still in active development (bug fixes) and is still a 1.0 release planned? It certainly appears alive. A majority of the recent commits have been made by Doug Coleman (erg), John Benediktsson (mrjbq7), and Björn Lindqvist (bjourne). Progress is being made on the 0.97 release[2], but disappointingly the release after 0.99 is being called 0.100. Will it ever end? [1]: http://pragprog.com/book/7lang/seven-more-languages-in-seven-weeks [2]: https://github.com/slavapestov/factor/milestones -- Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] What exactly is the retain stack?
So the retain stack is useless? Freeing up a whole register sounds like it should be great for performance, at least on 32 bit x86. You can make a complete stack-based concatenative language with only one stack. But some combinators are implemented more efficiently when you have scratch space to use. Here are some pseudocode reductions. You can implement “dip” as “swap quote cat apply”: 1 2 3 [ + ] dip 1 2 3 [ + ] swap quote cat apply 1 2 [ + ] 3 quote cat apply 1 2 [ + ] [ 3 ] cat apply 1 2 [ + 3 ] apply 3 3 Or you can implement it as “swap retain apply restore”: 1 2 3 [ + ] dip 1 2 3 [ + ] swap retain apply restore 1 2 [ + ] 3 retain apply restore 1 2 [ + ] apply restore 3 restore 3 3 In the former case, you had to allocate a quotation and concatenate two quotations. These can of course be optimised out, but a retain stack has a more efficient naïve operational semantics, and having a “spare” stack for temporary use makes some code a lot nicer without needing to go as far as introducing local variables. -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] What exactly is the retain stack?
Is that it's only use? Then why? dip can easily be formulated using non-retain stack using primitives: For example: a b c [ append ] dip - a b c -rot append swap That implementation assumes the quotation takes two operands and produces one result, which is not always the case. More generally, the functional argument of “dip” is not really supposed to be able to touch the argument it’s operating under. If you don’t have types or a stack checker enforcing this, the formulations with a retain stack or dynamically composing quotations are safe by construction, but the “-rot” version is not. Consider “[ 3drop ] dip” or “[ append dup ] dip”. You can easily describe the constraint with a type dependent on the arity of the argument type, though. In the current state of Kitten: dip :: ∀R S a. (R a (R → S) → S a) -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] What exactly is the retain stack?
In the current state of Kitten: Oop, correction: this is not Kitten syntax. I had been writing in Kitten but decided against it, then forgot to update the text. Current Kitten would be: def dip {.r, .s, a}(.r a (.r - .s) - .s a): … But this is a Factor mailing list. ;) -- Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free. http://p.sf.net/sfu/SauceLabs ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk