Two Tilted Rectangles

I found this problem from the wonderful Math with bad Drawings site in my news feed. They cite it from Carolina Shearer. Her twitter account contains more such nice problems. It is the kind of problem which seems only adequate for advanced students. Sometimes, you can solve them by looking at it in the right way. Most of the time, you will start a lengthy computation. Often, you will notice in retrospect that the solution was quite easy and you could have guessed it.

For this problem, I did not see the solution. The problem, of course, is to fit two equal rectangles into a square in the shown manner. For a start, try to find a reason why the point 1/2 on the lower side solves the problem. You can use the general fact that a=b+c in the figure below.

I admit that I did the computations using Euler Math Toolbox. That works. However, there is an elementary fact that can be used to prove a+b=c. For a hint, consult the following image. If the green lines are equal the red lines are equal.

Povray and Euler

I found a nice plot by Taha on my Google+ page. It uses a software called MathMod. Euler Math Toolbox can do this too teaming with Povray.

>load povray;
>povstart(zoom=4,distance=6,center=[1,0,0.5],height=45°);
>t=linspace(0,1,100); s=t';
>b=cos(2pi*s)*(t+0.01)+t; c=sin(2pi*s)*(t-0.01); a=t;
>X=cos(2pi*a)*(b+0.1); Y=sin(2pi*a)*(b+0.1); Z=c;
>writeln(povgrid(X,Y,Z,d=0.03,dballs=0,skip=[20,10]));
>povend();


This is all that is needed to generate the following spiraling tube.

Let me explain.

First of all, the pov…() commands generate text snippets which model graphical elements in the syntax of Povray. These text elements are written to a file by writeln(). The commands povstart() and povend() simply open and close the file and start the Povray interpreter. The output of this interpreter is then inserted into the notebook window of EMT.

For an example of such a Povray snippet, let us try the following.

 >povbox([0,0,0],[1,2,3],povlook(green))
box { <0,0,0>, <1,2,3>
texture { pigment { color rgb <0.0627451,0.564706,0.0627451> }  }
finish { ambient 0.2 }
}


This is a green box with side lengths 1,2,3.

The povgrid() command finally is able to draw the surface as a grid. We use the skip= parameter to skip most grid lines from drawing, but still get a smooth appearance of the grid.

The coordinates for the mantle surface of the tube are X,Y,Z. These three variables contain matrices. Thus X[i,j],Y[i,j],Z[i,j] is one point on the surface. To compute these matrices, we use the matrix language of EMT. First, s and t are two vectors, a row and a column vector with values from 0 to 1. Then we generate a cylindrically shaped surface with coordinates a,b,c.

>povstart(zoom=4,distance=6,angle=80°,center=[0,1,0]);
>t=linspace(0,1,100); s=t';
>b=cos(2pi*s)*(t+0.01)+t; c=sin(2pi*s)*(t+0.01); a=t;
>for i=1 to 3; writeAxis(0,1.2,axis=i,c=lightgreen); end;
>writeln(povgrid(a,b,c,d=0.03,dballs=0,skip=[50,50]));
>povend();

This cylindrical surface is then wrapped around the z-axis (point upwards). The details are a bit involved. But any mathematician should be able to understand what is going on here.

Translating a Sage Example for EMT

The nice Sage Math project is something I am very interested in. It is a rather complete package for mathematical computations based on Python. If you are interested in open source math this is probably one good way to start. I must add however that I prefer open source packages directly based on Python with a command line (like IPython) instead of a web based interface that covers everything with another layer. The advantage of the latter is, of course, that it may provide additional services, e.g., for cooperation.

On Windows you will have to run Sage Math in a Virtual Box. You can then open the web interface in your normal Windows browser and work there.

I will certainly come back in this blog to Sage Math. For a start, let me translate an example of Sage Math into Euler Math Toolbox (EMT). It is an example for the famous Lotka-Volterra equations, representing the relation between predator and prey. As far as I can tell, Python uses a fourth order Runge-Kutta method to solve the differential equation numerically. The equations themselves are written in symbolic form. The package contains features for symbolic computations.

