2016年9月16日金曜日

学習環境/開発環境

代数系入門 (松坂 和夫(著)、岩波書店)の第1章(整数)、2(数学的帰納法と除法の定理)、問題3.を取り組んでみる。

問題3.


  1. 1+2+···+n+( n+1 ) = n( n+1 ) 2 +( n+1 ) = ( n+1 )( ( n+1 )+1 ) 2

  2. 1 2 + 2 2 +···+ n 2 + ( n+1 ) 2 = n( n+1 )( 2n+1 ) 6 + ( n+1 ) 2 = ( n+1 )( n( 2n+1 )+6( n+1 ) ) 6 = ( n+1 )( 2 n 2 +7n+6 ) 6 = ( n+1 )( n+2 )( 2n+3 ) 6 = ( n+1 )( ( n+1 )+1 )( 2( n+1 )+1 ) 6

  3. 1 3 + 2 3 +···+ n 3 + ( n+1 ) 3 = n 2 ( n+1 ) 2 4 + ( n+1 ) 3 = ( n+1 ) 2 ( n 2 +4( n+1 ) ) 4 = ( n+1 ) 2 ( n 2 +4n+4 ) 4 = ( n+1 ) 2 ( n+2 ) 2 4 = ( n+1 ) 2 ( ( n+1 )+1 ) 2 4

  4. 1·2+2·3+···+n( n+1 )+( n+1 )( ( n+1 )+1 ) = 1 3 n( n+1 )( n+2 )+( n+1 )( ( n+1 )+1 ) = ( n+1 )( n+2 )( n+3 ) 3 = ( n+1 )( ( n+1 )+1 )( ( n+1 )+2 ) 3

  5. 1 1 2 + 1 3 1 4 +···+ 1 2n1 1 2n + 1 2( n+1 )1 1 2( n+1 ) = 1 n+1 + 1 n+2 +···+ 1 2n + 1 2( n+1 )1 1 2( n+1 ) = 1 n+2 +···+ 1 2n + 1 2n+1 1 2( n+1 ) + 1 n+1 = 1 n+2 + 1 n+3 +···+ 1 2n + 1 2n+1 + 1 2( n+1 ) = 1 ( n+1 )+1 + 1 ( n+1 )+2 +···+ 1 2( n+1 )

  6. ( n+1 )( n+2 )( n+3 )···( 2n ) ( 2n+1 )( 2( n+1 ) ) n+1 = 2 n ·1·3·5·····( 2n1 ) ( 2n+1 )( 2( n+1 ) ) n+1 = 2 n+1 ·1·3·5·····( 2n1 )( 2n+1 )

  7. 1+2x+3 x 2 +···+n x n1 +( n+1 ) x n = 1 x n ( 1x ) 2 n x n 1x +( n+1 ) x n = ( 1 x n )n( 1x ) x n + ( 1x ) 2 ( n+1 ) x n ( 1x ) 2 = 1 x n n x n +n x n+1 +n x n + x n 2n x n+1 2 x n+1 +n x n+2 + x n+2 ( 1x ) 2 = 1n x n+1 2 x n+1 +n x n+2 + x n+2 ( 1x ) 2 = 1 x n+1 ( 1x ) 2 x n+1 +n x n+1 n x n+2 x n+2 ( 1x ) 2 = 1 x n+1 ( 1x ) 2 ( n+1 ) x n+2 +( n+1 ) x n+1 ( 1x ) 2 = 1 x n+1 ( 1x ) 2 ( n+1 ) x n+1 ( 1x ) ( 1x ) 2 = 1 x n+1 ( 1x ) 2 ( n+1 ) x n+1 1x

JavaScript で確認。

HTML5

<label for="n0">n = </label>
<input id="n0" type="number" min="1" step="1" value="100">
<label for="x0">n = </label>
<input id="x0" type="number" value="10">
<div id="output0"></div>

<script src="array.js"></script>
<script src="number.js"></script>
<script src="sample3.js"></script>

JavaScript

コード(Emacs)

var input_n = document.querySelector('#n0'),
    input_x = document.querySelector('#x0'),
    inputs = [input_n, input_x],
    div_output = document.querySelector('#output0'),
    nl = '<br>',
    accumulate,
    sum,
    mul,
    funcs,
    output;

accumulate = function (op, func, initial, a, b) {
    return Array.range(a, b + 1)
        .map(function (n) {
            return func(n);
        })
        .reduce(function (x, y) {
            return op(x, y);
        }, initial);
};

sum = function (func, n) {
    return accumulate(
        function (x, y) {
            return x + y;
        }, func, 0, 1, n);
};
mul = function (func, n) {
    return accumulate(
        function (x, y) {
            return x * y;
        }, func, 1, 1, n);
};
funcs = [
    [
        function (n) {
            return sum(function (n) {
                return n;
            }, n);
        },
        function (n) {
            return n * (n + 1) / 2;
        }
    ],
    [
        function (n) {
            return sum(function (n) {
                return Math.pow(n, 2);
            }, n);
        },
        function (n) {
            return n * (n + 1) * (2 * n + 1) / 6;
        }
    ],
    [
        function (n) {
            return sum(function (n) {
                return Math.pow(n, 3);
            }, n);
        },
        function (n) {
            return Math.pow(n, 2) * Math.pow(n + 1, 2) / 4;
        }
    ],
    [
        function (n) {
            return sum(function (n) {
                return n * (n + 1);
            }, n);
        },
        function (n) {
            return 1 / 3 * n * (n + 1) * (n + 2);
        }
    ],
    [
        function (n) {
            return sum(function (n) {
                return 1 / (2 * n - 1) - 1 / (2 * n);
            }, n);
        },
        function (n) {
            return sum(function (i) {
                return 1 / (i + n);
            }, n);
        }
    ],
    [
        function (n) {
            return mul(function (n) {
                return 2 * n;
            }, n);
        },
        function (n) {
            return Math.pow(2, n) * mul(function (n) {
                return 2 * n - 1;
            }, n);
        }
    ],
    [
        function (n, x) {
            return sum(function (n) {
                return n * Math.pow(x, n -1);
            }, n);
        },
        function (x, n) {
            return (1 - Math.pow(x, n)) / Math.pow(1 - x, 2) -
                n * Math.pow(x, n) / (1 - x);
        }
    ]
];

output = function () {
    var n = parseInt(input_n.value, 10),
        x = parseFloat(input_x.value),
        code = 'a'.charCodeAt(0);

    div_output.innerHTML = '';
    Array.range(7).map(
        function (i) {
            return String.fromCharCode(code + i);
        })
        .forEach(function (ch, i) {
            var left = funcs[i][0](n, x),
                right = funcs[i][1](n, x);
            
            div_output.innerHTML +=
                '(' + ch + ')' + nl +
                ' 左辺: ' + left + ', 右辺: ' + right + nl +
                '左辺 = 右辺: ' + (left === right) + nl +
                '|左辺 - 右辺| = ' + (left - right).abs() + nl + nl;
        });
};

inputs.forEach(function (input) {
    input.onchange = output;
});

output();

0 コメント:

コメントを投稿

Comments on Google+: