Python code to find the integer solutions of multivariable cubic equation (Diophantine equation)?

64 Views Asked by At

My equation is a multivariable cubic equation, and I want to find its integer solutions in a given interval x = range(-10,11). The equation is

a3 + b3 + c3 + d3 + e3 - (a + b + c + d + e)3 = 0

Is the following code correct?

from itertools import product
def find_solutions():
    possible_values = range(-10, 11)
    variable_combinations = product(possible_values, repeat=5)
    solutions = []
    for combination in variable_combinations:
        if sum(combination) == 0 and sum(i**3 for i in combination) == 0:
            sorted_solution = tuple(sorted(combination))
            if sorted_solution not in solutions:
                solutions.append(sorted_solution)
    return solutions
1

There are 1 best solutions below

0
teapot418 On

You are looking for a subset of the solutions. X-Y==0 is not the same thing as X==0 && Y==0.

A more accurate rendering of the equation would be

if sum(i**3 for i in combination) - sum(combination)**3 == 0: