{ "cells": [ { "cell_type": "markdown", "id": "a93854ef-c338-4788-b6af-9299decd73b6", "metadata": {}, "source": [ "# 5次式の2次式と3次式の積への因数分解の仕方\n", "\n", "* 黒木玄" ] }, { "cell_type": "code", "execution_count": 1, "id": "84fec713-54b7-41e8-a851-3783380b7c22", "metadata": {}, "outputs": [], "source": [ "using SymPy\n", "\n", "# Override the Base.show definition of SymPy.jl:\n", "# https://github.com/JuliaPy/SymPy.jl/blob/29c5bfd1d10ac53014fa7fef468bc8deccadc2fc/src/types.jl#L87-L105\n", "\n", "@eval SymPy function Base.show(io::IO, ::MIME\"text/latex\", x::SymbolicObject)\n", " print(io, as_markdown(\"\\\\displaystyle \" * sympy.latex(x, mode=\"plain\", fold_short_frac=false)))\n", "end\n", "@eval SymPy function Base.show(io::IO, ::MIME\"text/latex\", x::AbstractArray{Sym})\n", " function toeqnarray(x::Vector{Sym})\n", " a = join([\"\\\\displaystyle \" * sympy.latex(x[i]) for i in 1:length(x)], \"\\\\\\\\\")\n", " \"\"\"\\\\left[ \\\\begin{array}{r}$a\\\\end{array} \\\\right]\"\"\"\n", " end\n", " function toeqnarray(x::AbstractArray{Sym,2})\n", " sz = size(x)\n", " a = join([join(\"\\\\displaystyle \" .* map(sympy.latex, x[i,:]), \"&\") for i in 1:sz[1]], \"\\\\\\\\\")\n", " \"\\\\left[ \\\\begin{array}{\" * repeat(\"r\",sz[2]) * \"}\" * a * \"\\\\end{array}\\\\right]\"\n", " end\n", " print(io, as_markdown(toeqnarray(x)))\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "id": "59d10a01-ecd8-4c15-9069-ef402e989736", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "factor_for_all_divisors (generic function with 1 method)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_coeffs(f, x) = sympy.poly(f, x).all_coeffs()\n", "\n", "function all_divisors(x)\n", " @assert x != 0\n", " A = typeof(x)[]\n", " for i in 1:abs(x)\n", " if mod(x, i) == 0\n", " push!(A, i, -i)\n", " end\n", " end\n", " A\n", "end\n", "\n", "function factor_for_all_divisors(f, var, constant_term)\n", " A = all_divisors(constant_term)\n", " stack([k, f(var=>k).factor()] for k in A; dims=1)\n", "end" ] }, { "cell_type": "markdown", "id": "f5ae8f78-2ab1-4393-8769-241b6a887164", "metadata": {}, "source": [ "## 一般論" ] }, { "cell_type": "code", "execution_count": 3, "id": "9daa19be-0419-4948-a2fa-c7504c573e46", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(a, b, c, d, e, p, q, r, s, t, u, v, x)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@vars a b c d e p q r s t u v x" ] }, { "cell_type": "markdown", "id": "3ba3bf7e-0a9d-4a45-8b32-d5817b59304f", "metadata": {}, "source": [ "$t\\ne 0$ と仮定する." ] }, { "cell_type": "code", "execution_count": 4, "id": "b6d25422-733a-46ef-9193-6581287f1868", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle p x^{4} + q x^{3} + r x^{2} + s x + t + x^{5}$\n" ], "text/plain": [ " 4 3 2 5\n", "p*x + q*x + r*x + s*x + t + x " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = x^5 + p*x^4 + q*x^3 + r*x^2 + s*x + t" ] }, { "cell_type": "code", "execution_count": 5, "id": "f2bfbd7c-2e65-488b-9e2a-6b35c810553c", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a x + b + x^{2}$\n" ], "text/plain": [ " 2\n", "a*x + b + x " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = x^2 + a*x + b" ] }, { "cell_type": "code", "execution_count": 6, "id": "1624c8e3-14b5-411b-95b3-f0db49e6b10f", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle c x^{2} + d x + e + x^{3}$\n" ], "text/plain": [ " 2 3\n", "c*x + d*x + e + x " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h = x^3 + c*x^2 + d*x + e" ] }, { "cell_type": "markdown", "id": "da0c7f1c-7775-4eab-97a9-049cd6271269", "metadata": {}, "source": [ "$f$ を $g$ で割ったときの商と余りを求める." ] }, { "cell_type": "code", "execution_count": 7, "id": "886e15ba-302b-400d-a70e-3d01f6c53267", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle \\operatorname{Poly}{\\left( x^{3} + \\left(- a + p\\right) x^{2} + \\left(a^{2} - a p - b + q\\right) x - a^{3} + a^{2} p + 2 a b - a q - b p + r, x, domain=\\mathbb{Z}\\left[p, q, r, a, b\\right] \\right)}\\\\\\displaystyle \\operatorname{Poly}{\\left( \\left(a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p - a r + b^{2} - b q + s\\right) x + a^{3} b - a^{2} b p - 2 a b^{2} + a b q + b^{2} p - b r + t, x, domain=\\mathbb{Z}\\left[p, q, r, s, t, a, b\\right] \\right)}\\end{array} \\right]$\n" ], "text/plain": [ "2-element Vector{Sym}:\n", " Poly(x^3 + (-a + p)*x^2 + (a^2 - a*p - b + q)*x - a^3 + a^2*p + 2*a*b - a*q - b*p + r, x, domain='ZZ[p,q,r,a,b]')\n", " Poly((a^4 - a^3*p - 3*a^2*b + a^2*q + 2*a*b*p - a*r + b^2 - b*q + s)*x + a^3*b - a^2*b*p - 2*a*b^2 + a*b*q + b^2*p - b*r + t, x, domain='ZZ[p,q,r,s,t,a,b]')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "quotient, remainder = sympy.div(f, g, x)\n", "sympy.poly.([quotient, remainder], x)" ] }, { "cell_type": "markdown", "id": "47209929-d47e-44b8-90a5-123fd8afc7bf", "metadata": {}, "source": [ "$h$ が商に一致することと $c,d,e$ が次のようになることは同値." ] }, { "cell_type": "code", "execution_count": 8, "id": "6ab7be70-17ce-4a78-a6b5-9f3ac250c4fb", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle - a + p\\\\\\displaystyle a^{2} - a p - b + q\\\\\\displaystyle - a^{3} + a^{2} p + 2 a b - a q - b p + r\\end{array} \\right]$\n" ], "text/plain": [ "4-element Vector{Sym}:\n", " 1\n", " -a + p\n", " a^2 - a*p - b + q\n", " -a^3 + a^2*p + 2*a*b - a*q - b*p + r" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_, C, D, E = all_coeffs(quotient, x)" ] }, { "cell_type": "markdown", "id": "5f7a84b8-d796-4c8d-b651-4498cea23290", "metadata": {}, "source": [ "$be = t\\ne 0$ ならば $b\\ne 0$ でなければいけない.\n", "\n", "そのとき, 余りが0になることと以下の2つが0になることは同値である." ] }, { "cell_type": "code", "execution_count": 9, "id": "67a90673-0e41-437c-a7ff-b1a1f89f16e3", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} - a^{2} p - 2 a b + a q + b p - r + \\frac{t}{b}$\n" ], "text/plain": [ " 3 2 t\n", "a - a *p - 2*a*b + a*q + b*p - r + -\n", " b" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eqrem0 = remainder.coeff(x, 0)/b |> expand" ] }, { "cell_type": "code", "execution_count": 10, "id": "953d1a3d-84e7-4d15-8986-670a965b469b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p - a r + b^{2} - b q + s$\n" ], "text/plain": [ " 4 3 2 2 2 \n", "a - a *p - 3*a *b + a *q + 2*a*b*p - a*r + b - b*q + s" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eqrem1 = remainder.coeff(x, 1)" ] }, { "cell_type": "markdown", "id": "ee63618f-f922-4576-99c7-690c008b7ede", "metadata": {}, "source": [ "与えられた5次でモニックな整数係数多項式 $f$ の整数係数の2次式 $g$ と3次式 $h$ の積への分解を求めるためには, まず $be=t$ を満たす整数の組 $(b, e)$ の各々について, `eqrem0` を0にする整数 $a$ が存在するかどうかを確認し, 存在する場合に `eqrem1` が0になるかどうかも確認し, `eqrem0` と `eqrem1` の両方を $0$ にするような整数の組 $(a,b)$ を見付ければよい. (見付からない場合には整数係数の2次式と整数係数の3次式の積に分解不可能なことが証明されたことになる.)" ] }, { "cell_type": "markdown", "id": "ef750b26-c6ca-4c90-b491-8bf8c7e687aa", "metadata": {}, "source": [ "## 雑多な計算メモ" ] }, { "cell_type": "code", "execution_count": 11, "id": "cac0ecd3-b7ad-4211-ae0c-20e06da0c035", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle a^{2} - a p - b + q + x^{2} + x \\left(- a + p\\right)\\\\\\displaystyle - a^{2} c + a c p + b c - c q + t + x^{2} \\left(- a^{3} + a^{2} p + 2 a b - a q - b p - c + r\\right) + x \\left(- a^{2} b + a b p + a c + b^{2} - b q - c p + s\\right)\\end{array} \\right]$\n" ], "text/plain": [ "2-element Vector{Sym}:\n", " a^2 - a*p - b + q + x^2 + x*(-a + p)\n", " -a^2*c + a*c*p + b*c - c*q + t + x^2*(-a^3 + a^2*p + 2*a*b - a*q - b*p - c + r) + x*(-a^2*b + a*b*p + a*c + b^2 - b*q - c*p + s)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sympy.div(f, x^3 + a*x^2 + b*x + c, x) |> collect" ] }, { "cell_type": "code", "execution_count": 12, "id": "5b48a9bd-4b4c-4ced-b6cf-c56104240f14", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p - a r + b^{2} - b q + s + x^{4} + x^{3} \\left(- a + p\\right) + x^{2} \\left(a^{2} - a p - b + q\\right) + x \\left(- a^{3} + a^{2} p + 2 a b - a q - b p + r\\right)\\\\\\displaystyle - a^{4} b + a^{3} b p + 3 a^{2} b^{2} - a^{2} b q - 2 a b^{2} p + a b r - b^{3} + b^{2} q - b s + u + x \\left(- a^{5} + a^{4} p + 4 a^{3} b - a^{3} q - 3 a^{2} b p + a^{2} r - 3 a b^{2} + 2 a b q - a s + b^{2} p - b r + t\\right)\\end{array} \\right]$\n" ], "text/plain": [ "2-element Vector{Sym}:\n", " a^4 - a^3*p - 3*a^2*b + a^2*q + 2*a*b*p - a*r + b^2 - b*q + s + x^4 + x^3*(-a + p) + x^2*(a^2 - a*p - b + q) + x*(-a^3 + a^2*p + 2*a*b - a*q - b*p + r)\n", " -a^4*b + a^3*b*p + 3*a^2*b^2 - a^2*b*q - 2*a*b^2*p + a*b*r - b^3 + b^2*q - b*s + u + x*(-a^5 + a^4*p + 4*a^3*b - a^3*q - 3*a^2*b*p + a^2*r - 3*a*b^2 + 2*a*b*q - a*s + b^2*p - b*r + t)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sympy.div(x^6 + p*x^5 + q*x^4 + r*x^3 + s*x^2 + t*x + u, g, x) |> collect" ] }, { "cell_type": "code", "execution_count": 13, "id": "8a546d0d-a7f0-4bf6-beae-206e904321a1", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle - a^{3} + a^{2} p + 2 a b - a q - b p - c + r + x^{3} + x^{2} \\left(- a + p\\right) + x \\left(a^{2} - a p - b + q\\right)\\\\\\displaystyle a^{3} c - a^{2} c p - 2 a b c + a c q + b c p + c^{2} - c r + u + x^{2} \\left(a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p + 2 a c - a r + b^{2} - b q - c p + s\\right) + x \\left(a^{3} b - a^{2} b p - a^{2} c - 2 a b^{2} + a b q + a c p + b^{2} p + 2 b c - b r - c q + t\\right)\\end{array} \\right]$\n" ], "text/plain": [ "2-element Vector{Sym}:\n", " -a^3 + a^2*p + 2*a*b - a*q - b*p - c + r + x^3 + x^2*(-a + p) + x*(a^2 - a*p - b + q)\n", " a^3*c - a^2*c*p - 2*a*b*c + a*c*q + b*c*p + c^2 - c*r + u + x^2*(a^4 - a^3*p - 3*a^2*b + a^2*q + 2*a*b*p + 2*a*c - a*r + b^2 - b*q - c*p + s) + x*(a^3*b - a^2*b*p - a^2*c - 2*a*b^2 + a*b*q + a*c*p + b^2*p + 2*b*c - b*r - c*q + t)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Q63, R63 = sympy.div(x^6 + p*x^5 + q*x^4 + r*x^3 + s*x^2 + t*x + u, x^3 + a*x^2 + b*x + c, x) |> collect" ] }, { "cell_type": "code", "execution_count": 14, "id": "abbd9173-2a71-4c16-a72a-fd8d83d087f2", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p + 2 a c - a r + b^{2} - b q - c p + s\\\\\\displaystyle a^{3} b - a^{2} b p - a^{2} c - 2 a b^{2} + a b q + a c p + b^{2} p + 2 b c - b r - c q + t\\\\\\displaystyle a^{3} c - a^{2} c p - 2 a b c + a c q + b c p + c^{2} - c r + u\\end{array} \\right]$\n" ], "text/plain": [ "3-element Vector{Sym}:\n", " a^4 - a^3*p - 3*a^2*b + a^2*q + 2*a*b*p + 2*a*c - a*r + b^2 - b*q - c*p + s\n", " a^3*b - a^2*b*p - a^2*c - 2*a*b^2 + a*b*q + a*c*p + b^2*p + 2*b*c - b*r - c*q + t\n", " a^3*c - a^2*c*p - 2*a*b*c + a*c*q + b*c*p + c^2 - c*r + u" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "C63 = all_coeffs(R63, x)" ] }, { "cell_type": "code", "execution_count": 15, "id": "8de6ac2a-1a95-41f6-a697-707ab803bd5b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{a^{3} c - a^{2} c p + a c q + c^{2} - c r + u}{c \\left(2 a - p\\right)}$\n" ], "text/plain": [ " 3 2 2 \n", "a *c - a *c*p + a*c*q + c - c*r + u\n", "------------------------------------\n", " c*(2*a - p) " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B63 = sympy.solve(C63[end], b)[end]" ] }, { "cell_type": "code", "execution_count": 16, "id": "6290231b-9240-475b-b148-921f92051037", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eqrem63_1 = -(((((C63[1])(b => B63))(u => c * v) * (-2a + p) ^ 2).expand()).factor()) = a^6 - 3*a^5*p + 3*a^4*p^2 + 2*a^4*q - 4*a^3*c - a^3*p^3 - 4*a^3*p*q + 4*a^3*v + 7*a^2*c*p + 2*a^2*p^2*q + a^2*p*r - 5*a^2*p*v + a^2*q^2 - 4*a^2*s - 4*a*c*p^2 - a*p^2*r + 2*a*p^2*v - a*p*q^2 + 4*a*p*s - c^2 + c*p^3 - c*p*q + 2*c*r - 2*c*v - p^2*s + p*q*r - p*q*v - r^2 + 2*r*v - v^2\n" ] } ], "source": [ "@show eqrem63_1 = -(C63[1](b=>B63)(u=>c*v) * (-2*a + p)^2).expand().factor();" ] }, { "cell_type": "code", "execution_count": 17, "id": "5e0a7857-58b8-4650-a504-d8d112aea9e9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle - 3 p\\\\\\displaystyle 3 p^{2} + 2 q\\\\\\displaystyle - 4 c - p^{3} - 4 p q + 4 v\\\\\\displaystyle 7 c p + 2 p^{2} q + p r - 5 p v + q^{2} - 4 s\\\\\\displaystyle - 4 c p^{2} - p^{2} r + 2 p^{2} v - p q^{2} + 4 p s\\\\\\displaystyle - c^{2} + c p^{3} - c p q + 2 c r - 2 c v - p^{2} s + p q r - p q v - r^{2} + 2 r v - v^{2}\\end{array} \\right]$\n" ], "text/plain": [ "7-element Vector{Sym}:\n", " 1\n", " -3*p\n", " 3*p^2 + 2*q\n", " -4*c - p^3 - 4*p*q + 4*v\n", " 7*c*p + 2*p^2*q + p*r - 5*p*v + q^2 - 4*s\n", " -4*c*p^2 - p^2*r + 2*p^2*v - p*q^2 + 4*p*s\n", " -c^2 + c*p^3 - c*p*q + 2*c*r - 2*c*v - p^2*s + p*q*r - p*q*v - r^2 + 2*r*v - v^2" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_coeffs(eqrem63_1, a)" ] }, { "cell_type": "code", "execution_count": 18, "id": "485f8585-85bf-47b4-885f-78b2a9efff7a", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{rr}\\displaystyle x^{5} + x + 1&\\displaystyle \\left(x^{2} + x + 1\\right) \\left(x^{3} - x^{2} + 1\\right)\\\\\\displaystyle x^{5} - 5 x + 3&\\displaystyle \\left(x^{2} + x - 1\\right) \\left(x^{3} - x^{2} + 2 x - 3\\right)\\\\\\displaystyle x^{5} + x + 6&\\displaystyle \\left(x^{2} + x + 2\\right) \\left(x^{3} - x^{2} - x + 3\\right)\\\\\\displaystyle x^{5} - x + 15&\\displaystyle \\left(x^{2} + x + 3\\right) \\left(x^{3} - x^{2} - 2 x + 5\\right)\\\\\\displaystyle x^{5} - 9 x - 27&\\displaystyle \\left(x^{2} + 3 x + 3\\right) \\left(x^{3} - 3 x^{2} + 6 x - 9\\right)\\\\\\displaystyle x^{5} - 9 x + 27&\\displaystyle \\left(x^{2} - 3 x + 3\\right) \\left(x^{3} + 3 x^{2} + 6 x + 9\\right)\\\\\\displaystyle x^{5} - 5 x + 28&\\displaystyle \\left(x^{2} + x + 4\\right) \\left(x^{3} - x^{2} - 3 x + 7\\right)\\\\\\displaystyle x^{5} + 16 x + 32&\\displaystyle \\left(x^{2} + 2 x + 4\\right) \\left(x^{3} - 2 x^{2} + 8\\right)\\\\\\displaystyle x^{5} + 16 x - 32&\\displaystyle \\left(x^{2} - 2 x + 4\\right) \\left(x^{3} + 2 x^{2} - 8\\right)\\\\\\displaystyle x^{5} - 5 x^{2} + 2&\\displaystyle \\left(x^{2} - x - 1\\right) \\left(x^{3} + x^{2} + 2 x - 2\\right)\\\\\\displaystyle x^{5} - x^{2} + 4&\\displaystyle \\left(x^{2} + x + 2\\right) \\left(x^{3} - x^{2} - x + 2\\right)\\\\\\displaystyle x^{5} + 2 x^{2} + 4&\\displaystyle \\left(x^{2} - 2 x + 2\\right) \\left(x^{3} + 2 x^{2} + 2 x + 2\\right)\\\\\\displaystyle x^{5} - 3 x^{2} + 18&\\displaystyle \\left(x^{2} - 3 x + 3\\right) \\left(x^{3} + 3 x^{2} + 6 x + 6\\right)\\\\\\displaystyle x^{5} + x^{2} + 18&\\displaystyle \\left(x^{2} + x + 3\\right) \\left(x^{3} - x^{2} - 2 x + 6\\right)\\end{array}\\right]$\n" ], "text/plain": [ "14×2 Matrix{Sym}:\n", " x^5 + x + 1 (x^2 + x + 1)*(x^3 - x^2 + 1)\n", " x^5 - 5*x + 3 (x^2 + x - 1)*(x^3 - x^2 + 2*x - 3)\n", " x^5 + x + 6 (x^2 + x + 2)*(x^3 - x^2 - x + 3)\n", " x^5 - x + 15 (x^2 + x + 3)*(x^3 - x^2 - 2*x + 5)\n", " x^5 - 9*x - 27 (x^2 + 3*x + 3)*(x^3 - 3*x^2 + 6*x - 9)\n", " x^5 - 9*x + 27 (x^2 - 3*x + 3)*(x^3 + 3*x^2 + 6*x + 9)\n", " x^5 - 5*x + 28 (x^2 + x + 4)*(x^3 - x^2 - 3*x + 7)\n", " x^5 + 16*x + 32 (x^2 + 2*x + 4)*(x^3 - 2*x^2 + 8)\n", " x^5 + 16*x - 32 (x^2 - 2*x + 4)*(x^3 + 2*x^2 - 8)\n", " x^5 - 5*x^2 + 2 (x^2 - x - 1)*(x^3 + x^2 + 2*x - 2)\n", " x^5 - x^2 + 4 (x^2 + x + 2)*(x^3 - x^2 - x + 2)\n", " x^5 + 2*x^2 + 4 (x^2 - 2*x + 2)*(x^3 + 2*x^2 + 2*x + 2)\n", " x^5 - 3*x^2 + 18 (x^2 - 3*x + 3)*(x^3 + 3*x^2 + 6*x + 6)\n", " x^5 + x^2 + 18 (x^2 + x + 3)*(x^3 - x^2 - 2*x + 6)" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Problems = [\n", " x^5 + x + 1\n", " x^5 - 5x + 3\n", " x^5 + x + 6\n", " x^5 - x + 15\n", " x^5 - 9x - 27\n", " x^5 - 9x + 27\n", " x^5 - 5x + 28\n", " x^5 + 16x + 32\n", " x^5 + 16x - 32\n", " x^5 - 5x^2 + 2\n", " x^5 - x^2 + 4\n", " x^5 + 2x^2 + 4\n", " x^5 - 3x^2 + 18\n", " x^5 + x^2 + 18\n", "]\n", "\n", "stack([f, f.factor()] for f in Problems; dims=1)" ] }, { "cell_type": "markdown", "id": "8f06619e-07e9-4f55-a507-8066c3832df3", "metadata": {}, "source": [ "## 例1\n", "\n", "$g = x^2 + 3x - 2$, $h = (x+1)^3-2 = x^3+3x^2+3x-1$ の場合にどうなるか." ] }, { "cell_type": "code", "execution_count": 19, "id": "2316fbfa-daa4-4475-8c0b-69867c8c795b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{2} + 3 x - 2$\n" ], "text/plain": [ " 2 \n", "x + 3*x - 2" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "GG = x^2 + 3x - 2" ] }, { "cell_type": "code", "execution_count": 20, "id": "08b30df4-848b-460e-8ddf-db2360d5da97", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{3} + 3 x^{2} + 3 x - 1$\n" ], "text/plain": [ " 3 2 \n", "x + 3*x + 3*x - 1" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HH = (x+1)^3-2 |> expand" ] }, { "cell_type": "code", "execution_count": 21, "id": "7d3cbc8c-13bf-48d2-b2e7-917158aa2694", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} + 3 x - 2\\right) \\left(x^{3} + 3 x^{2} + 3 x - 1\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 2 \\\n", "\\x + 3*x - 2/*\\x + 3*x + 3*x - 1/" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FF = GG*HH" ] }, { "cell_type": "code", "execution_count": 22, "id": "4d111fb6-5c7b-470e-b198-948d6a9d51c9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{5} + 6 x^{4} + 10 x^{3} + 2 x^{2} - 9 x + 2$\n" ], "text/plain": [ " 5 4 3 2 \n", "x + 6*x + 10*x + 2*x - 9*x + 2" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FF = expand(FF)" ] }, { "cell_type": "markdown", "id": "05131908-5323-4126-a7bf-2b3b8ec443c3", "metadata": {}, "source": [ "既存の函数を使えば因数分解は易しい." ] }, { "cell_type": "code", "execution_count": 23, "id": "fe89deee-1831-4039-a19d-946026f83cdd", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} + 3 x - 2\\right) \\left(x^{3} + 3 x^{2} + 3 x - 1\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 2 \\\n", "\\x + 3*x - 2/*\\x + 3*x + 3*x - 1/" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(FF)" ] }, { "cell_type": "markdown", "id": "8bdfdccf-feaf-4ecf-991f-4f80625b929c", "metadata": {}, "source": [ "係数を $P,Q,R,S,T$ に代入する." ] }, { "cell_type": "code", "execution_count": 24, "id": "75013cc9-6bc0-4654-aad4-93f4a6ac513c", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle 6\\\\\\displaystyle 10\\\\\\displaystyle 2\\\\\\displaystyle -9\\\\\\displaystyle 2\\end{array} \\right]$\n" ], "text/plain": [ "6-element Vector{Sym}:\n", " 1\n", " 6\n", " 10\n", " 2\n", " -9\n", " 2" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_, P, Q, R, S, T = all_coeffs(FF, x)" ] }, { "cell_type": "markdown", "id": "478a5a5b-0636-472b-9368-8d77ee5057bf", "metadata": {}, "source": [ "余りの定数項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 25, "id": "eb080670-4ef6-4f57-8581-cd8cfc396a9b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} - 6 a^{2} - 2 a b + 10 a + 6 b - 2 + \\frac{2}{b}$\n" ], "text/plain": [ " 3 2 2\n", "a - 6*a - 2*a*b + 10*a + 6*b - 2 + -\n", " b" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem0 = eqrem0(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "5690df89-8c11-4d2f-a222-7d7077ab9976", "metadata": {}, "source": [ "余りの1次の項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 26, "id": "61bd7ed1-9a74-46f1-8a6e-b5bb2c18369a", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} - 6 a^{3} - 3 a^{2} b + 10 a^{2} + 12 a b - 2 a + b^{2} - 10 b - 9$\n" ], "text/plain": [ " 4 3 2 2 2 \n", "a - 6*a - 3*a *b + 10*a + 12*a*b - 2*a + b - 10*b - 9" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem1 = eqrem1(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "ac761886-dea6-465d-b580-d0ca1aa66e16", "metadata": {}, "source": [ "$be = 2$ となる整数の組 $(b, e)$ 全体について, 最下段の方程式が整数解を持つ場合を探す." ] }, { "cell_type": "code", "execution_count": 27, "id": "cd9e057e-f04b-493c-8333-4ad0473e2049", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{rr}\\displaystyle 1&\\displaystyle a^{3} - 6 a^{2} + 8 a + 6\\\\\\displaystyle -1&\\displaystyle a^{3} - 6 a^{2} + 12 a - 10\\\\\\displaystyle 2&\\displaystyle a^{3} - 6 a^{2} + 6 a + 11\\\\\\displaystyle -2&\\displaystyle \\left(a - 3\\right) \\left(a^{2} - 3 a + 5\\right)\\end{array}\\right]$\n" ], "text/plain": [ "4×2 Matrix{Sym}:\n", " 1 a^3 - 6*a^2 + 8*a + 6\n", " -1 a^3 - 6*a^2 + 12*a - 10\n", " 2 a^3 - 6*a^2 + 6*a + 11\n", " -2 (a - 3)*(a^2 - 3*a + 5)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor_for_all_divisors(Eqrem0, b, N(T))" ] }, { "cell_type": "markdown", "id": "e14a0e9b-c64b-4eb4-ab54-668d5c24165c", "metadata": {}, "source": [ "最後の $b=-2$ の場合にのみ整数解 $a=3$ が存在することがわかった." ] }, { "cell_type": "code", "execution_count": 28, "id": "06cfd6a9-aec5-4c11-ae03-d4d19a6f0493", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(-2, 3)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = -2, 3" ] }, { "cell_type": "markdown", "id": "3c91fb73-f473-445c-9507-0e807c1063f2", "metadata": {}, "source": [ "この場合が実際に解になっていることの確認." ] }, { "cell_type": "code", "execution_count": 29, "id": "134001f9-9e00-452a-9c25-0ddd114a4a8b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(-a + p, a^2 - a*p - b + q, -a^3 + a^2*p + 2*a*b - a*q - b*p + r)" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "C, D, E" ] }, { "cell_type": "code", "execution_count": 30, "id": "c5203760-33ef-41bc-96c3-d660f9df4c08", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3, 3, -1)" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "CC, DD, EE = C(a=>AA, b=>BB, p=>P), D(a=>AA, b=>BB, p=>P, q=>Q), E(a=>AA, b=>BB, p=>P, q=>Q, r=>R, t=>T)" ] }, { "cell_type": "code", "execution_count": 31, "id": "6aef550c-e718-420d-a089-855aa56b56ea", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "code", "execution_count": 32, "id": "500fe1d2-bd75-473a-a682-192a1d1e388b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} + 3 x - 2\\right) \\left(x^{3} + 3 x^{2} + 3 x - 1\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 2 \\\n", "\\x + 3*x - 2/*\\x + 3*x + 3*x - 1/" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol = (x^2 + AA*x + BB)*(x^3 + CC*x^2 + DD*x + EE)" ] }, { "cell_type": "code", "execution_count": 33, "id": "5e1b5979-eaa3-49d8-9848-480793520d5b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol - FF |> simplify" ] }, { "cell_type": "markdown", "id": "b8fef769-ad5c-458d-8044-11981c9a19e5", "metadata": {}, "source": [ "## 例2\n", "\n", "$f = x^5 - x^4 - 1$ の因数分解." ] }, { "cell_type": "code", "execution_count": 34, "id": "2c13915d-b8f7-47cf-911e-49b62a476104", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{5} - x^{4} - 1$\n" ], "text/plain": [ " 5 4 \n", "x - x - 1" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FF = x^5 - x^4 - 1" ] }, { "cell_type": "markdown", "id": "e3ca68f2-6f73-443b-b4c2-504d4d01d695", "metadata": {}, "source": [ "既存の函数を使えば易しい." ] }, { "cell_type": "code", "execution_count": 35, "id": "1b820290-8f5b-4aa9-9663-e257af15b225", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} - x + 1\\right) \\left(x^{3} - x - 1\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 \\\n", "\\x - x + 1/*\\x - x - 1/" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(FF)" ] }, { "cell_type": "markdown", "id": "e7860708-6129-4869-a6c5-180a1d76c9d4", "metadata": {}, "source": [ "よくある解答例では天下り的に「$x^3$ を足して引く」という方法を使っている.\n", "\n", "$$\n", "\\begin{aligned}\n", "x^5 - x^4 - 1\n", "&=\n", "x^5 - x^4 + x^3 - x^3 - 1\n", "\\\\ &=\n", "(x^5 - x^4 + x^3) - (x^3 + 1)\n", "\\\\ &=\n", "x^3(x^2-x+1) -(x+1)(x^2-x+1)\n", "\\\\ &=\n", "(x^2-x+1)(x^3-x-1).\n", "\\end{aligned}\n", "$$\n", "\n", "他の方法: $x^2-x+1 = 0$ (これの2つの解は虚数)のとき $x^3=-1$ なので, $x^5-x^4-1=-x^2+x-1=0$ となるので, $x^5 - x^4 - 1$ は $x^2-x+1$ で割り切れることがわかる." ] }, { "cell_type": "markdown", "id": "e6661d21-e08e-4b5e-bb15-08124f5ce5d1", "metadata": {}, "source": [ "以下では素朴な方法でも同じ結果が得られることを示す.\n", "\n", "係数を $P,Q,R,S,T$ に代入する." ] }, { "cell_type": "code", "execution_count": 36, "id": "2c032626-3f4f-47aa-b699-874d51e6ffa4", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle -1\\\\\\displaystyle 0\\\\\\displaystyle 0\\\\\\displaystyle 0\\\\\\displaystyle -1\\end{array} \\right]$\n" ], "text/plain": [ "6-element Vector{Sym}:\n", " 1\n", " -1\n", " 0\n", " 0\n", " 0\n", " -1" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_, P, Q, R, S, T = all_coeffs(FF, x)" ] }, { "cell_type": "markdown", "id": "e269c7d1-774f-475c-a330-650af29c4e45", "metadata": {}, "source": [ "余りの定数項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 37, "id": "b126ffc1-4670-4e2a-af44-333cfd9230f6", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} + a^{2} - 2 a b - b - \\frac{1}{b}$\n" ], "text/plain": [ " 3 2 1\n", "a + a - 2*a*b - b - -\n", " b" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem0 = eqrem0(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "ee7a2d75-1d4d-4f10-aefa-2303fb47ae82", "metadata": {}, "source": [ "余りの1次の項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 38, "id": "39c92b13-99aa-48ee-b339-0ce7db6213e8", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} + a^{3} - 3 a^{2} b - 2 a b + b^{2}$\n" ], "text/plain": [ " 4 3 2 2\n", "a + a - 3*a *b - 2*a*b + b " ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem1 = eqrem1(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "fafc1bd6-4267-49f9-b6ae-c4fdc6d508a0", "metadata": {}, "source": [ "$be=-1$ となる整数の組 $(b,d)$ の各々について, 最下段の方程式が整数解を持つかどうかを確認する." ] }, { "cell_type": "code", "execution_count": 39, "id": "e3fe41b6-3ecc-4e22-91f4-0bd626e41fbf", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{rr}\\displaystyle 1&\\displaystyle \\left(a + 1\\right) \\left(a^{2} - 2\\right)\\\\\\displaystyle -1&\\displaystyle \\left(a + 1\\right) \\left(a^{2} + 2\\right)\\end{array}\\right]$\n" ], "text/plain": [ "2×2 Matrix{Sym}:\n", " 1 (a + 1)*(a^2 - 2)\n", " -1 (a + 1)*(a^2 + 2)" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor_for_all_divisors(Eqrem0, b, N(T))" ] }, { "cell_type": "markdown", "id": "bfb90943-6c64-4dc1-866f-342031914ac6", "metadata": {}, "source": [ "$b=\\pm 1$ の両方の場合に整数解 $a=-1$ を持つことがわかった.\n", "\n", "これらが下から2段目の方程式も満たしているかを確認する." ] }, { "cell_type": "code", "execution_count": 40, "id": "891f232a-d4ca-4679-bd09-f6cd47ee419e", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = 1, -1\n", "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "code", "execution_count": 41, "id": "0f71e001-416e-487b-bbf4-eb00de2e185b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2$\n" ], "text/plain": [ "2" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = -1, -1\n", "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "markdown", "id": "d2ed6509-4426-4f05-89f6-e35c479b9227", "metadata": {}, "source": [ "$(a, b) = -1, 1$ の場合のみが解になっていることがわかった." ] }, { "cell_type": "markdown", "id": "22b7194d-f43c-44ce-a8c9-137901f11d12", "metadata": {}, "source": [ "以下は検算である." ] }, { "cell_type": "code", "execution_count": 42, "id": "80feb09b-0858-4bcf-8987-3256012df508", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, -1, -1)" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "AA, BB = -1, 1\n", "CC, DD, EE = C(a=>AA, b=>BB, p=>P), D(a=>AA, b=>BB, p=>P, q=>Q), E(a=>AA, b=>BB, p=>P, q=>Q, r=>R, t=>T)" ] }, { "cell_type": "code", "execution_count": 43, "id": "3565b1b0-d959-4d78-8660-59194170a5be", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} - x + 1\\right) \\left(x^{3} - x - 1\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 \\\n", "\\x - x + 1/*\\x - x - 1/" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol = (x^2 + AA*x + BB)*(x^3 + CC*x^2 + DD*x + EE)" ] }, { "cell_type": "code", "execution_count": 44, "id": "fd159a47-ca9d-42f0-a78d-bfbd22762938", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol - FF |> simplify" ] }, { "cell_type": "markdown", "id": "d1d35cf7-1b60-4e83-bcb0-00981bdc689d", "metadata": {}, "source": [ "## 例3\n", "\n", "$f = x^5 + 16x + 32$ の因数分解." ] }, { "cell_type": "code", "execution_count": 45, "id": "24af85b2-a6d4-4154-837e-32afd11d670d", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{5} + 16 x + 32$\n" ], "text/plain": [ " 5 \n", "x + 16*x + 32" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FF = x^5 + 16x + 32" ] }, { "cell_type": "markdown", "id": "2395e598-0fdc-40e0-8176-3dd313695694", "metadata": {}, "source": [ "既存の函数を使えば易しい." ] }, { "cell_type": "code", "execution_count": 46, "id": "0ca2ad7b-95fb-486f-86f5-3054d941782f", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} + 2 x + 4\\right) \\left(x^{3} - 2 x^{2} + 8\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 2 \\\n", "\\x + 2*x + 4/*\\x - 2*x + 8/" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(FF)" ] }, { "cell_type": "markdown", "id": "d31e402b-5b27-4db5-89ed-d75fd822660e", "metadata": {}, "source": [ "$f$ に $x=2z$ を代入して得られる\n", "\n", "$$\n", "f|_{x=2z} = 32(z^5+z+1)\n", "$$\n", "\n", "は $z^2+z+1=0$ (これの2つの解は虚数)のとき, $z^3=1$, $z^5=z^2$ となるので $0$ になる.\n", "\n", "ゆえに $z^2+z+1$ に $z=x/2$ を代入したものの4倍\n", "\n", "$$\n", "x^2 + 2x + 4\n", "$$\n", "\n", "で $f$ は割り切れる." ] }, { "cell_type": "markdown", "id": "07e8b6d4-c18f-4585-9057-a4a5428506cd", "metadata": {}, "source": [ "以下では素朴な方法でも同じ結果が得られることを示そう.\n", "\n", "係数を $P,Q,R,S,T$ に代入する." ] }, { "cell_type": "code", "execution_count": 47, "id": "65d453b0-e174-457d-a9bf-4026368218b9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle 0\\\\\\displaystyle 0\\\\\\displaystyle 0\\\\\\displaystyle 16\\\\\\displaystyle 32\\end{array} \\right]$\n" ], "text/plain": [ "6-element Vector{Sym}:\n", " 1\n", " 0\n", " 0\n", " 0\n", " 16\n", " 32" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_, P, Q, R, S, T = all_coeffs(FF, x)" ] }, { "cell_type": "markdown", "id": "22b021b7-7af2-43d5-8bb2-ac8234726640", "metadata": {}, "source": [ "余りの定数項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 48, "id": "65ef985c-67c2-4a18-893a-a39c1702019e", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} - 2 a b + \\frac{32}{b}$\n" ], "text/plain": [ " 3 32\n", "a - 2*a*b + --\n", " b " ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem0 = eqrem0(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "9879cc28-5968-4fdd-8464-e8533e2e29ce", "metadata": {}, "source": [ "余りの1次の項が0になるという条件." ] }, { "cell_type": "code", "execution_count": 49, "id": "6efca41f-970f-4ea1-9753-2a3456d94d2a", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} - 3 a^{2} b + b^{2} + 16$\n" ], "text/plain": [ " 4 2 2 \n", "a - 3*a *b + b + 16" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem1 = eqrem1(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "markdown", "id": "45a9a6a2-2910-4229-bfe1-4ad8f6074220", "metadata": {}, "source": [ "$b$ として $32$ の約数全体を動かして, `eqrem0` を0にする整数 $a$ が存在する場合を探す." ] }, { "cell_type": "code", "execution_count": 50, "id": "70fd2fcd-3553-4699-b303-3988aa628756", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{rr}\\displaystyle 1&\\displaystyle a^{3} - 2 a + 32\\\\\\displaystyle -1&\\displaystyle a^{3} + 2 a - 32\\\\\\displaystyle 2&\\displaystyle a^{3} - 4 a + 16\\\\\\displaystyle -2&\\displaystyle \\left(a - 2\\right) \\left(a^{2} + 2 a + 8\\right)\\\\\\displaystyle 4&\\displaystyle \\left(a - 2\\right) \\left(a^{2} + 2 a - 4\\right)\\\\\\displaystyle -4&\\displaystyle a^{3} + 8 a - 8\\\\\\displaystyle 8&\\displaystyle a^{3} - 16 a + 4\\\\\\displaystyle -8&\\displaystyle a^{3} + 16 a - 4\\\\\\displaystyle 16&\\displaystyle a^{3} - 32 a + 2\\\\\\displaystyle -16&\\displaystyle a^{3} + 32 a - 2\\\\\\displaystyle 32&\\displaystyle a^{3} - 64 a + 1\\\\\\displaystyle -32&\\displaystyle a^{3} + 64 a - 1\\end{array}\\right]$\n" ], "text/plain": [ "12×2 Matrix{Sym}:\n", " 1 a^3 - 2*a + 32\n", " -1 a^3 + 2*a - 32\n", " 2 a^3 - 4*a + 16\n", " -2 (a - 2)*(a^2 + 2*a + 8)\n", " 4 (a - 2)*(a^2 + 2*a - 4)\n", " -4 a^3 + 8*a - 8\n", " 8 a^3 - 16*a + 4\n", " -8 a^3 + 16*a - 4\n", " 16 a^3 - 32*a + 2\n", " -16 a^3 + 32*a - 2\n", " 32 a^3 - 64*a + 1\n", " -32 a^3 + 64*a - 1" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor_for_all_divisors(Eqrem0, b, N(T))" ] }, { "cell_type": "markdown", "id": "47e8642d-b78a-4c97-ab42-5a2324e6aa36", "metadata": {}, "source": [ "方程式 `eqrem0 = 0` は $b=4,-2$ のときにのみ整数解 $a=2$ を持つことがわかった." ] }, { "cell_type": "code", "execution_count": 51, "id": "3e58b87c-4cbb-4a15-a1c3-1009bc73dbc9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = 4, 2\n", "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "code", "execution_count": 52, "id": "36fcd873-8dc7-45f1-bece-d9eb6f007239", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 60$\n" ], "text/plain": [ "60" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = -2, 2\n", "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "markdown", "id": "8cb3b847-8cca-49c5-a841-504994da80f3", "metadata": {}, "source": [ "方程式 `eqrem0 = eqrem1 = 0` の整数解 $a = 2$, $b=4$ が見付かった." ] }, { "cell_type": "code", "execution_count": 53, "id": "1acce335-5e2a-43d8-b173-4920666a4994", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(-2, 0, 8)" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "AA, BB = 2, 4\n", "CC, DD, EE = C(a=>AA, b=>BB, p=>P), D(a=>AA, b=>BB, p=>P, q=>Q), E(a=>AA, b=>BB, p=>P, q=>Q, r=>R, t=>T)" ] }, { "cell_type": "code", "execution_count": 54, "id": "a457dfd8-b6fc-407e-9236-0e3276175193", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{2} + 2 x + 4\\right) \\left(x^{3} - 2 x^{2} + 8\\right)$\n" ], "text/plain": [ "/ 2 \\ / 3 2 \\\n", "\\x + 2*x + 4/*\\x - 2*x + 8/" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol = (x^2 + AA*x + BB)*(x^3 + CC*x^2 + DD*x + EE)" ] }, { "cell_type": "code", "execution_count": 55, "id": "ac373687-98c3-404e-9a1a-61dcdb8eff04", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol - FF |> simplify" ] }, { "cell_type": "markdown", "id": "32c5229d-eb72-4151-98c8-03142b34e0b1", "metadata": {}, "source": [ "## 例4\n", "\n", "$f = x^5 + 3x^4 - 2x^3 - 2x^2 - 6x + 4$ の因数分解" ] }, { "cell_type": "code", "execution_count": 56, "id": "1757f818-64d1-4f79-a452-a395179e6ac6", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle x^{5} + 3 x^{4} - 2 x^{3} - 2 x^{2} - 6 x + 4$\n" ], "text/plain": [ " 5 4 3 2 \n", "x + 3*x - 2*x - 2*x - 6*x + 4" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FF = x^5 + 3x^4 - 2x^3 - 2x^2 - 6x + 4" ] }, { "cell_type": "code", "execution_count": 57, "id": "047ff974-a50a-47c2-8fd5-799e070f96c0", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{3} - 2\\right) \\left(x^{2} + 3 x - 2\\right)$\n" ], "text/plain": [ "/ 3 \\ / 2 \\\n", "\\x - 2/*\\x + 3*x - 2/" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(FF)" ] }, { "cell_type": "markdown", "id": "2a136eb0-50ef-4583-9b58-45dd98d02924", "metadata": {}, "source": [ "$f$ が $x^k + a$ 型の因子を持つと決め打ちできるなら, そのように $f$ を整理すれば容易に因数分解できる.\n", "\n", "$$\n", "\\begin{aligned}\n", "x^5 + 3x^4 - 2x^3 - 2x^2 - 6x + 4\n", "&=\n", "(x^5 + 3x^4 - 2x^3) - (2x^2 + 6x - 4)\n", "\\\\ &=\n", "x^3(x^2 + 3x - 2) - 2(x^2 + 3x - 2)\n", "\\\\ &=\n", "(x^3-2)(x^2 + 3x - 2).\n", "\\end{aligned}\n", "$$" ] }, { "cell_type": "code", "execution_count": 58, "id": "7fd6db4b-b273-4d9b-a90d-f2a16348d734", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{3} - 2\\right) \\left(x^{2} + 3 x - 2\\right)$\n" ], "text/plain": [ "/ 3 \\ / 2 \\\n", "\\x - 2/*\\x + 3*x - 2/" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(FF)" ] }, { "cell_type": "code", "execution_count": 59, "id": "d8e7adcc-88a6-445a-bc14-df0642840865", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{r}\\displaystyle 1\\\\\\displaystyle 3\\\\\\displaystyle -2\\\\\\displaystyle -2\\\\\\displaystyle -6\\\\\\displaystyle 4\\end{array} \\right]$\n" ], "text/plain": [ "6-element Vector{Sym}:\n", " 1\n", " 3\n", " -2\n", " -2\n", " -6\n", " 4" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_, P, Q, R, S, T = all_coeffs(FF, x)" ] }, { "cell_type": "code", "execution_count": 60, "id": "134a281b-876f-4a1c-9ee7-0f5c0cb4f804", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} - a^{2} p - 2 a b + a q + b p - r + \\frac{t}{b}$\n" ], "text/plain": [ " 3 2 t\n", "a - a *p - 2*a*b + a*q + b*p - r + -\n", " b" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eqrem0" ] }, { "cell_type": "code", "execution_count": 61, "id": "1b990dda-d211-4c93-a7e0-03ae6d98d447", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{3} - 3 a^{2} - 2 a b - 2 a + 3 b + 2 + \\frac{4}{b}$\n" ], "text/plain": [ " 3 2 4\n", "a - 3*a - 2*a*b - 2*a + 3*b + 2 + -\n", " b" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem0 = eqrem0(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "code", "execution_count": 62, "id": "51b044d6-6ec2-4800-83eb-2237379b9b56", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} - a^{3} p - 3 a^{2} b + a^{2} q + 2 a b p - a r + b^{2} - b q + s$\n" ], "text/plain": [ " 4 3 2 2 2 \n", "a - a *p - 3*a *b + a *q + 2*a*b*p - a*r + b - b*q + s" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eqrem1" ] }, { "cell_type": "code", "execution_count": 63, "id": "9729f33c-3bba-4211-889b-4196f86628a9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle a^{4} - 3 a^{3} - 3 a^{2} b - 2 a^{2} + 6 a b + 2 a + b^{2} + 2 b - 6$\n" ], "text/plain": [ " 4 3 2 2 2 \n", "a - 3*a - 3*a *b - 2*a + 6*a*b + 2*a + b + 2*b - 6" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eqrem1 = eqrem1(p=>P, q=>Q, r=>R, s=>S, t=>T)" ] }, { "cell_type": "code", "execution_count": 64, "id": "086ad167-0079-44e6-b6ee-fe6d5262d1a4", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\left[ \\begin{array}{rr}\\displaystyle 1&\\displaystyle a^{3} - 3 a^{2} - 4 a + 9\\\\\\displaystyle -1&\\displaystyle a^{3} - 3 a^{2} - 5\\\\\\displaystyle 2&\\displaystyle a^{3} - 3 a^{2} - 6 a + 10\\\\\\displaystyle -2&\\displaystyle \\left(a - 3\\right) \\left(a^{2} + 2\\right)\\\\\\displaystyle 4&\\displaystyle a^{3} - 3 a^{2} - 10 a + 15\\\\\\displaystyle -4&\\displaystyle a^{3} - 3 a^{2} + 6 a - 11\\end{array}\\right]$\n" ], "text/plain": [ "6×2 Matrix{Sym}:\n", " 1 a^3 - 3*a^2 - 4*a + 9\n", " -1 a^3 - 3*a^2 - 5\n", " 2 a^3 - 3*a^2 - 6*a + 10\n", " -2 (a - 3)*(a^2 + 2)\n", " 4 a^3 - 3*a^2 - 10*a + 15\n", " -4 a^3 - 3*a^2 + 6*a - 11" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor_for_all_divisors(Eqrem0, b, N(T))" ] }, { "cell_type": "code", "execution_count": 65, "id": "0616bd8a-0758-450c-8a6d-3894cd5acdf5", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BB, AA = -2, 3\n", "Eqrem1(a=>AA, b=>BB)" ] }, { "cell_type": "code", "execution_count": 66, "id": "abc91ac0-82a8-426f-84a9-47b2906ded58", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0, 0, -2)" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "AA, BB = 3, -2\n", "CC, DD, EE = C(a=>AA, b=>BB, p=>P), D(a=>AA, b=>BB, p=>P, q=>Q), E(a=>AA, b=>BB, p=>P, q=>Q, r=>R, t=>T)" ] }, { "cell_type": "code", "execution_count": 67, "id": "bf190e8c-54cb-4436-a202-f89d0b128015", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left(x^{3} - 2\\right) \\left(x^{2} + 3 x - 2\\right)$\n" ], "text/plain": [ "/ 3 \\ / 2 \\\n", "\\x - 2/*\\x + 3*x - 2/" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol = (x^2 + AA*x + BB)*(x^3 + CC*x^2 + DD*x + EE)" ] }, { "cell_type": "code", "execution_count": 68, "id": "19c1391f-a40d-41aa-8d3f-6721ba3962f9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 0$\n" ], "text/plain": [ "0" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sol - FF |> simplify" ] }, { "cell_type": "code", "execution_count": null, "id": "0edf973a-9e6d-47ff-ac54-1613a7a10948", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "encoding": "# -*- coding: utf-8 -*-", "formats": "ipynb,jl:hydrogen" }, "kernelspec": { "display_name": "Julia 1.9.0", "language": "julia", "name": "julia-1.9" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.9.0" } }, "nbformat": 4, "nbformat_minor": 5 }