Table of Contents

Introduction
For whom is this editor?
For what platforms?
Download and install
Newton-Raphson, using Ruby
Line number, dirty mark, key bindings, and type size
Newton-Raphson, using Java™
Other demo and Demo examples
Integration by Monte Carlo in Six Dimensions, using FreeBASIC
Cauchy Camel, using Lua or LuaJIT
Bessel, using Fortran 77
Euler, using Chipmunk Basic
Polar, using Free Pascal
Lissajous, using Rhino
Caught in a loop
The widgets in order
Encoding
The j template
License, revision date, and e-mail address

Introduction

ScaleUpEdit is an editor written in the Tcl/Tk language. It is small, and it is meant for use on small programs. The first claimed virtue is the RUN button. This button is able to save and run the program in just one click of the mouse. One may think of it as the instant gratification button.

The second claimed virtue is the GRAPH button. This button is able to save and run and graph the program in just one click of the mouse. Numbers and color names printed by the program are understood as plotting coordinates and colors for the graph. That is, the plotting is independent of language, so even computer languages without graphics can plot mathematical graphs.

The editor knows how to run the program by looking at the top line of the program file. That is, the editor is not specialized for a small set of languages. I hereby place ScaleUpEdit in the public domain. To top

For whom is this editor?

ScaleUpEdit is not for beginners in programming, because they need more features. Neither is it for professional programmers, because they need many more features. Rather, it is for amateur programmers who may wish to see a small editor so they can improve on it. Also, and mostly, it is for the authors of editors, so they can see my instant gratification button and see how it reads the first line of the file. Then they can easily add such a button to their editors. To top

For what platforms?

ScaleUpEdit ought to run on any platform having Tcl/Tk. However, the only platform I have now is Microsoft Windows XP, so I cannot be sure. To top

Download and install

All the files for ScaleUpEdit are in ScaleUpEdit.zip. The reader may just download that zip file into any desired folder or directory and then unzip it there. To top

Newton-Raphson, using Ruby

One of the program files is demo.rb. It looks like this:
# c:/ruby/bin/ruby.exe demo.rb

x=1.0

	15.times{ |j|
	x=x-( x**5 + x - 17.0 )/( 5.0 * x**4 + 1.0 - 0.0 )
	print j,"\t",x,"\n"
	}

In order to help load it into ScaleUpEdit, I have prepared a batch file called sue.bat looking like this:
start c:\tcl\bin\wish85.exe ScaleUpEdit.tk %*
The way of using it is to type
sue.bat demo.rb
at the Dos prompt and push return. (I speak of Microsoft Windows. The user will of course change all my batch files for other platforms and for other positions and names of wish.) The first line of the Ruby program shows the command which is going to be used to start the program after it is saved. If it is wrong for the user’s computer, I respectfully invite the user to make appropriate changes. Then the user may click the RUN button with the mouse. If everything is correct, the program area will be hidden and the output area will open showing the answers. Also, it will show the number of seconds the program used.

The way of getting back to the program area is by pushing the Escape key. This is usually on the extreme left of the topmost row of the keyboard. This key does not erase the output.

Of course, I have stolen the idea of using the first line to say how to run the file. The Unix and Linux shells do this with a shebang. I am merely taking advantage of comments. In the case of Ruby (and many other computer languages) the # character begins a comment. The RUN button’s procedure breaks the first line into tokens, using white-space, and then the left-most token is changed into exec. Then the tokens are handed to eval to be evaluated. The reader sees that there must be white-space after the comment token. Also the reader sees that those are forward slashes in the first line of the program, not backslashes, even though the path is in Microsoft Windows.

The program implements the good old Newton-Raphson loop to solve the equation x5 + x = 17 for its real root. The loop goes around fifteen times. All my demo and Demo programs implement this same algorithm. To top

Line number, dirty mark, key bindings, and type size

The line number and character number follow the title. For example, 8.2 means the eighth line, the second character of that line. That is where the cursor is.

The dirty mark is the asterisk, *. It goes on the left of the title when the file is “dirty,” that is, when the file in the editor is (or may be) different from the file saved in the hard disk. SAVE or RUN or GRAPH will erase the dirty mark.

I have bound control-minus to mean reduce the type size. I have bound control-plus to mean increase the type size, and I have bound control-equal to mean increase the type size. (The plus is the shifted equal sign on my keyboard.)

Control-c may be used to copy selected portion to the clipboard, both from the program area and from the output area. To top

Newton-Raphson, using Java™

Another one of the program files is Demo.java. It is brought by
sue.bat Demo.java
It looks like this:
// ScaleJava.bat Demo

import static java.lang.Math.*;

public class Demo
{

	public static void main( String[] args )
	{
	int n=15;
	double x=1.0;

		for( int j=0; j<n; j++ )
		{
		x=x-( pow(x,5)+x-17.0 )/( 5.0*pow(x,4)+1.0-0.0 );
		System.out.println( j+"\t"+x );
		}

	}

}
One may type
sue.bat Demo.java
at the Dos prompt and push return. (Again, I speak of Windows.) The first line of the Java program shows the batch file which is going to be used to start the program after the program is saved. The batch file is named ScaleJava.bat, and it looks like
@if exist %1.class del %1.class
@"C:\Program Files\Java\jdk1.7.0\bin\javac.exe" %1.java
@if exist %1.class java %1
If it is wrong for the user’s computer, I respectfully invite the user to make appropriate changes. Then the user may click the RUN button with the mouse. If everything is correct, the program area will be hidden and the output area will open showing the answers.

I respectfully point out that the last token of the first line of the program is merely Demo, without a suffix. To top

Other demo and Demo examples

I have also included demo or Demo files for C Sharp, PHP, Perl, and Python. As I said earlier in this file, all these programs implement the same algorithm, the Newton-Raphson loop. To top

Integration by Monte Carlo in Six Dimensions, using FreeBASIC

A common topic in numerical analysis is numerical integrals. I will take the integral of the square root of the sine of x*y*z*u*v*w over the unit hypercube in six dimensions. Here x, y, z, u, v, and w are the names of the six axes. I did try asking some freeware and proprietary calculus programs to do this symbolically, and they failed. Perhaps the reader knows of one that can succeed. Another thought is to use Simpson’s numerical method. The program will be complicated, because of the high number of dimensions.

No, the way to do this is to use Monte Carlo. That is, let us choose points at random in the hypercube and sum the values of the integrand. Then we can just divide the sum by how many values we used and print the quotient. The program is brought by

sue.bat sixDims.bas
and it looks like
rem ScaleBas.bat sixDims

option explicit
defdbl a-z

dim n,s
dim x,y,z,u,v,w
dim j as integer

n=1e7
randomize timer
s=0

	for j=1 to n
	x=rnd: y=rnd: z=rnd: u=rnd: v=rnd: w=rnd
	s=s+sqr( sin( x*y*z*u*v*w ) )
	next j
 
print "The answer is ", s/n
The rem token on the top line is the comment token of Basic. The ScaleBas.bat file is
@if exist %1.exe del %1.exe
@"c:\program files\freebasic\fbc.exe" -lang fblite -exx %1.bas
@if exist %1.exe %1.exe
As always, a user having her FreeBASIC in a different place will change the file to suit her.

Now the question arises, “How good is the answer?” The way to find out is to click on the RUN button, wait for an answer, push the Escape key, click again on the RUN button, wait for the second answer, push again on the Escape key, and finally click a third time on the RUN button, and wait for the final answer. If the three answers look somewhat alike, then maybe the true integral looks somewhat like them. This argument is feeble, but we have little choice.

I respectfully point out that the first line of the program file refers to sixDims without a suffix. To top

Cauchy Camel, using Lua or LuaJIT

In statistics class we are all told the virtues of Sir Ronald Fisher’s maximum likelihood estimator, that it is a panacea in every parametric problem. That is an overstatement of what Fisher actually said. We bring the program by
sue.bat graphCauchyCamel.lua
and it looks like
-- luaJIT graphCauchyCamel.lua

print( "set edge 5" )

local cauchy=function( x,c )return 1/( 1+(x-c)^2 )/math.pi end

local k=100

	for t = -2*k, 2*k
	do
	local product=cauchy( -k,t )*cauchy( k,t )
	print( t,math.log( product ),"purple" )
	end
