The Intellectual Wilderness There is nothing more useless than doing efficiently that which should not be done at all.

2019.11.21 17:24

Testing Textually Composed Numbers for Primality

Filed under: Computing,Science & Tech — Tags: , , , , , — zxq9 @ 17:24

Last night on Twitter one of my favorite accounts, @fermatslibrary, put up an interesting post:

Start at 82 and write it down, then 81, write that down, etc. until you reach one, and you’ve written a (huge) prime number. Wow!

This seemed so strange to me, so of course I got curious:

After some doodling around I wrote a script that checks whether numbers constructed by the method above are prime numbers when the number construction is performed in various numeric bases (from 2 to 36, limited to 36 because for now I’m cheating using Erlang’s integer_to_list/2). It prints the results to the screen as the process handling each base finishes and writes a text file “texty_primes-result-[timestamp].eterms” at the end for convenience so you can use file:consult/1 on it later to mess around.

There are a few strange aspects to large primes, one of them being that checking whether or not they are prime can be a computationally intense task (and nobody knows a shortcut to this). To this end I wrote the Miller-Rabin primality test into the script and allow the caller to decide how many rounds of Miller-Rabin to run against the numbers to check them. So far the numbers that have come out have matched what is expected, but once the numbers get extremely large (and they get pretty big in a hurry!) there is only some degree of confidence that they are really prime, so don’t take the output as gospel.

I wrote the program in Erlang as an escript, so if you want to run it yourself just download the script and execute it.
The script can be found here: texty_primes

A results file containing the (very likely) prime constructions in bases 2 through 36 using “count-back from X” where X is 1 to 500 can be found here: texty_primes-result-20191121171755.eterms
Analyzing from 1 to 500 in bases 2 through 36 took about 25 minutes on a mid-grade 8-core system (Ryzen5). There are some loooooooooong numbers in that file… It would be interesting to test the largest of them for primality in more depth.

(Note that while the script runs you will receive unordered “Base X Result” messages printed to stdout. This is because every base is handed off to a separate process for analysis and they finish at very different times somewhat unpredictably. When all processing is complete the text file will contain a sorted list of {Base, ListOfPrimes} that is easier to browse.)

An interesting phenomenon I observed while doing this is that some numeric bases seem simply unsuited to producing primes when numbers are generated in this manner, bases that themselves are prime numbers in particular. Other bases seem to be rather fruitful places to search for this phenomenon.

Another interesting phenomenon is the wide number of numeric bases in which the numbers “21”, “321”, “4321” and “5321” turn out to be prime. “21” and “4321” in particular turn up quite a lot.

Perhaps most strangely of all is that base 10 is not a very good place to look for these kinds of primes! In fact, the “count back from 82” prime is the only one that can be constructed starting between 1 and 500 that I’ve found. It is remarkable that anyone discovered that at all, and also remarkable that it doesn’t happen to start at 14,562 instead of 82 — I’m sure nobody would have noticed this were any number much higher than 82 the magic starting point for constructing a prime this way.

This was fun! If you have any insights, questions, challenges or improvements, please let me know in the comments.

2019.08.3 05:20

Building Erlang 22.0 on Debian/Ubuntu

Filed under: Computing,Science & Tech — Tags: , , — zxq9 @ 05:20

Every time I switch to a new system and have to build a new release of Erlang with kerl I sit and scratch my head to remember which dependencies are required. Once you’re set up or have a prep script it is just too easy to forget which thing is needed for what over the next few years.

Here is my list of pre-build package installs on Ubuntu 18.04 — note that they are in three groups instead of just being a single long apt install command (why apt couldn’t manage to install these all at once is beyond me…):

Group1:

  • gcc
  • curl

Group2:

  • g++
  • dpkg-dev

Group 3:

  • build-essential
  • automake
  • autoconf
  • libncurses5-dev
  • libssl-dev
  • flex
  • xsltproc
  • libwxgtk3.0-dev

2019.07.23 08:56

Erlang: R22.0 doc Mirror Updated

Filed under: Computing — Tags: , , , , , — zxq9 @ 08:56

The Erlang doc mirror linked here has been updated to include the R22.0 docs.

Note that some of the internal links and labels say “ERTS-10.4” and “Version 10.4” instead of “ERTS-11.0” and “Version 11.0”. This is an error. The docs refer to ERTS 11.0 but that detail seems to not have been updated when these docs were generated (whoops!). I was looking at fixing that throughout the docs and links, but it turns out to be a lot more complicated than I’m willing to deal with because of the number of references that include the string “10.4” (and some of them are in PDFs and other things more annoying to update than HTML pages). When the R22.1 docs come out that will probably be fixed and I’ll update to avoid confusion in the distant future.

2019.06.22 23:20

Social Prophecy

If you want to feel creeped out in 2019…

Backstory setting for the Cyberpunk 2020 game rulebook Neo Tribes: The Nomads of North America, published in 1994.
Sagan nailed it in The Demon Haunted World.

2019.06.20 15:28

Ad Saturation

Filed under: Computing,Society — Tags: , , , , — zxq9 @ 15:28

The greatest benefit of sharing an IP address with a large number of other people all browsing the same hundred or so websites at the same time is ad saturation. Adsearch auctions still have no idea how to account for a large number of hits that are clearly human, but also trigger frequency protections — so you just see no ads after a while. Nice. (Incidentally, nobody in the world has any clear idea how to distinguish robots from humans, so… have fun with that if your business model depends on any aspect of this.)

A second benefit is a super fast, constantly refreshed, broadly populated DNS cache on the local network.

2019.06.18 18:43

Zombies

Filed under: Computing,Society — Tags: , , , , — zxq9 @ 18:43

IRC will never die.
It will never die because its minimal implementation is useful.

Windows will die, but only after rotting all the way through.
It will continue to persist for the next few decades not because its minimal definition is useful (there is no minimal definition), but as a consequence of deliberate strategic choices that were highly effective at fostering dependency (not entirely unlike social welfare programs).

Linux will never die.
Its super power is the same as its curse: it is Shoggoth.

2019.06.12 15:53

Free Expression: Personal Sites > Social Media

Filed under: Computing,Society — Tags: , , , , — zxq9 @ 15:53

As major social media platforms morph into comic parodies of their former selves people who want to express original ideas will continue to seek alternatives that avoid the warring robot hordes and put them back in charge of regulating their own expression. Over the next few years I find it possible (though maybe not likely) that the biggest changes in online expression could be a return to personal sites and blogs. This is a viable alternative considering the latitude of expression possible, both in form and content, and the ready availability of interlinked comment and discussion systems.

There are some annoyances and responsibilities inherited with managing one’s own site, but to those for whom expression is paramount and “follower” count is not a primary goal personal sites provide everything but a captive audience — and finding an audience today, now that Google’s monopoly on search seems to be breaking in at least some communities, is not anywhere near as hard as it once was.

Until a distributed alternative to gated-community style social media comes along that is low-friction enough to find gain mindshare among non-tech types (something I would love to create, but currently lack the time) it seems likely that some combination of personal sites, aggregate sites (group-run news/op-ed blogs), blogs, non-YouTube video shares, and alternative social media sites will be the home of most censor-averse communities.

It will be interesting to see how things turn out.

2019.05.11 15:46

Erlang doc mirror

Filed under: Computing — Tags: , , , — zxq9 @ 15:46

erlang.org is undergoing scheduled maintenance this weekend.
In the meantime here is the doc mirror link:
http://zxq9.com/erlang/docs/

2018.08.14 15:37

Silly: Hextexting via the command line…

Filed under: Computing,Society — Tags: , , , , , , , — zxq9 @ 15:37

A silly thread on Twitter came to my attention today that stirred some late 1980’s/1990’s phreak/hax0r nostalgia in me. So, of course, I did what any geek would do, wrote a one-off utility script for it. Have fun confusing your parents, kids.

#! /usr/bin/env escript

-mode(compile).

main([Command | Input]) ->
    ok = io:setopts([{encoding, unicode}]),
    Output = convert(Command, Input),
    io:format("~ts~n", [Output]).

convert("t", Input) ->
    String = string:join(Input, " "),
    string:join(lists:map(fun(C) -> integer_to_list(C, 16) end, String), " ");
convert("h", Input) ->
    lists:map(fun(C) -> list_to_integer(C, 16) end, Input);
convert(_, _) ->
    "hextext usage: `hextext t|h [text]".

(Also, look up rot13 — ’twas all the rage 30 years ago, and still makes an appearance as a facilitator of hidden easter eggs in some games. A lot of “garbled alien/monster/otherling speech” text is rot13.)

2018.07.11 17:38

Erlang: Getting Started Without Melting

There are two things that might be meant when someone references “Erlang”: the language, and the environment (the EVM/BEAM and OTP). The first one, the language part, is actually super simple and quick to learn. The much larger, deeper part is learning what the BEAM does and how OTP makes your programs better.

It is clear that without an understanding of Erlang we’re not going to get very far in terms of understanding OTP and won’t be skilled enough to reliably interact with the runtime through a shell. So let’s forget about the runtime and OTP for a bit and just aim at the lowest, most common beginners’ task in coding: writing a script that tells me “Hello, World!” and shows whatever arguments I pass to it from the command line:

#! /usr/bin/env escript

% Example of an escript
-mode(compile).

main(Args) ->
    ok = io:setopts([{encoding, unicode}]),
    ok = io:format("Hello, world!~n"),
    io:format("I received the args: ~tp~n", [Args]).

Let’s save that in a file called e_script, run the command chmod +x e_script to make it executable, and take a look at how this works:

ceverett@takoyaki:~$ ./e_script foo bar
Hello, world!
I received the args: ["foo","bar"]
ceverett@takoyaki:~$

Cool! So it actually works. I can see a few things already:

  1. I need to know how to call some things from the standard library to make stuff work, like io:format/2
  2. io:setopts([{encoding, unicode}]) seems to makes it OK to print UTF-8 characters to the terminal in a script
  3. An escript starts execution with a traditional main/1 function call

Some questions I might have include how or why we use the = for both assignment and assertion in Erlang, what the mantra “crash fast” really means, what keywords are reserved, and other issues which are covered in the Reference Manual (which is surprisingly small and quick to read and reference).

An issue some newcomers encounter is that navigating an unfamiliar set of documentation can be hard. Here are the most important links you will need to know to get familiar and do useful things with the sequential language:

This is a short list, but it is the most common links you’ll want to know how to find. It is also easy to pull up any given module for doing a search for “erlang [module name]” on any search engine. (Really, any of them.)

In the rare case that erlang.org is having a hard time I maintain a mirror of the docs for various Erlang release versions here as well: http://zxq9.com/erlang/

Start messing with sequential Erlang. Don’t worry about being fancy and massively concurrent or maximizing parallelization or whatever — just mess around at first and get a feel for the language using escript. It is a lot of fun and makes getting into the more fully encompassing instructional material much more comfortable.

Older Posts »

Powered by WordPress