Our plan was to implement all Algebraic rules and complete the Rubi test suit for algebraic integration. However, there was a setback in our work because of a bug I found in
ManyToOneReplacer of MatchPy. This bug prevents matching of expressions having many nested commutative expressions. Hence, we were not able to match all expressions in the test suit. Manuel Krebber have helped us a lot in adding features and giving suggestions to make MatchPy work for Rubi. He have fixed the bug today. I will resume my testing of algebraic rules asap.
Previously, our strategy was to implement only those functions which were used by algebraic rules. However, we found that those functions have dependencies on many other functions. So, we decided to implement the functions from the beginning itself, to avoid problems in the long run.
Mathematica has functionality of implementing function arguments as patterns:
SqrtNumberQ[m_^n_] := IntegerQ[n] && SqrtNumberQ[m] || IntegerQ[n-1/2] && RationalQ[m] SqrtNumberQ[u_*v_] := SqrtNumberQ[u] && SqrtNumberQ[v] SqrtNumberQ[u_] := RationalQ[u] || u===I
In the above code
SqrtNumberQ is defined multiple times for different function arguments. To implement these functions in Python, Francesco suggested that we test the type of argument using conditionals:
def SqrtNumberQ(expr): # SqrtNumberQ[u] returns True if u^2 is a rational number; else it returns False. if expr.is_Pow: m = expr.base n = expr.exp return IntegerQ(n) & SqrtNumberQ(m) | IntegerQ(n-1/2) & RationalQ(m) elif expr.is_Mul: return all(SqrtNumberQ(i) for i in expr.args) else: return RationalQ(expr) or expr == I
There was some problem while implementing
Catch since SymPy doesn’t currently has
MapAnd[f_,lst_] := Catch[Scan[Function[If[f[#],Null,Throw[False]]],lst];True]
I used the following code to implement
ManAnd in Python:
def MapAnd(f, l, x=None): # MapAnd[f,l] applies f to the elements of list l until False is returned; else returns True if x: for i in l: if f(i, x) == False: return False return True else: for i in l: if f(i) == False: return False return True
I and Abdullah have implemented ~40 utility functions so far. There are around ~40 more functions which needs to be implemented in order to support all algebraic rules. We should be able to complete those functions by tomorrow.
I will also resume adding tests to Rubi test suit for algebraic functions.