RobWorkProject  23.9.11-
Classes | Functions | Variables
rwlibs::mathematica Namespace Reference

Implementation of the Wolfram Symbolic Transfer Protocol (WSTP) to allow communication with Mathematica. More...

Classes

class  EnterExpressionPacket
 A Mathematica WSTP EnterExpressionPacket. More...
 
class  EnterTextPacket
 A Mathematica WSTP EnterTextPacket. More...
 
class  EvaluatePacket
 A Mathematica WSTP EvaluatePacket. More...
 
class  FactorInteger
 Representation of the Mathematica FactorInteger function. More...
 
class  Image
 Representation of the Mathematica Image function. More...
 
class  InputNamePacket
 A Mathematica WSTP InputNamePacket. More...
 
class  List
 Representation of the Mathematica List function. More...
 
class  ListPlot
 Representation of the Mathematica ListPlot function. More...
 
class  Mathematica
 Implementation of the Wolfram Symbolic Transfer Protocol (WSTP) to allow communication with Mathematica. More...
 
class  MessagePacket
 A Mathematica WSTP MessagePacket. More...
 
class  OutputNamePacket
 A Mathematica WSTP OutputNamePacket. More...
 
class  RawArrayUtil
 Utility for the RawArray type. More...
 
class  RawArray
 Representation of a N-dimensional Mathematica array with fixed depth. More...
 
class  RawArray< T, Dynamic >
 Representation of a N-dimensional Mathematica array with dynamic depth. More...
 
class  ReturnExpressionPacket
 A Mathematica WSTP ReturnExpressionPacket. More...
 
class  ReturnPacket
 A Mathematica WSTP ReturnPacket. More...
 
class  ReturnTextPacket
 A Mathematica WSTP ReturnTextPacket. More...
 
class  Rule
 Representation of a Mathematica Rule. More...
 
class  TextPacket
 A Mathematica WSTP TextPacket. More...
 
class  ToExpression
 Representation of the Mathematica ToExpression function. More...
 

Functions

std::ostream & operator<< (std::ostream &out, const Mathematica::Expression &expression)
 Print a Mathematica expression to an output stream. More...
 

Variables

const int Dynamic = -1
 Value for the size of a RawArray when size is not known at compile time.
 

Detailed Description

Implementation of the Wolfram Symbolic Transfer Protocol (WSTP) to allow communication with Mathematica.

Example of basic usage:

Mathematica m;
m.initialize();
const Mathematica::Link::Ptr l = m.launchKernel();
*l >> result;
*l << "Solve[x^2 + 2 y^3 == 3681 && x > 0 && y > 0, {x, y}, Integers]";
*l >> result;
std::cout << *result << std::endl;
rw::core::Ptr< Packet > Ptr
Smart pointer type.
Definition: Mathematica.hpp:695

Construction of a Mathematica environment, m, makes it possible to create WSTP links (Mathematica::Link). Please note that the Mathematica object automatically closes all links at destruction. WSTP links can be used for different types of interprocess communication with Wolfram Symbolic expressions. In this example we launch and connect to a kernel.

The first expression (the In[1]:= prompt) is received from the kernel with the stream operator *l >> result. We simply ignore this value, and send the first command to be evaluated with the stream operator. The result is then retrieved and printed:

 ReturnPacket[
   List[
     List[
        Rule[x, 15],
        Rule[y, 12]],
     List[
        Rule[x, 41],
        Rule[y, 10]],
     List[
        Rule[x, 57],
        Rule[y, 6]]]]

Streaming of a string to the link will implicitly create a ToExpression expression and wrap it in an EvaluatePacket. The kernel will evaluate the expression in the packet and send back a ReturnPacket with the result (as an expression). Many different types of packets can be sent and received on the link (see Mathematica::PacketType). It is up to the user to deal with the different packet types, and to parse the results received.