Prolog


PART VI - Even-Odd

<< Previous  Main  Next >> 

Example #1: Even-Odd

even[X]:-num[Y]*eval[X==2*Y].
odd[X]:-num[X]*~even[X].
num[1].
num[2].
num[3].
num[4].
num[5].
num[6].

Resolution Trace for Example #1:

odd[X]  num[X]  ~even[X]  num[Y]  eval[X==2*Y] 
odd[A]        
  num[A]      
  A=1      
    ~even[1]    
      num[Y]  
      Y=1  
        eval[1==2*1]
        FALSE
      num[Y] (#2)  
      Y=2  
        eval[1==2*2] (#2)
        FALSE
      <...>  
    ~even[1] (#2)    
    FALSE    
    >>_odd[1]    
  num[A] (#2)      
  A=2      
    ~even[2]    
      num[Y]  
      Y=1  
        eval[2==2*1]
        TRUE
        >>_odd[2]
        eval[2==2*1] (#2)
        FALSE
      num[Y] (#2)  
      Y=2  
        eval[2==2*2]
        FALSE
      <...>  
    ~even[2] (#2)    
    FALSE    
    <<_odd[2]    
  <...>      
odd[A] (#2)        
FALSE        
<<_odd[1]        
>>odd[1]        
<<_odd[3]        
>>odd[3]        
<<_odd[5]        
>>odd[5]        
         

<Under Construction>

<< Previous  Main  Next >> 

Next: Primes


Questions? Comments? Send them here. Or return to deXXed.