Calqit: a quick calculator and scientific programming language.

Andrew M. Steane,
Exeter College, Oxford University
and Department of Physics, Oxford University
2023

March 2023 update: Calqit 2023 is now available.

 Download (alpha)

"Calqit" is pronounced with a hard q sound, as in "cal-kit" or "calc-it".

1. The basic message
2. Quick start
3. Further introductory remarks
4. Summary for experienced programmers
5. Tutorial
6. Syntax and function reference

1. The basic message

Using calqit you can type in things like
5 + 33/27
and
x = 0.5; y = 2 cos x
and
pi r^2
and
f = G M m / r^2
and expect to get back sensible results. Also, you can plot graphs, fit curves, handle files, etc., and altogether you have a complete programming language that is designed to be easy to learn, write and use. The language has elements of the flavours of Python and Matlab and Mathematica and Perl. It is not as sophisticated as any of those, but it is easy to use for the kinds of calculations you may find yourself doing in the context of teaching, studying and developing ideas. Also it is completely thorough and accurate (and fast) for many common scientific tasks such as fitting curves to experimental data or preparing lecture demonstrations. Like Matlab (and the freely distributed Octave), Calqit works with vectors and matrices, runs an interpretor, and is fairly flexible about types and declarations. Together, these features greatly simplify many kinds of scientific programming, and they enable the resulting code to attain respectable speeds.

The next thing to say is that Calqit is small and fast. It pops up on your computer and lets you get started right away. If you want to get a numerical answer to some problem in physics or engineering, for example, it has built-in many of the physical constants you may need, and it comes with its own database of information relating to physical properties of the most common substances, as well as a selection of other information such as properties of the solar system and the definitions of common units. You can also extend this database yourself.

Calqit uses the Gnu Scientific Library (GSL) for some mathematical functions, and therefore is distributed under the terms of the GNU General Public License.

2. Quick start with no fuss

The way to learn Calqit is to try some examples as described below, then look at and run some example scripts to see how programming is done. After that you may want to consult the technical information if you need to, or when you want to see if there is anything you have missed.

Calqit is currently distributed as a .zip file (for Windows). Extract all the contents to some convenient place on your system, then double-click calqit.exe (you can find it in the explorer and put a shortcut on your desktop if you like). [If windows sends a warning such as "The publisher could not be verified, are you sure you want to run this software?" then simply click "yes". This warning indicates merely that your operating system has not been told to trust the program. You can update your configuration later to correct this.]

Once you have Calqit running, the simplest thing to do is either to type in
help
and hit 'enter', or just type
?
(and hit 'enter') or pick 'basic help' from the help menu using the mouse. In either case you will see some simple information with ideas on what to do next.

Next enter:
help plot
or
?plot
You should see some help on the plot function. Towards the end are some examples. Double-click on the first example (just after the line "e.g."). You should see a plot appear, and also the related command will appear at the prompt.

Next, double-click one of the other examples, and see that a new graph appears.

Next, in the main calqit window, hit the up-arrow key. You should see the last command reappear. You can now change it if you like, and then enter it again using 'enter' (also know as 'return').

Hopefully by now you get the main idea. You can try some calculations and see what happens. The next section will fill out some of the syntax rules which are designed to make calculations easy to do.

N.B. Calqit is currently an alpha version, that is, useful but incomplete. Click for more info.

3. Further introductory remarks

One of the aims in developing Calqit is that writing calculations should feel similar to the way they are written on paper. So for example, multiplication is mostly assumed so you don't need the * symbol, and for functions you don't always need to put a bracket. Thus you can write
5 cos pi
and you get the answer -5 as expected.

Here are some further examples:

> # comments begin with '#' (as in Python)
> a=4                              # a simple assignment      
4
> b=6; c=2;                        # two commands on one line, semi-colon suppresses output
> (-b + sqrt(b^2 - 4 a c))/(2a)    # note the implied multiplication
-0.5
> -b + sqrt(b^2 - 4 a c) % 2a      # % means "divide the whole lhs by the whole rhs"
-0.5
> 1 + 2 // pi b^2                  # // means "divide this item by whole rhs"
1.01768388
> x=[0:4, 7,11]                    # the vector (0,1,2,3,4,7,11)
0 1 2 3 4 7 11
> x.sum                            # also allowed: sum x, sum(x), and some other forms
28
> plot(exp(-x^2/2);x,-4,4);        # plot a function
>?plot                             # get help regarding the plot function

The main uses foreseen are quick everyday calculations, exploring and checking ideas for research, science teaching (lecture and class demonstrations), real time looking at data (rapid curve fitting etc.), handling text and text files, and creating small programming projects. The syntax rules have been designed to be reasonably natural and flexible:

> # Bracket freedom: sin(x) means the sine of x. So does sin x, sin[x], sin{x} and \sin{x}.
> cos pi, cos(pi), cos{pi}, cos[pi], \cos{pi}
-1 -1 -1 -1 -1
> # You can often omit brackets altogether when working with functions.
> cos x, sum cos(x), poly a,x         # all do what you would expect.
> # An expression or assignment followed by ;; means "display the result":
> for i=1:10 { i;; 'hello';; }
> for i=1:10; disp 'hello ', i;       # use disp to arrange the output conveniently
 
> eV^2/(4 pi eps0 hbar c)             # many fundamental constants are pre-defined
0.00729735
> eV^2//4 pi eps0 hbar c              # // means everything to the right is in the denominator
0.00729735
> t=0:3; cos^2(t) + sin^2(t)          # cos^n(x) means (cos x)^n
1  1  1  1
> rho << density of copper            # look up a physical property in calqit's database
Density of copper: 8933 kg/m^3.
8933
> rho = property('density','copper'); # same thing written out as a function call    
Density of copper: 8933 kg/m^3.
> x=[0:2,7,11]
0 1 2 7 11
> x.4                                 # the 4'th element of x (can also be written x[4])
7  
> s = sum(x^n/n!; n, 0:100)           # note the intuitive syntax for this sum
1 2.71828 7.38906 1096.63 59874.1
> log s                               # confirm that s was the series for exp(x)
0 1 2 7 11
> myfun(n,x) := (sin(x)/x)^n;         # user-defined function
> m=Me;                               # set m equal to mass of an electron
> ke(v) := (1/2) m v^2                # user-defined function using a global variable m
> qinteg(exp(-x^2);x,[0,inf])         # can't remember an integral? get it here
0.886227
> 4(ans^2)                            # ans refers to the previous answer
3.14159                     

Calqit is

  1. small and powerful. Calqit offers a complete programming language. The total footprint on disk is about 1 Mbyte. The start-up time is essentially immediate (i.e. limited by your hard drive or network speed).
  2. intelligent: it allows the user flexibility in syntax and does a good job of interpreting what is meant and displaying results in a useful way.
  3. vectorized: handles lists of numbers, vectors and matrices, strings, and some other data types such as stack, queue, list.
  4. fast: it has good performance on a number of speed tests. It is not as fast on low-level numerics as compiled Fortran or C, but it compares well with high-level programming languages such as Matlab and Python. It has a similar speed on many tasks and is faster on some.
  5. well-informed: it possesses a database, containing a large number of physical constants, properties of materials, and scientific and mathematical formulae.
  6. suitable for creating lecture demonstrations: the language offers easy-to-implement animation via replot, and easy access to the mouse via getmouse, onLDown, onDrag, etc.

Overall, calqit offers a high-level language with an intuitive and flexible syntax, plenty of predefined constants, and a restricted range of types.

2023: alpha version
New software is commonly labelled alpha, beta, gamma, to indicate its state of development. alpha is a preliminary stage where the program is useful but incomplete. calqit has been at alpha stage for many years but during that time has developped significantly.

Strengths and weaknesses:

  • alpha-calqit should be regarded as a general purpose scientific calculator and a programming language. I have used it for: data analysis; testing out ideas in theoretical physics; text handling tasks such as extracting words from LaTeX files; creating high-quality graphics for research papers and textbooks (via Tikz); helping to prepare a bibliography; creating demonstration animations for physics teaching; creating some games. For many such tasks I prefer it to Matlab, Octave and Python, but beware: it is not nearly as sophisticated as those tools when it comes to user-defined classes and advanced numerical techniques. The programming language is function-based (like C) not object-oriented. If you have an object-oriented approach to programming, then you should regard the whole Calqit session as a single object, and therefore do not be shy of using global variables.
  • There are currently some major omissions, such as three-dimensional graphics.
  • Also missing (but planned): further special functions, bitmaps
  • Almost missing (=under development): keyboard input in user programs (getch, getkeyb functions).
  • Some speed-ups are still to be implemented.
  • Calqit does not offer many data types, but you can achieve some structure-like effects by using lists.
  • It is easy to write small programs, e.g. to demonstrate some maths or science, or load and analyse some data. Larger programs will need a debugger. This is planned but not yet available. The language includes some basic debugging tools such as assert and the use of ;; (display value).
  • 4. Summary for experienced programmers
    5. Tutorial
    6. Syntax and function reference

    7. History

    Calqit evolved from an earlier program called "AndyCalc" that was developed on DOS and was restricted to scalar calculations. AndyCalc proved to be a convenient and popular tool in the Oxford University Ion Trap Quantum Computing research group, so it was decided to upgrade it for Windows. The new program was for a while called jCalc, then re-named to calqit in 2011. calqit can handle vectors and matrices as well as single numbers (scalars) and has a greatly expanded set of functions. Calqit development began in 2007 and progressed intermittently. A major revision was undertaken in 2009. During 2010 occasional additions and tweaks were made. A functioning version was released in 2011. Most of the basic functionality was in place, but some syntax issues were still to be decided, and the graphics had some problems. In 2015 a major upgrade corrected those problems and introduced considerably more functionality. In late 2020 there was another major upgrade. Large parts were re-written to improve stability, make the language syntax more flexible, and settle some issues to do with the move to Windows 10. This upgrade continued intermittently to 2023 as I found time, and then in March a version (Calqit 5.3a) was released. I still have some reservations about it because of the omissions, but the fact is that I use the program all the time and find it very useful, so maybe others will too.

    [top]