0

Why prolog is so fast and accurate in numerical computation like this one

factorial(X, N) :- N = 0, X is 1;
                   N > 0, N1 is N - 1, factorial(X1, N1), X is X1 * N.

I entered factorial(X, 10000). and the answer was so accurate and fast, which is too long number. so how prolog is capable to do such thing?, what is the data structure of the numbers in it? and how to implement that in languages like C, C++, C#, and Java?

false
  • 10,264
  • 13
  • 101
  • 209

1 Answers1

3

If your question is about "big numbers", an appropriate "big number" library will be used.

For example, SWI-Prolog uses "GNU Multiprecision Library":

...although it doesn't provide "decimal numbers" (doesn't anybody want to compute monetary amounts in Prolog?)

OTOH it does provide non-integer rational numbers:

You would proceed similarly in C or C++.

For Java, use the BigInteger and BigDecimal implementations, which are standard. I'm sure the same exists in C#.

David Tonhofer
  • 14,559
  • 5
  • 55
  • 51