home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / ANSWERS.ARC / ANS_170C.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  963 b   |  36 lines

  1. /*
  2.    Turbo Prolog 2.0, Answer to third Exercise on page 170.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5. */
  6.  
  7. Predicates
  8.   power_of_two ( integer )
  9.  
  10. Clauses
  11.  
  12.   power_of_two(10) :- !.     % stop after 2^10 is processed
  13.   power_of_two(Expon) :-
  14.       Exp1 = Expon + 1 ,
  15.       Num = exp( Exp1 * ln(2) ) ,
  16.       write("\t   ",Exp1,"\t\t   ",Num,"\n"),
  17.       power_of_two(Exp1).
  18.       
  19. GOAL
  20.   makewindow(1,2,3," Powers of Two ",0,0,25,80) ,
  21.   write("\n\tExponent\tResult\n",
  22.           "\t========\t======\n") ,
  23.   power_of_two(0), nl.
  24.               
  25.  
  26. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  27.  
  28.  *  Since Turbo Prolog does not contain a power function,    *
  29.  
  30.  *  one can be modeled with the following equation:          *
  31.  
  32.  *     M^n = exp( n * ln(M) )                                *
  33.  
  34.  *  where ln is the Logarithm to base e.                     *
  35.  
  36.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */