Hello, my name is Christopher Howard and welcome to my talk.
This is basically an introduction
to the built-in Emacs calculator,
properly known as Emacs Calc,
particularly from the perspective of someone
with a technical background such as engineering or electronics.
I will say, though, my personal interest is not really
in digital computing or digital calculators,
but lately has been focused more on analog computing.
I have, for example, been working to master
the venerable slide rule, a mechanical computer
that calculates multiplication powers and logarithms.
Here's a picture of one.
It's a physical tool that was used for hundreds of years
for this sort of thing
before the handheld calculator was made popular.
And I also had a project that I did
for a while to several months
to build an electronic analog computer.
A rudimentary attempt of mine, but it's functional,
and it's basically a 1960s or 1970s style
electronic analog computer built very much on a budget,
but the box in the middle is the computer proper
which has most of the components inside of it
as well as the potentiometers for setting values,
and an operation switch.
There's a patch panel on the left
for connecting the different integrators,
amplifiers, multipliers, and so forth together.
Then the output of the simulation is displayed
on the oscilloscope on the right side,
which is a digital oscilloscope.
To be honest, I think that a talk about analog computing
would be much more interesting
than the talk that I'm about to give,
but unfortunately that would be out of scope for EmacsConf.
So instead I will talk about Emacs Calc,
the digital calculator built into Emacs.
Emacs Calc, while not being a replacement for software
like GNU Octave, does have advanced calculator functionality
that can be useful in engineering, electronics,
or other technical applications. So I don't want to oversell it,
but I think functionality-wise, Calc is somewhere in between
what you'd expect of a decent scientific calculator
and an advanced graphics calculator.
So this talk I'll mention is not intended to be a tutorial
but only a brief introduction to Calc.
Please refer to the built-in Calc info manual
for detailed instructions on how to complete operations.
Turn off my volume here.
The documentation for Emacs Calc is built-in,
although on some distributions you may have to install
the Emacs documentation separately for licensing reasons.
Calc presents itself as a stack-based calculator
where entries are dropped onto a stack
and then an operation is performed on the stack entries.
For example, I can drop 1.23 onto the stack,
and then 8.56, and then multiply them together.
It may present itself as a stack-based calculator,
but indeed, Calc is also capable of accepting input
in the more well-known algebraic format
by using the calc-algebraic-entry command,
which by default is bound to the apostrophe (') key.
So you type the apostrophe key, enter the algebraic input,
including parentheses as needed.
For example, here's a calculation of the resonance frequency
of a coil which has an inductance of 250 microhenries
and 160 picofarads, taken from one of my electronics handbooks.
The formula for that is 1 over 2 pi
and then the square root of our inductance
which is in this case 250 microfarads - excuse me, microhenries
and then the capacitance is 160 picofarads.
Small typo here.
Now I need to evaluate that one more time,
because pi is a symbol.
I get about 800 kHz resonant frequency.
The command calc-roll-down,
which by default is bound to the TAB key,
will swap the top two stack entries,
which is sometimes useful if you need to manipulate something
that's further down the stack.
So I can swap this around and say multiply by two
and then put it back where it was.
This command is also capable of rolling the entire stack.
Say I want to shift them all around.
This can be done by passing extra arguments
to the calc-roll-down function.
That's a little bit inconvenient to do manually,
so in my init file, I defined here a key definition
that passes in those arguments correctly.
I attached this to shift-tab,
so this way, I can roll the entire stack.
Then I could change one entry here
and then put it back where it was.
So Calc does algebraic input.
It also does advanced functions
that you would expect any handheld scientific calculator,
including trigonometric functions.
For example, we can get the sine of a number.
Now I'll mention here that Calc has multiple modes.
Right now it's in degree mode.
You can switch over to radian mode if you want.
I'm going to put it back in degrees.
Drop 12 degrees on the stack, and then get the sine of that.
And then with the inverse sine function, I can put it back.
Calc also has the nifty ability to solve equations for you
so long as the equation is not too complicated.
This is using the calc-solve-for function.
For example, we could enter in an equation algebraically,
then run calc-solve-for, and we just have to tell it
what variable we want to solve for. And there we go.
We can do this manually as well
just so you can see that we get the same result.
Calc is also able to solve systems of equations.
We can put more than one equation on the stack,
and then solve for several variables.
To give a technical example for this,
I'll show you a resistor network scribble that I did recently.
Hopefully you can see that. Basically,
it's fairly simple, a pretty simple resistor network
with 1 kilo ohm and 10 kilo ohm resistors,
and using the loop methods, we are calculating the currents,
the current in each loop, and then that current can be used
to solve for the voltage of each individual resistor
if we want to. So at the bottom there we have the equations
that we come up with as we work through each loop.
And I'm going to paste that into Calc.
To save some time, I'm going to copy and paste that
from my notes instead of typing it out.
So we have two equations there on the stack
in one stack entry. We run that calc-solve-for function again,
and we tell it which variables we want to solve for.
And voila! Those are our currents,
which we can then use to get the voltages
for the individual resistors.
I'll just briefly mention
that if Calc is not able to solve an equation
with calc-solve-for,
then you might be helped by another calc function
called calc-find-root.
This function basically does a manual search
for a numerical solution to the equation.
And there's the documentation page on that.
Calc can also solve or find derivatives of functions,
at least the more straightforward functions.
For a simple example,
we can get the derivative of that
with the derivative function.
On the other hand, Calc is also capable of figuring out
indefinite integrals.
Say we put that function back on the stack,
and this time, we call the integral function.
There you go. Of course, you have to add
your own constant of integration.
For integrals that Calc cannot figure out symbolically,
a numerical integration method is available
through the calc-num-integral command, which is documented...
The function documentation is available here, more or less.
I definitely need to mention
that Calc is capable of doing programmable functions.
That is to say, you can program your own functions into Calc.
There are three separate ways to do this.
One is through a macro method
similar to Emacs's usual keyboard macros.
The second method is to transform an algebraic function
into a stored function definition.
And the third is to use Elisp directly.
Personally, I find that the second method
is the most practical, the most convenient and practical
in my opinion. So I'll give a quick example of that.
So I could... Let's say I wanted to have a function
for calculating capacitive reactance.
I'll define that in algebraic mode first.
The function for that is 1 over 2 pi
the frequency and the capacitance.
Drop that on the stack. You see, it does automatically
get simplified a little bit, but it's the same function.
And then I press letters Z and F. Do that again.
Z and F to start transforming that into a stored function.
It asks me to select a user key, a single key press.
I'll use the letter c.
Then it's going to ask for a longer command name.
I've actually defined this once before, so it prefilled in
that command name.
Then I need to enter which variables in the formula
are actual arguments, rather than just symbols
to be evaluated later. I prefer to put this in with frequency
and the capacitance after that,
but actually in this particular case,
it doesn't matter at all to the mathematics.
So, now all I have to do, that this is defined,
is I can drop the frequency on the stack,
which we'll say, for this example, will be 4.5 MHz,
and then drop on the capacitance, which in this example
will be 22 pF.
Then I'll call the function that I just defined.
I don't really like having to try to remember
the short letters that I've come up with,
so I'll just use the longer name.
I need to evaluate one more time
because the symbol pi is in there and not yet evaluated.
And so if I've done that right,
we have a capacitive reactance of about 1600 ohms.
As the last feature that I'll mention here,
Emacs Calc does have an interface with gnuplot,
if you want to have Calc work as your graphing calculator.
I do need to be honest and mention
that I don't generally use it myself
because there's another program in GNOME
that I've found to be generally more convenient
for the things that I want to graph quickly.
But I think I can give you a simple example.
So first, we need to drop a range on the stack.
Let's say 0 to 10.
And then we need to drop the function on the stack.
And then I believe it's the letters g and f that graph this.
Let's see. Yep, there we go.
So there's our function and it looks nice.
That was pretty easy.
That's the fast way to do it.
I will, as a disclaimer, mention that
using this quick approach,
that sometimes more complicated graphs
will not turn out nicely,
because by default, the resolution will be pretty low.
That is to say it's... gnuplot is going to be
skipping a lot of points
and so you'll have to learn a bit more
about how to use the interface,
what parameters to pass if you want all your graphs
to come out looking nice.
So that covers all the features that I wanted to cover.
I wanted to briefly mention a wish list of items
that I'd like to see in Calc.
One of them would be improper integrals.
So that's like our definite integrals
except for where a limit of integration is infinity.
That's something that can be useful in a few applications.
Something else that would be neat to have would be
annotations for row entries. So for example
if I was putting together a sum of numbers
for, say, my monthly budget,
let's say I was paying $2,000 for my rent
and let's say $800 a month for my groceries,
(a lot of kids to feed there)
and then say another $60 for dining out, and so on,
it would be nice if there was some way
to put a little annotation next to each number
so that you could remember
what the meaning of that number was more easily.
I actually looked into programming this into Calc myself,
but discovered that it would require reprogramming
quite a bit of Calc to make that work well
across all calc functionality,
and so, eventually, I gave up.
But I'd still really like to have that feature.
The final thing, though
I think this would not necessarily belong in Calc,
I think it would be cool if Emacs had some way
to run numerical solutions
for systems of differential equations,
also known as a differential analyzer.
So this would allow you to be able to set up simulation models
involving systems of differential equations,
for example, a spring mass system, or pressure temperature,
or what have you, and then run the simulation
using numerical approximation.
Maybe it would be silly
to actually put that in Calc itself,
but a nice interface maybe to some other software,
simple software that did that,
an easy to use interface for that
would be really great.
So that's my entire talk.
I'll just mention some information.
If you want to learn more about me
or things that I'm interested in,
I do not any longer have a web presence.
I don't have a website anymore,
but I do have a Gemini capsule
that I post to all the time.
And if you can install, if you're willing to install the...
Gemini browser known as Elpher
into Emacs, which is available from ELPA,
then you can browse directly to it
and look around my Gemini capsule.
Thank you very much.