Unique things

The title of this notebook does not mean "fantastic, amazing things". The title does describe more or less literally the content. Many of the features and commands in Symata will be familiar from other programs. This notebook presents a few things that may be unfamiliar and not documented elsewhere. Also note that many of the "unique" features appear in other tutorial notebooks.


In [1]:
using Symata; isymata()  # enter Symata mode

Version information

Version information of main components.


In [2]:
VersionInfo()


symata version 0.3.0-dev.3
julia version  0.6.0-dev.435
python version 2.7.12
sympy version  1.0

OutputStyle

OutputStyle selects the appearance of printed (or rendered) Symata expressions. See the notebook "InteractingWithSymata" for more details.


In [3]:
? OutputStyle


OutputStyle(InputForm)

print plain 1d text output.

OutputStyle(UnicodeForm)

print 1d text output with pretty unicode characters.

OutputStyle(JupyterForm)

in a Jupyter notebook, print in typeset mathematics style using latex.

OutputStyle()

return the current output style.

InputForm and UnicodeForm give output that is valid Symata input for the same expression.

Help( OutputStyle)

See also CompactOutput.

 Attributes(OutputStyle) = [Protected]

Timing evaluation

Use Time(True) and Time(False) to toggle timing and allocation information after evaluation of each input line. Use Timing(expr) to time the evaluation of expr only.

Help

? prints help on the Help function.

Help(topic), Help("topic"), or ? topic prints documentation for topic.

h"words" does a case insensitive search of the contents of help documents.

Syamta uses the python package SymPy extensivley. Help prints relevant SymPy documentation along with Symata documentation. Type ShowSymPyDocs(False) to disable printing SymPy documentation.


In [ ]:

Big integers

By default, Symata converts input integers to the Julia type Int. But, you may want bigger numbers:


In [4]:
2^100   # overflow


Out[4]:
$$ 0 $$

In [5]:
? BigIntInput


BigIntInput(True)

enable interpreting all integers as arbitrary precision BigInts.

BigIntInput(False)

(default) disable interpreting all integers as arbitrary precision BigInts.

BigIntInput()

return the current state.

You can always specify that an integer should be a BigInt by giving BI(n).

Help( BigIntInput)

See also BF, BI, Big, BigFloatInput, N, and SetPrecision.

 Attributes(BigIntInput) = [Protected]

In [6]:
BigIntInput(True);

In [7]:
2^100


Out[7]:
$$ 1267650600228229401496703205376 $$

Note that this only applies to input integers (at the moment)


In [8]:
Head(Cos(Pi))


Out[8]:
$$ \text{Int64} $$

In [9]:
Head( BI(Cos(Pi)))     # Convert explicitly to BigInt


Out[9]:
$$ \text{BigInt} $$

Passing data between Julia and Symata

Symata's host language is Julia. There are several ways to interact with Julia in a Symata session.

Julia and Symata keep separate lists of symbols. For instance, x may be defined in Julia, but not Symata, and vice versa.

Use SetJ to bind (i.e. set) a Julia symbol to a Symata expression.


In [10]:
expr = x + y


Out[10]:
$$ x + y $$

In [11]:
? SetJ


SetJ(x,val)

sets the Julia symbol x to val.

Variables and functions in Symata are separate from those in Julia, ie, their table of bindings to symbols are separate.

Help( SetJ)


 Attributes(SetJ) = [HoldFirst,Protected]

Bind the Julia variable z to the result of evaluating expr.


In [12]:
SetJ(z , expr)


Out[12]:
$$ x + y $$

Execute Julia code, by enclosing it in :( ). We ask for the value of z.


In [29]:
J( Main.z )


Out[29]:
$$ x + y $$

We can also leave Symata and return to Julia


In [14]:
Julia()  # begin interpreting expressions as Julia code. ;

In [15]:
z         # Now in Julia


Out[15]:
:x + :y

The unexported Julia function symval returns the Symata binding of a symbol.


In [16]:
? Symata.symval


Out[16]:
symval(s::SJSym)

return the bound value of the Symata symbol with Julia-Symbol name s.

symval(s::SSJSym)

Return the value bound to the Symata symbol s.


In [17]:
Symata.symval(:expr)


Out[17]:
:x + :y

We can do the reverse, set a Symata variable to the value of a Julia variable.

Set a variable in Jula.


In [18]:
a = 1      # Set a Julia symbol  (bind an identifier to a value)


Out[18]:
1

In [19]:
isymata()   # Enter Symata mode again

In [20]:
(expr2 = J( Main.a  );  expr2)


Out[20]:
$$ 1 $$

Symata symbol expr2 is now set to 1.

SymPy

Symata uses the python package SymPy extensively. Most of the interaction with SymPy is transparent to the user. But there are several commands for controlling this interaction.

Use Symata's help search feature to find commands related to SymPy.


In [21]:
h"sympy"


Rewrite
SymPyError
ExpandA
ReturnSymPy
ToSymata
ShowSymPyDocs
ToSymPy

In [22]:
? SymPyError


SymPyError()

returns the most recent SymPy error message. If you see a message warning that a SymPy error has occurred, you can find the detailed error message.

Help( SymPyError)


 Attributes(SymPyError) = [Protected]

For debugging, you can disable converting SymPy objects to Symata.


In [23]:
? ReturnSymPy


ReturnSymPy(True)

disable conversion of expressions computed by SymPy to Symata.

ReturnSympy(False)

(default) enable conversion to Symata.

ReturnSympy()

return the current state.

Help( ReturnSymPy)

See also ShowSymPyDocs, ToSymPy, and ToSymata.

 Attributes(ReturnSymPy) = [Protected]

In [24]:
? ToSymata


ToSymata(expr)

convert the python PyObject expr to a Symata expression. Normally, expressions computed by SymPy are automatically converted to Symata expressions.

Help( ToSymata)

See also ReturnSymPy, ShowSymPyDocs, and ToSymPy.

 Attributes(ToSymata) = [HoldAll,Protected]

In [25]:
? ToSymPy


ToSymPy(expr)

convert expr to a (python) PyObject.

Help( ToSymPy)

See also ReturnSymPy, ShowSymPyDocs, and ToSymata.

 Attributes(ToSymPy) = [Protected]

Use ToSymPy and ToSymata to convert between the languages.


In [26]:
(OutputStyle(InputForm), pyobj = ToSymPy(Integrate(f(x),x)))


Out[26]:
PyObject Integral(f(x), x)

In [30]:
( OutputStyle(JupyterForm),  Head(pyobj))


Out[30]:
$$ \text{PyCall.PyObject} $$

Recover the Symata expression.


In [28]:
ToSymata(pyobj)


Out[28]:
$$ \int f \! \left( x \right) \, \mathbb{d}x $$

In [ ]: