0
log2(I,E):-
  (
    number(I)
    -> E is log(I)/log(2);
    number(E)
    -> I is 2**E
  ).

lgstar(N,A):-
  (N>1
  ->
    (
      log2(N,Nprev),
      lgstar(Nprev,Aprev),
      Aprev is A-1
    );
     A is 0
  ).

Log * is the number of times a log must be applied to a value until it is less than or equal to 1.

For Example:
log(log(log(log(3000)))) = 0.86364760439
so the log * (3000) = 4

From my understanding of the way recursion in prolog works when I get to the base case of N<1 the A should be returned and on the next level of the stack the Aprev should be inferred to be A +1 or Aprev is 1 and so on until it reaches the top of the stack where A is returned.

Query:
lgstar(3000,A)
--> Should be 4

When I reach the case that N<1 then I try to return 0 to the previous layer on the stack instead I get an arguments are not sufficiently instantiated error.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • @lurker I tried to clarify what exactly I wanted the function to do. – Crinkley Crewms Apr 25 '16 at 19:09
  • @WillBriggs I clarified exactly what I was trying to accomplish. What should I use instead of 'is' to set the A value? – Crinkley Crewms Apr 25 '16 at 19:11
  • What's wrong with `A is Aprev + 1`? – lurker Apr 25 '16 at 19:15
  • @lurker Thank you so much for all the help today. I have the biggest goofiest smile on my face right now. I get it now since Aprev would have been the returned value of 0 then the is operator can evaluate the right side of the expression. I wish you had answered the question directly so I could give you the reputation. – Crinkley Crewms Apr 25 '16 at 19:19

0 Answers0