You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This calculator started as an idea for a project for [REDACTED: name of a particular online course] which I felt would be difficult enough to test my own limits as well as be an actual functional tool that I would use for my day job (math tutor).
Intended to perform quick algebraic calculations.
Main feature: Flexible and 'loose' parsing of algebraic expressions, much like how one would write them out.
Installation
Clone the repository.
Install windows dependancies
pip install -r requirements.txt
Run calculator.py
python calculator.py
Commands
Command
Description
help
shows this page
vars
displays user-defined variables
del [v1] [v2] ...
deletes one or more user-defined variables
prec N
set working precision to 10^(-N), i.e. N decimal places
disp N
set final display precision to N decimal places
frac N
set length limit for fractions to be displayed
keyboard | kb [on/off]
enables / disables keyboard module for detection of Ctrl / Shift
debug [on/off]
debug mode shows calculation steps
sto[re] | = | -> <varName>
store previous calculation into 'varName'
Editing
Common text-editor functionality is available, i.e.
Holding Ctrl enables word-jump,
Holding Shift enables selection.
Backtick ` switches the active window. While the display window is active, use up and down to select, then Enter to paste into the input window.
Hotkeys
Description
Shift + <Arrow>
Text selection
Ctrl + <Arrow>
Jumps forward/backward by one word
Ctrl + X / C / V
Cut / Copy / Paste
Ctrl + A
Select all
Ctrl + Bkspc
Delete word at cursor
Things to try
Input
Notes
2{3-4[5+65(3!
Multiple bracket types are supported, and brackets are auto-closed
x = 2; 2x + 1/x
Semicolons separate expressions and evaluate to the rightmost expression
Whitespace has an effect on precedence. Some examples:
Input
Notes
a = 2/3x; b = 2/3 x
a evaluates as 2/(3x), b evaluates as (2x)/3
a = sin pi/2; b = sinpi/2
a evaluates as sin (pi/2), b evaluates as (sin pi)/2
4x^3/5
evaluates as (4x^3)/5
a = 1/2/3/4; b = 1/2 / 3/4; c = 1 / 2/3 / 4
Give these a try!
The previous calculation is automatically stored as ans:
Input
Notes
ans
shows previous calculation
2ans (repeatedly)
number keeps doubling
ans % 2 && 3ans + 1 || ans / 2 (repeatedly)
Collatz sequence starting with ans
You can store and use your own variables:
Input
Notes
a = b = c = 9
assignments can be chained
(a = 3)a(b = 5)bb
not sure why you would ever do this, but it's 1125
a^bc^d
evaluates as a^(b*(c^d)), unless bc exists, in which case it would be a^(bc^d)
pi = 3.14; r = 3
pi and e are (re)defineable. Use del to reset
pir^2
evaluated as pi∙r^2, unless a variable pir also exists, in which case it would be (pir)^2
a = b = c = ab = bc = ac = abc = 1; abc
multiple possible parses will trigger a warning
You can define your own functions. Use vars to see some preset functions.
reduce(f, v, a) = v$ ? reduce(f, 1 </ v, f(a, v @ 0)) : a
reduce function
dotProduct(u, v) = u$ ? u @ 0 conj(v @ 0) + dotProduct(1 </ u, 1 </ v) : 0
improved vector dot-product (any dimension)
transpose(m, result = (), col = (), r = 0, c = 0) = result$ == (m @ 0)$ ? result : r == m$ ? transpose(m, result <+> (col:), (), 0, c + 1) : transpose(m, result, col <+> (m @ r @ c:), r + 1, c)
matrix transposition
matrixMult(A, B) = B = transpose(B); (helper(result = (), row = (), r = 0, c = 0) = r == A$ ? result : c == B$ ? helper(result <+> (row:), (), r + 1, 0) : helper(result, row <+> (dotProduct(A @ r, B @ c):), r, c + 1))()
matrix multiplication. Observe that helper is an IIFE.