# Interacting with Symata¶

## Output¶

### Three diplay styles¶

Symata runs in either the ipython (Jupyter) notebook or the Julia REPL (or even in a dumb terminal). In the Julia REPL two output styles are available, InputForm and UnicodeForm. In the notebook, a third style, called JupyterForm, is available. The notebook starts with the JupyterForm style.

In [1]:
using Symata # load the package and enter Symata mode

In [2]:
Integrate(f(x + I), [x, 0, Infinity])

Out[2]:
$$\int_{0}^{\infty}f \! \left( \mathbb{i} + x \right) \, \mathbb{d}x$$

Here is the same thing in InputForm style

In [3]:
OutputStyle(InputForm)
Out(2)

Out[3]:
Integrate(f(I + x),[x,0,Infinity])

In UnicodeForm style, some of the symbols are pretty printed.

In [4]:
OutputStyle(UnicodeForm)
Out(2)

Out[4]:
Integrate(f(𝕚 + x),[x,0,∞])
In [5]:
Assume(a, Positive)
gammaint = Integrate(E^(-x) * x^(a-1), [x,0,Infinity])

Out[5]:
Γ(a)

In InputForm style

In [6]:
OutputStyle(InputForm)
gammaint

Out[6]:
Gamma(a)

And back to JupyterForm style

In [7]:
OutputStyle(JupyterForm)
gammaint

Out[7]:
$$\Gamma \! \left( a \right)$$

### InputForm output style¶

InputForm style output is closest to the internal form of the expression. It can be copied and pasted as input. (This is also true of UnicodeForm style)

In [8]:
OutputStyle(InputForm), Expand((x + y)^3)

Out[8]:
x^3 + 3*x^2*y + 3x*y^2 + y^3
In [9]:
FullForm(Out(8))  # Internal form of the previous output

Out[9]:
Plus(Power(x,3),Times(3,Power(x,2),y),Times(3,x,Power(y,2)),Power(y,3))
In [10]:
Plus(Power(x,3),Times(3,Power(x,2),y),Times(3,x,Power(y,2)),Power(y,3)) # This is also valid input

Out[10]:
x^3 + 3*x^2*y + 3x*y^2 + y^3

Compare this to JupyterForm output style which cannot in general be copied as input.

In [11]:
OutputStyle(JupyterForm);

Integrate(g(x), [x,0,Infinity])

Out[11]:
$$\int_{0}^{\infty}g \! \left( x \right) \, \mathbb{d}x$$

This is what we get by cutting and pasting from the typset integral in Out[12]: ∫∞0g(x)𝕕x. Not valid input. But, you can still refer to the output cell:

In [12]:
g(x_) := Exp(-x)

Out(11)

Out[12]:
$$1$$

In InputForm style, you can make the output more compact or less compact like this:

In [13]:
OutputStyle(InputForm), CompactOutput(False), Out(10)

Out[13]:
x^3 + 3 * x^2 * y + 3x * y^2 + y^3
In [14]:
CompactOutput(True), Out(10)

Out[14]:
x^3 + 3*x^2*y + 3x*y^2 + y^3

### JupyterForm output style¶

Here are some examples of formatting with JupyterForm output style

In [15]:
OutputStyle(JupyterForm), (1/2 +  a^b)/(x+y)

Out[15]:
$$\frac{\frac{1}{2} + a^{b}}{x + y}$$
In [16]:
Sum(g(i,j), [i,0,Infinity], [j,0,Infinity]) + Sum(h(i,j), [i,0,Infinity], [j,1,n])

Out[16]:
$$\sum _{\substack{i=0 \\ j=1}}^{\infty,n}h \! \left( i,j \right) + \sum _{\substack{i=0 \\ j=0}}^{\infty}g \! \left( i,j \right)$$
In [17]:
Integrate(g(x,y), [x,0,1], [y,0,1])

Out[17]:
$$\int_{0}^{1} \mathbb{d}x\int_{0}^{1} \mathbb{d}y \, g \! \left( x,y \right)$$
In [18]:
a < b < c/d

Out[18]:
$$a\text{<}b \, \text{&&} \, b\text{<} \left( \frac{c}{d} \right)$$

To cut and past from Jupyter to another application, right click on the displayed output. Then choose from the menu which format you like, such as the $\LaTeX$ source. (You can also choose math display options here)

To get an expression that can be cut and pasted as Symata input, say to text editor, you can either switch formats using OutputStyle(InputForm), or wrap a single expression in InputForm.

In [19]:
InputForm( a< b < c/d )

Out[19]:
a < b && b < (c*d^(-1))

### Formatting Numbers¶

You can change the way numbers are printed like this.

In [20]:
N(Pi)

Out[20]:
$$3.141592653589793$$
In [21]:
N(Pi) * 10^10

Out[21]:
$$3.141592653589793e10$$
In [22]:
FloatFormat(Short);

In [23]:
N(Pi)

Out[23]:
$$3.14159$$
In [24]:
N(Pi) * 10^10

Out[24]:
$$3.14159e+10$$

Print three digits

In [25]:
FloatFormat(3);

In [26]:
N(Pi)

Out[26]:
$$3.14$$
In [27]:
N(Pi) * 10^10

Out[27]:
$$3.14e+10$$

Changing the number of digits printed does not change the precision of the number.

In [28]:
Precision(N(Pi))

Out[28]:
$$16$$

The format of BigFloat numbers is not affected by FloatFormat

In [29]:
N(Pi,50)

Out[29]:
$$3.14159265358979323846264338327950288419716939937512$$

Use BigFloatFormat for this

In [30]:
BigFloatFormat(Short);

In [31]:
N(Pi,50)

Out[31]:
$$3.14159$$
In [32]:
Precision(N(Pi,50))

Out[32]:
$$50$$
In [33]:
FloatFormat(Full);

In [34]:
N(Pi)

Out[34]:
$$3.141592653589793$$
In [35]:
BigFloatFormat(Full);

In [36]:
N(Pi,50)

Out[36]:
$$3.14159265358979323846264338327950288419716939937512$$

## Input¶

### Unicode input¶

Unicode input is inherited from Julia and the ipython/Jupyter notebook. In both the REPL and the notebook, you can enter a $\LaTeX$ macro and hit TAB to convert it to a symbol. For instance, \alpha[TAB] gives α. You can also copy/paste unicode symbols into the notebook.

A few symbols, such as π, are intepreted as builtin Symata symbols.

In [37]:
OutputStyle(InputForm);

In [38]:
[π + 𝕖 + 𝕚 + a, Pi + E + I + a]   # \pi + \Bbbe + \Bbbi

Out[38]:
[I + a + E + Pi,I + a + E + Pi]
In [39]:
OutputStyle(UnicodeForm);

In [40]:
[π + 𝕖 + 𝕚 + a, Pi + E + I + a]

Out[40]:
[𝕚 + a + 𝕖 + π,𝕚 + a + 𝕖 + π]
In [41]:
OutputStyle(JupyterForm);

In [42]:
[π + 𝕖 + 𝕚 + a, Pi + E + I + a]

Out[42]:
$$\left[ \mathbb{i} + a + \mathbb{e} + \pi ,\mathbb{i} + a + \mathbb{e} + \pi \right]$$

Pi and π, etc. refer to the same symbol.

In [43]:
[Pi == π, E == 𝕖, I == 𝕚, EulerGamma == γ, Gamma == Γ]

Out[43]:
$$\left[ \text{True},\text{True},\text{True},\text{True},\text{True} \right]$$
In [44]:
Cos([Pi, π])

Out[44]:
$$\left[ -1,-1 \right]$$

### TAB completion¶

In Symata, in both the command line REPL and IJulia, you can use TAB completion to complete built-in and user-defined symbols, in the same way that you do in Julia.

In IJulia, typing Shift-TAB when the cursor is at the end of a built-in symbol displays a pop-up with the doc string, if available. (This feature may be broken in both Julia and Symata)

You can get the same doc string (and the corresponding sympy document) by typing ? followed by the symbol.

In [45]:
? 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.

See also CompactOutput.

Attributes(OutputStyle) = [Protected]


### Version and date¶

In [46]:
VersionInfo()

Symata version     0.4.6
Julia version      1.6.0-DEV.58
Python version     3.8.3
SymPy version      1.5.1

In [47]:
InputForm(Now())

Out[47]:
2020-05-29T22:27:50.568