### Simulates Lotka-Volterra population dynamics, producing a vector field
### Arrows indicate the direction of population evolution
### The blue contour is one potential stable loop
var('t R F R0 F0 a b c d')
## CONSTANTS
a = 0.04         # rabbit birthrate
b = 0.0005       # probability of predation per encounter
c = 0.1*0.0005   # rabbit -> fox conversion efficiency
d = 0.2          # death rate of foxes
## INITIAL CONDITIONS
R0 = 5000     #initial number of rabbits
F0 = 200      #initial number of foxes

## DIFFERENTIAL EQUATIONS
de_R = (diff(R,t) == a*R - b*R*F)
de_F = (diff(F,t) == c*R*F - d*F)

## CALCULATION PARAMETERS
end_points = 500
stepsize = 1.0
steps = end_points/stepsize
ics = [0,R0,F0]
des = [de_R.rhs(), de_F.rhs()]

## NUMERICAL SOLUTION OF DIFFERENTIAL EQUATIONS
sol = desolve_system_rk4(des,[R,F],ics,ivar=t,
end_points=end_points,step=stepsize)

## Clean up to graph
sol_t=[]; sol_R=[]; sol_F=[]
for i in range(steps):
sol_t.append(sol[i][0])
sol_R.append(sol[i][1])
sol_F.append(sol[i][2])

a = plot([],figsize=[6,4])
a += line(zip(sol_R,sol_F))
a += plot_vector_field((des[0], des[1]), (R,0,7000), (F,0,225),
xmin=1500,color='orange')
a.axes_labels(['Rabbits','Foxes']); show(a)


I entered that as is into the Sage Math browser and the following plot was produced. I had to copy the image out of the browser, because I have no idea on how to save the image with the browser interface. Let me also note that I do not understand every command above, though many of them are self explanatory.

Let us translate this too Euler Math Toolbox. We use the numerical side of EMT only, although we could have defined some functions in symbolic form. But it would not help much to do so.

>a=0.04; b=0.0005; c=0.1*b; d=0.2;
>R0=5000; F0=200;
>function dR ([R,F]) := a*R-b*R*F;
>function dF ([R,F]) := c*R*F-d*F;
>function f(x,y) := [dR(y),dF(y)];
>t=0:1:500;
>s=ode("f",t,[R0,F0]);
>{x,y}=vectorfield2("dR","dF",min(s[1]),max(s[1]),min(s[2]),max(s[2]), ...
>   scale=0.005,<plot);
>plot2d(s[1],s[2],color=blue, ...
>   xl="Rabbits",yl="Foxes");


The result is the following, very similar, plot. However, the anti-aliasing is better, but that could be due to my lack of knowledge in Sage Math.

Python in EMT – Cross Sum of Cubes

When is the cross sum (sum of the digits) of the cube of a number equal to the number?

It is obviously true for n=0 and n=1. You might be able to find n=8 with the cube 512. Then, how do you prove that there are finitely many numbers? How long will it take to find all numbers?

For a dirty estimate we have

$$(9m)^3 \ge (a_0+\ldots+a_{m-1})^3 = a_0+a_1 10 + \ldots + a_{m-1} 10^{m-1} \ge 10^{m-1}$$

It is an easy exercise to show that m<7 is necessary. So we only have to check up to n=100. The cube of 100 has already 7 digits. This can be done by hand with some effort, but here is a Python program written in Euler Math Toolbox.

>function python qs (n) ...
$s=0$while n>0:
$s+=n%10;$   n/=10
$return s$endfunction
>function python test() ...
$v=[]$for k in range(100):
$if k == qs(k**3):$       v.append(k)
$return v$endfunction
>test()
[0,  1,  8,  17,  18,  26,  27]


Recursion Formulas

I do not know if I ever wrote about this. But it is a well known theory, anyways. To find a formula for the Fibonacci numbers

$$F_{n+1} = F_n + F_{n-1}, \quad F_0 = 0, \quad F_1 = 1$$

you can use the „Ansatz“

$$F_n = c^n$$

you will immediately find that c must satisfy

$$c^2 = c + 1$$

The two solutions for this equation can both generate the recursion formulas as well as any linear combination of them. So our Ansatz yields

$$F_n = a c_1^n + b c_2^n = a \left(\dfrac{1+\sqrt{2}}{2}\right)^n + b \left(\dfrac{1-\sqrt{2}}{2}\right)^n$$

Observe the logic that we followed here! All we know by know is that if F(n) is defined by this formula, it will satisfy the recursion formula for the Fibonacci sequence. On the other hand, it is easy to find a and b such that F(0)=0, F(1)=1. Then we know that we have indeed found the correct formula for the sequence. I.e.,

$$F_n = a c_1^n + b c_2^n = \dfrac{1}{\sqrt{5}} \left( \left(\dfrac{1+\sqrt{2}}{2}\right)^n – \left(\dfrac{1-\sqrt{2}}{2}\right)^n\right)$$

We have also shown that any sequence which satisfies the recursion must be of that form with proper constants a and b. This is so, since we can determine a and b for any start values.

Due the fact that c(2) is between -1 and 0, we get

$$F_n = \text{round } \dfrac{1}{\sqrt{5}} \left(\dfrac{1+\sqrt{2}}{2}\right)^n$$

Now, if we take other start values, what happens? E.g., consider the numbers

$$L_n = \left(\dfrac{1+\sqrt{2}}{2}\right)^n + \left(\dfrac{1-\sqrt{2}}{2}\right)^n$$

The start values are then L(0)=2 and L(1)=1. We simply get another integer sequence. And we get the strange fact that

$latex \left(\dfrac{1+\sqrt{2}}{2}\right)^n$

gets closer and closer to integers. This has been observed by Yves Meyer and mentioned in a blog post recently by J. D. Cook. So I came to write this short article. The difference, computed in Euler Math Toolbox, is as follows

>p1 = (1+sqrt(5))/2
1.61803398875
>p2 = (1-sqrt(5))/2
-0.61803398875
>n=0:19; longest (p1^n)'
1
1.618033988749895
2.618033988749895
4.23606797749979
6.854101966249686
11.09016994374948
17.94427190999916
29.03444185374864
46.97871376374781
76.01315561749645
122.9918693812443
199.0050249987407
321.996894379985
521.0019193787257
842.9988137587108
1364.000733137437
2206.999546896147
3571.000280033584
5777.999826929732
9349.000106963316
>p1^n+p2^n
[2,  1,  3,  4,  7,  11,  18,  29,  47,  76,  123,  199,  322,  521,
843,  1364,  2207,  3571,  5778,  9349]


The difference to the next integer is of course a power of p2 goes to zero geometrically fast.

Me being the author of a matrix language, you will be surprised that I do no longer favor the matrix approach in education. In case you do not know what I am talking about: A matrix language avoids loops by vectorizing functions and operators.

Let me give you an example. In a classical language you would have to write something like the following.

>t=0:0.1:10;
>s=zeros(size(t));
>for k=1 to length(t); s[k]=sin(t[k])*exp(-t[k]); end;


The syntax is from EMT, but it does not matter. You need to declare a vector, then fill it with a loop. In a matrix language, you can simply write

>t=0:0.1:10;
>s=sin(t)*exp(-t);


The function sin() will operate on vectors and create a vector of the sine of all elements. Likewise, exp() and the operator * of the multiplication.

EMT has made that more comfortable than Matlab, allowing to combine column and row vectors to matrices, and introducing functions that map automatically to the elements of their arguments. For more, see the documentation of EMT.

This is very handy. It seems that with this trick you can write short code that is easily understandable even by non-programmers. But is that really so?

The problems start if you want to vectorize more complicated data structures, or want to do more complicated things than just applying a function to a vector. You will soon find that you have to use your pick of matrix language on a very high level of proficiency. Here is one example which is just a little above the basics: Create a vector that contains those elements of a vector where the next element is not smaller.

>x=normal(100);
>x[nonzeros(diff(x)>=0)]

I bet it is easier to write a loop in an ordinary programming language than to find out how that works in your choice of matrix language and in an efficient way.

My key experience was the following task in Matlab: Read in the words in 10000 spam mails and 10000 good mails, and make a statistical function that can detect spam mail by the words in the mail. Yes, I could to it! It took a full day to find the proper Matlab tricks and get it to run under two minutes. The next day I tried in Java. It took me two hours to write the code using Java’s tokenizers and dictionaries. And the program finished the task in under 5 seconds! That typically happens if you use the wrong tool.

So, is this an argument to drop matrix languages altogether? No, certainly not. They are way too practical for simple purposes like handling simple data or a plotting a function. But you should not base the education in universities or colleges on tools like Matlab or EMT. Those tools go into the wrong direction if they are taken too seriously. I would even include R into this collection. But R is more often used for the  specialized statistical functions it contains, so it has merits that no current programming language can provide.

You need to ground the base with a programming language like C, C++, Java or Python. There, the student can learn about vectors, matrices and loops to handle them. These languages do also contain advanced tools like dictionaries and other collections. And you can program your own data structures. They are also way more efficient than any of the all-in-one packages that come with a matrix language. Moreover, it is not at all difficult to create the matrix functionality in Java.

Python is a not the worst of ideas to use for education in programming. It is a basic language, and there are tools for all sorts of purposes, including numerical matrices, statistics or symbolic computations. It is not as basic as C++ or Java, however, and quite different from languages used in the industry. But it is, for sure, closer to those real world programs than Matlab.

Image Processing and Data Evaluation in EMT

There is an example for Euler Math Toolbox (EMT) where I tried to fit curves to a real chain. I then fitted a parabola and a catenary to the points and explained a bit about the catenary.

The points where derived by hanging a real chain in front of the screen. As one user pointed out, this is an outdated method in the ages of digital images. Of course, now you can do that with images in EMT too.

First I downloaded a free image of an egg. If you have an image from a digital camera reduce it in size. We do not want to load a high res image into EMT. You can place the image into the notebook with

>loadimg("egg.jpg");


The image was originally about 944×993 pixels. It will be reduced in size for the notebook. loadimg() accepts a number of lines to be used for the image in height. For the blog, I reduced the image too.

Now the following lines of code will load the image into EMT as a matrix of RGB (red-green-blue) values.

>M=loadrgb("egg.jpg");
>size(M)
[944,  993]


We can analyze the image in EMT.  E.g., let us plot the average portion of red color in each column of the image.

>aspect(2); plot2d(sum(getred(M'))'/rows(M)):


We could also process the image. Let us extract the RGB values and manipulate them to put a warm tint to the image.

>{R,G,B}=getrgb(M);
>function f(x,a) := x + a*x*(1-x)
>insrgb(rgb(f(R,0.4),G,B));
>savergb(rgb(f(R,0.4),G,B),"egg2.png");


The insrgb() command inserts the RGB image into the notebook. The savergb() command saves the image. It looks like this.

You can also plot the image as a background image to your plot. The command is plotrgb(). It uses the current plot area as set by window(). In this blog, we make it simple and set a plot are with setplot(). We draw a coordinate system with xplot(). These are older and more basic functions than plot2d(). But plot2d() relies on these functions too.

>savergb(rgb(f(R,0.4),G,B),"egg2.png");
>aspect(1); setplot(0,1,0,1); plotrgb(M); xplot();


You will notice that the plot is not very efficient. That is why you need to reduce your digital image to 1MB or less. This problem might be addressed in further versions of EMT. E.g., we could read the image from a file or a list of loaded images for each plot. Currently, plotrgb(M) for matrices M is the way to go. Of course, you can also use EMT to reduce your image. One way would be to smoothen it with a two matrix fold and then to take every other point. In the example, we reduce the size by a factor of 3.

>E=ones(5,5)/25;
>M1 = rgb(fold(R,E),fold(G,E),fold(B,E));
>M1=M1[2:3:rows(M1),2:3:cols(M1)]; size(M1)
[313,  330]
>savergb(M1,"egg2.png");


Note that the previous images of the egg were reduce for the blog. This is the original result of the reduction in EMT.

Assume we want to get points on the outline of the image. For this, we write a little code in EMT to get mouse clicks from the user.

>function getclicks () ...
$global M;$setplot(0,1,0,1); plotrgb(M); xplot();
$hold on;$v=[];
$repeat;$   m=mouse("Click or press Return!");
$until length(m)<2;$   v=v_m;
$mark(m[1],m[2]);$end;
$return v;$endfunction
>v=getclicks()
0.401925     0.0930601
0.249599       0.20031
0.131469      0.352635
0.066187      0.560917
0.112817      0.758318
0.28224        0.8951
0.569794      0.901318
0.768749      0.794068
0.88377      0.675938
0.956825       0.51895
0.959933      0.332429
0.900868      0.194092
0.762532     0.0868427
0.599326     0.0510929


The Bayesian and the Frequentist – III

For another story, I read the following problem on a Google+ site yesterday: You have three cards in your pocket, one with two red sides, one with two blue sides and one with a red and a blue side. You take one out of your pocket, place it on the table, and it shows a blue side. What is the probability that the other side is also blue?

That fits into my Credo that the quickest way to get order into our thinking is to imagine or actually do a simulation. So let us do that first without trying any abstract thoughts about the problem.

The simulation is obviously to draw one of the three cards with equal probability. Then to take one of the sides with equal probability. Then we have to discard the cases where the side is red. This time, we make a small Java program. I try to design one that is easily understandable.

public class MC
{
static final int red=0,blue=1;

public static int random (int n)
{
return (int)(Math.random()*n);
}

public static void main (String a[])
{
int C[][]={{red,red},{blue,blue},{red,blue}};

int n=100000000;
int found=0;
int valid=0;
for (int i=0; i<n; i++)
{
int card=random(3),side=random(2);
int otherside=1-side;
if (C[card][side]==blue)
{
valid++;
if (C[card][otherside]==blue) found++;
}
}
System.out.println("Found : "+(double)found/valid);

}
}


We can do 100 million simulations in about one seconde. The result is 0.66666164. Of course, we can also do it in EMT with its matrix language or with a TinyC program. With the matrix language, I can only get up to 10 million iterations. Extending the stack would help. But then it is still slower.

>C=[1,0,0;1,0,1]
1             0             0
1             0             1
>n=10000000;
>i=intrandom(n,2); j=intrandom(n,3);
>Sel=mget(C,i'|j'); Other=mget(C,(3-i)'|j');
>sum(Sel==1 && Other==1)/sum(Sel==1)
0.666787938524


So the result seems to be 2/3 probability for the other side to be blue. It is not difficult to understand. We always reject the card with two red sides. And we reject the card with one red side half of the time, but we always accept the card with two blue sides. Thus it is twice as likely to have blue on the other side.

The Bayesian trick does indeed help in this case. But it makes things more mysterious. Let us call BB the event that the card with two blue sides is drawn, and B the event that we see a blue side. Then

$$P(\text{BB}|\text{B}) = P(\text{B}|\text{BB}) \cdot \dfrac{P(\text{BB})}{P(\text{B})} = 1 \cdot \dfrac{1/3}{1/2} =\dfrac{2}{3}.$$

A Problem of Logic

The Problem

Recently, I stumbled across a very interesting problem. I closed the site and started to think about the solution. Therefore, I neither have a link nor the solution given on the page. Let us try our luck with it. (I found a similar problem here. The solution is similar to the one I found. But here, I try to say more about the problem.)

Problem: Two prisoners A and B are given two numbers, each between 0 and 10. A is given the number a=6 and B is given the number b=4. They are told that the numbers add to 9 or 10. As usual, the prisoners cannot communicate in any way. Each day, A is asked if the sum is 9 or 10, and then B is asked the same question. Either prisoner can pass or claim to know the answer. If the answer is correct both regain their freedom, if not both are executed.

Can they find a secure solution without ever communicating between each other? If they both are clever enough they can. Now, you can leave this page for thinking if you wish. But mark it so that you can find back in case you cannot solve the problem.

The logic gets very involved if you start with the given values a=6 and b=4. A knows from the start that either b=4 or b=3. This he knows that B knows that he has a number between 5 and 7 etc. If you think that way, you are in for a problematic approach.

The Solution

It took me several attempts to change my thinking. Let us call „shared knowledge“ the facts that both prisoners know and that both prisoners know the other prisoner knows. In fact, we think of what an observer would know. We ignore the specific numbers a=6 and b=4 for a moment.

Then, after A passes, everyone knows (including the observer) that A cannot have a=10. So he has any number between 0 and 9. Likewise, B cannot have b=10 when he passes. But notice that B can not have the number b=0. Because A has less than 10 he would immediately know the answer a+b=9. Thus, after the first day, we write the shared knowledge as

$$D_1 : \quad 0 \le a \le 9, \quad 1 \le b \le 9$$

Once, A passes the second day we know that he has neither a=0 or a=9.  Otherwise, he would have known the sum as you will easily check. So a is between 1 and 8. If B passes too we know that b=1 and b=9 are impossible. So after the second day everyone knows

$$D_2 : \quad 1 \le a \le 8, \quad 2 \le b \le 8$$

Continuing like that we get

$$D_3 : \quad 2 \le a \le 7, \quad 3 \le b \le 7$$
$$D_4 : \quad 3 \le a \le 6, \quad 4 \le b \le 6$$

Now, A knows that a=6. Thus either  b=3 or b=4. But b=3 no longer is possible. So when A is asked at Day 5, A knows for certain that a=6 and b=4.

Note that B has to decide between a=5 and a=6 which he cannot do earlier with this reasoning. But assume the correct numbers are a=6 and b=3. Then B has to decide between a=6 and a=7. We can do so when he is asked at Day 4. He will then already know A:3-6.

This solved the problem in our specific case. The logic is rather simple, but weird.

Deceptive Ideas

Let us try to shorten the process and put our logic to a test. We ignored the specific knowledge of A and B about the number they have. A knows a=6, and B knows b=4. So A knows that b=3 or b=4. Thus A knows that B knows that A has a number between 5 and 7.  Likewise, B knows that A knows that B has a number between 3 and 5. So, you might deduce that the shared knowledge between A and B at Day 0 is

$$D_0 : \quad 5 \le a \le 7, \quad 3 \le b \le 5 \tag{1}$$

With the logic from above, we deduce that A would know that answer with a=7. So, after a pass, B knows a=5 or a=6. With either b=3 or b=5 he could immediately deduce a+b=9 or a+b=10. Thus, when he passes he must have b=4. A could then declare the result after only two passes when asked at Day 2.

This is a false and deceptive logic. It cannot be correct, because if a=6 and b=3 then A will declare a+b=9 with the same logic on Day 2. In fact, the „shared knowledge“ becomes

$$D_0 : \quad 5 \le a \le 7, \quad 2 \le b \le 4 \tag{2}$$

From that B will exclude a=5 after a pass from A, which changes the outcome completely.

What goes wrong here? While both prisoners will agree to the facts in (1) and(2), and while both are true, they cannot come up with these facts out of their own knowledge. So they have no common agreement about the situation. They do not know what the other prisoner knows. Thus they cannot conclude anything form the assumed knowledge of the other prisoner. To be more precise, B cannot derive the answer from b=3, because from his viewpoint A can still have a=6 or a=7.

Simulation

It is quite an interesting question if we can simulate the procedure. In fact, we have just given an algorithm to deduce a+b from the number of passes and a or b. Extending from our special case N=10 to a general N, our algorithm goes as follows. The shared knowledge after Day d is

$$D_d : \quad d-1 \le a \le N-d, \quad d \le b \le N-d$$

Now we take into account the true values of a and b, known privately to A and B, respectively. E.g., A knows that b=N-1-a or N-a. Thus, after Day d-1, at Day d, he knows the value of b if d-1=N-a or N-(d-1)=N-a-1. Using similar arguments for B, we get

• B knows the sum at Day d if  d=N+1-b (sum=N) or d=b+1 (sum=N-1), after the pass from A at Day d.
• A knows the sum at Day d if d=N+1-a (sum=N) or d=a+2 (sum=N-1), after the pass from B at Day d-1.

Thus the result is known at day

$$d = \min \{N+1-a,a+2,N+1-b,b+1\}.$$

If N=10, a=6, b=4, then d=5. If N=10, a=6, b=3, then d=4. We can prove that this yields the correct answer for all a, b, and N. Or we can simulate, e.g. in EMT.

>function map check (a,b,N) ...
$v=[N+1-b,b+1,N+1-a,a+2];$  d=min(v);
$if d==N+1-a then$     s = N;
$elseif d==a+2 then$     s = N-1;
$elseif d==N+1-b then$     s = N;
$elseif d==b+1 then$     s = N-1;
$endif$  return s;
$endfunction >a=0:10; check(a,10-a,10) [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10] >a=0:9; check(a,9-a,10) [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]  But there is a logical problem. Does the algorithm proof that the two prisoners can escape? The problem is that the prisoners are not allowed to communicate and agree on a specific algorithm. Are there alternatives to this algorithm? Is this the fastest algorithm? These questions are not so easy to answer. But starting from the observation that A cannot declare anything on Day 1 unless a=10, one can work the way down to the solution as written above. It becomes obvious that the given path is the only possible algorithm Generalizations On the page linked at the start the problem is to decide between a+b=18 and a+b=20. Of course, we could set any other set of possible sums. The logic remains the same. Just don’t let yourself trapped into shortcuts taking into account the knowledge of his own number by any prisoner. Units in Euler Math Toolbox Units have long been an integral part of EMT. I want to show you a few examples. First, let us talk about the non-metric system the US is still using. Quote: „Nobody understands the metric system! We use teaspoons!“. >1inch 0.0254 >1in -> " cm" 2.54 cm >inch$, in$0.0254 0.0254 >1ft -> inch 12 >1yard -> ft 3 >1mile -> yard 1760 >1mile -> km 1.609344  As you see, you simply append the unit to a number and it will be converted into the metric system (in case you do not know that’s meters and kilograms). The units are stored in global variables which end with$. These variables are visible even within functions. So units work in functions too.

There is also a conversion operator -> which can either convert to text or to numbers, depending on the type of the parameter after the ->. See the examples.

But there is more to it. Often we use fractions or powers of units. EMT can handle that too. Let us start with fractions. In the following example, we introduce a new unit „nautical mile“ which is missing in EMT but will be present in future versions.

>sm$= 1852.216; >160sm/h -> " m/sec" 82.3207111111 m/sec  As you see, we can now easily convert nautical miles per hours (knots) to meter per second. Assume an airplane departing with 90 knots is forced to use a climb of 200 feet per nautical mile. We want to compute the feet per minute climb which we can read from the VSI. >200ft/sm * 90sm/h -> " ft/min" 300 ft/min  Of course, you can do this (at least approximately) in the head, if you multiply the numbers and divide by 60. E.g., at 120 knots, you need to double the ft/sm requirement. For just another example, let us compute the sink rate which is necessary at 190 knots to obtain a 3° glide path. >200ft/sm * 90sm/h -> " ft/min" 300 ft/min >190sm/h * tan(3°) -> ft/min; print(%,unit=" ft/min") 1008.50 ft/min  The example shows still another way to print with units. By the way, the degree symbol behaves like a unit in many ways. For further examples, here are some american kitchen units. You will also notice that EMT can handle powers in units on both sides. >10cm^3 1e-005 >cup$ = 236.5882365liter/1000
0.0002365882365
>tablespoon$= cup$/16;
>teaspoon$= tablespoon$/2;
>1teaspoon -> " cm^3"
7.39338239062 cm^3
>1liter -> teaspoon
135.256090807