comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@earthlink.net>
Subject: Re: Large numbers (or is Ada the choice for me?)
Date: Mon, 19 Mar 2001 20:48:40 GMT
Date: 2001-03-19T20:48:40+00:00	[thread overview]
Message-ID: <3AB67086.6A1BA83C@earthlink.net> (raw)
In-Reply-To: slrn9ai9uk.iv9.georg@apal.ii.uib.no

Hans Georg Schaathun wrote:

> I need a tool to solve large systems of linear equations, with no
> floating point operations (or any other approximations) allowed.
> Even though I am not a seasoned programmer, I think I'll have to
> write the tool myself.
> 
> My question is, will it be reasonably simple to handle large
> rational numbers with Ada?  Is there any packages for this?

Others have answered this correctly, but let me suggest a better way to
approach your original problem.  If the linear equations you are dealing
with are inequalities, then you are trying to solve an (HP-hard) integer
programming problem.  If all of the equations are equalities, then there
is a much easier approach than using abusing a linear algebra package by
instantiating it with a rational type.

Firt find the solution using 64-bit float.  Then, since you stated that
you are only interested in integer solutions, convert the float answers
to integers, and check that all the equations are satisfied.  You may be
able to do this with Ada integer types, but it shouldn't strain the
resouces of the rational arithmetic packages that come with Ada
compilers.

The only remaining problem is that you have to be able to determine
whether or not you are rejecting an otherwise valid solution because the
rounding from float to integer was inaccurate.  If you compute the
determinant of the matrix M in aM = b, and compare it to 0.5/Epsilon you
should be okay.

If your system of equations is too large, or the constants are large,
you may have to resort to the rational arithmetic approach.  An
intermediate choice is to compute the inverse of M above using LUP
decomposition of M.  M' = P'U'L', so since  aM = b, a = bP'U'L'.  P, and
P inverse are permutations of the identity matrix, so they don't add any
error, and U' and L' should be much more accurate than M' itself.  In
fact, by choosing P correctly you should minimize the determinants of U
and L... 
  
> I guess I will manage to implement the rational numbers without
> too much hardship, but I really don't feel like implementing
> arithmetics on large integers.

If you know the size of the maximum intermediates in advance, you can
use the Chinese Remainder trick.  AS long as you choose a vector of
large primes, you can use the extended GCD algorithm to find inverses. 
But always verify that your answers do solve the original equations.  If
any of your intermediate values would be out of range, you will still
get an answer, but possibly an invalid one.



  parent reply	other threads:[~2001-03-19 20:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-09 18:58 Large numbers (or is Ada the choice for me?) Hans Georg Schaathun
2001-03-09 19:35 ` Marin David Condic
2001-03-09 20:44   ` David Starner
2001-03-09 23:12     ` Marin David Condic
2001-03-10  2:56       ` David Starner
2001-03-10 11:37         ` Florian Weimer
2001-03-10  6:08       ` tmoran
2001-03-09 21:01   ` Randy Brukardt
2001-03-09 23:02   ` Robert A Duff
2001-03-09 23:28     ` Marin David Condic
2001-03-10 16:49       ` Hans Georg Schaathun
2001-03-10 11:59   ` Jeffrey Carter
2001-03-09 20:37 ` Brian Catlin
2001-03-09 21:26 ` JP Thornley
2001-03-09 21:59 ` Tucker Taft
2001-03-15  8:33   ` Modular type (Re: Large numbers) Hans Georg Schaathun
2001-03-15 10:58     ` Florian Weimer
2001-03-15 11:12       ` Hans Georg Schaathun
2001-03-15 16:24         ` Tucker Taft
2001-03-10  1:42 ` Large numbers (or is Ada the choice for me?) Keith Thompson
2001-03-19 20:48 ` Robert I. Eachus [this message]
2001-03-20  3:33   ` Brian Rogoff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox