-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5b4e8c0
Showing
54 changed files
with
87,818 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Copyright (c) 2006-2022 SymPy Development Team | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
a. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
b. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
c. Neither the name of SymPy nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Rubi | ||
|
||
Previously `sympy.integrals.rubi`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
''' | ||
Rule Based Integration(RUBI) module in SymPy uses set of transformation | ||
rules to integrate an expression. All the transformation rules are compiled as a | ||
discrimination-net which helps in matching expression with the rule efficiently. | ||
Due to large number of rules, the module would normally take lot of time to load. | ||
Hence, it is better to use Rubi while doing multiple integrations. | ||
Rules are taken from Rubi version 4.10.8. | ||
Note: This module has dependency on MatchPy library. | ||
Basic Structure | ||
=============== | ||
All rules in matchpy format are in rules folder. They are in separate files. | ||
While matching a pattern, there are constraints that need to be checked. | ||
These constraints are placed in a single file `constraints.py`. | ||
A complete rule look like this: | ||
``` | ||
def cons_f1(m, x): | ||
return FreeQ(m, x) | ||
cons1 = CustomConstraint(cons_f1) | ||
def cons_f2(m): | ||
return NonzeroQ(m + S(1)) | ||
cons2 = CustomConstraint(cons_f2) | ||
pattern1 = Pattern(Integral(x_**WC('m', S(1)), x_), cons1, cons2) | ||
def replacement1(m, x): | ||
rubi.append(1) | ||
return Simp(x**(m + S(1))/(m + S(1)), x) | ||
rule1 = ReplacementRule(pattern1, replacement1) | ||
``` | ||
As seen in the above example, a rule has 3 parts | ||
1. Pattern with constraints. Expression is matched against this pattern. | ||
2. Replacement function, which gives the resulting expression with which the original expression has to be replaced with. | ||
There is also `rubi.append(1)`. This (rubi) is a list which keeps track of rules applied to an expression. | ||
This can be accessed by `rules_applied` in `rubi.py` | ||
3. Rule, which combines pattern and replacement function. | ||
(For more details refer to matchpy documents) | ||
Note: | ||
The name of arguments of function for constraints and replacement should be taken care of. | ||
They need to be exactly same as wildcard in the `Pattern`. Like, in the above example, | ||
if `cons_f1` is written something like this: | ||
``` | ||
def cons_f1(a, x): | ||
return FreeQ(a, x) | ||
``` | ||
This is not going to work because in the Pattern, `m` has been used as a wildcard. So only thing is | ||
naming of arguments matters. | ||
TODO | ||
==== | ||
* Use code generation to implement all rules. | ||
* Testing of all the tests from rubi test suit. See: http://www.apmaths.uwo.ca/~arich/IntegrationProblems/MathematicaSyntaxFiles/MathematicaSyntaxFiles.html | ||
* Add support for `Piecewise` functions. | ||
Debugging | ||
========= | ||
When an integration is not successful. We can see which rule is matching the | ||
expression by using `get_matching_rule_definition()` function. We can cross-check | ||
if correct rule is being applied by evaluating the same expression in Mathematica. | ||
If the applied rule is same, then we need to check the `ReplacementRule` and | ||
the utility functions used in the `ReplacementRule`. | ||
Parsing Rules and Tests | ||
======================= | ||
Code for parsing rule and tests are included in sympy. | ||
They have been properly explained with steps in `sympy/integrals/rubi/parsetools/rubi_parsing_guide.md`. | ||
Running Tests | ||
============= | ||
The tests for rubi in `rubi_tests` have been blacklisted as it takes a very long time to run all the tests. | ||
To run a test run the following in a Python terminal: | ||
``` | ||
>>> import sympy | ||
>>> sympy.test("rubi_tests", blacklist = []) # doctest: +SKIP | ||
``` | ||
For specific tests like `test_sine.py` use this `sympy.test("rubi_tests/tests/test_sine.py", blacklist = [])`. | ||
References | ||
========== | ||
[1] http://www.apmaths.uwo.ca/~arich/ | ||
[2] https://github.com/sympy/sympy/issues/7749 | ||
[3] https://github.com/sympy/sympy/pull/12978 | ||
''' |
Oops, something went wrong.