Calc
Table of Contents
- 1. Global Keybidings
- 2. Local Keybindings
- 2.1. Help
- 2.2. Input
- 2.3. Basic Operations
- 2.4. Array Operations
v(V) - 2.5. Algebra
a - 2.6. Builtin Functions
- 2.7. Random
- 2.8. Units
u - 2.9. Store
s - 2.10. Select
j - 2.11. Convert
c - 2.12. Display
d - 2.13. Mode
m - 2.14. Trail
t - 2.15. Time
t - 2.16. Graphing
g - 2.17. Define Function and Macro
z,Z - 2.18. Register
r
- 3. Configurations
- 4. References
Calc is an advanced desk calculator and mathematical tool written by Dave Gillespie that runs as part of the GNU Emacs environment.
1. Global Keybidings
<C-x> * c,<C-x> * *,<M-x> calcto open<C-x> * oopen another window<C-x> * qquick calc. open in the minibuffer
<C-x> * eembedded calc on a block of continuous formula as a line, after evaluating it.- The separation of a block is detected by a two newlines. So the previous line must be empty.
<C-x> * jembed but on appropriate side of the=>or:=.a:=10becomes. .. 10<C-x> * wembed on a single word if the expression is not parsable, otherwise same as just embedding.- The embed can be exited with any of the commands
<C-x> * btoggle full screen for the Calc<C-x> * yyyank the top element to the most recent edit buffer<C-x> * ggrab, parse a line into the top element as vector- The number of line can be given as numeric prefix,
and if only
C-uis given the line is interpreted as a single entry. - Use Emacs region instead of evil region
- The number of line can be given as numeric prefix,
and if only
<C-x> * rrectangle, parse a region as matrix- The column length can be given as numeric prefix
- It works with evil region as well
<C-x> * :grab rectangle and sum the columns<C-x> * _grab rectangle and sum the rows
<C-x> * 0reset<C-x> * xturn calc off<C-x> * mread in as a macro<C-x> * zuser invocation- start Calc with user defined macro by
Z I
- start Calc with user defined macro by
2. Local Keybindings
The key in the heading is the common prefix.
pset precision- The floating point precision default to 12
xrun calc command<M-x> calc-qquit
2.1. Help
imanualhhelphall keybindingsssummary appendiximanual
?rotate through the brief help
2.2. Input
<,>scroll to the right/left{,}scroll up/down
Edit
Uundo,Dredo<TAB>rotate the top two- rotate the top
Nelements downward while wrapping if positive - move the entire stack
Nstep downward if negative. <M-...>rotate upwards
- rotate the top
<DEL>remove the top- remove the top
Nelements if positive - Delete the entire stack if
0 Nth element form the top is removed if negative<M-...>remove from the bottom
- remove the top
Input
<RET>duplicate the top element<M-RET>push the last arguments- recover the deleted elements by a function
[2-32]#NNinput number in a given radixNNeNNscientific notation_negative sign:enters the fraction[ .. , .. ; .. ]vector and matrix,[ .. ][ .. )interval, representing all number between the bounds[(pushes the incomplete object and complete it later.{ .. , .. }can also be used. comma is required
( .. , .. )( .. ; .. )complex number (in polar),NN@ NN' NN"hms time"string- Operation can be put right after number
$can be used in place of the top stack element, the output will be replace the top$$,$$$repeatedly using dollar sign accessNth element from the top
'algebraic input- Insert an expression containing symbols, equations, and various others
<RET>evaluate and the expression and insert<M-RET>evaluate with the variables resolved, and insert<C-j>or<LFD>(Line Feed) does not evaluate it,=to evaluate it later.
/has lower precedence than*.a mod bmodulo arithmetic+/-to include the uncertainty
< , : >inline function- The arguments are given in a vector.
- It cannot be used on its own. It needs to be evaluated by
another function, such as,
call(f, a, b),v A,apply(f, v)
2.3. Basic Operations
- They take the elements from the stack and perform certain operations
- Number prefix can be given
- The binary operation is going to be reduce the top
Nelements if positive, or operate on eachNnext-to-top element by the top element if negative.
- The binary operation is going to be reduce the top
+,-,*,/,^\integer division,%modulo:fraction~can be used to use the top element as the prefix numberKkeep the arguments in the stack by prefixing this- Evaluation
=evaluate and substitute the stored variablesNexpand the irrational valuesa vevaluate algebra
- Simplification
a salgebraic simplificationu sunit simplification- Automatically applied when in
UnitSympmode
- Automatically applied when in
2.4. Array Operations v (V)
p,pack(a, ...)pack first few top element into another object depending on the mode specified by numeric prefixN, or the value of the top element.- Vector of length
NifNis nonnegative -1complex number-2polar complex number-3HMS form-4error form-5modulo form-6closed interval,-7upper half-open interval,-8lower half-open interval,-9open interval-10fraction-11mantissa and exponent into floating point number
- Vector of length
u,unpack(a, ...)unpack the top element- negative number specifies the mode
- It can unpack any formula as well, including equations
- It unpack the structure given by the underlying lisp representation.
- (Without the prefix)
|,vconcat(a,b)concatenate top two element into a vector,I |in reverse order,H |not recursively. Econvert an interval into a vector of integers:vector into an intervalipush an identity matrixddiagonal matrix out of the topxpush the index vectorr,c,mrow(m, i),mcol(m, i)extract the row/column of a matrix at the index of the top element or numeric prefix.s,subvec(m, i1, i2)extract a subvector from the first index up to the second index excluding it.- The index is counted from 1
- A row/column is removed if negative number
m_i,subscrcan be used for the algebraic case.
- The index is counted from 1
fsearch for an element in a vectoraarrange a vector or a matrix into a matrix of a given number of columnvreverse the vectorh,head(v)take the head, the first element of a vector.
2.4.1. Linear Algebra
- The regular multiplication
*does the matrix multiplication. ttransposeJconjugate transposeCcross product- (no prefix)
AEuclidean norm or Frobenius norm nInfinity normNone-norm&inverse of a square matrixDdeterminantTtraceLLU decompositionKKronecker product
2.4.2. Element-wise Operations
AApply- provide each element as each argument to a function.
Mmap,Rreduce,Uaccumulate(scan)- Map can take multiple vectors as the inputs
:,_map or reduce each column/row of matricesNspecify the number of arguments.- The element-wise operation can be any Calc binding
such as
+,v M,a ]. xselect a lisp function'specify a custom function- Write the expression inline, for example,
sin(x) + y.- The arguments of the function will be selected manually after
you press
RET.
- The arguments of the function will be selected manually after
you press
- The inline expression can contain
$,$$in which case you don't need to specify the arguments.$for the top,$$for the second to top, and so on.
- The anonymous function can contain
#1or#(one variable) in which case the arguments does not need to be specified. - A lambda expression can be passed as well, for example,
lambda(a, b, a+b).
- Write the expression inline, for example,
O,Igeneralized outer/inner product- Inner product requires specifying two operator
2.4.3. Set Operations
+remove duplicates,#set cardinality,Vunion,^intersection,-set difference,Xset XOR,~set complement with respect to real number
2.5. Algebra a
vevaluate the algebra,"expand into the definitionssimplifyxexpand: divide fractions, distribute multiplicationffactor a polynomialH a freturn the list of factors with its multiplicity.
c,collectexpress the polynomial in a given variable.n,nrat(a)normalize rational (symbolic fractions into a one rational expression),apartial fraction\polynomial division,%polynomial remainder,gpolynomial gcdI a strigonometric function simplificationH a shyperbolic function simplificationa eextended (unsafe) simplification
dderivative,i(integ(f),integ(f(x), x, a, b)) integrateI(ninteg) numerical integration
Mmap equation- Map both side of the equation
Pfind the root of polynomialSsolve the equations- It can also take a vector of equations and a vector of variables.
Rroot finding- A formula or an equation is solved numerically, starting from the top element
- It can also take a vector of equations, and a vector of initial values, a vector of variables.
- Assigned variable can be used,
_dose not constitute a variable. - The formulas have to be differentiable
Fcurve fitting- It act on a list of list containing each variables consecutively.
- The number specify the detail
1linear,2-9multilineare,x,E,Xpolynomial,l,LlogarithmicqquadraticgGaussian functionsLogistic- …
+sum over a given range*product over a given range
2.6. Builtin Functions
- Inverse modifier
I, and hyperbolic modifierHare often used Q,sqrt(a)F,floor(a),I F,ceil(a)R,round(a),I R,trunc(a)J,conj(a)complex conjugate,G,arg(z)argumentL,ln(z),E,exp(z),H L,log10(z),B,log(b x)S,sin(z),C,cos(z),T,tan(z),H ...!factorialfh,hypot(a,b)hypotenuseQ,isqrt(a)integer square root, square root rounded downn,min(m, n)x,max(m, n)r,re(z)real part,i,im(z)imaginary partg,gamma(z)Gamma functionb,beta(a,b)Beta functione,erf(z)Error functionj,besJ(n,x),y,besY(n,x)Bessel function
kCombinatorial/Statisticalg,gcd(a,x)Greatest common divisorl,lcm(a,x)Least Common Multiplec,choose(n,m),H ...permutationb,bern(n)Bernoulli numberse,euler(n)Euler numbers,H ...Euler polynomials,stir1(n)of the first kind,H ...stir2(n)of second kindptest if prime- For a large integer, probabilistic method in The Art of Computer Programming-volume 2-section 4.5.4-algorithm P is used.
f,prfac(n)prime factorizationn,nextprime(n),I ...,prevprime(n)t,totient(n)Euler's totient functionm,mobius(n)- Probability Distributions
- The nomenclature is
Xutpx,H ...ltpxfor cumulative - The random variable is the top element
B,utpb(x,n,p)Binomial distributionC,utpc(x,v)Chi-squared distributionF,utpf(F,v1,v2)F-distributionN,utpn(x,m,s)Normal distributionT,utpt(t,v)t-distribution
- The nomenclature is
2.7. Random
rrandom()- It generate a random integer between 0 and the numeric
prefix, or the top element
agenerate a number reusing the recent valuehshuffle
- It shuffles the top vector, may be truncated to a desired length
- It generate a random integer between 0 and the numeric
prefix, or the top element
2.8. Units u
- Units are just unassigned variables that are in the unit table
- Number with unit can be entered as a algebraic expression.
Most common units and constants are predefined
eps0ɛ0,mu0μ0,c,G,h,hbar,eech,k, …
ssimplify for the unit expression,aautorange unit prefix the unit with appropriate one.cunit convert,nconvert if exact,bconvert to base unit, equivalent tos based,udefine/undefine unit,rremove unit,u pmake it permanent in thecalc.elgget unit definition,vshow unit tablesStoreinf,e,pi,phi,gamma,uinf,nanare preassigned variables- These are only evaluated by
N, not=
- These are only evaluated by
2.9. Store s
- If the variable name is a number
Nit is stored in special variableqN. The quick variables can be directly specified withouts - If the top element is an assign statement:
=,:=, it will perform it rrecall, push the valueuunstoretstore into, pop the top element and storexexchange with the top of the stackccopy to another variable+,-, … perform the operation and assign, equivalent to+==evaluate to, enter the evaluation statement of the top element=>The expression on the left is untact, the value on the right is recomputed by=(evaluate) whenever something changes.
ddeclare the type of a variable or a functionltemporarily store the top element and evaluate the second-top element with it.i(calc-insert-variables) insert all variables in current calc to a buffer.- variable can be defined any other buffer than calc
- literal string is interpreted automatically by calc
p(calc-permanent-variable) specify variable to store into thecalc-settings-file(.emacs.d/calc.elby default)- edit the file directly when deleting variable
2.10. Select j
- Select within a entry and perform operation on them
s,uselect/unselectaadd,bbreak selection,mlselect more/less,1, …,9select =N=th partn,pselect next/previousdhighlight selected part within the whole formulacclear all selectioneenable/disable selection. the*marker disappears and the operation works on the entire formula anyway. It is enables by default.'replace selection through minibuffer input`edit selection through a temporary bufferR,Lcommute right/left,Ccommute within a selectionD,Mdistribute/merge a levelJjump equals, move a term on the other side of the equation+,-,*,/, … Operate on both side of a equation, or numerator and denominator of a fraction.
2.11. Convert c
fconvert fraction to float,Ffloat to fractionpbetween polar and rectangular complex numbersd,r,hdegree, radian, hms
2.12. Display d
tTruncate. It cuts the stack at the cursor, and stashes the ones "above" it.rchange the radixc,i,j, complex number format- Language
Nnormal,Bbig (pretty print),Uunformatted(raw Lisp),C,LLaTeX,TTeX- The complex number format does not apply in
BandC
2.13. Mode m
- The current mode is displayed in the mode line
apartly algebraic mode,(and[also starts algebraic input.tfull algebraic mode,<ESC>to not use algebraic input.
Signore cases, the prefix key becomes case insensitive.ddegree,rradian- The default unit of the output of functions that produce angles
ppolar mode, prefer complex numberffraction mode, prefer fractionc fcan be used to evaluate the fractions
iinfinite mode,1/0produceinfssymbolic mode, the irrational result will be left symbolicNcan be used evaluate into numeric result
vmatrix mode, every object is assumed to be matrices unless it cannot beCtoggle automatic recomputation,=>- Simplification
Ibasic simplificationUunit simplificationAalgebraic simplification (Default)Nnumber simplification, only number operations are simplifiedEextended simplificationOno simplification
msave modes, including display/language/precision/definition/calculationgget modes, push the mode numbersRrecord mode change directly into the file
2.14. Trail t
dtoggle traili,ofocus into/outof trailn,p,[,]move the trail marker>(to the start/end),ypush trail marker to the stacks,rsearch (in reverse)
2.15. Time t
Npush current datetimeDdate into a number measured since Jan 1, 1 ADJconvert date into Julian day countUconvert date into unix time valueCconvert time zone of date
2.16. Graphing g
- It stores the values in a temporary buffer and let the Gnuplot plot it.
fFast plot. graph the top two element using . top element is the \(y\).- \(x\), \(y\) can be a vector of same length
- \(x\) can be an interval, then \(y\) needs to be an algebraic expression in one unassigned variable
- The top element can be a formula of the form
xy(x(t), y(t)).
pplota,d,cadd/delete/clear the plotg,b,k… grid, border, keyNselect the number of datapointsqquit the plot
2.17. Define Function and Macro z, Z
Z Dbind the function to a keyC-x (,C-x )the globalkmacrocan include the followingcalcspecific functionalities.- Branch
<COND>Z [start if,Z |else if,Z :else,Z ]end if
Loop
<repeat count>Z < <BODY> Z >repeats a command in between, the top value times.<repeat count>is the top element<init> <final>Z ( <BODY> <step> Z )for loop, repeat with
counter
<init>,<final>are the top two elements of the stack<step>is a number<COND>Z /break out of macro loop
- Breaks when the top element
<COND>evaluates to true.Z {,Z }loop forever
- Scope
Z `Z '
Z Kset macro name for the last recorded macro, which can
be executed by
zZ Eedit macro<C-x> eorXexecute macro<C-x> ecreate a undo history for each command,Xcreate a single undo history
- Branch
Z Idefine user invocationm msaves this
Z Fdefine a formula- The formula at the top element is stored into specified key, command and function.
- The anonymous function can also be used.
Z Gpush the formula to the stack
Z Pdefine a command permanently in thecalc.elZ Uundefinezis prefixed to use the user defined keys and functions- Lisp
defmathcan be used(interactive NUM TAG)- Takes
NUMarguments from the stack.
- Takes
(calc-eval "expr")is available
2.18. Register r
scopy the region as calc stack to registeriinsert calc stack, or parse the string and insert
3. Configurations
Configurations can be stored in:
.emacs: Configure manually or viaCustom- the file set by
calc-settings-file(.emacs.d/calc.elby default).- This file is loaded on the first launch of Calc.
The global variables can be accessed directly, but the internal
functions and variables needs to be imported via (require 'calc-*).
- The variables that controls the initialization can be set.
- The detail can be directly found in the repo