The execute command has been extended. The new features are - hidden windows, - non-wait execution, - catching output. The result is the exit code of the program, or a vector of strings with one string for each line of output. An example is the following command, which calls the "cmd" to run the "dir" command in the background, and presents the output. Note that we start it in the current directory, which is the directory where Euler stores the introduction notebooks. There is only one *.e file.
>exec("cmd","/c dir /w *.e",home(),>print,>hidden,>wait)
Volume in Laufwerk C: hat keine Bezeichnung. Volumeseriennummer: ECF3-71E6 Verzeichnis von C:\euler\docs\Programs test.e 1 Datei(en), 367 Bytes 0 Verzeichnis(se), 18.001.412.096 Bytes frei
The next example calls the system editor for text files. The text file is created in the home directory of Euler. Euler does not wait for the editor to finish.
>filename=eulerhome()+"test.txt"; ... writematrix(random(5,5),filename,"%1.5f"); ... exec("cmd","/c start "+filename,eulerhome(),<wait);
This should open the editor and return immediately. The following is a technique to communicate with the program later. First we start the Windows program cmd. This usually starts a shell. But we hide the shell. We want output, but do not wait for it.
>exec("cmd","",home(),>print,>hidden,<wait);
Now cmd runs in the background. We can write a string to it.
>execwriteln("dir /w *.e");
Then we can read the result from the input pipe.
>execread()
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten. C:\euler\docs\Programs>dir /w *.e Volume in Laufwerk C: hat keine Bezeichnung. Volumeseriennummer: ECF3-71E6 Verzeichnis von C:\euler\docs\Programs test.e 1 Datei(en), 367 Bytes 0 Verzeichnis(se), 18.001.403.904 Bytes frei C:\euler\docs\Programs>
The cmd program is killed when Euler closes, or with the following command.
>execkill();
There was a problem with very huge line plots in recent versions. leading to a large delay or even a halt of the Windows graphics system. The reason was that Euler is using a path to connect the lines. For paths with many segments, Windows can not handle the plot. I fixed that by splitting large paths into chunks. Nevertheless, these plots take a short moment to appear.
>t=linspace(0,2pi,100000); x=cos(47*t); y=cos(51*t); plot2d(x,y):
I thank B. Krämer for pointing me to this problem. I appreciate all user reports. The same plot can be produced with much less points, however.
>i=1:10:length(x); plot2d(x[i],y[i]):
Note that filled polygons are restricted to 4095 points.
>t=linspace(0,2pi,4095); plot2d(cos(5*t),sin(3*t),>filled):
The function polyval, splineval, etc. behaved in a way that was inconsistent with the rest of Euler. The points of evaluation come after the polynomial or the spline. This design goes back to very old times. Following an idea of Radovan, I introduced new functions starting with eval...
>plot2d("evalpoly(x,[0,-1,0,1])",-1,1): // x^3-x
The same with interpolation.
>xp=-3:3; yp=(xp==0); d=divdif(xp,yp); ... plot2d("evaldivdif(x,d,xp)",-3,3); ... plot2d(xp,yp,>points,>add):
The spline function computes the cubic natural spline. evalspline evalues the spline.
>xp=-3:3; yp=(xp==0); s=spline(xp,yp); ... plot2d("evalspline(x,xp,yp,s)",-3,3); ... plot2d(xp,yp,>points,>add):
In the same way, functions for exact evaluation and intervals were added.
>p=chebpoly(60); xevalpoly(0.9,p), evalpoly(0.9,p)
-0.350468376613 -14447.2139393
For comparison.
>cos(60*acos(0.9)), cheb(0.9,60)
-0.350468376614 -0.350468376614
>ievalpoly(0.9,p)
~-0.3504683772,-0.350468376~
The matrix FFT in Euler returned the conjugate of the usual matrix FFT (as implemented in fft2 in Matlab). I changed that. Moreover, ifft works now, and returns the inverse transformation.
>A=normal(8,8)+I*normal(8,8); totalmax(abs(ifft(fft(A))-A))
0
Note, that Matlab defines fft(A) for matrices A taking the FFT in each row. The matrix FFT is fft2(A). In Euler, fft(v) and fft(A) work differently for vectors v and matrices A. Euler can handle vectors of any size. However, the FFT is only efficient, if the size has many small factors. For matrices, Euler can only handle powers of 2.
>v=random(1,2*3*7^2*11); totalmax(abs(ifft(fft(v))-v))
0
I improved the display of errors for nexted functions. Now the lines in each function of the calling chain are displayed.
>function f(x) := x+; ... function g := f(2); ... g
Syntax error in expression, or unfinished expression! Error in function f in line useglobal; return x+ Error in function g in line useglobal; return f(2) Error in : g ^
If HTML exports of Euler notebooks are printed or if they are enlarged in browsers, Latex formulas did not look well. Now, Latex formulas are saved in full resolution by default.
By the same reason, there is a switch to activate larger images for images in the text window. Then insimg() will keep a 3 times larger image in the memory and save it with the notebook. The link to this larger image is used by the HTML export. The notebook display uses only the default smaller image. Larger images take space and time for saving. Symbolic expression in functions need quotes. If the quotes are missing, Euler now issues an error.
>function f := &x^5; ... f
Use quotes &"..." for symbolic expressions in functions! Symbolic expression expected. Error in function f in line useglobal; return &x^5 Error in : f ^
The error gets recognized only at run time. Note, that symbolic expressions in numerical functions can be useful, though they take a lot of time to evaluate.
>function T(expr,n) := &"taylor(@expr,x,0,@n)"; ... plot2d(T("sin(x)",5),0,pi):
I made it easier to handle non-square graphic windows. Simply turn off the square graphics. This will also disable "Graphics in Text Window". A separate window will appear in all cases. You can rescale this window. You should restart Euler now. Then the font will be based on the maximal dimension of the graphics (width or height). insimg() will use the default 25 number of lines. But it will decrease the number of lines, if the graphics would become to wide. Here is an example. I scaled the graphics window approximately 1.5:1 for this.
>plot2d("sin(x)",-pi,pi):
The aspect function has almost the same effect, if the square graphics is on. But the number of lines is a fraction of 25 (the same fraction as the aspect has from the full window).
>aspect(1.5,1); plot2d("sin(x)",-pi,pi); insimg;
The graphics export has a button "For Print" now, which disable anti-aliasing and takes 2000 pixels for the graphics width.
The one-window GUI is not yet ready. But since 18.8 there is a mode with only one textwindow, displaying the graphics in this window. The tabulator key, the "wait()" command and "shg" will bring the full graphics to the foreground. Moreover the colon after a command places the graphics below the command (as with the "insimg()" command).
>plot2d("x^3-x"); wait:
Some graphics were using a fixed font for the graphics window. I fixed that. All graphics use a non-fixed font now. A new feature brings boxes of text inside plots. In the following example, the two functions are labelled. The default anchor point is the top right corner of the box at the top right corner of the plot window.
>plot2d("x^3-x",-1,1); plot2d("x^2*(x-1)",style="--",color=blue,>add); ... labelbox(["x^3-x","x^2*(x-1)"],styles=["-","--"],colors=[black,blue]):
This is possible for point plots too, and only for one function. In the example we place the box at another position.
>n=10; plot2d(0:n,bin(n,0:n)); plot2d(0:n,bin(n,0:n),>points,>add); ... labelbox("Binomials",styles="[]",>points,x=0.3,y=0.1,tcolor=black):
Another new feature are text boxes.
>function f(x) &= exp(-x)*sin(2*pi*x); ... plot2d("f(x)",0,2pi); ... textbox(["Example of a damped oscillation",&f(x)]):
In previous versions, the user could interact with the program while the graphics is displayed with key presses or mouse clicks. An example is the >user flag in plot2d and plot3d. There is now a new function mousedrag(), which waits for mouse or keyboard events. It returns the type of the event, the mouse position or key, and the time of the event. The function dragpoints() makes use this, and lets the user drag points. We need a function, which can plot something in dependence of points.
>function f(x,y) := plot2d(x,y,>points,a=0,b=1,c=0,d=1);
Then we can let the user drag points. The function returns if a key is pressed. For the test, I dragged all points to the right.
>{x,y}=dragpoints("f",random(1,5),random(1,5)):
Another type of animation are dragged values. We need a function, which plots something depending on values. The values are stored in a vector. As an example, we draw the Taylor expansion of the cosine. The parameter is the degree of the expansion.
>function f([n]) ...
plot2d("cos(x)",-2pi,2pi,c=-2,d=2); plot2d(&"taylor(cos(x),x,0,@n)",>add,color=blue,style="--"); endfunction
Now we can plot a an action, where we drag the values. The number n varies from 0 to 20 with 10 subintervals, so n=0, n=2 etc. For the test, I dragged n to 8.
>vn=dragvalues("f","n",2,[0,20],10,status="Drag n", ... heading="cos and Taylor expansion"):
Since you get the values back, you can draw the plot without the dragging box. Or you can add the value of n at some other place.
>f(vn); labelbox(["cos","T_"+vn],["-","--"],[black,blue]):
In earlier versions, a parameter declared as string could not be used as a string vector and vice versa. Now a string vector can also be a string. In contrast to number types, a string is not a string vector. This is useful for strings of line types or other string attributes. You can now use the flag indexing v{i} for strings.
>v="test"; v{1}, v{2}
test test
And v[1] will work too, but other indices generate an error.
>v[1]
test
There is one problem left. The concetanation | works differently for strings and string vectors. If you want to make sure, that the string is a string vector, use [s]. This will work, even if s is already a string vector.
>v=["alpha","berta"]; [v]|"charlie"
alpha berta charlie
There are always fixes for tiny errors or incoveniences in Euler. One example is that you can now finish a one-line function with "; ..." in a multi-line command. In previous versions this worked only for symbolic funcitions, since these functions were parsed.
>function f(x) := x^3-x; ... plot2d("f",-1,1):
Note that you create multi-line one-line functions, i.e., functions with expressions spread over more then one line.
>function f(x) := x^3 - ... x; ... f(6)
210
I install the font "Source Code Pro" in this version along with Euler. This font is the default font for new installations, and it is the default font for the external editor JE. You can deselect the font in the Menu "Options - Program Settings - Use Source Code Pro", if you like. Source Code Pro By the way, I fixed this type of links, so that they also recognize "https://...". Moreover, links do display and print without "See:", and indent two spaces. I added help to the dialogs. The help button will open the documentation in the Browser at predefined positions. The first installation will open the new Tips page. With the default syntax settings, commands must now be separated by commas or semicolons plus a space.
>a:=3; a*2, a^2
6 9
I re-activated clearall. It will now clear all user variables only.
>%b=6; clearall; %b
6
I changed the computation of the cursor position somewhat. If a bitmap follows a command line, the first 5 lines of this bitmap will be visible. This makes sure that the output of the previous command is visible. The unit conversion now allows blanks.
>1km -> miles, 1mile -> " km"
0.621371192237 1.609344 km
I am recommending "Source Code Pro" for the default font now, and use it myself. You can download this font from the web. Install with right click on the fonts. Here is, how it looks:
I added a graphics feature, which scales the line width in relation to the font size. Usually, you will increase the font for small prints or images (small in physical size). Then you need fatter lines. Here is a typical case with a font of 20 lines per screen.
The same plot would look like this with the default font.
>plot2d("x^2"):
Due to user request, there is now a mode with one window only. Currently you will see either the graphics or the text in this window. For 19.0, I plan a version with a separate plot and help area in one window. Another step is to allow more than one notebook at once. The graphics appears with the tabulator key, the shg command, or the wait commands. The >user flag in plot2d etc. works. If you want to try, enable the mode in Options / Graphics / Graphics in Text Window.
>plot2d("x^2",>user):
The colon after a command allows a // comment now.
>plot2d("sin(exp(x))",-5,5): // strange function
The body of functions is no longer marked with dollar signs.
>function f(x) ...
return x^2 endfunction
There was a problem with map. A mapping function would not overwrite a default parameter with an assigned parameter. Now this works correctly.
>function map f(x,a=4,b=4) := a*b*x >f(1:5), f(1:5,b=5)
[ 16 32 48 64 80 ] [ 20 40 60 80 100 ]
The complex plots of points did not switch off the hold flag. I fixed that.
>z=exp(I*linspace(0,2pi,10)); plot2d(z,>points,r=1.2); plot2d(z,r=2):
Euler now suppresses the prompt > in the second and further lines of multi-line commands, if no output or comment is in front of the line.
>v=random(1,10000); ... mean(v), dev(v),
0.501303233385 0.289367580549
If a command line ends with : it will now call insimg with the default 25 lines. This works only in the command window, not in functions.
>plot2d("sin(x)/x^2",pi,6pi):
I fixed a problem with external processes which caused Latex to stop working after a while. Euler now releases the handles of processes properly and uses the search path of Windows in all cases. The following command should open the Windows Explorer in the user directory of Euler.
>exec("explorer",userdir());
This is an update to fix a bug, which seems to be connected with missing resources in Windows XP. It causes black boxes in the notebook after an insimg command, if the default "Square Graphics" is active. If the square graphics is not active, the crop in insimg did not work. It works now. Note that you can crop a real, an y-interval, or a rectangle.
>A=rgb(0:0.01:1,(0:0.01:1)',1); ... w=window(0,0,1024,1024); plotrgb(A); window(w); insimg(10);
But note that the line number in insimg refers to the full image.
>insimg(20,crop=[0.5,1,0.5,1]);
I added an approximation using a continued fraction due to Abramowitz-Stegun to improve the accuracy of normaldis. I got this from H. Vogel. The function is xnormaldis.
>longestformat; xnormaldis(-8), longformat;
6.220960574271785e-016
Another update of the documentation and the built-in files. I have collected some utility files to other utility files, added examples, removed embarrassing typos, and removed some example notebooks, which did not work properly. The insimg function does now accept a vector for cropping. This is useful, if you did some low level plotting and use only the center of the square window.
>clg; for i=1:9; bar([i*100,400,50,200]); end; >insimg(crop=[0.3,0.7]);
For an example see: Examples/Towers of Hanoi insimg crops automatically, if the aspect is set.
>aspect(2); plot2d("x^2"); insimg; aspect;
There is now a new menu item "Show HTML Export". If you press this, you can see the HTML output of the current notebook. Of course, you need to have exported the notebook before. I also improved the functionality of links in notebooks and their HTML export. Here is an example Predictions which will link to http://euler.rene-grothmann.de/renegrothmann/Predictions.html just by using the "See: http://... | ..." syntax. A change in the notebook interface deals with tabulator characters (ASCII 9) in pasted text. This occurs frequently, if you copy table lines from the web. If you paste into commands the tabulator will be replaced by a comma. For example go to this page http://www.intmath.com/blog/constrained-data-model-solution/7517 and copy the line in the table with data labeled s, and paste it. You get comma separated value, which you can easily convert into a vector.
>s=[2,4,3,5,9,6,8,9,8,10,6]
[ 2 4 3 5 9 6 8 9 8 10 6 ]
I discovered that "niveau" is not an English word. So I changed it in plot2d and plot3d to "level". But the old "niveau" still works, if you use it as an assigned argument.
>plot3d("x^2*y",level="auto",angle=55°); insimg;
There are more changes in the documentation. Moreover some functions are now in the Euler core. An example are the Gauß-Jordan scheme and also the ilpsolve function. New functions are date and printdate. Let us compute 1000.5 days after 2012-1-1 11:49.
>printdate(date(day(2012,1,1,11,49)+1000.5))
2014-09-27 23:49
Or the difference between two days.
>day(2012,5,1)-day(2005,3,15)
2604
There is a new function to convert between vectors and characters.
>strtochar("car")
[ 99 97 114 ]
>chartostr(flipx(strtochar("the brand new car")))
rac wen dnarb eht
There is also a function to break up a sentence into tokens.
>strtokens("the brand new car")
the brand new car
I changed the splineval function so that it easily maps.
>xp=-3:3; yp=(xp==0); ... s=spline(xp,yp); plot2d("splineval(x,xp,yp,s)",-3,3); insimg;
There are some enhancements of the syntax of Euler. Most work went into the documentation and the examples, however.
I changed the behavior of multiple returns to avoid confusing errors. E.g. the sort function returns two values, the sorted vector and the indices. Often, you wish to use only the first of these results (the sorted vector) as an argument to another function. In previous version, both results got arguments. So the following did not work, since shuffle expects only one argument. Now it works as expected. It generates a long random vector of integers, and counts the number of times 1 to 10 appears in this vector.
>multofsorted(sort(intrandom(1,1000,10)),1:10)
[ 96 98 117 110 112 98 78 100 101 90 ]
The function getmultiplicities uses this by first sorting the second argument.
>getmultiplicities(1:10,intrandom(1,1000,10))
[ 87 104 106 97 98 102 109 96 102 99 ]
Sometimes, we are writing a function with multiple returns, which should work as separate arguments. The histo() function is such a case.
>plot2d(histo(random(1,1000),20),>bar); insimg;
This can be achieved using the new "args" modifier in the definition of the function. function args histo (v) ... Note that the built-in function args() does the same. It is meant to return all semicolon parameters as arguments for another function.
I removed all examples in external files, which were pasted into the Euler documentation by Euler or by the HTML maker. Instead there are now examples in the Euler files. These examples are of course also in the HTML exports of the Euler files. For an example, double click on the fracprint command below and follow the link in the browser.
>fracprint(pi,eps=0.01)
22/7
Previously, "not", "and" and "or" worked only in if commands. You can now use them everywhere. "and" and "or" will not evaluate the second expression, if the result is known from the first one (logical shortcut). To make this work, the commands skip everything until ";" or ",", or until the end of the line, or until "then".
>function btest (x) ...
"Evaluate btest with "+x, return x; endfunction
The result of the following is true, since 1 is not zero.
>true and btest(1)
Evaluate btest with 1 1
Since false cannot become true after "and", the btest(1) evaluation is skipped.
>false and btest(1)
0
Note that "not" binds stronger than "and", and this binds stronger than "or".
>not 1 or 0 and btest(1)
0
You cannot use these as operators for matrices. For this you use && and ||.
>n=1:10; n>5 && n<8, nonzeros(%)
[ 0 0 0 0 0 1 1 0 0 0 ] [ 6 7 ]
For bitwise "and" and "or", you use "bitand" and "bitor".
>bitand(10,6), bitor(10,6)
2 14
The reason can be seen using the dual representation. By the way, the printdual function got the parameter length for the length of the output.
>printdual(10,true,20), printdual(6,true,20),
1010 110
This is just a fix for the window positions. Now the true area of the screen is determined before Euler positions its windows.
Now the version log is in this Euler file. Thus you can try the changes immediately, if you load the notebook XX - Changes into Euler. The documentation is now mainly by notebooks and the reference. The HTML documentation contains only technical information.
Version 18 extends Euler by many statistical functions and plots. Have a look into the introduction to statistics. 12 - Introduction to Statistics An example of the new plots is the boxplot. It works together with the quantiles function (computing min,0.25,0.5,0.75,max quantiles).
>v=normal(1,100)_(normal(1,100)+0.5); ... shortformat; quantiles(v), ...
-2.3303 -0.66066 -0.041025 0.68102 2.3892 -2.1511 -0.20804 0.48756 1.131 2.8615
> boxplot(%):
The statistical functions include reading and writing tables. Tables can contain string items, which are translated to numbers, and added to a token list. The following table contains strings in column 2. We let readtable collect the string tokens automatically.
>{MT,hd,tok}=readtable("table1.dat",ctok=2); ... writetable(MT,labc=hd,ctok=2,tok=tok);
Person Sex Age Mother Father Siblings 1 m 29 58 61 1 2 f 26 53 54 2 3 m 24 49 55 1 4 f 25 56 63 3 5 f 25 49 53 0 6 f 23 55 55 2 7 m 23 48 54 2 8 m 27 56 58 1 9 m 25 57 59 1 10 m 24 50 54 1 11 f 26 61 65 1 12 m 24 50 52 1 13 m 29 54 56 1 14 m 28 48 51 2 15 f 23 52 52 1 16 m 24 45 57 1 17 f 24 59 63 0 18 f 23 52 55 1 19 m 24 54 61 2 20 f 23 54 55 1
And simple analysis of columns.
>{vu,vf}=getstatistics(tablecol(MT,2)); vu_vf
1 2 11 9
Or a scatter plot of columns against columns.
>T=tablecol(MT,3:5); scatterplots(T,lab=hd[3:5]):
The histo function got an extension v=... These are the interval values to be used.
>plot2d(histo(random(1,100),v=0:0.1:1),>bar);
For counting of discrete data, there is now getmutiplicities, and the plot function columnsplot.
>columnsplot(getmultiplicities(1:6,intrandom(1,1000,6)))
Euler can now export Euler files to HTML for documentation. Here is an example and some technical information. Examples/astro.e ../documentation/gui
There are new functions for finding items in vectors.
>indexof([1,4,2,7],1:10)
[ 1 3 0 2 0 0 4 0 0 0 ]
The following is more efficient, but needs a sorted vector to search in.
>indexofsorted([1,2,4,7],1:10)
[ 1 2 0 3 0 0 4 0 0 0 ]
Another efficient counting is the following.
>multofsorted([1,1,1,3,3,3,4,4],1:4)
[ 3 0 3 2 ]
The function getmultiplicities relies on this.
>getmultiplicities(1:6,intrandom(1,60000,6))
[ 10076 9946 10062 10031 9808 10077 ]
These functions work for vectors of strings too.
>s=["a","a","b","b","a"]; getmultiplicities(["a","b"],s)
[ 3 2 ]
Find works for string vectors now, and returns the indeces of the ranges, where the strings of the second parameter sort in.
>find(["a","b","c"],["a","aa","bb","cc"])
[ 1 1 2 3 ]
This works like for numbered vectors. An old bug regarding the largest number has been removed. Moreover the functions is more efficient now.
>random(1,7), find(0:0.1:1,%)
[ 0.35892 0.70602 0.99477 0.99231 0.90611 0.9774 0.40741 ] [ 4 8 10 10 10 10 5 ]
The placement of the 3D labels improved. They are now in an angle of 45° to the sides of the cube. The scaling for plot3d has changed too. But you probably won't notice this. Previously, it depended on the r parameter.
>plot3d("x^2+y^3",angle=20°); insimg;
For very flat plots, the z scaling is expanded.
>plot3d("(x^2+y^3)/10",<fscale,angle=20°,>contour,scale=1.3); insimg;
A : (all columns or rows) can be omitted now.
>shortformat; A=random(2,2)
0.41444 0.32574 0.58955 0.73067
>A[,2]
0.32574 0.73067
Strings can now be sorted, and the function unique works for strings.
>sort(s)
a a a b b
>unique(s)
a b
Round without the number of digits rounds to the next integer now.
>round(pi)
3
Comparison to NAN now works. Note that "errors off" is needed to avoid an error break at 1/0.
>3==NAN, errors off; 1/0==NAN, errors on;
0 1
I found an error in the Julia code I translated for Euler. So the chi-square random generator was wrong as well as some distributions depending on it. Now it should work. Let us try a chi-square distribution.
>s=randchi(1,10000,5); mean(s), dev(s)^2
5.0053 9.8294
>plot2d(s,>distribution); plot2d("qchidis(x,5)",>add); insimg;
Here is the t-distribution.
>s=randt(1,10000,5); mean(s), dev(s)^2
-0.0057586 1.6388
We plot the empirical distribution along with the t-density and the normal density.
>plot2d(s,a=-5,b=5,c=0,d=0.5,distribution=100,style="/"); ... plot2d("qtdis(x,5)",>add); ... plot2d("qnormal(x)",color=red,>add); insimg;