; Scientific Notation in Any Base ; written by Teresa Carrigan, 2004 globals [ start-x praise digits myDigits save-base step number-of-digits to-left to-right expon start-num] breeds [ digit cross power byBase] digit-own [ digit-value point?] patches-own [ name ] ; runs setup when program is first loaded to startup setup end ; makes the correct number of digits, and the red arrow ; initializes variables to setup locals [ here-x n move-over here-num] ca set praise [ "You got it!" "Right!" "Correct" "Awesome!" "Perfect!" ] set digits [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ] set save-base base set myDigits [] set n 0 repeat base [ set myDigits lput (item n digits ) myDigits set n (n + 1) ] set start-num "" set number-of-digits 5 repeat number-of-digits [ set start-num (word start-num (random-one-of myDigits)) ] set move-over -5 + random 15 if move-over < 0 [ repeat abs move-over [ set start-num (word "0" start-num) ] set move-over 0 ] if move-over >= number-of-digits [ repeat (move-over - number-of-digits + 1) [ set start-num (word start-num "0") ] ] set number-of-digits length start-num set start-num add-point start-num move-over set here-num start-num ; create header bar at top ask patches with [ pycor > 3 ] [ set pcolor blue ] ask patch-at 6 5 [ set plabel "Scientific Notation in base " + base set plabel-color white set name -1 ] ask patch-at 6 4 [ set plabel "Unnormalized number = " + start-num set plabel-color white set name -2 ] set here-x -1 * (length start-num) / 2 set here-x here-x - 3 set n length start-num repeat n [ cct-digit 1 [ set shape "circle" set color black set label-color white set label first here-num ifelse label = "." [ set point? true set size .05 ] [ set point? false ] setxy here-x 0 ] set here-num but-first here-num set here-x here-x + 1 ] set here-x here-x + 1 cct-cross 1 [ set shape "cross" set size 0.5 set color white setxy here-x -.15 ] set here-x here-x + 1 cct-byBase 1 [ set shape "box" set color black set label-color white set label base setxy here-x 0 ] set here-x here-x + .5 cct-power 1 [ set shape "box" set color black set label-color white set label 0 setxy here-x 0.5 ] set here-x here-x + 3 cct-byBase 1 [ set shape "box" set color black set label-color white set label "base " + base setxy here-x 0 ] ; create explanation bar at the bottom ask patches with [ pycor < -2 ] [ set pcolor blue ] ask patch-at 6 -3 [ set plabel "" set plabel-color white set name 1 ] ask patch-at 6 -4 [ set plabel "" set name 2 ] ask patch-at 6 -5 [ set plabel "" set name 3 ] set step 1 end to explain [ which what ] ask patches with [ name = which ] [ set plabel what ] end to move-point-right ask digit with [ point? = true ] [ set heading 180 fd 1 wait slow-motion set heading 90 fd 1 wait slow-motion set heading 0 fd 1 wait slow-motion ask other-digit-here [ set heading -90 fd 1 ] ask power [ set label (label - 1) ] ] end to move-point-left ask digit with [ point? = true ] [ set heading 180 fd 1 wait slow-motion set heading -90 fd 1.5 wait slow-motion set heading 0 fd 1 wait slow-motion set heading 90 fd .5 ask other-digit-here [ set heading 90 fd 1 ] ask power [ set label (label + 1) ] ] end to step1 locals [ point-pos howmany ] explain 1 "Move radix point to left until there is " explain 2 "only one digit to left of the radix point." explain 3 "Exponent increases for each position moved." set point-pos xcor-of random-one-of digit with [ point? = true ] set howmany count digit with [ xcor < point-pos ] while [ howmany > 1 ] [ move-point-left wait slow-motion set point-pos xcor-of random-one-of digit with [ point? = true ] set howmany count digit with [ xcor < point-pos ] ] set step (step + 1) end to step2 locals [ point-pos move?] explain 1 "Drop leading zeroes, moving radix point" explain 2 "to the right for each zero dropped." explain 3 "Exponent decreases for each position moved." set move? false ask digit with [ point? = false ] [ set label remove " " label set label label + " " ] ask min-one-of digit [ xcor ] [ if label = "0 " [ set move? true die ] ] while [ move? = true ] [ move-point-right set move? false ask min-one-of digit [ xcor ] [ if label = "0 " [ set move? true die ] ] ] set step (step + 1) end to step3 locals [ doneyet? point-pos here-x ] explain 1 "Drop trailing zeroes, except possibly for a" explain 2 "single zero to the right of the radix point." explain 3 "Exponent does not change." set doneyet? false set point-pos xcor-of random-one-of digit with [ point? = true ] ask digit [ set label remove " " label ] while [ not doneyet? ] [ ask max-one-of digit [ xcor ] [ ifelse (label = "0") and ( xcor > (point-pos + 1)) [ die ] [ set doneyet? true ] ] wait slow-motion ] if count digit < 3 [ ; add a trailing zero explain 3 "Adding a zero after the radix point." ask digit [ set heading -90 fd 2 ] ask max-one-of digit [ xcor ] [ set here-x xcor ] cct-digit 1 [ set shape "circle" set color black set label-color white set label "0" set point? false setxy (here-x + 1) 0 ] wait slow-motion ] if count digit < 3 [ ; add a leading zero explain 3 "Zero - adjust exponent." ask power [ set label 0 ] ask min-one-of digit [ xcor ] [ set here-x xcor ] cct-digit 1 [ set shape "circle" set color black set label-color white set label "0" set point? false setxy (here-x - 1) 0 ] wait slow-motion ] set step (step + 1) end to step4 locals [ cross-pos digit-pos howmuch] explain 1 "Now in normalized scientific notation." explain 2 "" explain 3 "" set cross-pos xcor-of random-one-of cross set digit-pos xcor-of max-one-of digit [ xcor ] set howmuch (cross-pos - digit-pos - 1.5) if howmuch > 0 [ ask digit [ set heading 90 repeat howmuch [ fd 1 wait slow-motion ] ] ] ask patch-at 2 -1 [ set plabel "Answer" set plabel-color cyan ] ask digit [ set label-color cyan ] ask cross [ set color cyan ] ask power [ set label-color cyan ] ask byBase [ set label-color cyan ] set step (step + 1) end ; position the radix point to-report add-point [ here-num move-over ] locals [ before after result ] if move-over = 0 [ set here-num "0" + here-num set move-over 1 ] if move-over >= length here-num [ set here-num here-num + "0" ] set before substring here-num 0 move-over set after substring here-num move-over length here-num set result (word before "." after) report result end ; randomize settings and start over to setup-random set number-of-digits 2 + (random 4) set base 2 + (random 15) setup end ; do whatever step comes next, then wait until user wants to continue to one-step locals [ what-step ] set what-step (word "step" step) if step < 5 [ run what-step ] wait slow-motion end ; show all remaining steps to go ifelse step < 5 [ one-step wait slow-motion ] [ stop ] end to show-again locals [ here-x n move-over ] set n 0 ask turtles [ die ] ask patches [ set plabel "" ] explain -1 "Scientific Notation in base " + base explain -2 "Unnormalized number = " + start-num set here-x -1 * (length start-num) / 2 set here-x here-x - 3 set n length start-num repeat n [ cct-digit 1 [ set shape "circle" set color black set label-color white set label first start-num ifelse label = "." [ set point? true set size .05 ] [ set point? false ] setxy here-x 0 ] set start-num but-first start-num set here-x here-x + 1 ] set here-x here-x + 1 cct-cross 1 [ set shape "cross" set size 0.5 set color white setxy here-x -.15 ] set here-x here-x + 1 cct-byBase 1 [ set shape "box" set color black set label-color white set label base setxy here-x 0 ] set here-x here-x + .5 cct-power 1 [ set shape "box" set color black set label-color white set label 0 setxy here-x 0.5 ] set here-x here-x + 3 cct-byBase 1 [ set shape "box" set color black set label-color white set label "base " + base setxy here-x 0 ] explain 1 "" explain 2 "" explain 3 "" set step 1 end ; read the digits, storing it as a string to-report get-number locals [ target n num before after k] set target "" set n (xcor-of max-one-of digit [xcor]) repeat number-of-digits [ set num label-of random-one-of digit with [ xcor = n ] set target (word num target) set n (n - 2) ] set target remove " " target set k to-left set before substring target 0 k set after substring target (k ) (length target) set target (word before "." after) report target end to-report add-commas-fraction [number] locals [ before after k] set k position "." number set before substring number 0 k set after substring number (k + 1) (length number) set after reverse after set before add-commas before set after add-commas after set after reverse after report (word before "." after) end ; add commas every three digits, so the user won't make copy errors to-report add-commas [ number ] locals [ save k ] if member? "." number [ report add-commas-fraction number ] set save "" set k 0 while [ (length number) > 0 ] [ set save (word last number save ) set number butlast number set k (k + 1) if (k = 3) and (length number > 0) [ set save (word "," save ) set k 0 ] ] set number save report number end ; *** NetLogo Model Copyright Notice *** ; ; Copyright 2004 by Teresa W. Carrigan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Teresa W. Carrigan. ; Contact Teresa W. Carrigan for appropriate licenses for redistribution ; for profit. ; ; To refer to this model in academic publications, please use: ; Carrigan, T. (2004). Scientific Notation in Any Base model. ; Blackburn College, Carlinville, IL. ; ; In other publications, please use: ; Copyright 2004 by Teresa W. Carrigan. All rights reserved. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 3 10 488 316 9 5 25.0 1 18 1 1 1 CC-WINDOW 497 16 780 390 Command Center BUTTON 5 321 88 354 NIL setup NIL 1 T OBSERVER T SLIDER 300 318 488 351 slow-motion slow-motion 0 1 0.5 0.1 1 seconds SLIDER 299 351 488 384 base base 2 16 2 1 1 NIL BUTTON 5 355 87 388 step one-step NIL 1 T OBSERVER T BUTTON 89 320 178 353 random setup-random NIL 1 T OBSERVER T BUTTON 89 354 178 387 go go T 1 T OBSERVER T BUTTON 179 322 277 355 NIL show-again NIL 1 T OBSERVER T @#$#@#$#@ WHAT IS IT? ----------- This model demonstrates scientific notation in any base from two to sixteen. HOW IT WORKS ------------ First the radix point (decimal point in base ten) moves to the left until a single digit is to its left. Then any leading zeroes are dropped, moving the radix point to the right. Finally any trailing zeroes are dropped. Each time the radix point moves to the left, the exponent increases. Each time the radix point moves to the right, the exponent decreases. HOW TO USE IT ------------- If you want examples from a specific base: Use the base slider to set the base. Now press the setup button. This will generate a random number in that base. If you do not care which base is used, click the random button to generate an arbitrary base and number. The slow-motion slider is an easy way to adjust the speed of the display. Set it to zero if you want to show the final result as quickly as possible. 0.5 is a good setting for most purposes. The step button demonstrates the next step in converting to scientific notation, and then stops so you can take notes. This is useful when you are first learning the method. The go button does each remaining step, at a speed determined by the slow-motion slider. This is useful when you do not need to take notes between each step. The show-again button starts the exact problem from the beginning. You may then click either the step button or the go button to see the same demonstration. THINGS TO NOTICE ---------------- Every time the radix point moves a space to the left, the exponent increases by one. Every time the radix point moves a space to the right, the exponent decreases by one. The final answer always has exactly one digit to the left of the radix point, and at least one digit to the right of the radix point. THINGS TO TRY ------------- Set slow-motion to 0.5, click random, and then click go. Set the base slider to a problem type you want to drill, then click setup. Attempt one step at a time on paper, and then click the step button to check that you did that step correctly. EXTENDING THE MODEL ------------------- Allow the user to input a starting digit pattern. Modify the model so that some of the time the starting digit pattern already has an exponent. NETLOGO FEATURES ---------------- Extensive use is made of "other-BREED-here", "min-one-of" and "max-one-of". RELATED MODELS -------------- IEEE 754 Single Precision CREDITS AND REFERENCES ---------------------- This model was written by Teresa W. Carrigan, 2004. Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed: a) this copyright notice is included. b) this model will not be redistributed for profit without permission from Teresa W. Carrigan. Contact Teresa W. Carrigan for appropriate licenses for redistribution for profit. To refer to this model in academic publications, please use: Carrigan, T. (2004). Scientific Notation in Any Base model. Blackburn College, Carlinville, IL. In other publications, please use: Copyright 2004 by Teresa W. Carrigan. All rights reserved. FOR MORE INFORMATION -------------------- For more information on scientific notation, see one of the following textbooks: [1] Bronson, G. "Java for Engineers and Scientists", First Edition, Thomson/BrooksCole, page 52. [2] Warford, J. "Computer Systems", Second Edition, Jones and Bartlett, pages 112-113. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 circle false 0 Circle -7566196 true true 35 35 230 cross false 0 Polygon -7566196 true true 270 0 1 269 30 298 299 29 270 0 Polygon -7566196 true true 0 29 270 297 299 269 31 0 0 29 point false 0 Circle -7566196 true true 35 35 230 Circle -16777216 true false 111 114 75 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 @#$#@#$#@ NetLogo 2.0.1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@