The double hyphen of the first line is the comment token of the Lua language. The LuaJIT interpreter is an improvement to the Lua interpreter, and users having either may use it here. I respectfully draw the reader’s attention to the print statements. The first print statement prints set edge 5 which is a short statement in the Tcl/Tk language. The variable edge is the edge size of the solid squares of pixels of which the graph is made. (The squares may overlap, so things are more flexible than one may have feared.) We are setting edge to 5. The user is respectfully invited to change the edge size to suit her taste. This first print statement must execute exactly once.

The second print statement prints a number for x, a number for y, and a color name. The print statement must make white space to separate the three, but no other punctuation marks. The numbers will be rescaled and translated to fit the monitor, so the programmer need not scale them at all. The color name applies to the solid square of pixels to be drawn. To make the program happen, the user may click on the GRAPH button. (I am assuming that luaJIT.exe is in the path.) Then the program area will be covered up by the output area with a white background and solid purple squares to show the logarithm of the likelihood. The statistical sample has two numbers, k and -k, where k is 100. The user is respectfully invited to change the color name and the value of k.

The graph turns out to look like a two-humped camel, and the humps are sharp and equal in height. Which of these humps is at the maximum likelihood? To ask the question is to answer it. When the user tires of looking at the graph, a push on the Escape key will close the output area. The Escape key is commonly the leftmost key in the topmost row of the keyboard, and it is often labeled “Esc.”

Instead of clicking on GRAPH, the user may click on RUN, to see the numbers underlying the graph. When things go wrong, this is the right thing to do.

I nearly forgot to mention that Lua and LuaJIT as downloaded have no graphics of their own. That is the reason that I invented the GRAPH button. To top

Bessel, using Fortran 77

The preceding program printed in only one color. Now let us bring another program by using
sue.bat graphBessel.f
and we get
c scaleF.bat graphBessel

	function besselJ0( x )
	term=1
	sum=term
	k=1

16	continue
	term=-term*x*x/2/2/k/k
	k=k+1
	oldSum=sum
	sum=sum+term
	if( oldSum.ne.sum )goto 16

	besselJ0=sum
	end



	print *,"set edge 5"

	do 17 j=-10,250
	x=j/10.0
	y=besselJ0( x )
	print *,0,y," gray"
	print *,x,0," gray"
	print *,x,y," blue"
17	continue

	end
It uses two colors, gray and blue. The gray is for the horizontal and vertical axes, and the blue is for Bessel, using Bessel’s J0 function. The function is calculated by a Maclaurin series. The language is the f77 dialect of Fortran. The “c” at the left of the top line is the comment token of Fortran. The reader will notice " gray" and " blue" with a blank inside the quotes. This is to force whitespace between the ordinate value and the color name.

Here is scaleF.bat:

@path=c:\mingw\bin;%path%
@if exist z.exe del z.exe
@g77 -Wall -s %1.f -o z.exe -O3 -fomit-frame-pointer
@if exist z.exe call z.exe
@if exist z.exe del z.exe
The reader will perhaps change this to something more suitable. To top

Euler, using Chipmunk Basic

Next is an example with three colors: gray, red, and blue. It uses the Euler algorithm to solve van der Pol’s second-order differential equation for the triode oscillator with initial conditions. The equation is x''+a*(x*x-1)*x'+x=0. We let y=x'. We bring it by
sue.bat graphEuler.bas
Here is the program:
rem c:/chipmunk/chipmunk/basic.exe graphEuler.bas
print "set edge 2"

x=.01
y=0
t=0
h=.01
a=3

	for j=1 to 3e3
	t=t+h
	x=x+y*h
	y=y-( a*(x*x-1)*y+x )*h
	print t,0,"gray"
	print t,x,"red"
	print t,y,"blue"
	next j

quit
The rem at the left of the top line is the comment token for Basic. It may be that the reader put her copy of Chipmunk Basic in a different place from where I put mine, so I respectfully invite her to make the appropriate change to the top line. I respectfully point out that for Microsoft Windows the download of Chipmunk Basic comes with two interpreters: chipmunkbasic.exe cannot use the standard output, and basic.exe cannot do graphics. I use the latter.

I found out the hard way that the quit at the end of the program is really necessary. To top

Polar, using Free Pascal

Sometimes we wish a graph’s horizontal and vertical scales to be the same, so that squares will look square and not oblong. We wish circles to look circular and not elliptical. Especially for polar plots we wish to preserve shape. We bring the file by
sue.bat graphPolar.pp
Here it is, using set shape true:
(* ScalePp.bat graphPolar
*)
program graphPolar;

var
theta,r,x,y: double;
n,j: longint;

begin
writeln( 'set edge 2; set shape true' );
n:=1000;

	for j:=1 to n do
	begin
	theta:=2.0*pi*j/n;
	r:=sin(theta+0.4321)-0.5;
	x:=r*cos(theta);
	y:=r*sin(theta);
	writeln( x,' ',0,' lightgray' );
	writeln( 0,' ',y,' lightgray' );
	writeln( x,' ',y,' red' );
	end;

end.
The ScalePp.bat is
@if exist %1.exe del %1.exe
@if exist %1.o del %1.o
@c:\FPC\2.2.4\bin\i386-win32\fpc.exe %1.pp
@if exist %1.exe %1.exe
Allow me please to point out that the writeln of Pascal does not always put blanks between the fields, so ' ' must be inserted to make blanks. Please notice the semicolon between the two Tcl/Tk statements in the first writeln statement. The curve is a slightly tilted limaçon, a familiar polar curve from the calculus book.

I nearly forgot to mention the (* and *) tokens for a Pascal comment. ScaleUpEdit is not expecting a right-hand token, so the *) must be dropped down to the next line. To top

Lissajous, using Rhino

My last example is somewhat more light-hearted. It is a Lissajous graph printed in six colors. I stole the appearance of this from an animated True BASIC™ program called lissabox.tru. That was back in 1985. (Those were the days. True BASIC™ can still be purchased.) My drawing, however, does not move, and my algorithm is different and much simpler. The present program is in the EcmaScript language, in this case Rhino. It is brought by
sue.bat graphLissajous.js
and it looks like
// java -jar c:/rhino/rhino1_7R1/js.jar graphLissajous.js
print( "set edge 20; set background black" );
var n=5e2;
var kuller=["red","orange","yellow","green","blue","violet"];

	for( var j=0;j<n;j++ )
	{
	var x=Math.PI*2*j/n;
	print( Math.sin(3*x), Math.sin(4*x), kuller[j%6] );
	}
The // token is the comment token. Very possibly I put my js.jar in a different place from where the reader put hers. The statement set background black in the print statement is to make a black background for the graph, so it will resemble the good old True BASIC™ graph. To top

Caught in a loop

If the program seems to be running much too long, it may be that it is caught in a loop, and the programmer needs to stop it and the editor. The only sure way to do this in Microsoft Windows is to hold down the control and alternate keys and push the delete key. This will start the Windows Task Manager. Select “wish” or “wish85” or whatever its name is, and stop its process. Then select the running program, “lua” or “java” or whatever it may be, and stop its process too. Then stop the Windows Task Manager. It will then be possible to restart ScaleUpEdit and make a correction to the program.

I respectfully suggest that this is the only method that is sure to work. Stopping just the editor or just the program will fail astonishingly. One must stop both on the same occasion of using Windows Task Manager. To top

The widgets in order

First row, two text widgets

These are called leftText and rightText, and they have in them patterns and strings needed by or made by some of the buttons’ procedures.

Second row, buttons

REG SUB does regular expression substitution on the whole program. The pattern is in leftText. The thing to be substituted for the pattern is in rightText. If there is a beep and nothing changes, it may help to click the mouse in the program area and try again.

REG SUB SEL must be performed in correct order. First type the pattern in leftText. Then type the thing to be substituted for the pattern in rightText. Then use the mouse to select part of the program. Then click on REG SUB SEL. Only the selected part of the program can change. If nothing is selected, there will be a beep.

TCL/TK assumes that the contents of leftText is a program in the Tcl/Tk language, and it runs that program, putting the result, if any, in rightText.

\m\M puts \m on the left of leftText and \M on the right of leftText. This is to break on word boundaries, when searching for words or replacing words. This is meant for renaming variables or searching for variables.

***= puts ***= on the extreme left of leftText. This causes all the characters which follow to mean themselves and not be special. If the diagnostic “couldn’t compile regular expression pattern” appears, then the ***= button may be what is needed.

