-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b29c583
commit 24f9c03
Showing
22 changed files
with
2,219 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "a20a2420", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Original polynomial: x**3 - 10*x**2 + 31*x - 30\n", | ||
"Factorization of polynomial: (x - 5)*(x - 3)*(x - 2)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Prime Factorization of polynomials\n", | ||
"from sympy import symbols, factor\n", | ||
"from sympy.abc import x\n", | ||
"\n", | ||
"polynomial = x**3 -10*x**2 + 31*x - 30\n", | ||
"\n", | ||
"factored_polynomial = factor(polynomial)\n", | ||
"\n", | ||
"print(\"Original polynomial:\", polynomial)\n", | ||
"print(\"Factorization of polynomial:\", factored_polynomial)\n", | ||
"\n", | ||
"# Output\n", | ||
"# Original polynomial: x**3 - 10*x**2 + 31*x - 30\n", | ||
"# Factorization of polynomial: (x - 5)*(x - 3)*(x - 2)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "89ff714b", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Lagrange Polynomial: (x - 3)*(x - 2) - 3*(x - 3)*(x - 1) + 4*(x - 2)*(x - 1)\n", | ||
"Simplified Polynomial: 2*x**2 - 5*x + 5\n", | ||
"Value at x=4: 8\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Lagrange Interpolation Method\n", | ||
"from sympy import symbols\n", | ||
"from sympy.abc import x\n", | ||
"from sympy.polys.polyfuncs import interpolating_poly\n", | ||
"\n", | ||
"# Given interpolation points and their corresponding function values\n", | ||
"data = [(1, 2), (2, 3), (3, 8)]\n", | ||
"\n", | ||
"if isinstance(data, dict):\n", | ||
" X, Y = list(zip(*data.items()))\n", | ||
"else:\n", | ||
" if isinstance(data[0], tuple):\n", | ||
" X, Y = list(zip(*data))\n", | ||
" else:\n", | ||
" X = list(range(1, n + 1))\n", | ||
" Y = list(data)\n", | ||
"\n", | ||
"# Use the interpolating_poly function to construct the Lagrange interpolation polynomial\n", | ||
"interpolation_polynomial = interpolating_poly(len(data), x, X, Y)\n", | ||
"\n", | ||
"# Output the interpolation polynomial\n", | ||
"print(\"Lagrange Polynomial:\", interpolation_polynomial)\n", | ||
"print(\"Simplified Polynomial:\", interpolation_polynomial.expand())\n", | ||
"# Calculate the value at x=4 using the interpolation polynomial\n", | ||
"result = interpolation_polynomial.subs(x, 3)\n", | ||
"print(\"Value at x=4:\", result)\n", | ||
"\n", | ||
"# Sample Output\n", | ||
"# Lagrange Polynomial: (x - 3)*(x - 2) - 3*(x - 3)*(x - 1) + 4*(x - 2)*(x - 1)\n", | ||
"# Simplified Polynomial: 2*x**2 - 5*x + 5\n", | ||
"# Value at x=4: 8\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6f1b05a6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"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.7.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "a20a2420", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Polynomial p1: Poly(2*x**3 - 2*x**2 + x + 1, x, modulus=5)\n", | ||
"Polynomial p2: Poly(x**2 - x - 1, x, modulus=5)\n", | ||
"Addition result: Poly(2*x**3 - x**2, x, modulus=5)\n", | ||
"Subtraction result: Poly(2*x**3 + 2*x**2 + 2*x + 2, x, modulus=5)\n", | ||
"Multiplication result: Poly(2*x**5 + x**4 + x**3 + 2*x**2 - 2*x - 1, x, modulus=5)\n", | ||
"Modulo operation: Poly(-2*x + 1, x, modulus=5)\n", | ||
"Quotient: Poly(2*x, x, modulus=5)\n", | ||
"Greatest common divisor: Poly(x + 2, x, modulus=5)\n", | ||
"Result of substituting x = 2 into polynomial p1: 1\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sympy import symbols, Poly, GF, gcd\n", | ||
"\n", | ||
"# Define symbolic variables\n", | ||
"x = symbols('x')\n", | ||
"\n", | ||
"# Define polynomials with coefficients in the ring of integers modulo 5\n", | ||
"p1 = Poly(2*x**3 + 3*x**2 + x + 1, x, domain=GF(5))\n", | ||
"p2 = Poly(x**2 + 4*x + 4, x, domain=GF(5))\n", | ||
"\n", | ||
"# Print the polynomials\n", | ||
"print(\"Polynomial p1:\", p1)\n", | ||
"print(\"Polynomial p2:\", p2)\n", | ||
"\n", | ||
"\n", | ||
"# Polynomial addition\n", | ||
"add_result = p1 + p2\n", | ||
"print(\"Addition result:\", add_result)\n", | ||
"\n", | ||
"# Polynomial subtraction\n", | ||
"sub_result = p1 - p2\n", | ||
"print(\"Subtraction result:\", sub_result)\n", | ||
"\n", | ||
"# Polynomial multiplication\n", | ||
"mul_result = p1 * p2\n", | ||
"print(\"Multiplication result:\", mul_result)\n", | ||
"\n", | ||
"# Note: In the ring of integers modulo n, polynomial division is not always possible\n", | ||
"# However, modulo operation can be performed\n", | ||
"mod_result = p1 % p2\n", | ||
"print(\"Modulo operation:\", mod_result)\n", | ||
"\n", | ||
"# Quotient\n", | ||
"quotient_result = p1 // p2\n", | ||
"print(\"Quotient:\", quotient_result)\n", | ||
"\n", | ||
"# Greatest common divisor\n", | ||
"gcd_result = gcd(p1, p2)\n", | ||
"print(\"Greatest common divisor:\", gcd_result)\n", | ||
"\n", | ||
"# Substituting values to solve\n", | ||
"value_result = p1.subs(x, 2)\n", | ||
"print(\"Result of substituting x = 2 into polynomial p1:\", value_result)\n", | ||
"\n", | ||
"## Output Example\n", | ||
"# Polynomial p1: Poly(2*x**3 - 2*x**2 + x + 1, x, modulus=5)\n", | ||
"# Polynomial p2: Poly(x**2 - x - 1, x, modulus=5)\n", | ||
"# Addition result: Poly(2*x**3 - x**2, x, modulus=5)\n", | ||
"# Subtraction result: Poly(2*x**3 + 2*x**2 + 2*x + 2, x, modulus=5)\n", | ||
"# Multiplication result: Poly(2*x**5 + x**4 + x**3 + 2*x**2 - 2*x - 1, x, modulus=5)\n", | ||
"# Modulo operation: Poly(-2*x + 1, x, modulus=5)\n", | ||
"# Quotient: Poly(2*x, x, modulus=5)\n", | ||
"# Greatest common divisor: Poly(x + 2, x, modulus=5)\n", | ||
"# Result of substituting x = 2 into polynomial p1: 1\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6f1b05a6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"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.7.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "04209408", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Extension Field: QQ<sqrt(2)>\n", | ||
"a = ANP([MPQ(1,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n", | ||
"b = ANP([MPQ(3,1)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n", | ||
"a + b = ANP([MPQ(7,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n", | ||
"a * b = ANP([MPQ(3,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sympy import symbols, QQ, RootOf\n", | ||
"\n", | ||
"# Define symbolic variables\n", | ||
"x = symbols('x')\n", | ||
"\n", | ||
"# Construct the algebraic extension QQ/(sqrt(2)) (which is a root of x^2 - 2 = 0) over the rational number field QQ\n", | ||
"ext_field = QQ.algebraic_field(RootOf(x**2 - 2, 1))\n", | ||
"\n", | ||
"# Output the extension field and algebraic element\n", | ||
"print(\"Extension Field: \", ext_field)\n", | ||
"# QQ<sqrt(2)>\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"# Calculation on extention field\n", | ||
"a = ext_field(QQ(1, 2))\n", | ||
"b = ext_field(3)\n", | ||
"c = a + b\n", | ||
"d = a * b\n", | ||
"\n", | ||
"print(\"a =\", a)\n", | ||
"print(\"b =\", b)\n", | ||
"print(\"a + b =\", c)\n", | ||
"print(\"a * b =\", d)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4c678725", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"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.7.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.