Features 2007 CHLUGger of the Year! Mailing List Archive Help Open Source Question of the Day About Us Mission Directions to Meetings Contact Us Video Guest Speaker Info Acceptable Use Link To Us! Our Blog CHLUG Exclusives Open Office 3.0- New and Enhanced Features New! Linux Hacking and the Law New! VOIP with Asterisk Assessing OSS Knoppix Ubiquitous Computing Filesystem Hierarchy Virtual Hosting Wesnoth Xbox/Linux udev Emacs Talk Notes Home Sweet ~ Top 100 CLIs Device Drivers Real Time Linux Network Considerations Part II Network Considerations Part I Amanda Presentation GNU/Linux Calculators Configuring Rio ReiserFS Linux Sound Samba notes Network time protocol C programming in Linux Boot, startup and shutdown hdparm HOWTO Friends of CHLUG Ubuntu NJ LoCo New! Cherry Hill Library RUSLUG LUG in Princeton Useful Links Loads of Linux Links LinuxToday.com Art of UNIX Programming More Links Agenda Contact Congress Why We Use Linux Companies Using Linux Linux in Business GNU/Linux calculators  jon_low@yahoo.com gcalc  the Gnome calculator xcalc  the X-window calculator, emulates a TI-30 or with the -rpn option emulates a HP-10C (reverse polish notation) hexcalc the programmers calculator for X dc  arbitrary precision calculator bc  arbitrary precision calculator language, older versions were based on dc, but modern versions are written from scratch   What is bc well suited for? The manipulation of large integers. It will truncate at some point to the right of the decimal point, controlled by the scale variable, because it's easy to get a fractional part that is infinitely long. Finding the greatest common divisor of two numbers: gcd( X, Y ) { while ( Y != 0) { temp = Y; Y = X % Y;  // % is the mod or remained operator X = temp; } return X; } The mod operator, % , will give us values in the complete residue system modulo Y. This is the Euclidean algorithm. There is a faster binary algorithm, but bc does not have the bitwise shift operators to support such an algorithm. In fact bc may not be storing its numbers in a standard binary or two's complement notation. The gcd is used in finding the Euler F-function, also known as the totient, of a number, M, which is defined as the number of positive integers less than M that are relatively prime to M. Relatively prime means a gcd = 1. In number theory speak, the totient is the number of elements in the reduced residue system modulo M. totient( M ) { t=0; for ( i = 1; i < M; ++i ) if (gcd ( M, i ) != 1) ++t; return t; } Simple algorithms, yes. But you can't program them on your computer when the magnitude of your numbers is greater than the maximum value of your largest integer data type. Floating point data types don't work because all digits are significant and floating point data types have fairly short mantissas. Why is this significant? Because just about all public and private cryptologic keys are larger than 64 bits. Another use of arbitrary precision calculators is the testing of solutions of Diophantine equations. As with all cryptologic equations, they are difficult to solve, but easy to verify. Try these: W5 + X5 + Y5 + Z5 = Q5 It is difficult to find the variables, but easy to verify that they are the correct. Try W = 27 X = 84 Y = 110 Z = 133 Q = 144 [Lander, et al, Math. Comp. 21 (1967)] Here's another equation X4 + Y4 + Z4 = T4 Try X = 95800 Y = 217519 Z = 414560 T = 422481 [Roger Frye of Thinking Machines Corp., summer 1987] Or perhaps X = 2682440 Y = 15365639 Z = 18796760 T = 20615673 [Noam D. Elkies of Harvard University, summer 1987] While you might be able to do the examples above on your hand held calculator, the larger ones will require something like bc. Are there many of these solutions? Yes, there are an infinite number of solutions. Everyone who takes elementary geometry learns the algorithm to generate triplets that solve X2 + Y2 = Z2 . But no such algorithms are known for the above Diophantine equations. By the way, no need to try X4 + Y4 = Z4 Pierre de Fermat proved that it has no whole number solutions on or about 1669 A.D. There are many known Diophantine equations that have no solutions in whole numbers. I haven't found an obvious way to get bc to write to files, so what I do is start a script, enter bc, let bc write to the standard output, exit bc, close the script, and then read the file that script created. To start script % script To end the script session ^D That's a control d. This can be executed at any time, not necessarily from the command line prompt. A copy of the standard output is now in the file filename. You might need to do a dos2unix conversion on the file as the script command seems to have been ported from the teletype or DOS world (as were many utilities). % dos2unix filename This will overwrite the original file, replacing all of the character pairs (originally carriage return, line feed) with the single character (new line). Or in hex, all the byte pairs 0x0D 0x0A are replaced with the single byte 0x0A. (where the prefix 0x indicates base 16 number system)