Post Reply 
Books about CAS
01-31-2020, 07:52 PM
Post: #16
RE: Books about CAS
(01-31-2020 06:44 AM)Nad Wrote:  Hello!

Thanks, it's a pretty exciting project Smile

Looking through the Bignum source code I'm not sure if assembly code for the inner loops has been written for the Cortex-M family. There are generic C functions that aren't as fast - this is perhaps what the Cortex-M4 implementation mentioned above is using.


It's actually using the full blown GMP library AFAIK Smile

Quote:For this reason I may go with my original plan of writing my own mixed C/assembly routines for multiple-precision integers and rationals. Hopefully it won't be too difficult.

It won't be easy Smile You'll need to use advanced methods suich as Karatsuba multiplication and / or FFT based multiplication if you want to operate on **extremely huge** numbers Smile

Quote: I will first do addition, followed by multiplication, then GCD. Subtraction and division then follow pretty easily. I'll need to brush up on GNU syntax assembly, as the MCUXpresso IDE uses the GNU ARM toolchain.

Well, the GNU GMP library uses pairs of mpz_t integers to represent rationals, but, the numbers must be "canonicalized" so that the numerator and denominator don't share any factors and the denominator is positive Smile
You'll need to implement a GCD function first so you can prevent the integers representing the rational from becoming very large too quickly Smile

From the GMP manual :

Code:
Rational numbers are stored in objects of type mpq_t.

All rational arithmetic functions assume operands have a canonical form, and canonicalize their result. The canonical form means that the denominator and the numerator have no common factors, and that the denominator is positive. Zero has the unique representation 0/1.

Pure assignment functions do not canonicalize the assigned variable. It is the responsibility of the user to canonicalize the assigned variable before any arithmetic operations are performed on that variable.

Function: void mpq_canonicalize (mpq_t op)

    Remove any factors that are common to the numerator and denominator of op, and make the denominator positive.

Quote:But before that I need to determine the data types to use. A rational can be represented by a struct consisting of 2 multiple precision integers, which is what I think Bignum does.

Yep Smile

Quote:3) Convert result to string for display. The only way I know to do that is to subtract multiples of powers of 10, keeping count as you go, until you reach zero.

Well, one usually just uses a "modulo and divide loop" eg . :

Code:
loop:
        r = i % 10
        i = i / 10        // Integer division :)
        print r
        if (i == 0) break
        jump loop

The above algorithm is naïve though, and much faster algorithms can be used. See eg. here .

Regards,

Jonathan

Aeternitas modo est. Longa non est, paene nil.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Books about CAS - compsystems - 10-26-2019, 01:38 PM
RE: Books about CAS - Nad - 12-02-2019, 07:10 AM
RE: Books about CAS - Jonathan Busby - 01-10-2020, 09:55 PM
RE: Books about CAS - Nad - 01-12-2020, 06:26 AM
RE: Books about CAS - Jonathan Busby - 01-14-2020, 08:56 PM
RE: Books about CAS - Nad - 01-18-2020, 11:03 PM
RE: Books about CAS - Jonathan Busby - 01-19-2020, 04:38 PM
RE: Books about CAS - johanw - 05-02-2020, 09:45 PM
RE: Books about CAS - BruceH - 05-03-2020, 12:09 PM
RE: Books about CAS - Eddie W. Shore - 01-22-2020, 03:00 AM
RE: Books about CAS - Eddie W. Shore - 01-22-2020, 03:05 AM
RE: Books about CAS - Jonathan Busby - 01-23-2020, 04:29 PM
RE: Books about CAS - rprosperi - 01-23-2020, 09:51 PM
RE: Books about CAS - Nad - 01-24-2020, 12:13 AM
RE: Books about CAS - Jonathan Busby - 01-24-2020, 03:53 PM
RE: Books about CAS - Nad - 01-31-2020, 06:44 AM
RE: Books about CAS - Jonathan Busby - 01-31-2020, 06:39 PM
RE: Books about CAS - Jonathan Busby - 01-31-2020 07:52 PM
RE: Books about CAS - Nad - 02-01-2020, 05:20 AM
RE: Books about CAS - Jonathan Busby - 02-01-2020, 03:51 PM
RE: Books about CAS - Nad - 02-09-2020, 05:24 AM
RE: Books about CAS - F-73P - 05-01-2020, 02:42 AM
RE: Books about CAS - Nad - 05-06-2020, 05:08 AM
RE: Books about CAS - F-73P - 05-11-2020, 08:20 AM
RE: Books about CAS - compsystems - 05-06-2020, 05:39 PM
RE: Books about CAS - Jonathan Busby - 05-06-2020, 06:31 PM
RE: Books about CAS - Nad - 05-07-2020, 10:38 AM
RE: Books about CAS - jonmoore - 05-07-2020, 10:31 AM
RE: Books about CAS - Nad - 05-15-2020, 09:06 AM
RE: Books about CAS - John Keith - 05-15-2020, 06:13 PM
RE: Books about CAS - F-73P - 05-27-2020, 04:07 AM
RE: Books about CAS - Jonathan Busby - 05-27-2020, 07:00 PM
RE: Books about CAS - Nad - 05-17-2020, 07:12 AM
RE: Books about CAS - John Keith - 05-17-2020, 09:11 PM
RE: Books about CAS - Nad - 05-18-2020, 02:57 AM
RE: Books about CAS - F-73P - 06-03-2020, 05:14 AM



User(s) browsing this thread: 1 Guest(s)