From: Lucian Mogosanu Date: Fri, 19 Jan 2018 16:03:00 +0000 (+0200) Subject: posts: 069, 06a X-Git-Tag: v0.10~3 X-Git-Url: https://git.mogosanu.ro/?a=commitdiff_plain;h=519cc3edd725b1428750b0b676bbf75fb4e459b8;p=thetarpit.git posts: 069, 06a --- diff --git a/posts/y04/069-on-intellectual-ownership.markdown b/posts/y04/069-on-intellectual-ownership.markdown new file mode 100644 index 0000000..638473a --- /dev/null +++ b/posts/y04/069-on-intellectual-ownership.markdown @@ -0,0 +1,166 @@ +--- +postid: 069 +title: On intellectual ownership +date: January 15, 2018 +author: Lucian Mogoșanu +tags: cogitatio +--- + +Recently -- while I was busy getting out of +[one particular swamp][doctorate], to be more precise -- stuff has +happened, of which I will remind two events: Stanislav began writing his +epic [FFA series][ffa], and Diana introduced her very own +[reference code shelf][diana-code-shelf], to which she has already added +a few pieces. I find the latter to be particularly interesting: while +almost everyone has "an opinion" regarding, say, the software they use, +in the sense every Romanian has an opinion on politics and football, in +the very sense everyone has a butthole -- while this is so, few +individuals would claim any sort of responsibility for the items they so +judge. In fact, nowadays anyone at all rarely claims any responsibility +on any piece of "intellectual property" (whether written by them or +otherwise), to the extent that by now you're willingly getting fucked in +the ass by various [Googles][google], Microsofts, Apples and so on. + +Unfortunately for the variouses above, [V][v-genesis] exists today. In +practice this means that as the author of, say, a piece of code, you're +either prepared to put your ass on the line[^1] with respect to the item +and its intellectual honesty, or bust. The [orcs][orcs] and the +[wreckers][wreckers] might put some value on your attempts, but everyone +else -- that is, [your betters][betters] -- won't. + +This model works in some sense backwards from what today's so-called +"civilized world" deems to be "intellectual property". "Traditionally", +software is written by some nobodies toiling in nondescript swamps, then +is put a label on, then is sold[^2] as the premier "operating system", +"cloud management system", "app" or some other +[useless ambiguity][unambiguous]. But that's not all: given that putting +intellectual items on the market is a rather iffy matter, you're not +exactly sold the software, but the so-called rights to use said product +in some way or another, which typically includes the explicit +prohibition of reverse engineering `$thing`, even if, say, `$thing` +becomes obsolete within the year -- which it typically does. + +Or, to [quote a wise man][software-licensing]: + +> Similarly, "net neutrality" is not in any way related to network +> freedom. To best understand the competing paradigms : the artificial +> perspective - as proposed by the obsolete governments and the rest of +> the numerously various paper fiat arrays - revolves around the +> "rights" of the "owners" of hardware, and the "intentions" of the +> writers of software. In this perspective, using a computer "against +> the will of its owner", even if you're using it exactly in the manner +> it allows itself to be used, is "criminal" whatever that may mean +> anymore. +> +> Exactly contrary to that, the natural perspective : if you don't want +> me to use your server to print all the nude photos your users +> entrusted you, write your software and provision your hardware in such +> a way that I can't. Because if I can, then it is not my right but my +> freedom to do so. +> +> A parallel with human sexuality is not unwarranted here. At a past +> time when the ownership of female humans was the principal method to +> control capital formation and the political process, the same sort of +> dead hand fictions proposed that they in fact control the usage of +> women, that anyone owning a woman does so only as a sublicense from +> their sovereign ownership of all women, and may proceed only in +> furtherance of the regulation they emitted as to how women may be used +> and may not be used and so on and so forth. Specifically excluded from +> all this - the woman in question. Particularly "criminal" at the +> time - using a woman in the manner she herself wishes to be used. +> +> Times have changed, women are now worthless, but computers aren't, and +> these same dead hand fictions propose anew : that they own all +> computers, that if you own a computer it's only a sublease from them, +> subject to furthering their regulations and so on and so +> forth. Specifically excluded from all this - what the code actually +> says and does. Particularly "criminal" - using a computer in the +> manner it itself allows to be used. + +This then brings us to the fundamental question of our essay: how do we +define ownership? and in particular what does intellectual ownership +mean? + +Physical ownership is pretty straightforward. Given an arbitrary +`$object`, the proximate genus for ownership is control over said +`$object`: for example, in order to get from home to work, I could +either drive the `$object` that I have chosen to call "my car" or call +for another `$object` named a taxi. The specific difference is +exclusiveness in my relation to `$object`: others may or may not call +the same taxi at some point, but I am the only one who can use my car, +based on my own claim above anything else. This is for example what I +mean when I say that I would rather, at all costs, have my own computing +machines than rely on the inherently unreliable [cloud][cloud]. + +Intellectual ownership, that is, the ownership of an `$object` lying in +the realm of thought, is however an entirely different matter. Take for +example any non-trivial[^3] piece of knowledge, such as Shakespeare's +Othello or Thales' theorem. You may acknowledge their existence, know +where to put them in the great tree, maybe even have a vague idea about +their meaning; this is the proximate genus, and assuming you've been +through school, you probably know about a great deal of the intellectual +items ever conceived by humanity. The specific difference however refers +not merely to "knowing about" `$object`, but to devouring it entirely, +such that you understand all the intimate aspects of `$object`, its very +author becoming part of your internal conversation on the item in +question. + +This is then what I mean when I say that I own something +intellectual(ly): that I have read it[^4] carefully and that I +believe[^5] to have understood it in its entirety. In fact I am +unconvinced there exists any other kind of intellectual ownership; but +go ahead and humour me if you think otherwise. + +As a consequence, I have decided to open my own store of +[signed intellectual artifacts][mogosanu-v]. The linked page contains a +bunch of [V][v-intro] patches, the seals as generated by their original +author(s) and, added, my own signatures. At the time of writing the list +is quite modest, which only means that there's plenty of room for it to +grow into a repository of knowledge. So here's to that! + +[^1]: Or, to put this more mildly, your "skin in the game". + +[^2]: Not always for money. In fact, chances are you've already sold + [your freedom][freedom] for this-or-that very awesome smartphone + and/or phablet and/or smart always-connected device you supposedly + own. + +[^3]: We disregard trivial pieces of knowledge not because they're + merely failed attempts to enrich the [library™][library] -- which, + to be perfectly clear, they are -- but because they're not very + interesting. Ask yourself now, how many of the works you've read so + far really do matter? + + Let's just hope you're young enough to catch up. + +[^4]: Or [watched it][video], or [heard it][music]. I do admit to + fitting a not-very-small musical library in my head, I just don't + see any reason to share it publicly at the moment. + +[^5]: Believe me or not, belief is an essential part of the whole + deal. You'd be surprised how many times I would read a book the + second or third (sometimes the fourth) time, only to discover things + I had missed on previous readings. And + [I'm not the first][re-reading] to observe this either! + + It's either worth reading twice or not at all, or how did the saying + go? + +[doctorate]: /posts/y03/063-doctorate.html +[ffa]: http://www.loper-os.org/?p=1913 +[diana-code-shelf]: http://www.dianacoman.com/2017/12/17/my-reference-code-shelf/ +[google]: /posts/y02/046-google-is-making-you-stupid.html +[v-genesis]: http://trilema.com/2016/the-v-manual-genesis/ +[orcs]: http://btcbase.org/log-search?q=orcs +[wreckers]: http://btcbase.org/log-search?q=wreckers +[betters]: http://trilema.com/2017/heres-why-you-will-end-your-days-in-a-concentration-camp/#selection-853.0-857.92 +[freedom]: /posts/y03/04f-freedom-is-slavery.html +[unambiguous]: /posts/y03/052-on-the-unambiguous-usefulness-of-tools.html +[software-licensing]: http://trilema.com/2015/a-new-software-licensing-paradigm/ +[cloud]: /posts/y02/041-cloud-software-is-unreliable-ii.html +[library]: /posts/y01/038-the-archive.html +[video]: /tags/video.html +[music]: /posts/y00/020-on-the-difficulty-of-discussing-musical-works.html +[re-reading]: http://trilema.com/2017/re-reading-is-the-most-powerful-tool/ +[mogosanu-v]: http://lucian.mogosanu.ro/v/ +[v-intro]: http://cascadianhacker.com/07_v-tronics-101-a-gentle-introduction-to-the-most-serene-republic-of-bitcoins-cryptographically-backed-version-control-system diff --git a/posts/y04/06a-ffa-ch4-puzzle.markdown b/posts/y04/06a-ffa-ch4-puzzle.markdown new file mode 100644 index 0000000..f85248d --- /dev/null +++ b/posts/y04/06a-ffa-ch4-puzzle.markdown @@ -0,0 +1,314 @@ +--- +postid: 06a +title: A solution to the largest-of-seven FFACalc puzzle +date: January 19, 2018 +author: Lucian Mogoșanu +tags: tech +--- + +The solution itself is short and quite straightforward, so I'm not sure +it's qualified for a blog post of its own. Instead, I'm gonna use this +occasion to embellish it[^1] with a discussion of FFA (as far as I know +it at the time of writing) and a brief description of FFACalc, only then +followed by the solution to the puzzle given at the end of the +[fourth chapter][ffa-ch4] of Stanislav's [series][ffa]. + +FFA is, I quote: + +> [...] the Finite Field Arithmetic library. FFA differs from the +> typical "Open Sores" abomination, in that -- rather than trusting the +> author blindly with their lives -- prospective users are expected to +> read and fully understand every single line. In exactly the same +> manner that you would understand and pack your own parachute. The +> reader will assemble and test a working FFA with his own hands, and at +> the same time grasp the purpose of each moving part therein. + +That is, a library for performing arithmetic operations on arbitrarily +large numbers, in turn useful for things such as +[sane][software-engineering-iii] implementations of crypto +algorithms. "But wait, Lucian, there are implementations of crypto out +there already!" Yes, and none of them are sane, and yet you insist that +"there are", even though you haven't read the code[^2]. + +Anyway, by "sane" I mean very specifically items that you would run on +your car or in your nuclear plant (or any other safety-critical system); +and thus by "arbitrarily" I don't mean "however large", but "as large as +the operator specifies[^3], within constraints imposed by the iron". Or, +as seen in the [logs around 2016][preview]: + +> **asciilifeform**: sooooooo in other nyooz here's a small preview of +> things to come: +> **asciilifeform**: i discovered that mainstream finite field libs are +> as complicated as they are largely because they insist on growable - +> and, ergo, heap-allocated - nums. +> **mircea_popescu**: tbh, the heap should go away entirely. +> **mircea_popescu**: wtf is it even a thing for. +> **asciilifeform**: for items whose size you ~do not know~ in advance. +> **asciilifeform**: which - notably - integers used in crypto ARE NOT. +> **mircea_popescu**: this is not programming. +> **asciilifeform**: anyway +> pre-allocated-buffers-for-motherfucking-everything is sop in 'this +> must work' (e.g., avionics) world. +> **asciilifeform**: what is interesting is that - as far as i can +> tell - no one has ever published example of finite field system from +> such. +> **mircea_popescu**: hm. +> **asciilifeform**: 'there is a first time for everything' + +So how can one achieve such a thing? For one, the compiler and whatever +pieces of high-level language run-time there exist need to behave +deterministically, and provably so; this excludes every language with +garbage collected memory management[^4]. Assembly works, but it's not +portable; a subset of C should work, but unfortunately the C language +specification is a mess, and sane compilers are getting scarcer by the +day. Fortunately, other ALGOLs do a much better job at this, which is +how Stanislav chose (a very restricted subset of) [Ada][ada] as the +implementation tool. + +As previously mentioned, the core functionality of the FFA library +doesn't do much more besides addition, subtraction, etc.; its main +benefit being that it allows the programmer to cross the 64 bit limit, +or whatever the machine register size is. To keep things simple, FFA +contains a user-facing component, the small program called FFACalc. In +addition to being a small program, FFACalc is also a small stack-based +context-free[^5] language that can be used to "talk to" the FFA +arithmetron. + +The FFACalc in [Chapter 4][ffa-ch4] implements the following constructs: + +* comments, enclosed in parentheses, e.g. `( a comment )`; +* quotes, enclosed in square brackets, e.g. `[ bum ]`; as opposed to + comments, which are ignored completely, quotes are echoed to the + console; +* conditionals, enclosed in braces, e.g. `{[a]}{[b]}`; the example takes + the first FZ-sized word on the stack: if the word is zero, it prints + "b", otherwise it prints "a"; +* stack space allocation, e.g. `.` allocates one FZ-sized word on the + stack; +* insertion of hexadecimal values at the top of the stack, e.g. `.abcde` + allocates a FZ and inserts the value "abcde"; then the value can be + popped and printed using `#`, which leads us to e.g. `.abcde#` +* value duplication (`"` and `` ` ``), dropping (`_`), swapping (`'`); + `"` duplicates the top-most value, while `` ` `` ("over") does the + same for the second (starting from the top) value on the stack; +* comparison (`=`, `<`, `>`), e.g. `.1.2<` will push "1" and "2" on the + stack, then pop them, compare "1 < 2" and push the resulting value + ("0" for false, "1" for true) on the stack; +* arithmetic and logic operations (`-`, `+`, `&`, `|`, etc.); +* others, which the esteemed reader can find on his or her own by + reading the code. + +Now that we have the basics in place, let's take a look at the puzzle: + +> Write a FFACalc tape that will take seven numbers, presumed to be on +> the top of the stack, and return the largest. +> +> Your answer should work with any legal WIDTH, and any stack HEIGHT +> large enough to hold the working set. +> +> For instance, suppose file numbers.txt were to contain: +> +> ~~~~ +> .9.1.7.5.1.1.0 +> ~~~~ +> +> Then the following example invocation: +> +> ~~~~ +> cd ffacalc +> gprbuild +> cat numbers.txt youranswer.txt | ./bin/ffa_calc 256 16 +> ~~~~ +> +> ... should produce the output: +> +> ~~~~ +> 0000000000000000000000000000000000000000000000000000000000000009 +> ~~~~ +> +> ... and similarly for any other seven numbers. + +For our convenience, let's first specify the solution in a pseudo-code +(or quasi-natural) language. We have a stack off which we can pop items +and compare them. The algorithm would look something along the lines of: + +~~~~ +0. let S be our stack +1. pop S into Max +2. while S has elements +2. a. pop S into Candidate +2. b. if Candidate > Max then +2. c. | Max becomes Candidate +3. return Max +~~~~ + +Notice that we a. have a pure stack machine ("Candidate" and "Max" are +pseudo-variables that reside on the stack) and b. lack the means to loop +"while" or "until". However, we know that at step 0, the stack contains +precisely seven elements; thus it should be popped exactly seven times, +including the operation at step 1. Thus we can unroll our "while" loop +into precisely six comparisons. + +Given the FFACalc stack machine, steps 2.a-c can be expressed as: +compare the current two topmost elements on the stack and keep the +higher of the two. Let's assume for now that we push exactly two numbers +on the stack. Given that comparison and arithmetic operations are +destructive, we need to operate on copies of the two numbers, so the +first thing we need to do is "over" them (we also print the contents of +the stack): + +~~~~ +.2.1``#### +0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000002 +0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000002 +~~~~ + +So the next step would be to compare them using (conveniently) `<`: + +~~~~ +.2.1``<### +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000002 +~~~~ + +or + +~~~~ +.1.2``<### +0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000002 +0000000000000000000000000000000000000000000000000000000000000001 +~~~~ + +Now there are two approaches that we can take. Let's take the obvious +one first: based on the result of `<` at the top of the stack, we can +execute conditionally: + +~~~~ +.2.1``<{[a: ]#}{[b: ]#}## +b: 0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000002 +.1.2``<{[a: ]#}{[b: ]#}## +a: 0000000000000000000000000000000000000000000000000000000000000002 +0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000001 +~~~~ + +Notice that the second printed value is the conditional, and that it +gets printed *after* exiting the branch[^6]. So we just drop it: + +~~~~ +.2.1``<{[a: ]#}{[b: ]#}_# +b: 0000000000000000000000000000000000000000000000000000000000000001 +0000000000000000000000000000000000000000000000000000000000000002 +.1.2``<{[a: ]#}{[b: ]#}_# +a: 0000000000000000000000000000000000000000000000000000000000000002 +0000000000000000000000000000000000000000000000000000000000000001 +~~~~ + +So we notice that on the "if" branch (second execution), the largest +number is on the top of the stack, while on the "else" branch it's the +other way around. Thus, the correct reasoning is: if `S(SP - 1) < +S(SP)`, swap the two values and drop the first (i.e. the smaller value), +else just drop the first. That is: + +~~~~ +.2.1``<{'_}{_}_# +0000000000000000000000000000000000000000000000000000000000000002 +.1.2``<{'_}{_}_# +0000000000000000000000000000000000000000000000000000000000000002 +~~~~ + +Et voila! Extending this to a seven-number stack, we get: + +~~~~ +.9.1.7.5.1.1.0 +``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ +# +0000000000000000000000000000000000000000000000000000000000000009 +~~~~ + +This solution *works*, but the branches aren't "balanced", i.e. a +different number of operations are executed on each branch. We can solve +this quite elegantly by employing the mux (`U`) operation, whose +functionality is left as an exercise for the reader. The solution for +two numbers is: + +~~~~ +.2.1`` destroy both operands, whereas we want to destroy only +the lower of them. So first, we duplicate both operands, using 'over'; +then we compare and conditionally keep the higher of the two, a la: ) + +``<{'_}{_}_ + +( Note that '<' is Stack(SP - 1) < Stack(SP); thus, if the topmost word +is higher, we swap the two words and drop; else we just drop. Either +way, the lowest of the two is derped. ) + +( Now we just repeat this five more times (six comparisons in total). ) + +``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ ``<{'_}{_}_ + +( And we print. ) + +#