Git Product home page Git Product logo

symbolica's Introduction


logo

Symbolica website Zulip Chat Symbolica website Codecov

Symbolica โŠ† Modern Computer Algebra

Symbolica is a blazing fast computer algebra system for Python and Rust, born of a need to push the boundaries of computations in science and enterprise. Check out the live Jupyter Notebook demo!

For documentation and more, see symbolica.io.

Quick Example

Symbolica allows you to build and manipulate mathematical expressions, for example from a Jupyter Notebook:

A demo of Symbolica

You are able to perform these operations from the comfort of a programming language that you (probably) already know, by using Symbolica's bindings to Python and Rust:

A demo of Symbolica

Installation

Visit the Get Started page for detailed installation instructions.

Python

Symbolica can be installed for Python >3.5 using pip:

pip install symbolica

The installation may take some time on Mac OS and Windows, as it may have to compile Symbolica.

Rust

If you want to use Symbolica as a library in Rust, simply include it in the Cargo.toml:

[dependencies]
symbolica = "0.8"

Examples

Below we list some examples of the features of Symbolica. Check the guide for a complete overview.

Pattern matching

Variables ending with a _ are wildcards that match to any subexpression. In the following example we try to match the pattern f(w1_,w2_):

from symbolica import Expression
x, y, w1_, w2_, f = Expression.symbols('x','y','w1_','w2_', 'f')
e = f(3,x)*y**2+5
r = e.replace_all(f(w1_,w2_), f(w1_ - 1, w2_**2))
print(r)

which yields y^2*f(2,x^2)+5.

Solving a linear system

Solve a linear system in x and y with a parameter c:

from symbolica import Expression

x, y, c, f = Expression.symbols('x', 'y', 'c', 'f')

x_r, y_r = Expression.solve_linear_system(
    [f(c)*x + y + c, y + c**2], [x, y])
print('x =', x_r, ', y =', y_r)

which yields x = (-c+c^2)*f(c)^-1 and y = -c^2.

Series expansion

Perform a series expansion in x:

from symbolica import Expression
x = Expression.symbol('x')
e = Expression.parse('exp(5+x)/(1-x)').series(x, 0, 3)

print(e)

which yields (exp(5))+(2*exp(5))*x+(5/2*exp(5))*x^2+(8/3*exp(5))*x^3+O(x^4).

Rational arithmetic

Symbolica is world-class in rational arithmetic, outperforming Mathematica, Maple, Form, Fermat, and other computer algebra packages. Simply convert an expression to a rational polynomial:

from symbolica import Expression
p = Expression.parse('(x*y^2*5+5)^2/(2*x+5)+(x+4)/(6*x^2+1)').to_rational_polynomial()
print(p)

which yields (45+13*x+50*x*y^2+152*x^2+25*x^2*y^4+300*x^3*y^2+150*x^4*y^4)/(5+2*x+30*x^2+12*x^3).

Development

Follow the development and discussions on Zulip!

symbolica's People

Contributors

benruijl avatar jonasspinner avatar lcnbr avatar orottier avatar sudeepan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symbolica's Issues

unwanted automatic float conversion

With the current version (0.8.0) of symbolica that includes the float representations I see that rational factors in python are sometimes converted to floats. This example demonstrates where depending on how I write the expression it either is represented as a float or a rational number:

e = Expression.symbol("e")
e1 = 2/5 * e
e2 = 2 * e / 5
print(e1)  # gives:  4.00000000000000e-1*e
print(e2)  # gives:  2/5*e

Potential Issue with `factor()`

Hello,

I tried running the program below,

from symbolica import Expression
e = Expression.num(0)
print(e)
print(e.factor())

and it produced

0
1

I'm wondering if that's expected. Thanks!

You can rewrite your code from blog like this

Sorry i couldn't find any "comment" feature on your blog so i decided to write here.
Your 'loop' pattern can be written like this:

    let mut items = vec![3, 5, 7, 11, 13, 17];
    let item = 19;
    let location = items.iter().position(|x| *x == item).or_else(|| {
        items.push(item);
        Some(items.len() - 1)
    });

Infinite arrays of symbols?

Imagined use: Suppose we have an ODE and we wish to solve it with the Frobenius method. The we would like to convert the ansatz

$$y(t) = \sum_{i=0}^{\infty} c_{i} t^{i+\alpha}$$

to some recurrence involving only the $c_i$. Can this be done in an an automated way in symbolica? It seems this would require support for an infinite array of symbols, maybe?

c = Expression.var('c[0:infinity]')

or

c = Expression.vector_var('c[0:infinity]')

I submit this issue with some trepidation as I know absolutely nothing about this field and have no clue if I've made a feature request for something that's NP complete or undecidable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.