i41CX+ gets another plus (CAS with editor) [micro review]


i41CX+ already has a lot of pluses, e.g.:

  • Direct HW access (e.g. GPS, compass, accelerometer, etc...)
  • Printer emulation
  • Overlays and skins
  • Module support including HEPAX
  • Many ways to get data in and out
  • ARM-based math module with advanced functions (e.g. LnGamma, LambertW, etc...)
  • 5 field stack display
And soon, with the next release, CAS and a text editor.

I am currently beta testing the next release of i41CX+ and I thought I'd share with you some of the new CAS and editor features.

The Editor

There is a new command (I41CXED) that when executed will edit and/or create a text file as defined in the alpha register. The text file unless too large will be saved into XM. Any XM text file can be edited. If the file is too large then it will be saved (and can be retrieved) from XXM (extended extended memory :-). IOW, the iPhone main flash memory. AFAIK, only the I41CXED and CAS commands can actually access XXM files.

The editor supports two fonts (monospace and not monospace) with variable sizes and colors. The colors mimic the 41CX LCD, but you can toggle to black on white. Your last font, font size, and color are retained between sessions. Tapping the name of the file will drop down the keyboard.

The alternative would be to email (cut and paste) or download text files created elsewhere (also supported by i41CX+). Having the editor built-in is much nicer since the iPhone still does not allow the multitasking of 3rd party apps. I like it so much that Sigma+ is now I41CXED.


The CAS is based on REDUCE--"A portable general-purpose computer algebra system" (http://reduce-algebra.sourceforge.net/). The version of REDUCE used in i41CX+ is optimized for embedded systems (http://reduce-algebra.svn.sourceforge.net/viewvc/reduce-algebra/branches/asau-bsd-port/csl/embedded/). I use the embedded version on my MacBook to quickly prototype REDUCE programs for i41CX+. The documentation for both versions is the same and can be obtained from the first URL. (I have a PDF of the docs for any that are interested).

REDUCE is a worksheet style CAS environment similar to Mathematica, Sage, etc... Basically, you enter some expressions, statements, programs, etc... execute CAS and then view the output, e.g.:

Unless specified the output will be appended to the input. Most useful for a quick CAS session. Unlike Mathematica, Sage, and many others the input and output on the worksheet is not separated. Because of this a "re-CAS" would produce the same initial results, but then could produce a lot of errors as it parses the old output. The solution for this is to specify two files in the alpha register, e.g. FOO,BAR. Where FOO would be the input file and BAR the output file. When the editor is invoked it will stop parsing the alpha register when either a comma or end of line is encountered. If the output file does not exist then CAS will create it with the output of the input file. If the output file exists then the output will be appended. If the output file is not specified but a comma still terminates the line (e.g. FOO,), then the output is sent to /dev/null, IOW there will be no output. There is actually a use for no output when writing programs that directly manipulate the 41CX registers (more on this later).

Given all the CAS programs available for the iPhone, including HP 49g emulation in m48+, you may be asking yourself, "why?"

There are a few distinct advantages of having this CAS built into i41CX+:

  1. You can write an RPN program to programmatically create a CAS input file, execute CAS, then parse the output. Large matrix operations perhaps?
  2. You can write powerful CAS programs that can use any 41CX register as input and/or output.
  3. Because it's CAS in a 41CX. :-)

CAS Program Examples

REDUCE programs are not much different that other structured programming languages (smells a bit like Pascal). What is unique with REDUCE for i41CX+ is that you can get and put data to any RPN register. The following table illustrates this relationship:

41CX          REDUCE
--------- -------------------------
X,Y,Z,T,L x_reg, y_reg, etc...
ALPHA a_reg
R000-Rnnn data_reg(0)-data_reg(nnn)

Some of the following examples have been submitted for inclusion into the on-board i41CX+ examples.


define x=x_reg;
for i:=1:length(p) do <<
for j:=1:part(q,2) do
FACTOR will store all the prime factors of an integer into the 41CX registers starting with R001 with the number of factors stored in X. The fix function converts any non-integer input to integer--input conditioning as apposed to proper error handling. If the number of registers required is not available the CAS system will exit with a DATA ERROR message. I am unsure if a flag is set on error.

FACTOR can be easily modified to only return distinct primes by replacing this block:

for i:=1:length(p) do <<
for j:=1:part(q,2) do
for i:=1:length(p) do
data_reg(x:=x+1):=first part(p,i);
FACTOR relies on the CAS factorize function. factorize returns a list of pairs (lists), e.g. {{2,2},{5,2}}. The part function is one way to manipulate lists.

The define statement can be use to assign an alias. If you find your code using a lot of *_reg variables you can reduce your byte count by redefining some of the *_reg variables. This strategy was important with the early CAS betas, but now that XXM is supported it is less important.

REDUCE can use << >> or begin end to delimit blocks.


define x=x_reg;
define r=data_reg;
procedure err(a); <<
if not fixp x then
err """NOT INTEGER""";
if x<1 then err """X < 1""";
if x=1 then p:={};
while p neq {} do <<
t:=first p;
s:=first t;
p:=rest p;
l:=length q;
 for i:=1:second t do <<
for j:=1:l do
x:=length q;
if x>part(length(r),1)-1 then
err """OUT OF REGS""";
for i:=1:x do r(i):=part(q,i);

DIVIS will return all the divisors of an integer into registers R001-Rnumber-of-divisors with the number of divisors stored in X unless the initial X is not an integer or less than 1. In that case X is left on the stack and an error message returned to the ALPHA register. If the number of registers required is less than the number of divisors then DIVIS will exit with an error, however X will contain the number of divisors (and therefore the number of registers needed (remember to add one for R000)).

DIVIS does a better job of error handling than FACTOR. To do this I defined a procedure (err) to accept an encapsulated string as an argument that then stores that to the ALPHA register as well as stores a -1 to R000 (the default is R000=0). The last statement update_regs_and_quit() updates the registers then exits. If quit or bye had been used then none of the *_reg variables would have been returned to the 41CX environment.

Below is an RPN wrapper around DIVIS (also called DIVIS). R000 is used as a return code; 0 for OK, and -1 for error. If error, then AVIEW, otherwise print the divisors.

Example output of 90 DIVIS:

If you have a 49/50 handy you will notice both output in the same order (I'll assume they use the same basic algorithm). To address the order issue I created a small straight insertion sort program.


define r=data_reg;
for j:=2:x_reg do <<
while k>0 and r(k)>a do <<
All that is needed is to call this sort in my DIVIS RPN program. Since the X register is left with the number of divisors and the sort program is expecting X to have the last register used for sorting then all that is needed is:

New output of 90 DIVIS:



A 41CX with CAS? What's next? Graphics? :-)

I am not an expert with REDUCE. I have only quickly scanned the documentation. I cannot tell you if REDUCE is the most complete or best CAS for the iPhone. Without a complete survey its hard to say. However, I've tried just about every iPhone CAS. For programming, flexibility, and fun, this has to be my favorite (CAS is now assigned to Sigma-).

Edited: uploaded images locally

Edited: 15 Mar 2010, 11:20 a.m.


Looks cool, is there a PC or non-iphone version. i dont have an iphone, but i'd like to try it.



There is the Windows PC version of REDUCE here: http://reduce-algebra.sourceforge.net/.


Very nice work, congratulations!

I already have the emulator on my ipod Touch. I'm really looking forward to the this release...


Great job, Egan.

Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: CAS taylor Alberto Candel 5 1,328 12-13-2013, 09:45 PM
Last Post: Alberto Candel
  HP Prime CAS curiosity bluesun08 11 1,997 12-10-2013, 01:03 PM
Last Post: Han
  [HP-Prime CAS] "Warning, ^ (Command) Is ambiguous on non square matrices"?? CompSystems 1 899 12-07-2013, 07:15 PM
Last Post: CompSystems
  HP48GX - looking for Chotkeh Engineering Review Software MANUAL giancarlo 0 633 12-06-2013, 04:28 PM
Last Post: giancarlo
  HP Prime: complex numbers in CAS. Alberto Candel 1 750 12-06-2013, 02:36 PM
Last Post: parisse
  [HP Prime] plotfunc() bug in CAS Chris Pem10 2 927 12-04-2013, 02:46 PM
Last Post: Chris Pem10
  HP Prime: Home/CAS? Alasdair McAndrew 11 1,613 11-26-2013, 02:48 PM
Last Post: Alberto Candel
  HP Prime numerical precision in CAS and HOME Javier Goizueta 5 963 11-16-2013, 03:51 AM
Last Post: Paul Dale
  Need CAS help Michael de Estrada 6 1,100 11-13-2013, 01:29 AM
Last Post: cyrille de Brébisson
  HP Prime - CAS functions in Spreadsheet App CR Haeger 6 1,157 11-11-2013, 12:37 AM
Last Post: Michael de Estrada

Forum Jump: