<jupyter_start><jupyter_text>$min \; \; x_1 x_4(x_1 + x_2 + x_3) + x_3 \\ s.t. \; \; x_1 x_2 x_3 x_4 \geq  25 \\x_1^2 x_2^2 x_3^2 x_4^2 = 40 \\1 \leq x_1, x_2, x_3, x_4 \leq 5 \\x_0 = (1,5,5,1)$<jupyter_code>import numpy as np
from scipy.optimize import minimize
# Objective Function
def objective(x):
    #Defining the variable name is optional, makes it less confusing (but it's much more better if you go direct)
    x1, x2, x3, x4 = x[0], x[1], x[2], x[3]
    return x1 * x4 * (x1 + x2 + x3) + x3

#Constraints
def constraint1(x):
    return x[0] * x[1] * x[2] * x[3] - 25.0

def constraint2(x):
    z = 40
    for i in x:
        z = z - i ** 2
    return z
#Initival Values
x0 = [1,5,5,1]
print(objective(x0))
b = (1.0, 5.0)
bounds_x = (b, b, b, b)
constr1 = {'type': 'ineq', 'fun': constraint1}
constr2 = {'type': 'eq', 'fun': constraint2}
constr_all = [constr1, constr2]
print(constr_all)
# The solution
# Solving using SLSQP - Sequential Least Squares Programming
sol = minimize(objective,x0,method='SLSQP',bounds = bounds_x, constraints = constr_all)
print(sol)
#The results of x
print(sol.x)
#The value of function
print(sol.fun)<jupyter_output>[1.         4.7429961  3.82115462 1.37940765]
17.01401724563517
{'fraction_non_alphanumeric': 0.1583264971287941, 'fraction_numerical': 0.09762100082034454, 'mean_word_length': 3.5522388059701493, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '546605', 'license': 'MIT', 'n_tokens_mistral': 575, 'n_tokens_neox': 533, 'n_words': 152, 'path': 'Python-Optimization/optimization-1.ipynb', 'repo_name': 'atriple/Coding-Challenge', 'size': '1219'}