chronicles of letotag:leto.net,2008-04-19:/x//12010-06-10T20:37:13ZMovable Type Open Source 4.1C'Dent - An Acmeist Adventuretag:leto.net,2010:/x//1.2242010-06-10T19:59:00Z2010-06-10T20:37:13ZI saw Ingy talk at the Portland Perl Mongers last night, and he introduced his C'Dent "programming language". It is not actually a new language, since it defines no new syntax. It is actually the union of a subset of...Jonathan Leto
Ingy talk at the Portland Perl Mongers last night, and he introduced his C'Dent "programming language". It is not actually a new language, since it defines no new syntax. It is actually the union of a subset of the input languages it supports (currently Python, Javascript, Perl 6 and YAML) plus a "data model" for how represent and convert between them.

Given a module in the C'dent subset of a supported input language, it can export to one of the current output languages, which are the input languages, plus Perl 5, Python 3, Java, Ruby and PHP.

There are obviously many issues that will be interesting to address, such as dealing with concurrency and differences in object models, but I think the philosophy of the project is awesome: Acmeism :

Acmeism is the belief that language naturally tends to
divide people and ideas, but that technology can overcome this tendency.
People who create technology that is not limited to a particular
language are known as Acmeists.

We have plans to add Parrot Intermediate Representation (PIR) as an output and maybe an input language at the PDX Hackathon tonight. Come on by! PDX Hackathon has always been an Acmeist gathering, and it has been said that "Beer is our Bytecode."]]>
Sedtris - Tetris Written In Sedtag:leto.net,2009:/x//1.1942009-06-19T07:38:52Z2009-06-19T07:45:46ZNeed I say more? Sedtris....Jonathan Leto
Need I say more? Sedtris.

]]>
Find Files Who Have No Lines Matching a Regextag:leto.net,2009:/x//1.1752009-02-17T08:39:28Z2009-02-17T09:03:24ZI found myself in the situation of having a bunch of files and I needed to find out which one's did not include a certain header file. This turned out to be a great place for short-circuiting with grep. for...Jonathan Letofor i in files/*; do grep PATTERN $i >>/dev/null || echo $i; done

Grep returns false when it cannot find a match, which triggers the echo of the filename to STDOUT. The PATTERN can be any valid regular expression for your system's flavor of grep. This can save tons of time if you have dozens/hundreds of files and only a few are missing something. To edit these files in vim, it is nothing more than:

Happy Hacking! ]]>
Primes, Primality and Pseudoprimestag:leto.net,2009:/x//1.1712009-01-11T18:44:04Z2009-01-11T23:33:02ZPrimes are simple, right? A prime is a number that is divisible by only 1 and itself. The devil is in the details, though. What if your number is really big and someone else does not believe you that it...Jonathan Leto
Primes are simple, right? A prime is a number that is divisible by only 1 and itself. The devil is in the details, though.

What if your number is really big and someone else does not believe you that it is prime? How do you prove it? It turns out to be really easy to prove something is composite ( the opposite of prime, a.k.a not prime ), all you have to do is show them a single factor of the number.

If a shadowy figure emerges from a dark alley and shows you a strip of paper:

$latex x =742376437546875526384762834762837468273648992$

and says "I'll sell you this big fat prime for only five bucks" you can say "it is divisible by 2 and therefore composite. QED and go away."

But if you are trying to be an upstanding prime-number-selling business and therefore want to go the extra mile and prove that the numbers you sell are indeed prime, you will quickly go out of business. I guess that is why there are still sheisty guys selling primes in trench coats...

The reason is that to prove that $latex x=N$ is a prime number, you are actually making a statement about $latex x=N$ as well as saying that all numbers $latex y$ such that $latex y < N$ are not factors of $latex x$. This is a lot of information!

Currently it takes at most a few seconds to prove that large numbers are composite, but to prove that a similarly-sized number is prime could take thousands of CPU-hours!!! For those that like specific numbers, it took 6 CPU-years to prove that the 20,562-digit Mills' prime was indeed prime.

Even for numbers in the range of current cryptography systems (a few hundred digits), proving something is a prime is just too damn slow. Factoring integers is often a subalgorithm of many number theory and cryptography algorithms, it has to be as fast as possible. When a software algorithm factors a number, it often does some kind of check that all of the numbers it is returning are indeed prime, but it cannot afford to prove it. This is where pseudoprimes and primality testing come in, stage left.

Primality testing is mainly concerned with finding algorithms that are fast but have low probability to incorrectly declare that a composite number is prime. A pseudoprime is such a number that "fakes out" a primality test, also known as a false positive. Obviously, people developing cryptography software should be very concerned with how often they are going to produce pseudoprimes, more on this later.

Modern primality testing started with Pierre de Fermat, but Chinese mathematicians described the beginnings of these algorithms 2000 years before Fermat was on the scene. Numbers which "fake out" the Fermat Primality Test are called Carmichael numbers, and in 1994 a group of mathematicians proved that there are infinitely many of them, i.e. there is not only a few isolated numbers that "fake out" the test, the more your search for them, the more you find.

Some software packages may still use the Fermat Primality test for some algorithms, but it has been mostly superceded by the Rabin-Miller primality test.

This test allows you to run $latex k$ repetitions of the algorithm and on average, the probability of it incorrectly concluding that a composite number is prime is $latex P = 4^{-k}$. For $latex k=20$ this is roughly a chance of one in a trillion (1000000000000, a 1 with 12 zeros) that it will be wrong. This ain't bad.

But, as it turns out, there is a better way.

The better way is called The Baillie-PSW primality test (BPSW) which is actually just four independent steps which can be parrallelized quite easily. The BPSW first checks that the number is not 1, 2 or an even number, then checks to see if it has any small prime divisors, where small is defined as $latex p < 1000 $. It then performs a single Rabin-Miller primality test in base 2 and then a Lucas Primality test, which is another primality test that I have not described that uses Lucas Numbers (very closely related to Fibonacci numbers) as the basis for a test.

According to MathWorld "the multiple Rabin-Miller test in bases 2
and 3 combined with a Lucas pseudoprime test as the primality test have been used by the function PrimeQ[n]" since Mathematica 2.2 .

The problem with using software that use Miller-Rabin tests is such: the bases and number of repetitions used internally may change from one version of the software to the next, which means that different versions of your software may think the same number is either prime or composite. This is obviously Very Bad. If you always specify the bases and number of repetitions to use in the Miller-Rabin test then this will not occur, but that is not the case for most existing software.

So it would almost seem that BPSW is the perfect primality test, it is pretty fast and perhaps there is no number can fake out all four steps of the test. All is not peaches and cream, though. Carl Pomerance, the P in BPSW and one of the mathematicians that proved there are infinitely many Carmichael numbers, published a small article in 1984 giving an informal proof that BPSW pseudoprimes must exist, even though no one has ever found one. He could not construct one then and no has been able to in last 25 years either, but that is why mathematicians prove stuff. To be sure. One day someone will find a BPSW pseudoprime, how long will it take?

