【问题标题】:Arguments are not sufficiently instantiated in prolog在 prolog 中没有充分实例化参数
【发布时间】:2012-10-10 14:51:54
【问题描述】:

我正在尝试运行此代码,但每当我使用此查询时都会收到此错误:gp174(P, S). ERROR: >=/2: Arguments are not sufficiently instantiated.

这是我的代码:

call_option(B,S,C,E,P) :- 
    0 =< S, 
    S =< E / 100, 
    P = -C * B.

call_option(B,S,C,E,P) :- 
    S >= E / 100, 
    P = (100 * S - E - C) * B.

gp173(P) :- 
    call_option(1, 7, 200, 300, P).

% butterfly strike p174.
butterfly(S, H) :- 
    H = P1 + 2*P2 + P3,
    Buy = 1, Sell = -1,
        call_option(Buy, S, 100, 500, P1),
        call_option(Sell, S, 200, 300, P2),
        call_option(Buy, S, 400, 100, P3).

% goal for butterfly strike

gp174(P,S) :- 
    P >= 0, 
    butterfly(S,P).

我该怎么办?
我应该在哪里加载我的 clpr 库?

【问题讨论】:

  • 您的程序不是 CLP(R)。说 :- use_module(library(clpr)). 并将所有算术运算放入 {}。因此{H = P1+2*P2+P3}.
  • @false 是的,谢谢,太好了。接下来,标签维基... :)

标签: error-handling prolog clpr instantiation-error


【解决方案1】:

我尝试使用documented library进行修改:

:- [library(clpr)].

call_option(B,S,C,E,P) :-
    {0 =< S},
    {S =< E / 100},
    {P = -C * B}.

call_option(B,S,C,E,P) :-
    {S >= E / 100},
    {P = (100 * S - E - C) * B}.

gp173(P) :-
    call_option(1, 7, 200, 300, P).

% butterfly strike p174.
butterfly(S, H) :-
    {H = P1 + 2*P2 + P3,
    Buy = 1, Sell = -1},
        call_option(Buy, S, 100, 500, P1),
        call_option(Sell, S, 200, 300, P2),
        call_option(Buy, S, 400, 100, P3).

% goal for butterfly strike

gp174(P,S) :-
    {P >= 0},
    butterfly(S,P).

结果如下:

?- gp174(P,S).
{S=2.0+0.01*P, P=<100.0, _G56405= -300.0+P, P>=0.0} ;
{S=4.0-0.01*P, P=<100.0, _G59475= -100.0-P, _G59488=100.0+P, P>=0.0} ;
false.

HTH

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多