1

我有以下查询:

?- Remainder :: 0..8, Qoutient #:: 0..Dividened,
   Dividened #= Qoutient * 9 + Remainder, Dividened = 12.

如您所见,我有一个整数暂停Qoutient #:: 0..Dividened,并尝试清除最后的值Dividend。但是,我收到以下错误:

instantiation fault in Qoutient #:: 0 .. Dividened

那么如何解决 Eclipse CLP 中的问题呢?

4

1 回答 1

2

您可以编写Quotient#>=0, Quotient#=<Dividend,但实际上根本不需要对该变量给出任何先验界限。只需使用

?- Remainder :: 0..8, Dividend #= Quotient * 9 + Remainder, Dividend = 12.
Remainder = 3
Dividend = 12
Quotient = 1
Yes (0.00s cpu)

您可能希望将其推广到任意除数并将整个事物打包成一个辅助谓词,例如

divmod(Dividend, Divisor, Quotient, Remainder) :-
        0 #=< Remainder, Remainder #=< Divisor-1,
        Dividend #= Quotient*Divisor + Remainder.

然后你的查询变成

?- divmod(D, 9, Q, R), D = 12.
D = 12
Q = 1
R = 3
Yes (0.00s cpu)
于 2019-04-16T22:53:11.263 回答