So what is the moral of the story? Modern cryptography algorithms should be using some variant of the BPSW Primality Test for fast primality testing, always keeping a lookout for a pseudoprime and perhaps another step to add to the test to make it even better.

]]>
CyborgCamp: Notes from Evolution of the Language of Technologytag:leto.net,2008:/x//1.1582008-12-06T18:49:02Z2008-12-07T07:58:15ZBill DeRouchey (@billder) was the opening presentation at CyborgCamp and was wonderfully entertaining and informative. Here are some quick notes I took:How did the "Play/Pause" button become univerally understood?Typewriters choose the winning "letter symbols"Symbols evolve.Are we losing some types/modes of literacy?...Jonathan Leto

]]>
5 Minute Math Lesson: What is a metric tensor and what is it good for?tag:leto.net,2008:/x//1.1322008-12-03T05:39:31Z2008-12-03T06:45:40ZA metric tensor $latex g_{mn} $ is used to measure distances based on a given coordinate system. In terms of the Jacobian, the metric tensor can be found from $latex g_{mn} = (J^T J)_{mn} $ where $latex J^T $ is...Jonathan Leto
metric tensor $latex g_{mn} $ is used to measure distances based on a given coordinate system. In terms of the Jacobian, the metric tensor can be found from $latex g_{mn} = (J^T J)_{mn} $ where $latex J^T $ is the transpose of the Jacobian. Since $latex J^T J$ is a symmetric matrix for any matrix $latex J$, the metric tensor is always symmetric. (In fancy-pants math lingo this is called a symmetric bilinear form.) What is the real-life consequences of this? The distance from $latex a$ to $latex b$ is always the same as the distance from $latex b$ to $latex a$, no matter what kind of crazy coordinate system you are living in!
If we want to calculate the length of a parameterized curve $latex x^r = x^r(u) $ where $latex u $ is a parameter with respect to some coordinate system, then we can write an infintesmal displacement element as $latex dx^r = p^r(u) du $ . The length of this displacement is
$latex ds = \sqrt{g_{mn} p^m p^n} du $ and the length of the curve from $latex u=u_1 $ to $latex u=u_2 $ is $latex L = \int_{u_1}^{u_2} ds = \int_{u_1}^{u_2} \sqrt{g_{mn} p^m p^n} du $ .
So we need the metric tensor to define distance along a curve when we are in non-cartesian coordinate systems, such as spherical or toroidal. From the metric tensor one can then start to study the "curvature" of a coordinate system. More soon!]]>
5 Minute Math Lesson: What is a Jacobian and what is it good for?tag:leto.net,2008:/x//1.1302008-12-01T03:02:56Z2008-12-01T03:36:59ZIn Tensor Calculus, a Jacobian is a matrix defined as$latex J_{mn} = \frac{dy^m}{dx^n} $ where the $latex y^i $ 's are a new coordinate system defined in terms of the original coordinate system, the $latex x^i $ 's. (Note that...Jonathan Leto
Tensor Calculus, a Jacobian is a matrix defined as$latex J_{mn} = \frac{dy^m}{dx^n} $ where the $latex y^i $ 's are a new coordinate system defined in terms of the original coordinate system, the $latex x^i $ 's. (Note that we are using subscripts, $latex x^2 $ denotes the second element of the $latex \mathbf{x} $ vector.) The determinant of this matrix $latex J=det([J_{mn}]) $ is important because this represents the constant of proportionality between volumes in the old coordinates and in the new coordinates. As a simple example polar coordinates is the transformation $latex (x,y)= (r \cos {\theta} , r \sin {\theta} ) $ . When we want to perform an integration in cartesian coordinates by transforming into polar coordinates, we write $latex \int f(x,y) dx dy = \int f(r,\theta) r dr d\theta $ , the factor of $latex r $ is precisely the Jacobian. So in general, to convert an integral in the $latex x^i $ coordinate system to the $latex y^i $ coordinate system we have$latex \int f(\mathbf{x}) d\mathbf{x} = \int f(\mathbf{y}) J(\mathbf{y}) d\mathbf{y} $ where $latex \mathbf{x}=(x^1,x^2,\cdots,x^n) $ and $latex \mathbf{y}=(y^1,y^2,\cdots,y^n) $ .

In differential equation theory, the Jacobian matrix plays a key role in defining the stability of solutions. As a simple example, consider the matrix ordinary differential equation $latex \dot{\mathbf{x}} = A \mathbf{x} $ where $latex A = \left(\begin{array}{cc}a&b\\c&d\end{array} \right) $ . Because this is a linear system, the solution will always be a linear combination of exponentials $latex \mathbf{x} = \mathbf{v_1} e^{\lambda_1 t} + \mathbf{v_2} e^{\lambda_2 t } $ where $latex \mathbf{v_{1,2}} $ are the eigenvectors and $latex \lambda_{1,2} $ are the eigenvalues, and $latex t $ is time, which is positive. Since$latex t > 0 $ , we must have $latex Re(\lambda_{1,2}) < 0 $ for the solution to decay to a steady state. If this is violated for any$latex \lambda_i $ then that exponential "blows up" as $latex t \rightarrow \infty $ , since it is an exponential with an ever-increasing postive argument. Note that if the eigenvalues are complex then the imaginary part of the eigenvalue is related to the oscillatory part of the solution.

