potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
618 stars 82 forks source link

Does Clingo support floating-point number? #515

Open navdeepkjohal opened 3 months ago

navdeepkjohal commented 3 months ago

Hello,

Can you please tell me if clingo supports floating -point numbers or not?

I have a fact that says "one batch has 1.5 gallons of coffee. ". I want to write it as batch_size_gallons(1.5). but clingo reads the decimal after 1 as a full stop and throws an error that says:

:3:21-22: error: syntax error, unexpected ., expecting ) or ; The google search says that floating-point numbers are not supported by Answer-set programming. I am just checking if there is any work-around this that I do not know of. Thanks Navdeep
rkaminsk commented 3 months ago

Clingo does not support floats. It is possible to use them during grounding by using its API:

#script (python)
import math
from clingo.symbol import String
def sqrt(x):
    return String(repr(math.sqrt(float(x.string))))
#end.
p(@sqrt("17.3")).

See also our list: https://sourceforge.net/p/potassco/mailman/potassco-users/thread/0d78fb1b0eef6ddd729a856c013b79d2037a8bd8.camel%40cs.uni-potsdam.de/#msg37606655

Edit: I believe there was a paper once about extending ASP with floats. Unfortunately, I don't remember the title.