7.3 Fricas

7.3.1 Running Fricas script

create file, say F1.input like this

f(n)==n^2 
f(4)
 

And run it using the command

fricas -nosman < F1.input > o.txt
 

The output will go to file o.txt

7.3.2 Finding type of variable

Use  typeOf

r:=sqrt(-5)::Complex(Float) 
   (3)  2.2360679774_997896964 %i 
 
(5) -> typeOf(r) 
   (5)  Complex(Float)
 

7.3.3 Home page

Home page https://fricas.github.io/index.html

To install fricas on Linux Manjaro sudo pacman -S sagemath.

in case of error while installing the package, try sudo pacman -Rs sagemath and then repeat the previous command

If copy paste does not work between windows and Linux VBox, try VBoxClient --clipboard

To use Fricas online, go to

http://axiom-wiki.newsynthesis.org/FriCASIntegration

http://fricas-wiki.math.uni.wroc.pl/SandBox

https://wiki.fricas.org/SandBox

Go to bottom of page, type

\begin{axiom} 
setSimplifyDenomsFlag(true) 
integrate(sin(x),x) 
\end{axiom}

Then click the preview button

to send email to supprt group use fricas-devel@googlegroups.com

To download go to https://sourceforge.net/projects/fricas

To installl on Linux Manjaro, type yay -S fricas . Do not use the Manjaro GUI package manager, it always gives build error for some reason. Make sure to install yay first using GUI manager.

Make sure when installing Linux on VBox, to add second CPU to configuration of VBox. i.e. do not use ONE CPU (which is default). There is a bug in fricas installation which makes it fail due to use of multi-threading if only one CPU exist. This should be fixed in future, but just in case.

To install directly, see http://fricas.sourceforge.net/doc/INSTALL.txt

To build directly (but I use yay now and not this any more)

#install sbcl 
#sudo apt-get install sbcl #do not use this. bug 
sudo apt-get install clisp #This lisp works 
sudo apt-get install dvipng 
sudo apt-get install auctex 
bzip2 -dk fricas-1.3.2-full.tar.bz2 
tar -xf fricas-1.3.2-full.tar
 

Now build it

make clean 
fricas-1.3.2>./configure --with-lisp=/usr/bin/clisp 
checking build system type... x86_64-linux-gnu 
checking host system type... x86_64-linux-gnu 
checking target system type... x86_64-linux-gnu 
checking for make... make 
checking for gcc... gcc 
checking whether the C compiler works... yes 
checking for C compiler default output file name... a.out 
checking for suffix of executables... 
checking whether we are cross compiling... no 
checking for suffix of object files... o 
checking whether we are using the GNU C compiler... yes 
checking whether gcc accepts -g... yes 
checking for gcc option to accept ISO C89... none needed 
checking for a BSD-compatible install... /usr/bin/install -c 
checking for touch... touch 
checking for mktemp... mktemp 
checking for gawk... gawk 
checking for gtar... no 
checking for tar... tar 
checking for ranlib... ranlib 
checking for ar... ar 
checking for latex... /usr/local/texlive/2017/bin/x86_64-linux/latex 
checking for makeindex... makeindex 
checking PREGENERATED... "/home/me/data/fricas/fricas-1.3.2/pre-generated" 
checking for sbcl... /usr/bin/sbcl 
checking Lisp implementation... This is SBCL 1.3.1.debian, an implementation of ANSI Common Lisp. 
More information about SBCL is available at <http://www.sbcl.org/>. 
 
SBCL is free software, provided as is, with absolutely no warranty. 
It is mostly in the public domain; some portions are provided under 
BSD-style licenses.  See the CREDITS and COPYING files in the 
distribution for more information. 
* sbcl 
checking how to run the C preprocessor... gcc -E 
checking for grep that handles long lines and -e... /bin/grep 
checking for egrep... /bin/grep -E 
checking for ANSI C header files... yes 
checking for sys/types.h... yes 
checking for sys/stat.h... yes 
checking for stdlib.h... yes 
checking for string.h... yes 
checking for memory.h... yes 
checking for strings.h... yes 
checking for inttypes.h... yes 
checking for stdint.h... yes 
checking for unistd.h... yes 
fasl 
checking dirent.h usability... yes 
checking dirent.h presence... yes 
checking for dirent.h... yes 
checking whether closedir is declared... yes 
checking whether opendir is declared... yes 
checking whether readdir is declared... yes 
checking whether dirfd is declared... yes 
checking whether fchdir is declared... yes 
checking signal.h usability... yes 
checking signal.h presence... yes 
checking for signal.h... yes 
checking whether sigaction is declared... yes 
checking for sys/stat.h... (cached) yes 
checking for unistd.h... (cached) yes 
checking whether getuid is declared... yes 
checking whether geteuid is declared... yes 
checking whether getgid is declared... yes 
checking whether getegid is declared... yes 
checking whether kill is declared... yes 
checking sys/socket.h usability... yes 
checking sys/socket.h presence... yes 
checking for sys/socket.h... yes 
checking util.h usability... no 
checking util.h presence... no 
checking for util.h... no 
checking pty.h usability... yes 
checking pty.h presence... yes 
checking for pty.h... yes 
checking whether openpty is declared... yes 
checking for openpty in -lc... no 
checking for openpty in -lutil... yes 
checking sys/wait.h usability... yes 
checking sys/wait.h presence... yes 
checking for sys/wait.h... yes 
checking whether wait is declared... yes 
checking whether fork is declared... yes 
checking for X... no 
configure: The Graphics and HyperDoc components are disabled. 
configure: WARNING: Aldor interface will not be built. 
configure: creating ./config.status 
config.status: creating src/clef/Makefile 
config.status: creating src/sman/Makefile 
config.status: creating src/hyper/Makefile 
config.status: creating src/doc/Makefile 
config.status: creating Makefile 
config.status: creating src/Makefile 
config.status: creating src/lib/Makefile 
config.status: creating src/lisp/Makefile 
config.status: creating src/boot/Makefile 
config.status: creating src/interp/Makefile 
config.status: creating src/algebra/Makefile 
config.status: creating src/input/Makefile 
config.status: creating src/etc/Makefile 
config.status: creating src/aldor/Makefile 
config.status: creating src/aldor/Makefile2 
config.status: creating src/aldor/Makefile3 
config.status: creating contrib/emacs/Makefile 
config.status: creating config/fricas_c_macros.h 
extracting list of SPAD type definitions 
Type 'make' (without quotes) to build FriCAS
 

And

make
 

Add these to .bashrc

export PATH=/home/me/data/fricas/fricas-1.3.2/target/x86_64-linux-gnu/bin:$PATH 
export AXIOM=/home/me/data/fricas/fricas-1.3.2/target/x86_64-linux-gnu 
export DAASE=/home/me/data/fricas/fricas-1.3.2/target/x86_64-linux-gnu
 

Example of integral which fails in Fricas

ii:=integrate(log(1+x)/x/(1+(1+x)^(1/2))^(1/2),x) 
 
 
   >> Error detected within library code: 
   integrate: implementation incomplete (constant residues)
 

For Fricas, use these commands to get 1D plain text output

setSimplifyDenomsFlag(true) 
)set output algebra on 
ii:=integrate(1/(x*(3*x^2 - 6*x + 4)^(1/3)),x); 
unparse(ii::InputForm)
 

Otherwise the output will go to console in 2D. To get Latex output do

setSimplifyDenomsFlag(true) 
)set message prompt plain 
)set output algebra off 
)set output tex on 
s:=asin(sqrt(1-x^2))/sqrt(1-x^2); 
ii:=integrate(s,x)
 

To record console session to file, use (from https://github.com/daly/axiom/blob/master/faq)

)spool filename 
    starts sending output to the file called filename 
)spool )off 
stops sending output to the file
 

Like this

)spool /home/me/data/output.txt 
)set message prompt plain 
)set output algebra off 
)set output tex on 
ii:=integrate(sin(x), x) 
)set output tex off 
)set output algebra on 
unparse(ii::InputForm) 
)spool )off
 

To send Latex output to file do

)set output tex  on 
)set output tex  filename
 

To turn off, just do )set output tex off. Make sure to tex on first. To send back to console, do )set output tex console

To read an input file into Axiom, use the )read system command. read For example, you can read a file in a particular directory by issuing

)read /spad/src/input/matrix.input

To make record

)clear prop r 
r: Record(a: String,b:Integer) 
r:=["hello",10]
 

Some hints below thanks to Waldek Hebisch http://mathforum.org/kb/message.jspa?messageID=9791385

copied here so easy for me to get to:

1. How to measure CPU time used from the int call? 
(3) -> )set messages time on 
(3) -> integrate(x^(3/2)/sqrt(1 + x^5), x) 
 
Type: Union(Expression(Integer),...) 
Time: 0.06 (EV) + 0.00 (OT) = 0.06 sec
 

There is command ')set messages time on' tell FriCAS to print time needed to execute following command. The (EV) part means actual computation (OT) printing and at the end there is total

2. How to measure leaf count/size of result? (Maple and Mathematica have build in function to do this)

That is a bit tricky. FriCAS (like Axiom) has quite different representation of expressions tham Maple or Mathematica. In FriCAS expression is a quotient of two polnomials, with variables beeing kernels:

(13) -> f := exp(x^3 + 1/x) + 1 
(14) -> numer(f) 
 
4 
x + 1 
------ 
x 
 
(15) -> denom(f) 
 
 
(16) -> variables(numer(f)) 
 
4 
x + 1 
------ 
x 
(16) [%e ] 
Type: List(Kernel(Expression(Integer))) 
Time: 0.00 (OT) = 0.00 sec
 

From FriCAS point of view natural measure of size is number of monomials in numerator and denominator:

(17) -> numberOfMonomials(numer(f)) 
 
(17) 2 
(18) -> numberOfMonomials(denom(f)) 
(18) 1
 

but this may underestimate size because kernels may be big. Also internally given kernel is stored only once, but in printed output it may appear several times.

It is possible to traverse expression is somewhat tree like manner, so it is possible to give better approximation to say Maple result, but that would require investigating what Maple is doing. I personally never used Maple node count so I do not know it this is simple or if there are some traps.

3. How to check if int passed or failed? Aborted? nil result? etc..

integrate may produce an error (in particular it will do so if it can not decide if integral is elementary). Or may produce unevaluated integral. Or normal result. At programistic level it is possible to catch errors, but a bit tricky, If you look at printed output, than errors are reasonably easy to match via a regex:

(22) -> integrate(1/sqrt(exp(x) - x + 1), x) 
integrate: implementation incomplete (constant residues)
 

the '>> Error' part indicates error. Unevaluated integrals always have integral sign at top level. FriCAS never returns partial results, so text match is relatively easy. Or you may use code like:

test_int(f) == 
res : Union(Expression Integer, LE) 
res := integrate(f, 'x) 
res0 : List Expression Integer := 
res case Expression Integer => 
[res::(Expression Integer)]@(List Expression Integer) 
res case List Expression Integer => 
res::(List Expression Integer) 
error "test_int: impossible 1" 
for ri in res0 repeat 
#(kernels ri) > 0 and is?(operator first kernels ri, 'integral) => 
print("Unevaluated integral"::OutputForm)
                                                                                    
                                                                                    
 

Note1: this is part extracted from bigger test script, I did not test it alone.

Note2: FriCAS may either return list of results or a single result. Middle part converts this to have always a list (typically of length 1). The last part is a loop so that all solutions can be examined. It you only want to know if result is evaluated, than loop is not needed: more than one result means that integral is evaluated.

Note3: In FriCAS testsuite I use a bit different test for evaluated integrals. Namely, FriCAS can do useful computations on unevaluated integrals and in particular unevaluated integrals may appear in the argument to integrate. Such unevaluated integrals of course may propagate form input to the output. The test above may misclasify such integral as unevaluated, while better test checks that unevaluated integral came from the input.

4. And most importantly, how to export the result (if it passed) to a plain text file in _Latex_ format?

(24) -> )set output tex on 
(24) -> integrate(exp(x)*exp(1/(exp(x)+1)-x), x)
 

Here one have to decide what to do with errors. Without error trapping error will abort currently executing function and propagate to top level (up to command line).

After doing:

)set break resume
 

after error FriCAS will continue executing file from next command (but still abort current command). If you need real loop then I can provide error catcher, but it is a bit more complicated than snippets above. Waldek Hebisch

To get type of value in fricas do  typeOf(r)

To clear everything do

)clear all 
)clear completely