A $latex \lambda_i $ would be called an unstable eigenvalue of the system and also forms part of the vector space called the unstable manifold. Instability is defined as the tendency for a system to shoot away from a certain state when it is slightly disturbed (perturbed) from that state. Stability is the feature of a system to come back to a certain state if it is slightly perturbed from that state.

Stability has important consequences for applications, because it can determine if your chemical/combustion reaction will go out of control, of if the species in your mathematical model go extinct, etc, depending on what the differential equations describe. Whatever your equations describe, knowing if the solutions are stable is pretty important and usually the first step of an analysis. If you have stable solutions, then you can reasonably trust numerics but if you are trying to numerically simulate an unstable solution of an equation, you must be much more careful. In these situations you want to use specialized integration algorithms that preserve certain properties of your solutions, like if it is symplectic. More about this later!]]>

LaTeX finally workstag:leto.net,2008:/x//1.1252008-11-30T10:36:08Z2008-11-30T22:58:51ZYes, now I can write Euler's Identity properly: $latex e^{i \pi } + 1 = 0$. This required some heavy hacking on the MTLaTeX plugin, mostly in telling LaTeX where to find style files and fonts. I fixed some glaring security...Jonathan Leto
Yes, now I can write Euler's Identity properly: $latex e^{i \pi } + 1 = 0$. This required some heavy hacking on the MTLaTeX plugin, mostly in telling LaTeX where to find style files and fonts. I fixed some glaring security bugs waiting to happen and improved error reporting. Once I started looking at the source, it was pretty apparent that it was translated from PHP *wince*. I started an overhaul, but it definitely needs a rewrite from the ground up. It would be nice to have config parameters viewable and changeable within MT. Thankfully MT has some pretty good documentation.

LaTeX makes math jokes so much more fun:

$latex \int{ \frac{1}{cabin} } = \log{ cabin} + C$

Don't forget the $latex + C $, it's important.

]]>
Thesis Revisitedtag:leto.net,2008:/x//1.1242008-11-28T09:01:47Z2008-11-28T09:38:34ZEnough time has passed after the defense of my masters that I can stand looking at it again, so I did a git svn clone of my old svn thesis repo and put it on my gitweb. The scary-sounding title...Jonathan Leto
git svn clone of my old svn thesis repo and put it on my gitweb. The scary-sounding title of my thesis was: Solitary Wave Families In Two Non-Integrable Models Using Reversible Systems Theory. It is 48 pages of gobbleygook unless you have some decent differential equations and linear algebra background. The presentation that I gave during my defense is at least a tiny bit more digestible. It at least has a Sherlock Holmes quote and some pretty pictures. One sentence english translation of my thesis: I found some solutions to some equations that people hadn't found before.

]]>
People Pay for Oracle?tag:leto.net,2008:/x//1.1232008-11-27T04:53:13Z2008-11-27T05:09:57ZI was utterly amazed when I had the pleasure of interacting with an Oracle database at work and realized that even the latest and greatest Oracle 10 command-line shell has no readline support. Are we still in the days of vacuum...Jonathan Leto
readline support. Are we still in the days of vacuum tubes? Seriously people! Thankfully there is a spiffy utility called rlwrap which saves the day. It acts as a buffer between another interactive program and provides proper command completion and history. ]]>
GitX 0.5 has Gravatar Support!tag:leto.net,2008:/x//1.1222008-11-22T03:14:17Z2008-11-22T03:26:09ZGitX just auto-upgraded itself and the interface just keeps getting prettier and more functional! Check out the spiffy Gravatar and one-click gist creation:...Jonathan Leto
GitX just auto-upgraded itself and the interface just keeps getting prettier and more functional! Check out the spiffy Gravatar and one-click gist creation:
]]>
Running a Factor Scripttag:leto.net,2008:/x//1.982008-11-06T15:32:56Z2008-11-06T16:18:33ZFor those who are put off by the interactive UI part of Factor, you can run a script from the command-line like so#! /Users/leto/git/factor/factor -scriptUSING: gsl gsl.sf.result gsl.sf.bessel gsl.sf.log kernel tools.test ;"gsl.sf" testNote the space after the ! is necessary...Jonathan Leto

#! /Users/leto/git/factor/factor -script

USING: gsl gsl.sf.result gsl.sf.bessel gsl.sf.log kernel tools.test ;

"gsl.sf" test

Note the space after the ! is necessary because every "word" in Factor must be separated by a space. The practice of running factor as a non-interactive script is not encouraged, but in certain situations it wins the day. The above script could be factored to take an argument of a subsystem to test and then I would make a key-binding in vim (or emacs or whatever) so that when I am editing a file and I type ,t it shows me the results of that subsystems tests.

All of this stuff can be done in the interactive UI, but I think people will fiddle with Factor more if they can easily bolt it onto their current workflow. People tend not to even try things that require totally changing their current tool chain. For me, I am editing the source of the GSL bindings in VIM, so having that script is invaluable. I hack on the source and whenever I change anything important I run the tests by hitting 2 keys. It is really important to make running and writing tests as easy as possible, or they won't get written at all.

Today ...... is a good day to hack.

]]>
New Factor Git repotag:leto.net,2008:/x//1.972008-11-06T07:41:36Z2008-11-06T08:10:53ZYou can view my new factor repo's gitweb. Or you can clone my repo withgit clone http://leto.net/code/factor.gitThis should start getting pulled upstream into the main factor repo sometime soon.The GSL bindings are now in "extra/gsl", which is the extra.gsl namespace...Jonathan Leto
gitweb. Or you can clone my repo with

git clone http://leto.net/code/factor.git

This should start getting pulled upstream into the main factor repo sometime soon.

The GSL bindings are now in "extra/gsl", which is the extra.gsl namespace in Factor. I have bindings to all of GSL's special functions, I am currently working on documenting the Bessel functions and writing tests for the functions which take/return gsl_sf_result structures. If you would like to see another subsystem, just ask and I will let you know if it is doable. There are almost 50 subsystems, so if you want to help: clone, hack, commit and push!

]]>
CouchDB talk at OpenSourcerytag:leto.net,2008:/x//1.962008-11-06T02:21:51Z2008-11-06T04:39:40ZI attended a presentation at OpenSourcery by Chris Anderson about CouchDB. He showed off Futon, which is CouchDB's online web interface, which allows one to do normal CRUD, as well as set up replications, run tests and set configuration variables....Jonathan Leto
I attended a presentation at OpenSourcery by Chris Anderson about CouchDB. He showed off Futon, which is CouchDB's online web interface, which allows one to do normal CRUD, as well as set up replications, run tests and set configuration variables. It has some simple JavaScript functions which are basically map/reduce elements and it seems to be tightly integrated with jQuery. When I asked about Prototype I got the "Why are you still using Prototype?" spiel. Perhaps I should actually look into why people think jQuery is so much better. Anyway, Here are my rough notes of the interesting features of CouchDB that caught my eye:

HTTP server + JSON Doc DB (key/value pairs), RESTful

Incremental Map reduce views

peer-based replication

multi-master OR push all changes to one write-master and + read slaves

concurrency over serial speed

Ex: lotsofwords.com = 120GB database, 200ms response

written in Erlang

sharding via hash functions

documents vs. relations

each doc has a "revision"

first in wins

standalone apps via _external servers

p2p replication - this is really cool and powerful

_external servers - api to parse request as json, filter it and then return

rollup = reduce

re-reduce phase =~ aggregate

]]>
Bessel Functions in Factortag:leto.net,2008:/x//1.952008-11-02T05:08:41Z2008-11-02T05:14:54ZView ScreenshotClick on the link above to see a screenshot of how to make plots of functions in Factor. I am showing off the Regular Bessel function J0(x) which is called gsl_sf_bessel_J0 in GSL. In the background I also have...Jonathan LetoView Screenshot

Click on the link above to see a screenshot of how to make plots of functions in Factor. I am showing off the Regular Bessel function J0(x) which is called gsl_sf_bessel_J0 in GSL. In the background I also have the source of the documentation.