> <\body> Plugin>|||>|>> <\table-of-contents|toc> About Pure> |.>>>>|> Pure Sessions> |.>>>>|> Completion and Help> |.>>>>|> Pure and Reduce> |.>>>>|> Mathematical Input and Output> |.>>>>|> Basic expressions |.>>>>|> > Trees |.>>>>|> > Lists |.>>>>|> > Big operators (integrals, limits, sums, etc.) |.>>>>|> > Differentials and integrals |.>>>>|> > Programming |.>>>>|> > Caveats |.>>>>|> > Pure and Octave> |.>>>>|> PostScript Output> |.>>>>|> Pure Scripting> |.>>>>|> You can insert a Pure session as usual with . <\session|pure|default> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\input> \\ <|input> fact n = if n\0 then n*fact (n-1) else 1; <\unfolded-io> \\ <|unfolded-io> map fact (0..10); <|unfolded-io> [1,1,2,6,24,120,720,5040,40320,362880,3628800] <\unfolded-io> \\ <|unfolded-io> show fact <|unfolded-io> fact n = if n\0 then n*fact (n-1) else 1; As with other session inserts, these snippets aren't just verbatim Pure code, they are with the Pure interpreter, so you can rerun the calculations or enter your own code. By these means you can use as a frontend for the Pure interpreter; please check the documentation, section `` \ as an interface'', for details. To make this work, you'll have to install the plugin first so that knows about it; instructions for that can be found in the . The distributed configuration actually defines various different types of Pure sessions, each with their own options for the Pure interpreter, and it's easy to add your own if needed. Sessions can be formatted in different ways. Here we use the style package for a somewhat fancier formatting. It's also possible to globally override formatting options such as the color of prompts, input and output fields, by defining the and macros accordingly; see the manual, section ``Writing style files'', for details. An example can be found in the accompanying file; install this in your directory if you want to give it a try. Here's another session showing plain text formatting and subsessions. <\session|pure|subsession-example> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\input> \\ <|input> fact n = if n\0 then n*fact (n-1) else 1; <\unfolded> This is a subsession. <|unfolded> <\unfolded-io> \\ <|unfolded-io> map fact (1..10); // comment with math: \\\n>.> <|unfolded-io> [1,2,6,24,120,720,5040,40320,362880,3628800] <\unfolded-io> \\ <|unfolded-io> show fact <|unfolded-io> fact n = if n\0 then n*fact (n-1) else 1; <\input> \\ <|input> \; <\unfolded-io> \\ <|unfolded-io> fact fact; <|unfolded-io> <\errput> \stdin\, line 4: unhandled exception 'failed_cond' while evaluating 'fact fact' <\unfolded-io> \\ <|unfolded-io> fact 30L; <|unfolded-io> 265252859812191058636308480000000L <\unfolded-io> \\ <|unfolded-io> quit <|unfolded-io> Another session type (, this runs the interpreter in debugging mode): <\session|pure-debug|default> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\input> \\ <|input> fact n = if n\0 then n*fact (n-1) else 1; <\input> \\ <|input> break fact <\unfolded-io> \\ <|unfolded-io> fact 5; <|unfolded-io> ** [1] fact: fact n = if n\0 then n*fact (n-1) else 1; \ \ \ \ \ n = 5 (Type 'h' for help.) <\unfolded-io> :\ <|unfolded-io> h <|unfolded-io> Debugger commands: a \ \ \ \ \ \ auto: step through the entire program, run unattended c [f] \ \ continue until next breakpoint, or given function f h \ \ \ \ \ \ help: print this list n \ \ \ \ \ \ next step: step over reduction p [n] \ \ print rule stack (n = number of frames) r \ \ \ \ \ \ run: finish evaluation without debugger s \ \ \ \ \ \ single step: step into reduction t, b \ \ \ move to the top or bottom of the rule stack u, d \ \ \ move up or down one level in the rule stack x \ \ \ \ \ \ exit the interpreter (after confirmation) . \ \ \ \ \ \ reprint current rule ! cmd \ \ execute interpreter command ? expr \ evaluate expression \cr\ \ \ \ single step (same as 's') \eof\ \ \ step through program, run unattended (same as 'a') <\unfolded-io> :\ <|unfolded-io> s <|unfolded-io> ** [2] (\): x::int\y::int = x\y; \ \ \ \ \ x = 5; y = 0 <\unfolded-io> :\ <|unfolded-io> s <|unfolded-io> ++ [2] (\): x::int\y::int = x\y; \ \ \ \ \ x = 5; y = 0 \ \ \ \ \ --\ 1 ** [2] (-): x::int-y::int = x-y; \ \ \ \ \ x = 5; y = 1 <\unfolded-io> :\ <|unfolded-io> s <|unfolded-io> ++ [2] (-): x::int-y::int = x-y; \ \ \ \ \ x = 5; y = 1 \ \ \ \ \ --\ 4 ** [2] fact: fact n = if n\0 then n*fact (n-1) else 1; \ \ \ \ \ n = 4 <\unfolded-io> :\ <|unfolded-io> r <|unfolded-io> 120 Note that always runs plugins in the current working directory in which it was started, which is also the directory from which the Pure interpreter will read its startup files. If you start from the GUI, this will most likely be your home directory. It often makes more sense to run the interpreter in the directory of the document hosting the Pure sessions, so that you can keep scripts and other files needed by your sessions in the same directory. Unfortunately, offers no help with this; there's simply no way to specify a working directory when running a session. Thus you'll either have to run in the right directory (by invoking it from the command line), or change the working directory manually inside the Pure session. To help with the latter, the -hosted interpreter offers a special (``current document directory'') command: <\session|pure|default> <\unfolded-io> \\ <|unfolded-io> pwd <|unfolded-io> /home/ag <\input> \\ <|input> cdd <\unfolded-io> \\ <|unfolded-io> pwd <|unfolded-io> /home/ag/.TeXmacs/plugins/pure/doc Completion of Pure keywords and functions is fully supported in . Just type as usual and displays a list of possible completions in its status line. Pressing again you can cycle through the completions and pick the one that you want. For instance, you can try this yourself on the following input line by placing the cursor behind the and hitting the key repeatedly: <\session|pure|default> <\input> \\ <|input> f The Pure command also works in . This pops up a new window with the help file in it. Search terms also work as usual; you might want to try the following to find out how the Pure help system works (this may take a while to load, so be patient): <\session|pure|default> <\input> \\ <|input> help online-help Note that Pure's online help is in html format by default. While can load html files, it has to convert them to its own format first, which at least in the current version of is quite slow and the rendering isn't perfect. As a remedy, there's -formatted online documentation available on the Pure website, see the Pure installation instructions for details. If these files are installed then the Pure help can also be accessed using the corresponding options in the plugin menu which automatically appears when the cursor is inside a Pure session. If you still prefer the html documentation, then it's also possible to use an external graphical html browser instead. Just set the shell environment variable accordingly, the interpreter will then use that command to display the online help.<\footnote> Note that the environment variable also works outside of , i.e., when the interpreter is run from Emacs or the shell. The environment variable, however, does change the way that the command works in , so you can use this variable instead to specify a browser program for use outside of only. The following example shows how to run the Reduce computer algebra system in Pure (to make this work, you also need to have the module installed; this is available as an addon from the ). <\session|pure|reduce> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\unfolded-io> \\ <|unfolded-io> using reduce; <|unfolded-io> Reduce (Free CSL version), 03-Nov-12 ... <\unfolded-io> \\ <|unfolded-io> simplify (df (sin (x^2)) x); <|unfolded-io> 2*cos (x^2)*x Up to now we've only been running Pure in verbatim a.k.a.program mode. But the Pure plugin also fully supports math input and output. These are enabled as follows: <\itemize> To use math , you can toggle the input line between math and program (verbatim) mode using the key combination. This isn't a standard keybinding, but is defined at the beginning of the script for your convenience; you can edit the script to change this according to your preferences. Of course, you can also use the corresponding menu option or the equivalent toolbar item; these become visible when the cursor is located at the input line. Or you can make math input the default by putting the following Scheme command into your file: <\scm-code> (if (not (session-math-input?)) (toggle-session-math-input)) To enable math , you'll have to invoke the function from the Pure module. This module is always loaded when running Pure inside . The function uses the Reduce package, so the module be installed to make this work. The function switches back to verbatim Pure output. Verbatim output is also used as a fallback in math mode for all Pure expressions which cannot be printed through the Reduce interface (typically because they aren't valid Reduce expressions). To make math output the default, you can also run a session () which works like a regular Pure session but enables math output and loads the module at startup. At present this is still a bit experimental and work in progress, but it seems to work pretty well already, as shown below. (If you notice any bugs or missing features in math input and output, please submit a bug report on the .) <\session|pure|reduce> <\unfolded-io> \\ <|unfolded-io> math; <|unfolded-io> () <\unfolded-io-math> \\ <|unfolded-io-math> simplify |)>|)> x|)>; <|unfolded-io-math> |)>*x> <\unfolded-io-math> \\ <|unfolded-io-math> simplify |)> x|)>; <|unfolded-io-math> *sin +x|2>> A more detailed account on math input and output can be found in the following section. For the purposes of this section, let's start up a regular Pure session and load the and modules. <\session|pure|math> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\unfolded-io> \\ <|unfolded-io> using math, reduce; <|unfolded-io> Reduce (Free CSL version), 03-Nov-12 ... <\unfolded-io> \\ <|unfolded-io> simplify (df (sin (x^2)) x); <|unfolded-io> 2*cos (x^2)*x To enter an expression like the one above as a mathematical formula, we must first switch the input line to . To do that, you can go search the toolbar for and check it, or type the key combination defined by the Pure plugin. Another useful convenience is the prefix operator (defined in ) which simplifies its expression argument, which is quoted automagically. Here's how the expression looks like when typed in math input mode: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> ?df |)>|)> x; <|unfolded-io-math> 2*cos (x^2)*x This is pretty much the same as: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> simplify df |)>|)> x|)>; <|unfolded-io-math> 2*cos (x^2)*x But it's a lot easier to type, and the operator uses rather than just , which also supports some customary notation for limits, integrals and differentials commonly used in . The operator does the same, but evaluates its argument; you want to use that if the expression includes some Pure functions which should be evaluated before submitting the result to Reduce. Note the difference: <\session|pure|math> <\input-math> \\ <|input-math> foo x = x+1; <\unfolded-io-math> \\ <|unfolded-io-math> ?intg x; <|unfolded-io-math> \; *** foo declared operator\ intg (foo x) x <\unfolded-io-math> \\ <|unfolded-io-math> ?:intg x; <|unfolded-io-math> (x^2+2*x)/2 Note that both and are at the lowest possible precedence level in Pure so that their arguments don't have to be parenthesized (but this also means that you'll have to parenthesize the entire or expression if you want to use it in the context of a larger expression). Once we change to , simplifications of expressions are done automatically by the pretty-printer, so we can often do without explicitly using the , and operations. We'll do the rest of this session in this mode, so let's switch to it now. As explained in the previous section, this is done by invoking the function from the module.<\footnote> Note the keyword before the call to . In Pure this normally indicates a global variable definition, but if the left-hand side is omitted, the interpreter executes the right-hand side expression as usual and skips the printing of the result, similar to what the terminator does in Reduce. We'll use this trick a lot in the following, to suppress uninteresting evaluation results. <\session|pure|math> <\input-math> \\ <|input-math> let math; <\unfolded-io-math> \\ <|unfolded-io-math> df |)>|)> x; <|unfolded-io-math> |)>*x> Note that the term got simplified, but that's only in the display: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> df (sin (x^2)) x To actually obtain a simplified result which can be processed further in Pure land (passed to Pure functions or assigned to Pure variables), you still need to use , etc.: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> ?df |)>|)> x; <|unfolded-io-math> |)>*x> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> 2*cos (x^2)*x Note that the function from the module lets us peek at how the verbatim result looks like, without actually switching to verbatim mode. Similarly, the function temporarily switches the output mode to math mode when in verbatim mode. There are some Pure expressions (such as strings, lambdas and pointers) which are always printed verbatim. However, the pretty-printer will try to print as much of the result in math mode as it can. For instance: <\session|pure|math> <\unfolded-io> \\ <|unfolded-io> (\\x-\x^2),"abc",df (sin (x^2)) x*y; <|unfolded-io> #\closure 0x7f1db00e3580\,"abc",|)>*x*y> There are in fact two different variations of math output mode. Just calling is the same as which corresponds to Reduce's and causes printed expressions to be simplified before they are printed. In contrast, employs Reduce's to pretty-print the raw expressions simplifying them.<\footnote> Note that these commands don't actually change Reduce's internal mode of operation, they only affect the display mode in . Likewise, there are functions (which is a synonym for ) and to temporarily switch to the algebraic and symbolic math output modes, respectively. For instance: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> df |)>|)> x;> <|unfolded-io-math> |)>*x> <\unfolded-io-math> \\ <|unfolded-io-math> symb ans;> <|unfolded-io-math> *sin |)>|\*x>> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans;> <|unfolded-io-math> df (sin (x^2)) x Note that there are some kinds of symbolic expressions (specifically, the logical expressions other than equality) which aren't by default valid in Reduce's algebraic mode, but work in symbolic mode: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> x\y\y\0; <|unfolded-io-math> \=&&\ <\unfolded-io-math> \\ <|unfolded-io-math> symb ans; <|unfolded-io-math> y\y\0> <\unfolded-io-math> \\ <|unfolded-io-math> ?x\0; <|unfolded-io-math> \; ***** \ invalid as algebraic operator\ \; ***** \ invalid as algebraic operator\ \ As a remedy, you can just declare the logical operations as Reduce operators; this won't actually convince Reduce to simplify them, but at least it gets rid of those annoying error messages and also makes the pretty-printer do a nicer job in algebraic mode: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> declare operator |)>,|)>,|)>,|)>,|)>,|)>,|)>,|)>|]>; <|unfolded-io-math> () <\unfolded-io-math> \\ <|unfolded-io-math> x\y\y\0; <|unfolded-io-math> y\y\0> <\unfolded-io-math> \\ <|unfolded-io-math> ?x\y\y\0; <|unfolded-io-math> y\y\0> Most mathematical expressions are mapped to corresponding Pure expressions in a sensible way. We start out by declaring a few additional operators to be used below, so that they are known to Reduce. (This isn't strictly necessary, but silences the ``'' messages from Reduce.) <\session|pure|math> <\input-math> \\ <|input-math> let declareoperator ; <\unfolded-io-math> \\ <|unfolded-io-math> x\2*x+\|)> 5; <|unfolded-io-math> +> <\unfolded-io-math> \\ <|unfolded-io-math> x,x,x,x,,;> <|unfolded-io-math> !,>,!,>,>,> <\unfolded-io-math> \\ <|unfolded-io-math> ,,,,x/y; <|unfolded-io-math> >,>,>,>,> <\unfolded-io-math> \\ <|unfolded-io-math> 189\30;> <|unfolded-io-math> |>> <\unfolded-io-math> \\ <|unfolded-io-math> +;> <|unfolded-io-math> +> <\unfolded-io-math> \\ <|unfolded-io-math> |>||>>>>, |>||>>>>, |>||>>>>;> <|unfolded-io-math> |>||>>>>|)>>,|>||>>>>|)>>,|>||>>>>|)>> <\unfolded-io-math> \\ <|unfolded-io-math> |>||>>>>;> <|unfolded-io-math> +b|)>> <\unfolded-io-math> \\ <|unfolded-io-math> ||>>>>, >|>|>>>>;> <|unfolded-io-math> ||>>>>|)>>,>|>|>>>>|)>> <\unfolded-io-math> \\ <|unfolded-io-math> exp*\+\;> <|unfolded-io-math> *\+\> <\unfolded-io-math> \\ <|unfolded-io-math> +y>, ;> <|unfolded-io-math> +y>>,3>> <\unfolded-io-math> \\ <|unfolded-io-math> \A\C|)>;> <|unfolded-io-math> \C|)>> <\unfolded-io-math> \\ <|unfolded-io-math> x\y, x\y, x\y,x\y,x\y,x\y;> <|unfolded-io-math> y>,y>,y>,y>,y>,y> <\unfolded-io-math> \\ <|unfolded-io-math> y, x\y|)>;> <|unfolded-io-math> ===,~== <\unfolded-io-math> \\ <|unfolded-io-math> eval ans; <|unfolded-io-math> , <\unfolded-io-math> \\ <|unfolded-io-math> ;> <|unfolded-io-math> >2>3|]>> <\unfolded-io-math> \\ <|unfolded-io-math> 1\10; 1:3\11;> <|unfolded-io-math> >2>3>4>5>6>7>8>9>|]>> >3>5>7>9>|]>> <\unfolded-io-math> \\ <|unfolded-io-math> a=1\10;a mod 2|]>;> <|unfolded-io-math> >4>6>8>|]>> <\unfolded-io-math> \\ <|unfolded-io-math> ; ; |a,b+1|\>; |a,b+1|\>; |n/2|\>; |n/2|\>; ; |x|\<\|\|\>>;> <|unfolded-io-math> , >b+1|]>> , >b+1|]>> |)>> |)>> > > <\input-math> \\ <|input-math> let declareoperator ; <\unfolded-io-math> \\ <|unfolded-io-math> ;;>;>;>;>;>;>;>;>;x;x; ;\x;> <|unfolded-io-math> > > > > > > > > > > ' > > <\unfolded-io-math> \\ <|unfolded-io-math> x\y;x\y;x\y;x\y;x\y;x\y;x\y;x\y;x\y;x\y;> <|unfolded-io-math> oplus ominus otimes oslash pm mp % cap cup uplus <\unfolded-io-math> \\ <|unfolded-io-math> \;\;\;\;\;\;\;\,\,\;\;> <|unfolded-io-math> > > ,, <\unfolded-io-math> \\ <|unfolded-io-math> ,,,,,;> <|unfolded-io-math> ,,,,, <\unfolded-io-math> \\ <|unfolded-io-math> , , , , , , , , ;> <|unfolded-io-math> ,,,,,,,,,,,,,,,,, More examples using list and matrix comprehensions (these are all plain Pure evaluations, Reduce is only used for the pretty-printing here):<\footnote> Note that in order to get the single vertical bar in math mode, you'll have to type either or (the latter gives you a ``big'' symbol which automatically expands with the brackets surrounding it). <\session|pure|math> <\input> \\ <|input> |X\matrix|\<\|\|\>> = x=X|]>>;> <\unfolded-io> \\ <|unfolded-io> ||||>>>>|\<\|\|\>>;> <|unfolded-io> <\unfolded-io> \\ <|unfolded-io> x=1\5|]>;> <|unfolded-io> >5>7>9>|]>> <\input-math> \\ <|input-math> eye n = ji=1\n;j=1\n>>>>>; <\unfolded-io-math> \\ <|unfolded-io-math> eye 3; <|unfolded-io-math> ||>|||>|||>>>>|)>> Here's an example of an infinite list, a prime sieve: <\session|pure|math> <\input-math> \\ <|input-math> P=sieve (2\\) sieve(p:) = p :sieve[qq = ; q p] & ; <\unfolded-io-math> \\ <|unfolded-io-math> P!!20|)>; <|unfolded-io-math> >3>5>7>>>>>>>>>>>>>>>>|\>> |>73|]>> <\unfolded-io-math> \\ <|unfolded-io-math> list |)>; <|unfolded-io-math> >>>>>>>>>>>>>>>|\>> |641>>>>|]>> has a nice and convenient notation for labelled trees. These are handled gracefully in Pure as well: <\session|pure|math> <\input-math> \\ <|input-math> let declare operator tree; <\unfolded-io-math> \\ <|unfolded-io-math> >; <|unfolded-io-math> |)>> Because is variadic (a tree may have any number of subtrees), it's denoted as an uncurried function in Pure. The first argument of is always the label of the root node, the remaining arguments are the subtrees and/or leaves beneath the root node. The simplest way to translate this into a nested Pure list for easier processing is to just define as the standard Pure function : <\session|pure|math> <\input-math> \\ <|input-math> tree=list; <\unfolded-io-math> \\ <|unfolded-io-math> >; <|unfolded-io-math> >b>c>>y>z|]>|]>> This corresponds to a preorder traversal of the tree. If you prefer to have the labels of the branches as separate arguments then you might use a definition like the following instead: <\session|pure|math> <\input-math> \\ <|input-math> clear tree <\unfolded-io-math> \\ <|unfolded-io-math> declare operator branch; <|unfolded-io-math> () <\input-math> \\ <|input-math> tree \tuple|)>=branch x |)>; tree =branch x ; <\unfolded-io-math> \\ <|unfolded-io-math> >; <|unfolded-io-math> >c>>z|]>|)>|]>|)>> Note that the way we defined , is in fact a curried constructor; the uncurried notation is an artifact of the pretty-printing here. As a verbatim Pure term the result looks like this: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> branch a [b,c,branch x [y,z]] If the trees denote valid Pure terms then you might wish to get rid of all the extra baggage and just translate them to plain Pure applications. Here's a third variation of which does this: <\session|pure|math> <\input-math> \\ <|input-math> clear tree <\input-math> \\ <|input-math> tree x=foldl1 ; <\unfolded-io-math> \\ <|unfolded-io-math> |)>|y|z>>; <|unfolded-io-math> \; *** f declared operator\ > <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> f a b (y*z) With this definition of you can now enter arbitrary Pure expressions as trees if you like: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> ||a|b>|2>; <|unfolded-io-math> +2*a*b+b> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> (a+b)^2 List and vector/matrix data can be exchanged between Pure and Reduce in a seamless fashion. This makes it easy to inspect and manipulate compound results returned by Reduce, such as lists of partial fractions: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> let p=2/*|)>; p; <|unfolded-io-math> +4*x+5*x+2>> <\unfolded-io-math> \\ <|unfolded-io-math> let off exp; p;> <|unfolded-io-math> *>> <\unfolded-io-math> \\ <|unfolded-io-math> let pfs = ?:pf px; pfs; <|unfolded-io-math> >>>|]>> <\unfolded-io-math> \\ <|unfolded-io-math> map df yx|)> pfs; <|unfolded-io-math> >>>>>|]>> <\unfolded-io-math> \\ <|unfolded-io-math> let on exp; ans;> <|unfolded-io-math> +4*x+4>>+2*x+1>>+3*x+3*x+1>|]>> Let's consider another typical example, equation solving: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> leteqn=log|)>\8; eqn; <|unfolded-io-math> |)>\8> <\input-math> \\ <|input-math> let solns=?:solve eqnx; <\unfolded-io-math> \\ <|unfolded-io-math> #solns; take 2 solns; <|unfolded-io-math> 2**\+arcsin *cos |5>|)>|)>|exp *sin |5>|)>*i|)>>|)>-3>x\2**\-arcsin *cos |5>|)>|)>|exp *sin |5>|)>*i|)>>|)>+\-3|]>> <\unfolded-io-math> \\ <|unfolded-io-math> let solns=?:reduce_with cst 0|]>solns; take 2 solns; <|unfolded-io-math> arcsin *cos |5>|)>|)>|exp *sin |5>|)>*i|)>>|)>-3>x\-arcsin *cos |5>|)>|)>|exp *sin |5>|)>*i|)>>|)>+\-3|]>> <\input-math> \\ <|input-math> check \ v|)> y|)>=evaly|]> |)>; <\input-math> \\ <|input-math> \ s=check eqns;let \=10; <\unfolded-io-math> \\ <|unfolded-io-math> x\y=solns;\y|)>\0|]>;> <|unfolded-io-math> >|)>-3>-arcsin >|)>+\-3|]>> <\unfolded-io-math> \\ <|unfolded-io-math> s@y|)>=solns;\ s\0\\ s\\|]>;> <|unfolded-io-math> *cos |5>|)>+2*sin |5>|)>*i|)>|)>-3|]>> <\unfolded-io-math> \\ <|unfolded-io-math> \ s s@y|)>=solns;\ s\\|]>;> <|unfolded-io-math> *cos |5>|)>|)>|exp *sin |5>|)>|)>*i|)>>|)>-3\>*cos |5>|)>|)>|exp *sin |5>|)>|)>*i|)>>|)>+\|)>-3\>|\>> *cos |5>|)>+*sin |5>|)>|)>*i|)>>|)>-3\>*cos |5>|)>+*sin |5>|)>|)>*i|)>>|)>+\|)>-3\>> *sin |5>|)>|)>*i|)>|e*cos |5>|)>>>|)>-3\>*sin |5>|)>|)>*i|)>|e*cos |5>|)>>>|)>+\|)>-3\>> |*cos |5>|)>+*sin |5>|)>|)>*i|)>|)>+\|)>-3\|]>> Big operators ( in math mode) are mapped to corresponding Pure expressions, generally using a Reduce-compatible form: <\session|pure|math> \; <\unfolded-io-math> \\ <|unfolded-io-math> sin x \x; <|unfolded-io-math> > <\unfolded-io> \\ <|unfolded-io> reduce::load "defint"; // we need this for the definite integrals <|unfolded-io> <\unfolded-io-math> \\ <|unfolded-io-math> x\x;x\x; <|unfolded-io-math> +b|3>> +b|3>> <\unfolded-io-math> \\ <|unfolded-io-math> lim0>, lim\>|)>,lim\>; <|unfolded-io-math> >,, <\unfolded-io-math> \\ <|unfolded-io-math> sin x \x,x\x,x\x; <|unfolded-io-math> >,+b|3>>,+b|3>> <\unfolded-io-math> \\ <|unfolded-io-math> ,; <|unfolded-io-math> >,*|2*\>> <\unfolded-io-math> \\ <|unfolded-io-math> , ; <|unfolded-io-math> |2>>,+3*n+2>> Sums and products with known (i.e., non-symbolic) bounds are translated to the appropriate aggregates of Pure list comprehensions so that they can be computed directly in Pure: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> ,; <|unfolded-io-math> , This is always the case if the entire generator clause is given as a subscript and the superscript is absent: <\session|pure|math> <\unfolded-io> \\ <|unfolded-io> 5>,5>;> <|unfolded-io> , Note that the above is equivalent to the following verbatim Pure code: <\verbatim-code> sum [(2*k-1)\|k=1..5], prod [(2*k-1)\|k=1..5]; The same holds for a number of other big operators, such as the big wedge and vee, which have no counterpart in Reduce. These aren't predefined in Pure either, but we can implement some useful Pure operations with them, for instance: <\session|pure|math> <\input-math> \\ <|input-math> bigwedge=foldl |)> true;bigvee=foldl |)> false; <\unfolded-io> \\ <|unfolded-io> |\0|)>,\0|)>|\> x=-3\3; n=#x ;> <|unfolded-io> , Both differentials and integrals can be specified using customary mathematical notation which gets translated to invocations of the Reduce and operators (the latter is actually named in Pure, to avoid a name clash with the built-in Pure function ). They are constructed according to the following syntactical rules: <\itemize> The differential operator is written as , which may be denoted either as a function application (with a space between and ) or as a product with an (invisible) multiplication sign between and . Instead of , you can also use the upright d symbol ( or in math input mode), in which case no delimiter between d and is needed. In the case of differentials you may also use the partial symbol > ( or ) instead. Integrals take the form f*\*x> ( or ) with the appropriate delimiters between , > and (either invisible multiplication signs or spaces; again these may be omitted if the special upright d symbol is used). Differentials are written as a quotient f/\x>, using either the operator or an explicit fraction ( or ).<\footnote> Note that in the former case the denominator *x> has to be parenthesized if it is written in multiplicative form. This is because the multiplication operators including and are left-associative in Pure, so will be parsed as rather than . This pitfall can be avoided by just using an explicit fraction instead. Higher-order differentials may be denoted either as an application k f/\ x k> or with a superscript f/\x>. In either case, multiple differentiation variables can be given as a product of the corresponding differential terms in the denominator, such as f/x*\y|)>>. Moreover, the notation /\x*f> (with a multiplication sign between /\x*> and ) is provided as an alternative to f/\x>. Note that if or are compound expressions, you may have to put them in parentheses according to the rules of Pure syntax. (If multiplication signs are used as delimiters and both and are either symbols or function applications, this is usually unnecessary since these bind stronger than both multiplication and exponents.) Of course, in either case you may also just write the corresponding Pure/Reduce call, which is often easier to type, but doesn't nearly look as nice and mathematical. It is also instructive to take a look at how Reduce itself renders calls to and ; you can always copy such output to the input line again and it should just work. Here are some examples. <\session|pure|math> <\input-math> \\ <|input-math> let declaredepend ; <\unfolded-io-math> \\ <|unfolded-io-math> df f x 2, intg f x; <|unfolded-io-math> *f|\*x>>,f*d*x> <\unfolded-io-math> \\ <|unfolded-io-math> \*f/\x; <|unfolded-io-math> *f|\*x>> <\unfolded-io-math> \\ <|unfolded-io-math> 2*f\x; <|unfolded-io-math> f*d*x> <\unfolded-io-math> \\ <|unfolded-io-math> 2*f\ ; <|unfolded-io-math> *f> <\unfolded-io-math> \\ <|unfolded-io-math> \|)>/\x; <|unfolded-io-math> <\unfolded-io-math> \\ <|unfolded-io-math> *y*z|)>|\x*\y*\z>; <|unfolded-io-math> <\unfolded-io-math> \\ <|unfolded-io-math> \/\x*; <|unfolded-io-math> +4*x*y+6*x*y+4*x*y+y|)>> <\unfolded-io-math> \\ <|unfolded-io-math> \/\x**cos|)>; <|unfolded-io-math> -sin > <\unfolded-io-math> \\ <|unfolded-io-math> sin\x; <|unfolded-io-math> |2>> <\unfolded-io-math> \\ <|unfolded-io-math> |x*\x|\> b=0 ; <|unfolded-io-math> *a*x|n+3>> It is often convenient to abbreviate parametric Reduce expressions using Pure functions. We'll learn about different ways to enter Pure functions in math mode below, but for the moment it suffices to know that the simplest form is just x\x=> where is the name of the function, ,\,x> are the parameters and is the right-hand side (the body) of the definition. Note the missing parentheses around the parameters. Pure uses the curried notation for function applications where the parameters simply follow the function, similar to shell command syntax. For compatibility with Reduce, function calls in expressions can also be specified in the usual uncurried form ,\,x|)>>, but Pure definitions and expressions generally use the curried form. For instance: <\session|pure|math> <\input-math> \\ <|input-math> Iabn=?x*\x; Note that we employed the operator here so that the function produces a simplified result rather than just a literal integral which then needs to be computed when pretty-printed. <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> I a b n; <|unfolded-io-math> **n*x+3*a*n*x+2*a*x+a*b*n*x+a*b*n*x-2*a*b*n*x+2*b|)>|a*+6*n+*n+6|)>>> <\unfolded-io-math> \\ <|unfolded-io-math> I a b 0; <|unfolded-io-math> |3>> <\unfolded-io-math> \\ <|unfolded-io-math> I 0 b n; <|unfolded-io-math> *x|3>> <\unfolded-io-math> \\ <|unfolded-io-math> I a 0 k; <|unfolded-io-math> *a*x|k+3>> We've already seen various simple kinds of Pure programs (i.e., function definitions) throughout this section. One important thing to note here is that all supported math elements not only work in expressions to be evaluated, but also when defining functions, on sides of the definition. We can make good use of this to make Pure code look like real mathematical formulas. For instance, let's define a prettier notation for the list slicing operator ( in Pure). We'd actually like to write an ordinary index in math mode, like this: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> |)>n>; <|unfolded-io-math> !(..) As you can see, this kind of expression isn't readily defined in Pure, so we can do it ourselves: <\session|pure|math> <\input-math> \\ <|input-math> \list|)>\list>=!!; That's it. Now we can write: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> "z"|)>16>; <|unfolded-io-math> ["k","l","m","n","o","p","q"] <\input-math> \\ <|input-math> P=sieve (2\\) sieve(p:) = p :sieve[qq = ; q p] & ; <\unfolded-io-math> \\ <|unfolded-io-math> P117>; <|unfolded-io-math> >>>>>>>>>>>>>>>|\>> |631>>>|]>> Let's consider another example, the binomials: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> ; <|unfolded-io-math> > This function isn't predefined in Pure either, so let's do that now. To get nicely aligned equations, we'll use an equation array this time. This is available as in math mode; similarly, the binomials can be entered with in math mode: <\session|pure|math> <\input-math> \\ <|input-math> <\eqnarray*> int|k\int>>||+n\k\k\0;>>|||;>>>> <\unfolded-io> \\ <|unfolded-io> show binom <|unfolded-io> binom n::int k::int = binom (n-1) (k-1)+binom (n-1) k if n\k&&k\0; binom n::int k::int = 1; Let's calculate the first five rows of the Pascal triangle to see that it works: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> k=0\n|]>n=0\5|]>; <|unfolded-io-math> >>1|]>>>2>1|]>>>3>3>1|]>>>4>6>4>1|]>>>5>>>5>1|]>|]>> Of course, the text book formula we used above isn't the best way to implement binomials. The following algorithm employing factorials is much faster; it also uses bigints to prevent wrapover. <\session|pure|math> <\input-math> \\ <|input-math> clear binom> <\input-math> \\ <|input-math> int|k\int>=>i|)> div>i|)>; <\unfolded-io-math> \\ <|unfolded-io-math> ; <|unfolded-io-math> As we already saw in the prime sieve example, Pure can deal with ``lazy'' lists (called in functional programming parlance) just fine. So let's be bold and just define the infinite stream of rows of the Pascal triangle. This is easily done with a nested list comprehension in Pure: <\session|pure|math> <\input-math> \\ <|input-math> binomials =k=0\n|]>n=0\\|]>; <\unfolded-io-math> \\ <|unfolded-io-math> binomials; binomials5>; binomials; <|unfolded-io-math> >:#\thunk 0x7ff6b44e0ef0\ >>1|]>>>2>1|]>>>3>3>1|]>>>4>6>4>1|]>>>5>>>5>1|]>|]>> >>>>>>>>>>|\>> >>>>>>>> >>>>>>>> |>142506>>>>>1|]>> Sometimes we may want to align subterms in expressions or definitions, in order to improve the readability of a formula. provides the construct for this purpose, which arranges stuff in rows and columns pretty much like a matrix. The Pure converter simply traverses this construct in row-major order. Thus the \ |>||>>>>> stack will expand to just in Pure. This can be used, in particular, to align the parts of an equation or comprehension. For instance: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> |||5;>>|||n>>>>>|]>; <|unfolded-io-math> >1>1>1>2>1>1>3>3>1>1>4>6>4>1>1>5>>>5>1|]>> Note that the above produces exactly the same result as the following linear notation: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> n=0\5;k=0\n|]>; <|unfolded-io-math> >1>1>1>2>1>1>3>3>1>1>4>6>4>1>1>5>>>5>1|]>> Moreover, the construct can be used to write Pure function definitions involving guards in a compact and pretty way. For instance, here's another definition of the factorial, this time entered in math mode:<\footnote> Note that the keyword is mandatory here, as it is required by the Pure syntax (as are the semicolons). The keyword is just syntactic sugar, however, although it often improves readability. <\session|pure|math> <\input-math> \\ <|input-math> fact = |n\0>>|fact>|>>>>>; <\unfolded-io-math> \\ <|unfolded-io-math> map fact 12|)>; <|unfolded-io-math> [,,,,,,,,,,,,479001600] The above definition is in fact equivalent to the following verbatim Pure code (which isn't all that unreadable either, as Pure's function definition syntax already mimics mathematical notation very closely): <\verbatim-code> fact(n) = 1 if n\=0; = n*fact(n-1) otherwise; Of course, the same construct can also be used to define local functions: <\session|pure|math> <\unfolded-io-math> \\ <|unfolded-io-math> map fact 12|)>fact = |n\0>>|fact>|>>>>>; <|unfolded-io-math> [,,,,,,,,,,,,479001600] Last but not least, the construct can also be used with Pure's pattern-matching expressions. Note that the closing of the expression is omitted, the construct supplies it automatically. <\session|pure|math> <\input-math> \\ <|input-math> \list|\|>= >|||>|>|||\|>>|>>>>>; <\unfolded-io-math> \\ <|unfolded-io-math> 100|\|>; <|unfolded-io-math> This defines |\|>> (a.k.a. in Pure notation) to compute the size of a list (similar to what Pure's operator does). For instance, let's count the number of primes up to 5000 (this may take a little while; alas, our definition of the prime sieve isn't very efficient!): <\session|pure|math> <\input-math> \\ <|input-math> P=sieve (2\\) sieve(p:) = p :sieve[qq = ; q p] & ; <\unfolded-io-math> \\ <|unfolded-io-math> 5000|)> P|\|>; <|unfolded-io-math> doesn't know anything about Pure syntax; as far as it is concerned, Pure's functions, operators and keywords are just text. So there are situations in which you may have to help the converter along by adding parentheses to disambiguate the parsing. This is true, in particular, for big operators (integrals, sums, etc., especially in conjunction with Pure and clauses) and differentials. Even an invisible bracket (shortcut: ) will be good enough. For instance: <\session|pure|caveats> <\unfolded-io> \\ <|unfolded-io> let math; <|unfolded-io> Reduce (Free CSL version), 03-Nov-12 ... <\unfolded-io-math> \\ <|unfolded-io-math> \x/\x; <|unfolded-io-math> \; *** d declared operator\ > Note the missing bracket around >. As reveals, this yields instead of (which is what we want): <\session|pure|caveats> <\unfolded-io-math> \\ <|unfolded-io-math> verb ans; <|unfolded-io-math> d x^2/d x The remedy is to just parenthesize the > term: <\session|pure|caveats> <\unfolded-io-math> \\ <|unfolded-io-math> \||)>|\>/\x;> to disambiguate> <|unfolded-io-math> <\unfolded-io-math> \\ <|unfolded-io-math> \|x|\>/\x;> does the trick> <|unfolded-io-math> Here's another snippet which produces a strange error: <\session|pure|caveats> <\unfolded-io-math> \\ <|unfolded-io-math> n>,n> n = 5; <|unfolded-io-math> <\errput> \stdin\, line 6: syntax error, unexpected '\|', expecting end The tuple (comma operator) binds stronger than the clause, so this looks like valid Pure syntax. What went wrong? Unfortunately, we can't use to reveal how Pure parsed the expression here, because it couldn't! But there's a neat trick to show us what exactly fed into the Pure interpreter: just copy and paste the entire expression to another input line operated in verbatim input mode. We get: <\session|pure|dummy> <\input> \\ <|input> sum [(2*k-1)\|k=1..n],prod [(2*k-1) when n \|k=1..n]= 5 end; Note that for the `` n>'' part looks like any other ordinary term belonging under the product on the right, which is followed by an equals sign and another term ``>''. This makes perfect sense for , but it's not valid Pure syntax. This wouldn't normally be a problem (Pure would be able to reparse the expression correctly anyway), if it wasn't for the >operator which translates to a Pure list comprehension. So the `` n>'' part ended up in this list comprehension where it doesn't belong, hence the somewhat surprising syntax error. Placing brackets around either the entire tuple or just the product on the right correctly resolves the ambiguity. In this case, we might as well use visible parentheses, since they make the expression easier to parse for human readers, too: <\session|pure|caveats> <\unfolded-io-math> \\ <|unfolded-io-math> n>,n>|)> n = 5; <|unfolded-io-math> , We can copy/paste the modified expression to a verbatim input line again, to confirm that it was converted correctly this time: <\session|pure|dummy> <\input> \\ <|input> (sum [(2*k-1)\|k=1..n],prod [(2*k-1)\|k=1..n]) when n = 5 end; It's also possible to call Octave from Pure in order to do numeric calculations, and use the math output mode to handle the pretty-printing via Reduce. To do this, you also need to have the package installed. For instance: <\session|pure|octave> <\output> \; \ __ \\ \ \| \ \ \| \ __\| _ \\ \ \ \ Pure 0.56 (x86_64-unknown-linux-gnu) \ \| \ \ \| \| \ \ \| \| \ \ \ __/ \ \ \ Copyright (c) 2008-2012 by Albert Graef \ .__/ \\__,_\|_\| \ \\___\| \ \ \ (Type 'help' for help, 'help copying' _\| \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for license information.) \; Loaded prelude from /usr/lib/pure/prelude.pure. \; <\unfolded-io> \\ <|unfolded-io> using octave; let math; <|unfolded-io> Reduce (Free CSL version), 03-Nov-12 ... <\input-math> \\ <|input-math> <\eqnarray> ||;>>|x>||;>>>> <\unfolded-io-math> \\ <|unfolded-io-math> eig |>||>>>>; <|unfolded-io-math> >|>>>>|)>> <\unfolded-io-math> \\ <|unfolded-io-math> eig2 |>||>>>>; <|unfolded-io-math> |>||>>>>|)>>,|>||>>>>|)>> It goes without saying that this is pretty useful if a problem calls for a mix of symbolic and numeric algorithms. It's also possible to call back into Pure from Octave, and thereby into Reduce. To do this, you need to wrap up the computation as a Pure function which in turn uses or to invoke Reduce. Just to illustrate how this works, here's a (somewhat contrived) example where we call the Reduce transpose function from Octave: <\session|pure|octave> <\input-math> \\ <|input-math> tp x\matrix=?tp; <\unfolded-io> \\ <|unfolded-io> octave_call "pure_call" 1 ("tp",{1,2;3,4}); <|unfolded-io> |>||>>>>|)>> <\unfolded-io> \\ <|unfolded-io> let octave_eval "pure_call('tp',[1 2;3 4])"; // Octave output! <|unfolded-io> ans = \; \ \ \ 1 \ \ 3 \ \ \ 2 \ \ 4 In a similar fashion you might, e.g., have Octave call Pure to solve an equation which Octave itself can't handle. With the module included in the latest version of the package, you can also make good use of Octave's Gnuplot interface. There's a convenience function named in the module which grabs an Octave plot in PostScript format and pipes it into so that it gets inserted directly into the session output. (The function is in fact just a little wrapper around the Octave function and the function from the module described in the following section.) For instance, here's how to do a basic function plot. We have to import the module and, since we're doing all calculations in Pure here, we also need the module for the and functions. Also note that the Octave plotting functions are all in their own namespace, so for convenience we import this namespace. The module also provides various utility functions such as which we use here to generate a vector of values for the plot. <\session|pure|octave> <\input-math> \\ <|input-math> gnuplot,math; gnuplot; <\unfolded-io-math> \\ <|unfolded-io-math> x=linspace|)>; fig1=plot;axis "tight"; <|unfolded-io-math> () <\unfolded-io-math> \\ <|unfolded-io-math> psplot; <|unfolded-io-math> |ps>||||> "/tmp/oct-7P9aFt.eps" As you can see, the function also returns the name of the PostScript file it generated, which is a temporary file by default. It's also possible to explicitly specify a filename and other options understood by the command. For instance: <\session|pure|octave> <\unfolded-io-math> \\ <|unfolded-io-math> fig2=sombrero;psplot "sombrero.eps"; <|unfolded-io-math> |ps>||||> "sombrero.eps" The given filename is interpreted relative to the current directory of the interpreter (which is normally the directory in which was started). You can also display the Gnuplot window for 3d viewing, and hide it again, as follows (these operations aren't part of Octave's plot functions, but are provided as convenience functions in the module):\ <\session|pure|octave> <\unfolded-io-math> \\ <|unfolded-io-math> popup; <|unfolded-io-math> () <\unfolded-io-math> \\ <|unfolded-io-math> popdn; <|unfolded-io-math> () Octave's Gnuplot interface is very comprehensive. Please refer to the for a description of the provided plotting functions. Most of the plotting examples given in the Octave documentation can be translated to Pure in a fairly straightforward manner. More examples can be found in the package. Like the Python plugin, Pure can pipe PostScript graphics directly into . This is done with the function from the module which takes either verbatim PostScript code (indicated by a header) or a PostScript filename as its string argument. In the latter case, if the PostScript filename doesn't have a slash in it, it is searched for in all directories on the , and a or suffix is added automatically when needed. Otherwise the filename is interpreted relative to the current directory of the interpreter (which is normally the directory in which was started). Here is a simple example illustrating verbatim PostScript code: <\session|pure|postscript> <\unfolded-io> \\ <|unfolded-io> ps "%!\\n%%BoundingBox: 195 295 405 405\\n/Times-Roman findfont 20 scalefont setfont newpath 200 300 moveto 200 0 rlineto 0 100 rlineto -200 0 rlineto 0 -100 rlineto 235 345 moveto (Hello, world!) show closepath stroke showpage"; <|unfolded-io> |ps>||||> () Last but not least, Pure can also be used as a in . This is done by enabling the option (or if you prefer math output; this is what we use here). This enables a few additional options in the plugin menu, as well as the menu and the corresponding toolbar button. These facilities are described in more detail at the end of the `` \ as an interface'' section in the online help, so we only give a few basic examples here. For instance, you can just select any valid Pure expression in the text and evaluate it with the option of the menu or like this: > > +2*a*b+b>. It's also possible to create an such as ,x|)>>|+2*x*y+y|)>>> which can be toggled between input and computed result by pressing inside the field (try it!). Note that as an additional convenience, the scripting plugins accept a simple expression without the trailing semicolon as input. This is in contrast to the regular Pure plugins which allow you to enter definitions and expressions spanning multiple input lines, but also require you to terminate each input item with a semicolon. With the scripting plugins the terminating semicolon is optional and will be added automatically when needed, but it also doesn't hurt if you type it anyway: ,x|)>;>|+2*x*y+y|)>>> There's also the possibility to work with and . These offer the advantage that fields may depend on other fields in the same document.<\footnote> Note that the spreadsheet functionality requires 1.0.7.15 or later to work. Also be warned that, at least at the time of this writing, this might become slow in large documents; however, it's possible to work around this limitation by breaking your document into smaller include files. For instance, here is an example of a textual spreadsheet () showing some Pure and Reduce calculations. Type in the cells of the last column to reveal the underlying Pure formulas; also try changing some of the values in the and columns and hitting to recompute the corresponding values in the last column. <\with|par-mode|center> ||||||||>|>|>|>>|>|>|>|0 then n*fact(n-1) else 1 end|1932053504>>>|>|>|>|>>>|>||)>>>>|>>||)>*x>>>>|>|>>>|>>|+2*x*y+y|)>>>>>>>> > You can also refer to a table field in text like this: ||)>*x>>>. Here we set the Ref field of the table to ; the reference to cell can then be entered with the following series of key strokes: . Executable fields can be used to run arbitrary Pure code. For instance, here's the PostScript example from the previous section as a field (again, you can hit on the field to reveal the actual Pure code): <\with|par-mode|center> |ps>||||>> Note that scripting by default uses its own instance of the Pure interpreter which is separate from all Pure sessions that might be included in the same document. But with executable switches it's possible to hook into any Pure session, so that you can use variables and functions defined or imported in that session. To do this, you'll have to create an executable switch for a specific session type (). (Also note that in this case the expressions be terminated with a semicolon, just like in a regular Pure session.) For instance, the following switch hooks into the Octave session from above: \; <\with|par-mode|center> |>||>>>>;>||>||>>>>|)>>,|>||>>>>|)>>> \; In the same fashion we can also reproduce the plot of the sombrero: <\with|par-mode|center> fig2=sombrero; psplot;>||ps>||||>> <\initial> <\collection>