--- Emacs Calculator Mode --- |Emacs Calc Mode v2.00...
2: 17.3 | 17.3
1: -5 | 3
. | 2
| 4
| * 8
| ->-5
|
--%%-Calc: 12 Deg (Calculator)----All----- --%%-Emacs: *Calc Trail*
2<ret>2<ret>+
+ the
two 2s visible on the stack become
replaced with a 4.
Q to extract In order to illustrate how to call various Calc function, I will use the following notation:2<ret>2<ret>+ 1: 4The top line is what you type, in this case2followed byreturnthen2andreturnagain, and finally a+. As you you type it all in, at the end Calc will respond with1: 4. The final answer is always the number 1 item on the stack, with other objects pushed down to positions, 2, 3, 4, and so on. Most often Calc functions take one or two top objects from the stack and replace them both with and answer. That way the stack doesn't grow too much.
2<ret>Q 1: 1.41421356237
90<ret>S 1: 1Observe that Calc measures angles in degrees, not in radians, by default. You can switch to radians as follows:
mrP2<ret>/S 1: 1.What happens here is as follows:
P, no need to follow it
with return
2 on the stack,
as before
M-x calc-radians-modeThis is the same as to type
mr. Now
type an apostrophy, followed by the formula:
'sin(pi/2) 1: sin(pi / 2)Calc took your algebraic formula, and placed it on the stack without evaluating it! To get the number type:
N 1: 1.Observe the difference:
M-x calc-degrees-mode 'sin(90) 1: 1Here I have switched again to the degrees mode. Instead of typing
M-x calc-degrees-mode
you can accomplish the same by typing md.
This time Calc not only evaluates
90<ret>C 1: 0 'cos(90) 1: 0 'cos(pi/2) 1: cos(pi / 2) M-x calc-eval-num 1: 0.999624216859 'cos(pi/2) 1: cos(pi / 2) N 1: 0.999624216859Capital
N, as in Mathematica, forces a
numerical evaluation of a
symbolic expression.
It is equivalent to calling Calc function
calc-eval-num.
45<ret>T 1: 1. 90<ret>T 1: tan(90) Division by zero: 1.In the second operation Calc flagged a division by zero. Indeed
mior
M-x calc-infinite-modeObserve the following:
mi 'tan(90) 1: uinf
uinf means undirected infinity,
in other
words, 'ln(0) 1: -inf 'exp(inf) 1: inf 'gamma(-7) 1: uinf
1<ret>E 1: 2.71828182846 'exp(1) 1: 2.71828182846 'exp(-inf) 1: 0This is very impressive. This is more than Maxima can do!
1<ret>L 1: 0 'ln(1) 1: 0
HS returns 1<ret>HS 1: 1.17520119364 'sinh(1) 1: 1.17520119364
IS returns 90<ret>S 1: 1 IS 1: 90 'arcsin(1) 1: 90
15<ret>! 1: 1307674368000In this case you can also do:
15!<ret> 1: 1307674368000Do you remember my comment that
'gamma(16) 1: 1307674368000
2<ret>2<ret>^ 1: 4 2<ret>3.7<ret>^ 1: 12.9960383417 '2^3.7 1: 12.9960383417 '2^-3.7 1: 0.0769465258341How can you input a negative number in a stack mode? The moment you type a minus sign, Calc attempts a subtraction! You can use either
n or _
for that. n toggles the sign of the
last number on the stack. _ is
used to enter a negative number, e.g.,
2<ret>_3.7<ret>^ 1: 0.0769465258341 n 1: -0.0769465258341
10<ret>HL 1: 1 'log10(10) 1: 1As you see, the key-stroke combination for
HL. For a logarithm of any base use
B, or 'log. This function takes
two arguments off the stack, with the second
one being the base:
15<ret>15<ret>B 1: 1 'log(15, 15) 1: 1 'log(100, 10) 1: 2 100<ret>10<ret>B 1: 2
gammaP and
gammaQ. They have key-stroke abbreviations,
which are as follows:
gamma, gammaP,
gammaQ,
gammag,
gammaG,
'gammaG instead of HIfG, but, the
point is that if you use these functions very often
in your work sooner or later you'll master the
key-stroke entry. Here's a quick demo:
'gamma(5) 1: 24 'gammag(5, 7) 1: 19.8482014108 'gammaG(5, 7) 1: 4.15179858917 + 1: 24. 'gammaP(5, 7) 1: 0.827008392118 'gammaQ(5, 7) 1: 0.172991607882 + 1: 1.
'(6 - 2) * choose(6, 2)<ret> 1: 60 '1/beta(3, 4)<ret> 1: 59.9999999999You can also use the stack notation and key-strokes perform both calculations. Key-strokes for
choose and beta are kc and
fb respectively:
6<ret>2<ret>-6<ret>2<ret>kc* 1: 60 1<ret>3<ret>4<ret>fb/ 1: 59.9999999999Calc can evaluate the incomplete beta function too. Its definition is
betaI which
is invoked by the fB key-stroke combination.
We also have the un-normalised version:
betaB and by
the HfB keystroke combination. Here
is an example:
'betaI(0.7, 3, 4) 1: 0.92953 'betaB(0.7, 3, 4) 1: 0.0154921666667 'betaB(0.7, 3, 4) / beta(3, 4) 1: 0.92953 '1/betaB(1, 3, 4) 1: 59.9999999999The Euler beta function is associated with some trigonometric integrals. For example:
Calc notation for the error functions is
erf (fe) and erfc (Ife).
Observe the following features of error functions:
M-x calc-infinite-mode 'erf(inf) 1: 1. 'erf(0) 1: 0 'erfc(inf) 1: 0. 'erfc(0) 1: 1 'erf(-1) 1: -0.842700792945 'erf(1) 1: 0.842700792945 'erfc(-1) 1: 1.84270079295 '2 - erfc(1) 1: 1.84270079295
How to input complex numbers into Calc? Simply type in a pair:
(2,7) 1: (2, 7) (3,4) 1: (3, 4) - 1: (-1, 3)Note: when you input complex numbers in the stack mode, you must not type a space between the comma and the imaginary part. You do not have to type a return at the end of your input either. Calc will place the whole complex number on the stack, the moment you type the closing bracket.
Using algebraic notation you can do as follows:
'(2, 7) - (3, 4) 1: (-1, 3)
You can also input complex numbers in a polar mode. To switch to the polar mode issue the command:
M-x calc-polar-modeor type
mpThis is a toggle, so to get out of the polar mode, simply type
mp again.
Back to the Bessel functions. They are invoked by
typing 'besJ(n,x) or fj and
'besY(n,x) or fy. For example:
'besJ(2, 3.5) 1: 0.45862918 'besJ(2, (3.5, 0)) 1: 0.45862918 'besJ(2, (3.5, 1)) 1: (0.60582898, -0.1362245)Observe the following relationships:
'(2 * 3 / 3.5) * besJ(3, 3.5) - besJ(2, 3.5) 1: 0.204405294287 'besJ(4, 3.5) 1: 0.20440529 '(2 * 1.5 / 3.5) * besY(1.5, 3.5) - besY(0.5, 3.5) 1: -0.173345324286 'besY(2.5, 3.5) 1: -0.17334532As an exercise verify with Calc the following approximate formulae that hold in the regime
Bessel functions appear whenever standing oscillation or eigen-value (much the same) problems are solved in spherical coordinates.
random. You can see the latter in action as follows:
*scratch* buffer by typing
C-x b *scratch*
*scratch* buffer type
(random)
C-j
kr:
20<ret>kr 1: 6To continue the generation or random numbers with the same top integer, type
ka:
ka 1: 5 ka 1: 13 ka 1: 12 ka 1: 9The key-binding
kr stands for 'random(n), e.g.,
'random(20) 1: 18If the number on the stack is a floating point number,
kr will return a random floating point
number between that number and 0:
1.73<ret>kr 1: 1.67106802028 ka 1: 0.206379750199 ka 1: 1.19060203945If the number on the stack is 0,
kr will
return a random number with a Gaussian distribution
with a mean of 0 and a standard deviation of 1:
0<ret>kr 1: 1.70864920311 ka 1: 1.07740857088 ka 1: 0.0891803626409 ka 1: 1.16205405156 ka 1: 1.20374162505If the number on the stack is given in the form of a mean with an error, i.e.,
kr
and ka generate random numbers with a Gaussian
distribution around the mean, e.g., 7, and with
the standard deviation as given by 7p2<ret> 1: 7 +/- 2 kr 1: 6.27794656568 ka 1: 7.28422903876 ka 1: 5.35137211447The argument on the stack can be also an interval, e.g., [3.7..7.4] or [3.7..7.4). The former includes the upper limit, whereas the latter exludes it. For floating point integrals, they are divided into one million chunks and
kr returns one of them
at random. The borders are included or excluded as
specified. For example:
[3.7..7.4] 1: [3.7 .. 7.4] kr 1: 5.93551484212 ka 1: 5.65907211985 ka 1: 7.26496077254For integer borders the result is an integer too:
[3..7] 1: [3 .. 7] kr 1: 4 ka 1: 6 ka 1: 7 ka 1: 5 ka 1: 4If the argument to
kr is a vector, then the result
is one element of the vector taken from it at random:
[7,3,5,11,24,2] 1: [7, 3, 5, 11, 24, 2] kr 1: 24 ka 1: 7 ka 1: 5You can also use
kr with algebraic vectors:
M-x calc-algebraic-mode [a,b,c,d,e,f,g,h] 1: [a, b, c, d, e, f, g, h] kr 1: g ka 1: c ka 1: g ka 1: aAnother useful random function is
shuffle, which
is invoked by the kh sequence. Try the following
while still in the algebraic mode (remember that
ma is a toggle):
'shuffle(5, [a,b,c,d,e,f,g,h,i,j]) 1: [j, b, a, f, h] 4 1: 4 kh 1: [b, h, a, j]
gcd and its key-binding is kg. That's
how it works:
'gcd(772435, 978985) 1: 5 772435<ret>978985<ret>kg 1: 5
lcm,
and the key-binding is kl:
'lcm(26, 34) 1: 442 'gcd(26, 34) 1: 2 '2*442 1: 884 '26*34 1: 884
gcd is the extended
gcd. It returns a vector of 3 numbers
[g, a, b] such that
'egcd(26, 34) 1: [2, 4, -3] '4 * 26 - 3 * 34 1: 2
!!, or in a stack mode
using kd. You cannot use !! in
in the stack mode. That would evaluate (n!)! which
would usually be an insanely large number.
The function name that stands for the double factorial
is dfact:
'8!! 1: 384 '7!! 1: 105
choose, and
the corresponding key-binding is kc.
Be it as it may, Calc function for that thing
is perm and its key-binding is
Hkc:
'choose(7,3) 1: 35 'perm(7,3) 1: 210 '3!*choose(7,3) 1: 210
'bern(0) 1: 1 'bern(1) 1: -1:2 'bern(2) 1: 1:6 'bern(3) 1: 0 'bern(4) 1: -1:30Observe that Calc returns Bk using exact fraction notation. The key-binding for Bk is
kb.
If you type Hkb you get Bernoulli
polynomial for that k:
8<ret>kb 1: -1:30 8<ret>'x<ret>Hkb 1: x^8 - 4 x^7 + 14:3 x^6 - 7:3 x^4 + 2:3 x^2 - 1:30
euler, key-binding ke, whereas
Hke computes the Euler polynomial:
8<ret>ke 1: 1385 6<ret>'x<ret>Hke 1: 0.999999999999 x^6 - 3. x^5 + 5. x^3 - 3.00000000003 x - 1.3e-11
stir1 or ks,
calculates the number of k-cycle permutations
of n objects. For example, the number of
2-cycle permutations of 4 objects is 11:
'stir1(4,2) 1: 11The second one, invoked by
stir2
or Hks, calculates the number of ways to
partition n objects into k non-empty sets, e.g.,
a 4 element set can be divided in 7 ways into two
non-empty sets:
'stir2(4,2) 1: 7
7<ret>kp 1: 7 [Prime (guaranteed)]Here the messages
Prime (guaranteed) appears
in the mini-buffer and in the print-out window.
The function invoked by the key-stroke kb
invokes a prime test. A test can be also carried out
by calling prime:
'prime(7000235) 1: 0 'prime(7) 1: 1where 0 stands for false and 1 stands for true. An integer can be factorized into primes by calling function
prfac, key-binding
kf:
'prfac(7000235) 1: [5, 11, 123277]Successive primes can be searched for by calling
nextprime, key-binding: kn, or
prevprime, key-binding: Ikn:
'prevprime(127276) 1: 127271 'nextprime(127276) 1: 127277
'totient(16) 1: 8 'totient(17) 1: 16 'totient(384) 1: 128
moebius or
by km tells us if its argument has
any duplicate prime factors (in which case
it returns 0) or if it is a product of k distinct prime factors, in which case -1k is returned:
'7*7<ret> 1: 49 km 0 '3*5*7<ret> 1: 105 km 1: -1
'utpb(7, 10, 0.5) 1: 0.171874999999 10<ret>0.5<ret>7<ret>kB 1: 0.171874999999
'utpc(15.31, 8) 1: 0.0533906926374Remember that in our programs we have calculated
There no key-binding for the
distribution.
F would be as large as it is if the fist sample's distribution has a smaller variance than the second's.The Calc function that corresponds to the F distribution is
utpf(F,v1,v2).
'utpn(7, 4, 3) 1: 0.158655253933is the probability that
a normal distributed random variable for a Gaussian distribution with mean of 4 and standard deviation of 3 would exceed 7
In Calc the probability that n or more random Poisson events with a Poisson
distribution of mean x will occur is given by
'utpp(k,x), for example:
'utpp(5, 10) 1: 0.031828057306this, again, is the upper tail function.
The function is given in terms of the Euler
beta function and the following integral:
In other words, if for a given t andis the probability , for
degrees of freedom, that t, which is related to the difference of means, would be smaller than the observed value if the means were in fact the same.
The Calc Student's t function corresponds to
and is called
is utpt(t,v). There's no key-binding for it.