mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
1.97k stars 115 forks source link

Conjunction of 32665 predicates #532

Open ghost opened 4 years ago

ghost commented 4 years ago

With this program, a prolog code is generated with 32665 predicates but the conjunction fails, the definition of a and pasting the body of a in toplevel fails. There error is:

$ python main.py > predicates.pl
$ scryer-prolog predicates.pl

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1]    1253364 abort (core dumped)  scryer-prolog predicates.pl
UWN commented 2 years ago

Could you put your program here into this issue? The pastebin no longer works

Skgland commented 2 years ago

The wayback machine has the site archived while it was still available https://web.archive.org/web/20200530183759/https://pastebin.com/FrRUahFE

```python # -*- coding: utf-8 -*- # Source: https://stackoverflow.com/a/1119769 BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" def encode(num, alphabet=BASE62): """Encode a positive number in Base X Arguments: - `num`: The number to encode - `alphabet`: The alphabet to use for encoding """ if num == 0: return alphabet[0] arr = [] base = len(alphabet) while num: num, rem = divmod(num, base) arr.append(alphabet[rem]) arr.reverse() return ''.join(arr) def decode(string, alphabet=BASE62): """Decode a Base X encoded string into the number Arguments: - `string`: The encoded string - `alphabet`: The alphabet to use for encoding """ base = len(alphabet) strlen = len(string) num = 0 idx = 0 for char in string: power = (strlen - (idx + 1)) num += alphabet.index(char) * (base ** power) idx += 1 return num if __name__ == '__main__': n = 2 ** 14 + 2 ** 13 + 2 ** 12 + 2 ** 11 + 2 ** 10 + 2 ** 9 + 2 ** 8 + 2 ** 7 + 2 ** 4 + 2 ** 3 + 1 for i in range(n): print('a' + encode(i) + '.') print('a :- a0', end='') for i in range(1, n): print(', a' + encode(i), end='') print('.') ```