7.4 sympy

To install type  pip install -U sympy 

To install using anaconda:

First install anaconda using Linux Manjaro package manager.

To install latest sympy in anaconda try conda install -c anaconda sympy see https://anaconda.org/anaconda/sympy

To update to latest conda do

sudo -i 
#conda update conda
 

To update to latest sympy do

sudo -i 
#conda update sympy 
... now check version 
#python 
>>> import sympy 
>>> sympy.__version__ 
'1.8'
 

Next must install matchpy, without it Rubi will not worK:

>sudo conda install -c conda-forge matchpy 
[sudo] password for me: 
Collecting package metadata: done 
Solving environment: done 
 
## Package Plan ## 
 
  environment location: /opt/anaconda 
 
  added / updated specs: 
    - matchpy 
 
 
The following packages will be downloaded: 
 
    package                    |            build 
    ---------------------------|----------------- 
    ca-certificates-2019.3.9   |       hecc5488_0         146 KB  conda-forge 
    certifi-2019.3.9           |           py37_0         149 KB  conda-forge 
    conda-4.6.14               |           py37_0         2.1 MB  conda-forge 
    hopcroftkarp-1.2.4         |             py_0          20 KB  conda-forge 
    matchpy-0.5.1              |             py_0          52 KB  conda-forge 
    multiset-2.1.1             |             py_0          11 KB  conda-forge 
    openssl-1.1.1b             |       h14c3975_1         4.0 MB  conda-forge 
    ------------------------------------------------------------ 
                                           Total:         6.4 MB 
 
The following NEW packages will be INSTALLED: 
 
  hopcroftkarp       conda-forge/noarch::hopcroftkarp-1.2.4-py_0 
  matchpy            conda-forge/noarch::matchpy-0.5.1-py_0 
  multiset           conda-forge/noarch::multiset-2.1.1-py_0 
 
The following packages will be UPDATED: 
 
  ca-certificates    pkgs/main::ca-certificates-2019.1.23-0 --> conda-forge::ca-certificates-2019.3.9-hecc5488_0 
 
The following packages will be SUPERSEDED by a higher-priority channel: 
 
  certifi                                         pkgs/main --> conda-forge 
  conda                                           pkgs/main --> conda-forge 
  openssl              pkgs/main::openssl-1.1.1b-h7b6447c_1 --> conda-forge::openssl-1.1.1b-h14c3975_1 
 
 
Proceed ([y]/n)? y 
 
 
Downloading and Extracting Packages 
multiset-2.1.1       | 11 KB     | ####################################################################### | 100% 
openssl-1.1.1b       | 4.0 MB    | ####################################################################### | 100% 
matchpy-0.5.1        | 52 KB     | ####################################################################### | 100% 
conda-4.6.14         | 2.1 MB    | ####################################################################### | 100% 
hopcroftkarp-1.2.4   | 20 KB     | ####################################################################### | 100% 
ca-certificates-2019 | 146 KB    | ####################################################################### | 100% 
certifi-2019.3.9     | 149 KB    | ####################################################################### | 100% 
Preparing transaction: done 
Verifying transaction: done 
Executing transaction: done 
>
 

In general, To install python package do conda install package-name to update do conda   update package for example conda   update spyder

To use Rubi in sympy, do (note this no longer works in recent version of sympy. 2023)

>python 
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from sympy import * 
>>> from sympy.integrals.rubi.rubimain import rubi_integrate
 

For testing do

from sympy import * 
 
or 
 
import sympy  #but now have to add sympy. to each call 
 
import os 
os.getcwd() 
os.chdir('X:\\data\\public_html\\my_notes\\CAS_integration_tests\\reports\\rubi_4_11\\code') 
os.getcwd() 
import math 
init_printing() 
init_printing(use_unicode=False, wrap_line=False, no_global=True) 
x = symbols('x', real=True) 
r=integrate(x,x) 
r0=latex(r) 
text_file = open("python.txt", "w") 
text_file.write("\"%s\"" % r0) 
text_file.close()
 

To check if integral failed

r=integrate(f*g, (x, L/2, L)) 
type(r) is integrals.Integral 
 
Out[41]: True 
 
or 
 
isinstance(r, integrals.Integral) 
Out[48]: True 
 
 
r=integrate(x,x) 
type(r) is integrals.Integral 
Out[43]: False 
 
if isinstance(r, integrals.Integral): 
    result = 0 
else: 
    result=1
 

To get cwd

os.getcwd() 
 
To get list of folder in cwd do 
 
os.listdir(os.getcwd()) 
 
or 
 
ls 
 
Out[85]: 
['1_Algebraic_functions', 
 '2_Exponentials', 
 '3_Logarithms', 
 '4_Trig_functions', 
 '5_Inverse_trig_functions', 
 '6_Hyperbolic_functions', 
 '7_Inverse_hyperbolic_functions', 
 '8_Special_functions', 
 'Independent_test_suites'] 
 
f = open('Hebisch_Problems.txt','r') 
f.readline() 
f.close()
 

how to do timeout? simple timeouts using signal.alarm module check http://stackoverflow.com/questions/492519/timeout-on-a-function-call for some code. There is also talk about it here https://groups.google.com/forum/#!topic/sympy/qsPImy6WqcI code from above is

def _timeout(self, function, timeout): 
         def callback(x, y): 
             signal.alarm(0) 
             raise Skipped("Timeout") 
         signal.signal(signal.SIGALRM, callback) 
         signal.alarm(timeout)  # Set an alarm with a given timeout 
         function() 
         signal.alarm(0)  # Disable the alarm
 

elementry functions http://docs.sympy.org/latest/modules/functions/elementary.html and http://docs.sympy.org/dev/modules/functions/special.html

and http://docs.sympy.org/latest/modules/functions/index.html

Need to change

AppellF1 -->             #hypergeometric function of two variables 
Ellipticpi--> 
arctanh -->atanh 
arctan --> atan 
arccosh->acosh 
Pi --> pi. 
arcsin -> asin 
arccos -> acos 
hypergeom -> hyper, 
arccoth -> acoth 
GAMMA -> uppergamma() 
arccsc -> acsc 
arcsec -> asec 
arccot -> acot, 
EllipticF -> elliptic_f 
EllipticE -> elliptic_e 
Li -> Li 
Si -> Si 
Ci -> Ci 
Ei -> Ei 
FresnelS -> fresnels 
FresnelC -> fresnelc
 

I also removed 4th field that contains integrate(...) in it as it hangs the reading of the input file.

To run python tests do

 
cd /media/data/public_html/my_notes/CAS_integration_tests/reports/rubi_4_11 
python sympy_main.py
 

To add new test, or run more tests, edit sympy_main.py and change the line

for n in range(0,1):  #change the last number to the number of tests to do
 

To update conda and python do

conda update conda 
conda update python
 

To update sympy do

pip list | grep sympy 
pip install --upgrade sympy
 

To find version, from inside python, type

import sympy 
sympy.__version__
 

from github https://github.com/sympy/sympy/wiki/SymPy-vs.-Sage

To obtain a Rational in SymPy, one of these methods must be used: 
 
>>> from sympy import Rational 
>>> Rational(2, 7) 
2/7
 

In python/sympy, to loop using index 1, can use this:

>>> for num,val in enumerate(sol,start=1): 
...   print("root number {} is {}".format(num,val))
 

For timeout in recent python, on windows, this seems to work

from subprocess import STDOUT, check_output 
output = check_output('dir', shell=True, stderr=STDOUT, timeout=5) 
print(output)
 

To download development sympy

sudo git clone git://github.com/sympy/sympy.git 
sudo git clone https://github.com/HPAC/matchpy.git
 

To install using conda sudo conda install multiset

packages are here /home/me/anaconda3/lib/python3.6/site-packages

To install pymatch

>sudo conda install -c conda-forge matchpy 
[sudo] password for me: 
Solving environment: done 
 
## Package Plan ## 
 
  environment location: /opt/anaconda 
 
  added / updated specs: 
    - matchpy 
 
 
The following packages will be downloaded: 
 
    package                    |            build 
    ---------------------------|----------------- 
    hopcroftkarp-1.2.4         |             py_0          20 KB  conda-forge 
    certifi-2018.4.16          |           py36_0         142 KB  conda-forge 
    conda-4.5.5                |           py36_0         624 KB  conda-forge 
    matchpy-0.4.4              |             py_0          49 KB  conda-forge 
    multiset-2.1.1             |             py_0          11 KB  conda-forge 
    ------------------------------------------------------------ 
                                           Total:         845 KB 
 
The following NEW packages will be INSTALLED: 
 
    hopcroftkarp: 1.2.4-py_0       conda-forge 
    matchpy:      0.4.4-py_0       conda-forge 
    multiset:     2.1.1-py_0       conda-forge 
 
The following packages will be UPDATED: 
 
    certifi:      2018.4.16-py36_0             --> 2018.4.16-py36_0 conda-forge 
    conda:        4.5.4-py36_0                 --> 4.5.5-py36_0     conda-forge 
 
Proceed ([y]/n)? y 
 
 
Downloading and Extracting Packages 
hopcroftkarp-1.2.4   |   20 KB | ########################################################################################### | 100% 
certifi-2018.4.16    |  142 KB | ########################################################################################### | 100% 
conda-4.5.5          |  624 KB | ########################################################################################### | 100% 
matchpy-0.4.4        |   49 KB | ########################################################################################### | 100% 
multiset-2.1.1       |   11 KB | ########################################################################################### | 100% 
Preparing transaction: done 
Verifying transaction: done 
Executing transaction: done 
>
 

To update sympy in conda do sudo conda update sympy  I do not know now if I should always use sudo for this, but it works. To check conda version do

>conda list anaconda$ 
# packages in environment at /opt/anaconda: 
# 
# Name                    Version                   Build  Channel 
anaconda                  5.2.0                    py36_3 
 
>sudo conda update conda 
[sudo] password for me: 
Solving environment: done 
 
# All requested packages already installed. 
 
 
>conda update anaconda 
Solving environment: done 
 
# All requested packages already installed.
 

Can also do conda update --all to update other conda stuff.

To get all info about conda do

>conda info 
 
     active environment : None 
       user config file : /home/me/.condarc 
 populated config files : 
          conda version : 4.5.5 
    conda-build version : 3.10.5 
         python version : 3.6.5.final.0 
       base environment : /opt/anaconda  (read only) 
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64 
                          https://repo.anaconda.com/pkgs/main/noarch 
                          https://repo.anaconda.com/pkgs/free/linux-64 
                          https://repo.anaconda.com/pkgs/free/noarch 
                          https://repo.anaconda.com/pkgs/r/linux-64 
                          https://repo.anaconda.com/pkgs/r/noarch 
                          https://repo.anaconda.com/pkgs/pro/linux-64 
                          https://repo.anaconda.com/pkgs/pro/noarch 
          package cache : /opt/anaconda/pkgs 
                          /home/me/.conda/pkgs 
       envs directories : /home/me/.conda/envs 
                          /opt/anaconda/envs 
               platform : linux-64 
             user-agent : conda/4.5.5 requests/2.18.4 CPython/3.6.5 Linux/4.14.53-1-MANJARO manjaro/17.1.11 glibc/2.27 
                UID:GID : 1000:1000 
             netrc file : None 
           offline mode : False
 

see also https://conda.io/docs/_downloads/conda-cheatsheet.pdf

This will list all versions of specific package conda search sympy