Having seen expressions that are hard to simplify into the same form, I'd say that it has a place in SymPy (there's even a utilities directory). That said, I'd probably suggest a name like nequiv similar to nsolve.
Cheers, Tim. On 2015-02-09, at 11:09 AM, Peter Chervenski <[email protected]> wrote: > I made this function to test for the equivalence of two expressions. It > doesn't really prove anything, but if the tests are many, the probability of > it being wrong becomes negligible. Do such utility functions have a place in > SymPy? > > def equiv(a, b, ntests=15): > """ Test if expression a is equivalent to b > by comparing the results of many random numeric tests """ > > # get the symbols > sb_a = filter(lambda x: x.is_Symbol, a.atoms()) > sb_b = filter(lambda x: x.is_Symbol, b.atoms()) > > sb = list(set(sb_a + sb_b)) > > eq = True > for i in xrange(ntests): > k = dict(zip(sb, np.random.randn(len(sb)))) > > r_a = a.subs( k ) > r_b = b.subs( k ) > > # prove there is a difference > if (r_a - r_b)**2 > 1e-30: # not the same? the expressions are > different > eq = False > break > > return eq > > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/58700b18-624c-4723-935a-dd71bb30d738%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/EDA65D41-14BB-4475-B4C9-AEF1588490DD%40gmail.com. For more options, visit https://groups.google.com/d/optout.
