Home Download Help Resources Extensions FAQ NetLogo Publications Contact Us Donate Models: Library Community Modeling Commons User Manuals: Web Printable Chinese Czech Farsi / Persian Japanese Spanish

NetLogo User Community Models(back to the NetLogo User Community Models)
WHAT IS IT?
This is a collection of reporters for doing calculations with arbitraryprecision integer and floatingpoint real and complex numbers. In the collection you find the following reporters which accept both STRINGS and normal NetLogo numbers as arguments. In the case of complex numbers, for each complex number, one 2element list of strings (real part and imaginary part) are passed. Results are ALWAYS passed back to the caller as STRINGS (real floatingpoint numbers) or 2element lists of strings (complex numbers).
Example: set c real_mul "1288272.827727272727" "188272727.292929299229922992292971"
or, one example for complex numbers:
int_add a b : adds two large  signed or unsigned  integer numbers
real_add a b : adds two large  unsigned or signed  floatingpoint numbers
complex_add a b: sum of two complex numbers (handed as 2element lists
real_sgn a : reports the sign of a number (1 positive, 0 zero, 1 negative)
integer? a : reports TRUE if a has no decimal point, FALSE otherwise
equal? a b : reports TRUE if a equals b, FALSE otherwise
string text times : reports a string with #text appended #times times.
power10 number times : reports the product of number and 10 raised to the
decimal_sameness a b dec_places : for #dec_places > 0, reports the number of
HOW IT WORKS
Pass arguments to the reporters mentioned above as normal NetLogo numbers or as STRINGS (for arbitrarylength and precision numbers) containing the numbers to be processed in base 10 notation.
The most elaborate routines are int_mul for the multiplication of large integers (which is used for floatingpoint numbers as well). That reporter uses the TOOMCOOK algorithm which desiplays a much better runtime behavior than multiplying with the longhand "school" method, i.e. O(n^1.485) vs. O(n^2). At the heart of the floating point division algorithm is a standard NewtonRhapson iteration. As a sufficiently close first approximation of the solution for 1/b in (a/b = a * 1/b) is crucial for this algorithm, the routines tries to find out a close guess, but it appears to be clumsy. Rewrite it with a better approach  and mail it to me! :) info@noemanetz.de
My motivation in writing these routines was my interest in fractal geometry. For producing my own fractal exploration software, I need customized routines that can handle numbers with arbitrary precision (length). Most of the programs that have been written so far for creating Mandelbrot sets, Julia sets and images of Newtoniterated roots of complex functions are not capable of handling really highprecision numbers. As a result, the user can zoom into the calculated fractal image only a few times before the builtin arithmetic becomes too "coarse" for deep detail. But realizing how slow NetLogo is when it comes to string manipulation, I have decided to only use it as a rapid prototyping environment and will rewrite the routines in a different programming language after testing of the routines.
HOW TO USE IT
Run the test suite by pressing the button on the interface tab. You may use the routines provided here as you like.
THINGS TO NOTICE
Normally, when doing iterations and checking whether the old approximated value is sufficiently close to the new one, one subtracts both, calculated XoldXnew and checks if this is less a certain threshold epsilon. With the reporter decimal_sameness, the check is made "graphically" by comparing the significant decimal places instead of a fullblown subtraction and comparison (which in itself is another comparison). If you are interested in this approach, have a look at the WHILE loop in the real_div reporter.
THINGS TO TRY
call real_mul with really large numbers. Time the result. See how slow NetLogo string handling is.
EXTENDING THE MODEL
Write reporters that draw roots (square, cubic, arbitrary).
NETLOGO FEATURES
RELATED MODELS
CREDITS AND REFERENCES

(back to the NetLogo User Community Models)