SWI-PROLOG:エラー:IS / 2:引数は十分にインスタンス化されていません

StackOverflow https://stackoverflow.com/questions/3299445

  •  18-09-2020
  •  | 
  •  

質問

間隔内にある滑らかな数字の数を印刷するプログラムを作成しようとしています。コードの一部はここにあります:

countsmooth(_, [], _, _, Count) :-
   Count is 0.
countsmooth(X, [H|T], Min, Max, Count) :-
   (  Y is X*H,
      Y =< Max 
   -> (  Y >= Min 
      -> NewX is X*H,
         countsmooth(X, T, Min, Max, NCount1),
         countsmooth(NewX, [H|T], Min, Max, NCount2),
         Count is (1+NCount1+NCount2)

      ;  NewX is X*H,
         countsmooth(X, T, Min, Max, NCount1),
         countsmooth(NewX, [H|T], Min, Max, NCount2),
         Count is (NCount1+NCount2)
      )
   ;  Count is 0
   ).

smooth(B, I, J, Smooths) :- 
   (  B =< 1 
   -> Smooths is 0
   ;  I =:= 1 
   -> primes(B, FilPrimes),
      countsmooth(1, Filprimes, I, J, Count),
      Smooths is (1+Count)
   ;  primes(B, FilPrimes),
      countsmooth(1, Filprimes, I, J, Count),
      Smooths is Count
   ).
.

primesから2へのすべての素数を作成する述語Bもあります。

例えば、B = 11の場合は、FilPrimes = [2,3,5,7,11]

SWI-PROLOGのcountsmoothを呼び出すとき ?- countsmooth(1, [2,3,5,7,11,13,17,19,23], 1, 100000000, Count)。 結果が得られます。

しかし、smoothのように?- smooth(2,100,10000,Smooths).を呼び出すとき 次のエラーが発生します。

ERROR: is/2: Arguments are not sufficiently instantiated
.

正しい解決策はありません

他のヒント

本当に申し訳ありません。私は間違っていることを見つけるために一日中を試みていて、ついに私は「ilprimes」を書いたのと同じ場所で「Filprimes」と同じ場所でそれを見ました。

私はとてもばかです!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top