Created
February 23, 2023 16:52
-
-
Save maple3142/0bb20789d7372b7e0e822d1b91ca7867 to your computer and use it in GitHub Desktop.
sage multivariate polynomial variable substitution
This file contains hidden or 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
| def poly_sub(f, x, y): | |
| ret = f.parent().zero() | |
| for c, m in f: | |
| while m % x == 0: | |
| m //= x | |
| c *= y | |
| ret += c * m | |
| return ret | |
| def poly_sub2(f, x, y): | |
| # https://ask.sagemath.org/question/25972/substitute-xy-by-u/#post-id-25996 | |
| Q = f.parent().quotient(x - y) | |
| return Q(f).lift() | |
| for R in [ZZ, Zmod(17 * 19), GF(2 ^ 8), CyclotomicField(17)]: | |
| PR = R["x, y, z"] | |
| x, y, z = PR.gens() | |
| assert poly_sub((x * y + 1) ^ 7, x * y, z) == (z + 1) ^ 7 | |
| assert poly_sub2((x * y + 1) ^ 7, x * y, z) == (z + 1) ^ 7 | |
| assert poly_sub((x ^ 2 * y + 1) ^ 3, x * y, z) == (z * x + 1) ^ 3 | |
| assert poly_sub2((x ^ 2 * y + 1) ^ 3, x * y, z) == (z * x + 1) ^ 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment