SWI-Prolog: ERROR: is/2: Arguments nicht ausreichend instanziiert

Ich versuche, erstellen Sie ein Programm, das druckt, wie viele glatte zahlen sind in einem Intervall. Ein Teil der code ist hier:

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
   ).

Es ist auch ein Prädikat primes schafft, dass alle Primzahlen von 2 zu B.

Zum Beispiel, wenn B = 11, dann FilPrimes = [2,3,5,7,11].

Wenn ich rufe countsmooth im SWI-Prolog-wie
?- countsmooth(1, [2,3,5,7,11,13,17,19,23], 1, 100000000, Count).
Ich bekomme ein Ergebnis.

Aber wenn ich rufe smooth wie ?- smooth(2,100,10000,Smooths).
Ich bekomme die folgende Fehlermeldung:

ERROR: is/2: Arguments are not sufficiently instantiated

InformationsquelleAutor Alex | 2010-07-21

Schreibe einen Kommentar