EMPTY LEFT clears leftText.

EMPTY RIGHT clears rightText.

UNDO undoes one change to the program. The number of UNDOs is limited only by the size of memory. This is handy when half a dozen wrong replacements or cuts or pastes have been done. Just UNDO six times, and nobody will know what happened. Even SAVEs and CLSs and RUNs and GRAPHs do not prevent UNDO. Using an editor without unlimited UNDO is greatly hazardous.

REDO cancels out UNDO. The number of REDOs is limited only by the number of outstanding UNDOs. This is handy when too many UNDOs have been done.

GREP finds all appearances in the program of the pattern in leftText. Then these appearances are appended to the output area. To leave the output area, push the Escape key. GREP is not case sensitive.

Third row, buttons

SAVE saves the contents of the editor and erases the dirty mark, but it does not do anything else. This is needed when editing things that are not programs, such as html pages, including this one.

TAB tabulates all the selected lines one tab to the right.

UNTAB untabs all the selected lines one tab to the left.

WRAP causes word wrapping.

UNWRAP prevents word wrapping.

LQQ inserts the html code for left double quote.

RQQ inserts the html code for right double quote.

LQ inserts the html code for left single quote.

RQ inserts the html code for right single quote.

CUT cuts the selected portion. That is, it copies the selected portion to the clipboard and erases it from the editor.

COPY copies the selected portion to the clipboard.

PASTE pastes from the clipboard to the insertion cursor.

CLS means “clear screen.” It clears the output area.

RUN saves the program (and erases the dirty mark) and then uses exec to run it. The line at the top of the file tells exactly what to run. Then the program results are appended to the output area. Also, the number of seconds used by the program is appended to the output area. To get back to the program area, push the Escape key.

GRAPH saves the program (and erases the dirty mark) and then uses exec to run it. ( The line at the top of the file tells exactly what to run.) Then it erases the output area and makes a graph from the program results. To leave the output area, push the Escape key.

Lastly, the big text widget

This is where the program is, and where most of the typing is done. To top

Encoding

The default file encoding of ScaleUpEdit.tk is utf-8. That is, it expects to work on files in that encoding. Some legacy files are in different encodings. The rootTable.bas which I have included in the zip file is in the ebcdic encoding. A user wishing to see it is respectfully invited to type
sue rootTable.bas ebcdic
at the Dos prompt. The user will see a Basic program to make a table of square roots.

The available encodings at the time of writing are ascii big5 cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp737 cp775 cp850 cp852 cp855 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp932 cp936 cp949 cp950 dingbats ebcdic euc-cn euc-jp euc-kr gb12345 gb1988 gb2312 gb2312-raw identity iso2022 iso2022-jp iso2022-kr iso8859-1 iso8859-10 iso8859-13 iso8859-14 iso8859-15 iso8859-16 iso8859-2 iso8859-3 iso8859-4 iso8859-5 iso8859-6 iso8859-7 iso8859-8 iso8859-9 jis0201 jis0208 jis0212 koi8-r koi8-u ksc5601 macCentEuro macCroatian macCyrillic macDingbats macGreek macIceland macJapan macRoman macRomania macThai macTurkish macUkraine shiftjis symbol tis-620 unicode and utf-8. To top

The j template

The only part of Java™ programming that is not fun is the very beginning, typing the class declaration and the declaration of the main method. For this I have written a proc called j. Just type j into leftText, and click on the TCL/TK button, and those declarations will be inserted into the editing area. If something is already there, it will go inside the main method.

The proc is clever enough to look at the name of the file and derive the class name from it. For instance, if the file name is Payroll.java , then the class name will be Payroll without the .java . That is, the suffix and its preceding dot are not used. To top

License, revision date, and e-mail address

All the files in my zip file, and the zip file too, are in the public domain. On the other hand, the computer language compilers and interpreters that I mention are not mine at all, and they are protected by trade marks and copyrights. The date of my most recent revision is 17 September 2009. Please send criticism, both constructive and destructive, to me, Harold Kaplan,
       at        dot
smtw2gh  toadmail   com
To top

For links to some of Harold Kaplan’s programs, click on programming.htm.