Last active
April 8, 2023 17:50
-
-
Save thomasjpfan/aac53353dd0fc39ec375784ec7959b57 to your computer and use it in GitHub Desktop.
exact solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "88746977-dbf4-47ae-8588-8803c0e02de4", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"from sympy.abc import x, u\n", | |
"from sympy import solve, N\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "87129f36-6f41-47f9-99e4-b56087a0bd10", | |
"metadata": {}, | |
"source": [ | |
"## Degree 2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "bfeb9d60-7226-41c9-92b1-bb97ac2532fc", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"int64_max = np.iinfo(np.int64).max" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "6a52d9a2-ce72-4702-a832-212a7fe7115d", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3037000499.47605\n" | |
] | |
} | |
], | |
"source": [ | |
"solutions = solve(x**2 + x - int64_max, x)\n", | |
"print(N(solutions[0]))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "40705a67-ab17-4cce-b047-01c0310289e2", | |
"metadata": { | |
"tags": [] | |
}, | |
"source": [ | |
"## Degree 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "37add24c-de2e-42c3-ab42-b9d497b0e965", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"2097151.00000016\n" | |
] | |
} | |
], | |
"source": [ | |
"solutions = solve(x * (x**2 + 3 * x + 2) - int64_max, x)\n", | |
"print(N(solutions[-1]))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "sympy (python3)", | |
"language": "python", | |
"name": "conda-env-sympy-py" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment