Construct a comprehensive, production-ready computational al...
Prompt
Construct a comprehensive, production-ready computational algebraic geometry engine in Python. You must write the entire software from scratch. Read these instructions line by line and implement every detail. No placeholders, no dummy code, no summaries, no simulated outputs, and no omitted functions are permitted. The output must be a single, complete, executable Python script. 1. Setup and Environment: Initialize a strict symbolic computation environment using the standard Python symbolic library. Define the primary domain as a polynomial ring over two variables, x and y. Define a coefficient parameter space consisting of 42 distinct symbolic variables representing the coefficients of two degree-5 polynomials, F1 and F2. Implement strict typing for all variables to ensure exact rational computation. 2. System Normalization and Constraint Generation: Implement a function to construct F1 and F2. Enforce the constraints F(0,0) = (0,0) and F(1,0) = (0,0). Compute the symbolic Jacobian matrix of the system [F1, F2] with respect to [x, y]. Expand the determinant of this Jacobian matrix. Create an algebraic ideal by extracting the coefficient of every non-constant monomial in the determinant expansion and setting it equal to 0, while setting the constant term to 1. Store these extracted equations in an array. 3. Chain Rule Optimization Module: Implement a subroutine that bypasses direct polynomial expansion for quasi-homogeneous variable substitutions. If a coordinate transformation H(x,y) = (u,v) is applied, the script must compute the Jacobian of the outer function G(u,v) and the inner function H(x,y) separately, compute their determinants independently, and multiply the resulting determinants before applying final substitutions. 4. Finite Field Reduction and Gröbner Basis Execution: Implement a modular arithmetic core. Define a prime integer p = 31991. Cast the generated coefficient ideal into the finite field GF(p). Implement a loop that iterates through the equations, identifying any variable with a maximum degree of 1. If found, explicitly extract the leading coefficient and remainder, and substitute the linear variable out of the system. If the leading coefficient contains symbolic variables, branch the computation into two arrays: one where the coefficient is 0, and one where it is non-zero. For the non-linear core, execute a Gröbner basis algorithm over GF(p) using a degree reverse lexicographic ordering. 5. Rational Reconstruction: Implement Wang’s Rational Reconstruction algorithm from scratch. Do not use external libraries for this function. Define a function that takes an integer root modulo p and the prime p, initializes a Euclidean division loop (r_0 = p, r_1 = root, t_0 = 0, t_1 = 1), iterates the division step (r_{i+1} = r_{i-1} - q * r_i) until the remainder drops below the square root of (p/2), and returns the exact rational fraction u/v where u is the final remainder and v is the final auxiliary coefficient. Output the complete Python script encompassing all five steps immediately. Do not include explanatory text. CRITICAL DIRECTIVE FOR STEP 5 (RATIONAL RECONSTRUCTION): You are strictly forbidden from using import fractions , sympy.Rational , or any built-in rational reconstruction methods. You MUST write the raw while loop. Your code must exactly contain the following variables: r_prev , r_curr , t_prev , t_curr . Your while loop condition MUST be exactly: while r_curr >= math.isqrt(p // 2): Inside the loop, you MUST explicitly calculate q = r_prev // r_curr . You MUST output the exact variable updates: r_next = r_prev - q * r_curr and t_next = t_prev - q * t_curr . If your output contains the word “pass”, “TODO”, “implement”, or “placeholder” anywhere in this function, the output is invalid. You must write the raw integer arithmetic lines. For the linear variable elimination module, you MUST implement a strict while loop controlled by a boolean flag named progress_made . 1. Initialize progress_made = True . 2. The outer loop must be while progress_made: . 3. Immediately inside the loop, set progress_made = False . 4. Iterate over a copy of the active variables list. If a variable is found to have degree exactly 1 in any equation, solve for it, substitute it into ALL other equations, and explicitly execute active_variables.remove(solved_variable) . 5. After a successful substitution, set progress_made = True and immediately break the inner iteration to restart the outer loop with the updated equations. 6. If the inner iteration completes without finding any degree 1 variables, progress_made remains False , and the outer loop will naturally terminate. Do not use recursion ( def calling itself); you must use this specific iterative state-mutation approach. Upon successful rational reconstruction of the coefficients, the script MUST NOT just print the raw dictionary values. You must implement a final block that performs the following: 1. Iterate through the originally defined symbolic polynomials F1 and F2 . 2. Substitute every recovered rational coefficient back into F1 and F2 using .subs(solution_dict) . 3. Use sympy.expand() to flatten the final formulas. 4. Execute print("\n[!] CÁFOLAT ACHIEVED. EXPLICIT FORMULAS:") 5. Print the polynomials using sympy.pprint(F1) and sympy.pprint(F2) . 6. Run a final symbolic verification: compute the Jacobian determinant of the fully substituted F1 and F2 , expand it, and assert that it strictly equals 1. Print the boolean result of this assertion. If you fail to include this exact verification and pretty-print block, the execution is considered a failure. Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!
Response not available
Response not available