This is a small tour of the capabilities Yacas currently offers. Note that this list of examples is far from complete. Yacas contains a few hundred commands, of which only a few are shown here.
Additional example calculations including the results can be found here:
The default operation of Yacas is to run in the interactive console mode. Yacas accepts several options that modify its operation. Here is a summary of options:
Options can be combined, for example
yacas -pc filename |
Here is a more detailed description of the command-line options.
yacas -c |
yacas -f |
yacas -p |
yacas -t |
yacas [options] {filename} |
yacas -v |
yacas -d |
yacas --patchload |
yacas --init [file] |
yacas --read-eval-print [expression] |
There is also a fallback read-eval-print loop in the kernel; it can be invoked by passing an empty string to this command line option, as --read-eval-print "".
An alternative way to replace the default read-eval-print loop is to write a custom initialization script that implements the read-eval-print loop function REP() instead of yacasinit.ys.
Care has to be taken with this option because a Yacas session may become unusable if the read-eval-print expression doesn't function correctly.
yacas --server <port> |
Commands can be sent to the server by sending a text line as one block of data, and the server will respond back with another text block.
One can test this function by using telnet. First, set up the server by calling
yacas --server 9734 |
telnet 127.0.0.1 9734 |
Some security measures and resource management measures have been taken. No more than 10 connections can be alive at any time, a calculation cannot take more than 30 seconds, and Yacas operates in the secure mode, much like calling an expression by passing it as an argument to the Secure function. This means that no system calls are allowed, and no writing to local files, amongst other things. Something that has not been taken care of yet is memory use. A calculation could take up all memory, but not for longer than 30 seconds.
The server is single-threaded, but has persistent sessions for at most 10 users at a time, from which it can service requests in a sequential order. To make the service multi-threaded, a solution might be to have a proxy in front of the service listening to the port, redirecting it to different processes which get started up for users (this has not been tried yet).
The flag --single-user-server can be passed on to instruct yacas to start in single-user mode. In this mode, unsecure operations can be performed (like reading from and writing to files), and the calculation may take more than 30 seconds. The yacas process will automatically be shut down when the last session is closed or when "Exit();" is sent.
yacas --rootdir [directory] |
yacas --dlldir [directory] |
yacas --archive [file] |
Yacas has an experimental system where files can be compressed into one file, and accessed through this command line option. The advantages are:
An additional savings is due to the fact that the script files are stripped from white spaces and comments, making them smaller and faster loading.
To prepare the compressed library archive, run ./configure with the command line option --enable-archive.
The result should be the archive file scripts.dat. Then launch Yacas with the command line option --archive scripts.dat, with the file scripts.dat in the current directory.
The reason that the scripts.dat file is not built automatically is that it is not tested, at this time, that the build process works on all platforms. (Right now it works on Unix, MacOSX, and Win32.)
Alternatively, configure Yacas with
./configure --enable-archive |
When an archive is present, Yacas will try to load it before it looks for scripts from the library directories. Typing
make archivetest -f makefile.compressor |
The currently supported compression schemes are uncompressed and compressed with minilzo. Script file stripping (removing whitespace and comments) may be disabled by editing compressor.cpp (variable strip_script).
yacas --disable-compiled-plugins |
Disable loading of compiled scripts, in favor of scripts themselves. This is useful when developing the scripts that need to be compiled in the end, or when the scripts have not been compiled yet.
yacas --stacksize <size> |
For a function that would take 4 arguments and has one return value, there would be 5 places reserved on this stack, and the function could call itself recursively 10000 steps deep.
This differs from the MaxEvalDepth mechanism. The MaxEvalDepth mechanism allows one to specify the number of separate stack frames (number of calls, nested), instead of the number of arguments pushed on the stack. MaxEvalDepth was introduced to protect the normal C++ stack.
yacas --execute <expression> |
user% ./yacas -pc --execute '[Echo("answer ",D(x)Sin(x));Exit();]' answer Cos(x) user% |
The script yacas_client reads Yacas commands from the standard input and passes them to the running "Yacas server"; it then waits 2 seconds and prints whatever output Yacas produced up to this time. Usage may look like this:
8:20pm Unix>echo "x:=3" | yacas_client Starting server. [editvi] [gnuplot] True; To exit Yacas, enter Exit(); or quit or Ctrl-c. Type ?? for help. Or type ?function for help on a function. Type 'restart' to restart Yacas. To see example commands, keep typing Example(); In> x:=3 Out> 3; In> 8:21pm Unix>echo "x:=3+x" | yacas_client In> x:=3+x Out> 6; In> 8:23pm Unix>yacas_client -stop In> quit Quitting... Server stopped. 8:23pm Unix> |
Persistence of the session means that Yacas remembered the value of x between invocations of yacas_client. If there is not enough time for Yacas to produce output within 2 seconds, the output will be displayed the next time you call yacas_client.
The "Yacas server" is started automatically when first used and can be stopped either by quitting Yacas or by an explicit option yacas_client -stop, in which case yacas_client does not read standard input.
The script yacas_client reads standard input and writes to standard output, so it can be used via remote shell execution. For example, if an account "user" on a remote computer "remote.host" is accessible through ssh, then yacas_client can be used remotely, like this:
echo "x:=2;" | \ ssh user@remote.host yacas_client |
On a given host computer running the "Yacas server", each user currently may have only one persistent Yacas session.