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.

Reply via email to