zoukankan      html  css  js  c++  java
  • A number of problems from coded in ARM assembly language Problems

    http://www.fourtheye.org/cgi-bin/language.pl?language=asm

    NOTE: This documents my investigation into assembly language programming on the ARM processor running my SheevaPlug. This runs Debian GNU/Linux. I use the GNU assembler, gas, the GNU linker, ld and the GNU debugger, gdb.


    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    Description of problem

    If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

    Find the sum of all the multiples of 3 or 5 below 1000.

    001.s

    .syntax unified .equ max3start,999 .equ max5start,995 number .req r4 matched .req r5 sum .req r6 max3 .req r7 max5 .req r8 .section .rodata .align 2 string: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r8, lr} ldr max5, =max5start ldr max3, =max3start ldr number, =max3start @ start at 1000 - 1 ; numbers < 1000 mov matched, 0 mov sum, 0 loop: cmp number, max3 bne test5 # matched a multiple of 3 - decrement max3, add to sum and set matched to 1 mov matched, 1 add sum, sum, number subs max3, max3, 3 test5: cmp number, max5 bne last # matched a multiple of 5 - decrement max5, add to sum and set matched to 1 subs max5, max5, 5 cmp matched, 1 @ have we already added it? addne sum, sum, number @ if not add it to the total last: # decrement number and reset matched and loop mov matched, 0 subs number, number, 1 bne loop mov r1, sum ldr r0, =string @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r8, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

    1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

    By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

    002.s

    .syntax unified .equ maxfib,4000000 previous .req r4 current .req r5 next .req r6 sum .req r7 max .req r8 tmp .req r9 .section .rodata .align 2 fibstring: .asciz "fib is %d " sumstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r9, lr} ldr max, =maxfib mov previous, 1 mov current, 1 mov sum, 0 # mov r1, current # ldr r0, =fibstring @ store address of start of string to r0 # bl printf loop: cmp current, max bgt last # mov r1, current # ldr r0, =fibstring @ store address of start of string to r0 # bl printf add next, current, previous movs tmp, current, lsr 1 @ set carry flag from lsr - for the odd-valued terms addcc sum, sum, current @ these are even-valued fibonacci (when cc is true) mov previous, current mov current, next b loop last: mov r1, sum ldr r0, =sumstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r9, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

    Find the sum of all the primes below two million.

    010.s

    .syntax unified .equ word,4 .equ logword,2 .equ limit,2000000 .equ numprimes4,595732 sum_hi .req r4 sum_lo .req r5 numprimes .req r6 primes_ptr .req r7 number .req r8 limit .req r9 .align 2 .section .bss .lcomm primes_vector,numprimes4 .section .rodata .align 2 llustring: .asciz "%llu " primestring: .asciz "num %d primality is %d " .text .align 8 .global main .type main, %function main: stmfd sp!, {r4-r9, fp, lr} ldr primes_ptr, =primes_vector mov numprimes, 1 mov number, 2 strb number, [primes_ptr] ldr limit, =limit mov sum_hi, 0 mov sum_lo, 2 mov number, 3 loop: cmp number, limit bge printme mov r0, number ldr r1, =primes_vector mov r2, numprimes bl prime_vector teq r0, 1 bne nexti str number, [primes_ptr, numprimes, lsl 2] add numprimes, numprimes, 1 adds sum_lo, sum_lo, number adc sum_hi, sum_hi, 0 nexti: add number, number, 2 b loop printme: mov r2, sum_lo mov r3, sum_hi ldr r0, =llustring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r9, fp, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    The prime factors of 13195 are 5, 7, 13 and 29.

    What is the largest prime factor of the number 600851475143 ?

    003.s

    .syntax unified @ 600851475143 is 8BE589EAC7 in hex @ root 600851475143 is 775146.099 .align 4 .equ numhi,139 @ 0x8b .equ numlo,3851020999 @ 0xe589eac7 .equ root,775147 num_hi .req r4 num_lo .req r5 maxdiv .req r6 n .req r7 tmp .req r8 .section .rodata .align 2 resstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r8, lr} mov maxdiv, 0 ldr n, =root ldr num_lo, =numlo ldr num_hi, =numhi loop: ldr r0, =numlo ldr r1, =numhi mov r2, n mov r3, 0 bl long_divide mov tmp, r0 teq r2, 0 bne nextn teq r3, 0 bne nextn bl isprime teq r0, 1 bne testn cmp maxdiv, tmp movlt maxdiv, tmp testn: mov r0, n bl isprime teq r0, 1 bne nextn cmp maxdiv, n movlt maxdiv, n nextn: sub n, n, 2 teq n, 1 beq printme b loop printme: mov r1, maxdiv ldr r0, =resstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r8, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux

    isprime.s

    .syntax unified # this subroutine returns 1 if the passed number is prime; 0 if not # inputs # r0 - integer to test # outputs # r0 - prime boolean number .req r4 divisor .req r5 tmp .req r6 .global isprime .type isprime, %function .text .align 2 isprime: stmfd sp!, {r4-r6, lr} mov number, r0 ands tmp, number, 1 bne odd mov r0, 0 cmp number, 2 @ 2 is the only prime even number bne last mov r0, 1 b last odd: mov divisor, 3 cmp number, 8 bgt big mov r0, 1 cmp number, 1 @ 1 is the only odd number < 8 not prime bne last mov r0, 0 b last big: mov r0, number mov r1, divisor bl divide teq r1, 0 beq factor add divisor, divisor, 2 mul tmp, divisor, divisor subs tmp, tmp, number ble big mov r0, 1 b last factor: mov r0, 0 last: ldmfd sp!, {r4-r6, pc}
    Description of problem

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

    Find the largest palindrome made from the product of two 3-digit numbers.

    004.s

    .syntax unified .equ max3,999 .equ min3,100 .equ maxdigits,6 i .req r4 j .req r5 product .req r6 maxp .req r7 mini .req r8 minj .req r9 maxj .req r10 .section .rodata .align 2 sumstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r10, lr} ldr i, =max3 ldr mini, =min3 ldr maxj, =max3 ldr minj, =min3 iloop: mov j, maxj jloop: mul product, i, j mov r0, product bl is_palindromic cmp r0, #1 bne next cmp product, maxp ble next mov maxp, product mov r0, product bl divide_by_10 @ divides r0 by 10 bl divide_by_10 @ so 3 consecutive calls bl divide_by_10 @ will divide by 1000 mov minj, r0 mov minj, r0 next: subs j, j, 1 cmp j, minj bgt jloop subs i, i, 1 mov maxj, i cmp i, mini bgt iloop last: mov r1, maxp ldr r0, =sumstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r10, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux

    ispalindromic.s

    .syntax unified .equ datum_size, 1 .equ digits, 6 # this subroutine returns 1 if the passed 6-digit number is palindromic; 0 if not # the number is a product of 2 3-digit numbers so we assume the product has 6 digits # # inputs # r0 - integer to test # # outputs # r0 - palindromic boolean # # local # left .req r4 right .req r5 counter .req r6 buffer_address .req r7 running .req r8 tmp .req r9 # .section .bss .lcomm buffer, 6 # .global is_palindromic .type is_palindromic, %function .global get_digits .type get_digits, %function .text .align 2 # is_palindromic: stmfd sp!, {r4-r9, lr} bl get_digits mov counter, 3 ldr buffer_address, =buffer ip_last: sub left, buffer_address, counter ldrb tmp, [left, 3] add right, buffer_address, counter ldrb running, [right, 2] teq tmp, running bne no subs counter, counter, 1 bgt ip_last mov r0, 1 b last no: mov r0, 0 last: ldmfd sp!, {r4-r9, pc} # get_digits: stmfd sp!, {r7-r8, lr} ldr running, =digits ldr buffer_address, =buffer gd_loop: subs running, running, 1 bl divide_by_10_remainder strb r1, [buffer_address], #datum_size bgt gd_loop gd_last: ldmfd sp!, {r7-r8, pc}
    Description of problem

    The sum of the squares of the first ten natural numbers is,

    12 + 22 + ... + 102 = 385

    The square of the sum of the first ten natural numbers is,

    (1 + 2 + ... + 10)2 = 552 = 3025

    Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 ? 385 = 2640.

    Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

    006.s

    .syntax unified .equ limit,100 number .req r4 sumsq .req r5 sqsum .req r6 tmp .req r7 .section .rodata .align 2 string: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r7, lr} mov sqsum, 0 mov sumsq, 0 ldr number, =limit loop: mul tmp, number, number add sqsum, sqsum, tmp # decrement number and loop or exit subs number, number, 1 beq end_loop b loop end_loop: ldr number, =limit add number, number, 1 ldr sumsq, =limit mul sumsq, sumsq, number lsr sumsq, sumsq, 1 mul sumsq, sumsq, sumsq last: sub tmp, sumsq, sqsum mov r1, tmp ldr r0, =string @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r7, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux

    test_ispalindromic.s

    .equ nonpalindromic,123456 .equ palindromic1,123321 .equ palindromic2,815518 .syntax unified number .req r4 palindromicflag .req r5 .macro num_is_palindromic a ldr number, =a mov r0, number bl is_palindromic mov palindromicflag, r0 mov r2, palindromicflag mov r1, number ldr r0, =palindromicstring bl printf .endm .section .rodata .align 2 palindromicstring: .asciz "num %d palindromicity is %d " .text .align 2 .global main .type main, %function main: num_is_palindromic nonpalindromic num_is_palindromic palindromic1 num_is_palindromic palindromic2 mov r0, 0 mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux

    test_isprime.s

    .syntax unified number .req r4 primeflag .req r5 .macro num_is_prime a mov number, a mov r0, number bl isprime mov primeflag, r0 mov r2, primeflag mov r1, number ldr r0, =primestring bl printf .endm .section .rodata .align 2 primestring: .asciz "num %d primality is %d " .text .align 2 .global main .type main, %function main: num_is_prime 1 num_is_prime 2 num_is_prime 3 num_is_prime 4 num_is_prime 5 num_is_prime 7 num_is_prime 9 num_is_prime 11 num_is_prime 13 num_is_prime 15 num_is_prime 17 num_is_prime 19 num_is_prime 20 num_is_prime 21 num_is_prime 23 num_is_prime 25 num_is_prime 27 num_is_prime 29 ldr number, =716151937 mov r0, number bl isprime mov primeflag, r0 mov r2, primeflag mov r1, number ldr r0, =primestring bl printf mov r0, 0 mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux

    divide_by_10.s

    .syntax unified # this subroutine divides the passed number by 10 and # returns the dividend and remainder # # The const -0x33333333 is 0xccccccd (2s complement) # 0xcccccccc is 12/15th (0.8) of 0xffffffff and we use this as # a multiplier, then shift right by 3 bits (divide by 8) to # effect a multiplication by 0.1 # # We multiply this number by 10 (multiply by 4, add 1 then multiply by 2) # and subtract from the original number to give the remainder on division # by 10. # # inputs # r0 - integer to divide # # outputs # r0 - the dividend # r1 - the remainder .equ const,-0x33333333 #.equ const,0xcccccccd .text .align 2 .global divide_by_10_remainder .type divide_by_10_remainder, %function divide_by_10_remainder: stmfd sp!, {lr} cmp r0, 10 blt rsmall ldr r1, =const umull r2, r3, r1, r0 mov r2, r3, lsr #3 @ r2 = r3 / 8 == r0 / 10 mov r3, r2 @ r3 = r2 mov r3, r3, asl #2 @ r3 = 4 * r3 add r3, r3, r2 @ r3 = r3 + r2 mov r3, r3, asl #1 @ r3 = 2 * r3 rsb r3, r3, r0 @ r3 = r0 - r3 = r0 - 10*int(r0/10) mov r1, r3 @ the remainder mov r0, r2 @ the dividend b rlast rsmall: mov r1, r0 mov r0, 0 rlast: ldmfd sp!, {pc} # this subroutine divides the passed number by 10 # returns the dividend # # The const -0x33333333 is 0xccccccd (2s complement) # 0xcccccccc is 12/15th (0.8) of 0xffffffff and we use this as # a multiplier, then shift right by 3 bits (divide by 8) to # effect a multiplication by 0.1 # # We multiply this number by 10 (multiply by 4, add 1 then multiply by 2) # # inputs # r0 - integer to divide # # outputs # r0 - the dividend .align 2 .global divide_by_10 .type divide_by_10, %function divide_by_10: stmfd sp!, {lr} cmp r0, 10 blt small ldr r1, =const umull r2, r3, r1, r0 mov r2, r3, lsr #3 @ r2 = r3 / 8 == r0 / 10 mov r0, r2 @ the dividend b last small: mov r0, 0 last: ldmfd sp!, {pc}
    Description of problem

    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

    What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

    005.s

    .syntax unified .equ limit,20 .align 4 @ algorithm @ initialise try_products to 1 @ foreach number > 1 and <= limit @ test if it is prime @ if try_products is set, then multiply the number by itself @ while it does not exceed limit, then multiply the total by @ this product. if the number squared exceeds the limit, then @ set try_product to 0. @ if try_products is 0 and the number is prime, then multiply @ the total by number. try_product .req r4 number .req r5 last .req r6 total .req r7 tmp .req r8 .section .rodata .align 2 resstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r8, lr} mov total, 1 mov try_product, 1 mov number, 2 loop: mov r0, number bl isprime20 cmp r0, 1 bne nexti cmp try_product, 1 bne no_product mul tmp, number, number cmp tmp, limit ble prod_start mov try_product, 0 b no_product prod_start: mov tmp, number mov last, tmp prod_loop: cmp tmp, limit bgt last_mul mov last, tmp mul tmp, tmp, number b prod_loop last_mul: mul total, total, last no_product: cmp try_product, 0 bne nexti mul total, total, number nexti: cmp number, limit beq printme add number, number, 1 b loop printme: mov r1, total ldr r0, =resstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r8, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux # this subroutine returns 1 if the passed number (<= 20) is prime; 0 if not # # inputs # r0 - integer to test # # outputs # r0 - prime boolean .global isprime20 .type isprime20, %function .text .align 2 isprime20: stmfd sp!, {lr} mov r1, r0 ands r2, r1, 1 bne odd mov r0, 0 cmp r1, 2 @ 2 is the only prime even r1 bne last mov r0, 1 b last odd: mov r0, 1 cmp r1, 9 bne test15 mov r0, 0 b last test15: cmp r1, 15 bne last mov r0, 0 last: ldmfd sp!, {pc}

    test_divide_by_10.s

    .equ num0,7830 .equ num3,783 .equ num7,7847 .equ num8,78 .equ num9,7 .syntax unified .macro dividend num ldr r1, = um ldr r0, =numstring bl printf ldr r0, = um bl divide_by_10 mov r1, r0 ldr r0, =dividendstring bl printf .endm .macro remainder num ldr r1, = um ldr r0, =numstring bl printf ldr r0, = um bl divide_by_10_remainder mov r2, r0 ldr r0, =remainderstring bl printf .endm .section .rodata .align 2 numstring: .asciz "num is %d " dividendstring: .asciz "dividend is %d " remainderstring: .asciz "remainder is %d and dividend is %d " .text .align 2 .global main .type main, %function main: remainder num0 remainder num7 remainder num3 remainder num8 remainder num9 dividend num0 dividend num7 dividend num3 dividend num8 dividend num9 mov r0, 0 mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

    What is the 10 001st prime number?

    007.s

    .syntax unified .equ limit,10000 .equ limit4,40000 .align 4 number .req r4 count .req r5 numprimes .req r6 primes_ptr .req r7 .section .bss .lcomm primes_vector,limit4 .section .rodata .align 2 resstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r7, lr} ldr primes_ptr, =primes_vector mov numprimes, 1 mov number, 2 strb number, [primes_ptr] ldr count, =limit mov number, 3 @ 2 is the first prime loop: mov r0, number ldr r1, =primes_vector mov r2, numprimes bl prime_vector teq r0, 1 bne nexti str number, [primes_ptr, numprimes, lsl 2] add numprimes, numprimes, 1 subs count, count, 1 beq printme nexti: add number, number, 2 b loop printme: mov r1, number ldr r0, =resstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r7, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    Find the greatest product of five consecutive digits in the 1000-digit number.

    73167176531330624919225119674426574742355349194934
    96983520312774506326239578318016984801869478851843
    85861560789112949495459501737958331952853208805511
    12540698747158523863050715693290963295227443043557
    66896648950445244523161731856403098711121722383113
    62229893423380308135336276614282806444486645238749
    30358907296290491560440772390713810515859307960866
    70172427121883998797908792274921901699720888093776
    65727333001053367881220235421809751254540594752243
    52584907711670556013604839586446706324415722155397
    53697817977846174064955149290862569321978468622482
    83972241375657056057490261407972968652414535100474
    82166370484403199890008895243450658541227588666881
    16427171479924442928230863465674813919123162824586
    17866458359124566529476545682848912883142607690042
    24219022671055626321111109370544217506941658960408
    07198403850962455444362981230987879927244284909188
    84580156166097919133875499200524063689912560717606
    05886116467109405077541002256983155200055935729725
    71636269561882670428252483600823257530420752963450

    008.s

    .syntax unified .equ limit,10000 .equ outer, 996 .equ inner, 5 .align 4 address .req r4 thisbyte .req r5 icounter .req r6 ocounter .req r7 maxv .req r8 tmp .req r9 .section .data buffer: .byte 7, 3, 1, 6, 7, 1, 7, 6, 5, 3, 1, 3, 3, 0, 6, 2, 4, 9, 1, 9, 2, 2 .byte 5, 1, 1, 9, 6, 7, 4, 4, 2, 6, 5, 7, 4, 7, 4, 2, 3, 5, 5, 3, 4, 9, 1, 9 .byte 4, 9, 3, 4, 9, 6, 9, 8, 3, 5, 2, 0, 3, 1, 2, 7, 7, 4, 5, 0, 6, 3, 2, 6 .byte 2, 3, 9, 5, 7, 8, 3, 1, 8, 0, 1, 6, 9, 8, 4, 8, 0, 1, 8, 6, 9, 4, 7, 8 .byte 8, 5, 1, 8, 4, 3, 8, 5, 8, 6, 1, 5, 6, 0, 7, 8, 9, 1, 1, 2, 9, 4, 9, 4 .byte 9, 5, 4, 5, 9, 5, 0, 1, 7, 3, 7, 9, 5, 8, 3, 3, 1, 9, 5, 2, 8, 5, 3, 2 .byte 0, 8, 8, 0, 5, 5, 1, 1, 1, 2, 5, 4, 0, 6, 9, 8, 7, 4, 7, 1, 5, 8, 5, 2 .byte 3, 8, 6, 3, 0, 5, 0, 7, 1, 5, 6, 9, 3, 2, 9, 0, 9, 6, 3, 2, 9, 5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8, 4, 9, 0, 9, 1, 8, 8, 8, 4, 5, 8, 0, 1, 5, 6, 1, 6, 6, 0 .byte 9, 7, 9, 1, 9, 1, 3, 3, 8, 7, 5, 4, 9, 9, 2, 0, 0, 5, 2, 4, 0, 6, 3, 6 .byte 8, 9, 9, 1, 2, 5, 6, 0, 7, 1, 7, 6, 0, 6, 0, 5, 8, 8, 6, 1, 1, 6, 4, 6 .byte 7, 1, 0, 9, 4, 0, 5, 0, 7, 7, 5, 4, 1, 0, 0, 2, 2, 5, 6, 9, 8, 3, 1, 5 .byte 5, 2, 0, 0, 0, 5, 5, 9, 3, 5, 7, 2, 9, 7, 2, 5, 7, 1, 6, 3, 6, 2, 6, 9 .byte 5, 6, 1, 8, 8, 2, 6, 7, 0, 4, 2, 8, 2, 5, 2, 4, 8, 3, 6, 0, 0, 8, 2, 3 .byte 2, 5, 7, 5, 3, 0, 4, 2, 0, 7, 5, 2, 9, 6, 3, 4, 5, 0 .section .rodata .align 2 resstring: .asciz "%d " .text .align 2 .global main .type main, %function main: stmfd sp!, {r4-r9, lr} ldr address, =buffer ldr ocounter, =outer outer_start: ldr icounter, =inner mov tmp, #1 inner_start: ldrb thisbyte, [address], 1 mul tmp, tmp, thisbyte subs icounter, icounter, 1 bne inner_start cmp maxv, tmp movlt maxv, tmp sub address, address, 4 subs ocounter, ocounter, 1 bne outer_start printme: mov r1, maxv ldr r0, =resstring @ store address of start of string to r0 bl printf mov r0, 0 ldmfd sp!, {r4-r9, pc} mov r7, 1 @ set r7 to 1 - the syscall for exit swi 0 @ then invoke the syscall from linux
    Description of problem

    A Pythagorean triplet is a set of three natural numbers, a b <img src= a2 + b2 = c2

    For example, 32 + 42 = 9 + 16 = 25 = 52.

    There exists exactly one Pythagorean triplet for which a + b + c = 1000.
    Find the product abc.

  • 相关阅读:
    vue computed watch 使用区别
    element 问题
    vue vue.config.js
    vue 路由
    算法
    《概率统计》10.变与不变:马尔科夫链的极限与稳态
    《概率统计》9.状态转移:初识马尔科夫链
    《概率统计》8.由静向动:随机过程导引
    《概率统计》7.统计推断:寻找最大似然与最大后验
    《概率统计》6.推断未知:统计推断的基本框架
  • 原文地址:https://www.cnblogs.com/ztguang/p/12648419.html
Copyright © 2011-2022 走看看