Tag Archives: mathematics

c, calcc and calccmd: Three small calculators

Three-for-one on a Friday today, and calculators are the featured toy. The first one suffers from an unfortunate name, but seems to make up for it in its ratio of function to footprint. This is c:


c is an RPN calculator, and if you don’t know what that means, it might be a very confusing experience for you. c is somewhat helpful to newcomers though, since its registers are clear at every operation. Put the values you want inside, press the key for the operation, and as you can see, the result is kept in the lowermost register.

It’s not hard to figure out, and I imagine if you like RPN calculators you’ll get a kick out of such a small one — only 4.1K for the source file, and roughly twice that for the executable. It’s not often you get that much function in such a small space. Too bad its name will make it virtually unfindable. … 😦

calcc is next.


calcc is similar to c in its captive terminal approach, and has a style somewhat like bc or other calculators, with each line interpreted and calculated at once.

Its results are what set it apart; calcc saves you the step of converting your answer between bases or formats, and displays everything at once. So you won’t need a date converter or a base converter to supplement calcc. If you need a legend for what each column is, there is a text file in the source package that explains which is ASCII, which is base 32, base 64, and so forth. Very convenient.

The last one today is calccmd.


calccmd is the only one of these three to send your calculations through as command-line arguments, and I’ll be honest and say there are times when I would prefer that approach. Sometimes I don’t want to fire up all of bc just to divide two numbers, and allow for two decimal points.

So a command-plus-flag style calculator is not unwelcome. And calccmd has enough options to keep it up to speed with what c and calcc can do, as well as quite a few other calculators. (The home page mentions that calccmd has been deprecated in favor of calccli by the same author, but I don’t see that project anywhere.)

And so, armed with those three options, feel confident as you venture forth into the world of mathematics. … :mrgreen:

datamash: Statistical tools for raw numerical data

I like tools that do simple things in obvious ways. I like tools that have color too, but sometimes I’m willing to forgive that, and award points on cleverness.

Here’s datamash, a GNU tool, doing something fairly straightforward.


Forgive my rotten formatting. I was trying to line up the sums under their appropriate columns, but I ran out of patience with it. What you should see there are two arbitrary columns of numbers, and datamash summing both on the fly.

It’s not a terribly earth-shattering function, but it does make a lot of otherwise tricky number functions accessible to flat numeric data files. So you don’t have to import into a spreadsheet to get a sum, a mean, a max, a min or whatever.

And you don’t have to rely on statistical packages like r or octave to do some simple budget analysis. 😉

datamash also does some rather clever text formatting tricks, which might be reason enough to keep it installed. Observe:


So you can feed datamash a series of columns vertically, and it will run them out horizontally. Omigoshthatissocool.

datamash is in AUR and testing/unstable. I don’t know why it’s not in the standard repos for either distro, except that it may be too new. The development pages for datamash suggest it started about a year and half ago, but saw most of its activity within the past six months. Give it time.

A lot of what datamash can do — particularly the higher statistical functions — are much more than I would need on a day-to-day basis. But if you keep something like r or octave on board for regular data analysis, you might consider datamash as a lighter alternative.

seq: Count up, count down

A quick note before we get into seq today: If you left a comment in the past 18 hours or so but don’t see it by now, it might have gotten lost in a spam avalanche.

Someone out there in the world must have turned up the dial on the spam machine, because I had more than 120 spam comments between noon today and early yesterday evening. For reference, I usually see 10 or 12 in a day.

Usually WordPress.com — in spite of all my complaints — does a decent job of filtering out the winners from the losers, but sometimes people get lost in the fracas. If for some reason your comment got mixed in with the spam, I’m sorry, but it’s likely gone forever.

And just FYI: If you include a URL in your comment, it’s more likely to be flagged as dubious by the automated system. Sometimes I can pluck a comment out while it’s circling the drain, but this time there were too many to scan through. My apologies.

Anyways. … seq is up to bat today, and this won’t take long. seq doesn’t do much other than count, by increment, between a stop and a start number. Sounds simple enough.


The fun in seq is getting it to pad its output with leading zeros, which pleases people like me who want their numbered files to line up vertically down the screen. 🙄 And as you can see, you can set a delimiter for seq, which comes in handy at times.

It does pad things a little oddly at times — for example, that 00.0 in the screenshot above. And if you pad your numbers while counting in reverse (yes, you can do that), you’ll find that seq pads 0 as 00, and so forth. I should also mention that seq‘s last output doesn’t carry a separator. That means if you do something funky like this:

kmandla@6m47421: ~$ seq -w -s' '$(shuf -n1 /usr/share/dict/cracklib-small)$'\n' 1 1 10

You’ll see that every line but the last carries a random word. Just so you’re aware. 😉 Things like that are a little unusual but not deal-breakers. Not like join was. 😐

That’s about all I need to say about seq. It comes in very handy at times, which is probably why it’s part of coreutils. 😉

e: Like a diamond bullet

I will apologize first, for the long lapse in communication. The end-of-season workload in real life took over late last week, and very foolishly I did not make preparations for posts during that time. I should have; I knew it was coming, but I acted all surprised when I suddenly had no time for the things I enjoy — like picking around at software.

But it should all be okay now. At least I have a better handle on real life responsibilities. :\

e is the topic of choice today, and what I’d really like to point out about e is this:

-rwxr-xr-x 1 kmandla users 6.9K Jul 11  2001 e
-rw-r--r-- 1 kmandla users 4.0K Jul 11  2001 e.c

Yup, the e binary is a meager 6.9K in size, and the source code would fit in an Atari 2600 game cartridge. Technically. Sort of. Maybe. 🙄

That’s impressive for a one-shot command-line expression evaluator — or calculator, as some like to call it. Hand just about any expression to e and it will click and sputter briefly before throwing out an answer.

And not just simple math either. All these things are legitimate e commands.

kmandla@6m47421: ~/downloads/e-0.02718$ ./e 128!

kmandla@6m47421: ~/downloads/e-0.02718$ ./e 1/2*1/3*1/4*1/5

kmandla@6m47421: ~/downloads/e-0.02718$ for i in {0..90..15} ; do ./e sin[${i}] ; done

That’s impressive for a 7K binary with no, repeat no dependencies. To quote from the home page, “It doesn’t need bison or anything else other than a C compiler. In fact it is a recursive-descent parser with one character look-ahead.”

For its size and its potential, e should be an addition to just about any system. No more mucking around with bc while trying to balance your checkbook. e can solve it all in a fraction of the time, and take up no more space than a postage stamp.

And if you enjoy math logic, the home page has an interesting (and convincing, from my uneducated perspective) treatise on why zero is not a number and why just a plus sign — “+” — should evaluate to zero. I’m a believer now.

By the way, I owe a small note of thanks to NiceGuyJoe on reddit who sent me a message months ago linking to e, and it has just come up in the rotation. A good lead, all the same. 🙂

Now, let’s talk about that one-character program name. … 😡

factor: Simple tools are fun

After more than a year and a half of tinkering with random console programs, I know enough to look forward to fun stuff out of coreutils. Here’s factor, which I admit has almost no explicit function beyond showing the prime factorization of a number.

kmandla@6m47421: ~$ factor 120
120: 2 2 2 3 5

Which is absolutely correct, of course: 2x3x4x5 does in fact equal 120, and factor is nice enough to group similar factors for readability.

But that’s all it does. So what’s the big deal, K.Mandla?

Well, aside from fulfilling my desire to see simple, straightforward, light but functional software, factor has potential. My only real concession to factor is that I’d prefer I had a count of how many of each factor there were, rather than just a string of factors. That would mean factor 65536 would appear as


rather than just a string of 16 number 2s. Call me picky.

First let’s lose the colon-plus-space arrangement, and kick in a tab character instead, for reasons that will be clear in a moment. sed can help with that.

factor 720 | sed -e 's/: /\t/g'

I’d prefer a tab character there only because cut likes tab characters as delimiters.

factor 720 | sed -e 's/: /\t/g' | cut -f2

Now we just need to break off each number where a space appears, and we can call in some heavyweights. sed again, just for kicks.

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g'

Now we go medieval. Remember uniq? Watch this:

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c

Four twos, two threes and a five. Yup, that’s right. That’s 720. uniq counted the lines and gave a total. Too much whitespace at the front though.

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g'

And it would be nice if there was just a multiplier mark between the count and the factor.

kmandla@6m47421: ~$ factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g' | sed -e 's/ /x/g'

Close enough for government work. From there we would only need to prefix the output with the number, like I showed above. If you stick this in a loop, it becomes even more interesting. Try

for i in {2..99} ; do echo $i':' ; factor $i | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g' | sed -e 's/ /x/g' ; echo ; done

for more complete (replete?) results.

What’s the point in all this? Not much of one, that I can see. This wasn’t meant to be some sort of lesson on sed and uniq; suffice to say I have plans for that particular loop that are … beyond the focus of this blog. Feel free to adjust it to your own nefarious plans. 😉

st and st: One for numbers, one for … numbers and letters?

I’ve got two programs named “st” on the list, which caused no end of confusion for about an hour today. Oddly, I can’t show much of either one.

The first one comes, yet again, from the suckless.org gang, because everything in the suckless stable starts with the letter S.

Just kidding. In this case st is a simple terminal and unfortunately every rendition — which is quite a few according to the AUR — failed to build for me. Most of those seemed to be from git, so maybe I just grabbed it at the wrong time.

I’m going to keep trying though, mostly because suckless.org usually does things right, and I plan on trying out some of their other toys too.

The other st is a miniature statistics tool, capable of skimming through numbers in a text file and providing some fundamental statistical information — a minimum, maximum, mean, standard deviation and a few other things.

I could build st but I’m not a perl pro, and it only gave me error messages when I tried to kick it into action. I have a feeling I hadn’t put all st’s little important parts in the right places.

The second st isn’t in AUR or Debian, so if you decide to try it out, there might be a little work involved. Not that a little work ever hurt anybody. … 😉

r: Might as well start at the beginning

I know enough about statistics to know that r is a good name for a statistics software package, but I also know it’s hell on searching for an application.


r is the GNU statistical software and graphics package, which stands as r-base-core in Debian, but is tricky to find in Arch/AUR. No matter, I had no trouble getting it to compile in Arch once I had installed perl-exutils-f77.

Of course, now that it’s been built, along comes the perennial question … what do I do with it? 😕 Like I said, I know a little about statistics. It’s not enough to put me at any advantage over r though.

And so again I find myself years behind the curve, much as I was with octave, mathomatic or even gnuplot. I swear it’s not for a lack of ability, just a lack of necessity that keeps me from having used or seen these things.

I showed r in a demo(), and there are others available. r can do some amazing graphs and diagrams, as the screenshots page attests.

Unfortunately, I find myself lacking the need for a statistical analysis package, even if it did take me quite a while to find it. 😐

qalc: qalculate!’s text only version

I can remember first seeing a GTK+ version of qalculate! around 2009 or so. As a replacement for a generic desktop calculator, it does a fine job.

It never really caught on with me, mostly because I don’t have need of a desktop calculator very often. galculator is okay for my needs, in its GTK2 version, thank you.

There is a command-line version of qalculate! that Debian calls “qalc,” which I have seen called “the greatest calculator ever.” I won’t say whether I agree with that or not.


qalc follows an interactive style, in the same way as bc or some other calculators, but can also calculate CLI-wise. It has onboard help, which is always good. It can access the Internet to get up-to-date conversion data.

I also like that by default, qalc shows you your entire calculation spaced out and arranged, rather than just spitting out an answer. Of course, there is a “terse” flag if you prefer the opposite.

There’s not much to dislike in qalc, but as I am finicky today, I have to be honest.

It seems that qalc (and by extension qalculator!) is trying rather hard to become all things mathematical. While there is convenience in that, I have this nagging prejudice in the back of my mind against programs that try to do everything at once.

I don’t care for audio players that double as music managers, I don’t like file managers that try to be hex editors, and I don’t want a text editor that tries to be an operating system.

All that said, I will temper my dislike by saying that qalc, to the best of my knowledge, stays within the mathematical and doesn’t try to work as a chat client too. I respect that. 😉

pi: A request from the audience

Okay, I promised bshir I would make a brief jump backwards in the otherwise impeccable alphabetical order of these posts, in order to include pi.

Yes, pi. There is a quick-and-dirty tool available to you, to display the value of π out to as many digits as you like. bshir says it’s worth including, and I’m willing to give it a brief spotlight, out of respect for the audience. 😉


And in its own way, pi is pretty cool. It reminds me of primes, and between the two (and maybe factor, which is slated for my next run through the F section), that’s a fairly healthy slice of mathematical power available without relying on a calculator application.

In Arch, pi is in the cln package, which is described as a “class library for numbers.” I’m not sure what that means. In Debian it has its own package called “pi” … which you probably could have guessed. 🙄

But I do like filling up the screen with 10,000 digits of π. I shall have to look closely for the secret of the universe in there somewhere. … 😉

orpie: Or should I say, “Orpie!”

My favorite part of orpie is the name. My second favorite part of orpie is the snarky subtitles it gives itself, when it starts up — things like ” ‘=’ is for the weak” or “RPN for the masses.”

I like an application with an attitude.

Attitude aside, orpie is actually quite easy to use, and I have next to no experience with RPN.


Come to think of it, the last time I used anything RPN-ish was the last time I tinkered with orpie. 🙄

orpie wins points for me by using the full screen, keeping all the important tips on the screen and using the obvious keystrokes for the major mathematical functions.

On top of that, it handles trigonometric functions, octal, hex, binary, polar, and a long list of other fun stuff … most of which is triggered through the abbreviations menu.

The screenshot above is from Debian, because as luck would have it, the Arch version fails on some dependencies — ocaml-gsl, if I remember right.

Score one more small point for precompiled distros. 🙄