Math-Intensive Reports with GNU Emacs and Calc, Part 2

Using Calc for vector, matrix and complex operations.
About This Article

One aspect of Calc that is difficult to simulate properly for publication is its interactive behavior. In order to explain how to use Calc interactively in the static medium of the printed page, I had to resort in a couple of places to the trick of showing a line twice. The first is what I typed in the editing buffer before invoking Calc. The second is what I got back on the same line after invoking Calc. Therefore, if I run Calc a second time on the article file, it won't come out identical. This isn't generally a problem when preparing a report, because one is normally using Calc instead of trying to demonstrate it.

Resources

Emacs

General description: www.gnu.org/software/software.html

FTP mirror list & instructions for downloading: www.gnu.org/order/ftp.html

Emacs Wiki: www.emacswiki.org/cgi-bin/wiki.pl

NTEmacs

Download: ftp.gnu.org/gnu/windows/emacs

FAQ: www.cs.washington.edu/~voelker/ntemacs.html

Calc

Download: ftp.gnu.org/gnu/calc

Manual: www.cl.cam.ac.uk/texinfodoc/calc_toc.html

Cygwin Tools

Download: sources.redhat.com/cygwin

User's Guide: sources.redhat.com/cygwin/cygwin-ug-net/cygwin-ug-net.html

Emacs Lisp

The Emacs Lisp Archive: archive.cis.ohio-state.edu/pub/emacs-lisp

The Emacs Lisp List: thalamus.wustl.edu/wonglab/stephen/ell/ell.html

AucTeX

Download code and documentation: mirrors.sunsite.dk/auctex/www/auctex

Octave

Download code and documentation: www.octave.org

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Math-Intensive Reports with GNU Emacs and Calc, Part 2

Anonymous's picture

The author seemingly does not have worked extensively with calc. calc-2.02f does not work too well with Emacs-21. There are a lot of problems with symbolic simplifications, and some quirks with regard to input, scrolling and display.

For that reason, Emacs-21 users should, if at all, get calc directly from the Emacs CVS archive at Savannah.gnu.org where it is maintained as part of the next new-feature release of Emacs (probably 21.4). That version works quite better.

It is a pity that calc's author Dave Gillespie has stopped working on calc while still having a significantly faster (calc-2 does not even use Emacs' floating point variables!) and more extensive version of calc up his sleeves and already in use privately. If anybody manages to wheedle out those floppy disks or whatever else he has been storing this work on...

Re: Math-Intensive Reports with GNU Emacs and Calc, Part 2

Anonymous's picture

You're correct, in that at the time I wrote the article I was quite inexperienced with Calc. Yes, I had noticed some problems on the symbolic side when using 2.02f with Emacs-21 (my setup). I thought it might be me, but you have confirmed the existence of a general problem. Thanks! And I also thank you for the pointer to the CVS version--and for the intelligence about Dave Gillespie's newer version. I, too, hope he takes steps to release it to the public.

But my article's emphasis was mostly on straight-ahead numerical evaluation, as that accounts for 95% or more of my typical usage. My setup works quite well for that, and I would advise anybody whose patterns of usage resembles mine not to be put off too much by the issues you quite correctly raise in your letter.

Thanks for the comments.

Charles Hethcoat, author.

Re: Math-Intensive Reports with GNU Emacs and Calc, Part 2

Anonymous's picture

The auther writes:

"The only problem I had with it as a publication tool is that your input file requires #-style comment lines for documentation,

Re: Math-Intensive Reports with GNU Emacs and Calc, Part 2

Anonymous's picture

Hi, everyone. I didn't realize until today that my article was already on-line! I appreciate the nice feedback.

Concerning the syntax of Calc: I repeat, I'm still fairly new to it, but my reading of the manual leads me to believe that it's probably configurable within elisp, but I haven't tried to figure out how. For my purposes, the `=>' is fine. In any event, you certainly can post-process these marks to taste within or without Emacs.

The only thing to keep in mind is whether you may need to re-process the file with Calc later on. (Remember my discussion of design changes?) You don't want to leave your master file damaged with respect to Calc's ability to read and process the formulas.

So if you create a filter to fix up the syntax, try to create the corresponding "unfilter" as well. Better still, create a processing pipeline to first /copy/ your file to another name and work on that one. Now your original remains untouched. When the need arises to update your original, just rerun your pipeline.

Charles Hethcoat

Re: Math-Intensive Reports with GNU Emacs and Calc, Part 2

Anonymous's picture

You're right, Emacs certainly can auto-convert those comments. One would need to use something like:

M-x replace-regexp ^# RET RET

to remove all #s at the starts of words, and then

M-x replace-regexp ^[^$] RET # SPACE RET

to put them back again. (This assumes all lines start either with a Calc $ or a comment #, which may be incorrect - I haven't used Calc myself.)

But the author was referring to Octave, not to Emacs+Calc. He wrote:

"you need to perform some downstream editing with tools like sed or awk. Not at all difficult on UNIX but not easy on Windows, and the additional processing requires more steps than the combination of Emacs+Calc."

So the fact that it needs processing that could be easily done in Emacs may be precisely his point...

calc math syntax constraint

Anonymous's picture

Thanks a lot. Very interesting article.

One question. Is there a way to get free of the calc package syntax constraint? I mean that in my report, i want to use the '=' caracter for assignments as well as for 'evaluates to' operations. For example, I want to see things like:

c = sqrt( a^2 + b^2 ) = 5.14003891036

and NOT:

c := sqrt(a^2 + b^2) => 5.14003891036

Is it possible, or are we stuck with one and only one syntax?

Re: calc math syntax constraint

Anonymous's picture

Ok, done a bit of reading and the following should work

M-x replace-regexp RET:=|=>RET=RET

Do what you need to do to print the file then Ctrl-_ will set things back to how they were .

Hope that's of help

Euan

Re: calc math syntax constraint

Anonymous's picture

BAH! Bloody stripped the backslash!

M-x replace-regexp RET :=BACKSLASH|=>RET=RET

Re: calc math syntax constraint

Anonymous's picture

One possible solution is to run a regex-replace on the document prior to printing. I'm fairly new to Emacs so not too sure of the syntax for regex. In Vi it would look something like this:

1,$ s/=>|:=/=/g

Which tranlates to search the whole file for => or := and replace with =.

Once you've published it you can then hit Ctrl_ to undo the regex.

If anyone's read this and knows how to do it in Emacs regex then please post :-)

Re: calc math syntax constraint

Anonymous's picture

oops, regex missing a backslash. Should read:

1,$ s/=>|:=/=/g

Sorry,

Euan

Re: calc math syntax constraint

Anonymous's picture

OK, for reasons unknown the backlsash gets stripped when I post. Here we go once more:

1,$ s/=>BACKSLASH|:=/=/g

>sigh<

Re: calc math syntax constraint

Anonymous's picture

Not that i know of... This syntax is used as a programming language one, rather than a symbolic one. And, as such, it has been elaborated since the early days of Pascal...

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix