currently I am running reduce on windows. I would like to use one of reduce's packages as a "blackbox" in my program. So my question is: Is there some API to access reduce's functionality or (even easier) is there a way to use reduce in a command line fashion, i.e. I do not want to start the GUI but instead execute it just like a command and receive the output.
I will speak for the CSL version of Reduce, but the PSL one is mostly command line anyway.
If you run Reduce either in a context where it can not access a display (eg under X windows with no DISPLAY variable set), or run it via a pipe so it does not have direct access to the keyboard, or if you launch it with a "-w" flag on the command-line it should run in console mode. If you are on Wndows you probably want to use reduce.com not reduce.exe for that (in cslbuild/i686-pc-windows/csl) and if you are a windows programmer you will know about console and windowed applications.
Several people over the years have used Reduce as a back-end for something else that way… eg on sourceforge you will find redfront and also iot is (sometimes!) possible to use texmacs as a front-end for Reduce - in each case things work by launching the main code in command-line mode at the end of a pipe.
For more challenging integration with another application you could look at the "embedded" directory on the CSL side.
For yet more thorough integration with other things the CSL source code has the skeleton of support for "procedural IO" where another application first launched Reduce then does calls into it to provide input and receive output. Using that is for somebody who wants to get hacking into the code rather than for trivial or casual use.
thank you for your quick and detailed reply.
In my case I simply would like use Reduce as a back-end in a Java program and communicate in a query and reply fashion. Thus is looks like the "-w" option might help but unfortunately Reduce gives me results that are hard to parse because
a) like in the interactive GUI it prints every statement from the input
b) the format of the output is inconvenient, e.g. d^2 is written in two lines:
Is there a way to suppress a) and change the output format so it becomes (maybe less human readable) but therefore easy to parse?
Thanks for your advice.
"off nat;" exists for just such a purpose!
Again if you ended up with seriously demanding needs and wanted to take the time and effort to investigate it is possible to set a variable called outputhandler!!* to the name of a lisp-level function that then gets passed every output request, so you can write code there to translate into pretty much any format you like. Eg the file tmprint/tmprint.red goes that route and turns stuff into TeX-like output.
So try "off nat;" for a starter…
Thanks for your help. I think now I got more or less what I want. In the Reduce manual I could not find a description of the nat switch - maybe I overlooked something. I only found that we can disable output alltogether. Thus taking the nat switch into account (which adresses the issue in b) above) my input file looks like this:
%last statement which gives the desired result
The output looks like this:
>reduce.com freddys_tests\progra_global4_a1.red -w
Reduce (Free CSL version), 21-Oct-09 ...
c1 + 2*c2 <= 0 or c1 + 2*c2 - d < 0 and c1 = 0 and c2 = 0 or c1*d + 2*c2*d - d**
2 <= 0 and c1 + 2*c2 - d <> 0 and c1 = 0 and c2 = 0 or c1 = 0 and c2 = 0 and (c1
+ 2*c2 - d < 0 or c1 + 2*c2 - d = 0 and d <= 0)$
*** End-of-file read
Now, I think I can work with that :-)
Just one last thing: I suppose that turning the output off has the consequence that I do not see if errors occur. Is there a way to start Reduce such that it only parses the code without computations so that I can be sure that my file is (at least) syntactically correct before I invoce Reduce a second time to perform the computation.
I have not used "off output" before, but when I try it in interactive mode I stilll see a variety of diagnostics that I provoke being reported. So I think you may not need a "dummy run" facility.
I might deal with this by a script that went a bit more like
write "*** AND NOW FOR MY BIG RESULT***";
then make my program that involed it look for the banner. That avoids any risk of anything getting lost, in that you can keep ALL the reduce output in your program for inspection in a log if there is some grief.
Another thing to note - these dats if you fetch source from subversiuon and go
./configure -with-csl -without-fox
the version made does not include any GUI capability so may be especially relevant to anybody who just wants to use it as a back-end. It naturally then does not need the "-w" flag to switch off activation of a GUI.
Hi, I'm using "Reduce (Free CSL version), 21-Oct-09" in WinXP SP3, I downloaded the running code from sorceforge.net directly. It works well, but sometimes when I use plot function to draw 2d or 3d function, no graph appears, but sometime has graph. I have try to use plotreset, but it remains the same status, that is when using plot, sometime can see a graph sometime no graph. I tried reduce.com, it works perfect, displays graph all the time. Can someone show me what's the problem? Thanks.