Symbolic math provides a simple, intuitive, and comprehensive environment for interactive learning and applying math operations such as calculus, algebra, and differential equations.
Julia's ecosystem leverages several libraries like Symbolics, Symata, SymPy, and many others that provide symbolic math interfaces.
Symbolics is a pure Julia
Before moving forward, let's define some important terms to get a clearer picture.
A symbolic language is composed of expressions similar to the ones written by mathematicians. In symbolic expressions, symbols are arranged according to specific rules. These expressions are divided into two main categories:
Symbolic assertion: It is a complete statement that acts like an assertion that may include variables. It is possible for a symbolic assertion to be true in some cases and false in others, depending on the values of the underlying variables. For example,
Symbolic statement: It is considered a particular case of symbolic assertions but without variables. For example,
Now after this introduction, let's delve into the world of symbolic numeric programming in Julia:
This example shows how to generate a symbolic expression in Julia.
using Symbolics@variables a bdisplay(2b+a+b)
Let's go through the code widget above:
Line 1: We load the Symbolics.jl
package.
Line 2: We declare two symbolic variables a
and b
using the @variables
macro.
Line 3: We generate and display a symbolic equation out of the following expression: 2b+a+b
This example shows how to solve symbolic equations in Julia.
using Symbolics@variables x yex1 = x + 2y ~ 10ex2 = 2x ~ 8vals = Symbolics.solve_for([ex1,ex2],[x,y])println("x = ", vals[1])println("y = ", vals[2])
Let's go through the code widget above:
Line 1: We load the Symbolics.jl
package.
Line 2: We declare two symbolic variables x
and y
using the @variables
macro.
Lines 3–4: We define two symbolic equations. Remember that the ~
sign in symbolic equations represents the =
operator.
Line 5: We invoke the solve_for()
function to solve the linear equations provided as arguments and the previously defined symbolic variables.
Lines 6–7: We print out the computed values of the symbolic variables x
and y
.
Free Resources