2008 1 2008.10.10 1
( 2 ) ( ) ( ) 1 2 1.5 3 2
( ) 50:50 Ruby ( ) Ruby http://www.ruby-lang.org/ja/ Windows Windows 3
Web Web http://lecture.ecc.u-tokyo.ac.jp/~kuno/is08/ / ( / ) / @@@ ( 3 ) @@@ :!! ( ) @@@ 4
Web (Q&A) ( ) http://www.sodan.ecc.u-tokyo.ac.jp/cgi-bin/qbbs/view.cgi http://www.sodan.ecc.u-tokyo.ac.jp/cgi-bin/sbbs/view.cgi 5
: Ruby 6
/ 2 / 2 7
(analog quantity) (digital quantity) (analog representation) (digital representation) 8
( 1 0.1Kg ) 13.2Kg 1: 9
( ) 10
2 Kg 000.00Kg 999.99Kg 100,000 (1t ) 2 0/1 1 2 1 : 12 0 1 1 (bit) 2 1 (binary digit) 2 1 11
1 / 2 00 01 10 11 1 2 N 2 N ( ) / 12
(model) ( ) / ( )? 10cm 8cm 10 8 = 40(cm 2 ) 2 6cm 5cm 6 5 2 = 15(cm 2 ) : 13
(procedure) (data) (program) 10 8 3 4 3 6 5 4 (abstraction) 14
1 3 ( ) 10cm 8cm 15
( ) (algorithm) 5 1 2 3 6 5 6 ( ) 16
(pseudocode) (code) : 7 triarea: w h s w h 2 s 7 ( ) ( ) 17
/ : s w h 2 (assignment) (expression) 8 (variable ) w h 2 s (action) s = w h 2 h = 2s w = 8 (mathematical expression) 18
/ (main storage) (memory) (procedural computational model) (imperative language) (procedural language) 19
(programming language) (natural language ) Ruby 20
Ruby Ruby irb (irb command) 9 Ruby (method) 10 : def triarea(w, h) end s = (w * h) / 2.0 return s 9 Ruby 1 10 (subroutine) procedure ( ) 21
Ruby 1. def end 1 2. (parameter) 11 3. (statement) 12 1 ; s = (w * h) / 2.0; retu 1 4. 1 5. return (return statement) return 11 12 22
Ruby s return : def triarea(w, h) end return (w * h) / 2.0 ( ) 23
! sample1.rb Ruby.rb? Mac OS TextEdit Finder 24
! irb Ruby ( % ): % irb irb(main):001:0> irb > irb (prompt ) Ruby 25
! main ( ) (nesting ) 1 1 irb> load( ) sample1.rb (string) "" : 13 irb> load sample1.rb => true irb> true triarea load 13 Ruby irb 26
! 3 4? irb irb load load triarea : irb> triarea 8, 5 => 20.0 irb> triarea 7, 3 => 10.5 irb> irb quit : irb> quite % 1 27
! 1 irb 2 2.0 2 14 3 a. 2 ( ) b. % (reminder) c. d. x x 10 x 0.1 e. x x 15 f. 14 1 (def... end) 15 x (square root) Math.sqrt(x) 28
! e f irb puts( ) ( ) printf(" ",,, ) (format) %.Ng N x y 20 : printf("%.20g %.20g\n", x, y) 29
/ / (numerical value) (Arabic numerals 0 9 ) (positional notation) ( (Chinese numerals)( ) (Roman numerals)(i II III IV IX X XI XII ) ) 0 9 30
(decimal representation) (decimal system) 0 9 10 1 120 12 : 1 10 2 + 2 10 1 + 0 10 0 1 10 1 + 2 10 0 ( ) 10 0 = 1 10 1 = 10 2 = 100 0 9 10 (radix) 10 ( ) ( 10 ) 0 1 2 3 1 3 120 15 : 16 120 (3) = 1 3 2 + 2 3 1 + 0 3 0 = 15 (10) 16 31
(binary representation) (binary system) / / 2 / (binary numbers)/ (decimal numbers) p p (p-adic number) 0 1 2 1 2 1010 (2) 10 : 1 2 3 + 0 2 2 + 1 2 1 + 0 2 0 = 8 (10) + 2 (10) = 10 (10) 32
N 0 2 N 1 ( ) (unsigned binary representation) 1 (sign bit) (two s complement representation) ( 1) 3 2 3 0 7 4 3 7 111 6 110 5 101 4 100 3 011 011 2 010 010 1 001 001 0 000 000-1 111-2 110-3 101-4 100 2: 3 33
( ) 2 + 3 = 1 110 + 011 = (1)001 (negation 1 ) 0/1 1 3 011 0/1 100 1 101 3 101 010 011 3 2 (overflow) 34
2 0 1 ( ) (C C++ Java ) 17 Ruby Ruby Ruby 17 32 2 35
4 Ruby (time mesurement) : def bench(count, &block) end t1 = Process.times.utime count.times do yield end t2 = Process.times.utime return t2-t1 bench (1) CPU (2) (3) CPU (4)2 ( CPU ) (load ) do... end (block ) : 18 irb> bench 100000 do add(100000000, 1) end => 0.125 CPU 18 36
(integral number) (real number) 2.0 2 2.0 2 2 2 / 1 2 37
? 10 8 4 :. (fixed point) 30,000,000 0.0000001 38
3 10 8 1 10 6 1 (exponent ) (mantissa ) (floating point) 10 8 6 2 9.99999 10 99 0 0.00001 10 99 39
2 2 1 52 ( )11 64 ( IEEE754 ) (rouding ) (roundoff error) 40
2 ( ) (loss of information) ( ) 3 1.00000 2.00000 10 4 10-2 1.00000 0.000002 10 4 10 4 1.00000 10 4 3: 41
0 (cancellation) ( 0 0 ) (infinity ) (NaN Not a Number) 0 +0 0 4 10 8 10 10 8 10 8 10 8 8 10 8 10 10 8 10 4 4: 42
5 Ruby 19 6 NaN 0 Ruby 19 printf 43
1A 3 ( 1 ) kuno@mail.ecc.u-tokyo.ac.jp 1. Subject: ASCII( ) Report 1A ( ) 2. 3. 3 1 ( ) & ( ) 4. ( ) Q1.? 2? Q2. Ruby? Q3. 44
1B 3 ( ) ( 1A ) 4 6 2 4 6 1 1. Subject: Report 1B 2. 3. 1 4. 5. 1 6. 7. Q1.? Q2.? Q3. 45
! ECC ( ECC ) ( ) ( ) ( ) ( ) 4 / / 46
( :? ) ( ) Subject: ^_^; Web PDF? 47