Search code examples
randomprologinfinity

How to express infinity in Prolog?


I am trying to use random/3

random(+L:int, +U:int, -R:int)

Is there any thing that can be used for representing infinity?

For Example:

random(0, Infinity, Random_Number).

Is it possible to achieve this with random? Or is there any other simple alternative?

P.S. I have made clpfd programs where I have used sup ( Supremum ), but I am not working with clpfd.


Solution

  • What an amusing discussion in the comments. My underdeveloped intuition for infinite numbers and math tells me:

    There is a finite number of integers that can be represented on a physical computer using a consistent representation. So there will be an infinity of other integers that cannot be represented. So, if you randomly pick any number, the probability that you can represent it on your machine is 0. You might as well define:

    random_between(0, infinite, infinite).
    

    Transfinite numbers might be one place to start reading, but who am I to say. You need a mathematician for that kind of questions, not a programming pedestrian.

    Maybe you should ask at https://math.stackexchange.com/?


    To your question: you can represent the concept of infinity with a symbol, for example the atom infinite. Then you need to decide how you treat that concept in your algebra, and provide rules for it. The random_between/3 above is just one example. For inspiration, check out how floating point numbers handle infinity.