Here is a long-term project of mine that still isn't finished, but is starting to become useful. I started this in a computer science class last year, so not all of it was done on my own time. At Olin, sometimes I'd like to have the software equivalent of my TI calculator. Matlab can be useful, but takes
a while to load and cannot be described as light-weight.
So, for quick calculations, I made Minimath, a small command line interface to evaluate math.
The main design goal was to save typing for commonly-occuring tasks. As you can see, the UI is pretty sparse now, and that is on my list of things to improve.
Another feature is variable substitution. Pressing alt-, makes a "<-" symbol that can be used to subsitute values into an expression. For example,
the result of "2*x^2 + 3*x <- 4" is 44.
- Fills-in incomplete expressions. It is perfectly ok to evaluate "sin(pi" without the closing paren, because it will understand what you meant.
- Line history, with arrow keys. Control-Up and Control-Down search history based on prefix like Matlab.
- Supports complex numbers, saving values in variables.
- You can press Alt-. to create a "->" symbol to store values, like a TI 83.
- "ans" refers to last result.
- If the first key you press is an operator, it fills in the "ans" like a TI 83. This one saves a lot of time.
- Any valid Python expression can also be evaluated.
- Pressing the "\" key (while not in a string literal) creates a lambda symbol, so that expressions like "f = λx.x+2" can be used.
- Pretty print, which behind-the-scenes is parsing the expression, creating and rendering a temporary LaTeX file.
- Uses Numpy library which provides many math functions.
In the future, I plan to add more-advanced interpretation.
For example, the string "3x4" could be recognized as "3*x^4", and "4(x+3)" to "4*(x+3)"
Also, I should integrate Matplotlib or something similar.
- The symbol "^" now is exponentiation.
- The ternary expression ? : can be used as in C.
- The shortened "for(i,5)" can be used in place of "for i in range(5)".
- Syntax for making arrays: "arr = a[1 2 3]" and "arr = a[1 2 3;4 5 6]". (Note that arrays are different than Python lists).
- "i[0,4,10]" is like Matlab's linspace, 10 elements equally spaced from 0 to 4.
- "i[0..4]" is an inclusive range, the result is [0,1,2,3,4].
- It allows more items on one line than Python, just use semicolons. In particular, something like "for val in array:t+=val;print val" will work all on one line.