├── .README.txt.un~ ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── INSTALL.txt ├── NEWS ├── README.txt ├── README.txt~ ├── VERSION ├── altproto.h ├── am.c ├── am.h ├── blt.h ├── changes.txt ├── changes_series_15.txt ├── cmds.c ├── compile.mingw ├── compile.secure ├── complex.c ├── complex.h ├── complex_lib.c ├── diff.c ├── doc ├── README.txt ├── am.html ├── doc.css ├── favicon.ico ├── fdl-1.3-standalone.html ├── gnu-fdl.png ├── greenfade.png ├── index.html ├── led_circle_green.png ├── manual.html ├── matho-mult.1.html ├── matho-pascal.1.html ├── matho-primes.1.html ├── matho-sum.1.html ├── matho-sumsq.1.html ├── mathomatic.1.html ├── mathomatic16x16.png ├── open_book_nae_02.png ├── primorial.1.html ├── quickrefcard.html └── rmath.1.html ├── examples ├── README.txt ├── compile.limits ├── compile.roots ├── fact.c ├── fact.py ├── factorial ├── intfact.c ├── limits.c ├── roots.c └── testprimes ├── externs.h ├── factor.c ├── factor_int.c ├── gcd.c ├── globals.c ├── help.c ├── icons ├── README.txt ├── icon.rc ├── mathomatic.desktop ├── mathomatic.icns ├── mathomatic.ico ├── mathomatic.png ├── mathomatic.svg ├── mathomatic.xpm └── mathomatic32x32.png ├── includes.h ├── integrate.c ├── lib ├── README.txt ├── compile.testmain ├── example.c ├── lib.c ├── makefile ├── matho_clear.3 ├── matho_init.3 ├── matho_parse.3 ├── matho_process.3 ├── mathomatic.h └── testmain.c ├── license.h ├── list.c ├── m4 ├── README.txt ├── degrees.m4 ├── file_id.diz ├── functions.m4 ├── gradians.m4 ├── matho ├── matho-install ├── matho-install-degrees ├── matho-uninstall └── rmath ├── main.c ├── makefile ├── makehtmlcard.awk ├── makehtmlcard.sh ├── makenews.sh ├── makepdfsheet.sh ├── mathomatic.1 ├── menu ├── README.txt ├── mathomatic └── mathomatic-primes ├── misc ├── README.txt ├── ideas.txt ├── identities.in ├── john.in ├── known_bugs.txt └── linear4.in ├── parse.c ├── poly.c ├── primes ├── README.txt ├── bigtwins.out ├── lsqrt.c ├── makefile ├── matho-mult ├── matho-mult.1 ├── matho-pascal.1 ├── matho-pascal.c ├── matho-primes.1 ├── matho-primes.c ├── matho-sum ├── matho-sum.1 ├── matho-sumsq.1 ├── matho-sumsq.c ├── primorial ├── primorial.1 ├── t └── twins.out ├── proto.h ├── rmath.1 ├── simplify.c ├── solve.c ├── standard.h ├── super.c ├── t ├── tests ├── README.txt ├── all.in ├── all.out ├── batman_gnuplot_bug.in ├── batman_plot ├── circles.in ├── collatz.in ├── cubic.in ├── cubic2.in ├── demo ├── demo.in ├── demo_sub ├── distance.in ├── electronics.in ├── ellipse.in ├── examples.in ├── fibonacci.in ├── finance.in ├── fix1.in ├── fix2.in ├── fix5.in ├── fix7.in ├── fix8.in ├── fix9.in ├── fraction.in ├── heart.in ├── heron.in ├── how_limit_works.in ├── hypertrig.in ├── limits.in ├── linear.in ├── pie.in ├── points.in ├── poly.in ├── pyth3d.in ├── quadratic.in ├── quartic.in ├── radius.in ├── simplify.in ├── t ├── test.in ├── test1.in ├── test2.in ├── test3.in ├── test6.in ├── trig └── trig.in ├── unfactor.c ├── update └── zipsrc /.README.txt.un~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/.README.txt.un~ -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | George Gesslein II 2 | Chief Mathomatic creator, author, maintainer, and copyright holder. 3 | http://www.mathomatic.org 4 | 5 | There are many individuals maintaining Mathomatic ports. Thank you very much 6 | for creating, supporting, and sponsoring the Mathomatic ports for all these 7 | years. 8 | 9 | Thanks to all people who have contributed code and time to the Mathomatic 10 | project: 11 | 2010 Simon Geard for better and more readable code command code. :-) 12 | 2010 Michael Pogue of Sun Microsystems for help on compiling under Solaris. 13 | 2010 Jonathan Stark for the original cmake file "CMakeLists.txt". 14 | 2011 Doug Snead for the MinGW color mode code for cmd.exe and command.com. 15 | 2012 Doug Snead creates and sells a fancy Android version with a GUI. 16 | 17 | Thanks to all the wonderful people that have been testing, contributing, and 18 | donating to the Mathomatic project and encouraging me on; many are not listed 19 | here. If you think you belong in this list, please let George Gesslein II 20 | know. I will mention anyone that has contributed to or guided the Mathomatic 21 | project, that wishes to be mentioned here. Please indicate how you would like 22 | your entry to appear (website?, email address?). 23 | 24 | And late thanks to Dennis M. Ritchie, whose work to design and create the 25 | original C language and compiler made Mathomatic and our life possible. I 26 | even learned C from his book. 27 | 28 | Sincerely, 29 | George Gesslein II 30 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake build file for Mathomatic and the Symbolic Math Library, 2 | # originally contributed by Jonathan Stark. 3 | # Produces the normal version of Mathomatic with readline support. 4 | # If you need the Symbolic Math Library as a shared library, 5 | # change the line "add_library(mathomatic_cmake" to: 6 | # "add_library(mathomatic_cmake SHARED" below. 7 | # This is all untested! It is recommended to use "makefile" instead! 8 | # To use cmake instead of "makefile", type: 9 | # 10 | # cmake . 11 | # make -f Makefile 12 | # 13 | # Please note that cmake makes an unfixable mess of the Mathomatic 14 | # source distribution directory, so make a copy, first. 15 | 16 | cmake_minimum_required(VERSION 2.6) 17 | 18 | project(mathomatic) 19 | 20 | file(READ VERSION FV) 21 | string(STRIP ${FV} MATHOMATIC_VERSION) 22 | message(STATUS VERSION: ${MATHOMATIC_VERSION}) 23 | add_definitions(-O3 -Wall -Wshadow -Wno-char-subscripts -fexceptions -DVERSION="${MATHOMATIC_VERSION}") 24 | 25 | add_library(mathomatic_cmake 26 | includes.h 27 | standard.h 28 | am.h 29 | altproto.h 30 | externs.h 31 | blt.h 32 | license.h 33 | complex.h 34 | proto.h 35 | lib/mathomatic.h 36 | lib/lib.c 37 | globals.c 38 | complex.c 39 | poly.c 40 | super.c 41 | am.c 42 | factor.c 43 | help.c 44 | list.c 45 | unfactor.c 46 | complex_lib.c 47 | factor_int.c 48 | simplify.c 49 | cmds.c 50 | diff.c 51 | gcd.c 52 | integrate.c 53 | parse.c 54 | solve.c 55 | ) 56 | 57 | add_executable(testmain 58 | lib/mathomatic.h 59 | lib/testmain.c 60 | ) 61 | 62 | add_dependencies(testmain 63 | mathomatic_cmake 64 | ) 65 | 66 | add_executable(mathomatic 67 | includes.h 68 | standard.h 69 | am.h 70 | altproto.h 71 | externs.h 72 | blt.h 73 | license.h 74 | complex.h 75 | proto.h 76 | globals.c 77 | complex.c 78 | poly.c 79 | super.c 80 | am.c 81 | factor.c 82 | help.c 83 | list.c 84 | unfactor.c 85 | complex_lib.c 86 | factor_int.c 87 | main.c 88 | simplify.c 89 | cmds.c 90 | diff.c 91 | gcd.c 92 | integrate.c 93 | parse.c 94 | solve.c 95 | ) 96 | 97 | set_target_properties(mathomatic_cmake PROPERTIES COMPILE_FLAGS "-DLIBRARY") 98 | set_target_properties(mathomatic PROPERTIES COMPILE_FLAGS "-DREADLINE -DUNIX") 99 | target_link_libraries(mathomatic -lm -lreadline) 100 | target_link_libraries(testmain mathomatic_cmake) 101 | target_link_libraries(mathomatic_cmake -lm) 102 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | 2 | Mathomatic Installation Instructions 3 | ------------------------------------ 4 | 5 | The requirements for easy installation from this source code are: the GNU 6 | make utility and the GNU C compiler (gcc). Other C compilers may be used, but 7 | may require small changes to the makefile, source files, or compilation 8 | command-line. You will need to open a shell window to compile, install, and 9 | run Mathomatic. 10 | 11 | On a Debian or Ubuntu Linux computer, the "build-essential" and readline or 12 | editline development packages "libreadline-dev" or "libeditline-dev" are 13 | required to compile Mathomatic with readline functionality. To open a shell 14 | window in desktop Linux, launch Applications/Accessories/Terminal. 15 | 16 | To skip these compilation instructions and install an older version of 17 | Mathomatic, already compiled and ready to run under Debian or Ubuntu, type: 18 | 19 | sudo apt-get install mathomatic mathomatic-primes 20 | 21 | at the shell prompt, then type your password if prompted for it. You can then 22 | run Mathomatic by typing "mathomatic". This is possible because Mathomatic is 23 | an official Debian package. It is also an official Fedora package. To install 24 | Mathomatic in Fedora Linux, type: 25 | 26 | sudo yum install mathomatic 27 | 28 | To install Mathomatic in Gentoo Linux, type: 29 | 30 | sudo emerge mathomatic 31 | 32 | The Mathomatic code is portable, self-testing, and easily compiles and 33 | installs using the GNU utilities under Linux, Unix, SunOS, Mac OS X, 34 | Microsoft Windows, and many modern mobile devices. Both the source code and 35 | compiled, ready to run, binary packages may be available from your operating 36 | system's package manager or from the Mathomatic website: 37 | http://www.mathomatic.org/math/download.html 38 | 39 | 40 | Typical compilation and installation 41 | ------------------------------------ 42 | 43 | Root (super-user) authority is needed to install Mathomatic, because write 44 | permission is needed to copy files into the directories in "/usr/local". 45 | Mathomatic need not be installed to run the compiled executable. Reading the 46 | makefile comments is recommended. 47 | 48 | A typical compile/install is done by typing the following at the shell 49 | prompt, while in the Mathomatic source code directory: 50 | 51 | make clean 52 | make READLINE=1 or make EDITLINE=1 53 | make test 54 | sudo make install 55 | 56 | and enter your password. That will compile the source code with readline 57 | enabled, test the functionality of the generated executable (named 58 | "mathomatic"), and install the executable, docs, and tests in "/usr/local" in 59 | less than a minute. After that, typing "man mathomatic" should bring up the 60 | man page, and typing "mathomatic" should run Mathomatic. If Mathomatic 61 | doesn't run, check that the PATH environment variable includes 62 | "/usr/local/bin" with the shell command "echo $PATH". 63 | 64 | To install in "/usr" instead of "/usr/local", type: 65 | 66 | sudo make prefix=/usr install 67 | 68 | sudo asks you for your password; if it doesn't work, login as root or type: 69 | 70 | su -c "make install" 71 | 72 | and enter the root password to install as the super-user. 73 | 74 | 75 | m4 Mathomatic 76 | ------------- 77 | 78 | To install everything, including m4 Mathomatic (rmath), which allows easy 79 | entry of math functions like sqrt(x) and sin(x) as macros, use "make 80 | m4install" or "make m4install-degrees" instead of "make install". "make 81 | m4install-degrees" sets degree mode instead of radian mode for trig 82 | functions. 83 | 84 | 85 | Prime Number Tools 86 | ------------------ 87 | 88 | To clean, compile, test, and install the Mathomatic Prime Number Tools: 89 | 90 | cd primes 91 | make flush 92 | make 93 | ./t 94 | sudo make install 95 | 96 | 97 | Uninstall 98 | --------- 99 | 100 | To undo the installation, removing Mathomatic from the local computer, type: 101 | 102 | sudo make uninstall 103 | 104 | These instructions were written by George Gesslein II of www.mathomatic.org 105 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 16.0.5 2 | -------------------------------------------------------------------------------- /altproto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Alternate global C function prototypes for Mathomatic. 3 | * 4 | * Copyright (C) 1987-2012 George Gesslein II. 5 | */ 6 | 7 | /* command function list */ 8 | int clear_cmd(), quit_cmd(), list_cmd(), simplify_cmd(), help_cmd(), eliminate_cmd(); 9 | int fraction_cmd(), unfactor_cmd(), compare_cmd(), extrema_cmd(); 10 | int read_cmd(), display_cmd(), calculate_cmd(), solve_cmd(); 11 | int factor_cmd(), derivative_cmd(), replace_cmd(), approximate_cmd(); 12 | int save_cmd(), taylor_cmd(), limit_cmd(), echo_cmd(), plot_cmd(); 13 | int copy_cmd(), divide_cmd(), pause_cmd(), version_cmd(); 14 | int edit_cmd(), real_cmd(), imaginary_cmd(), tally_cmd(); 15 | int roots_cmd(), set_cmd(), variables_cmd(), code_cmd(), optimize_cmd(), push_cmd(), push_en(); 16 | int sum_cmd(), product_cmd(), for_cmd(), integrate_cmd(), nintegrate_cmd(), laplace_cmd(); 17 | 18 | /* various functions that don't return int */ 19 | char *dirname_win(); 20 | char *skip_space(), *skip_comma_space(), *skip_param(); 21 | char *get_string(); 22 | char *parse_equation(), *parse_section(), *parse_var(), *parse_var2(), *parse_expr(); 23 | char *list_expression(), *list_equation(), *flist_equation_string(); 24 | double gcd(), gcd_verified(), my_round(), multiply_out_unique(); 25 | long decstrtol(), max_memory_usage(); 26 | 27 | void fphandler(int sig); 28 | void inthandler(int sig); 29 | void alarmhandler(int sig); 30 | void exithandler(int sig); 31 | void resizehandler(int sig); 32 | -------------------------------------------------------------------------------- /blt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * blt(), also know as memmove(3), include file for Mathomatic. 3 | * 4 | * Copyright (C) 1987-2012 George Gesslein II. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | #if 1 26 | #define blt(dest, src, cnt) memmove((dest), (src), (cnt)) /* memory copy function; must allow overlapping of src and dest */ 27 | #else 28 | /* If no fast or working memmove(3) routine exists use this one. */ 29 | static inline char * 30 | blt(dest, src, cnt) 31 | char *dest; 32 | const char *src; 33 | int cnt; 34 | { 35 | char *tdest; 36 | const char *tsrc; 37 | int tcnt; 38 | 39 | if (cnt <= 0) { 40 | if (cnt == 0) { 41 | return dest; 42 | } else { 43 | error_bug("blt() cnt < 0"); 44 | } 45 | } 46 | if (src == dest) { 47 | return dest; 48 | } 49 | 50 | tdest = dest; 51 | tsrc = src; 52 | tcnt = cnt; 53 | 54 | if (tdest > tsrc) { 55 | tdest += tcnt; 56 | tsrc += tcnt; 57 | while (--tcnt >= 0) 58 | *--tdest = *--tsrc; 59 | } else { 60 | while (--tcnt >= 0) 61 | *tdest++ = *tsrc++; 62 | } 63 | return dest; 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /compile.mingw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script for creating the Windows 32-bit executables "mathomatic.exe" and Prime Number Tools. 3 | # In Debian or its derivatives, install the MinGW cross-compiler package mingw32 (tested; 4 | # run "sudo apt-get install mingw32"). MinGW doesn't recognize long longs or 5 | # long doubles, and the 64-bit version doesn't appear to work yet. 6 | # 7 | # The 32-bit executables created here are very capable, work standalone or with Cygwin, 8 | # and do not require readline or editline to recall and edit command-line history, 9 | # this already works in the Windows console (cmd.exe and command.com). 10 | # 11 | # To compile everything with MinGW, just type: 12 | # ./compile.mingw 13 | # This file may require editing if you are not using Debian or a derivative distro. 14 | # 15 | 16 | # Abort on any errors: 17 | set -e 18 | 19 | # Define the C cross-compiler and flags we are using here: 20 | export CC=i586-mingw32msvc-cc 21 | export CFLAGS="-O3 -Wall -DMINGW -DWIN32_CONSOLE_COLORS -DBOLD_COLOR $CFLAGS" 22 | 23 | echo Compiling Windows 32-bit Mathomatic... 24 | make clean 25 | cd icons 26 | i586-mingw32msvc-windres icon.rc icon.o 27 | cd .. 28 | AOUT=mathomatic.exe MATHOMATIC_OBJECTS="icons/icon.o" make -j 29 | make clean 30 | 31 | echo 32 | echo Compiling the 32-bit Prime Number Tools... 33 | cd primes 34 | make flush 35 | CFLAGS="-DUSE_DOUBLES $CFLAGS" make -j 36 | make clean 37 | echo 38 | mv matho-primes matho-primes.exe 39 | mv matho-pascal matho-pascal.exe 40 | mv matho-sumsq matho-sumsq.exe 41 | echo Prime Number Tools executables had .exe appended to the filenames. 42 | cd .. 43 | 44 | exit 0 # 64-bits isn't completely supported by MinGW yet. 45 | 46 | export CC=amd64-mingw32msvc-cc 47 | 48 | echo Compiling Windows 64-bit Mathomatic... 49 | make clean 50 | cd icons 51 | amd64-mingw32msvc-windres icon.rc icon.o 52 | cd .. 53 | AOUT=mathomatic64.exe MATHOMATIC_OBJECTS="icons/icon.o" make -j 54 | make clean 55 | -------------------------------------------------------------------------------- /compile.secure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script for creating the executable "mathomatic_secure", 3 | # which lacks the code for file I/O and shelling out. 4 | # The result can safely be used as an application on open public servers. 5 | # The Mathomatic run-time option -s4 performs exactly the same function, 6 | # so this script that makes a separate executable is no longer necessary. 7 | 8 | # You will need to install the libeditline-dev package to run this. 9 | 10 | echo Compiling Secure Mathomatic... 11 | set -v 12 | gcc -O3 -Wall -Wshadow -Wno-char-subscripts -fexceptions $CFLAGS $CPPFLAGS -DEDITLINE -DUNIX -DVERSION=\"`cat VERSION`\" -DSECURE -DTIMEOUT_SECONDS=3600 $LDFLAGS *.c -lm -leditline $LDLIBS -o mathomatic_secure && echo ./mathomatic_secure created. 13 | make clean # for any subsequent makes 14 | -------------------------------------------------------------------------------- /complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Include file for the double precision floating point complex number 3 | * arithmetic functions in "complex_lib.c". 4 | * 5 | * Copyright (C) 1987-2012 George Gesslein II. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | 21 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 22 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 23 | 24 | */ 25 | 26 | typedef struct complexs { /* complex number structure */ 27 | double re; /* real part */ 28 | double im; /* imaginary part */ 29 | } complexs; 30 | 31 | /* 32 | * Complex number arithmetic function prototypes 33 | */ 34 | int complex_fixup(complexs *ap); 35 | complexs complex_add(complexs a, complexs b); 36 | complexs complex_negate(complexs a); 37 | complexs complex_mult(complexs a, complexs b); 38 | complexs complex_div(complexs a, complexs b); 39 | complexs complex_log(complexs a); 40 | complexs complex_exp(complexs a); 41 | complexs complex_pow(complexs a, complexs b); 42 | -------------------------------------------------------------------------------- /complex_lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * A handy, tested, small, stand-alone, double precision floating point 3 | * complex number arithmetic library for C. 4 | * Just include "complex.h" if you use this. 5 | * 6 | * Copyright (C) 1987-2012 George Gesslein II. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 23 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 24 | 25 | */ 26 | 27 | #include "complex.h" 28 | #include 29 | 30 | #define true 1 31 | #define false 0 32 | 33 | #define epsilon 0.00000000000005 /* a good value for doubles */ 34 | 35 | /* 36 | * Zero out relatively very small real or imaginary parts of a complex number, 37 | * because they probably are a result of accumulated floating point inaccuracies. 38 | * 39 | * Return true if something was zeroed out. 40 | */ 41 | int 42 | complex_fixup(ap) 43 | complexs *ap; /* complex number pointer */ 44 | { 45 | if (fabs(ap->re * epsilon) > fabs(ap->im)) { 46 | ap->im = 0.0; 47 | return true; 48 | } 49 | if (fabs(ap->im * epsilon) > fabs(ap->re)) { 50 | ap->re = 0.0; 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | /* 57 | * Add two complex numbers (a + b) 58 | * and return the complex number result. 59 | * 60 | * Complex number subtraction (a - b) is done by 61 | * complex_add(a, complex_negate(b)). 62 | */ 63 | complexs 64 | complex_add(a, b) 65 | complexs a, b; 66 | { 67 | a.re += b.re; 68 | a.im += b.im; 69 | return(a); 70 | } 71 | 72 | /* 73 | * Negate a complex number (-a) 74 | * and return the complex number result. 75 | */ 76 | complexs 77 | complex_negate(a) 78 | complexs a; 79 | { 80 | a.re = -a.re; 81 | a.im = -a.im; 82 | return(a); 83 | } 84 | 85 | /* 86 | * Multiply two complex numbers (a * b) 87 | * and return the complex number result. 88 | */ 89 | complexs 90 | complex_mult(a, b) 91 | complexs a, b; 92 | { 93 | complexs r; 94 | 95 | r.re = a.re * b.re - a.im * b.im; 96 | r.im = a.re * b.im + a.im * b.re; 97 | return(r); 98 | } 99 | 100 | /* 101 | * Divide two complex numbers (a / b) 102 | * and return the complex number result. 103 | */ 104 | complexs 105 | complex_div(a, b) 106 | complexs a; /* dividend */ 107 | complexs b; /* divisor */ 108 | { 109 | complexs r, num; 110 | double denom; 111 | 112 | b.im = -b.im; 113 | num = complex_mult(a, b); 114 | denom = b.re * b.re + b.im * b.im; 115 | r.re = num.re / denom; 116 | r.im = num.im / denom; 117 | return r; 118 | } 119 | 120 | /* 121 | * Take the natural logarithm of a complex number 122 | * and return the complex number result. 123 | */ 124 | complexs 125 | complex_log(a) 126 | complexs a; 127 | { 128 | complexs r; 129 | 130 | r.re = log(a.re * a.re + a.im * a.im) / 2.0; 131 | r.im = atan2(a.im, a.re); 132 | return(r); 133 | } 134 | 135 | /* 136 | * Raise the natural number (e) to the power of a complex number (e^a) 137 | * and return the complex number result. 138 | */ 139 | complexs 140 | complex_exp(a) 141 | complexs a; 142 | { 143 | complexs r; 144 | double m; 145 | 146 | m = exp(a.re); 147 | r.re = m * cos(a.im); 148 | r.im = m * sin(a.im); 149 | return(r); 150 | } 151 | 152 | /* 153 | * Raise complex number "a" to the power of complex number "b" (a^b) 154 | * and return the complex number result. 155 | */ 156 | complexs 157 | complex_pow(a, b) 158 | complexs a, b; 159 | { 160 | complexs r; 161 | 162 | r = complex_log(a); 163 | r = complex_mult(r, b); 164 | r = complex_exp(r); 165 | complex_fixup(&r); 166 | return(r); 167 | } 168 | -------------------------------------------------------------------------------- /doc/README.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory contains the complete Mathomatic user documentation in HTML. 3 | Everything in this documentation directory is copyrighted and licensed under 4 | the GNU Free Documentation License version 1.3. The full text of this license 5 | is contained in file "fdl-1.3-standalone.html". 6 | 7 | To read or print the Mathomatic user documentation, point your web browser to 8 | the file "index.html". If the PDF documentation was created, it is in the 9 | file "../manual.pdf". This PDF document is made by the htmldoc program by 10 | typing "make pdf" in the parent directory. 11 | 12 | When copying the Mathomatic documentation, please copy this entire directory, 13 | not just selected HTML files from it. 14 | 15 | To view online the most recent documentation, visit 16 | http://mathomatic.org/math/doc/ with your web browser. 17 | -------------------------------------------------------------------------------- /doc/doc.css: -------------------------------------------------------------------------------- 1 | /* George Gesslein II's CSS for HTML documentation */ 2 | 3 | /* Commonly used classes: */ 4 | .clear { clear: both; } 5 | .right { float: right; } 6 | .left { float: left; } 7 | .center { text-align: center; } 8 | .middle { vertical-align: middle; } 9 | .indent { margin-left: 2em; margin-right: 2em; } 10 | .large { font-size: larger; } 11 | .small { font-size: x-small; } 12 | 13 | .sample { 14 | border-style: solid; border-width: 1px; border-color: black; 15 | border-radius: 7px; 16 | color: black; 17 | background-color: #FFFAF0; 18 | padding: 10px; 19 | } 20 | 21 | a img { border: none; } /* don't draw borders around images that are links */ 22 | 23 | body { 24 | font-family: sans-serif; 25 | /* font-size: large; */ 26 | color: black; 27 | background-color: white; 28 | } 29 | 30 | tt { 31 | color: brown; 32 | } 33 | 34 | a:link { 35 | color: blue; 36 | } 37 | 38 | a:visited { 39 | color: purple; 40 | } 41 | 42 | a:hover { 43 | color: green; 44 | } 45 | 46 | a:active { 47 | color: red; 48 | } 49 | 50 | caption { 51 | color: orange; 52 | font-weight: bold; 53 | } 54 | 55 | @media print 56 | { 57 | a { text-decoration: none; } /* no underlined links when printing */ 58 | /* h2 { page-break-before: always; } Uncomment this to page break at the beginning of every section. */ 59 | } 60 | -------------------------------------------------------------------------------- /doc/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/favicon.ico -------------------------------------------------------------------------------- /doc/gnu-fdl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/gnu-fdl.png -------------------------------------------------------------------------------- /doc/greenfade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/greenfade.png -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Official Mathomatic user documentation, top level 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |

outline of book Official Documentation for Mathomatic

31 | 32 |

HTML User Guides:

33 | 34 |
35 | button 36 | The Mathomatic User Guide 37 |
38 | button 39 | The Mathomatic Command Reference 40 |
41 | button 42 | The Unix/Linux man page for Mathomatic 43 |
44 | button 45 | The rmath application man page (m4 Mathomatic) 46 |
47 | button 48 | The matho-primes utility man page 49 |
50 | button 51 | The primorial utility man page 52 |
53 | 54 |

55 | This HTML format documentation is easily viewed and printed using your web browser. 56 | 57 |

PDF User Guides:

58 |

59 | For the PDFs, see the online 60 | Mathomatic User Guide and Command Reference PDF file in a file called "manual.pdf", 61 | or all Unix/Linux man pages for Mathomatic in one PDF file called "bookman.pdf". 62 | PDFs are generally used when you want to print out a hardcopy 8.5-inch by 11-inch manual, but they can be browsed 63 | with a PDF document viewer and saved to disk easily, too. 64 | 65 |


66 | 67 |

68 | GFDL logo 69 | Mathomatic documentation copyright © 1987-2012 George Gesslein II 70 |

71 | Permission is granted to copy, distribute and/or modify this document 72 | under the terms of the GNU Free Documentation License, Version 1.3 73 | or any later version published by the Free Software Foundation; 74 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. 75 | A copy of the license is included here 76 | in the Mathomatic documentation directory. 77 | 78 |
79 |
80 |


81 | 82 |
83 | 84 | Mathomatic icon www.mathomatic.org 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /doc/led_circle_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/led_circle_green.png -------------------------------------------------------------------------------- /doc/matho-mult.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | MATHO-MULT(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

matho-mult - 17 | multiply large integers 18 | 19 |

Synopsis

matho-mult [integers] 21 | 22 |

Description

This 23 | command-line utility is optionally part of the mathomatic(1) package. It uses 25 | Python to multiply many large integers separated by spaces or 26 | newlines. The size of the integers is only limited by the 27 | available memory of the computer. The single integer result is 28 | output to standard output, followed by a newline. 29 | 30 |

The integers to multiply may be specified on the command line 31 | or read from standard input.

32 | 33 |

Author

George Gesslein 34 | II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 36 | 37 |

Reporting Bugs

If you 38 | find a bug, please report it to the author or at "https://launchpad.net/mathomatic 40 | ". 41 | 42 |

See Also

mathomatic(1) , primorial(1) , matho-sum(1) 46 |
47 | 48 |

Table of Contents

49 | 50 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /doc/matho-pascal.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | MATHO-PASCAL(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

matho-pascal - display Pascal’s 18 | triangle 19 | 20 |

Synopsis

matho-pascal [number-of-lines] 22 | 23 |

Description

This command-line utility is 25 | optionally part of the mathomatic(1) package. It 27 | calculates up to 1000 lines of Pascal’s triangle using 28 | floating point arithmetic, dumping the lines to standard output. 29 | The default is to center one screen full. 30 | 31 |

Every number inside Pascal’s triangle is the sum of the 32 | two numbers immediately above it.

33 | 34 |

Each line of Pascal’s triangle is the same as the 35 | binomial coefficients for a given power.

36 | 37 |

The sum of all numbers in each line of Pascal’s triangle 38 | is a power of 2.

39 | 40 |

Author

George 41 | Gesslein II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 43 | 44 |

Reporting 45 | Bugs

If you find a bug, please report it to the author or 46 | at "https://launchpad.net/mathomatic 48 | ". 49 | 50 |

See 51 | Also

mathomatic(1) 52 | , matho-primes(1) , 53 | matho-sumsq(1) 54 |
55 | 56 |

Table of Contents

57 | 58 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /doc/matho-primes.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | MATHO-PRIMES(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

matho-primes - 17 | generate consecutive prime numbers 18 | 19 |

Synopsis

matho-primes [start [stop] or 21 | "all"] ["twin"] ["pal" [base]]
22 | matho-primes [-htuv] [-c count] [-m number] [-p base] 23 | [start [stop]] 24 | 25 |

Description

This 26 | command-line utility is optionally part of the mathomatic(1) package. It quickly 28 | computes any number of consecutive prime numbers using a 29 | windowing, memory efficient sieve of Eratosthenes algorithm, 30 | dumping them to standard output. They are displayed one prime per 31 | line in ascending order, unless the "twin" option is specified, 32 | which displays only twin primes, two primes per line. 33 | 34 |

Generates up to 18 decimal digit primes, or whatever is the 35 | number of digits of precision for a floating point long 36 | double in the C compiler used to compile this utility. Note 37 | that this utility might be compiled to use only double precision 38 | floating point, if long double precision is not fully supported 39 | by the C compiler or hardware, allowing at most 15 decimal digit 40 | primes in that case.

41 | 42 |

Ways to verify that this utility is working are to pipe the 43 | output into the Unix "factor" utility, or compare the output with 44 | the BSD Games "primes" utility, using the supplied shell script: 45 | examples/testprimes.

46 | 47 |

All numbers displayed by this utility are decimal (base 10) 48 | prime numbers. A prime number is an integer that cannot be 49 | factored.

50 | 51 |

A range may be specified on the command line, otherwise the 52 | starting number and the number of primes to output is prompted 53 | for. The range is start to stop inclusive, and 54 | stop must be greater than or equal to start.

55 | 56 |

If the -c option is specified, the number of lines of 57 | primes displayed is limited to the decimal count that follows 58 | this option.

59 | 60 |

If the -t or "twin" option is specified on the command 61 | line, only twin primes will be displayed. Twin primes are 62 | two primes that differ in value by 2. Each twin pair is displayed 63 | together on the same line separated by a space character.

64 | 65 |

If the -p or "pal" option is specified on the command 66 | line, only palindromic primes are displayed. Palindromes 67 | are symmetrical, they read exactly the same forward and backward. 68 | The palindromic number base may be specified, the default 69 | is base 10. The base can be any integer greater than 1. 70 | Primes are always displayed in decimal (base 10).

71 | 72 |

The version number and short help on the allowed command-line 73 | parameters and usage information are displayed when given the 74 | -h option.

75 | 76 |

With the -u option, all output (standard output and 77 | standard error output) is set to be unbuffered, making all output 78 | happen immediately, instead of when the output buffer is full or 79 | when the program terminates or waits for input.

80 | 81 |

The -m option changes the memory size of the prime 82 | number sieve window. It is followed by a decimal, floating point 83 | number which is a multiplier of the default window size (2 84 | megabytes). It is possible that changing the memory size may 85 | speed up the total run time a bit; otherwise there is no reason 86 | to use this option, and its use is not recommended.

87 | 88 |

The -v option simply displays the program name and 89 | version number, and then exits successfully.

90 | 91 |

Author

George Gesslein 92 | II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 94 | 95 |

Reporting Bugs

If you 96 | find a bug, please report it to the author or at "https://launchpad.net/mathomatic 98 | ". 99 | 100 |

See Also

rmath(1) , mathomatic(1) , primorial(1) , matho-mult(1) , matho-sum(1) , matho-pascal(1) , matho-sumsq(1) 108 |
109 | 110 |

Table of Contents

111 | 112 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /doc/matho-sum.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | MATHO-SUM(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

matho-sum - sum 17 | large integers 18 | 19 |

Synopsis

matho-sum [integers] 21 | 22 |

Description

This 23 | command-line utility is optionally part of the mathomatic(1) package. It uses 25 | Python to sum many large integers separated by spaces or 26 | newlines. The size of the integers is only limited by the 27 | available memory of the computer. The single integer result is 28 | output to standard output, followed by a newline. 29 | 30 |

The integers to sum may be specified on the command line or 31 | read from standard input.

32 | 33 |

Author

George Gesslein 34 | II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 36 | 37 |

Reporting Bugs

If you 38 | find a bug, please report it to the author or at "https://launchpad.net/mathomatic 40 | ". 41 | 42 |

See Also

mathomatic(1) , primorial(1) , matho-mult(1) 46 |
47 | 48 |

Table of Contents

49 | 50 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /doc/matho-sumsq.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | MATHO-SUMSQ(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

matho-sumsq - Find 17 | the minimum sum of the squares for integers 18 | 19 |

Synopsis

matho-sumsq [numbers] 21 | 22 |

Description

This 23 | command-line utility is optionally part of the mathomatic(1) package. It finds 25 | the minimum number of positive integers that when squared and 26 | added together, equal the given number. There is a proof that no 27 | more than 4 squares summed together are required to represent any 28 | positive integer. 29 | 30 |

The command-line may contain positive integers to find the 31 | minimum squares of, they must be less than 2147483648 (2^31) on 32 | 32-bit systems or less than 9223372036854775808 (2^63) on 64-bit 33 | systems. If "+" is appended to the given number, the program 34 | counts up from the given number. If the minimum number of squares 35 | is 2, this program displays all possible combinations with 2 36 | squares for the given number, otherwise it just displays the 37 | first combination it finds.

38 | 39 |

If no command-line arguments are given, the programs reads the 40 | numbers from standard input.

41 | 42 |

Author

George Gesslein 43 | II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 45 | 46 |

Reporting Bugs

If you 47 | find a bug, please report it to the author or at "https://launchpad.net/mathomatic 49 | ". 50 | 51 |

See Also

mathomatic(1) , matho-pascal(1) , matho-primes(1) 55 |
56 | 57 |

Table of Contents

58 | 59 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /doc/mathomatic16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/mathomatic16x16.png -------------------------------------------------------------------------------- /doc/open_book_nae_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/doc/open_book_nae_02.png -------------------------------------------------------------------------------- /doc/primorial.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | PRIMORIAL(1) manual page 11 | 12 | 13 | 14 | Table of Contents 15 | 16 |

Name

primorial - 17 | calculate large primorials 18 | 19 |

Synopsis

primorial integers 21 | 22 |

Description

This 23 | command-line utility is optionally part of the mathomatic(1) package. It uses 25 | Python and matho-primes(1) and matho-mult(1) to calculate and 28 | display large primorials. 29 | 30 |

A primorial is the product of all primes up to the given 31 | integer. The integers to show the primorials of are given on the 32 | command line.

33 | 34 |

The calculated primorials are output to standard output. The 35 | size is limited by the amount of computer memory available.

36 | 37 |

Author

George Gesslein 38 | II (gesslein@mathomatic.org) at "http://www.mathomatic.org ". 40 | 41 |

Reporting Bugs

If you 42 | find a bug, please report it to the author or at "https://launchpad.net/mathomatic 44 | ". 45 | 46 |

See Also

mathomatic(1) , matho-mult(1) , matho-primes(1) 50 |
51 | 52 |

Table of Contents

53 | 54 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | examples/README.txt 3 | ------------------- 4 | 5 | See directory ../tests for example, tutorial, and test scripts for 6 | Mathomatic. 7 | 8 | This directory is where example source code goes for a binary distribution. 9 | 10 | ----------------------------------------------------------------------------- 11 | 12 | limits.c - C program to display current C data type limits and sizes. 13 | Mathomatic is limited to double precision floating point. 14 | Use "./compile.limits" to compile. 15 | 16 | roots.c - Nice GSL example of a numerical polynomial equation solver utility. 17 | Compile with "./c", requires the libgsl development files. 18 | Like Mathomatic, uses complex number double precision output. 19 | Use "./compile.roots" to compile. 20 | 21 | testprimes - A parallel, brute force test of the prime number generator. 22 | Checks the first 50,000,000 primes for gaps or errors. 23 | Requires matho-primes and BSD Games primes to be installed. 24 | It simply compares their output up to 1,000,000,000. 25 | 26 | ----------------------------------------------------------------------------- 27 | 28 | This directory also contains factorial functions "factorial()" in various 29 | computer languages are for use with output from the Mathomatic code command, 30 | which converts factorial expressions like x! to factorial(x). 31 | 32 | Type "./factorial" followed by integers or integer expressions to compute 33 | large factorials with Python and test "fact.py". 34 | 35 | ----------------------------------------------------------------------------- 36 | 37 | These files do not have any man page, because I think they are not ready or 38 | are not made for packaging. They are just example programs. Any requests to 39 | make man pages for these files will be honored by the author of this 40 | document: George Gesslein II. Please specify which utilities you think should 41 | be installable with a man page. 42 | -------------------------------------------------------------------------------- /examples/compile.limits: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Compile limits.c and create the executable in ~/bin if it exists. 3 | # limits is a standalone program that nicely 4 | # displays current C data type limits and sizes. 5 | # Works with any C compiler, compiles with the C compiler you set CC to. 6 | 7 | CC=${CC-cc} 8 | 9 | if [ -d ~/bin ] 10 | then 11 | LIMITS=~/bin/limits 12 | else 13 | LIMITS=./limits 14 | fi 15 | echo Compiling limits.c 16 | set -e 17 | set -x 18 | $CC -Wall $CFLAGS $CPPFLAGS $LDFLAGS -o $LIMITS limits.c 19 | echo limits.c compiled and installed as $LIMITS 20 | -------------------------------------------------------------------------------- /examples/compile.roots: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Compile roots.c and create the executable in ~/bin if it exists. 3 | # roots is a command-line numerical polynomial equation solver. 4 | # Requires the GNU Scientific Library (GSL) development files. 5 | 6 | if [ -d ~/bin ] 7 | then 8 | ROOTS=~/bin/roots 9 | else 10 | ROOTS=roots 11 | fi 12 | echo Compiling roots.c 13 | gcc -O3 -Wall $CFLAGS $CPPFLAGS $LDFLAGS -o $ROOTS roots.c `pkg-config --cflags --libs gsl` && echo Done, executable installed in $ROOTS 14 | -------------------------------------------------------------------------------- /examples/fact.c: -------------------------------------------------------------------------------- 1 | 2 | #if 0 3 | #define _REENTRANT 1 /* Should be defined before including math.h for Mac OS X. */ 4 | /* Do not use with iOS. Disabled by default and unnecessary. */ 5 | #endif 6 | 7 | #include 8 | 9 | /* 10 | * General factorial function in C for double precision floating point. 11 | * Uses the threadsafe lgamma_r(3) function, if _REENTRANT is defined. 12 | * Works for any floating point value. 13 | * Recommend using tgamma(3) (true gamma) function instead, if available. 14 | * 15 | * Link with -lm 16 | * 17 | * Returns (arg!) (same as gamma(arg+1)). 18 | * Sets "errno" external variable on overflow or error. 19 | */ 20 | double 21 | factorial(double arg) 22 | { 23 | double d; 24 | 25 | #if USE_TGAMMA 26 | d = tgamma(arg + 1.0); 27 | return d; 28 | #else 29 | #if _REENTRANT 30 | int sign; 31 | 32 | d = exp(lgamma_r(arg + 1.0, &sign)); 33 | return(d * sign); 34 | #else 35 | d = exp(lgamma(arg + 1.0)) * signgam; 36 | return d; 37 | #endif 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /examples/fact.py: -------------------------------------------------------------------------------- 1 | # This is a general factorial function written in Python. 2 | # A factorial is the product of all positive integers <= a given number. 3 | # Works transparently with integers and floating point; 4 | # that is, it returns the same type as its single argument. 5 | # Gives an error for negative or non-integer input values. 6 | 7 | def factorial(x): 8 | "Return x! (x factorial)." 9 | if (x < 0 or (x % 1.0) != 0.0): 10 | raise ValueError, "Factorial argument must be a positive integer." 11 | if (x == 0): 12 | return x + 1 13 | d = x 14 | while (x > 2): 15 | x -= 1 16 | temp = d * x 17 | if (temp <= d): 18 | raise ValueError, "Factorial result too large." 19 | d = temp 20 | return d 21 | -------------------------------------------------------------------------------- /examples/factorial: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This is a Python program to display large factorials and test "fact.py". 4 | 5 | from fact import factorial 6 | import sys 7 | import os 8 | import string 9 | 10 | def usage(): 11 | print "This program calculates large factorials." 12 | print "Requires and tests \"fact.py\"." 13 | print 14 | print "Usage: %s integer_expressions" % os.path.basename(sys.argv[0]) 15 | print 16 | print "The integer expressions should be separated by spaces." 17 | print "A factorial is the product of all positive integers <= a given integer." 18 | sys.exit(2) 19 | 20 | args = sys.argv[1:] 21 | if (args == []): 22 | usage() 23 | else: 24 | try: 25 | num = eval(string.join(args)) 26 | print "factorial(", num, ") =", factorial(num) 27 | except: 28 | for arg in args: 29 | num = eval(arg) 30 | print "factorial(", num, ") =", factorial(num) 31 | -------------------------------------------------------------------------------- /examples/intfact.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Factorial function in C for positive integers. 3 | * 4 | * Return (arg!). 5 | * Returns -1 on error. 6 | */ 7 | int 8 | factorial(int arg) 9 | { 10 | int result; 11 | 12 | if (arg < 0) 13 | return -1; 14 | for (result = 1; result > 0 && arg > 1; arg--) { 15 | result *= arg; 16 | } 17 | if (result <= 0) /* return -1 on overflow */ 18 | return -1; 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /examples/limits.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Standalone program to nicely display current C data type limits and sizes. 3 | * 4 | * Copyright (C) 2008-2012 George Gesslein II 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | /* 26 | * Compile with: 27 | * 28 | * cc limits.c -o limits 29 | * 30 | * then type "./limits". 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | int 39 | main(void) 40 | { 41 | float xf = 1.0; 42 | double xd = 1.0; 43 | #ifdef LDBL_EPSILON 44 | long double xl = 1.0; 45 | #endif 46 | 47 | #ifdef __VERSION__ 48 | #ifdef __GNUC__ 49 | printf("GNU "); 50 | #endif 51 | printf("C Compiler version: %s\n\n", __VERSION__); 52 | #endif 53 | 54 | printf("C compiler integer limits:\n"); 55 | printf("--------------------------\n"); 56 | 57 | printf("CHAR_BIT: Bits of type char: %d\n", CHAR_BIT); 58 | printf("sizeof(char) = %u bytes.\n", (unsigned) sizeof(char)); 59 | printf("sizeof(char *) = %u bytes.\n", (unsigned) sizeof(char *)); 60 | 61 | if (CHAR_MIN < 0) { 62 | printf("Current type char is signed.\n"); 63 | } else { 64 | printf("Current type char is unsigned.\n"); 65 | } 66 | printf("CHAR_MAX: Maximum numeric value of type char: %d\n", CHAR_MAX); 67 | printf("CHAR_MIN: Minimum numeric value of type char: %d\n\n", CHAR_MIN); 68 | 69 | printf("SCHAR_MAX: Maximum value of type signed char: %d\n", SCHAR_MAX); 70 | printf("SCHAR_MIN: Minimum value of type signed char: %d\n\n", SCHAR_MIN); 71 | 72 | printf("UCHAR_MAX: Maximum value of type unsigned char: %u\n\n", (unsigned) UCHAR_MAX); 73 | 74 | printf("sizeof(short) = %u bytes.\n", (unsigned) sizeof(short)); 75 | printf("SHRT_MAX: Maximum value of type short: %d\n", SHRT_MAX); 76 | printf("SHRT_MIN: Minimum value of type short: %d\n\n", SHRT_MIN); 77 | 78 | printf("USHRT_MAX: Maximum value of type unsigned short: %u\n\n", (unsigned) USHRT_MAX); 79 | 80 | printf("sizeof(int) = %u bytes.\n", (unsigned) sizeof(int)); 81 | printf("INT_MAX: Maximum value of type int: %d\n", INT_MAX); 82 | printf("INT_MIN: Minimum value of type int: %d\n\n", INT_MIN); 83 | 84 | printf("UINT_MAX: Maximum value of type unsigned int: %u\n\n", UINT_MAX); 85 | 86 | printf("sizeof(long) = %u bytes.\n", (unsigned) sizeof(long)); 87 | printf("LONG_MAX: Maximum value of type long: %ld\n", LONG_MAX); 88 | printf("LONG_MIN: Minimum value of type long: %ld\n\n", LONG_MIN); 89 | 90 | printf("ULONG_MAX: Maximum value of type unsigned long: %lu\n\n", ULONG_MAX); 91 | 92 | #ifdef ULLONG_MAX 93 | printf("sizeof(long long) = %u bytes.\n", (unsigned) sizeof(long long)); 94 | printf("LLONG_MAX: Maximum value of type long long: %lld\n", LLONG_MAX); 95 | printf("LLONG_MIN: Minimum value of type long long: %lld\n\n", LLONG_MIN); 96 | 97 | printf("ULLONG_MAX: Maximum value of type unsigned long long: %llu\n\n", ULLONG_MAX); 98 | #else 99 | printf("Type \"long long\" not supported by this C compiler.\n\n"); 100 | #endif 101 | 102 | printf("\nC compiler floating point limits:\n"); 103 | printf("---------------------------------\n"); 104 | 105 | printf("sizeof(float) = %u bytes.\n", (unsigned) sizeof(float)); 106 | printf("FLT_DIG: Decimal digits of precision for float: %d\n", FLT_DIG); 107 | printf("sizeof(double) = %u bytes.\n", (unsigned) sizeof(double)); 108 | printf("DBL_DIG: Decimal digits of precision for double: %d\n", DBL_DIG); 109 | #ifdef LDBL_DIG 110 | printf("sizeof(long double) = %u bytes.\n", (unsigned) sizeof(long double)); 111 | printf("LDBL_DIG: Decimal digits of precision for long double: %d\n", LDBL_DIG); 112 | #endif 113 | 114 | printf("\nFLT_MAX: Maximum value of float: %g\n", FLT_MAX); 115 | printf("FLT_MIN: Minimum value of float: %g\n\n", FLT_MIN); 116 | 117 | printf("DBL_MAX: Maximum value of double: %g\n", DBL_MAX); 118 | printf("DBL_MIN: Minimum value of double: %g\n\n", DBL_MIN); 119 | 120 | #ifdef LDBL_MAX 121 | printf("LDBL_MAX: Maximum value of long double: %Lg\n", LDBL_MAX); 122 | printf("LDBL_MIN: Minimum value of long double: %Lg\n\n", LDBL_MIN); 123 | #else 124 | printf("Type \"long double\" not supported by this C compiler.\n\n"); 125 | #endif 126 | 127 | printf("Epsilon is the smallest x such that 1.0 + x != 1.0\n"); 128 | printf("FLT_EPSILON: Float epsilon: %g", FLT_EPSILON); 129 | xf += (FLT_EPSILON / 2.0); 130 | if (xf == 1.0) { 131 | xf += FLT_EPSILON; 132 | if (xf > 1.0) { 133 | printf(" verified."); 134 | } 135 | } 136 | printf("\n"); 137 | printf("DBL_EPSILON: Double epsilon: %g", DBL_EPSILON); 138 | xd += (DBL_EPSILON / 2.0); 139 | if (xd == 1.0) { 140 | xd += DBL_EPSILON; 141 | if (xd > 1.0) { 142 | printf(" verified."); 143 | } 144 | } 145 | printf("\n"); 146 | #ifdef LDBL_EPSILON 147 | printf("LDBL_EPSILON: Long double epsilon: %Lg", LDBL_EPSILON); 148 | xl += (LDBL_EPSILON / 2.0); 149 | if (xl == 1.0) { 150 | xl += LDBL_EPSILON; 151 | if (xl > 1.0) { 152 | printf(" verified."); 153 | } 154 | } 155 | printf("\n"); 156 | #endif 157 | 158 | printf("\nEnd of limits program output.\n"); 159 | 160 | return 0; 161 | } 162 | -------------------------------------------------------------------------------- /examples/roots.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Command-line numerical polynomial equation solver using the GNU Scientific Library (GSL). 3 | * GSL is available from: "http://www.gnu.org/software/gsl/". 4 | * 5 | * Copyright (C) 2008-2011 George Gesslein II 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | 21 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 22 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 23 | 24 | */ 25 | 26 | /* 27 | * To compile: 28 | 29 | ./compile.roots 30 | 31 | * or 32 | 33 | gcc -O3 -Wall -o roots roots.c -lgsl -lgslcblas 34 | 35 | * This program nicely solves any degree polynomial 36 | * with real coefficients by calling the 37 | * GSL function gsl_poly_complex_solve(). 38 | * This file is also useful for testing 39 | * and as an example of using the GSL from C. 40 | * The results are double precision floating point values 41 | * that are sometimes accurate to 14 digits. 42 | * Complex numbers are output if successful. 43 | * Here is an example of it solving a cubic polynomial: 44 | 45 | $ roots 1 1 1 1 46 | The 3 approximate floating point solutions of: 47 | +x^3 +x^2 +x +1 = 0 48 | are: 49 | 50 | x = +0 +1*i 51 | x = +0 -1*i 52 | x = -1 53 | $ 54 | 55 | Try this for a large amount of error: 56 | roots -1 -1 1 1 57 | 58 | Proof the GSL isn't perfect. 59 | 60 | */ 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | #define EPSILON 0.00000000000005 /* a good value for doubles */ 72 | #define HELP 1 /* display helpful text */ 73 | 74 | void display_root(int i); 75 | 76 | char *prog_name = "roots"; /* name of this program */ 77 | double *a, *z; /* input and output arrays, respectively */ 78 | int precision = DBL_DIG - 1; /* display precision, it is not useful to set this higher than 15 */ 79 | 80 | void 81 | usage(void) 82 | { 83 | printf("\n%s version 1.0 - numerical polynomial equation solver\n", prog_name); 84 | printf("Uses the GNU Scientific Library (GSL).\n"); 85 | printf("\nSolves polynomial = 0 when given all real coefficients of the polynomial.\n"); 86 | printf("Double precision floating point math is used, accurate to about 14 digits.\n"); 87 | printf("\nUsage: %s highest-power-coefficient ... constant-term\n", prog_name); 88 | printf("\nThe coefficients must be decimal, floating point, real numbers.\n"); 89 | printf("For example, if 4 real numbers are given, there will be 3 complex number\n"); 90 | printf("results or \"roots\" that are all valid solutions to polynomial = 0.\n"); 91 | } 92 | 93 | int 94 | main(int argc, char **argv) 95 | { 96 | int i, highest_power; 97 | char *cp, *arg; 98 | gsl_poly_complex_workspace *w; 99 | 100 | if (argc <= 1) { 101 | fprintf(stderr, "%s: The polynomial coefficients must be specified on the command line.\n", prog_name); 102 | usage(); 103 | exit(2); 104 | } 105 | 106 | highest_power = argc - 2; 107 | a = calloc(highest_power + 1, sizeof(double)); /* allocate real double input array */ 108 | z = calloc(2 * highest_power, sizeof(double)); /* allocate complex double output array */ 109 | 110 | /* parse the command line into the coefficient array a[] */ 111 | for (i = 0; i < argc - 1; i++) { 112 | arg = argv[argc-i-1]; 113 | errno = 0; 114 | a[i] = strtod(arg, &cp); 115 | if (arg == cp || *cp) { 116 | fprintf(stderr, "%s: Argument \"%s\" is not a floating point number.\n", prog_name, arg); 117 | usage(); 118 | exit(2); 119 | } 120 | if (errno) { 121 | fprintf(stderr, "%s: Argument \"%s\" is out of range.\n", prog_name, arg); 122 | exit(2); 123 | } 124 | } 125 | 126 | #if HELP 127 | /* nicely display the actual polynomial equation we are solving */ 128 | printf("The %d approximate floating point solutions of:\n", highest_power); 129 | for (i = highest_power; i >= 0; i--) { 130 | if (a[i]) { 131 | if (i && a[i] == 1.0) { 132 | printf("+x"); 133 | } else { 134 | printf("%+.*g", precision, a[i]); 135 | if (i) { 136 | printf("*x"); 137 | } 138 | } 139 | if (i > 1) { 140 | printf("^%d", i); 141 | } 142 | printf(" "); 143 | } 144 | } 145 | printf("= 0\nare:\n\n"); 146 | #endif 147 | 148 | /* solve the polynomial equation */ 149 | w = gsl_poly_complex_workspace_alloc(highest_power + 1); 150 | if (gsl_poly_complex_solve(a, highest_power + 1, w, z) != GSL_SUCCESS) { 151 | fprintf(stderr, "%s: GSL approximation failed.\n", prog_name); 152 | exit(1); 153 | } 154 | gsl_poly_complex_workspace_free(w); 155 | 156 | /* display all solutions */ 157 | for (i = 0; i < highest_power; i++) { 158 | #ifdef EPSILON /* zero out relatively very small values (which are floating point error) */ 159 | if (fabs(z[2*i] * EPSILON) > fabs(z[2*i+1])) 160 | z[2*i+1] = 0.0; 161 | else if (fabs(z[2*i+1] * EPSILON) > fabs(z[2*i])) 162 | z[2*i] = 0.0; 163 | #endif 164 | #if HELP 165 | printf("x = "); 166 | #endif 167 | display_root(i); 168 | printf("\n"); 169 | } 170 | 171 | exit(0); 172 | } 173 | 174 | void 175 | display_root(int i) 176 | { 177 | printf("%+.*g", precision, z[2*i]); /* output real part */ 178 | if (z[2*i+1]) 179 | printf(" %+.*g*i", precision, z[2*i+1]); /* output imaginary part */ 180 | } 181 | -------------------------------------------------------------------------------- /examples/testprimes: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test matho-primes by comparing output with the BSD Games primes utility. 3 | # Only run this if matho-primes and the bsdgames package are installed. 4 | # The comparison is performed in parallel, to save time. 5 | # The whole test takes 30 seconds on a fast, dual-core computer. 6 | # 7 | # Checks the first 50,000,000 primes for gaps or errors. 8 | # It simply compares their output up to 1,000,000,000. 9 | # 10 | # Usage: testprimes [ primes_utility_name ] 11 | 12 | echo Testing matho-primes by comparing output with bsdgames primes... 13 | if ! matho-primes 0 0 14 | then 15 | echo Mathomatic Prime Number Tools not installed. 16 | echo Cannot find matho-primes 17 | exit 1 18 | fi 19 | 20 | PRIMES=${1-primes} 21 | if ! $PRIMES 0 0 22 | then 23 | PRIMES=/usr/games/primes 24 | if $PRIMES 0 0 25 | then 26 | echo Using $PRIMES 27 | else 28 | echo bsdgames package not installed. 29 | echo Cannot find primes utility. 30 | exit 1 31 | fi 32 | fi 33 | 34 | TESTOUT1=`mktemp /tmp/test.XXXXXXXXXX` || exit 1 35 | TESTOUT2=`mktemp /tmp/test.XXXXXXXXXX` || exit 1 36 | echo Starting and timing matho-primes 37 | time -p matho-primes 1 1000000000 >$TESTOUT1 & 38 | echo Starting $PRIMES 39 | $PRIMES 1 1000000000 >$TESTOUT2 && echo -n Word count: && wc $TESTOUT2 & 40 | wait 41 | echo Output files to compare, 42 | echo matho-primes output: 43 | ls -l $TESTOUT1 44 | echo primes output: 45 | ls -l $TESTOUT2 46 | echo Comparing: 47 | diff -uq --strip-trailing-cr $TESTOUT1 $TESTOUT2 && echo Files are identical. && echo "Test passed 100% correctly." && rm $TESTOUT1 $TESTOUT2 && exit 0 48 | echo 49 | echo Test failed. 50 | rm -f $TESTOUT1 $TESTOUT2 51 | exit 1 52 | -------------------------------------------------------------------------------- /externs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mathomatic global variable extern definitions, from file "globals.c". 3 | * 4 | * Copyright (C) 1987-2012 George Gesslein II. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | extern int n_tokens; 26 | extern int n_equations; 27 | extern int cur_equation; 28 | 29 | extern token_type *lhs[N_EQUATIONS]; 30 | extern token_type *rhs[N_EQUATIONS]; 31 | 32 | extern int n_lhs[N_EQUATIONS]; 33 | extern int n_rhs[N_EQUATIONS]; 34 | 35 | extern token_type *tlhs; 36 | extern token_type *trhs; 37 | extern token_type *tes; 38 | 39 | extern int n_tlhs; 40 | extern int n_trhs; 41 | extern int n_tes; 42 | 43 | extern token_type *scratch; 44 | 45 | extern token_type zero_token; 46 | extern token_type one_token; 47 | 48 | extern int precision; 49 | extern int case_sensitive_flag; 50 | extern int factor_int_flag; 51 | extern int display2d; 52 | extern int fractions_display; 53 | extern int approximate_roots; 54 | extern int preserve_surds; 55 | extern int rationalize_denominators; 56 | extern int modulus_mode; 57 | extern volatile int screen_columns; 58 | extern volatile int screen_rows; 59 | extern int finance_option; 60 | extern int autosolve; 61 | extern int autocalc; 62 | extern int autodelete; 63 | extern int autoselect; 64 | extern char special_variable_characters[256]; 65 | extern char plot_prefix[256]; 66 | extern int factor_out_all_numeric_gcds; 67 | extern int right_associative_power; 68 | extern int power_starstar; 69 | #if !SILENT 70 | extern int debug_level; 71 | #endif 72 | extern int domain_check; 73 | extern int color_flag; 74 | extern int bold_colors; 75 | extern int text_color; 76 | extern int cur_color; 77 | extern int html_flag; 78 | extern int readline_enabled; 79 | extern int partial_flag; 80 | extern int symb_flag; 81 | extern int symblify; 82 | extern int high_prec; 83 | extern int input_column; 84 | extern int sign_cmp_flag; 85 | extern double small_epsilon; 86 | extern double epsilon; 87 | 88 | extern char *prog_name; 89 | extern char *var_names[MAX_VAR_NAMES]; 90 | extern char var_str[MAX_VAR_LEN+80]; 91 | extern char prompt_str[MAX_PROMPT_LEN]; 92 | #if !SECURE 93 | extern char rc_file[MAX_CMD_LEN]; 94 | #endif 95 | 96 | #if CYGWIN || MINGW 97 | extern char *dir_path; 98 | #endif 99 | #if READLINE || EDITLINE 100 | extern char *last_history_string; 101 | #endif 102 | #if READLINE 103 | extern char *history_filename; 104 | extern char history_filename_storage[MAX_CMD_LEN]; 105 | #endif 106 | 107 | extern double unique[]; 108 | extern int ucnt[]; 109 | extern int uno; 110 | 111 | extern int previous_return_value; 112 | extern sign_array_type sign_array; 113 | extern FILE *default_out; 114 | extern FILE *gfp; 115 | extern char *gfp_filename; 116 | extern int gfp_append_flag; 117 | extern jmp_buf jmp_save; 118 | extern int eoption; 119 | extern int test_mode; 120 | extern int demo_mode; 121 | extern int quiet_mode; 122 | extern int echo_input; 123 | extern volatile int abort_flag; 124 | extern int pull_number; 125 | extern int security_level; 126 | extern int repeat_flag; 127 | extern int show_usage; 128 | extern int point_flag; 129 | 130 | extern char *result_str; 131 | extern int result_en; 132 | extern const char *error_str; 133 | extern const char *warning_str; 134 | 135 | extern char *vscreen[TEXT_ROWS]; 136 | extern int current_columns; 137 | -------------------------------------------------------------------------------- /icons/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Mathomatic icons for your desktop go here. 3 | 4 | icon.rc - Windows resource compiler file used to link icon with .exe file 5 | mathomatic.desktop - Unix and Linux desktop entry 6 | mathomatic.icns - Mathomatic icons for Mac OS X 7 | mathomatic.ico - 32x32 and 64x64 pixels icons for Microsoft Windows 8 | mathomatic.png - generic 64x64 Mathomatic icon 9 | mathomatic.svg - The new resizeable Mathomatic logo and icon 10 | mathomatic.xpm - X-Windows pixmap 32x32 Mathomatic icon 11 | mathomatic32x32.png - generic 32x32 Mathomatic icon 12 | 13 | These icons/logos are free to use for anything Mathomatic related. 14 | -------------------------------------------------------------------------------- /icons/icon.rc: -------------------------------------------------------------------------------- 1 | /* 2 | * icon.rc - Windows resource compiler input file used to link 3 | * the Mathomatic icon with the mathomatic.exe file. 4 | * 5 | * To compile, run: 6 | * 7 | * windres icon.rc icon.o 8 | * 9 | * then link mathomatic.exe with icon.o, 10 | * so that mathomatic.exe will have an nice icon in Windows Explorer! 11 | */ 12 | icon1 ICON "mathomatic.ico" 13 | -------------------------------------------------------------------------------- /icons/mathomatic.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Mathomatic 3 | GenericName=Computer Algebra System 4 | Comment=Do symbolic mathematics and quick calculations 5 | Exec=mathomatic 6 | Icon=mathomatic 7 | Terminal=true 8 | Type=Application 9 | Categories=Education;Science;Math; 10 | StartupNotify=false 11 | -------------------------------------------------------------------------------- /icons/mathomatic.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/icons/mathomatic.icns -------------------------------------------------------------------------------- /icons/mathomatic.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/icons/mathomatic.ico -------------------------------------------------------------------------------- /icons/mathomatic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/icons/mathomatic.png -------------------------------------------------------------------------------- /icons/mathomatic.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *mathomatic[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "32 32 4 1", 5 | " c #000000", 6 | ". c #FFFF00", 7 | "X c #0000BF", 8 | "o c None", 9 | /* pixels */ 10 | "o oo", 11 | " o", 12 | " ....XX...XXXXX.....XX...X o", 13 | " ......XXX.XXXXX..XX..XXX.XX o", 14 | " ..XX..X...XXXXX..XX..X...XX o", 15 | " ..XX..X.XXXXXXX..XX..X.XXXX o", 16 | " ......X...X.XXX.....XX...XX o", 17 | " ......XXXXX.XXX..XX..XXXXXX o", 18 | " ..XX..XXX.....X..XX..XXXXXX o", 19 | " ..XX..XXXXX.XXX..XX..XXXXXX o", 20 | " ..XX..XXXXX.XXX.....XXXXXXX o", 21 | " XXXXXXXXXXXXXXXXXXXXXXXXXXX o", 22 | " XXXXXXXXXXXXXXXXXXXXXXXX... o", 23 | " XXXXXXXXXXXXXXXXXX.....XXX. o", 24 | " XXXXXXXXXXXXXXXXXX.....X... o", 25 | " XXXXXXXXXXXXXXXXXX..XXXX.XX o", 26 | " XXXXXXXXXX......XX..XXXX... o", 27 | " XXXXXXXXXXXXXXXXXX..XXXXXXX o", 28 | " XXXXXXXXXX......XX..XXXXXXX o", 29 | " XXXXXXXXXXXXXXXXXX..XXXXXXX o", 30 | " XXXXXXXXXXXXXXXXXX.....XXXX o", 31 | " XXXXXXXXXXXXXXXXXX.....XXXX o", 32 | " XXXXXXXXXXXXXXXXXXXXXXXXX o", 33 | " o", 34 | "o oo", 35 | "oooooooooooooo ooooooooooooooo", 36 | "oooooooooooooo ooooooooooooooo", 37 | "ooooooooooooo oooooooooooooo", 38 | "ooooooooooooo oooooooooooooo", 39 | "ooooooooooo oooooooooooo", 40 | "ooooooo oooooooo", 41 | "ooo oooo" 42 | }; 43 | -------------------------------------------------------------------------------- /icons/mathomatic32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfillpot/mathomatic/6eb4cc1674c2aa30a514e850aa0663b7bbc060de/icons/mathomatic32x32.png -------------------------------------------------------------------------------- /includes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Standard C include files for Mathomatic. 3 | * Automatically includes all necessary C include files for 4 | * any Mathomatic C source code. 5 | * 6 | * Copyright (C) 1987-2012 George Gesslein II. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 23 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 24 | 25 | */ 26 | 27 | #define true 1 28 | #define false 0 29 | 30 | #if 0 31 | #define _REENTRANT 1 /* Can be defined before including math.h for Mac OS X. Mac OS X allows a few re-entrant functions with this. iOS requires this commented out. */ 32 | #endif 33 | 34 | #if ROBOT_COMMAND 35 | #define NOT80COLUMNS 1 /* For programs that use less than 80 columns wide display. */ 36 | #endif 37 | 38 | #ifndef HELP 39 | #define HELP 1 /* Define HELP=0 to remove the help command. Shaves at least 10 kilobytes off of the executable. */ 40 | #endif 41 | 42 | #if LIBRARY /* If compiling this Mathomatic code as the symbolic math library: */ 43 | #ifndef SILENT /* Define SILENT=0 to have debugging enabled with the symbolic math library. */ 44 | #define SILENT 1 /* Disable debug level setting and stop messages going to stdout. */ 45 | #endif 46 | #undef READLINE /* Readline shouldn't be included in the library code. */ 47 | #undef EDITLINE /* Editline neither */ 48 | #endif 49 | 50 | #if __CYGWIN__ && !CYGWIN 51 | #warning Compiling under Cygwin without proper defines. 52 | #warning Please define CYGWIN on the compiler command line with -DCYGWIN 53 | #define CYGWIN 1 54 | #endif 55 | 56 | #if CYGWIN || MINGW 57 | #undef UNIX /* Unix desktop functionality is slightly different for CYGWIN and MINGW */ 58 | #endif 59 | 60 | #if (UNIX || CYGWIN || MINGW) && !SECURE && !LIBRARY 61 | #define SHELL_OUT 1 /* include the code to shell out (run system(3) commmand) */ 62 | #endif 63 | 64 | #if SECURE && SHELL_OUT 65 | #warning SHELL_OUT defined during secure mode compilation. This is a security problem. 66 | #endif 67 | 68 | /* Include files from /usr/include: */ 69 | #include 70 | #include 71 | #include 72 | 73 | #if UNIX 74 | #include 75 | #endif 76 | 77 | #if sun 78 | #include 79 | #endif 80 | 81 | #if SHOW_RESOURCES 82 | #include 83 | #include 84 | #endif 85 | 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | #include 94 | 95 | #if I18N /* Internationalization doesn't work yet. It would need a translation and some work on the code and makefile. */ 96 | #include /* Mac OS X doesn't have libintl.h, so define "char *gettext();" then. */ 97 | #include 98 | #endif 99 | 100 | #if READLINE 101 | #if 0 /* The following two includes only needed if explicitly calling ncurses functions. */ 102 | #include 103 | #include 104 | #endif 105 | #include 106 | #include 107 | #endif 108 | #if EDITLINE /* Editline is a stripped down version of readline. */ 109 | #include 110 | #endif 111 | 112 | /* Include files from the current directory: */ 113 | #include "standard.h" /* a standard include file for any math program written in C */ 114 | #include "am.h" /* the main include file for Mathomatic, contains tunable parameters */ 115 | #include "complex.h" /* floating point complex number arithmetic function prototypes */ 116 | #include "proto.h" /* global function prototypes, made with cproto utility */ 117 | #include "altproto.h" /* backup global function prototypes, in case of no proto.h */ 118 | #include "externs.h" /* global variable extern definitions */ 119 | #include "blt.h" /* blt() function definition */ 120 | -------------------------------------------------------------------------------- /lib/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Mathomatic Symbolic Math Library 3 | -------------------------------- 4 | 5 | This directory contains the API (Application Programming Interface) "lib.c" 6 | and test/example programs "testmain.c" and "example.c" for the Mathomatic 7 | symbolic math library. The API can be used to link your C compatible programs 8 | with the Mathomatic symbolic math engine. This simple API provides for 9 | passing C text strings containing expressions and commands to the Mathomatic 10 | engine. If successful, a text string containing the resulting expression is 11 | returned, otherwise an error message is returned. 12 | 13 | Mathomatic is released under the GNU Lesser General Public License, so that 14 | even closed-source software can make use of it. 15 | 16 | This symbolic math library is at least able to be run anywhere the main 17 | Mathomatic application can be run, and does not require an operating system 18 | beyond the ability to allocate memory with malloc(3). The symbolic math 19 | library is not re-entrant, meaning it cannot successfully be called again 20 | until the last call to it completes. This is due to the fact that most data 21 | storage areas in Mathomatic are global and static. I think that also means 22 | Mathomatic is not threadsafe, correct me if I am wrong. 23 | 24 | If you are trying to use this library as a plotting engine, please don't. 25 | Every numerical calculation requires a memory move of half of the entire 26 | expression for each and every number in it, to simplify a numerical 27 | expression in Mathomatic. This will make 3D plots impossible and 2D plots 28 | very slow. You need a library that parses to an expression tree and evaluates 29 | that. Package "libmatheval1" will do this for you. It is available at 30 | 31 | http://www.gnu.org/software/libmatheval/ 32 | 33 | and is free software that is currently maintained as of 2011. 34 | 35 | To compile the Mathomatic symbolic math library and its test program, type 36 | "make" while in this "lib" directory. This will create the static library 37 | "libmathomatic.a" and the API test executable named "testmain". To run the 38 | test executable, type "./testmain". 39 | 40 | To do a system install of the development library "libmathomatic.a" and C 41 | header file "mathomatic.h", type: 42 | 43 | make flush 44 | make 45 | sudo make install 46 | 47 | and enter your password. There are no tests, because the library uses the 48 | same code as the Mathomatic application. If the application passes all tests, 49 | the library should work too. "testmain" will successfully "read" in most of 50 | the standard tests with the read command, until it encounters a calculate 51 | command, which doesn't exist in the library, causing the read to terminate. 52 | 53 | Just include the file "mathomatic.h" and call the functions in "lib.c" to use 54 | this library. Link your program with "libmathomatic.a" by using "-lmathomatic 55 | -lm" at the end of the ld linker command line. "libmathomatic.a" is not 56 | required on the target system, since it is a static library, meaning it is 57 | included in the resulting executable as needed. 58 | 59 | The following code provides a quick test of this library: 60 | 61 | char *output; 62 | matho_init(); 63 | matho_parse("x^2=4", NULL); 64 | matho_process("solve x", &output); 65 | printf("%s\n", output); 66 | 67 | Remember to free(output) on each successful call to matho_process() and 68 | matho_parse() to return the memory used by the output string when you are 69 | finished using it, otherwise there will be a memory leak. Here is the above 70 | code fixed properly so it doesn't leak: 71 | 72 | char *output; 73 | int rv; 74 | if (!matho_init()) { 75 | printf("Not enough memory.\n"); 76 | exit(1); 77 | } 78 | matho_parse("x^2=4", NULL); 79 | rv = matho_process("solve x", &output); 80 | if (output) { 81 | printf("%s\n", output); 82 | if (rv) { 83 | free(output); 84 | } else { 85 | printf("Error return.\n"); 86 | } 87 | } 88 | 89 | The above code is in the file "example.c" and the result of running the above 90 | code when linked with the Mathomatic library should be: 91 | 92 | x = 2*sign 93 | 94 | The following Mathomatic commands are omitted in this library: calculate, 95 | edit, plot, push, quit, and tally. To make up for the lack of the calculate 96 | command, the replace, approximate, and "simplify sign" commands are provided, 97 | allowing very similar functionality. 98 | 99 | This paragraph is old information, you can now specify the integrate bounds 100 | on the command-line. Recently, the "nintegrate" and "integrate definite" 101 | commands are allowed; the bounds of integration are specified in the two 102 | equation spaces following the current equation. cur_equation+1 is the lower 103 | bound, and cur_equation+2 is the upper bound. Of course, the integrate and 104 | nintegrate commands operate on the current equation, specified by the global 105 | "cur_equation" variable (origin 0). The equation number displayed is always 106 | origin 1, making it 1 greater than "cur_equation", so keep that in mind. 107 | 108 | Please define the C preprocessor name HANDHELD=1 when compiling this library 109 | for handheld computing devices like the iPhone and other small computing 110 | devices, for reduced memory usage. For embedded devices with no file storage, 111 | or for privacy or no wish to use file storage, define SECURE=1 too. 112 | 113 | Please read the file "../README.txt" for more developer information. These 114 | files were written by George Gesslein II of www.mathomatic.org 115 | -------------------------------------------------------------------------------- /lib/compile.testmain: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script for creating the Mathomatic library test and example programs "testmain" and "example". 3 | # testmain.c and example.c are compiled and linked with 4 | # /usr/local/lib/libmathomatic.a or /usr/lib/libmathomatic.a 5 | # 6 | # If this fails, you probably need to compile and install the Mathomatic symbolic math library, 7 | # by downloading the Mathomatic source code, then: 8 | # 9 | # cd lib 10 | # make flush 11 | # make lib 12 | # sudo make install 13 | 14 | CC=${CC-cc} 15 | 16 | echo Compiling and linking testmain.c with currently installed libmathomatic.a 17 | set -x 18 | $CC -g -O3 -Wall -Wshadow -fexceptions $CFLAGS $CPPFLAGS $LDFLAGS testmain.c -lmathomatic -lm -o testmain && echo ./testmain created. 19 | echo Compiling and linking example.c, too. 20 | $CC -g -O3 -Wall -Wshadow -fexceptions $CFLAGS $CPPFLAGS $LDFLAGS example.c -lmathomatic -lm -o example && echo ./example created. 21 | make clean # for any subsequent makes 22 | -------------------------------------------------------------------------------- /lib/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Real quick and dirty example of usage of the Mathomatic Symbolic Math Library. 3 | * Designed to be as simple as possible, yet work. 4 | * Just displays: "x = 2*sign". 5 | */ 6 | #include 7 | #include 8 | #include "mathomatic.h" 9 | 10 | int 11 | main() 12 | { 13 | #if WANT_LEAKS /* Causes memory leaks, wrong code to use, but will work in a pinch. */ 14 | char *output; 15 | 16 | matho_init(); 17 | matho_parse("x^2=4", NULL); 18 | matho_process("solve x", &output); 19 | printf("%s\n", output); 20 | #else /* right code to use */ 21 | char *output; 22 | int rv; 23 | 24 | if (!matho_init()) { 25 | printf("Not enough memory.\n"); 26 | exit(1); 27 | } 28 | matho_parse((char *) "x^2=4", NULL); 29 | rv = matho_process((char *) "solve x", &output); 30 | if (output) { 31 | printf("%s\n", output); 32 | if (rv) { 33 | free(output); 34 | } else { 35 | printf("Error return.\n"); 36 | } 37 | } 38 | #endif 39 | 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /lib/makefile: -------------------------------------------------------------------------------- 1 | # Makefile for the Mathomatic symbolic math library and its test program. 2 | # See file README.txt for instructions. 3 | 4 | SHELL = /bin/sh # from http://www.gnu.org/prep/standards/ 5 | CC ?= gcc # C compiler to use 6 | INSTALL ?= install # installer to use 7 | INSTALL_PROGRAM ?= $(INSTALL) # command to install executable program files 8 | INSTALL_DATA ?= $(INSTALL) -m 0644 # command to install data files 9 | 10 | VERSION = `cat ../VERSION` 11 | OPTFLAGS ?= -g -O3 -Wall -Wshadow -Wno-char-subscripts -Wno-unused-variable # gcc specific flags; can be removed 12 | CFLAGS ?= $(OPTFLAGS) 13 | CFLAGS += -fexceptions -DLIBRARY -DVERSION=\"$(VERSION)\" # necessary C compiler flags 14 | LDLIBS += -lm # system libraries to link 15 | 16 | # Install directories follow; installs everything in $(DESTDIR)/usr/local by default. 17 | prefix ?= /usr/local 18 | mandir ?= $(prefix)/share/man 19 | libdir ?= $(prefix)/lib 20 | includedir ?= $(prefix)/include 21 | 22 | AOUT = testmain # The name of the library test executable file to create. 23 | LIB = libmathomatic.a # The name of the symbolic math library file to create. 24 | HEADERS = mathomatic.h 25 | 26 | MATHOMATIC_OBJECTS += globals.o am.o solve.o help.o parse.o cmds.o simplify.o \ 27 | factor.o super.o unfactor.o poly.o diff.o integrate.o \ 28 | complex.o complex_lib.o list.o gcd.o factor_int.o 29 | 30 | # man pages to automatically make and install: 31 | MAN3 = matho_init.3 matho_clear.3 matho_parse.3 matho_process.3 32 | 33 | .PHONY: all install uninstall clean distclean maintainer-clean flush lib manpages 34 | 35 | all: lib $(AOUT) 36 | 37 | lib: $(LIB) $(MAN3) 38 | 39 | $(LIB): lib.o $(MATHOMATIC_OBJECTS) 40 | $(AR) cr $(LIB) $+ 41 | -ranlib $(LIB) 42 | @echo 43 | @echo Symbolic math library $(LIB) created. 44 | @echo 45 | 46 | lib.o $(MATHOMATIC_OBJECTS): $(HEADERS) ../includes.h ../license.h ../standard.h ../am.h ../externs.h ../blt.h ../complex.h ../proto.h ../altproto.h ../VERSION 47 | 48 | $(MATHOMATIC_OBJECTS): %.o: ../%.c 49 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ 50 | 51 | $(AOUT): testmain.o $(LIB) 52 | $(CC) $(CFLAGS) $(LDFLAGS) $+ $(LDLIBS) -o $(AOUT) 53 | @echo 54 | @echo ./$(AOUT) created. 55 | 56 | example: example.o $(LIB) 57 | $(CC) $(CFLAGS) $(LDFLAGS) $+ $(LDLIBS) -o example 58 | @echo 59 | @echo ./example created. 60 | 61 | # Generate the library man pages, if not already made. 62 | # Requires the very latest version of txt2man. 63 | manpages $(MAN3): lib.c 64 | src2man -r "Mathomatic" -v "Symbolic Math Library" $+ 65 | 66 | install: 67 | $(INSTALL) -d $(DESTDIR)$(libdir) 68 | $(INSTALL) -d $(DESTDIR)$(includedir) 69 | $(INSTALL) -d $(DESTDIR)$(mandir)/man3 70 | $(INSTALL_DATA) $(LIB) $(DESTDIR)$(libdir) 71 | $(INSTALL_DATA) $(HEADERS) $(DESTDIR)$(includedir) 72 | $(INSTALL_DATA) $(MAN3) $(DESTDIR)$(mandir)/man3 73 | @echo 74 | @echo Mathomatic Symbolic Math Library installed. 75 | 76 | uninstall: 77 | cd $(DESTDIR)$(mandir)/man3 && rm -f $(MAN3) 78 | cd $(DESTDIR)$(includedir) && rm -f $(HEADERS) 79 | rm -f $(DESTDIR)$(libdir)/$(LIB) 80 | @echo 81 | @echo Symbolic Math Library uninstall completed. 82 | 83 | clean: 84 | rm -f *.o 85 | 86 | distclean flush: clean 87 | rm -f $(AOUT) example 88 | rm -f *.a 89 | rm -f *.exe 90 | 91 | maintainer-clean: distclean 92 | rm -f $(MAN3) 93 | -------------------------------------------------------------------------------- /lib/matho_clear.3: -------------------------------------------------------------------------------- 1 | .\" Extracted by src2man from lib.c 2 | .\" Text automatically generated by txt2man 3 | .TH matho_clear 3 "15 October 2012" "Mathomatic" "Symbolic Math Library" 4 | .SH NAME 5 | \fBmatho_clear \fP- Erase all equation spaces so they can be reused 6 | .SH SYNOPSIS 7 | .nf 8 | .fam C 9 | \fIvoid\fP \fBmatho_clear\fP(\fIvoid\fP); 10 | .fam T 11 | .fi 12 | .fam T 13 | .fi 14 | .SH DESCRIPTION 15 | Mathomatic only has a limited number of equation spaces. 16 | Similar to a restart, recommended after each group of symbolic math operations. 17 | Currently this is the same as entering the command "clear all". 18 | .PP 19 | \fBmatho_init\fP(3) must have been called only one time before this 20 | to initialize the Mathomatic symbolic math engine. 21 | .SH FILE 22 | lib.c 23 | -------------------------------------------------------------------------------- /lib/matho_init.3: -------------------------------------------------------------------------------- 1 | .\" Extracted by src2man from lib.c 2 | .\" Text automatically generated by txt2man 3 | .TH matho_init 3 "15 October 2012" "Mathomatic" "Symbolic Math Library" 4 | .SH NAME 5 | \fBmatho_init \fP- Initialize the Mathomatic symbolic math library 6 | .SH SYNOPSIS 7 | .nf 8 | .fam C 9 | int \fBmatho_init\fP(\fIvoid\fP); 10 | .fam T 11 | .fi 12 | .fam T 13 | .fi 14 | .SH DESCRIPTION 15 | Call this only once before calling any Mathomatic code. 16 | This must be called exactly once upon program startup and not again, 17 | unless \fBfree_mem\fP() is called. 18 | .PP 19 | Returns true if successful. 20 | If this returns false, there was not enough memory available 21 | and Mathomatic cannot be used. 22 | .SH FILE 23 | lib.c 24 | -------------------------------------------------------------------------------- /lib/matho_parse.3: -------------------------------------------------------------------------------- 1 | .\" Extracted by src2man from lib.c 2 | .\" Text automatically generated by txt2man 3 | .TH matho_parse 3 "15 October 2012" "Mathomatic" "Symbolic Math Library" 4 | .SH NAME 5 | \fBmatho_parse \fP- Process Mathomatic expression or equation input 6 | .SH SYNOPSIS 7 | .nf 8 | .fam C 9 | int \fBmatho_parse\fP(char *\fIinput\fP, char **\fIoutputp\fP); 10 | .fam T 11 | .fi 12 | .fam T 13 | .fi 14 | .SH DESCRIPTION 15 | Parse a mathematical equation or expression and store in the next available equation space, 16 | making it the current equation. 17 | Afterwards, it can be operated on by Mathomatic commands using \fBmatho_process\fP(3). 18 | .PP 19 | \fBmatho_init\fP(3) must have been called only one time before this 20 | to initialize the Mathomatic symbolic math engine. 21 | Use \fBmatho_clear\fP(3) as many times as you want to restart Mathomatic 22 | for the next group of operations. 23 | .PP 24 | The \fIinput\fP and output ASCII strings are expressions, if successful. 25 | The expression or equation string to enter is in "\fIinput\fP", 26 | the resulting output string is stored in "*\fIoutputp\fP". 27 | The equation number of the equation space that the output expression 28 | is additionally stored in (if any) is available in the global "result_en", 29 | otherwise result_en = \fB-1\fP. 30 | .PP 31 | Works the same as \fBmatho_process\fP(3), except commands are not allowed, 32 | so that variables are not ever confused with commands. 33 | In fact, this function is currently set to only allow 34 | entry and storage of expressions and equations. 35 | .PP 36 | Returns true (non-zero) if successful. 37 | .SH FILE 38 | lib.c 39 | -------------------------------------------------------------------------------- /lib/matho_process.3: -------------------------------------------------------------------------------- 1 | .\" Extracted by src2man from lib.c 2 | .\" Text automatically generated by txt2man 3 | .TH matho_process 3 "15 October 2012" "Mathomatic" "Symbolic Math Library" 4 | .SH NAME 5 | \fBmatho_process \fP- Process Mathomatic command or expression input 6 | .SH SYNOPSIS 7 | .nf 8 | .fam C 9 | int \fBmatho_process\fP(char *\fIinput\fP, char **\fIoutputp\fP); 10 | .fam T 11 | .fi 12 | .fam T 13 | .fi 14 | .SH DESCRIPTION 15 | Process a Mathomatic command or enter an expression into an equation space. 16 | The command or expression ASCII string is given as "\fIinput\fP", 17 | the resulting output string is stored in "*\fIoutputp\fP". 18 | .PP 19 | \fBmatho_init\fP(3) must have been called only one time before this 20 | to initialize the Mathomatic symbolic math engine. 21 | Use \fBmatho_clear\fP(3) as many times as you want to restart Mathomatic 22 | for the next group of operations. 23 | .PP 24 | This function works just like typing something into the Mathomatic prompt. 25 | To only parse any expression or equation and store it, use \fBmatho-parse\fP(3). 26 | .PP 27 | If this returns true (non-zero), the command or \fIinput\fP was successful, 28 | and the resulting expression output string is stored in "*\fIoutputp\fP". 29 | That is a \fBmalloc\fP()ed text string which must be \fBfree\fP()d after use 30 | to return the memory used by the string. 31 | The equation number of the equation space that the output expression 32 | is additionally stored in (if any) is available in the global "result_en", 33 | otherwise result_en = \fB-1\fP. 34 | .PP 35 | If this returns false, the command or \fIinput\fP failed and a text error 36 | message is always stored in "*\fIoutputp\fP". 37 | The error message is a constant string and should NOT be \fBfree\fP()d. 38 | .PP 39 | Some commands, like the set command, will return no output when successful, 40 | setting "*\fIoutputp\fP" to NULL. 41 | .PP 42 | The resulting output string can safely be ignored by calling 43 | this function with "\fIoutputp\fP" set to NULL. 44 | .SH FILE 45 | lib.c 46 | -------------------------------------------------------------------------------- /lib/mathomatic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Include file for user programs using the Mathomatic symbolic math library API. 3 | */ 4 | 5 | extern int matho_init(void); /* one-time Mathomatic initialization */ 6 | extern int matho_process(char *input, char **outputp); /* Mathomatic command or expression input */ 7 | extern int matho_parse(char *input, char **outputp); /* Mathomatic expression or equation input */ 8 | extern void matho_clear(void); /* Restart Mathomatic quickly and cleanly, replaces clear_all(). */ 9 | 10 | extern void free_mem(void); /* Free all allocated memory before quitting Mathomatic, if operating system doesn't when done. */ 11 | /* Mathomatic becomes unusable after free_mem(), until matho_init() is called again. */ 12 | /* Only Symbian OS is known to need a call to free_mem() before quitting. */ 13 | 14 | extern int load_rc(int return_true_if_no_file, FILE *ofp); /* Load Mathomatic startup set options from ~/.mathomaticrc, should allow "set save" to work. */ 15 | 16 | extern int cur_equation; /* current equation space number (origin 0) */ 17 | 18 | extern int result_en; /* Equation number of the API's returned result, */ 19 | /* if the result is also stored in an equation space, */ 20 | /* otherwise -1 for no equation number associated with result. */ 21 | /* Set by the last call to matho_parse() or matho_process(). */ 22 | /* Useful if you want to know where the result string is from, */ 23 | /* to act on it with further commands. */ 24 | 25 | extern const char *warning_str; /* optional warning message generated by the last command */ 26 | -------------------------------------------------------------------------------- /lib/testmain.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains the test/example program 3 | * for the Mathomatic symbolic math library and API. 4 | * Copy or refer to this, 5 | * if you are going to use the Mathomatic code in your other projects. 6 | */ 7 | 8 | #include 9 | #include 10 | #include "mathomatic.h" 11 | 12 | int 13 | main(int argc, char **argv) 14 | { 15 | char *cp; /* character pointer */ 16 | char *ocp; /* output character pointer */ 17 | int rv; /* return value */ 18 | char buf[10000]; /* input buffer */ 19 | char *version; /* version number of the library */ 20 | 21 | printf("Mathomatic library test/example program.\n"); 22 | /* Initialize all global variables and arrays so that Mathomatic will work properly. */ 23 | if (!matho_init()) { /* call this library function exactly once in your program */ 24 | fprintf(stderr, "Not enough memory.\n"); 25 | exit(1); 26 | } 27 | /* Mathomatic is ready for use. */ 28 | if (matho_process((char *) "version", &version)) { 29 | printf("Mathomatic library version %s\n", version); 30 | } else { 31 | fprintf(stderr, "Error getting Symbolic Math Library version number.\n"); 32 | fprintf(stderr, "Mathomatic version command failed.\n"); 33 | exit(1); 34 | } 35 | 36 | /* Uncomment the following if you would like "set save" to save the current session settings for every future session. */ 37 | /* load_rc(true, NULL); */ 38 | 39 | /* This is a standard input/output loop for testing. */ 40 | printf("Press the EOF character (Control-D) to exit.\n"); 41 | for (;;) { 42 | printf("%d-> ", cur_equation + 1); 43 | fflush(stdout); 44 | if ((cp = fgets(buf, sizeof(buf), stdin)) == NULL) 45 | break; 46 | /* Run the Mathomatic symbolic math engine. */ 47 | rv = matho_process(cp, &ocp); 48 | if (warning_str) { 49 | /* Optionally display any warnings (not required, but helpful). */ 50 | printf("Warning: %s\n", warning_str); 51 | } 52 | if (ocp) { 53 | if (rv && result_en >= 0) { 54 | /* Display the result equation number. */ 55 | printf("%d: ", result_en + 1); 56 | } 57 | /* Display the result. */ 58 | printf("Library result string:\n%s\n", ocp); 59 | if (rv) { 60 | free(ocp); 61 | } else { 62 | printf("Error return.\n"); 63 | } 64 | } 65 | } 66 | #if VALGRIND 67 | free(version); 68 | free_mem(); /* reclaim all memory to check for memory leaks with something like valgrind(1) */ 69 | #endif 70 | printf("\n"); 71 | exit(0); 72 | } 73 | -------------------------------------------------------------------------------- /license.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Mathomatic include file contains the current license notice. 3 | */ 4 | 5 | /* The following is the Mathomatic license notice, stored in a string. */ 6 | /* It is displayed by the "help copyright" command. */ 7 | char *license_string = 8 | " Mathomatic computer algebra system\n" 9 | " Copyright (C) 1987-2012 George Gesslein II\n\n" 10 | 11 | "This library is free software; you can redistribute it and/or\n" 12 | "modify it under the terms of the GNU Lesser General Public\n" 13 | "License as published by the Free Software Foundation; either\n" 14 | "version 2.1 of the License, or (at your option) any later version.\n\n" 15 | 16 | "This library is distributed in the hope that it will be useful,\n" 17 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 18 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" 19 | "Lesser General Public License for more details.\n\n" 20 | 21 | "You should have received a copy of the GNU Lesser General Public\n" 22 | "License along with this library; if not, write to the Free Software\n" 23 | "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n\n" 24 | 25 | "The full text of this license with details is contained in the file \"COPYING\"\n" 26 | "in the Mathomatic source distribution, obtainable from \"www.mathomatic.org\";\n" 27 | "All Mathomatic software and associated files (except for the documentation)\n" 28 | "are published under this license. The Mathomatic documentation is licensed\n" 29 | "under the GNU Free Documentation License (GFDL) version 1.3,\n" 30 | "with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts,\n" 31 | "so it can be easily published, corrected, and translated by anyone.\n\n" 32 | 33 | "Chief author and copyright holder contact information:\n\n" 34 | 35 | " email:\n" 36 | " gesslein@mathomatic.org or\n" 37 | " georgegesslein@gmail.com\n\n" 38 | 39 | " postal address:\n" 40 | " George Gesslein II\n" 41 | " P.O. Box 224\n" 42 | " Lansing, New York 14882-0224\n" 43 | " USA\n\n" 44 | 45 | "Most others who have kindly contributed working code or good ideas to\n" 46 | "Mathomatic are listed in the files \"AUTHORS\" and \"changes.txt\".\n" 47 | "Great merit is given to people that report bugs, in the file \"changes.txt\".\n" 48 | "This means you will also show up in the file \"NEWS\".\n" 49 | "To report a bug, simply email the author, or use the bug reporting facility\n" 50 | "shown with \"help bugs\".\n"; 51 | -------------------------------------------------------------------------------- /m4/README.txt: -------------------------------------------------------------------------------- 1 | 2 | m4 Mathomatic 3 | ------------- 4 | 5 | The executable named "mathomatic" is the best to run, however if you would 6 | like functions, you need to run "rmath", which runs Mathomatic using GNU m4 7 | as a macro pre-processor, allowing easy entry of standard math functions like 8 | sqrt(x) and sin(x) (no logarithm function yet). "rmath" and "matho" are shell 9 | scripts and are only known to work with GNU software. "rmath" runs "matho" 10 | with a readline wrapper (rlwrap), if available. "matho" runs m4, reading 11 | "functions.m4", and piping the output into Mathomatic. m4 Mathomatic will not 12 | run under MS-Windows, unless m4 is provided by the third-party system CygWin. 13 | 14 | To permanently install these program files along with their man pages on a 15 | Unix-like system, if this is a binary distribution, type: 16 | 17 | sudo ./matho-install 18 | 19 | for trig functions with radian units. For trig with degree units, type: 20 | 21 | sudo ./matho-install-degrees 22 | 23 | These install commands may be repeated, the last one entered is current. This 24 | binary distribution archive must be extracted to a directory and shell must 25 | be running for the installation to work. 26 | 27 | To undo the above commands and uninstall Mathomatic from your system, type: 28 | 29 | sudo ./matho-uninstall 30 | 31 | Installation is *not* necessary to run Mathomatic. 32 | 33 | "sudo make m4install" or "sudo make m4install-degrees" is the proper way to 34 | install these files from the source code distribution. 35 | 36 | Defined m4 macros for functions and constants are listed in the file 37 | "functions.m4" and the rmath man page. All trigonometric functions (sin(x), 38 | tan(x), etc.) are implemented as complex exponentials in m4 Mathomatic, so 39 | they can be simplified, manipulated, and calculated. 40 | 41 | Mathomatic input is filtered by m4, so opening a shell or an editor doesn't 42 | work when running m4 Mathomatic. These are disabled. 43 | 44 | The "quit" and "exit" commands may have some delay. You can use the EOF 45 | character (control-D) to quit instantly, instead. 46 | 47 | The read command currently doesn't use m4, so it can't process functions. The 48 | way to read in text files with functions is to supply the filenames on the 49 | shell command line: 50 | 51 | rmath filenames 52 | 53 | All Mathomatic functions are real number, complex number, and symbolically 54 | capable. 55 | 56 | ---------------------------------------------------------------------------- 57 | 58 | You can turn on color mode with the Mathomatic command: 59 | 60 | set color 61 | 62 | For brighter colors, use: 63 | 64 | set bold color 65 | 66 | typed at the Mathomatic main prompt. For dimmer colors, type: 67 | 68 | set no bold 69 | 70 | To turn off color mode, type: 71 | 72 | set no color 73 | 74 | You can save the current color state (and all other settings) with: 75 | 76 | set save 77 | 78 | so that Mathomatic starts up with your desired color setting every time. 79 | -------------------------------------------------------------------------------- /m4/degrees.m4: -------------------------------------------------------------------------------- 1 | set no prompt 2 | ; Read this into rmath with "rmath degrees.m4" to use trig 3 | ; with arguments in degree units instead of radians. 4 | 5 | ; Standard trigonometry functions as complex exponentials follow. 6 | ; Argument x is in degrees. 7 | m4_define(`sin', `((e**(i*(($1)*pi/180))-e**(-i*(($1)*pi/180)))/(2i))'); sin(x) = sine of x 8 | m4_define(`cos', `((e**(i*(($1)*pi/180))+e**(-i*(($1)*pi/180)))/2)'); cos(x) = cosine of x 9 | m4_define(`tan', `((e**(i*(($1)*pi/180))-e**(-i*(($1)*pi/180)))/(i*(e**(i*(($1)*pi/180))+e**(-i*(($1)*pi/180)))))'); tan(x) = tangent of x 10 | m4_define(`cot', `(i*(e**(i*(($1)*pi/180))+e**(-i*(($1)*pi/180)))/(e**(i*(($1)*pi/180))-e**(-i*(($1)*pi/180))))'); cot(x) = cotangent of x 11 | m4_define(`sec', `(2/(e**(i*(($1)*pi/180))+e**(-i*(($1)*pi/180))))'); sec(x) = secant of x 12 | m4_define(`csc', `(2i/(e**(i*(($1)*pi/180))-e**(-i*(($1)*pi/180))))'); csc(x) = cosecant of x 13 | 14 | echo Trig function arguments are now in degree units only. 15 | set prompt >/dev/null 16 | -------------------------------------------------------------------------------- /m4/file_id.diz: -------------------------------------------------------------------------------- 1 | Mathomatic V16: Symbolic math program 2 | This program can automatically solve, 3 | simplify, compare, and calculate 4 | algebraic equations, etc. Does 5 | calculus operations, too. Free 6 | to distribute. 7 | -------------------------------------------------------------------------------- /m4/functions.m4: -------------------------------------------------------------------------------- 1 | set no prompt 2 | 3 | ; This m4 input file is used by the shell scripts "matho" and "rmath". 4 | ; This defines and enables named math functions in Mathomatic. 5 | ; Most functions here should be real number, complex number, and symbolically capable. 6 | 7 | ; m4 macro definitions for some elementary math functions and constants in Mathomatic. 8 | m4_define(`sqrt', `(($1)**.5)'); function sqrt(x) = square root of x 9 | m4_define(`cbrt', `(($1)**(1/3))'); function cbrt(x) = cube root of x 10 | m4_define(`exp', `(e**($1))'); function exp(x) = e^x 11 | m4_define(`pow', `(($1)**($2))'); function pow(x, y) = x^y 12 | m4_define(`abs', `(|($1)|)'); function abs(x) = absolute value = |x| 13 | m4_define(`sgn', `(($1)/|($1)|)'); signum function sgn(x) = sign of x; sgn(0) fails. 14 | m4_define(`factorial', `(($1)!)'); factorial(x) function = x! 15 | m4_define(`gamma', `((($1)-1)!)'); gamma(x) function = (x-1)! 16 | m4_define(`phi', `((1+5**.5)/2)'); phi = the golden ratio constant, a root of x^2-x-1=0 17 | m4_define(`omega', `(0.5671432904097838729999686622)'); an approximation of the Omega constant 18 | m4_define(`euler', `(0.57721566490153286060651209008)'); the Euler-Mascheroni constant (approximation) 19 | 20 | ;set modulus_mode=2 >/dev/null ; mode 1 or 2 required for floor() and ceil(). 21 | m4_define(`floor', `(($1)-($1)%1)'); floor(x) = floor function, real x -> integer result 22 | m4_define(`ceil', `(($1)+(-($1))%1)'); ceil(x) = ceiling function, real x -> integer result 23 | m4_define(`int', `(($1)//1)'); int(x) = truncate to integer, real x -> integer result 24 | m4_define(`round', `((($1)+|($1)|/($1)/2)//1)'); round(x) = round to nearest integer; beware, round(0) fails. 25 | 26 | ; Standard trigonometry functions as complex exponentials follow. 27 | ; Based on Euler's identity: e^(i*x) = cos(x) + i*sin(x) 28 | ; Argument x is in radians. 29 | m4_define(`sin', `((e**(i*($1))-e**(-i*($1)))/(2i))'); sin(x) = sine of x 30 | m4_define(`cos', `((e**(i*($1))+e**(-i*($1)))/2)'); cos(x) = cosine of x 31 | m4_define(`tan', `((e**(i*($1))-e**(-i*($1)))/(i*(e**(i*($1))+e**(-i*($1)))))'); tan(x) = tangent of x 32 | m4_define(`cot', `(i*(e**(i*($1))+e**(-i*($1)))/(e**(i*($1))-e**(-i*($1))))'); cot(x) = cotangent of x 33 | m4_define(`sec', `(2/(e**(i*($1))+e**(-i*($1))))'); sec(x) = secant of x 34 | m4_define(`csc', `(2i/(e**(i*($1))-e**(-i*($1))))'); csc(x) = cosecant of x 35 | m4_define(`sinc', `(((e**(i*pi*($1))-e**(-i*pi*($1)))/(2i))/(pi*($1)))'); sinc(x) = normalized sinc function 36 | 37 | ; Standard hyperbolic trigonometry functions follow. 38 | ; Available are sinh(x), cosh(x), tanh(x), coth(x), sech(x), and csch(x). 39 | ; These are related to the above trigonometry functions without the "h" appended to the function name. 40 | m4_define(`sinh', `((e**($1)-e**-($1))/2)') 41 | m4_define(`cosh', `((e**($1)+e**-($1))/2)') 42 | m4_define(`tanh', `((e**($1)-e**-($1))/(e**($1)+e**-($1)))') 43 | m4_define(`coth', `((e**($1)+e**-($1))/(e**($1)-e**-($1)))') 44 | m4_define(`sech', `(2/(e**($1)+e**-($1)))') 45 | m4_define(`csch', `(2/(e**($1)-e**-($1)))') 46 | 47 | echo Press the EOF character (Control-D) if you wish to exit Mathomatic. 48 | echo Standard functions are now available, except for logarithms. 49 | set prompt >/dev/null 50 | -------------------------------------------------------------------------------- /m4/gradians.m4: -------------------------------------------------------------------------------- 1 | set no prompt 2 | ; Read this into rmath with "rmath gradians.m4" to use trig 3 | ; with arguments in gradian units instead of radians. 4 | 5 | ; Standard trigonometry functions as complex exponentials follow. 6 | ; Argument x is in gradians. 7 | m4_define(`sin', `((e**(i*(($1)*pi/200))-e**(-i*(($1)*pi/200)))/(2i))'); sin(x) = sine of x 8 | m4_define(`cos', `((e**(i*(($1)*pi/200))+e**(-i*(($1)*pi/200)))/2)'); cos(x) = cosine of x 9 | m4_define(`tan', `((e**(i*(($1)*pi/200))-e**(-i*(($1)*pi/200)))/(i*(e**(i*(($1)*pi/200))+e**(-i*(($1)*pi/200)))))'); tan(x) = tangent of x 10 | m4_define(`cot', `(i*(e**(i*(($1)*pi/200))+e**(-i*(($1)*pi/200)))/(e**(i*(($1)*pi/200))-e**(-i*(($1)*pi/200))))'); cot(x) = cotangent of x 11 | m4_define(`sec', `(2/(e**(i*(($1)*pi/200))+e**(-i*(($1)*pi/200))))'); sec(x) = secant of x 12 | m4_define(`csc', `(2i/(e**(i*(($1)*pi/200))-e**(-i*(($1)*pi/200))))'); csc(x) = cosecant of x 13 | 14 | echo Trig function arguments are now in gradian units only. 15 | set prompt >/dev/null 16 | -------------------------------------------------------------------------------- /m4/matho: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This shell script runs Mathomatic with the GNU m4 macro pre-processor so that 3 | # standard math functions such as sqrt(x), sin(x), etc. may be easily entered. 4 | # Hyperbolic trig has "h" appended, like sinh(x) for hyperbolic sine. 5 | # Only works with GNU software. 6 | # See file "functions.m4" for the complete list of supported functions, 7 | # or type "man rmath" at the shell prompt. 8 | # 9 | # Usage: matho [ input_files ] 10 | 11 | MATHOMATIC="${0}matic" 12 | MFUNCTIONS="${0%/matho}/functions.m4" 13 | MOPTIONS="-ru -s-1" 14 | 15 | if ! m4 --version >/dev/null 16 | then 17 | echo The \"m4\" package is not installed. GNU m4 is required to run m4 Mathomatic. 18 | exit 1 19 | fi 20 | 21 | if [ -x "$MATHOMATIC" ] 22 | then 23 | echo Running "$MATHOMATIC" 24 | m4 -eP -- "$MFUNCTIONS" "$@" - | "$MATHOMATIC" $MOPTIONS 25 | elif [ -x ../mathomatic ] 26 | then 27 | echo Running ../mathomatic 28 | m4 -eP -- "$MFUNCTIONS" "$@" - | ../mathomatic $MOPTIONS 29 | else 30 | echo Running mathomatic 31 | m4 -eP -- "$MFUNCTIONS" "$@" - | mathomatic $MOPTIONS 32 | fi 33 | -------------------------------------------------------------------------------- /m4/matho-install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This shell script installs m4 Mathomatic so that any user can use it. 3 | # If this is a source distribution, you should change directory to its root, 4 | # and compile Mathomatic and "sudo make m4install" to install everything. 5 | # If this is a binary distribution, you should type "sudo ./matho-install" 6 | # from this directory to install the program files and man pages. 7 | 8 | PREFIX=/usr/local 9 | BINDIR=$PREFIX/bin 10 | MANDIR=$PREFIX/share/man/man1 11 | MAN1="mathomatic.1 rmath.1" 12 | MATHOMATIC=mathomatic 13 | if [ ! -x "$MATHOMATIC" ] 14 | then 15 | MATHOMATIC="../$MATHOMATIC" 16 | fi 17 | if [ ! -x "$MATHOMATIC" ] 18 | then 19 | echo mathomatic executable not found. 20 | exit 21 | fi 22 | 23 | echo Installing "$MATHOMATIC" to "$BINDIR" 24 | set -x 25 | mkdir -p $BINDIR 26 | mkdir -p $MANDIR 27 | cp $MAN1 $MANDIR 28 | ln -sf $MANDIR/rmath.1 $MANDIR/matho.1 29 | cp "$MATHOMATIC" functions.m4 matho rmath "$BINDIR" && echo Done! && exit 30 | echo 31 | echo Usage: sudo $0 32 | -------------------------------------------------------------------------------- /m4/matho-install-degrees: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This shell script installs m4 Mathomatic with trig functions that use degree units. 3 | # If this is a source distribution, you should change directory to its root, 4 | # and compile Mathomatic and "sudo make m4install-degrees" to install everything. 5 | # If this is a binary distribution, you should type "sudo ./matho-install-degrees" 6 | # from this directory to install the program files and man pages. 7 | 8 | PREFIX=/usr/local 9 | BINDIR=$PREFIX/bin 10 | MANDIR=$PREFIX/share/man/man1 11 | MAN1="mathomatic.1 rmath.1" 12 | MATHOMATIC=mathomatic 13 | if [ ! -x "$MATHOMATIC" ] 14 | then 15 | MATHOMATIC="../$MATHOMATIC" 16 | fi 17 | if [ ! -x "$MATHOMATIC" ] 18 | then 19 | echo mathomatic executable not found. 20 | exit 21 | fi 22 | 23 | echo Installing "$MATHOMATIC" to "$BINDIR" 24 | set -x 25 | mkdir -p $BINDIR 26 | mkdir -p $MANDIR 27 | cp $MAN1 $MANDIR 28 | ln -sf $MANDIR/rmath.1 $MANDIR/matho.1 29 | cp "$MATHOMATIC" functions.m4 matho rmath "$BINDIR" && 30 | cat degrees.m4 >>"$BINDIR"/functions.m4 && echo Done! && exit 31 | echo 32 | echo Usage: sudo $0 33 | -------------------------------------------------------------------------------- /m4/matho-uninstall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This shell script uninstalls m4 Mathomatic if installed 3 | # with matho-install or matho-install-degrees. 4 | # To uninstall Mathomatic from your computer, 5 | # type "sudo ./matho-uninstall". 6 | 7 | PREFIX=/usr/local 8 | BINDIR=$PREFIX/bin 9 | MANDIR=$PREFIX/share/man/man1 10 | MATHOMATIC=mathomatic 11 | BINFILES="$MATHOMATIC matho rmath functions.m4" 12 | MANFILES="mathomatic.1 rmath.1 matho.1" 13 | 14 | set -x 15 | for file in $BINFILES; 16 | do 17 | rm -f "$BINDIR"/"$file"; 18 | done 19 | for file in $MANFILES; 20 | do 21 | rm -f "$MANDIR"/"$file"; 22 | done 23 | 24 | echo "$MATHOMATIC" uninstalled. 25 | -------------------------------------------------------------------------------- /m4/rmath: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This shell script runs m4 Mathomatic (matho) with readline capability. 3 | # Uses rlwrap program, if available, which is a readline front end. 4 | # The rlwrap program may be obtained at 5 | # http://utopia.knoware.nl/~hlub/uck/rlwrap/ 6 | # 7 | # Usage: rmath [ input_files ] 8 | 9 | MATHOPATH="${0%/rmath}/matho" 10 | if [ ! -x "$MATHOPATH" ] 11 | then 12 | MATHOPATH=matho 13 | fi 14 | 15 | if rlwrap true 16 | then 17 | rlwrap -H ~/.matho_history "$MATHOPATH" "$@" 18 | else 19 | echo readline support not loaded because \"rlwrap\" utility was not found. 20 | "$MATHOPATH" "$@" 21 | fi 22 | -------------------------------------------------------------------------------- /makehtmlcard.awk: -------------------------------------------------------------------------------- 1 | # Convert TAB delimited Mathomatic help file to HTML. 2 | # See "makehtmlcard.sh". 3 | # Usage awk -F"\t" -f makehtmlcard.awk infile.txt >outfile.html 4 | # Credit goes to John Blommers (http://www.blommers.org) for starting this awk file and for the cheat sheet idea. 5 | 6 | BEGIN { 7 | print "" 8 | print "" 9 | print "" 10 | } 11 | 12 | NR==1 { 13 | print "Mathomatic Quick Reference Card" 14 | print "" 15 | print "" 16 | print "" 17 | print "" "" "" 18 | } 19 | 20 | NR==2 { 21 | print "" 22 | print "" 23 | print "" 24 | print "" 25 | print "" 26 | } 27 | 28 | NR>2 { 29 | print "" 30 | print "" 31 | print "" 32 | print "" 33 | print "" 34 | } 35 | 36 | END { 37 | print "
" "" $1 "" "
" $1 "" $2 "" $3 "
" $1 "" $2 "" $3 "
" 38 | print "
" 39 | # print "

" 40 | print "" 41 | print "Anything enclosed by straight brackets [like this] means it is optional and may be omitted." 42 | print "" 43 | # print "

" 44 | # print "" 45 | # print "To select an equation space and make it the current equation, type the equation number at the main prompt.
" 46 | # print "To solve the current equation, type the variable name at the main prompt or use the solve command." 47 | # print "
" 48 | print "

" 49 | print "" 50 | print "For more information, visit www.mathomatic.org" 51 | print "" 52 | print "" 53 | print "" 54 | } 55 | -------------------------------------------------------------------------------- /makehtmlcard.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | textfile="$1"quickrefcard.txt 6 | trap "echo Removing \"$textfile\"; rm -f \"$textfile\"" EXIT 7 | echo Creating Mathomatic Quick Reference Card named: "$1"quickrefcard.html 8 | ./mathomatic -e "help table >$textfile" 9 | echo Running awk... 10 | awk -F"\t" -f makehtmlcard.awk "$textfile" >"$1"quickrefcard.html 11 | echo Created "$1"quickrefcard.html 12 | echo Use print to PDF file in Firefox to create the PDF quick reference card. 13 | 14 | # pisa "$1"quickrefcard.html "$1"quickrefcard.pdf 15 | -------------------------------------------------------------------------------- /makenews.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Make forward order changelog in "NEWS" file from changes.txt: 3 | set -e 4 | (echo; echo "The latest version of Mathomatic is `cat VERSION`, here are the changes:"; tac -r -s "^Mathomatic version.*$" changes.txt) | head -n -9 >NEWS.tmp 5 | echo >>NEWS.tmp 6 | echo ---------------------------------------------------------------------- >>NEWS.tmp 7 | echo End of this version history of the Mathomatic computer algebra system. >>NEWS.tmp 8 | echo Current as of `date '+%D'` \(`date '+%F'`\). >>NEWS.tmp 9 | echo The latest changes are at the beginning of this file. >>NEWS.tmp 10 | echo This file is always available up-to-date at http://mathomatic.org/NEWS >>NEWS.tmp 11 | echo Alternatively, you can get it at http://mathomatic.orgserve.de/NEWS >>NEWS.tmp 12 | echo Do not edit this file, edit the end of changes.txt instead. >>NEWS.tmp 13 | echo Written and maintained by George Gesslein II. >>NEWS.tmp 14 | mv NEWS.tmp NEWS 15 | -------------------------------------------------------------------------------- /makepdfsheet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | htmlfile="$1"quickref.html 4 | pdffile=quickref.pdf 5 | 6 | echo Generating the Mathomatic Quick Reference Sheet PDF file... 7 | 8 | echo "" >"$htmlfile" 9 | echo '' >>"$htmlfile" 10 | echo '' >>"$htmlfile" 11 | echo 'Mathomatic Quick Reference Sheet' >>"$htmlfile" 12 | echo '' >>"$htmlfile" 13 | echo '' >>"$htmlfile" 14 | echo '

' >>"$htmlfile"
15 | 
16 | ./mathomatic -e "set html all" "help all main equations constants >>$htmlfile" || (rm "$htmlfile"; exit 1)
17 | 
18 | echo >>"$htmlfile"
19 | echo 'For more information, visit www.mathomatic.org' >>"$htmlfile"
20 | 
21 | echo '
' >>"$htmlfile" 22 | echo '' >>"$htmlfile" 23 | echo '' >>"$htmlfile" 24 | 25 | if htmldoc --webpage --format pdf --linkstyle plain --no-links -f "$pdffile" "$htmlfile" 26 | then 27 | echo "$pdffile" successfully created. 28 | rm "$htmlfile" 29 | exit 0 30 | else 31 | rm "$htmlfile" 32 | exit 1 33 | fi 34 | -------------------------------------------------------------------------------- /menu/README.txt: -------------------------------------------------------------------------------- 1 | 2 | The Debian Menu System provides a unified menu interface for both text and 3 | X Windows oriented programs, without having to configure each window manager. 4 | 5 | These are the Debian Menu System files for Mathomatic. 6 | "mathomatic" and "mathomatic-primes" go in "/usr/share/menu". 7 | They should be put there by the Debian mathomatic package. 8 | -------------------------------------------------------------------------------- /menu/mathomatic: -------------------------------------------------------------------------------- 1 | ?package(mathomatic):\ 2 | needs="text"\ 3 | hints="Mathomatic"\ 4 | section="Applications/Science/Mathematics"\ 5 | title="Mathomatic"\ 6 | command="/usr/bin/mathomatic"\ 7 | icon="/usr/share/pixmaps/mathomatic.xpm" 8 | -------------------------------------------------------------------------------- /menu/mathomatic-primes: -------------------------------------------------------------------------------- 1 | ?package(mathomatic-primes):\ 2 | needs="text"\ 3 | hints="Mathomatic"\ 4 | section="Applications/Science/Mathematics"\ 5 | title="Prime Numbers (Mathomatic)"\ 6 | command="/usr/bin/matho-primes"\ 7 | icon="/usr/share/pixmaps/mathomatic.xpm" 8 | -------------------------------------------------------------------------------- /misc/README.txt: -------------------------------------------------------------------------------- 1 | 2 | misc/README.txt 3 | --------------- 4 | 5 | Useful stuff that doesn't belong anywhere else goes in this directory: 6 | 7 | ideas.txt - The Mathomatic todo and idea list. 8 | 9 | known_bugs.txt - Current list of known Mathomatic bugs. 10 | Normally bugs are fixed immediately if they can be. 11 | 12 | *.in - Some Mathomatic input files that Mathomatic has trouble with. 13 | -------------------------------------------------------------------------------- /misc/ideas.txt: -------------------------------------------------------------------------------- 1 | Ideas to code in Mathomatic 2 | --------------------------- 3 | 4 | A GPL compatible, free software GUI needs to be written for Mathomatic. 5 | Anyone interested in writing one should contact me at some point, so it can 6 | be included in the Mathomatic distribution. 7 | 8 | Implement logarithms as a binary operator mapped from the log(x, y) or ln(x) 9 | functions, using m4. The rules for logarithms can be slowly added later. This 10 | is a large project that only George Gesslein II knows how to do properly 11 | (well maybe, because Mathomatic is like a highly efficient CAS written in 12 | assembly language, but it is written in C for portability). This easy idea 13 | implements each logarithm as a binary operator like in the J programming 14 | language, then uses m4 as a macro preprocessor to map the log(x, y) and ln(x) 15 | functions to it. I am currently looking for ideas from anyone on which ASCII 16 | character or combination of characters should best represent the logarithm 17 | function. My best idea so far is (a\/b) for logarithm base "b" of "a". m4 18 | would allow entry of ln(a) and log(a, b) after the log operator is 19 | implemented. ln(a) would translate to ((a)\/e). The default display in 20 | Mathomatic is always an operator display, but certain listing and exporting 21 | commands will be able to display logarithms as log functions. 22 | 23 | Simplify nested radicals like ((9 + 4*(2^.5))^.5) to (1 + 2*(2^.5)). This may 24 | be difficult, I have an idea how this is generally done, just need some free 25 | thinking and implementation time. Slow trial and error algorithms are not 26 | acceptable for this. The routine should temporarily square the result to make 27 | sure it is correct, or temporarily numerically approximate the original and 28 | the result and compare the resulting constants, before acceptance. Here is an 29 | article on one way to simplify nested radicals: 30 | "http://www.almaden.ibm.com/cs/people/fagin/symb85.pdf". Also, see Landau's 31 | algorithm (http://en.wikipedia.org/wiki/Landau%27s_algorithm). 32 | 33 | Use the GNU Scientific Library (GSL) to automatically numerically solve any 34 | degree numeric polynomial equation, like "examples/roots.c" does, when 35 | symbolic solving fails. Unfortunately, the GSL results are sometimes 36 | inaccurate, and it adds a library dependency, so I may not do this. Instead, 37 | the general cubic formula in "tests/cubic.in" could be hard-coded into the 38 | Mathomatic poly_solve() function, so any cubic equation could be 39 | automatically solved. I just haven't figured out how Mathomatic is going to 40 | easily handle 3 solutions per equation space. Solving quartic equations with 41 | "tests/quartic.in" is not recommended, due to the large, accumulated 42 | round-off error of floating point when approximating large formulas, and the 43 | many cases that quartic formula causes division by zero and fails, though 44 | handling an even number of solutions is very easy in Mathomatic. 45 | 46 | Implement complex number factorials, when an accurate, floating point, 47 | complex number gamma calculating function is found. The GSL does this. 48 | 49 | Make polynomial gcd calculation partially recursive. This is difficult, as 50 | the expression storage areas are currently static globals. If successful, 51 | this will make polynomial gcd calculation multivariate, so it will succeed 52 | with larger expressions with many variables. There is no need for total 53 | recursion, because it would never be used anyways, with the amount of 54 | floating point round-off error that occurs in Mathomatic. Every inexact 55 | floating point mathematical operation has a small round-off error that adds 56 | up with many operations, making polynomial gcd determination fail with large 57 | polynomials, anyways. 58 | 59 | Add a "polynomial" command that tells what type and degree polynomial the 60 | current expression is, if it is a polynomial in the optional specified 61 | variable. Study Maxima's facsum() function, it does a related thing. 62 | 63 | matho and rmath don't work perfectly; because they use m4 as a front end, 64 | there are some user interface problems. I probably should write some C code 65 | to do the string macro expansion as part of the main mathomatic program. If I 66 | am feeling better I will do that and add logarithm function support. 67 | 68 | 69 | ----------------------------------------------------------------- 70 | This file was written by George Gesslein II of www.mathomatic.org 71 | -------------------------------------------------------------------------------- /misc/identities.in: -------------------------------------------------------------------------------- 1 | ; Mathomatic fails to completely simplify the following 3 identities with the simplify command. 2 | ; Solving for x or 0 verifies they are identities. 3 | 4 | ; (cos(4x)+cos(3x)+cos(2x))/(sin(4x)+sin(3x)+sin(2x))=cot(3x) 5 | ((((e^(4*i*x)) + (e^(-4*i*x)))/2) + (((e^(3*i*x)) + (e^(-3*i*x)))/2) + (((e^(2*i*x)) + (e^(-2*i*x)))/2))/((((e^(4*i*x)) - (e^(-4*i*x)))/(2*i)) + (((e^(3*i*x)) - (e^(-3*i*x)))/(2*i)) + (((e^(2*i*x)) - (e^(-2*i*x)))/(2*i))) = i*((e^(3*i*x)) + (e^(-3*i*x)))/((e^(3*i*x)) - (e^(-3*i*x))) 6 | ((e^x) - 1)/((e^(x/2)) + 1) = (e^(x/2)) - 1 7 | ((4^x) - 1)/((4^(x/2)) + 1) = (4^(x/2)) - 1 8 | simplify all 9 | copy all 10 | 11 | :solve 1-3 x 12 | solve 4-6 verifiable 0 13 | -------------------------------------------------------------------------------- /misc/john.in: -------------------------------------------------------------------------------- 1 | ; A hard equation for improving Mathomatic. 2 | ; Shows that the simplify command is not perfect. 3 | P = (c - (r/((1 + f)^(t + 1))))*(1 - (1/((1 + f)^t)))/((1 + f)*f) 4 | -------------------------------------------------------------------------------- /misc/known_bugs.txt: -------------------------------------------------------------------------------- 1 | Known bugs in Mathomatic 2 | ------------------------ 3 | 4 | Compiling with Clang or Xcode 4 and up, which uses LLVM: 5 | This is actually an optimization bug in the LLVM backend used by Clang 6 | and the Apple Xcode IDE. When dealing with memmove(3), LLVM optimization 7 | introduces bugs and program hangs. So when you are compiling Mathomatic with 8 | Clang or the latest Xcode, please be sure and compile with no optimization 9 | options or the "-O0" option (which disables all optimization), otherwise the 10 | regression tests and entering things like y=32^.5 and then simplifying will 11 | cause Mathomatic to hang forever. memmove(3) is used throughout Mathomatic. 12 | So when compiling Mathomatic with Clang or Xcode, always disable 13 | optimization, it will run all the tests in 1 second and is not noticeably 14 | slower. Mathomatic will hang during "make test" if compiled with optimization 15 | enabled when using LLVM as a backend. 16 | 17 | 17! bug: Fixed. 18 | "factor number 17!" and higher don't work because the maximum safely 19 | representable integer for double precision floating point is 15 digits long. 20 | This is not a bug. 21 | 22 | Absolute values and complex number problems: 23 | Absolute values and the imaginary unit (i) do not always remain intact 24 | after being manipulated with the standard rules of algebra. For example, 1/i 25 | correctly simplifies to -i, changing the sign of the result. So the fraction 26 | command and other possible operations may give wrong results due to differing 27 | sign after manipulations. The simplify command should always work, but it is 28 | not guaranteed for these. 29 | The solve command may have a problem too, but using the verify option 30 | should check that the result of solving absolute value or complex number 31 | equations is 100% correct. Don't forget though that the absolute value |x| 32 | definition in Mathomatic is ((x^2)^.5), which is different from the standard 33 | absolute value function in the complex realm, which would always return a 34 | positive and real distance on a complex Cartesian graph. Mathomatic is taking 35 | shortcuts with its definition and will not always return a real value result 36 | if any of the absolute value arguments are imaginary. It works perfectly with 37 | real value arguments. 38 | 39 | Solving modulus equations: 40 | May result in garbage, due to incomplete modulus operator solving code. 41 | I could just disable it, but I choose to research it at a later time, because 42 | it does sometimes work nicely. Again, the "solve verify" option tells if you 43 | should trust the results. 44 | -------------------------------------------------------------------------------- /misc/linear4.in: -------------------------------------------------------------------------------- 1 | ; Combine 4 simultaneous linear equations with 4 unknowns (x1, x2, x3, x4). 2 | ; Solve for all 4 unknowns using the eliminate, solve, and simplify commands. 3 | 4 | ; Keep this to test simplification in Mathomatic when recursion is added to the GCD routines. 5 | ; Currently Mathomatic is unable to completely simplify all of the resulting equations. 6 | ; By using the simplify command immediately after some eliminate commands, 7 | ; equation number 4 solved for x4 is completely simplified. 8 | ; 9 | ; The rest may be easily simplifiable when polynomial GCD works recursively, 10 | ; so that it is multivariate. 11 | 12 | clear all ; restarts Mathomatic 13 | ; The next four lines enter all of the equations into Mathomatic 14 | b1 = a11*x1+a12*x2+a13*x3+a14*x4 15 | b2 = a21*x1+a22*x2+a23*x3+a24*x4 16 | b3 = a31*x1+a32*x2+a33*x3+a34*x4 17 | b4 = a41*x1+a42*x2+a43*x3+a44*x4 18 | 2 ; select equation #2 19 | eliminate x1 ; eliminate x1 variable from eq#2 20 | 3 ; select equation #3 21 | eliminate x1 x2 ; eliminate x1 x2 from eq#3 22 | 4 ; select equation #4 23 | eliminate x1 x2 x3 ; eliminate x1 x2 x3 from eq#4 24 | simplify all 25 | solve verifiable x4 ; solve for x4 26 | 3 ; select equation #3 27 | eliminate x4 using 4; find x3 28 | 2 ; select equation #2 29 | eliminate x4 using 4, x3 using 3; find x2 30 | 1 ; select equation #1 31 | eliminate x4 using 4, x3 using 3, x2 using 2; find x1 32 | simplify all 33 | -------------------------------------------------------------------------------- /primes/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Mathomatic Prime Number Tools 3 | ----------------------------- 4 | 5 | This directory contains some small, command-line, integer math utilities 6 | written in C and Python. To compile, test, and install these utilities, type 7 | the following commands at the Unix shell prompt: 8 | 9 | make 10 | make test 11 | sudo make install 12 | 13 | This will install: 14 | 15 | matho-primes - quickly generate consecutive prime numbers 16 | primorial - calculate large primorials 17 | matho-mult - multiply large integers 18 | matho-pascal - output Pascal's triangle 19 | matho-sum - sum large integers 20 | matho-sumsq - output the minimum sum of the squares of integers 21 | 22 | These stand-alone utilities come with Mathomatic and they don't need to be 23 | installed to work properly. See the website www.mathomatic.org to get the 24 | latest version. 25 | 26 | The Python program "primorial" is included in this directory for calculating 27 | large primorials from matho-primes. A primorial is the product of all primes 28 | up to the given number. To generate a list of all unique primorials from 2 to 29 | 97, type the following at the Unix shell after installing matho-primes: 30 | 31 | primorial `matho-primes 2 97` 32 | 33 | Example that calculates the number of primes less than or equal to 1,000,000: 34 | 35 | matho-primes 0 1000000 | wc -w 36 | 37 | The result should be 78498. 38 | -------------------------------------------------------------------------------- /primes/lsqrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tested long integer square root function. 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | #define true 1 9 | #define false 0 10 | 11 | #if DEBUG 12 | /* 13 | * Return true if x is the truncated integer square root of y. 14 | */ 15 | int 16 | verify_lsqrt(long y, long x) 17 | { 18 | if ((long long) x * x > y || ((long long) x + 1) * ((long long) x + 1) <= y) { 19 | return false; 20 | } 21 | return true; 22 | } 23 | #endif 24 | 25 | /* 26 | * Returns the truncated integer square root of y using 27 | * the Babylonian iterative approximation method, derived from Newton's method. 28 | * Returns -1 on error. 29 | * 30 | * This lsqrt() function was written by George Gesslein II 31 | * and is placed in the public domain. 32 | */ 33 | long 34 | lsqrt(long y) 35 | { 36 | long x_old, x_new; 37 | long testy; 38 | int nbits; 39 | int i; 40 | 41 | if (y <= 0) { 42 | if (y != 0) { 43 | #if DEBUG 44 | fprintf(stderr, "Domain error in %s().\n", __func__); 45 | #endif 46 | return -1L; 47 | } 48 | return 0L; 49 | } 50 | /* select a good starting value using binary logarithms: */ 51 | nbits = (sizeof(y) * 8) - 1; /* subtract 1 for sign bit */ 52 | for (i = 4, testy = 16L;; i += 2, testy <<= 2L) { 53 | if (i >= nbits || y <= testy) { 54 | x_old = (1L << (i / 2L)); /* x_old = sqrt(testy) */ 55 | break; 56 | } 57 | } 58 | /* x_old >= sqrt(y) */ 59 | /* use the Babylonian method to arrive at the integer square root: */ 60 | for (;;) { 61 | x_new = (y / x_old + x_old) / 2L; 62 | if (x_old <= x_new) 63 | break; 64 | x_old = x_new; 65 | } 66 | #if DEBUG 67 | if (!verify_lsqrt(y, x_old)) { 68 | fprintf(stderr, "Verification error in %s().\n", __func__); 69 | return -1L; 70 | } 71 | #endif 72 | return x_old; 73 | } 74 | -------------------------------------------------------------------------------- /primes/makefile: -------------------------------------------------------------------------------- 1 | # Makefile for compiling and installing the Mathomatic Prime Number Tools 2 | # under a Unix-like system. 3 | # See file README.txt for instructions. 4 | # 5 | # If make fails due to incomplete "long double" support, try: 6 | # CFLAGS="-O3 -DUSE_DOUBLES" make 7 | 8 | 9 | SHELL = /bin/sh # from http://www.gnu.org/prep/standards/ 10 | CC ?= gcc # C compiler to use 11 | INSTALL ?= install # installer to use 12 | INSTALL_PROGRAM ?= $(INSTALL) # Command to install executable program files. 13 | INSTALL_DATA ?= $(INSTALL) -m 0644 # Command to install data files. 14 | 15 | CC_OPTIMIZE = -O3 # Default C compiler optimization flags that are safe. 16 | #CC_OPTIMIZE += -ffast-math -fomit-frame-pointer # Extra optimize for speed, not functional under Mac OS X. 17 | 18 | OPTFLAGS ?= $(CC_OPTIMIZE) -Wall -Wshadow -Wno-char-subscripts # gcc specific flags; change for other C compilers. 19 | CFLAGS ?= $(OPTFLAGS) 20 | #CFLAGS += -std=gnu99 # Uses the Gnu99 standard; may require setting this on gcc command line if using an older compiler. 21 | LDLIBS += -lm 22 | 23 | # Install directories follow, installs everything in $(DESTDIR)/usr/local by default. 24 | prefix ?= /usr/local 25 | bindir ?= $(prefix)/bin 26 | mandir ?= $(prefix)/share/man 27 | 28 | # The executables to create: 29 | TARGETS = matho-primes matho-pascal matho-sumsq 30 | # The Python scripts to install: 31 | PYTHON_SCRIPTS = primorial matho-mult matho-sum 32 | # The executables to install: 33 | EXECUTABLES = $(TARGETS) $(PYTHON_SCRIPTS) 34 | # The man pages to install: 35 | MAN1 = matho-primes.1 matho-pascal.1 matho-sumsq.1 primorial.1 matho-mult.1 matho-sum.1 36 | 37 | all static: $(TARGETS) # make these by default 38 | @echo 39 | @echo Prime Number Tools successfully created. 40 | 41 | # Strip the binaries of their symbol tables. Makes smaller executables, but debugging becomes impossible. 42 | strip: $(TARGETS) 43 | strip $(TARGETS) 44 | 45 | matho-sumsq: matho-sumsq.o lsqrt.o 46 | $(CC) $(CFLAGS) $(LDFLAGS) $+ $(LDLIBS) -o $@ 47 | 48 | # To compile the Mathomatic Prime Number Tools as stand-alone executables 49 | # that have no shared library dependencies, type "make flush static". 50 | static: LDFLAGS += -static 51 | 52 | test: 53 | @echo Testing basic functionality of matho-primes: 54 | time -p ./matho-primes 10000000000000 10000000300000 twin >test.out && diff -u --strip-trailing-cr twins.out test.out 55 | @rm test.out 56 | @echo Small primes test passed. 57 | @echo 58 | 59 | # Same as "make test", except doesn't run the time command. 60 | check: 61 | @echo Testing basic functionality of matho-primes: 62 | ./matho-primes 10000000000000 10000000300000 twin >test.out && diff -u --strip-trailing-cr twins.out test.out 63 | @rm test.out 64 | @echo Small primes test passed. 65 | @echo 66 | 67 | bigtest: 68 | @echo Testing that long doubles are fully functional in matho-primes: 69 | time -p ./matho-primes 100000000000000000 100000000000300000 twin >bigtest.out && diff -u --strip-trailing-cr bigtwins.out bigtest.out 70 | @rm bigtest.out 71 | @echo Big primes test passed. 72 | @echo 73 | 74 | # Same as "make bigtest", except doesn't run the time command. 75 | bigcheck: 76 | @echo Testing that long doubles are fully functional in matho-primes: 77 | ./matho-primes 100000000000000000 100000000000300000 twin >bigtest.out && diff -u --strip-trailing-cr bigtwins.out bigtest.out 78 | @rm bigtest.out 79 | @echo Big primes test passed. 80 | @echo 81 | 82 | install: 83 | $(INSTALL) -d $(DESTDIR)$(bindir) 84 | $(INSTALL) -d $(DESTDIR)$(mandir)/man1 85 | $(INSTALL_PROGRAM) $(EXECUTABLES) $(DESTDIR)$(bindir) 86 | $(INSTALL_DATA) $(MAN1) $(DESTDIR)$(mandir)/man1 87 | @echo 88 | @echo The Prime Number Tools are installed. 89 | 90 | uninstall: 91 | cd $(DESTDIR)$(bindir) && rm -f $(EXECUTABLES) 92 | cd $(DESTDIR)$(mandir)/man1 && rm -f $(MAN1) 93 | @echo 94 | @echo Prime Number Tools uninstall completed. 95 | 96 | clean: 97 | rm -f *.o *.pyc *.pyo 98 | rm -f test.out bigtest.out 99 | 100 | flush distclean maintainer-clean: clean 101 | rm -f *.a 102 | rm -f $(TARGETS) 103 | rm -f *.exe 104 | -------------------------------------------------------------------------------- /primes/matho-mult: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Python program to multiply many large integers separated by spaces or newlines. 4 | # The integers to multiply may be entered on the command-line or into standard input. 5 | 6 | # Used by "primorial" with "matho-primes" to calculate large primorials. 7 | # A primorial is the product of all primes up to a given number. 8 | 9 | import string 10 | import sys 11 | 12 | prod = 1 # initialize product and make it an integer 13 | args = sys.argv[1:] 14 | if (args == []): 15 | # read stdin if no command line args 16 | while True: 17 | try: 18 | input_line = raw_input() 19 | except: 20 | break; 21 | for s in string.split(input_line): 22 | prod *= int(s) 23 | else: 24 | # multiply together the command-line args 25 | for arg in args: 26 | prod *= int(arg) 27 | print prod 28 | -------------------------------------------------------------------------------- /primes/matho-mult.1: -------------------------------------------------------------------------------- 1 | .TH MATHO-MULT 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | matho-mult \- multiply large integers 5 | 6 | .SH SYNOPSIS 7 | .B matho-mult 8 | [integers] 9 | 10 | .SH DESCRIPTION 11 | This command-line utility is optionally part of the 12 | .BR mathomatic (1) 13 | package. 14 | It uses Python to multiply many large integers separated by spaces or newlines. 15 | The size of the integers is only limited by the available memory of the computer. 16 | The single integer result is output to standard output, followed by a newline. 17 | 18 | The integers to multiply may be specified on the command line or 19 | read from standard input. 20 | 21 | .SH AUTHOR 22 | George Gesslein II (gesslein@mathomatic.org) 23 | at "http://www.mathomatic.org". 24 | 25 | .SH "REPORTING BUGS" 26 | If you find a bug, please report it to the author 27 | or at "https://launchpad.net/mathomatic". 28 | 29 | .SH "SEE ALSO" 30 | .BR mathomatic (1), 31 | .BR primorial (1), 32 | .BR matho-sum (1) 33 | -------------------------------------------------------------------------------- /primes/matho-pascal.1: -------------------------------------------------------------------------------- 1 | .TH MATHO-PASCAL 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | matho-pascal \- display Pascal's triangle 5 | 6 | .SH SYNOPSIS 7 | .B matho-pascal 8 | [number-of-lines] 9 | 10 | .SH DESCRIPTION 11 | This command-line utility is optionally part of the 12 | .BR mathomatic (1) 13 | package. 14 | It calculates up to 1000 lines of Pascal's triangle using floating point arithmetic, 15 | dumping the lines to standard output. 16 | The default is to center one screen full. 17 | 18 | Every number inside Pascal's triangle is the sum of the two numbers 19 | immediately above it. 20 | 21 | Each line of Pascal's triangle is the same as the binomial coefficients 22 | for a given power. 23 | 24 | The sum of all numbers in each line of Pascal's triangle is a power of 2. 25 | 26 | .SH AUTHOR 27 | George Gesslein II (gesslein@mathomatic.org) 28 | at "http://www.mathomatic.org". 29 | 30 | .SH "REPORTING BUGS" 31 | If you find a bug, please report it to the author 32 | or at "https://launchpad.net/mathomatic". 33 | 34 | .SH "SEE ALSO" 35 | .BR mathomatic (1), 36 | .BR matho-primes (1), 37 | .BR matho-sumsq (1) 38 | -------------------------------------------------------------------------------- /primes/matho-pascal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Calculate and display Pascal's triangle. 3 | * 4 | * Copyright (C) 2005 George Gesslein II. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #if !MINGW 35 | #include 36 | #include 37 | #endif 38 | 39 | #define true 1 40 | #define false 0 41 | 42 | #ifndef LDBL_DIG 43 | #define USE_DOUBLES 1 44 | #warning "long doubles not supported by this C compiler." 45 | #endif 46 | 47 | #if USE_DOUBLES 48 | typedef double double_type; 49 | #warning "Using only double floats instead of long double floats, as requested." 50 | #else 51 | typedef long double double_type; 52 | #endif 53 | 54 | #define MAX_LINES 1000 /* max number of lines of Pascal's triangle allowed */ 55 | 56 | void allocate_triangle(void); 57 | void calculate_triangle(void); 58 | void display_triangle(void); 59 | int center_buf(int line_no, int cell_size); 60 | void usage(int ev); 61 | 62 | #if USE_DOUBLES 63 | int precision = DBL_DIG; 64 | #else 65 | int precision = LDBL_DIG; 66 | #endif 67 | int glines = 26; 68 | int gcell_size = 6; 69 | double_type *garray[MAX_LINES]; 70 | int screen_columns = 80; 71 | int centered = true; 72 | char gline_buf[1000]; 73 | 74 | char *prog_name = "matho-pascal"; 75 | 76 | int 77 | main(int argc, char *argv[]) 78 | { 79 | #if !MINGW 80 | struct winsize ws; 81 | 82 | ws.ws_col = 0; 83 | ws.ws_row = 0; 84 | ioctl(1, TIOCGWINSZ, &ws); 85 | if (ws.ws_col > 0) { 86 | screen_columns = ws.ws_col; 87 | } 88 | #endif 89 | if (screen_columns >= sizeof(gline_buf)) { 90 | screen_columns = sizeof(gline_buf) - 1; 91 | } 92 | 93 | switch (argc) { 94 | case 0: 95 | case 1: 96 | break; 97 | case 2: 98 | centered = false; 99 | if (isdigit(argv[1][0])) { 100 | glines = atoi(argv[1]); 101 | break; 102 | } 103 | default: 104 | usage(EXIT_FAILURE); 105 | } 106 | if (glines <= 0 || glines > MAX_LINES) { 107 | fprintf(stderr, "%s: Number of lines out of range (1..%d).\n", prog_name, MAX_LINES); 108 | exit(EXIT_FAILURE); 109 | } 110 | allocate_triangle(); 111 | calculate_triangle(); 112 | display_triangle(); 113 | exit(EXIT_SUCCESS); 114 | } 115 | 116 | void 117 | allocate_triangle(void) 118 | { 119 | int i; 120 | 121 | for (i = 0; i < glines; i++) { 122 | garray[i] = (double_type *) calloc(i + 1, sizeof(double_type)); 123 | if (garray[i] == NULL) { 124 | fprintf(stderr, "%s: Not enough memory.\n", prog_name); 125 | exit(EXIT_FAILURE); 126 | } 127 | } 128 | } 129 | 130 | void 131 | calculate_triangle(void) 132 | { 133 | int i, j; 134 | 135 | for (i = 0; i < glines; i++) { 136 | for (j = 0; j <= i; j++) { 137 | if (j == 0 || j == i) { 138 | garray[i][j] = 1.0; /* the line begins and ends with 1 */ 139 | } else { 140 | garray[i][j] = garray[i-1][j-1] + garray[i-1][j]; 141 | } 142 | } 143 | } 144 | } 145 | 146 | void 147 | display_triangle(void) 148 | { 149 | int i, j; 150 | int len; 151 | 152 | if (centered && glines > 20) { 153 | len = center_buf(19, 8); 154 | if (len > 0 && len < screen_columns) { 155 | gcell_size = 8; /* for very wide screens */ 156 | } 157 | } 158 | for (i = 0; i < glines; i++) { 159 | if (centered) { 160 | len = center_buf(i, gcell_size); 161 | if (len <= 0 || len >= screen_columns) { 162 | return; /* stop here because of wrap-around */ 163 | } 164 | /* center on screen */ 165 | for (j = (screen_columns - len) / 2; j > 0; j--) { 166 | printf(" "); 167 | } 168 | printf("%s", gline_buf); 169 | } else { 170 | for (j = 0; j <= i; j++) { 171 | #if USE_DOUBLES 172 | printf("%.*g ", precision, garray[i][j]); 173 | #else 174 | printf("%.*Lg ", precision, garray[i][j]); 175 | #endif 176 | } 177 | } 178 | printf("\n"); 179 | } 180 | } 181 | 182 | /* 183 | * Create a line of output in gline_buf[] for centering mode. 184 | 185 | * Return length if successful, otherwise return 0. 186 | */ 187 | int 188 | center_buf(int line_no, int cell_size) 189 | { 190 | int j, k; 191 | int i1; 192 | int len; 193 | char buf2[100]; 194 | 195 | assert(line_no < glines); 196 | gline_buf[0] = '\0'; 197 | for (j = 0; j <= line_no; j++) { 198 | #if USE_DOUBLES 199 | len = snprintf(buf2, sizeof(buf2), "%.*g", precision, garray[line_no][j]); 200 | #else 201 | len = snprintf(buf2, sizeof(buf2), "%.*Lg", precision, garray[line_no][j]); 202 | #endif 203 | assert(len > 0); 204 | if (len >= cell_size) { 205 | return(0); /* cell_size too small */ 206 | } 207 | /* center in the cell */ 208 | for (k = i1 = (cell_size - len) / 2; k > 0; k--) { 209 | strcat(gline_buf, " "); 210 | } 211 | strcat(gline_buf, buf2); 212 | for (k = len + i1; k < cell_size; k++) { 213 | strcat(gline_buf, " "); 214 | } 215 | } 216 | return(strlen(gline_buf)); 217 | } 218 | 219 | void 220 | usage(int ev) 221 | { 222 | printf("Usage: %s [number-of-lines]\n\n", prog_name); 223 | printf("Display up to %d lines of Pascal's triangle.\n", MAX_LINES); 224 | printf("If number-of-lines is specified, don't center output.\n"); 225 | printf("Number of digits of precision is %d.\n", precision); 226 | exit(ev); 227 | } 228 | -------------------------------------------------------------------------------- /primes/matho-primes.1: -------------------------------------------------------------------------------- 1 | .TH MATHO-PRIMES 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | matho-primes \- generate consecutive prime numbers 5 | 6 | .SH SYNOPSIS 7 | .B matho-primes 8 | [start [stop] or "all"] ["twin"] ["pal" [base]] 9 | .br 10 | .B matho-primes 11 | [\-htuv] [\-c count] [\-m number] [\-p base] [start [stop]] 12 | 13 | .SH DESCRIPTION 14 | This command-line utility is optionally part of the 15 | .BR mathomatic (1) 16 | package. 17 | It quickly computes any number of consecutive prime numbers 18 | using a windowing, memory efficient 19 | sieve of Eratosthenes algorithm, dumping them to standard output. 20 | They are displayed one prime per line in ascending order, 21 | unless the "twin" option is specified, 22 | which displays only twin primes, two primes per line. 23 | 24 | Generates up to 18 decimal digit primes, 25 | or whatever is the number of digits of precision for a floating point 26 | .B long double 27 | in the C compiler used to compile this utility. 28 | Note that this utility might be compiled to use only double precision floating point, 29 | if long double precision is not fully supported by the C compiler or hardware, 30 | allowing at most 15 decimal digit primes in that case. 31 | 32 | Ways to verify that this utility is working are to pipe the output into the Unix "factor" utility, 33 | or compare the output with the BSD Games "primes" utility, using the supplied shell script: 34 | .B examples/testprimes. 35 | 36 | All numbers displayed by this utility 37 | are decimal (base 10) prime numbers. 38 | A prime number is an integer that cannot be factored. 39 | 40 | A range may be 41 | specified on the command line, otherwise the starting number and 42 | the number of primes to output is prompted for. 43 | The range is 44 | .B start 45 | to 46 | .B stop 47 | inclusive, and 48 | .B stop 49 | must 50 | be greater than or equal to 51 | .B start. 52 | 53 | If the 54 | .B \-c 55 | option is specified, the number of lines of primes displayed is limited to the 56 | decimal count that follows this option. 57 | 58 | If the 59 | .B \-t 60 | or "twin" option is specified on the command line, 61 | only 62 | .B twin primes 63 | will be displayed. 64 | Twin primes are two primes that differ in value by 2. 65 | Each twin pair is displayed together on the same line separated by a space character. 66 | 67 | If the 68 | .B \-p 69 | or "pal" option is specified on the command line, 70 | only 71 | .B palindromic primes 72 | are displayed. 73 | Palindromes are symmetrical, they read exactly the same forward and backward. 74 | The palindromic number 75 | .B base 76 | may be specified, the default is base 10. 77 | The 78 | .B base 79 | can be any integer greater than 1. 80 | Primes are always displayed in decimal (base 10). 81 | 82 | The version number and 83 | short help on the allowed command-line parameters and usage information 84 | are displayed when given the 85 | .B \-h 86 | option. 87 | 88 | With the 89 | .B \-u 90 | option, all output (standard output and standard error output) 91 | is set to be unbuffered, making all output happen immediately, 92 | instead of when the output buffer is full or when the program terminates 93 | or waits for input. 94 | 95 | The 96 | .B \-m 97 | option changes the memory size of the prime number sieve window. 98 | It is followed by a decimal, floating point number which is a multiplier 99 | of the default window size (2 megabytes). 100 | It is possible that changing the memory size may speed up the total run time a bit; 101 | otherwise there is no reason to use this option, and its use is not recommended. 102 | 103 | The 104 | .B \-v 105 | option simply displays the program name and version number, and then exits successfully. 106 | 107 | .SH AUTHOR 108 | George Gesslein II (gesslein@mathomatic.org) 109 | at "http://www.mathomatic.org". 110 | 111 | .SH "REPORTING BUGS" 112 | If you find a bug, please report it to the author 113 | or at "https://launchpad.net/mathomatic". 114 | 115 | .SH "SEE ALSO" 116 | .BR rmath (1), 117 | .BR mathomatic (1), 118 | .BR primorial (1), 119 | .BR matho-mult (1), 120 | .BR matho-sum (1), 121 | .BR matho-pascal (1), 122 | .BR matho-sumsq (1) 123 | -------------------------------------------------------------------------------- /primes/matho-sum: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Python program to sum many large integers separated by spaces or newlines. 4 | # The integers to sum may be entered on the command-line or into standard input. 5 | 6 | import string 7 | import sys 8 | 9 | sum = 0 # initialize sum and make it an integer 10 | args = sys.argv[1:] 11 | if (args == []): 12 | # read stdin if no command line args 13 | while True: 14 | try: 15 | input_line = raw_input() 16 | except: 17 | break; 18 | for s in string.split(input_line): 19 | sum += int(s) 20 | else: 21 | # sum together the command-line args 22 | for arg in args: 23 | sum += int(arg) 24 | print sum 25 | -------------------------------------------------------------------------------- /primes/matho-sum.1: -------------------------------------------------------------------------------- 1 | .TH MATHO-SUM 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | matho-sum \- sum large integers 5 | 6 | .SH SYNOPSIS 7 | .B matho-sum 8 | [integers] 9 | 10 | .SH DESCRIPTION 11 | This command-line utility is optionally part of the 12 | .BR mathomatic (1) 13 | package. 14 | It uses Python to sum many large integers separated by spaces or newlines. 15 | The size of the integers is only limited by the available memory of the computer. 16 | The single integer result is output to standard output, followed by a newline. 17 | 18 | The integers to sum may be specified on the command line or 19 | read from standard input. 20 | 21 | .SH AUTHOR 22 | George Gesslein II (gesslein@mathomatic.org) 23 | at "http://www.mathomatic.org". 24 | 25 | .SH "REPORTING BUGS" 26 | If you find a bug, please report it to the author 27 | or at "https://launchpad.net/mathomatic". 28 | 29 | .SH "SEE ALSO" 30 | .BR mathomatic (1), 31 | .BR primorial (1), 32 | .BR matho-mult (1) 33 | -------------------------------------------------------------------------------- /primes/matho-sumsq.1: -------------------------------------------------------------------------------- 1 | .TH MATHO-SUMSQ 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | matho-sumsq \- Find the minimum sum of the squares for integers 5 | 6 | .SH SYNOPSIS 7 | .B matho-sumsq 8 | .RI [ numbers ] 9 | 10 | .SH DESCRIPTION 11 | This command-line utility is optionally part of the 12 | .BR mathomatic (1) 13 | package. 14 | It finds the minimum number of positive integers that when squared 15 | and added together, equal the given number. There is a proof that no more 16 | than 4 squares summed together are required to represent any positive 17 | integer. 18 | 19 | The command-line may contain positive integers to find the minimum squares of, 20 | they must be less than 2147483648 (2^31) on 32-bit systems or 21 | less than 9223372036854775808 (2^63) on 64-bit systems. 22 | If "+" is appended to the given number, 23 | the program counts up from the given number. 24 | If the minimum number of squares is 2, 25 | this program displays all possible combinations with 2 squares for the given number, 26 | otherwise it just displays the first combination it finds. 27 | 28 | If no command-line arguments are given, the programs reads the numbers from 29 | standard input. 30 | 31 | .SH AUTHOR 32 | George Gesslein II (gesslein@mathomatic.org) 33 | at "http://www.mathomatic.org". 34 | 35 | .SH "REPORTING BUGS" 36 | If you find a bug, please report it to the author 37 | or at "https://launchpad.net/mathomatic". 38 | 39 | .SH "SEE ALSO" 40 | .BR mathomatic (1), 41 | .BR matho-pascal (1), 42 | .BR matho-primes (1) 43 | -------------------------------------------------------------------------------- /primes/matho-sumsq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Find and display the minimum sum of the squares for integers. 3 | * 4 | * Copyright (C) 2007 George Gesslein II. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | /* 26 | * Usage: matho-sumsq [numbers] 27 | * 28 | * This program finds the minimum number of positive integers squared 29 | * and summed to equal a given positive integer. If the number of squared 30 | * integers is 2 (default "multi"), all combinations with 2 squares are displayed, 31 | * otherwise only the first solution found is displayed. 32 | * 33 | * If nothing is specified on the command line, the program gets its numbers from standard input. 34 | * 35 | * This file is mostly useful for testing the long integer square root function lsqrt() in file "lsqrt.c". 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #define true 1 45 | #define false 0 46 | 47 | #define squared(a) ((a) * (a)) 48 | 49 | int multi = 2; /* display all combinations for this number of squares or less */ 50 | 51 | long squares[4]; 52 | 53 | long lsqrt(long y); 54 | 55 | /* 56 | * Find the sum of "n" squares that equal "d1" and display if found. 57 | * 58 | * Return false if not found. 59 | */ 60 | int 61 | sumsq(long d1, int n) 62 | { 63 | int i = 0; 64 | long d2; 65 | long save = 0; 66 | int found_one = false; 67 | 68 | d2 = d1; 69 | try_again: 70 | for (;;) { 71 | if (i == 2) { 72 | save = d2; 73 | } 74 | squares[i] = lsqrt(d2); 75 | assert(squares[i] >= 0); 76 | d2 -= squared(squares[i]); 77 | i++; 78 | if (i >= n) { 79 | break; 80 | } 81 | } 82 | if (d2 == 0) { 83 | for (i = 0; i < n; i++) { 84 | d2 += squared(squares[i]); 85 | } 86 | if (d2 != d1) { 87 | fprintf(stderr, "Error: Result doesn't compare identical to original number!\n"); 88 | exit(EXIT_FAILURE); 89 | } 90 | for (i = 0; i < (n - 1); i++) { 91 | if (squares[i] < squares[i+1]) { 92 | goto skip_print; 93 | } 94 | } 95 | found_one = true; 96 | printf("%ld = %ld^2", d1, squares[0]); 97 | for (i = 1; i < n; i++) { 98 | if (squares[i] != 0) 99 | printf(" + %ld^2", squares[i]); 100 | } 101 | printf("\n"); 102 | skip_print: 103 | assert(found_one); 104 | if (n < 2 || n > multi) { 105 | return found_one; 106 | } 107 | } 108 | switch (n) { 109 | case 4: 110 | if (squares[2] > squares[n-1]) { 111 | squares[2] -= 1; 112 | d2 = save - squared(squares[2]); 113 | i = 3; 114 | goto try_again; 115 | } 116 | case 3: 117 | if (squares[1] > squares[n-1]) { 118 | squares[1] -= 1; 119 | d2 = d1 - squared(squares[0]) - squared(squares[1]); 120 | i = 2; 121 | goto try_again; 122 | } 123 | case 2: 124 | if (squares[0] > squares[n-1]) { 125 | squares[0] -= 1; 126 | d2 = d1 - squared(squares[0]); 127 | i = 1; 128 | goto try_again; 129 | } 130 | } 131 | return found_one; 132 | } 133 | 134 | /* 135 | * Display the shortest sums of squares for long integer "d1". 136 | * 137 | * Return the minimum number of summed squares required to represent "d1". 138 | */ 139 | int 140 | findsq(long d1) 141 | { 142 | if (sumsq(d1, 1)) 143 | return 1; 144 | if (sumsq(d1, 2)) 145 | return 2; 146 | if (sumsq(d1, 3)) 147 | return 3; 148 | if (sumsq(d1, 4)) 149 | return 4; 150 | fprintf(stderr, "Whoops! Can't find the sum of four squares that equal %ld.\n", d1); 151 | exit(EXIT_FAILURE); 152 | } 153 | 154 | int 155 | main(int argc, char *argv[]) 156 | { 157 | int i; 158 | long d1 = 0; 159 | char *cp, buf[1000]; 160 | 161 | if (argc > 1) { 162 | for (i = 1; i < argc; i++) { 163 | errno = 0; 164 | d1 = strtol(argv[i], &cp, 10); 165 | if (errno) { 166 | perror(argv[i]); 167 | exit(EXIT_FAILURE); 168 | } 169 | if (d1 < 0) { 170 | fprintf(stderr, "Invalid command-line argument: \"%s\", positive integer required.\n", argv[i]); 171 | exit(EXIT_FAILURE); 172 | } 173 | if (*cp == '+') { 174 | for (;; d1 += 1) { 175 | findsq(d1); 176 | } 177 | exit(EXIT_SUCCESS); 178 | } 179 | if (argv[i][0] == '\0' || *cp) { 180 | fprintf(stderr, "Invalid number: \"%s\".\n", argv[i]); 181 | exit(EXIT_FAILURE); 182 | } 183 | findsq(d1); 184 | } 185 | } else { 186 | for (fflush(NULL); fgets(buf, sizeof(buf), stdin); fflush(NULL)) { 187 | errno = 0; 188 | d1 = strtol(buf, &cp, 10); 189 | if (errno) { 190 | perror(NULL); 191 | continue; 192 | } 193 | if (cp != buf && d1 == 0) { 194 | exit(EXIT_SUCCESS); 195 | } 196 | if (d1 <= 0) { 197 | fprintf(stderr, "Positive integer required; 0 to quit.\n"); 198 | continue; 199 | } 200 | findsq(d1); 201 | } 202 | } 203 | exit(EXIT_SUCCESS); 204 | } 205 | -------------------------------------------------------------------------------- /primes/primorial: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This is a Python program to display large primorials. 4 | # A primorial is the product of all primes up to the given number. 5 | # Uses the programs "matho-primes" and "matho-mult" as follows: 6 | # primorial 1000 7 | # runs: 8 | # matho-primes 0 1000 | matho-mult 9 | # 10 | # For fun, try: 11 | # primorial `matho-primes 2 97` 12 | # 13 | # to display all unique primorials from 2 to 97. 14 | 15 | import os 16 | import sys 17 | 18 | def usage(ev): 19 | print "This program calculates large primorials." 20 | print 21 | print "Usage: %s integers" % os.path.basename(sys.argv[0]) 22 | print 23 | print "A primorial is the product of all primes up to the given number." 24 | sys.exit(ev) 25 | 26 | def output_primorial(arg): 27 | sys.stdout.write(arg + "# = ") 28 | sys.stdout.flush() 29 | if (os.system("matho-primes 0 " + arg + " | matho-mult") != 0): 30 | sys.exit(1) 31 | 32 | args = sys.argv[1:] 33 | if (args == []): 34 | usage(2) 35 | else: 36 | for arg in args: 37 | try: 38 | if (int(arg) < 1): 39 | print >>sys.stderr, "Number too small." 40 | sys.exit(1) 41 | except: 42 | print >>sys.stderr, "Positive integer required." 43 | usage(1) 44 | output_primorial(arg) 45 | -------------------------------------------------------------------------------- /primes/primorial.1: -------------------------------------------------------------------------------- 1 | .TH PRIMORIAL 1 "" "Mathomatic" "Mathomatic Utilities" 2 | 3 | .SH NAME 4 | primorial \- calculate large primorials 5 | 6 | .SH SYNOPSIS 7 | .B primorial 8 | integers 9 | 10 | .SH DESCRIPTION 11 | This command-line utility is optionally part of the 12 | .BR mathomatic (1) 13 | package. 14 | It uses Python and 15 | .BR matho-primes (1) 16 | and 17 | .BR matho-mult (1) 18 | to calculate and display large primorials. 19 | 20 | A primorial is the product of all primes up to the given integer. 21 | The integers to show the primorials of are given on the command line. 22 | 23 | The calculated primorials are output to standard output. 24 | The size is limited by the amount of computer memory available. 25 | 26 | .SH AUTHOR 27 | George Gesslein II (gesslein@mathomatic.org) 28 | at "http://www.mathomatic.org". 29 | 30 | .SH "REPORTING BUGS" 31 | If you find a bug, please report it to the author 32 | or at "https://launchpad.net/mathomatic". 33 | 34 | .SH "SEE ALSO" 35 | .BR mathomatic (1), 36 | .BR matho-mult (1), 37 | .BR matho-primes (1) 38 | -------------------------------------------------------------------------------- /primes/t: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script to test the Mathomatic prime number tools. 3 | 4 | set -e 5 | set -u 6 | 7 | trap "rm -f test.out bigtest.out" EXIT 8 | 9 | make -j2 check bigcheck 10 | 11 | echo Testing matho-pascal... 12 | ./matho-pascal >/dev/null 13 | 14 | echo Testing matho-sumsq... 15 | ./matho-sumsq 12146807 50000000 >/dev/null 16 | 17 | echo Prime number tools tests successful. 18 | -------------------------------------------------------------------------------- /rmath.1: -------------------------------------------------------------------------------- 1 | .TH RMATH 1 2 | 3 | .SH NAME 4 | rmath \- a computer algebra system with functions and readline 5 | .br 6 | matho \- a computer algebra system with functions 7 | 8 | .SH SYNOPSIS 9 | .B rmath 10 | [ 11 | input_files 12 | ] 13 | .br 14 | .B matho 15 | [ 16 | input_files 17 | ] 18 | 19 | .SH DESCRIPTION 20 | Mathomatic is a general-purpose computer algebra system (CAS) 21 | that can symbolically solve, simplify, combine, and compare algebraic equations, 22 | perform standard, complex number, modular, and polynomial arithmetic, etc. 23 | It does some calculus and handles all elementary algebra, except logarithms. 24 | Plotting expressions with 25 | .B gnuplot 26 | is also supported. 27 | 28 | .B rmath 29 | and 30 | .B matho 31 | are shell scripts that allow you 32 | to use Mathomatic with input of functions like 33 | .BI sin (x) 34 | and 35 | .BI sqrt (x) 36 | automatically expanded to equivalent algebraic expressions 37 | by the 38 | .B m4 39 | macro preprocessor. 40 | A matching pair of parentheses is required around the parameters for all functions in m4 Mathomatic; m4 requires this. 41 | .B rmath 42 | also runs the 43 | .B rlwrap 44 | readline wrapper utility if available, to provide readline input editing support similar to 45 | that provided by 46 | .BR mathomatic (1). 47 | 48 | .B rmath 49 | and 50 | .B matho 51 | define and enable named math functions in Mathomatic. 52 | Most functions enabled here should be real number, complex number, and symbolically capable. 53 | One exception is the 54 | .BI abs (x) 55 | function, which doesn't work with complex numbers, because it is defined 56 | in Mathomatic as (((x)^2)^.5). 57 | 58 | The following general functions are defined when using 59 | .B rmath 60 | or 61 | .B matho: 62 | .BI sqrt (x), 63 | .BI cbrt (x), 64 | .BI exp (x), 65 | .BI pow (x,y), 66 | .BI abs (x), 67 | .BI sgn (x), 68 | .BI factorial (x), 69 | .BI gamma (x), 70 | .BI floor (x), 71 | .BI ceil (x), 72 | .BI int (x), 73 | and 74 | .BI round (x). 75 | 76 | The following standard trigonometric functions are defined: 77 | .BI sin (x), 78 | .BI cos (x), 79 | .BI tan (x), 80 | .BI cot (x), 81 | .BI sec (x), 82 | and 83 | .BI csc (x). 84 | .BI sinc (x) 85 | is the normalized sinc function, defined as 86 | .BI sin (pi*x) /(pi*x) . 87 | 88 | The following standard hyperbolic trigonometric functions are defined: 89 | .BI sinh (x), 90 | .BI cosh (x), 91 | .BI tanh (x), 92 | .BI coth (x), 93 | .BI sech (x), 94 | and 95 | .BI csch (x). 96 | 97 | The following universal constants are defined: 98 | .I pi, 99 | .I e, 100 | .I i 101 | (the imaginary unit), 102 | .I euler 103 | (the Euler-Mascheroni constant), 104 | .I omega, 105 | and 106 | .I phi 107 | (the golden ratio). 108 | 109 | .SH GENERAL 110 | Text files may be specified on the shell command line 111 | that will be automatically read in through the m4 preprocessor into Mathomatic. 112 | After any files are read in, Mathomatic prompts for input from the console. 113 | 114 | Mathomatic is best run from within a terminal emulator. 115 | It uses console line input and output for the user interface. 116 | First you type in your mathematical equations in standard algebraic notation, 117 | then you can solve them by typing in the variable name at the prompt, or 118 | perform operations on them with simple English commands. 119 | Type "help" or "?" for the help command, 120 | "help examples" to get started. 121 | If the command name is longer than 4 letters, you only need 122 | to type in the first 4 letters. 123 | Most commands operate on the current equation by default. 124 | 125 | Complete documentation is available in HTML and PDF formats; 126 | see the local documentation directory or online at "http://mathomatic.org/math/doc/" 127 | for the latest Mathomatic documentation. 128 | 129 | .SH FILES 130 | .TP 131 | .B ~/.mathomaticrc 132 | Optional startup file containing Mathomatic set command options. 133 | It should be a text file with one or more set options per line. 134 | For example, the line "no color" will make Mathomatic default to non-color mode, 135 | which is useful if you aren't using a supported color device. 136 | 137 | .SH AUTHOR 138 | Mathomatic has been written by George Gesslein II (gesslein@mathomatic.org), 139 | with help from the Internet community. 140 | 141 | .SH "REPORTING BUGS" 142 | Please report any bugs to the author or 143 | on the Launchpad website: "https://launchpad.net/mathomatic". 144 | 145 | .SH "SEE ALSO" 146 | .BR mathomatic (1), 147 | .BR matho-primes (1), 148 | .BR primorial (1), 149 | .BR matho-mult (1), 150 | .BR matho-sum (1), 151 | .BR matho-pascal (1), 152 | .BR matho-sumsq (1) 153 | -------------------------------------------------------------------------------- /standard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A standard include file for all math programs written in C. 3 | * 4 | * Copyright (C) 1987-2012 George Gesslein II. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | The chief copyright holder can be contacted at gesslein@mathomatic.org, or 21 | George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 22 | 23 | */ 24 | 25 | #ifndef M_EULER 26 | #define M_EULER 0.57721566490153286060651209008 /* Euler-Mascheroni constant (from GSL) */ 27 | #endif 28 | #ifndef M_PI 29 | #define M_PI 3.14159265358979323846 /* pi */ 30 | #endif 31 | #ifndef M_E 32 | #define M_E 2.7182818284590452354 /* e */ 33 | #endif 34 | 35 | #ifndef max 36 | #define max(a, b) (((a) > (b)) ? (a) : (b)) /* return the maximum of two values */ 37 | #endif 38 | #ifndef min 39 | #define min(a, b) (((a) < (b)) ? (a) : (b)) /* return the minimum of two values */ 40 | #endif 41 | 42 | #ifndef INFINITY 43 | #define INFINITY HUGE_VAL /* the floating point, positive infinity constant */ 44 | #endif 45 | 46 | #ifndef isfinite 47 | #define isfinite(d) finite(d) /* true if double d is finite (not infinity nor NaN) */ 48 | #endif 49 | 50 | #ifndef isinf 51 | #if sun /* reconstruct missing isinf() function */ 52 | #define isinf(d) ((fpclass(d) == FP_PINF) - (fpclass(d) == FP_NINF)) 53 | #endif 54 | #endif 55 | 56 | #define ARR_CNT(a) ((int) (sizeof(a)/sizeof(a[0]))) /* returns the number of elements in an array */ 57 | #define CLEAR_ARRAY(a) memset(a, 0, sizeof(a)) /* quickly sets all elements of an array to zero */ 58 | -------------------------------------------------------------------------------- /t: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Shell script to test Mathomatic. 3 | 4 | if make --version >/dev/null 2>&1 5 | then 6 | set -x 7 | make test 8 | else 9 | set -x 10 | gmake test 11 | fi 12 | -------------------------------------------------------------------------------- /tests/README.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory contains only Mathomatic scripts. They include tests, 3 | examples, short tutorials, and educational math toys. 4 | 5 | To run all of the tests on a Unix compatible system 6 | and check their output, type "./t". 7 | 8 | To run a specific script, type "mathomatic script-name", 9 | or "read script-name" from within Mathomatic. 10 | 11 | To run a specific script, and create a complete HTML output file 12 | from it, type "./demo script-name". 13 | 14 | Look around and have fun! Feel free to contribute your Mathomatic scripts. 15 | Here are the good examples and lessons that are available in this directory: 16 | 17 | all.in - script that reads in all test scripts 18 | circles.in - uses eliminate command to combine the equations for 2 circles 19 | collatz.in - the Collatz conjecture as an equation 20 | cubic.in - calculate the 3 solutions of any cubic polynomial equation 21 | cubic2.in - general cubic polynomial formula using 2 equations 22 | demo.in - a demonstration of differentiation and Taylor series 23 | distance.in - derive the shortest distance between a point and a line in 2D 24 | electronics.in - a few electrical formulas 25 | ellipse.in - 2D equations for ellipses 26 | examples.in - some simple examples of Mathomatic in action 27 | fibonacci.in - direct formula to calculate phi and any Fibonacci number 28 | finance.in - derivation of the present value annuity formula 29 | fraction.in - shows how "simplify fraction" and "unfactor fraction" work 30 | heart.in - plot a heart with gnuplot 31 | heron.in - tutorial for the area formula of any triangle and derivations 32 | how_limit_works.in - how the experimental limit command works 33 | linear.in - combine 3 simultaneous linear equations with 3 unknowns 34 | pie.in - how to approximate the universal constants pi and e 35 | points.in - derive simple equations from 2 or 3 points in 2 dimensions 36 | poly.in - combine 3 quadratic equations with 3 unknown coefficients 37 | pyth3d.in - arrives at the distance between two points in 3D space 38 | quadratic.in - derives the general quadratic (2nd degree polynomial) formula 39 | quartic.in - calculate the 4 solutions of quartic polynomial equations 40 | radius.in - some fun formulas for the radius of a circle 41 | 42 | Some "rmath" (or "matho") only scripts: 43 | 44 | trig - creates an equation for each trigonometry function 45 | batman_plot - Batman equations plot the Batman logo 46 | 47 | Install m4 Mathomatic and type "rmath script-name" to run rmath scripts. 48 | -------------------------------------------------------------------------------- /tests/all.in: -------------------------------------------------------------------------------- 1 | ; This is a Mathomatic script that reads in all test scripts. 2 | 3 | clear all 4 | ; Test simplifying trig functions: 5 | read trig.in 6 | read hypertrig.in 7 | simplify all 8 | simplify frac all 9 | ; Let's simplify some trig identities without using m4: 10 | sin^2+cos^2=1 11 | elim all 12 | simplify 13 | tan=sin/cos 14 | elim all 15 | csc=1/sin 16 | elim all 17 | sec=1/cos 18 | elim all 19 | cot=1/tan 20 | elim all 21 | 1+tan^2=sec^2 22 | elim all 23 | cosh^2-sinh^2=1 ; The main hyperbolic trigonometry identity: 24 | elim all 25 | ; Now verify them all, to show and check the new solve command usage. 26 | solve 13-19 verifiable 0 27 | pause 28 | clear all 29 | ; Next, test fixed-point mode and some financial equations: 30 | read finance 31 | a=55/-3 32 | list 33 | display mixed 34 | display mixed factor 35 | display simple 36 | list 37 | display 38 | set no fixed_point 39 | display 40 | clear all 41 | read quadratic 42 | clear all 43 | read electronics 44 | simplify all 45 | clear all 46 | read fibonacci 47 | clear all 48 | read test 49 | clear all 50 | read fraction 51 | clear all 52 | read pie 53 | 1 54 | fraction 55 | read demo 56 | read limits 57 | ; read how_limit_works 58 | read test3 59 | read poly 60 | clear all 61 | read examples 62 | clear all 63 | read test1 64 | read test2 65 | read test6 66 | clear all 67 | read simplify 68 | read heron 69 | clear all 70 | read radius 71 | clear all 72 | read pyth3d 73 | clear all 74 | read distance 75 | clear all 76 | read circles 77 | clear all 78 | read ellipse 79 | solve all y 80 | simplify all 81 | pause 82 | clear all 83 | help examples 84 | clear all 85 | help conversions 86 | simplify all 87 | clear all 88 | help geometry 89 | simplify all 90 | quit 91 | -------------------------------------------------------------------------------- /tests/batman_gnuplot_bug.in: -------------------------------------------------------------------------------- 1 | 2 | ; Read this in with mathomatic, not rmath nor matho. 3 | ; These are the Batman equations. 4 | ; They plot the Batman logo using many absolute value functions with gnuplot. 5 | ; This plot proves gnuplot has a bug in it, because it doesn't come out quite right. 6 | ; There are 4 expressions simultaneously plotted here; 7 | ; it is the first, and longest, expression that comes out wrong. 8 | ; If you plot this in Google or Lybniz, it comes out right. 9 | 10 | plot 1.5*sqrt((-abs(abs(x)-1))*abs(3-abs(x))/((abs(x)-1)*(3-abs(x))))*(1+abs(abs(x)-3)/(abs(x)-3))*sqrt(1-(x/7)^2)+(4.5+0.75*(abs(x-0.5)+abs(x+0.5))-2.75*(abs(x-0.75)+abs(x+0.75)))*(1+abs(1-abs(x))/(1-abs(x))),(-3)*sqrt(1-(x/7)^2)*sqrt(abs(abs(x)-4)/(abs(x)-4)),abs(x/2)-0.0913722*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2),(2.71052+1.5-0.5*abs(x)-1.35526*sqrt(4-(abs(x)-1)^2))*sqrt(abs(abs(x)-1)/(abs(x)-1)) 11 | 12 | ; If readline is enabled, 13 | ; hitting the up arrow, then the Enter key, should allow a replot. 14 | :push plot 1.5*sqrt((-abs(abs(x)-1))*abs(3-abs(x))/((abs(x)-1)*(3-abs(x))))*(1+abs(abs(x)-3)/(abs(x)-3))*sqrt(1-(x/7)^2)+(4.5+0.75*(abs(x-0.5)+abs(x+0.5))-2.75*(abs(x-0.75)+abs(x+0.75)))*(1+abs(1-abs(x))/(1-abs(x))),(-3)*sqrt(1-(x/7)^2)*sqrt(abs(abs(x)-4)/(abs(x)-4)),abs(x/2)-0.0913722*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2),(2.71052+1.5-0.5*abs(x)-1.35526*sqrt(4-(abs(x)-1)^2))*sqrt(abs(abs(x)-1)/(abs(x)-1)) 15 | -------------------------------------------------------------------------------- /tests/batman_plot: -------------------------------------------------------------------------------- 1 | 2 | ; These are the Batman equations. 3 | ; They plot the Batman logo using many absolute value functions. 4 | ; This is a good test of absolute value simplification. 5 | ; To read in, install m4 Mathomatic and type "rmath batman_plot". 6 | 7 | y=1.5*sqrt((-abs(abs(x)-1))*abs(3-abs(x))/((abs(x)-1)*(3-abs(x))))*(1+abs(abs(x)-3)/(abs(x)-3))*sqrt(1-(x/7)^2)+(4.5+0.75*(abs(x-0.5)+abs(x+0.5))-2.75*(abs(x-0.75)+abs(x+0.75)))*(1+abs(1-abs(x))/(1-abs(x))) 8 | y=(-3)*sqrt(1-(x/7)^2)*sqrt(abs(abs(x)-4)/(abs(x)-4)) 9 | y=abs(x/2)-0.0913722*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2) 10 | y=(2.71052+1.5-0.5*abs(x)-1.35526*sqrt(4-(abs(x)-1)^2))*sqrt(abs(abs(x)-1)/(abs(x)-1)) 11 | ; Type "plot all" to see the batman logo. 12 | ; Test the simplify command by typing "repeat simplify all" 13 | ; then "plot all" again, making sure it is exactly the same plot. 14 | -------------------------------------------------------------------------------- /tests/circles.in: -------------------------------------------------------------------------------- 1 | 2 | ; This is a simple example of eliminate command usage. 3 | ; Combine the equations for 2 circles of radius "r" on a 2D Cartesian plane 4 | ; to find the points of intersection (x, y). 5 | 6 | (x-x1)^2+(y-y1)^2=r^2 ; circle of radius "r" with center at (x1, y1) 7 | (x-x2)^2+(y-y2)^2=r^2 ; circle of radius "r" with center at (x2, y2) 8 | eliminate x ; combine the two equations, removing the x variable from the result 9 | solve for y 10 | repeat simplify 11 | -------------------------------------------------------------------------------- /tests/collatz.in: -------------------------------------------------------------------------------- 1 | 2 | ; The Collatz conjecture as a mathematical feedback equation: 3 | out = (in/2) - (((5*in) + 2)*(((-1)^in) - 1)/4) 4 | ; Prove that feeding "out" into "in" will 5 | ; always eventually count down to the number 1. 6 | ; Run with the command "calc in". 7 | ; Repeatedly prompt with the command "repeat calc in". 8 | ; See all intermediate in/out values by typing "set debug 1" beforehand. 9 | -------------------------------------------------------------------------------- /tests/cubic.in: -------------------------------------------------------------------------------- 1 | 2 | ; General cubic (3rd degree polynomial) formula using 3 equations. 3 | ; Formula for the 3 roots (solutions for x) of the general 3rd degree polynomial equation. 4 | ; These formulas always seem to work correctly, whether imaginary or real solutions. 5 | ; 6 | ; This is currently the only way to solve cubic polynomials in Mathomatic, 7 | ; by manually entering the coefficients (a, b, c, and d) into the following equations. 8 | ; To visualize the coefficients of a polynomial equation: 9 | ; solve for 0 10 | ; unfactor 11 | ; factor x 12 | ; 13 | ; See also file "cubic2.in" for using 2 equations instead of 3. 14 | 15 | a x^3 + b x^2 + c x + d = 0 ; The general cubic equation. 16 | x_1=-b/{3 a}-1/{3 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)-1/{3 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3) 17 | x_2=-b/{3 a}+{1+i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)+{1-i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3) 18 | x_3=-b/{3 a}+{1-i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)+{1+i 3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3) 19 | ; x_1, x_2, and x_3 are the solutions to the given general cubic equation. 20 | ; Type "calculate all" to temporarily plug in coefficients. 21 | -------------------------------------------------------------------------------- /tests/cubic2.in: -------------------------------------------------------------------------------- 1 | 2 | ; General cubic (3rd degree polynomial) formula using 2 equations. 3 | ; Formula for the 3 roots (solutions for x) of the general 3rd degree polynomial equation. 4 | ; These formulas always seem to work correctly, whether imaginary or real solutions. 5 | ; 6 | ; This is currently the only way to solve cubic polynomials in Mathomatic. 7 | ; This is also a good test of the optimize and "simplify quick" commands. 8 | ; Try "simplify quick all" and then "optimize all" for some true optimalism! 9 | 10 | a x^3 + b x^2 + c x + d = 0 ; The general cubic equation. 11 | ; A real solution: 12 | x_r=-b/{3 a}-1/{3 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)-1/{3 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3) 13 | ; The 2 imaginary solutions or 2 more real solutions: 14 | x_i=-b/{3 a}+{1-sign*i*3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d+{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/{2}}^(1/3)+{1+sign*i*3^.5}/{6 a} {{2 b^3-9 a b c+27 a^2 d-{(2 b^3-9 a b c+27 a^2 d)^2-4 (b^2-3 a c)^3}^.5}/2}^(1/3) 15 | ; x_r and x_i are the three solutions to the given general cubic equation. 16 | ; Type "calculate all" to temporarily plug in coefficients. 17 | -------------------------------------------------------------------------------- /tests/demo: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Create complete color html files out of Mathomatic input (*.in) files. 3 | # The result is suitable for display on a website. 4 | # Usage: ./demo script_base_filenames 5 | 6 | RUN_SUB="${0}_sub" 7 | 8 | for file in "$@" 9 | do 10 | if [ ! -f "$file.in" ] 11 | then 12 | echo $file.in not found. 13 | exit 1 14 | fi 15 | echo Doing "$file.in" with "$RUN_SUB" and tidy... 16 | "$RUN_SUB" "$file" | tidy -q -i -wrap 1000 >$file.html 17 | done 18 | -------------------------------------------------------------------------------- /tests/demo.in: -------------------------------------------------------------------------------- 1 | clear all 2 | ; Some symbolic differentiation examples follow. 3 | 4 | ; Take the derivative of the absolute value function: 5 | |x| 6 | derivative ; The result is the sign function sgn(x), which gives the sign of x. 7 | repeat echo * 8 | ; Mathomatic can differentiate anything that doesn't require symbolic logarithms. 9 | y=e^(1+1/x) 10 | derivative ; The first order derivative is: 11 | derivative ; The second order derivative is: 12 | expand fraction ; Perhaps easier to read: 13 | repeat echo * 14 | ; A Taylor series demonstration: 15 | y=x_new^n ; x_new is what we want, without using the root operator. 16 | x_new ; It is easily solved for in Mathomatic. 17 | y ; But we want an algorithm to compute it without using non-integer exponentiation. 18 | taylor x_new, 1, x_old ; build the (nth root of y) iterative approximation formula 19 | solve verifiable x_new ; solve for the output variable 20 | ; That is the convergent nth root approximation formula. 21 | copy ; "calculate x_old 10000" tests this formula, if you would like to see for yourself. 22 | replace x_old x_new with x ; make x_old (input) and x_new (output) the same 23 | x ; make sure the formula was correct by solving for x 24 | repeat echo * 25 | ; Another Taylor series demo: 26 | e^x ; enter the exponential function 27 | taylor x, 10, 0 ; generate a 10th order taylor series of the exponential function 28 | laplace x ; do a Laplace transform on it 29 | simplify ; show the structure of the result 30 | laplace inverse x ; undo the Laplace transform 31 | compare with 10 ; check the result 32 | -------------------------------------------------------------------------------- /tests/demo_sub: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Called and used only by the demo shell script. 3 | 4 | set -e 5 | set -u 6 | 7 | echo '' 8 | echo '' 9 | echo 10 | echo '' 11 | echo '' 12 | echo "Actual timed Mathomatic output from the $@ script" 13 | echo '' 14 | echo '' 15 | echo '' 16 | echo '' 17 | 18 | echo '' 19 | echo '' 20 | echo 21 | echo '' 22 | 23 | echo "

Actual timed Mathomatic output from the $@ script

" 24 | 25 | /usr/bin/time -p mathomatic -dxr "$@" &1 26 | 27 | echo 'seconds total execution time of this script.' 28 | echo '
' 29 | echo 'More examples' 30 | echo 'www.mathomatic.org' 31 | 32 | echo '' 33 | echo '' 34 | -------------------------------------------------------------------------------- /tests/distance.in: -------------------------------------------------------------------------------- 1 | 2 | ; This input arrives at the shortest distance between a point and a line 3 | ; in 2 dimensions. The point is at (x0, y0) in cartesian coordinates. 4 | ; (x, y) are the points on the line. 5 | 6 | a*x+b*y+c=0 ; equation of the line 7 | y ; solve for y 8 | unfactor fraction ; equation of the line in slope-intercept form: 9 | distance=|a*(x-x0)+b*(y-y0)|/(a^2+b^2)^.5 10 | eliminate y ; Combine the above two equations to eliminate x and y. 11 | simplify ; The beautiful answer is: 12 | ; Replacing a with -m, b with 1, and c with -b results in the shortest distance from the line y=m*x+b. 13 | -------------------------------------------------------------------------------- /tests/electronics.in: -------------------------------------------------------------------------------- 1 | 2 | ; General electrical formulas: 3 | 4 | volts=amps*ohms ; Ohm's Law, commonly solved for resistance (ohms) or current (amps). 5 | watts=volts*amps ; Power Law 6 | 1/r=1/r1+1/r2 ; Resistance (r) of 2 resistors (r1 and r2) wired in parallel. 7 | solve verifiable r ; Solve for the resulting resistance. 8 | 1/r=1/r1+1/r2+1/r3 ; Resistance (r) of 3 resistors wired in parallel. 9 | solve verifiable r ; Solve for the resulting resistance. 10 | frequency=1/(2*pi*(L*C)^.5) ; Resonant frequency of an LC circuit in hertz. 11 | ; L is the inductance in henries, and C is the capacitance in farads. 12 | -------------------------------------------------------------------------------- /tests/ellipse.in: -------------------------------------------------------------------------------- 1 | 2 | ; This is an equation for an ellipse that was created using the rule 3 | ; that the sum of the distances from any point on the perimeter (x, y) 4 | ; to the two foci: (x1, y1) and (x2, y2), is a constant k. This can 5 | ; represent any ellipse of any orientation on the Cartesian plane. 6 | 7 | k = ((x1-x)^2+(y1-y)^2)^0.5 + ((x2-x)^2+(y2-y)^2)^0.5 8 | 9 | ; A simplified equation for a right ellipse centered at the origin (0, 0) 10 | ; of the Cartesian plane: 11 | 12 | 1 = x^2/radius1^2 + y^2/radius2^2 13 | ; The x-intercepts are radius1 and -radius1 because y=0 there. 14 | ; The y-intercepts are radius2 and -radius2 because x=0 there. 15 | -------------------------------------------------------------------------------- /tests/examples.in: -------------------------------------------------------------------------------- 1 | 2 | ; This is a line comment. This script shows some simple examples of Mathomatic usage. 3 | ; Mathomatic input files are scripts that may be read in with the "read" command. 4 | 5 | ; Equations are entered by just typing or pasting them in: 6 | c^2=a^2+b^2 ; The Pythagorean theorem, "c" squared equals "a" squared plus "b" squared. 7 | ; The entered equation becomes the current equation and is displayed. 8 | ; The current equation can be solved by simply typing in a variable name: 9 | c ; which is shorthand for the solve command. Solve for variable "c". 10 | ; "sign" variables are special two-valued variables that may only be +1 or -1. 11 | solve for b ; Another way to solve for a variable, using English. 12 | ; To output programming language code, use the code command: 13 | code ; C language code is the default. 14 | 15 | code java ; Mathomatic can also generate Java 16 | 17 | code python ; and Python code. 18 | 19 | repeat echo * 20 | a=b+1/b ; Enter another equation; this is actually a quadratic equation. 21 | 0 ; Solve for zero. 22 | unfactor ; Expand, showing that this is a quadratic polynomial equation in "b". 23 | solve verifiable b ; Require solution verification with the "verifiable" option. 24 | a ; Solve back for "a" and we should get the original equation. 25 | simplify ; The simplify command makes expressions simpler and prettier. 26 | repeat echo * 27 | ; Mathomatic is also handy as an advanced calculator. 28 | ; Expressions without variables entered at the main prompt are instantly evaluated: 29 | 2+3 30 | 495/44 ; Fractions are always reduced to their simplest form: 31 | ; Fractions greater than 1 can easily be displayed as mixed fractions. 32 | display mixed ; Display above fraction as a mixed fraction: 33 | display factor ; Integers and fractions are easily factored: 34 | 2^.5 ; The square root of 2, rounded to the default 14 digits: 35 | 36 | repeat echo * 37 | ; Symbolic logarithms like log(x) are not implemented, yet. 38 | 27^y=9 ; An example that uses numeric logarithms. 39 | solve verifiable y ; Require solution verification with the "verifiable" option. 40 | 41 | repeat echo * 42 | 0=2x^2-3x-20 ; A simple quadratic equation, to show how the calculate command works. 43 | solve verifiable x ; Solve for x, plugging the results into the original equation to verify. 44 | calculate ; Expand "sign" variables and approximate the RHS (Right-Hand Side). 45 | ; The calculate command also lets you plug values into a formula with variables, if any. 46 | display; Display the current equation, showing that it was not modified by calculate. 47 | -------------------------------------------------------------------------------- /tests/fibonacci.in: -------------------------------------------------------------------------------- 1 | 2 | ; This Mathomatic input file contains the mathematical formula to 3 | ; directly calculate the "n"th Fibonacci number. 4 | ; The formula presented here is called Binet's formula, found at 5 | ; http://en.wikipedia.org/wiki/Fibonacci_number 6 | ; 7 | ; The Fibonacci sequence is the endless integer sequence: 8 | ; 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 ... 9 | ; Any Fibonacci number is always the sum of the previous two Fibonacci numbers. 10 | ; 11 | ; Easy to understand info on the golden ratio can be found here: 12 | ; http://www.mathsisfun.com/numbers/golden-ratio.html 13 | 14 | -1/phi=1-phi ; Derive the golden ratio (phi) from this quadratic polynomial. 15 | 0 ; show it is quadratic 16 | unfactor 17 | solve verifiable for phi ; The golden ratio will help us directly compute Fibonacci numbers. 18 | replace sign with -1 ; the golden ratio constant: 19 | fibonacci = ((phi^n) - ((1 - phi)^n))/(phi - (1 - phi)) ; Binet's Fibonacci formula. 20 | eliminate phi ; Completed direct Fibonacci formula: 21 | simplify ; Note that Mathomatic rationalizes the denominator here. 22 | for n 1 20 ; Display the first 20 Fibonacci numbers by plugging in values 1-20: 23 | ; Note that this formula should work for any positive integer value of n. 24 | -------------------------------------------------------------------------------- /tests/finance.in: -------------------------------------------------------------------------------- 1 | 2 | ; Combine 2 commonly used formulas to produce the mortgage payment formula. 3 | ; Here are 3 related financial formulas that can be "read" into Mathomatic. 4 | 5 | set fixed ; Enable fixed-point money mode; rounds to the nearest cent. 6 | ; First, the variable definitions: 7 | ; pv = present value 8 | ; fv = future value (maturity value) 9 | ; interest_rate = interest rate per period (1 = 100%) 10 | ; n = number of periods 11 | 12 | ; Compound Interest Future Value Formula: 13 | fv1 = pv*(1+interest_rate)^n 14 | ; Future Value Annuity Formula: 15 | fv2 = payment*(((1+interest_rate)^n-1)/interest_rate) 16 | ; Next we will combine these to produce the standard annuity formula. 17 | ; Set equal, then solve and simplify: 18 | fv1 = fv2 19 | pause 20 | eliminate all ; combine both formulas to produce the annuity formula: 21 | solve verifiable pv ; solve for present value: 22 | solve verifiable payment ; or solve for payment per period: 23 | pause End of finance tutorial 24 | ; Remember we are still in fixed-point money mode, 25 | ; unless you typed "set no fixed". 26 | -------------------------------------------------------------------------------- /tests/fix1.in: -------------------------------------------------------------------------------- 1 | clear all 2 | y = (((((a+b)/(b-c))^0.25)+(((b-c)/(a+b))^0.25)+(((a-b)*i/(b-c))^0.5))*(i^0.5))^(1/n) 3 | y = (a^a)*(1+(((a^(a^2))*(b^a))^(1/(1-a)))) 4 | y = (a^2)*(1+(((a^(2*((1.5*a)-1)))*(b^a))^(1/(1-a)))) 5 | y = (15*(d^2)/((1+(d^2))^(7/2)))-(12/((1+(d^2))^(5/2)))-6 6 | y = ((9 + (32^.5))^.5) ; should simplify to (1 + 2*(2^.5)) someday 7 | simplify symbolic all 8 | simplify all 9 | x^2=|x| 10 | solve for x 11 | x^(1/99)=x 12 | solve verifiable x 13 | (2i)^.5+e^(pi*i) 14 | (1-2i)/(3+4i) 15 | divide (1-2i) (3+4i) 16 | 17 | y=x^3 18 | extrema x 19 | (x+1)^4 20 | extrema x 21 | roots 4 1 0 ; The 4 roots of unity. 22 | factor number -75 100000000000000 16! 7921%14 ; should be exactly 11 23 | -------------------------------------------------------------------------------- /tests/fix2.in: -------------------------------------------------------------------------------- 1 | clear all 2 | b = ((-1)^(1/((-1*n)+1)*(2+n)))*(a^(1/((-1*n)+1))) 3 | x = 1/(y^(1/(n-1)*(-2+n)))/((n^(n/(n-1)))-(n^(1/(n-1)))) 4 | y = (x+(((1/x)+1)*((x^m)+((a+b)/(x^n)/(c+d)))))/(x+1) 5 | y = 3 / (x^3+3x^2-x-3) - 2 / (x^3-x^2-3x+3) + 4 / (x^3+x^2-3x-3) 6 | (x^2 - 1)^4/(x + 1)^2 7 | simplify all 8 | 1 9 | solve verifiable a 10 | 2 11 | solve verifiable y 12 | 1/(x+y) 13 | taylor x, 5, 0 14 | fraction 15 | simplify fraction 16 | simplify 17 | -------------------------------------------------------------------------------- /tests/fix5.in: -------------------------------------------------------------------------------- 1 | clear all 2 | a = (x+1/2^.5)^3 3 | a = (b+((c+1)^0.5))^3 4 | a = b*c*x*((((x^2)*c)+(b^4))^3)*(x+c) 5 | a = (((b^2)+x)^3)*((1/x)+x)*b 6 | a = b*(((1/b)+(1/c))^3) 7 | a = (b^2)*(((1/b)+(1/c))^3) 8 | a = (b^2)*((b-c)^3) 9 | simplify all 10 | -------------------------------------------------------------------------------- /tests/fix7.in: -------------------------------------------------------------------------------- 1 | ; Algebraic fractions test 2 | clear all 3 | (c+a-b)/(b-a) 4 | ((d*(b+c))+(a*(e1+f)))/(e1+f)/(b+c) 5 | ((((e1^2)+d)*b*((b^2)+2))-e1-f)/b/((b^2)+2)/(e1+f) 6 | ((b*((((e1^2)+d)*((b^2)+2))+(b*(e1+f))))+e1+f)/(e1+f)/b/((b^2)+2) 7 | ((1/(x^(1+n)))+(1/(x^n))+(x^(m-1))+(x^m)+x)/(x+1) 8 | (1/(a + b)) + (1/(b + c)) 9 | ((x - 1)^2)*(2 + x)/((1 + x)*((x - 3)^2)) 10 | simplify all 11 | fraction all 12 | simplify fraction all 13 | simplify all 14 | -------------------------------------------------------------------------------- /tests/fix8.in: -------------------------------------------------------------------------------- 1 | clear all 2 | a = (((b^2)*(x^2))+(4*(b^2)*x)+(b^2)+(2*(b^3)*x)+(2*(b^3))+(b^4)+(2*b*(x^2))+(2*b*x)+(x^2))/(((b^3)*(x^2))+(2*(b^4)*x)+(b^5)) 3 | y = (((b+1)^0.5)*((b^2.5)+c))+((((b^2)+b)^0.5)*a) 4 | a = (b^(1-n))/(1+(b^(m-n))) 5 | a = (((b^2)+(b*(c^(1-n)))+(b^0.5))/(b^n)/(1+(b^(m-n))))^0.5 6 | simplify all 7 | -------------------------------------------------------------------------------- /tests/fix9.in: -------------------------------------------------------------------------------- 1 | clear all 2 | ((1/b) + (1/c) + (1/d))^3 3 | ((+/-1000*(b!^4)+/-x)^2)*((1/x)+x)*b 4 | ((b+(2*i))^5) 5 | (((1/(b^2))+c)^2)*((1/b)+(c*b)) 6 | (6*(b^0.5)-3)^3 7 | (2-(4/(c-b)))^3 8 | (((e*((2*(x^3)) + 24 + (x!) - zy)) - pi)/e)^2 9 | (2+3x)^3 10 | simplify all 11 | display factor all 12 | -------------------------------------------------------------------------------- /tests/fraction.in: -------------------------------------------------------------------------------- 1 | 2 | ; Algebraic fractions tutorial. 3 | ; This Mathomatic input shows how "simplify fraction" and "unfactor fraction" work. 4 | 1/x+1/y+1/z 5 | fraction ; Convert expressions with algebraic fractions into a single fraction. 6 | simplify 7 | simplify fraction ; does the same as the above fraction command, but simplifies more. 8 | unfactor ; Expand the products of sums. 9 | unfactor fraction ; Fully expand algebraic fractions by also expanding division of sums. 10 | -------------------------------------------------------------------------------- /tests/heart.in: -------------------------------------------------------------------------------- 1 | 2 | ; Plot a heart with gnuplot: 3 | plot [-2:2] acos(1-abs(x))-pi,sqrt(1-(abs(x)-1)^2) 4 | 5 | ; If readline is enabled, 6 | ; hitting the up arrow, then the Enter key, should allow a replot. 7 | :push plot [-2:2] acos(1-abs(x))-pi,sqrt(1-(abs(x)-1)^2) 8 | -------------------------------------------------------------------------------- /tests/heron.in: -------------------------------------------------------------------------------- 1 | clear all 2 | ; This Mathomatic script shows two reverse derivations of Heron's formula. 3 | ; This is Heron's formula for the area of any triangle, 4 | ; given side lengths "a", "b", and "c". 5 | 6 | 2s = a+b+c 7 | triangle_area = (s*(s-a)*(s-b)*(s-c))^.5 8 | eliminate s ; Heron's formula: 9 | simplify ; Heron's formula simplified by Mathomatic: 10 | pause 11 | ; This is how we arrive at Heron's formula for the area 12 | ; of any triangle, given side lengths a, b, and c, using the formula 13 | ; for the area of a trapezoid with side lengths a, b, c, and d, 14 | ; where a and c are the parallel sides (a is the longer parallel side). 15 | 16 | ; A trapezoid is a quadrilateral with 17 | ; two sides that are parallel to each other. 18 | 19 | ; Formula for the area of a trapezoid that is not a parallelogram: 20 | trapezoid_area=(a+c)/(4*(a-c))*((a+b-c+d)*(a-b-c+d)*(a+b-c-d)*(-a+b+c+d))^.5 21 | pause 22 | copy 23 | replace c with 0 ; make the shorter parallel side length = 0 24 | replace d with c ; Heron's formula in its simplest form: 25 | replace trapezoid_area with triangle_area 26 | pause Please press the Enter key to verify the result. 27 | copy 28 | display 2 29 | compare 5 with 2 ; simplify and compare the result with Heron's formula: 30 | clear 5 31 | pause 32 | 33 | ; This is how we arrive at Heron's formula for the area 34 | ; of any triangle, given side lengths a, b, and c, using 35 | ; Brahmagupta's formula for the area of a cyclic quadrilateral, 36 | ; making one side length equal zero, to make a cyclic triangle. 37 | ; Since all triangles are cyclic (can be circumscribed by a circle), 38 | ; this gives the area for any triangle. 39 | 40 | 2s=a+b+c+d ; cyclic quadrilateral side lengths are a, b, c, and d 41 | cyclic_area = ((s-a)*(s-b)*(s-c)*(s-d))^.5 42 | eliminate s ; Brahmagupta's formula: 43 | pause 44 | copy 45 | replace d with 0 ; make one side length zero to get Heron's formula: 46 | pause Please press the Enter key to verify the result. 47 | compare 2 ; simplify and compare the result with Heron's formula: 48 | clear 49 | clear 1 5 50 | -------------------------------------------------------------------------------- /tests/how_limit_works.in: -------------------------------------------------------------------------------- 1 | clear all 2 | ; Read this file into Mathomatic to learn how the limit command does limits. 3 | ; The formula for the derivative of a function of "x" (f(x)) is: 4 | 5 | ; f(x+h) - f(x) 6 | ; limit ------------- As "h" goes to 0. 7 | ; h 8 | 9 | ; Here we will compute the derivative of "x^.5" using limits: 10 | 11 | y=((x+h)^.5-x^.5)/h 12 | pause 13 | limit h 0 ; Take the limit of the current equation as h goes to 0. 14 | ; The result should be the derivative of "x^.5": "y = 1/(2*x^0.5)". 15 | pause 16 | ; To show how the limit command works, we will do what it does, step by step. 17 | 18 | 1 ; Select the original equation (equation number 1). 19 | ; We want "h" to go to 0 to give us the derivative. 20 | ; Just entering 0 for "h" will give a divide by zero error. 21 | pause 22 | ; So we will first have to solve for "h": 23 | 24 | h 25 | pause 26 | ; Simplify and replace "h" with 0: 27 | 28 | simplify symbolic 29 | replace h with 0 30 | pause 31 | ; Last step, solve the equation back for "y": 32 | 33 | y 34 | compare 1 with 2 ; Compare with the result of the limit command. 35 | 36 | ; Obviously this method only works if the equation is solvable. 37 | pause 38 | ; INFINITY LIMITS 39 | ; --------------- 40 | ; To take the limit as some variable "h" goes to infinity, 41 | ; remember that 1/infinity is essentially 0, and the limit 42 | ; of "1/h" as "h" goes to 0 is +/-infinity, so replace "h" 43 | ; with "1/h" and take the limit as "h" now goes to 0. 44 | ; Note that this method doesn't always work and sometimes gives wrong answers. 45 | 46 | ; Let's try a simple example: 47 | y=(5x+100-a)/(x-b) 48 | limit x inf 49 | ; The limit command should say the result is 5. 50 | pause 51 | ; To show how the limit command works, we will do what it does, step by step. 52 | 53 | 3 ; Select the original equation (equation number 3). 54 | ; To take the limit as "x" approaches infinity, 55 | ; first replace "x" with "1/x": 56 | 57 | replace x with 1/x 58 | pause 59 | 60 | ; Simplify and replace "x" with 0: 61 | simplify 62 | replace x with 0 63 | ; The result should be 5. 64 | pause End of limit command tutorial. 65 | -------------------------------------------------------------------------------- /tests/hypertrig.in: -------------------------------------------------------------------------------- 1 | ; Definitions for hyperbolic trigonometry. 2 | ; Use m4 Mathomatic instead for easy entry of these hypertrig functions. 3 | ; Based on the identity cosh(x)^2-sinh(x)^2 = 1. 4 | 5 | ; sinh(x); hyperbolic sine of x 6 | sinh=(e^x-e^-x)/2 7 | 8 | ; cosh(x); hyperbolic cosine of x 9 | cosh=(e^x+e^-x)/2 10 | 11 | ; tanh(x); hyperbolic tangent of x 12 | tanh=(e^x-e^-x)/(e^x+e^-x) 13 | 14 | ; coth(x); hyperbolic cotangent of x 15 | coth=(e^x+e^-x)/(e^x-e^-x) 16 | 17 | ; sech(x); hyperbolic secant of x 18 | sech=2/(e^x+e^-x) 19 | 20 | ; csch(x); hyperbolic cosecant of x 21 | csch=2/(e^x-e^-x) 22 | -------------------------------------------------------------------------------- /tests/limits.in: -------------------------------------------------------------------------------- 1 | 2 | ; Tests for the experimental limit command. 3 | 4 | clear all 5 | ; find the derivative of: 6 | y = 1/(x^.5) 7 | ; using the difference quotient: 8 | y' = (1/(x+delta_x)^.5-1/x^.5)/delta_x 9 | limit delta_x 0 ; take the limit as delta_x (change in x) goes to 0 10 | 3 11 | integrate x ; take the antiderivative to see if it's right 12 | compare 1 13 | 14 | ; test infinity limits: 15 | 2x/(x+1) 16 | limit x inf ; answer should be 2 17 | 18 | (3x+100-a)/(x-b) 19 | limit x inf ; answer should be 3 20 | 21 | (((x^2) - (5*x) + 6)^(1/2)) - x 22 | limit x inf ; answer should be -5/2 23 | 24 | x*((x^2+1)^.5-x) 25 | limit x inf ; answer should be 1/2 26 | 27 | 1/x^2+1/x 28 | limit y inf ; result should be original expression with a warning. 29 | limit x inf ; result should be 0 30 | 31 | ((2*(x^2)) - x - 6)/((x^2) + (2*x) - 8) 32 | limit x inf ; result should be 2 33 | 34 | x^2+x 35 | limit x 0 ; result should be 0 36 | limit x 2 ; result should be 6 37 | display 38 | ; The following currently gives the wrong answer: 39 | limit x inf ; result should be inf 40 | ; The following currently gives errors: 41 | y=x+1/x 42 | :limit x 0 ; result should be inf 43 | :limit x inf; result should be inf 44 | -------------------------------------------------------------------------------- /tests/linear.in: -------------------------------------------------------------------------------- 1 | 2 | ; Combine 3 simultaneous linear equations with 3 unknowns (x, y, z). 3 | ; Solve for all 3 unknowns using the eliminate, solve, and simplify commands. 4 | 5 | clear all ; restart Mathomatic 6 | ; enter all 3 equations: 7 | d1=a1*x+b1*y+c1*z 8 | d2=a2*x+b2*y+c2*z 9 | d3=a3*x+b3*y+c3*z 10 | 2 ; select equation number 2 as the current equation 11 | eliminate x ; eliminate variable x from the current equation 12 | 3 ; select equation number 3 13 | eliminate x y ; eliminate variables x and then y from the current equation 14 | solve for z 15 | 2 ; select equation number 2 16 | eliminate z using 3 ; find y by combining equation numbers 2 and 3 17 | simplify 18 | 1 ; select equation number 1 19 | eliminate z using 3, y using 2; find x 20 | 21 | simplify all ; simplify and display all solutions 22 | -------------------------------------------------------------------------------- /tests/pie.in: -------------------------------------------------------------------------------- 1 | 2 | ; This is the famous Bailey-Borwein-Plouffe (BBP) formula. 3 | ; Sum this n = 0 to infinity to compute pi. 4 | ; This is especially useful for calculating pi in hexadecimal. 5 | ; One hexadecimal digit of pi is generated with each iteration. 6 | ((4/((8*n)+1))-(2/((8*n)+4))-(1/((8*n)+5))-(1/((8*n)+6)))/(16^n) 7 | simplify ; BBP simplifies to the ratio of two polynomials. 8 | sum n=0 to 10 ; Numerically sum BBP from n = 0 to 10 in steps of 1. 9 | pi ; The digits should be the same. 10 | repeat echo * 11 | x^n/n! ; Sum this n = 0 to infinity to compute (e^x). 12 | replace x with 1 ; Sum this n = 0 to infinity to compute e: 13 | sum n=0 to 20 ; Numerically sum from n = 0 to 20 in steps of 1. 14 | e ; The digits should be the same. 15 | repeat echo * 16 | ; Euler's identity is made of these most important universal constants: 17 | e^(pi*i)+1=0 18 | simplify ; An identity is when the LHS is identical to the RHS: 19 | -------------------------------------------------------------------------------- /tests/points.in: -------------------------------------------------------------------------------- 1 | 2 | ; This is the equation for a straight line given 2 points on the line. 3 | ; Point 1 is (x1, y1) and point 2 is (x2, y2) on a 2D Cartesian plane. 4 | 5 | y = ((y2*x1)+(x*(y1-y2))-(y1*x2))/(x1-x2) 6 | 7 | ; This is the equation for a quadratic curve given 3 points on it. 8 | ; It is derived in the file "poly.in" (y = a + b*x + c*x^2). 9 | ; Point 1 is (x1, y1), point 2 is (x2, y2), and point 3 is (x3, y3). 10 | 11 | y = ((y2*((x3*x1)+(x^2))*(x3-x1))+(x*(((x1^2)*(y2-y3))+((x3^2)*(y1-y2))))+(y1*((x2*((x^2)-(x3^2)))-((x^2)*x3)))+((x2^2)*((x*(y3-y1))+(x3*y1)))-(y3*((x^2)+(x1*x2))*(x2-x1)))/(x3-x1)/(x2-x1)/(x2-x3) 12 | 13 | ; Type in "calc" to plug in values. 14 | ; Just hit Enter when prompted for "x". 15 | -------------------------------------------------------------------------------- /tests/poly.in: -------------------------------------------------------------------------------- 1 | 2 | ; Combine 3 quadratic polynomial equations with 3 unknown coefficients (a, b, c). 3 | ; Solve for variables (a), (b), and (c). 4 | 5 | clear all ; restart Mathomatic 6 | ; enter all 3 equations: 7 | y1=a+b*x1+c*x1^2 8 | y2=a+b*x2+c*x2^2 9 | y3=a+b*x3+c*x3^2 10 | 2 ; select equation number 2 as the current equation 11 | eliminate a ; eliminate variable (a) from the current equation 12 | 3 ; select equation number 3 13 | eliminate a b ; eliminate variables (a) and then (b) from the current equation 14 | solve verifiable c 15 | simplify 16 | 2 ; select equation number 2 again 17 | eliminate c using 3 ; find (b) by combining equation numbers 2 and 3 18 | simplify 19 | 1 ; select equation number 1 20 | eliminate c using 3, b using 2 ; find (a) 21 | 22 | simplify fraction all ; display all solutions, converting to simple fractions first 23 | -------------------------------------------------------------------------------- /tests/pyth3d.in: -------------------------------------------------------------------------------- 1 | 2 | ; This arrives at the distance between two points in 3D space from the 3 | ; Pythagorean theorem (distance between two points on a 2D plane). 4 | ; The coordinate of point 1, 2D: (x1, y1), 3D: (x1, y1, z1). 5 | ; The coordinate of point 2, 2D: (x2, y2), 3D: (x2, y2, z2). 6 | 7 | distance2D^2=(x1-x2)^2+(y1-y2)^2 ; Distance formula for a 2D Cartesian plane. 8 | distance3D^2=distance2D^2+(z1-z2)^2 ; Add another leg. 9 | eliminate distance2D ; Combine the two equations. 10 | distance3D ; Solve to get the distance in 3D Cartesian space. 11 | -------------------------------------------------------------------------------- /tests/quadratic.in: -------------------------------------------------------------------------------- 1 | 2 | ; General quadratic (2nd degree polynomial) formula. 3 | ; Formula for the 2 roots (solutions for x) 4 | ; of the general quadratic equation. 5 | ; 6 | a x^2 + b x + c = 0 ; The general quadratic equation. 7 | copy select ; Make a copy and select it. 8 | solve verifiable for x ; Mathomatic can easily solve and verify that: 9 | ; This is the quadratic formula. 10 | ; The coefficients (a, b, and c) may be any mathematical expression not containing x. 11 | pause 12 | ; Here is the derivation and proof of the quadratic formula, 13 | ; without actually using the quadratic formula, 14 | ; because that is what we are trying to derive now, from the quadratic equation: 15 | #1: 16 | copy select ; make a copy of the general quadratic equation to work on and select it. 17 | -=c ; subtract "c" from both sides. 18 | /=a ; divide both sides by "a". 19 | pause Next simplify it and turn it into a repeated factor polynomial equation 20 | simplify 21 | +=b^2/(4*(a^2)) ; add "b^2/(4*(a^2))" to both sides. 22 | ; Now the LHS is a repeated factor polynomial, next factor it by pressing Enter to simplify. 23 | pause 24 | simplify ; Now the LHS is a factored polynomial, so solving for the single "x" is easy. 25 | set debug 1 ; Let Mathomatic do the work and show it too. 26 | ; Show how easy it is to solve this equation now, after pressing Enter. 27 | pause 28 | x 29 | ; Here is the raw solve result, press the Enter key to simplify and compare with the quadratic formula. 30 | pause 31 | set no debug 32 | repeat simplify 33 | compare with 2 34 | 35 | -------------------------------------------------------------------------------- /tests/quartic.in: -------------------------------------------------------------------------------- 1 | 2 | ; This general quartic (4th degree polynomial) formula as 3 | ; four equations combined into one is from: 4 | ; http://planetmath.org/encyclopedia/QuarticFormula.html 5 | ; Not perfect, gives division by zero warnings and only NaN for results 6 | ; if all four roots are the same. 7 | 8 | ; The four roots of the general 4th degree polynomial equation 9 | x^4 + a x^3 + b x^2 + c x + d = 0 10 | ; are given by 11 | 12 | x = ((-a)/4 + sign * 1/2(((a^2)/4 - (2b)/3 + (2^(1/3)(b^2 - 3a*c + 12d))/(3((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))^(1/3)) + (((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4 ((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))/54)^(1/3))^.5) + sign1 * 1/2(((a^2)/2 - (4b)/3 - (2^(1/3)(b^2 - 3a*c + 12d))/(3((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))^(1/3)) - (((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4 ((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))/54)^(1/3) + sign (-a^3 + 4a*b - 8c)/(4(((a^2)/4 - (2b)/3 + (2^(1/3) (b^2 - 3a*c + 12d))/(3 ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4 ((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))^(1/3)) + (((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d + ((-4 ((b^2 - 3a*c + 12d))^3 + ((2b^3 - 9a*b*c + 27c^2 + 27a^2d - 72b*d))^2)^.5)))/54)^(1/3))^.5)))^.5)) 13 | 14 | ; Type "calculate all" to temporarily plug in coefficients. 15 | ; Use "repeat simplify quick" to simplify this, plain old simplify does a terrible job. 16 | -------------------------------------------------------------------------------- /tests/radius.in: -------------------------------------------------------------------------------- 1 | 2 | ; Some more fun formulas. These are very similar to Heron's formula 3 | ; for the area of a triangle (see "heron.in"). a, b, and c are the 4 | ; lengths of the sides of the triangle. 5 | 6 | s=(a+b+c)/2 ; semiperimeter 7 | ; radius of a circle inscribed in a triangle, called an incircle: 8 | inradius=(s*(s-a)*(s-b)*(s-c))^.5/s 9 | eliminate s 10 | simplify 11 | 12 | ; The following is the equation for the radius of a circle circumscribing 13 | ; a triangle, called a circumcircle, which is a circle that passes through 14 | ; all the vertices of a polygon. 15 | radius=a*b*c/(4*(s*(s-a)*(s-b)*(s-c))^.5) 16 | eliminate s 17 | simplify 18 | #s ; Search backwards for the s variable; "/" searches forwards. 19 | clear ; No longer needed. 20 | display all 21 | -------------------------------------------------------------------------------- /tests/simplify.in: -------------------------------------------------------------------------------- 1 | 2 | ; Some complete simplifications Mathomatic has always been able to do. 3 | ; The result is the smallest expression that gives exactly the same results. 4 | 5 | 2*(x^2-y^2)^16-(x^2-y^2)^15*(2x^2-3) 6 | simplify ; Simplify the previously entered expression above. 7 | repeat echo * 8 | a^3/((a-b)*(a-c))+b^3/((b-c)*(b-a))+c^3/((c-a)*(c-b)) 9 | simplify ; Simplify algebraic fractions. 10 | repeat echo * 11 | (x^6+a^6)*(x+1)/((x^6+a^6)*(x^2-a^2)+a^2*x^2*(x^4-a^4))+a^2*x^2*(x+1)/(x^6-a^6-a^2*x^2*(x^2-a^2)) 12 | simplify 13 | repeat echo * 14 | (1-(1-(y+1)/(x+y+1))/(1-x/(x+y+1)))/((y+1)^2-x/(1+x/(y-x+1))*(x*(y+1)/(y-x+1)-x)) 15 | simplify fraction ; Any complex fraction can be reduced to a simple fraction with this command. 16 | repeat echo * 17 | ((2*((x*(x+(((x^2)-1)^(1/2))))-1))+1)/((2*x*((x^2)-1))+((((x^2)-1)^(1/2))*((2*(x^2))-1))) 18 | simplify ; Simplify an expression containing radicals (roots). 19 | ; Rationalizing the denominator was required to simplify the above expression. 20 | repeat echo * 21 | ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) / (4*y^2 + x^2) 22 | repeat simplify 23 | -------------------------------------------------------------------------------- /tests/t: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Alternative shell script to test Mathomatic that doesn't require the make utility. 3 | # Just run this while in the tests directory with "./t" 4 | # to see if Mathomatic runs properly on your system. 5 | # After reading in and executing the Mathomatic scripts in "all.in", 6 | # it does a diff between the output of the test and the expected output. 7 | # If no differences are reported, "All tests passed 100% correctly" is displayed. 8 | 9 | # Usage: ./t [ mathomatic_executable_to_test ] 10 | 11 | if [ "$1" != "" ] 12 | then 13 | MATHOMATICPATH="$1" 14 | else 15 | MATHOMATICPATH="../mathomatic" 16 | if [ ! -x "$MATHOMATICPATH" ] 17 | then 18 | MATHOMATICPATH=mathomatic 19 | fi 20 | fi 21 | 22 | echo 23 | echo Testing $MATHOMATICPATH \(`$MATHOMATICPATH -v`\) || exit 1 24 | TESTOUT=`mktemp /tmp/test.XXXXXXXXXX` || exit 1 25 | time -p "$MATHOMATICPATH" -t all 0<&- >$TESTOUT && diff -u --strip-trailing-cr all.out $TESTOUT && echo "All tests passed 100% correctly." && rm $TESTOUT && exit 0 26 | echo "Test failed. Errors are in $TESTOUT" 27 | exit 1 28 | -------------------------------------------------------------------------------- /tests/test.in: -------------------------------------------------------------------------------- 1 | ; Read in some of the things previously fixed in Mathomatic. 2 | read fix1 3 | read fix2 4 | read fix5 5 | read fix7 6 | read fix8 7 | read fix9 8 | -------------------------------------------------------------------------------- /tests/test1.in: -------------------------------------------------------------------------------- 1 | y = .6666 - (4*(((10*(pi^2)*(r^3)/((d^2)*g*m*epsilon)) - 1)^(1/2))/15) 2 | simplify 3 | simplify symbolic 4 | r 5 | repeat simplify 6 | y 7 | repeat simplify symbolic 8 | -------------------------------------------------------------------------------- /tests/test2.in: -------------------------------------------------------------------------------- 1 | clear all 2 | y=(a/2)^2/b/4 3 | l=f*(b-y)+z*(a-f) 4 | m=2*(b-y)-a+f 5 | n=2*(b-y)+a-f 6 | o=l*(1/m-1/n)/2 7 | eliminate l m n y 8 | simplify 9 | copy 10 | f 11 | simplify symbolic 12 | 6 13 | derivative z 14 | f 15 | repeat simplify symbolic 16 | -------------------------------------------------------------------------------- /tests/test3.in: -------------------------------------------------------------------------------- 1 | ; Test solving linear equations with Mathomatic. 2 | 3 | read linear 4 | copy 5 | b2 6 | c2 7 | b3 8 | c3 9 | b1 10 | c1 11 | d2 12 | a2 13 | d3 14 | a3 15 | d1 16 | a1 17 | x 18 | compare with 4 19 | -------------------------------------------------------------------------------- /tests/test6.in: -------------------------------------------------------------------------------- 1 | ; Combine the equations for conservation of momentum and kinetic energy 2 | ; to solve for the resulting velocity of two objects colliding head on. 3 | clear all 4 | ; equations for energy: 5 | e1=1/2*mass1*velocity1_old^2 6 | e2=1/2*mass2*velocity2_old^2 7 | e3=1/2*mass1*velocity1_new^2 8 | e4=1/2*mass2*velocity2_new^2 9 | e1+e2=e3+e4 10 | eliminate all 11 | ; equations for momentum: 12 | #1: u1=mass1*velocity1_old 13 | #2: u2=mass2*velocity2_old 14 | #3: u3=mass1*velocity1_new 15 | #4: u4=mass2*velocity2_new 16 | u1+u2=u3+u4 17 | eliminate all 18 | clear 1-4 19 | eliminate velocity1_new 20 | velocity2_new 21 | simplify 22 | velocity2_new = ((sign*((mass1*(velocity1_old-velocity2_old))^2)^.5)+(mass1*velocity1_old)+(mass2*velocity2_old))/(mass1+mass2) 23 | compare 6 24 | -------------------------------------------------------------------------------- /tests/trig: -------------------------------------------------------------------------------- 1 | 2 | ; Trigonometric and hyperbolic trigonometric function listing that can be 3 | ; expanded and simplified by reading this file into m4 Mathomatic 4 | ; with the following shell command: 5 | 6 | ; rmath trig 7 | 8 | ; Trig functions: 9 | sine = sin(x) ; sine of x 10 | cosine = cos(x) ; cosine of x 11 | tangent = tan(x) ; tangent of x 12 | cotangent = cot(x) ; cotangent of x 13 | secant = sec(x) ; secant of x 14 | cosecant = csc(x) ; cosecant of x 15 | 16 | ; Hyperbolic trig functions: 17 | hypersine = sinh(x) ; hyperbolic sine of x 18 | hypercosine = cosh(x) ; hyperbolic cosine of x 19 | hypertangent = tanh(x) ; hyperbolic tangent of x 20 | hypercotangent = coth(x) ; hyperbolic cotangent of x 21 | hypersecant = sech(x) ; hyperbolic secant of x 22 | hypercosecant = csch(x) ; hyperbolic cosecant of x 23 | -------------------------------------------------------------------------------- /tests/trig.in: -------------------------------------------------------------------------------- 1 | ; Trigonometric functions as complex exponentials. 2 | ; Use m4 Mathomatic instead for easy entry of these trig functions. 3 | ; Based on Euler's identity: e^(i*x) = cos(x) + i*sin(x) 4 | ; Variable x is an angle in radians. 5 | 6 | ; Unity relationship: sin(x)^2 + cos(x)^2 = 1 7 | 8 | ; sin(x) (sine of x) = cos(pi/2 - x) 9 | sin=(e^(i*x)-e^(-i*x))/(2i) 10 | 11 | ; cos(x) (cosine of x) = sin(pi/2 - x) 12 | cos=(e^(i*x)+e^(-i*x))/2 13 | 14 | ; tan(x) (tangent of x) = sin(x)/cos(x) = cot(pi/2 - x) 15 | tan=(e^(i*x)-e^(-i*x))/(i*(e^(i*x)+e^(-i*x))) 16 | 17 | ; cot(x) (cotangent of x) = cos(x)/sin(x) = tan(pi/2 - x) 18 | cot=i*(e^(i*x)+e^(-i*x))/(e^(i*x)-e^(-i*x)) 19 | 20 | ; sec(x) (secant of x) = 1/cos(x) = csc(pi/2 - x) 21 | sec=2/(e^(i*x)+e^(-i*x)) 22 | 23 | ; csc(x) (cosecant of x) = 1/sin(x) = sec(pi/2 - x) 24 | csc=2i/(e^(i*x)-e^(-i*x)) 25 | -------------------------------------------------------------------------------- /update: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Update the function prototypes in proto.h by using the cproto utility. 3 | # Run this whenever a new C function is added to the Mathomatic source code or 4 | # whenever a function definition is changed. 5 | 6 | cproto /dev/null || exit 1 # Test for existence of cproto utility. 7 | echo '/* Complete list of global C function prototypes for Mathomatic. */' >cproto.h 8 | echo '/* This file was created with the cproto utility by running the "./update" script. */' >>cproto.h 9 | echo '/* This file is required to compile Mathomatic quietly with the -Wall compiler option. */' >>cproto.h 10 | echo >>cproto.h 11 | cproto -DUNIX -DDEBUG *.c >>cproto.h && mv cproto.h proto.h && echo proto.h recreated. 12 | -------------------------------------------------------------------------------- /zipsrc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Create a zip file in your home directory containing 3 | # the Mathomatic source distribution with no object files or binary executable files. 4 | # The current directory must be the Mathomatic build directory for this to work 5 | # and "make distclean" should have been done at some time beforehand. 6 | # Uses Info-ZIP and its command line options. 7 | 8 | if [ ! -f "VERSION" ] 9 | then 10 | echo 'zipsrc executed from an improper directory;' 11 | echo 'Must only be invoked as "./zipsrc" from the Mathomatic source directory.' 12 | exit 1 13 | fi 14 | 15 | set -e 16 | ./makenews.sh 17 | make -s -C primes distclean 18 | make -s -C lib distclean 19 | make -s doc/quickrefcard.html 20 | rm -f ~/am.zip */*.o */*.pyc */*.pyo 21 | echo Mathomatic development source code and docs version `cat VERSION`+ \ 22 | | zip -9rqzX ~/am.zip *.c *.h make* t update compile* *.txt VERSION AUTHORS COPYING NEWS *.1 zipsrc doc primes tests lib examples m4 misc icons menu \ 23 | && echo ~/am.zip created. 24 | --------------------------------------------------------------------------------