How do I write this equation in Python? -


cardano triplets

i don't know how write correctly. how tried:

def is_cardano_triplet(a, b, c):     f = lambda x: x ** 1. / 2     g = lambda x: x ** 1. / 3     return g(a + b*f(c)) + g(a - b*f(c)) == 1  print is_cardano_triplet(2,1,5) # should true 

i should true 2, 1, 5, i'm not. what's wrong function?

doing bit of research and calculations, solving equation variable c, i found out that

lolz

and therefore

lolzz

now, due floating point arithmetic being imprecise on binary-based systems known reasons, first formula pretty hard compute precisely. however, the second 1 easier compute without floating point precision errors since doesn't involve irrational functions , a, b , c integers.

here's smart solution:

def is_cardano_triplet(a, b, c):     return (a + 1)**2 * (8*a - 1) - 27*b**2*c == 0  >>> is_cardano_triplet(2, 1, 5) true 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -