Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34

Thread: Introducing NUMS -- an Arbitrary Precision Math Library

  1. #1
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24

    Introducing NUMS -- an Arbitrary Precision Math Library

    Hello, Everyone,

    I am happy to announce the NUMS Arbitrary Precision Math Library by Eddy Van Esch, the author of H.I.M.E., the Huge Integer Math and Encryption library. It is free for non-commercial use and can be downloaded from Devotechs.com.

    I will be offering some Thinbasic scripts based upon math problems here on these fora.

    Download and enjoy.

    Regards,
    Bob

  2. #2
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24
    On the topic "n! - very slowly," I submit a TB script that calculates n! to 100,000 digits in 61 seconds.

    ===========================================================
    ================       N  U  M  S       ===================
    ===========================================================
    Arbitrary precision floating point and integer math library
                     Free for personal use.
                  Commercial use not allowed.
                  Please read 'NUMS_Info.txt'
                      (c) 2011 DevOTechS
    ===========================================================
    Last Modified = 09-01-2011 at 00:28:05
    Program = Factorial.tbasic
        Factorial (n)
     100000! = 456575 digits
         61,086.917 msecs.
    Done...
    Press any key to end program.
    
    Regards,
    Bob
    Attached Files Attached Files

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Bob,

    thanks for letting us know. I downloaded the package from website, run the example, but ThinBASIC seemed to have problem with line:
    DECLARE FUNCTION nu_PutString_AZ             LIB "NUMS.dll" (BYVAL azStr AS ASCIIZ * 100, BYVAL lVar AS LONG) AS LONG
    
    I modified it to:
    DECLARE FUNCTION nu_PutString_AZ             LIB "NUMS.dll" (BYVAL azStr AS ASCIIZ, BYVAL lVar AS LONG) AS LONG
    
    And then the example ran OK. I will talk to Eros why this is happening.


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    I get an error when I try to run it.

    Main script name: C:\Users\root\Desktop\NUMS\Factorial.tbasic

    Included script: C:\Users\root\Desktop\NUMS\NUMS.inc

    Error code: 20

    Error Description: Missing Close Parens ')'. Expected a ')' but found something else.

    Line number: 102

    Line code: DECLARE FUNCTION NU_PUTSTRING_AZ LIB "NUMS.dll"(BYVAL AZSTR AS ASCIIZ * 100, BYVAL LVAR AS LONG) AS LONG

    Token found: AZSTR

    My guess is that thinBasic does not like the, "* 100".

    That is the only difference I can detect in line 102.

    -----------------------------------------------------------------------------------------------------------------------------

    On my computer, and using Racket, it takes 130 seconds.

    But, I get 456574 digits.

    And, Mathematica agrees (next two lines).

    2.8242294079603478742934215780245355184774949260912... × 10^456573

    http://www.wolframalpha.com/input/?i=100000!

    Dan

    ' code ----------------------------------------------------------------------------------------------------------------------
    
    #lang racket
    
    (define fact-value 0)
    
    (define (num-digits n)
      (add1 (order-of-magnitude n)))
    
    (define (time-function f n)
      (let ((t1 (current-milliseconds)))
        (set! fact-value (f n))
        (let ((t2 (current-milliseconds)))
          (let ((tt (/ (- t2 t1) 1000.0)))
            tt))))
    
    (define (fact n)
      (define prod 1)
      (define (loop m)
        (cond
          ((> m n) prod)
          (else
           (set! prod (* prod m))
           (loop (+ m 1)))))
      (loop 1))
    
    ' REPL interactions ---------------------------------------------------------------------------------------------------------
    
    Welcome to DrRacket, version 5.1 [3m].
    Language: racket.
    > (time-function fact 100000)
    130.026
    > (num-digits fact-value)
    456574
    >
    
    Last edited by danbaron; 01-09-2011 at 09:15.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  5. #5
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Like Petr said, I took out the, "* 100", and it runs OK.

    On my computer, it took 103 seconds.

    (I didn't know how to use a DLL with thinBasic, I have to admit, NUMS works nice.)

    Dan

    ================       N  U  M  S       ===================
    ===========================================================
    
    Arbitrary precision floating point and integer math library
                     Free for personal use.
                  Commercial use not allowed.
                  Please read 'NUMS_EULA.txt'
                      (C) 2011 DevOTechS
                       www.devotechs.com
    
    ===========================================================
    Last Modified = 09-01-2011 at 00:00:23
    
    Program = Factorial.tbasic
    
        Factorial (n)
    
     100000! = 456575 digits
    
        103,081.056 msecs.
    
    Done...
    
    Press any key to end program.
    
    Last edited by danbaron; 01-09-2011 at 09:18.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  6. #6
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    I tried finding 100000! using Python.

    On my machine it took 54 seconds.

    Somehow, it seems that Python and Ruby are very hard to beat.

    (But, unlike NUMS, I don't think they can be called from thinBasic.)

    Dan

    ' code --------------------------------------------------------------------------------------
    
    # fact.py
    
    import time
    
    def fact(n):
      fact = 1
      for i in range(1,n+1):
          fact *= i
      return fact
    
    t1 = time.clock()
    f = fact(100000)
    t2 = time.clock()
    print(t2-t1)
    
    ' output ------------------------------------------------------------------------------------
    
    C:\Users\root\Desktop\py>python
    Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.exit()
    
    C:\Users\root\Desktop\py>python fact.py
    54.26329864
    
    C:\Users\root\Desktop\py>
    
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  7. #7
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24
    Quote Originally Posted by Petr Schreiber View Post
    Hi Bob,

    thanks for letting us know. I downloaded the package from website, run the example, but ThinBASIC seemed to have problem with line:
    DECLARE FUNCTION nu_PutString_AZ             LIB "NUMS.dll" (BYVAL azStr AS ASCIIZ * 100, BYVAL lVar AS LONG) AS LONG
    
    I modified it to:
    DECLARE FUNCTION nu_PutString_AZ             LIB "NUMS.dll" (BYVAL azStr AS ASCIIZ, BYVAL lVar AS LONG) AS LONG
    
    And then the example ran OK. I will talk to Eros why this is happening.


    Thanks,
    Petr
    I changed the declare to:
    Declare Function nu_PutString_AZ             Lib "NUMS.dll" Alias "nu_PutString_AZ" (ByVal azStr As Asciiz * 100, ByVal lVar As Long) As Long
    

  8. #8
    Quote Originally Posted by danbaron View Post

    But, I get 456574 digits.
    And, Mathematica agrees
    That's correct Dan. Bob used the NUMS function nu_ConvertDT (to convert from one datatype to another) to convert from floating point to ascii string.
    nu_ConvertDT adds a leading space in case of a positive number or a minus sign in case of a negative number, as is custom in the various BASIC languages.
    That explains the extra digit count.

    Kind regards
    Eddy

  9. #9
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    I tried finding 100000! using Ruby.

    On my machine it took 47 seconds.

    (But, I don't think anyone will be calling Ruby from thinBasic.)

    Dan

    ' code --------------------------------------------------------------------------------------
    
    # fact.rb
    
    def fact(n)
    fact = 1
    i=1
    while i<=n
    fact = fact*i
    i = i+1
    end
    fact
    end
    
    t1 = Time.now.to_f
    fact(100000)
    t2 = Time.now.to_f
    puts t2-t1
    
    ' output ------------------------------------------------------------------------------------
    
    C:\Users\root\Desktop\Ruby\test>ruby -v
    ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
    
    C:\Users\root\Desktop\Ruby\test>ruby fact.rb
    47.15880012512207
    
    C:\Users\root\Desktop\Ruby\test>
    
    Last edited by danbaron; 02-09-2011 at 07:55.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  10. #10
    this is a usefull thread as always with REDEBOLT and Dan posts.
    using the example posted here about using GMP with Thinbasic it took 125871 microseconds for 100000! the example in that link needs a correction for the size of the output buffer :
    '---Used as output buffer
    Global outb As Asciiz * 500000


    and instead of directing the factorial output to RichText box which needs more time to display, direct the output to text file "test.txt" .
    attached the re edited calc_v0_4.tbasic‎ bundled with gmp dll
    Jack have posted a more gmp declarations before the old example Calc_v0_3.tbasic‎ so we can add more functions in the future. the rarely used code are used through space and time this is why the calc... example downloaded 91 times from 2008, possibly by people who was searching google for gmp dlls. this is why we must not disappointed if a file have not downloaded and used immediately, the possible users are there standing over time line and will use your code someday.
    Attached Files Attached Files
    Last edited by zak; 02-09-2011 at 10:07.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. GMP library: free library for arbitrary precision arithmetic
    By ErosOlmi in forum thinBasic vaporware
    Replies: 24
    Last Post: 03-01-2009, 01:01

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •