C Computer Algebra System (CAS) in C?

Hello,

CAS : What is CAS?
https://en.wikipedia.org/wiki/List_of_computer_algebra_systems
There are on GITHUB several possibilities: https://github.com/search?l=C&q=computer+algebra+system+&type=Repositories&utf8=✓

I would like to solve very basic functions, like here in the picture (here url). With the regular scanf, I wish to enter the function and 'x' variable. It shall output then either the derivates or integrals in symbolic. If you know good libraries in C for this, please let me know.

In my opinion, CAS is very useful for everyone dealing with maths.
 
You need to explain: What is your goal?

Do you want a functioning system, and use it to solve problems? Then just find a free one and use it. Macsyma still exists (I used to use it in the 1980s); you can also download Mathematica for free on the Raspberry Pi.

Or do you want to learn how to implement it yourself? Then you have to be aware that as a hobbyist, you won't get very far compared to the existing solutions (which have had lots of people working on them, in some cases for decades).

EDIT: Historic note: Somewhere in the basement I have a floppy that contains MuMath and MuSimp for cp/m. I used to run it in the late 80s on my self-built Z80 machine with 64K of memory. It was actually useful. I think my floppy has been copied by the Computer History Museum here in the bay area, and must be online somewhere.
 
  • Thanks
Reactions: Oko
You need to explain: What is your goal?

Do you want a functioning system, and use it to solve problems? Then just find a free one and use it. Macsyma still exists (I used to use it in the 1980s); you can also download Mathematica for free on the Raspberry Pi.

Or do you want to learn how to implement it yourself? Then you have to be aware that as a hobbyist, you won't get very far compared to the existing solutions (which have had lots of people working on them, in some cases for decades).

EDIT: Historic note: Somewhere in the basement I have a floppy that contains MuMath and MuSimp for cp/m. I used to run it in the late 80s on my self-built Z80 machine with 64K of memory. It was actually useful. I think my floppy has been copied by the Computer History Museum here in the bay area, and must be online somewhere.

A good modern Casio fx-9860GII is likely better than using Mathematica...?
In my opinion, the TI-86 was the best of the best! I wish that the Ti-86 could still be existing. A programme CAS (app) can even be employed on the TI-86.

best-calc.png


Mathematica will close you into a software. The C language is the key of freedom.

CAS is just for hobby to make simple calculations within a spreadsheet. I need actually CAS and the Newton Raphson method for solving complex modern systems (10-20 equations).

wow. this impressive, full respect.

I never heard of MuSimp or anything for maths. Probably today, no one still remember.
All those CP/M information might have been disappeared from mind. Lost histories of informatics probably. The creators of MuSimp and co are likely no longer there :(
 
In my opinion, the TI-86 was the best of the best! I wish that the Ti-86 could still be existing. A programme CAS (app) can even be employed on the TI-86.

What you see in the TI calculators is "derive". It is a newer version of MuMath and MuSimp: The same people who wrote MuMath/MuSimp (Soft Warehouse, of Honolulu, HI) later worked for TI. I also lived in Honolulu at the time, and visited and chatted, and they kindly gave me a copy of the very obsolete Mu* software.

But: If you look at what a modern symbolic package can do (like Macsyma, like Mathematica): It is WAY more powerful than a calculator. If you then combine it with a good numerics package (like Octave), it is an astonishingly good tool for many science and engineering problems. It is a calculator time 1000.

Mathematica will close you into a software. The C language is the key of freedom.
Nonsense. Having to do complex symbolic stuff in C is so tedious and difficult, you will never get anywhere near a large productive system, unless you invest years of your time. What you are saying is like "living in a rented house or apartment closes you into housing. Using grains of sand is the key of freedom". Yes, you can theoretically build your own place to live using grains of sand (and a little bit of glue or concrete). But in practice, if you start with such small pieces as grains of sand, you will not get to a livable house in a sensible amount of time.

If you want to do CAS yourself, the first step is to abandon the use of C. You need a programming environment (not just language, the whole environment) that is more productive, and more tailored towards algebra, which is mostly about processing lists of symbols. Traditionally, the correct language for that has been Lisp. In C, you would spend the first half year of work building libraries just getting the basics of symbol parsing, printing, and lists of symbols to work. You might be able to find pre-existing libraries for this. But if you do, you are tied to those libraries forever. If you want to tie yourself to something, you are better of downloading the source code for something like Macsyma or Reduce, and start at a higher level.

CAS is just for hobby to make simple calculations within a spreadsheet. I need actually CAS and the Newton Raphson method for solving complex modern systems (10-20 equations).
Mathematica is free, if you run it on a Raspberry Pi (although I think only the Linux version is freely available). This might be the most efficient method.

The creators of MuSimp and co are likely no longer there :(
I heard from David Stoutemyer a year or two ago. When I knew him, he was in his 50s, so by now he should be in his 70s or 80s, but likely alive and well.
 
  • Thanks
Reactions: Oko
you may try this
https://www.ginac.de
i never used it.sorry for concision i am on phone keyboard.

1) My goal is to make a spreadsheet, first to make my mathematical calculations and models working, and then take this programme to a higher level to a very performant modelling simulation software.
2) Today, unfortunately, there is no single opensource programme, which is public available for this type of desired math models, and it won't change in the next 10-20 years. Example: big companies such as Apple or Microsoft never release their source code ;)
3) Due to high maths complexity, step by step is required. Of course, including 1 or 2 libraries, is planned, especially including CAS.


thank you,... !! it looks pretty interesting.
 
You need to explain: What is your goal?
+1
How people even come up with such a random bullshit questions?

Do you want a functioning system, and use it to solve problems? Then just find a free one and use it. Macsyma still exists (I used to use it in the 1980s); you can also download Mathematica for free on the Raspberry Pi.
Macsyma started as a research project assigned to a few grad students at MIT in 1968. During my math career I meet few of early contributors during their sunset years. Today there are whole mathematical journals devoted to this field of applied mathematics.

https://www.journals.elsevier.com/journal-of-symbolic-computation/

The spirit of Macsyma is still alive and well in the open source CAS called math/maxima

IIRC another well know CAS (without checking the fact) Maple started at the department of mathematics at the University of Waterloo (Canada thus Maple and Maple leaf as a logo) out of their inability to pay for the license for Macsyma. Currently the greatest Maple claim to fame is that it is the engine behind several well known commercial calculus automated homework assignment tools (the greatest thing after slice of bread if you asked me few years ago when I was still teaching undergrads). It is very rarely used by my pears in Math Physics for example.

MuPad similar story as Maple except it took place in Germany. MuPad is acquired by MathWorks and it is the engine behind MATLAB symbolic computational toolbox.

Finally the most widely used general purpose CAS (at least in Math Physics and Physics) is Mathematica started by Stephen Wolfram while he was a grad student at the physics department at Caltech. It came out of his research on finite automata.

Generally pure math people have little interest in general purpose CAS system. Rather they are interested in very highly specialized peaces of software like GAP which is of course open source (how otherwise could we referee such papers).


TLTW

In general amateurs have no business in CAS. It is the vast ever growing research area in Mathematics (pure and applied), Mathematical Physics and Artificial Intelligence.

It would take me pages just to describe the use of CAS in pure mathematics research let alone to explain to non-specialist a single interesting symbolic computation open problem which could be useful to pure mathematicians.

Oh I just forgot before a "bright" guy races me to this. math/sage-math is just a stupid Python wrapper around Maxima, GNU Ocatve and few other things. Just a typical GNU kitchen sink crap. Python symbolic computational library has a true re-implementation of some basic symbolic computational algorithms from Maxima.
 
What you see in the TI calculators is "derive". It is a newer version of MuMath and MuSimp: The same people who wrote MuMath/MuSimp (Soft Warehouse, of Honolulu, HI) later worked for TI. I also lived in Honolulu at the time, and visited and chatted, and they kindly gave me a copy of the very obsolete Mu* software.


But: If you look at what a modern symbolic package can do (like Macsyma, like Mathematica): It is WAY more powerful than a calculator. If you then combine it with a good numerics package (like Octave), it is an astonishingly good tool for many science and engineering problems. It is a calculator time 1000.
Your patience to explain to clueless and uneducated never cease to amaze me :)



Nonsense. Having to do complex symbolic stuff in C is so tedious and difficult, you will never get anywhere near a large productive system, unless you invest years of your time. What you are saying is like "living in a rented house or apartment closes you into housing. Using grains of sand is the key of freedom". Yes, you can theoretically build your own place to live using grains of sand (and a little bit of glue or concrete). But in practice, if you start with such small pieces as grains of sand, you will not get to a livable house in a sensible amount of time.
+1

If you want to do CAS yourself, the first step is to abandon the use of C. You need a programming environment (not just language, the whole environment) that is more productive, and more tailored towards algebra, which is mostly about processing lists of symbols. Traditionally, the correct language for that has been Lisp. In C, you would spend the first half year of work building libraries just getting the basics of symbol parsing, printing, and lists of symbols to work. You might be able to find pre-existing libraries for this. But if you do, you are tied to those libraries forever. If you want to tie yourself to something, you are better of downloading the source code for something like Macsyma or Reduce, and start at a higher level.
Writing a Lisp program for something as simple as automatics differentiation and integration would be a fair semester long project question for a bright undergraduate math student. Implementing something like polynomial factorization (only two symbolic algorithms a known for the well know fundamental theorem of algebra which was proved by Gauss in his Ph.D. dissertation) is still a challenge even for the whole teams at Wolfram research.

Mathematica is free, if you run it on a Raspberry Pi (although I think only the Linux version is freely available). This might be the most efficient method.
+1
Not a very useful tool for a pure mathematician and not something you can refer in a paper but indispensable for a person who works in Math Physics like myself.
 
+1
Not a very useful tool for a pure mathematician and not something you can refer in the paper but indispensable for the person who works in Math Physics like myself.

Do you work with CAS and Newton Raphson methods in your simulations? here, I got at least about 40 equations to solve. That's fun.
 
Do you work with CAS and Newton Raphson methods in your simulations? here, I got at least about 40 equations to solve.
That is not CAS (symbolic computational) problem! That is numerical analysis problem. No I am not trained as a numerical analyst. I am trained in Dynamical Systems and work with Math Physics and AI/Big Data. You should look at BLAS, ATLAS, LAPACK, and such to understand how is implemented or if you just want to use such stuff fire up MATLAB or numpy.

I do more numerical linear algebra (matrix perturbation theory) these days than I would like to admit.
 
Wasn't muSimp written in lisp?
Now you made me look it up in Wikipedia! I always thought that muMath (which is the algebra package) was written in the programming language muSimp. Wikipedia, however, says that muSimp in turn was written in a dialect of Lisp called "muLisp". Which I seem to have forgotten about. I did try out muMath, and I was always amazed that it could do things like factoring and multiplying out expressions.

Another thing that amazed me was the existence of Fortran and C for cp/m; I had both of them installed (although programming in them was amazingly painful, since compiles often took 5-10 minutes, and any IO error on the floppy would kill them). Actually did productive things in Fortran and C on my machine.

But there are two pieces of cp/m software that I have been searching for (not seriously, since I currently have no functioning cp/m machine, and not enough time to set one up): The COBOL compiler (I think it came from MicroFocus), and the MDBS-ii database: It was a full implementation of a hierarchical CODASYL-style database, and fit in 64K of address space.
 
When I was at school I had pirate copies of the mu things, and I got told that it all was Lisp. But it was too complicated for me, and I had no literature :)
... the existence of Fortran and C for cp/m; I had both of them installed (although programming in them was amazingly painful, since compiles often took 5-10 minutes, and any IO error on the floppy would kill them). ... and fit in 64K of address space.
I played a bit with FORTRAN-80 back then.
I had 5 1/4" drives without headloading, I guess that was a bit less stressful for diskettes than the 8"s drives hammering their heads onto the surface so they might not even survive their nominal 40 hours.
And even compiling a small program took looong time on 56k CP/M 2.2 on 2MHz Z80... ohh yes.

But I guess this all was extremely comfortable compared with the 1959 IBM 1401, or even with the 1948 IBM 604 (there is even a link to the user manual pdf), which is shown running a program in a 3-minute video here. I guess back then the guys found the 1401 extremely comfortable...

Whatever, I find just amazing with how little memory it is possible to do things.
I mean I find it even a bit sick when a hello world program needs dozens megabyte on a smartphone...

Edit: I find amazing how people can have fun with maths :) My brain just shuts down when I see greek chars :)
 
OT.

Since I was a long time user of CAS systems I add a few considerations which may be of use to someone who is starting.

-] If you want to learn a bit how the comuputer algebra works and why Lisp (or Lisp like languages) is a good choice for it you may read the right chapters of "Structure And Interpretation of Computer Program". A highly reccomended book. Also, the old (Lisp) edition of Artificial Intelligence by Peter Norvig was a nice book with some intro to the subject.

-] Mathematica is just Lisp with parentheses ruels a bit changed
Example
Code:
mathematica> First[List[{1,2},{3,4}]]     =>   {1,2}
# change bracket positions before function name
-> [First [List {1,2} {3,4}]]
# change brackets to parentheses and lowercase
-> (first (list {1, 2} {3,4}))
# braces are list constructor, equivalent to (list xx yy)
lisp> (first (list (list 1 2)) (list 3 4)))     => (1 2)

-] There are many software for computer algebra, as said by others
Maxima, Reduce, Derive, Axiom, Maple ... then there are special purpose tools for special problems.

-] In the last 20 years, the most popular on the market have been Maple and Mathematica. I will list some differences about these two

-] Mathematica:
[+] beautiful well working Worksheet environment
[+] Graphics creation well integrated into the language
[+/-] Very similar to Lisp, it can be a joy or not, depends on taste.
[-] Superficial documentation, you must belive Mathematica, not understand what it is doing.
[-] Superficially documented algorithms
[-] On optimization tasks, It has happened to me more than one time to see Mathamtica results were wrong, without any kind of warning. The only way to check was to produce another solution with another sofware and then compare the two. In general I would not use Mathematica to compute stuff I can not backcheck in some way.
[-] Highly arrogant approach. You read the Mathematica Book and you have the impression Wolfram invented it all. From the REPL to HashTable to Closures. (insted they only invented different names for these things). There is not a single reference to Lisp in the book AFAIR, instead they copied almost all from it.

-] Maple:
[-] Cranky workbook interface (written in Java)
[-] Graphics, a lot more messy respect to Mathematica
[-] In the last years it has become more and more directed to students, so focus has moved on filling silly gui-widget instead of fixing the interface
[+] Its programming language is imperative, it is much easier to write software if you already know something about programming in C/Javascript like languages.
[+] Beautiful documentation, you read and you learn what the system can compute and what will probably fail.
[+] Reference to academinc research papers
[+] When the system is not able to find what is considered to be a solution a lot of warnings come out with the result.

Said that, I used a lot more Mathematica, but all because of its
beautiful worksheet interface and graphics primitives well integrated.
 
  • Thanks
Reactions: Oko
Spartrekus , can I see your equations system ?

Often, with many equations, the system is overdetermined so
you would need to use something different respect to a classic root finder.
... sorry if this precisation is trivial for you ... let me see the equations, i will try to direct you to an appropriate tool.
 
Spartrekus,

I am also a big fan of spreadsheets.
I made many experiments trying to integrate my own functions into a spreadsheet. These are my temporary conclusions. If you have
found something better, let me know !

[*] [not practical, i don't like Windows] Use windows and Excel, there exist a Python plugin.
[*] [not practical, i don't like Windows] Program Excel in VBA.
[*] [not practical] Program LibreOffice, i tried, it is a nightmare, after 2 days i gave up.
[*] [feasible, practical] Use GoogleSheets, it is programmable in Javascript. This is what i am doing currently.
[*] [feasible, but ??] GoogleSheets is a "fork" of Ethercal AFAIK, so i thought I could add functions to Ethercal, after a few hours i gave up, it does not seem practical. I admit i did not put much effort here.
[*] [feasible] Maple has a little spreadsheet interface !
[*] [not practical, onl Windows] Mathematica AFAIR can connect to Excel
[*] [not ready] TeXmacs has a spreadsheet like interface where you can program your functions. But it is not ready for prime time IMO.
[*] [in theory working] There exist a Spreadsheet in Siag office, programmable in Scheme, unfortunately there is not package for FreeBSD, the stuff is old. I tried to complie it from source but in a couple of hours I was not able to make it. I saw there is a package in OpenBSD.
[*] [far from ready] I tried to implement my own spreadsheet ... this require really more time than available, but i started;P
 
Spartrekus,

I am also a big fan of spreadsheets.
I made many experiments trying to integrate my own functions into a spreadsheet. These are my temporary conclusions. If you have
found something better, let me know !

[*] [not practical, i don't like Windows] Use windows and Excel, there exist a Python plugin.
[*] [not practical, i don't like Windows] Program Excel in VBA.
[*] [not practical] Program LibreOffice, i tried, it is a nightmare, after 2 days i gave up.
[*] [feasible, practical] Use GoogleSheets, it is programmable in Javascript. This is what i am doing currently.
[*] [feasible, but ??] GoogleSheets is a "fork" of Ethercal AFAIK, so i thought I could add functions to Ethercal, after a few hours i gave up, it does not seem practical. I admit i did not put much effort here.
[*] [feasible] Maple has a little spreadsheet interface !
[*] [not practical, onl Windows] Mathematica AFAIR can connect to Excel
[*] [not ready] TeXmacs has a spreadsheet like interface where you can program your functions. But it is not ready for prime time IMO.
[*] [in theory working] There exist a Spreadsheet in Siag office, programmable in Scheme, unfortunately there is not package for FreeBSD, the stuff is old. I tried to complie it from source but in a couple of hours I was not able to make it. I saw there is a package in OpenBSD.
[*] [far from ready] I tried to implement my own spreadsheet ... this require really more time than available, but i started;P

Why don't you use ncurses then? There is a cool library for plain C that does sin, cos, ln, pi,.... and it is really C ! A spreadsheet is important to make complex calculations. It does not needs beautiful graphics because it is just maths. who really cares how beautiful is the applications, if it produces exact numerical math results.

Once it works in the terminal, it is very easy to make it work graphically with FLUID and FLTK !!

An example. It gives you complete freedom, and you can do anything completely complicated, like integrating more complex C libraries, e.g. CAS, NR-methods, ...
https://github.com/cerosrhino/ceros-sheet

Tell me, I give you a cool spreadsheet like this one. We can work on it together.
 
I am interested in having a powerful-spreadsheet and as soon as I will have more free time I will be more than happy to collaborate !

Take a look at sc-im, there is a package for FreeBSD.
Its interface seems much more "ready to use" than cero-sheet.
So, it may be easier to hack that to use a C interpreter instead of Lua.

Said that, in my opinion it is not a good idea to have a spreadsheet in the shell. Even if I am a shell fanatic. The reasons are:
1] You will need to remember a lot shortcuts ... doh
2] Point and click in a GUI to reference a cell is much more practical than writing its address by hand.
3] If you have a GUI it is easy to consider each cell as a seperate graphical widget which than can behave as you wish. E.g. these are the functions I consider extremely useful:
3.1] Wrap cell height to content
3.2] Change cell text color when content matches XX
3.3] Change cell format to currency
3.4] Change .... to have thousands separator
3.5] hilight important sfuff
IMPORTANT] My ideal spreadsheet must be able display LaTeX formulas in cells. => This is very important for the sheet to be self documenting. Nowadays understanding a complex spreadsheet is truly painful.

The architecture of my dream would be a Qt interface with an exchangeable interpreter. But, i started something easier for prototyping, Tk interface with Ruby command language. At the moment project is stuck;)
 
In my opinion, the TI-86 was the best of the best! I wish that the Ti-86 could still be existing.
Heh, not quite a TI-86 but I just managed to find this at my local computer exchange for £20 :D
They did have a Casio fx-something but I like my TIBasic ;)

Unfortunately did not come with any cables (or manual) but I have some left over from my old TI-83 which got trodden on :(
 

Attachments

  • ti84-plus.jpg
    ti84-plus.jpg
    180 KB · Views: 341
@Nicola: 3.1 to 3.5 are readily possible with ncurses. Except being graphical (xorg), unless a port to FLTK is made. Here I come with a quite good example: Isn't VIM the most powerful and most employed editor for *nix/BSD ? (This is the power of terminal + no graphics, just term, for more than 30 years). VIM flavor: terminal or graphical, use it as you wish, full freedom for users.
 
Last edited:
https://github.com/spartrekus/nrpn

a simple cas on top would be nice
A CAS is a tad more sophisticated than an interactive formula parser + numeric evaluation. A real CAS is:
  • a user interface allowing to enter and display mathematical formulas,
  • a programming language and an interpreter (the result of a computation commonly has an unpredictable form and an unpredictable size; therefore user intervention is frequently needed),
  • a simplifier, which is a rewrite system for simplifying mathematics formulas,
  • a memory manager, including a garbage collector, needed by the huge size of the intermediate data, which may appear during a computation,
  • an arbitrary-precision arithmetic, needed by the huge size of the integers that may occur,
  • a large library of mathematical algorithms.
The backends of full featured CAS's are not solely written in C but at least the core is written in LISP. The frontends are perhaps in C, depending on the target system.

My suggestion is to:
  1. look for a BSD licensed readily available backend. From the Wikipedia link which you informed in your initial post, there are 5, and the most promising ones seem to be Axiom, OpenAxiom and FriCAS,

  2. work with each of the candidates on the CLI in order to see which one suits best your needs,

  3. write a CGI possibly in C, capable of processing AJAX requests and interface this to the selected backend
    (actually, I would write this in Objective-C or Swift because of the dynamic method resolution which eases quite a bit the implementation of the dispatcher of the asynchronous HTTP (AJAX) responder, and because compared to Java both can be compiled to produce native (full speed) binaries,

  4. attach that CGI to a web server of your choice and write the frontend using HTML/CSS/SVG/JS.
The benefits of this approach are that the UI looks almost the same on all modern web browsers. You can run this either completely locally (web server on localhost and client on the same machine) or access the CAS server from anywhere, even from your smart phone or tablet. Getting things looking nice with HTML/CSS/SVG/JS is way much easier than with ncurses and this can be done with the assistance of web designers. You could even use the image of your favorite pocket calculator as the UI.

Usually 3 and 4 is the fun part of coding, because you see the results immediately. I wrote a dynamic process simulation for industrial surface treatment. The backend is a differential equation solver which solves the process model based on the parameters to be entered by the user into the web frontend. Parameters and results are passed back and forth with AJAX by the way of a CGI written in Objective-C. The different models are added by a plugin-system. All the graphics is done using SVG and it looks nice at any screen resolution.

Think about replacing the ODE-Solver by one of the CLI-CAS-Systems as the backend and do some HTML/CSS/SVG/JS coding, pronto.
Bildschirmfoto 2018-04-14 um 11.18.41.png
Said all this, I actually don't understand your goals. Why C? Why CAS in the first place, if you are satisfied with simple interactive RPN arithmetics? And in which hell did you digg-out ncurses?
 
Last edited:
The software nrpn for terminal is surely using ncurses, for guaranteeing a high flexibility and quick&simple use. It can be adapted for many math/physics problems. - why no Gui? My old good HP48 has no nice graphics and no shinny windows features. So, I believe that for doing maths for just integration, df(X)/dX (without any needed plots), so the use of AJAX, graphical applications, shinny GUI,... is not necessary for the case. It would make a complex project.

It may even be used over SSH. It is just made to be a simple spreadsheet, as it looks like:
nrpn-term.png


The spreadsheet is far enough for this purpose, needing a little CAS for working with rather simple linear equation problems, e.g. f(X) = 3X^7 + exp( 2*X ) +5X^5+43+X with df(X)/dX.

It is not for solving, just for maths and fun, but for implementing into a simulation software in physics (requiring little simple calculations).

As you say, there are numerous CAS already existing, above mentioned.
A simple CAS system library is interesting for makign it slightly elaborated.
The existing CAS free libraries will imply to make a new project, probably using C++ or better C#. C# is well adapted for this.
 
Back
Top