2017年12月30日土曜日

学習環境

代数系入門 (松坂 和夫(著)、岩波書店)の第1章(整数)、6(同値関係、合同式)、問題6.を取り組んでみる。


  1. m = m 1 m k m 1 , , m k

    が成り立つ。

    d = m 1 , , m k

    とおく。(d は最大公約数)

    m = m 1 m k d

    また、

    a - b = d s s a - b d = s
    m i d | a - b d i = 1 , , k m i d , m j d = 1

    よって

    m i d · m j d | a - b d i j m i m j d 2 l = a - b d l m i m j d l = a - b m i m j d | a - b

    ゆえに、帰納的に

    m 1 m k d | a - b

    が成り立つ。

    よって、

    m | a - b

    すなわち

    a b m o d m

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, gcd
import random


def mod(a, b, m):
    return (a - b) % m == 0


a = 35
b = 65

m1 = 10
m2 = 15
m = 30
for t in [mod(a, b, m1), mod(a, b, m2), mod(a, b, m)]:
    pprint(t)
    print()

入出力結果(Terminal, Jupyter(IPython))

$ ./sample6.py
True

True

True

$

HTML5

<pre id="output0"></pre>

<input id="a0" type="number" step="1" value="35"><input id="b0" type="number" step="1" value="65">
(mod <input id="m1" type="number" min="1" step="1" value="10">)
<br>
<span class="a1"></span><span class="b1"></span>
(mod <input id="m2" type="number" step="1" value="15">)
<br>
<span class="a1"></span><span class="b1"></span>
(mod <span id="m0"></span>)
<button id="run0">run</button>
<button id="clear0">clear</button>
<script src="sample6.js"></script>

JavaScript

let pre0 = document.querySelector('#output0'),
    run0 = document.querySelector('#run0'),
    clear0 = document.querySelector('#clear0'),
    input_a0 = document.querySelector('#a0'),
    input_b0 = document.querySelector('#b0'),
    input_m1 = document.querySelector('#m1'),
    input_m2 = document.querySelector('#m2'),
    span_a1 = document.querySelectorAll('.a1'),
    span_b1 = document.querySelectorAll('.b1'),
    span_m0 = document.querySelector('#m0'),    
    inputs = [input_a0, input_b0, input_m1, input_m2],
    range = (n) => {
        let result = [];

        for (let i = 0; i < n; i += 1) {
            result.push(i);
        }
        
        return result;
    },
    p = (text) => pre0.textContent += text + '\n',
    clear = () => pre0.textContent = '',
    mod = (a, b, m) => (a - b) % m === 0,
    gcd = (a, b) => {
        let d = a < b ? a : b
        for (; a % d !== 0 || b % d !== 0; d -= 1) {
        }
        return d;
    },
    output = () => {
        let a = parseInt(input_a0.value, 10),
            b = parseInt(input_b0.value, 10),
            m1 = parseInt(input_m1.value, 10),
            m2 = parseInt(input_m2.value, 10),
            m = m1 * m2 / gcd(m1, m2);

        span_a1.forEach((cls) => cls.textContent = a)
        span_b1.forEach((cls) => cls.textContent = b)
        span_m0.textContent = m;
        
        if ((a - b) % m1 === 0 && (a - b) % m2 === 0) {
            [mod(a, b, m1), mod(a, b, m2), mod(a, b, m)]
                .forEach((b) => p(b));
        } else {
            p('仮定を満たしていない');
        }
    };

run0.onclick = output;
clear0.onclick = clear;
inputs.forEach((input) => input.onchange = output);
output();



(mod )

(mod )
(mod )

0 コメント:

コメントを投稿