Exploring Thales’ Theorem

I was playing with a geometry software package and decided to explore Thales Theorem.

The theorem states that for any diameter line drawn through the circle with endpoints B and C on the circle (obviously passing through the circle’s center point), any third non-collinear point A on the circle can be used to form a right angle triangle. That is, no matter where you place A on the circle, the angle BAC is always a right angle. Most places I have read online stop there.

There was one small problem on my software. Since constructing this circle meant that the center point was already defined on my program, there didn’t seem to be a way to make the center point part of the line, except by manipulating the mouse or arrow keys. So, as a result, my angle ended up being slightly off: 90.00550^{\circ} was the best I could do. But then, I noticed something else: No matter where point A was moved from then on, the angle would stay exactly the same, at 90.00550^{\circ}.

Now, 90.00550^{\circ} is not a right angle. Right angles have to be exactly 90^{\circ} or go home. If it’s not a right angle, then Thales’ theorem should work for any angle.

Why not restate the theorem for internal angles in the circle a little more generally then?

For any chord with endpoints BC in the circle, and a point A in the major arc of the circle, all angles \angle BAC will all equal some angle \theta. For points A in the minor arc, all angles will be equal to 180^{\circ} - \theta.

Note that BC is the desired chord, making the arc containing point A the major arc, with the small arc in the lower part of the circle the minor arc. As shown, all angles in the major arc are about 30.3 degrees.

So, now the limitations of my software are unimportant. In the setup shown on the left, the circle contains the chord BC, and A lies in the major arc, forming an angle \angle BAC = 30.29879^{\circ}. If A lay in the minor arc, the angle would have been 180^{\circ} - 30.29879^{\circ} = 149.70121^{\circ}.

By manipulating BC, you can obtain any angle \angle BAC you like, so long as \angle BAC < 180^{\circ}. More precisely, all angles in the minor arc drawn in the manner previously described will be 90^{\circ} < \angle BAC < 180^{\circ}, and all angles in the major arc will tend to be: 0^{\circ} < \angle BAC < 90^{\circ}. If the chord is actually the diameter line of the circle, then \angle BAC = 90^{\circ} exactly.

Programmatic Mathematica XVII: The Collatz Conjecture

There has been a lot of interest recently in the Collatz Conjecture. A lot of video blogs are going into it, particularly Numberphile, a vlog present on YouTube. It might have something to do with the fact that this year is the 70th anniversary of the conjecture. It is a simple idea, easy enough for a child to understand. Yet, it has been difficult enough that no one has been able to either prove or disprove it to this day.

The Collatz Conjecture is the hunch, or guess, or idea, that performing a certain recursive operation on any positive integer leads to the inevitable result that repeated operations on all successors will lead to the number 1. After that, the sequence of {1, 4, 2, …} occurs in an infinite repetition.

This problem was first posed by Lothar Collatz in 1937. The reason it is only a conjecture is that no one has been able to prove it for all positive integers. It is only conjectured to work as such. Over the past seventy years, no one has been able to furnish a counterexample where the number 1 is not reached. So by now, we’re “pretty sure” Collatz is correct for all positive integers.

I thought of some Mathematica code to write for this. The algorithm would go something like:

  1. Precondition: n > 0; n \in Z
  2. If n is 1, return 1 and exit
  3. If n is even, return n/2
  4. If n is odd, return 3n + 1
  5. Go back to line 2.

Like Fermat’s Last Theorem, which has been proved once and for all in 1995 by Professor Andrew Wiles, and aided by Richard Taylor, the Collatz Conjecture is simple enough to describe to any lay person (as I just did), but its proof has eluded us.

The application of the above algorithm to Mathematica code involves some new syntax. Sow[n] acts as a kind of array for anyone who doesn’t want to declare and implement an array. I would suppose that the programmers of the Mathematica language didn’t see the need for an array for many implementations, such as sequences of numbers. If you want to generate a sequence, you want the numbers in order from some lower bound, up to some upper bound. If you want to list them, you want to do the same thing. It is not often that you want to access only one particular value inside the sequence. This is for those people who just want the whole sequence uninterrupted.

I guess what Sow[n] does is leave the members of the sequence lying around in some pre-defined region in computer memory. That memory is likely to be freed once the Reap[n] function is called, which lists all the members of the stored sequence in the order generated.

EvenQ[] and OddQ[] are employed to check if n if odd or even before executing the rest of the line. If false, control passes through the next line. The testing is inefficient here, since each statement is tested all the time. So, if we already know the number is even, OddQ[] is executed anyway.

ClearAll[Co];
Co[1] = 1;
Co[n_ /; EvenQ[n]] := (Sow[n]; Co[n/2])
Co[n_ /; OddQ[n]] := (Sow[n]; Co[3*n + 1])
Collatz[n_] := Reap[Co[n]]

But Reap[n] by itself gives a nested array (or more accurately, a “ragged” array) with the final “1” outside of the innermost nesting, where the other numbers are.

In[10]:= Collatz[7]
Out[10]= {1, {{7, 22, 11, 34, 17, 52, 26, 13,
    40, 20, 10, 5, 16, 8, 4, 2}}}

Nested arrays are un-necessary, but the remedy to this gets rid of the number “1” which is the number the Collatz function is supposed to always land on. So we then rely on the presence of the number “2”, the number arrived at before going to “1”, at the end of the sequence. Getting rid of the nested array relies on using Flatten[Reap[Co[n]]]. But when you do that, this happens:

In[11]:= Collatz[7]
Out[11]= {1, 7, 22, 11, 34, 17, 52, 26, 13,
    40, 20, 10, 5, 16, 8, 4, 2}

Flattening has the effect of placing the ending 1 at the beginning of the array. If we can live with this minor inconvenience, then we are able to test the Collatz Conjecture on wide ranges of positive integers. So, this is the code we ended up with:

ClearAll[Co];
Co[1] = 1;
Co[n_ /; EvenQ[n]] := (Sow[n]; Co[n/2])
Co[n_ /; OddQ[n]] := (Sow[n]; Co[3*n + 1])
Collatz[n_] := Flatten[Reap[Co[n]]]

The sequences generated by the Collatz conjecture have the well-documented property of having common endings. Using the Table[] command, we can observe the uncanny phenomena that most of these sequences end in “8, 4, 2” (or, to be more precise, “8, 4, 2, 1”). Here are the sequences generated for the numbers from 1 to 10:

In[38]:= Table[Collatz[i], {i, 10}]

Out[38]= {{1}, 
          {1, 2}, 
          {1, 3, 10, 5, 16, 8, 4, 2}, 
          {1, 4, 2}, 
          {1, 5, 16, 8, 4, 2}, 
          {1, 6, 3, 10, 5, 16, 8, 4, 2}, 
          {1, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2},
          {1, 8, 4, 2}, 
{1, 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2},    
          {1, 10, 5, 16, 8, 4, 2}}

Because even numbers are to be divided by 2, somewhere along the meanderings of the sequence, a power of 2 is encountered, and from there it’s a one-way trip to the number “1”.

Happy π day, 2017

For π day 2017, this video posted back in 2015 about Pi day, 2019. That is when 2015 students graduate at MIT. Students at MIT registering in 2015 would now be in their second year.

Another crack at 6×6 magic squares

Even-ordered magic squares are not difficult just because they are even, in my opinion. They are difficult to design because their order is composite. My experience has shown that by far the easiest to design are magic squares whose order is a prime number like 5, 7, 11, or 13. I have run into similar problems with 9×9, 15×15, as well as 6×6 and 8×8. The 6×6 seems to have the reputation for being the most difficult to make magic, although I have stumbled on one system that produced them, and wrote about it a few years ago, about how I applied that method to a spreadsheet. That method, however, led only to 64 possibilities.

Spreadsheets are a great way of checking your progress as you are building such squares, especially when you are trying to build a square using, say, a method you made up on your own, such as applying a Knight’s tour (which works OK with an order-8 square) to an order-6 square. This would require some facility with using spreadsheet formulae and other features which improve efficiency. Using your own method is very much based on trial and error, and you have to make a rule as to whether you will be wrapping the Knight’s moves (if you decide to use a Knight’s tour) to the opposite side of the board, or will you be keeping your moves within the board limits, changing direction of the “L’s” in your movements (this seems to lead to dead ends as you find you have no destinations left which follow an “L”, and consequently, squares which are not really magic). At any rate, the best squares follow some kind of rule which you need to stick to once you make it.

The best ones I have been able to make with a knights tour are: 1) when your L’s are all in the same “direction”‘ 2) when you sum up two squares. The problem is, all of the ones I have made with these methods so far either end up with weak magic (rows add up but not the columns) but the numbers 1-36 are all there; or all rows and columns make the magic number of 111, yet not all of the numbers are present and there are several duplicated (and even triplicated) numbers.

1 9 17 24 28 32 111
26 36 4 7 15 23 111
17 19 27 32 6 10 111
34 2 12 17 19 27 111
21 29 31 4 8 18 111
12 16 20 27 35 1 111
132 111 111 111 111 111 111 90

The above table shows the totals for the rows and columns for one attempt I made for a semi-magic square. Rows and columns work out to the correct total, but not the diagonals, as shown by the yellowed numbers. There are also duplicate entries, as well as missing entries. 1, 4, 12, 19, and 32 have duplicates, while there are three of 17 and of 27. Numbers missing are 3, 5, 11, 14, 22, 25, 30, and 33. That being said, the rows and columns add perfectly to 111, but not the diagonals. However, the average of the diagonals is the magic number 111 (this does not always work out). The sum of the missing numbers is 156, while the sum of the “excess” numbers (the sum of the numbers that occur twice plus double the sum of the numbers occurring thrice) is also 156 (could be a coincidence).

The above semi-magic square results from the sum of two squares where a knight’s tour is performed with the second square where the numbers 1 to 6 go in random order going down from top to botton. If I am too close to the bottom edge of a column, the knight’s tour wraps back to the top of the square. Beginning on the third column, I shift the next entry one extra square downward. The result is 6 of each number, each of these unique to its own row and column.

The first square are the multiples of 6 from 0 to 30 in random order going from left to right, also in a knight’s tour, wrapping from right to left and continuing. The third row is shifted by 1 to the right.

0 6 12 18 24 30
24 30 0 6 12 18
12 18 24 30 0 6
30 0 6 12 18 24
18 24 30 0 6 12
6 12 18 24 30 0
+
1 3 5 6 4 2
2 6 4 1 3 5
5 1 3 2 6 4
4 2 6 5 1 3
3 5 1 4 2 6
6 4 2 3 5 1

Note that the first square wasn’t really randomized.  When I tried to randomize it, the result was still semi-magic, similar to what was described. In the case I attempted, the average of the diagonals was not 111. The two are added, this time using actual matrix addition built into Excel. There is a “name box” above and at the far left of the application below the ribbon but above the spreadsheet itself. This is where you can give a cell range a name. I highlighted the first square with my mouse, and in the name box I gave a unique name like “m1x” (no quotes). The second was similarly selected and called “m2x”. I prefer letter-number-letter names so that the spreadsheet does not confuse it with a cell address (which it will). Then I selected a 6×6 range of empty cells on the spreadsheet and in the formula bar (not in a cell) above the spreadsheet (next to the name box), I entered =m1x+m2x, then I pressed CTRL+ENTER. The range of empty cells I selected is now full with the sum of the squares m1x and m2x, which is the first semi-magic square shown in this article.

Programmatic Mathematica XVI: Patterns in Highly Composite Numbers

This article was inspired by a vlog from Numberphile, on the discussion of “5040: an anti-prime number”, or some title like that.

A contributor to the OEIS named Jean-François Alcover came up with a short bit of Mathematica code that I modified slightly:

Reap[
   For[
      record = 0; n = 1, n <= 110880, n = If[n < 60, n + 1, n + 60], tau = DivisorSigma[0, n]; 
      If[tau > record, record = tau; Print[n, "\t\t", tau];
      Sow[tau]]]][[2, 1]]

This generates a list of a set of numbers with an unusually high amount of factors called “highly composite numbers” up to 110,880. The second column of the output are the number of factors.

1      1
2       2
4       3
6       4
12      6
24      8
36      9
48      10
60      12
120     16
180     18
240     20
360     24
720     30
840     32
1260        36
1680        40
2520        48
5040        60
7560        64
10080       72
15120       80
20160       84
25200       90
27720       96
45360       100
50400       108
55440       120
83160       128
110880      144

For a number like 110,880, there is no number before it that has more than 144 factors.

Highly composite numbers (HCNs) are loosely defined as a natural number which has more factors than any others that came before it. 12 is such a number, with 6 factors, as is 6 itself with 4. The number 5040 has 60 factors, and is also considered highly composite.

5040=24×32×5×7
This works out to 60, because with 24, for example, we get the factors 2, 4, 8, and 16. With 24×32, we get 2, 3, 4, 6, 8, 9, 16, 18, 36, 72, and 144, all which evenly divide 5040. The total number of factors including 1 and 5040 itself can be had from adding 1 to each exponent and multiplying: (4+1)(2+1)(1+1)(1+1)=5×3×2×2=60.

Initially, facotorization of HCNs was done in Maple using the “ifactor()” command. But there is a publication circulating the Internet referring to a table created by Ramanujan that has these factors. A partial list of these are summarized in a table below. The top row headers are the prime numbers that can be the prime factors, from 2 to 17. The first column is the number to factorize. The numbers in the same columns below these prime numbers are the exponents on the primes, such as: 10,080=25×32×51×71. The last column are the total number of factors on these HCNs. So, by adding 1 to each exponent in the row and multiplying, we find that 10,080 has 6×3×2×2=72 factors.

NUMBER PATTERNS OBSERVED

As a number of factors (underneath the “# facotrs” column), We get overlapping patterns starting from 60. One of them would be the sequence: 120, 240, 360, 480, 600, and 720. But the lack of an 840 breaks that pattern. But then we get 960, then 1080 is skipped, but then we get 1200.

For numbers of factors that are powers of 2, it seems to go right off the end of the table and beyond: 64, 128, 256, 512, 1024, 2048, 4096, 8192, … . Before 5040, the pattern is completed, since 2 has 2 factors, 6 has 4 factors, 24 has 8 factors, 120 has 16 factors, and 840 has 32 factors. The HCN with 8192 factors is 3,212,537,328,000. We have to go beyond that to see if there is a number with 16,384 factors.

Multiples of 12 make their appearance as numbers of factors: 12, 24, 36, 48, 60 (which are the numbers of factors of 5040), 72, 84, 96, 108, 120, but a lack of a 132 breaks that pattern. But then we see: 144, 288, 432, 576, 720, 864, 1008, 1152, and the pattern ends with the lack of a 1296.

We also observe short runs of numbers of factors in the sequence 100, 200, 400, 800, until we reach the end of this table. But the pattern continues with the number 2,095,133,040, which has 1600 factors. Then, 3200 is skipped.

There are also multiples of 200: 200, 400, 600, 800, but the lack of a 1000 breaks that pattern. But when seen as multiples of 400, we get: 400, 800, 1200, 1600, but then 2000 is skipped.

There are also peculiarities in the HCNs themselves. Going from 5040 to as high as 41,902,660,800, only 4 of the 60 HCNs were not multiples of 5040. The rest had the remainder 2520, which is one-half of 5040.

Also beginning from the HCN 720,720, we observe a run of numbers containing 3-digit repeats: 1081080, 1441440, 2162160, 2882880, 3603600, 4324320, 6486480, 7207200, 8648640, 10810800, and 14414400.

Number 2   3   5   7   11  13  17  # of
                                factors
-----------------------------------------------------------------------
5040    4   2   1   1               60  
7560    3   3   1   1               64  
10080   5   2   1   1               72  
15120   4   3   1   1               80  
20160   6   2   1   1               84  
25200   4   2   2   1               90  
27720   3   2   1   1   1           96  
45360   4   4   1   1               100 
50400   5   2   2   1               108 
55440   4   2   1   1   1           120 
83160   3   3   1   1   1           128 
110880  5   2   1   1   1           144 
166320  4   3   1   1   1           160 
221760  6   2   1   1   1           168 
332640  5   3   1   1   1           192 
498960  4   4   1   1   1           200 
554400  5   2   2   1   1           216 
665280  6   3   1   1   1           224 
720720  4   2   1   1   1   1       240 
1081080 3   3   1   1   1   1       256 
1441440 5   2   1   1   1   1       288 
2162160 4   3   1   1   1   1       320 
2882880 6   2   1   1   1   1       336 
3603600 4   2   2   1   1   1       360 
4324320 5   3   1   1   1   1       384 
6486480 4   4   1   1   1   1       400 
7207200 5   2   2   1   1   1       432 
8648640 6   3   1   1   1   1       448 
10810800    4   3   2   1   1   1       480 
14414400    6   2   2   1   1   1       504 
17297280    7   3   1   1   1   1       512 
21621600    5   3   2   1   1   1       576 
32432400    4   4   2   1   1   1       600 
61261200    4   2   2   1   1   1   1   720 
73513440    5   3   1   1   1   1   1   768 
110270160   4   4   1   1   1   1   1   800 
122522400   5   2   2   1   1   1   1   864 
147026880   6   3   1   1   1   1   1   896 
183783600   4   3   2   1   1   1   1   960 
245044800   6   2   2   1   1   1   1   1008    
294053760   7   3   1   1   1   1   1   1024    
367567200   5   3   2   1   1   1   1   1152    
551350800   4   4   2   1   1   1   1   1200    

After that run, we see a 4-digit overlapping repeat. The digits of the HCN 17297280 could be thought of as an overlap of 1728 and 1728 to make 1729728 as part of that number. The 3-digit run continues with: 21621600, 32432400, 61261200, and after that the pattern is broken.

Programmatic Mathematica XV: Lucas Numbers

The Lucas sequence follows the same rules for its generation as the Fibonacci sequence, except that the Lucas sequence begins with t1 = 2 and t2 =1.

Lucas numbers are found in the petal counts of flowing plants and pinecone spirals much the same as the Fibonnaci numbers. Also, like the Fibonacci numbers, successive pairs of Lucas numbers can be divided to make the Golden Ratio, \phi. The Mathematica version (10) which I am using has a way of  highlighting certain numbers that meet certain conditions. One of them is the Framed[] function, which draws a box around numbers. Framed[] can be placed into If[] statements so that an array of numbers can be fed into it (using a Table[] command).

For example, let’s frame all Lucas numbers that are prime:

In[1]:= If[PrimeQ[#], Framed[#], #] & /@ Table[L[n], {n, 0, 30}]

The If[] statement is best described as:

If[Condition[#], do_if_true[#], do_if_false[#]]

The crosshatch # is a positional parameter upon which some condition is placed by some function we are calling Condition[]. This boolean function returns True or False. In the statement we are using above, the function PrimeQ will return true if the number in the positional parameter is prime; false if 1 or composite.

The positional parameters require a source of numbers by which to make computations, so for this source, we shall look to a sequence of Lucas numbers generated by the Table command. The function which generates the numbers is a user-defined function L[n_]:

In[2]:= L[0] := 2
In[3]:= L[1] := 1
In[4]:= L[n_] := L[n-2] + L[n-1]

With that, I can generate an array with the Table[] command to get the first 31 Lucas numbers:

In[5]:= Table[L[n], {n, 0, 30}]
{2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, \
2207, 3571, 5778, 9349, 15127, 24476, 39603, 64079, 103682, 167761, \
271443, 439204, 710647, 1149851, 1860498}

This list (or “table”) of numbers is passed through the If[] statement thusly:

In[6]:= If[PrimeQ[#], Framed[#], #] & /@ Table[L[n], {n, 0, 30}]

to produce the following output:

In[7]:=Array_Frame_Lucas_Prime

Note that this one was an actual screenshot, to get the effect of the boxes. So, these are the first 31 Lucas numbers, with boxes around the prime numbers. The Table[] command appears to feed the Lucas numbers into the positional parameters represented by #.

There was a sequence I created. Maybe it’s already famous; I have no idea. On the other hand, maybe no one cares. But I wanted to show that with any made-up sequence that is recursive in the same way Fibonacci and Lucas numbers were, that I could show, for example, that as the numbers grow, neighbouring numbers can get closer to the Golden Ratio. The Golden Ratio is \phi = \frac{1 + \sqrt{5}}{2}. I want to show that this is not really anything special that would be attributed to Fibonacci or François Lucas. It can be shown that, for any recursive sequence involving the next term being the sum of the previous two terms, sooner or later, you will always approach the Golden Ratio in the same way. It doesn’t matter what your starting numbers are. In Lucas’s sequence, the numbers don’t even have to begin in order. So let’s say I have:

K[0] := 2
K[1] := 5

K[n_] := K[n-2] + K[n-1]

So, just for kicks, I’ll show the first 31 terms:

Table[K[n], {n, 0, 30}]
{2, 5, 7, 12, 19, 31, 50, 81, 131, 212, 343, 555, 898, 1453, 2351, \
3804, 6155, 9959, 16114, 26073, 42187, 68260, 110447, 178707, 289154, \
467861, 757015, 1224876, 1981891, 3206767, 5188658}

Now, let’s output the Golden Ratio to 15 decimals as a reference:

N[GoldenRatio, 15]
1.61803398874989

Now, let’s take the ratio of the last two numbers in my 31-member sequence:

N[K[30]/K[29], 15]
1.61803398874942

You may say that the last two digits are off, but trying against the Fibonacci sequence, the ratio of the 30th and 31st numbers yields merely: 1.61803398874820, off by 3 digits.

For Lucas: 1.61803398875159, off by 4 digits — even worse.

So, my made-up sequence is more accurate for \phi than either Lucas or Fibonacci. I have tried other made-up sequences. Some are more, and some are less accurate. If it depends on the starting numbers, I think some combinations work better, and you won’t necessarily get greater accuracy by starting and ending with larger numbers.

Latex editors: a comparison

latex_lamport
If you are using Lyx or Texmacs, this book is still an absolute must. It is THE bible for this language.

Latex is a math typesetting markup language which has been around for about 30 years. It is about as old as HTML, and runs on pretty much any kind of computer that can support a Latex compiler. I have written many term papers in it, and continue to use it to write documents. Its best feature is its ability to handle mathematical and scientific notation. It is also the official typesetting language of the American Mathematical Society. A Stanford professor named Dr. Donald Knuth invented a lower-level markup language called Tex as far back as 1976, and Latex, designed in 1985 by Leslie Lamport, was and is just a bunch of Tex macros, sophisticated enough in itself to amount to a higher-level language. You can edit complete documents and even entire books with only a background in Latex. Latex is therefore robust enough that that is all I ever use for math and science documents.

Latex documents are known for their distinctive roman font, and its clean presentation of even the most complicated formulae. The WordPress editor used in making this blog article can show formulae using the distinctive Latex fonts: m = \frac{m_0}{\sqrt{1-\frac{v^2}{c^2}}} is the way Einstein’s relative mass formula is presented on my editor. This is identical to how it would appear in a Latex paper document. Unfortunately, this editor only displays inline math, so I can’t show you how it would display “presentation-style” math, where the fonts would be larger.

Over the decades, there have been editors in existence that mimic Latex in presentation of fonts and formulae. Two that I have encountered are Lyx and Texmacs.

Both Lyx and Texmacs try to distance themselves from being just WYSIWYG wrappers for the Tex/Latex language. While the metafonts displayed are the distinctive fonts known to exist in Latex are those displayed by default in these editors, saving the files saves to the format native to these separate editors. If you want Latex, you have to export your work into Latex format.

texmacs
Examples of output from Texmacs. Not bad for math, (especially if you know the Latex math codes) but not so easy to use when not in math mode.

First I’ll discuss Texmacs, since my experience with it is the most recent. I discovered Texmacs by surprise when browsing through my Cygwin menus on my laptop. While one would think that going by the name, Texmacs must have some combination of Tex and Emacs, it has dependence on neither. The editor has no resemblance to Emacs (neither in the user interface nor the keystrokes), and a selection of document options appear on the toolbar and in the menus that appear to be in line with Latex document and font options. Texmacs produces its own Texmacs code by default, and while Latex can be exported, the document in Latex may not end up looking the same. I have found that many font changes were lost, for instance.

For one who has worked with Latex for close to 30 years, I can say that nearly all of the resemblance to Latex as well as its ease of use lie in the editor’s use of math commands, although there is more dependence on the GUI. One finds that you can’t enter “\frac{3}{4}” to get \frac{3}{4}, but there is a Texmacs icon you can click that handles that.  Its weakness lay in its handling of the rest of the document. Tables were not well implemented. It appears incapable of inserting gridlines forming the borders for the table cells, for instance, even though the command for it appears to be there in the GUI. I found I needed to export the Latex code, bail out of Texmacs and edit the Latex code directly in a text editor. Another drawback of Texmacs is that while the icons cover nearly anything you would like to do in math, the fact remains that your choices of math expressions are largely limited to the buttons provided. If you are going to do something more complicated, you are going to find reason to edit the Latex code directly by hand again in a text editor. And once you do, importing the *.tex file back into Texmacs to continue editing will not guarantee that your new Latex code will be understood the way you want it. One thing that Texmacs does rather well is change fonts. Latex/Tex has ways of changing fonts internal to its language, but you are limited to only a small number of standard Tex fonts, unless you know your way around the preamble, or header part of the code. Texmacs leaves you more open to alternative installed fonts, allowing you to take advantage of the diversity of Tex fonts of which there are hundreds, created over the last 10 or more years. In fact Texmacs is the only way I know of to take advantage of alternative fonts outside of the Roman/Helvetica/monospace fonts that are at the core of Tex in a way that is even remotely as easy as a word processor. Texmacs documents will have a Latex look and feel, with greater flexibility in font choices, but as said earlier, all this is great as long as you are sticking largely to simple math or math in the toolbars, or as long as you avoid typesetting constructs outside of the math markup, such as tables.

lyx
An older version of the Lyx editor.

Lyx is, I believe a much older editor. It claims to use Latex for its typesetting, but my experience with it (although admittedly years ago) was that for serious math applications, you have to export Latex code and edit it by hand if you want to get what you want. Make sure you have Leslie Lamport’s Latex book beside you at the time. After decades of working on and off with Latex, I can never completely get the language and all its nuances in my head, and need the constant assistance of Lamport’s Latex book at my side. This also ends up being the case for Texmacs, since even basic formatting has to be changed under that editor.

In the end, these editors can save a lot of time to get the basic look and feel down for your document, but in the end you need to, at some point, hunker down and edit Latex code directly, using a text editor. I use vi, where I constantly need to bail out and compile the code and run xdvi on the compiled *.dvi file to see what it looks like and what Latex code I need to tweak next.

Both Texmacs and Lyx are on the GPL.
Texmacs source code: http://savannah.gnu.org/svn/?group=texmacs
Lyx source code: http://www.lyx.org/Download

Programmatic Mathematica XIV: Generating a Hilbert Matrix

I briefly covered Gaussian Elimination in Mathematica for small matrices. You can easily google gaussian elimination or consult an introductory Linear Algebra textbook if you like to know more. Going a whole lot higher in this discussion, we will try to see how we can shoe-horn Mathematica to “ill-conditioned” matrices such as the Hilbert Matrix. Hilbert matrices have cells with formulae H(i,j) = 1/(i+j-1). The determinant of the matrix can be had by knowing if a function f(n) can be defined such that f(n) = 1!\cdot2!\cdot3!\cdot ... \cdot(n-1)!, then the determinant of a Hilbert Matrix has the formula: \det_{H_n} = \frac{(f(n))^4}{f(2n)}. It may not look like it, but the numerator increases much faster than the denominator, causing the fraction to approach zero when n is large.

A sort of matrix can be made in Mathematica:

In[12]:= HilbertMatrix[15]

Out[12]= {{1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15},
{1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16},
{1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17},
{1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18},
{1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19},
{1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20},
{1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21},
{1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22},
{1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23},
{1/10, 1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24},
{1/11, 1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24, 1/25},
{1/12, 1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24, 1/25, 1/26},
{1/13, 1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24, 1/25, 1/26, 1/27},
{1/14, 1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24, 1/25, 1/26, 1/27, 1/28},
{1/15, 1/16, 1/17, 1/18, 1/19, 1/20, 1/21, 1/22, 1/23, 1/24, 1/25, 1/26, 1/27, 1/28, 1/29}}

This square matrix is classified as a Hilbert matrix, famous for being non-trivial to solve, even by computer. I fixed the output using the Rationalize[] function to show that what the Table[] function actually generated was a matrix of rational numbers. In addition, the output looks less like a matrix and more like a two-dimensional array. This tells you the implementation of matrices in Mathematica: it sees your matrix as “a kind of table”, or more accurately, “a kind of array”. The same array could have been generated repurposing the Table[] command:

    m = Rationalize[N[Table[1/(i + j - 1), {i, 15}, {j, 15}]]]

This kind of formula also reminds us that the cells H_{i,j} in the Hilbert Matrix are each made up of the values 1/(i + j + 1), giving it the familiar pattern of fractions we see.

Mathematica can present this as an actual matrix if pressed, using the MatrixForm[] command. Mathematica 10 even provides a direct HilbertMatrix[] command:

hilbert_square_matrixThis command was invoked to produce the same Hilbert Matrix that we started earlier in this example. Mathematica 10 appears to choke on finding the determinant of this matrix (Det[] command), but what it does is echoes back your Det[] command with the expanded matrix. When that output is re-run, Mathematica returns with the determinant for this 15-by-15 matrix:

1/9446949653634668571373109351236989087975627994978804269595338137635022705891424600259116300098090513203200000000000000000000,

the denominator being a 123-digit number. As stated earlier, the determinant quickly goes to zero, but a square dimension of 15 is hardly a large matrix, suggesting that you need not go far to see this being demonstrated. Even the 5×5 version of the Hilbert Matrix has a determinant in the hundreds of billionths. Making it 3×3, the determinant is still 1/2160.

A belated Sony Reader review

Sony released its last e-reader about 2 years ago, so if you just bought one at a firesale price you probably found out that its default bookstore has moved with Kobo.

I was not fussy about the lack of backlighting on the PRS-T3 e-Reader. The display has enough contrast that you can read it quite well under at least moderate light. Many websites touted a reading lamp connected with the PRS-T3, but it didn’t come with mine.

A bigger concern is that I used its browser to search for new e-books, and came to a web page that used plain HTML, and when I tried to zoom, it didn’t re-flow the text at the new font size, so the lines just ran off the side of the screen. It accepts mostly the EPUB format, but will also read PDF files. I surfed to Project Gutenberg to download an EPUB file of the novel Ann Vickers by Sinclair Lewis, first published in 1933.

If you wanted to torture-test your e-reader, a good place to go at the moment is the Canadian site of Project Gutenberg. This page is about 99.9% text, but it is so long that it takes forever to render onto a wifi-enabled e-reader. Of course, if you arrived there, it would be to download some EPUB novels on to your device and get some reading done. My e-reader behaved bizarrely and unpredictably, sometimes refreshing the page for no apparent reason, and then forgetting to reflow the text resulting in lines running off the edge of the screen. I blame the site, not the e-reader.