

<!DOCTYPE html>
<!-- Server: sfs-forge-4 -->


    

















<html lang="en" class="no-js">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    <title>
  XSB / Src  (SVN)-old /
  [r7607]
  /trunk/XSB/docs/userman/tables.tex
</title>
    

<meta name="viewport" content="width=1100">


<link rel="icon" sizes="180x180" href="https://a.fsdn.com/con/img/sandiego/logo-180x180.png" type="image/png">
<link rel="icon" sizes="any" href="https://a.fsdn.com/con/img/sandiego/svg/originals/sf-icon-orange-no_sf.svg" type="image/svg+xml">
<link rel="apple-touch-icon" sizes="180x180" href="https://a.fsdn.com/con/img/sandiego/logo-180x180.png">
<link rel="mask-icon" href="https://a.fsdn.com/con/img/sandiego/svg/originals/sf-icon-orange-no_sf.svg" color="#FF6600">


<script src="https://a.fsdn.com/allura/nf/1753456284/_ew_/theme/sftheme/js/sftheme/cmp2.js"></script>






    
    
    
    
    
    
    
    
    <link rel="stylesheet" href="https://a.fsdn.com/con/css/lato.css?">


<script>
if (!window.SF) { window.SF = {}; }
SF.sandiego = false;
SF.sandiego_chrome = true;
SF.cdn = "https://a.fsdn.com/con";
SF.fpid = '8e037856-8140-4387-a5a5-957978b7a356';
SF.billboard_route = '/software/product/$slug/';
</script>
    
        <!-- ew:head_css -->

    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1753456284/_ew_/_slim/css?href=allura%2Fcss%2Fforge%2Fhilite.css%3Ballura%2Fcss%2Fforge%2Ftooltipster.css"
                >
    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1753456284/_ew_/allura/css/font-awesome.min.css"
                >
    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1753456284/_ew_/theme/sftheme/css/forge.css"
                >
    
        
<!-- /ew:head_css -->

    
    
        <!-- ew:head_js -->

    
        <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1753456284/_ew_/_slim/js?href=allura%2Fjs%2Fjquery-3.6.0.min.js%3Ballura%2Fjs%2Fjquery.cookie-1.4.1.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fshared_head.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Ftypescript%2Fcompliance.js"></script>
    
        
<!-- /ew:head_js -->

    

    
        <style type="text/css">
            /* make URL &amp; Project custom fields in support tickets not get hidden as much */
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(5),
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(6) {
  overflow: visible;
  font-size: 22px;
  width: 340px;
  line-height: 1;
  margin-bottom: 5px;
}
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(5) label, .project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(6) label {
  font-size: 14px;
}
        </style>
    
    
    <link rel="alternate" type="application/rss+xml" title="RSS" href="/p/xsb/src/feed.rss"/>
    <link rel="alternate" type="application/atom+xml" title="Atom" href="/p/xsb/src/feed.atom"/>
    <style type="text/css">
        #access_urls .btn-set {
            
            min-width: 14em;
        }
    </style>

    <style>.XwrfCqMOHwseMOEbHDDqKNwzCmsOmwTDkGsLJVw {
        display: none
    }</style>

    
    
    
        <link rel="canonical" href="https://sourceforge.net/p/xsb/src/7607/tree/trunk/XSB/docs/userman/tables.tex" />
    


    

<script>
    var data = {hem: null };
    bizx.uids.gatherAndClean(data);
</script>



<script>
    function initPiwik(){
      var _paq = window._paq = window._paq || [];
      _paq.push(['trackPageView', document.title, {
            dimension1: 'xsb',
            dimension2: 'svn'
      }]);
      _paq.push(['enableLinkTracking']);
      
          _paq.push(['enableHeartBeatTimer']);
      
      (function() {
        var u="//analytics.slashdotmedia.com/";
        _paq.push(['setTrackerUrl', u+'sf.php']);
        _paq.push(['setSiteId', 39]);
        
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'sf.js'; s.parentNode.insertBefore(g,s);
      })();
    }
    bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'sdm'}, initPiwik);
</script>






<!-- Hubspot tracking -->






 <script>
    $(function() {
        bizx.cmp.ifConsent({ purposes: 'all' , vendors: 'narrative'}, function() {
            var current_time = (new Date()).getTime();
            let imageUrl = "https://io.narrative.io/?companyId=2440&id=first_party%3A8e037856-8140-4387-a5a5-957978b7a356&id=site_name%3Asourceforge.net&id=url%3A%2Fp%2Fxsb%2Fsrc%2F7607%2Ftree%2Ftrunk%2FXSB%2Fdocs%2Fuserman%2Ftables.tex&id=pagetitle%3A%24PAGE_TITLE&id=vertical%3AOpen+Source+Software&id=product%3AXSB";
            imageUrl = imageUrl.replace(encodeURIComponent("$PAGE_TITLE"), document.title);  

            imageUrl = URL.parse(imageUrl);
            let hem = bizx.uids.getHem();
            if (hem) {
                imageUrl.searchParams.append('id', 'hem:' + hem);
            }
            imageUrl.searchParams.append('rand', current_time);

            var image = new Image();
            image.src = imageUrl.toString();
            image.style.display = "none";
            image.style.height = 0;
            image.style.width = 0;
            document.body.appendChild(image);
        });
    });
</script>



</head>

<body class="
body_class sandiego_chrome  legacy_chrome  l-allow-natural-width 
" id="forge">

    
        <!-- ew:body_top_js -->

    
        
<!-- /ew:body_top_js -->

    





<div class="off-canvas position-right" id="offCanvas" data-off-canvas>
    <!-- Menu -->
    <ul class="header-nav-menulist">
        <li class="highlight search">
            
            
                
            
            
    <form method="get" action="/directory/" class="m-search-form">
    
        <input type="text" placeholder="Search for software or solutions" autocomplete="off" name="q" >
        
        <label >
            <input type="submit" class="bt" value="">
            


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
        </label>
    </form>
        </li>
        
        <li class="highlight"><a href="/auth/">Join/Login</a></li>
        
        <li><a href="/software/">Business Software</a></li>
        <li><a href="/directory/">Open Source Software</a></li>
        <li><a  href="/software/vendors/" title="For Vendors">For Vendors</a></li>
        <li><a href="/blog/" title="Blog">Blog</a></li>
        <li><a href="/about">About</a></li>
        <li><a id="header-nav-more" data-toggle="header-nav-more header-nav-more-content" data-toggler=".toggled">More</a></li>
        <li>
            <ul id="header-nav-more-content" class="toggled" data-toggler=".toggled">
                
    

    
    
        <li><a href="/articles/">Articles</a></li>
    
    

    
 
                
                <li><a href="/create">Create</a></li>
                
                <li><a href="https://sourceforge.net/articles/category/sourceforge-podcast/">SourceForge Podcast</a></li>
                
                    <li><a href="https://sourceforge.net/p/forge/documentation/Docs%20Home/">Site Documentation</a></li>
                
                <li><a href="/user/newsletters">Subscribe to our Newsletter</a></li>
                <li><a href="/support">Support Request</a></li>
            </ul>
        </li>
    </ul>
</div>
<div class="off-canvas-content" data-off-canvas-content>

    




<script>
    SF.linkout_icon = '<svg  data-name="sf-linkout-icon" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve"><polygon class="st0" points="243.2,243.2 56.8,243.2 56.8,56.8 123,56.8 123,9 9,9 9,291 291,291 291,179.4 243.2,179 "/><polygon class="st0" points="128.5,213 155,186.5 176,165.5 206.7,196.3 235.5,132.5 248.9,102.6 290.6,9.8 291,9 290.6,9.2 197.4,51.1 169.1,63.8 103.7,93.3 137,126.5 115.9,147.5 89.5,174 "/></svg>';
</script>


<div class="l-header-nav  sandiego">

    <section class="sandiego l-header-nav-top show-for-large">
        <div class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <nav class="links">
                
                    <a href="/user/newsletters" title="Subscribe to our newsletter"><span class="newsletter-icon">


<svg  data-name="mmSF_11mail" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 42 42" enable-background="new 0 0 42 42" xml:space="preserve"><path fill="#FFFFFF" d="M0,6v30h42V6H0z M24.2,21.2c-0.8,0.8-2.3,2-3.2,2c-0.9,0-2.4-1.2-3.2-2L5.8,9.7h30.3L24.2,21.2z M13.7,21l-9.9,9.4V11.6L13.7,21z M15.7,23L15.7,23c0.5,0.5,2.9,2.9,5.3,2.9c2.4,0,4.8-2.4,5.2-2.8l0.1-0.1l9.8,9.4H5.8L15.7,23z M28.3,21l9.9-9.5v18.9L28.3,21z"/></svg></span></a>
                
                <a href="/software/vendors/" title="For Vendors">For Vendors</a>
                
                
                    <a href="/support" title="Help">Help</a>
                    <a href="/create/" title="Create">Create</a>
                

                
                <a href="/user/registration" title="Join" >Join</a>
                <a href="/auth/" title="Login">Login</a>
                
            </nav>
        </div>
    </section>

    <section class="sandiego l-header-nav-top hide-for-large">
        <div class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <div class="title-bar-right">
                <button type="button" aria-label="Toggle Main Menu" class="menu-icon" data-toggle="offCanvas"></button>
            </div>
        </div>
    </section>
    <section class="sandiego l-header-nav-bottom">
        <nav class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <div class="links">
                
    
        <div class="nav-dropdown">
            <a href="/software/">Business Software</a>
            
        </div>
        <div class="nav-dropdown">
            <a href="/directory/" title="Browse">Open Source Software</a>
            
        </div>
        <div class="nav-dropdown">
            <a href="https://sourceforge.net/articles/category/sourceforge-podcast/">SourceForge Podcast</a>
        </div>
        <div class="nav-dropdown">
            <a>Resources</a>
            <ul class="nav-dropdown-menu">
                  <li><a href="/articles/">Articles</a></li>
                  
                  <li><a href="/software/case-studies/">Case Studies</a></li>
                  
                  <li><a href="/blog/">Blog</a></li>
            </ul>
        </div>
    

                <div class="dev-menu-when-stuck">
                    Menu
                    <ul class="dev-menu-dropdown header-nav-menulist">
                        <li><a href="/support">Help</a></li>
                        <li><a href="/create">Create</a></li>
                        <li><a href="/user/registration/" title="Join" >Join</a></li>
                        <li><a href="/auth/" title="Login">Login</a></li>
                    </ul>
                </div>
                <div class="search-toggle-when-stuck">
                    <a class="search-toggle">
                        


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
                    </a>
                </div>
            </div>

            <div class="search">
                
                
    
    
        <div class="main-nav-link">
            
            
            <a href="https://www.avast.com/lp-free-av?full_trSrc=mmm_srf_dlp_008_406_a&amp;utm_medium=referral&amp;utm_source=sourceforge&amp;utm_campaign=srf_dlp_008_406_a:site_banner" rel="nofollow" target="_blank" id="main-nav-badge-link" data-label="avastjuly">
                <img src="https://a.fsdn.com/con/assets/maxnav/sourceforge/ai-protection-32-75dd98b2.png"  srcset="https://a.fsdn.com/con/assets/maxnav/sourceforge/ai-protection-75de80f6.png 2x"  alt="" id="main-nav-image"/>
            </a>
        </div>
    


                
                    
                
                
                
                
    <form method="get" action="/directory/" class="m-search-form">
    
    <div class="typeahead__container">
      <div class="typeahead__field">
        <div class="typeahead__query">
        
        <input type="text" placeholder="Search for software or solutions" autocomplete="off" name="q" >
        
        </div>
        
        <label >
            <input type="submit" class="bt" value="">
            


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
        </label>
      </div>
    </div>
    
    </form>
                
            </div>
        </nav>
        
    </section>
    
</div>
    
    
    <div class="notification-on-project-page">
    
        
    
    
    
    </div>
    
    


    <section id="page-body" class=" neighborhood-Projects project-xsb mountpoint-src 

">
        <div id="nav_menu_holder">
            
                
                    
    <div class="sandiego"> 
            
            
            
            
<section class="project-masthead"> 
    
    

    
<div class="backdrop" style="box-sizing: content-box; padding-bottom: 24px"></div>

    <div class="content">
    
        
    <nav id="breadcrumbs" class="breadcrumbs rtl">
        <ul itemscope itemtype="http://schema.org/BreadcrumbList">
            <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                <a itemprop="item" href="/"><span itemprop="name">Home</span></a>
                <meta itemprop="position" content="1"/>
            </li>
            <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                <a itemprop="item" href="/directory/"><span itemprop="name">Browse</span></a>
                <meta itemprop="position" content="2"/>
            </li>
            
            
                
                
            
            
                
            
            
                <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                    <a itemprop="item" href="/p/xsb/"><span itemprop="name">XSB</span></a>
                <meta itemprop="position" content="3"/>
                </li>
            
                <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                    <span itemprop="name">Src  (SVN)-old</span>
                <meta itemprop="position" content="4"/>
                </li>
            
        </ul>
    </nav>
    
    
    
        
                
                
<div class="overview">
    


<div class="project-icon   " >
    
    
    <img itemprop="image" alt="XSB" title="XSB" 
    
    
    src="https://a.fsdn.com/allura/p/xsb/icon?1368563712"
    /></div>


    
    <div class="title "> 

        <meta itemprop="name" content="XSB"/>
        <h1  >XSB Src  (SVN)-old
        </h1>
        
            
            
          
        
            
            
            <div class="as-h3 brought-by">
                
                Brought to you by:
                
                    <a href="/u/carlandersen/profile/">carlandersen</a>,
                    
                
                    <a href="/u/dwarren/profile/">dwarren</a>,
                    
                
                    <a href="/u/evansbj/profile/">evansbj</a>,
                    
                
                    <a href="/u/kifer/profile/">kifer</a>,
                    
                
                    
                        and <a href="/p/xsb/_members/">3 others</a>
                    
                
            </div>
            
        

        

        
    </div>


    

</div>

                
                
    
  
            
            
        
    </div>
</section>

        </div>
    

                
            
        </div>
        <div id="top_nav" class="">
            
                
<div id="top_nav_admin">
<ul class="dropdown">
  
  
    <li class="">
        <a href="/projects/xsb/" class="tool-summary-32" >
            Summary
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/files/" class="tool-files-sf-32" >
            Files
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/reviews/" class="tool-reviews-32" >
            Reviews
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/support" class="tool-support-32" >
            Support
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/mailman/" class="tool-mailman-32" >
            Mail Lists
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/_list/tickets" class="tool-tickets-32" >
            Tickets ▾
        </a>
        
        
            <ul>
                
                    <li class=""><a href="/p/xsb/bugs/" >Bugs</a></li>
                
                    <li class=""><a href="/p/xsb/feature-requests/" >Feature Requests</a></li>
                
                    <li class=""><a href="/p/xsb/support-requests/" >Support Requests</a></li>
                
                    <li class=""><a href="/p/xsb/patches/" >Patches</a></li>
                
            </ul>
        
    </li>
  
    <li class="">
        <a href="/p/xsb/news/" class="tool-blog-32" >
            News
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/code/" class="tool-git-32" >
            Sources (GIT)
        </a>
        
        
    </li>
  
    <li class="selected">
        <a href="/p/xsb/src/" class="tool-svn-32" >
            Src  (SVN)-old
        </a>
        
        
    </li>
  
  
</ul>
</div>


            
        </div>
        <div id="content_base">
            

    
                
                    
<a id="sidebar-activate" href="#">
    <span class="btn-label">Menu</span>
    <span class="btn-arrow-down">▾</span>
    <span class="btn-arrow-up">▴</span>
</a>

                        


<div id="sidebar">
  
    <div class="placeholder-no-searchbox">&nbsp;</div>
  
    
    
      
      
        
    
      <ul class="sidebarmenu">
      
    
  <li>
      
        <a class="icon" href="/p/xsb/src/commit_browser" rel="nofollow" title="Browse Commits"><i class="fa fa-list"></i>
      
      <span>Browse Commits</span>
      </a>
  </li>
  
      
        
    
  <li>
      
        <a href="/p/xsb/src/"  rel="nofollow" >
      
      <span>Browse Files</span>
      </a>
  </li>
  
      
    
    
      </ul>
      
    
    
</div>



<script>
$('#sidebar-admin-header').on('click', function(e){
    $("#sidebar-admin-menu").toggleClass("hidden");
    $(this).toggleClass("expanded");
    e.preventDefault();
});
</script>

                    

                    
                
                
                    
                
                <div class="grid-20 pad">
                    <h2 class="dark title">
                        <span>
<a href="/p/xsb/src/7607/" rel="nofollow">[r7607]</a>:

  
      <a href="./../../../../" rel="nofollow"><b class="fa fa-folder-open-o" title="Root directory"></b></a> /
  
  
    <a href="./../../../" rel="nofollow">trunk</a> /
  
    <a href="./../../" rel="nofollow">XSB</a> /
  
    <a href="./../" rel="nofollow">docs</a> /
  
    <a href="./" rel="nofollow">userman</a> /
  
 tables.tex
</span>
                        <!-- actions -->
                        <small>
                            

    
    <a class="icon" href="#" id="maximize-content" title="Maximize"><i class="fa fa-expand"></i>&nbsp;Maximize</a>
    <a class="icon" href="#" id="restore-content" title="Restore"><i class="fa fa-compress"></i>&nbsp;Restore</a>
<a class="icon" href="/p/xsb/src/7607/log/?path=/trunk/XSB/docs/userman/tables.tex" rel="nofollow" title="History"><i class="fa fa-calendar"></i>&nbsp;History</a>

                        </small>
                        <!-- /actions -->
                    </h2>
                    
                    <div>
                        
  

                        
  
    <p><a rel="nofollow" href="?format=raw">Download this file</a></p>
    <div class="clip grid-19 codebrowser">
      <h3>
        2265 lines (2037 with data), 104.4 kB
      </h3>
      
        <div class="codehilite"><table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">   1</span>
<span class="normal">   2</span>
<span class="normal">   3</span>
<span class="normal">   4</span>
<span class="normal">   5</span>
<span class="normal">   6</span>
<span class="normal">   7</span>
<span class="normal">   8</span>
<span class="normal">   9</span>
<span class="normal">  10</span>
<span class="normal">  11</span>
<span class="normal">  12</span>
<span class="normal">  13</span>
<span class="normal">  14</span>
<span class="normal">  15</span>
<span class="normal">  16</span>
<span class="normal">  17</span>
<span class="normal">  18</span>
<span class="normal">  19</span>
<span class="normal">  20</span>
<span class="normal">  21</span>
<span class="normal">  22</span>
<span class="normal">  23</span>
<span class="normal">  24</span>
<span class="normal">  25</span>
<span class="normal">  26</span>
<span class="normal">  27</span>
<span class="normal">  28</span>
<span class="normal">  29</span>
<span class="normal">  30</span>
<span class="normal">  31</span>
<span class="normal">  32</span>
<span class="normal">  33</span>
<span class="normal">  34</span>
<span class="normal">  35</span>
<span class="normal">  36</span>
<span class="normal">  37</span>
<span class="normal">  38</span>
<span class="normal">  39</span>
<span class="normal">  40</span>
<span class="normal">  41</span>
<span class="normal">  42</span>
<span class="normal">  43</span>
<span class="normal">  44</span>
<span class="normal">  45</span>
<span class="normal">  46</span>
<span class="normal">  47</span>
<span class="normal">  48</span>
<span class="normal">  49</span>
<span class="normal">  50</span>
<span class="normal">  51</span>
<span class="normal">  52</span>
<span class="normal">  53</span>
<span class="normal">  54</span>
<span class="normal">  55</span>
<span class="normal">  56</span>
<span class="normal">  57</span>
<span class="normal">  58</span>
<span class="normal">  59</span>
<span class="normal">  60</span>
<span class="normal">  61</span>
<span class="normal">  62</span>
<span class="normal">  63</span>
<span class="normal">  64</span>
<span class="normal">  65</span>
<span class="normal">  66</span>
<span class="normal">  67</span>
<span class="normal">  68</span>
<span class="normal">  69</span>
<span class="normal">  70</span>
<span class="normal">  71</span>
<span class="normal">  72</span>
<span class="normal">  73</span>
<span class="normal">  74</span>
<span class="normal">  75</span>
<span class="normal">  76</span>
<span class="normal">  77</span>
<span class="normal">  78</span>
<span class="normal">  79</span>
<span class="normal">  80</span>
<span class="normal">  81</span>
<span class="normal">  82</span>
<span class="normal">  83</span>
<span class="normal">  84</span>
<span class="normal">  85</span>
<span class="normal">  86</span>
<span class="normal">  87</span>
<span class="normal">  88</span>
<span class="normal">  89</span>
<span class="normal">  90</span>
<span class="normal">  91</span>
<span class="normal">  92</span>
<span class="normal">  93</span>
<span class="normal">  94</span>
<span class="normal">  95</span>
<span class="normal">  96</span>
<span class="normal">  97</span>
<span class="normal">  98</span>
<span class="normal">  99</span>
<span class="normal"> 100</span>
<span class="normal"> 101</span>
<span class="normal"> 102</span>
<span class="normal"> 103</span>
<span class="normal"> 104</span>
<span class="normal"> 105</span>
<span class="normal"> 106</span>
<span class="normal"> 107</span>
<span class="normal"> 108</span>
<span class="normal"> 109</span>
<span class="normal"> 110</span>
<span class="normal"> 111</span>
<span class="normal"> 112</span>
<span class="normal"> 113</span>
<span class="normal"> 114</span>
<span class="normal"> 115</span>
<span class="normal"> 116</span>
<span class="normal"> 117</span>
<span class="normal"> 118</span>
<span class="normal"> 119</span>
<span class="normal"> 120</span>
<span class="normal"> 121</span>
<span class="normal"> 122</span>
<span class="normal"> 123</span>
<span class="normal"> 124</span>
<span class="normal"> 125</span>
<span class="normal"> 126</span>
<span class="normal"> 127</span>
<span class="normal"> 128</span>
<span class="normal"> 129</span>
<span class="normal"> 130</span>
<span class="normal"> 131</span>
<span class="normal"> 132</span>
<span class="normal"> 133</span>
<span class="normal"> 134</span>
<span class="normal"> 135</span>
<span class="normal"> 136</span>
<span class="normal"> 137</span>
<span class="normal"> 138</span>
<span class="normal"> 139</span>
<span class="normal"> 140</span>
<span class="normal"> 141</span>
<span class="normal"> 142</span>
<span class="normal"> 143</span>
<span class="normal"> 144</span>
<span class="normal"> 145</span>
<span class="normal"> 146</span>
<span class="normal"> 147</span>
<span class="normal"> 148</span>
<span class="normal"> 149</span>
<span class="normal"> 150</span>
<span class="normal"> 151</span>
<span class="normal"> 152</span>
<span class="normal"> 153</span>
<span class="normal"> 154</span>
<span class="normal"> 155</span>
<span class="normal"> 156</span>
<span class="normal"> 157</span>
<span class="normal"> 158</span>
<span class="normal"> 159</span>
<span class="normal"> 160</span>
<span class="normal"> 161</span>
<span class="normal"> 162</span>
<span class="normal"> 163</span>
<span class="normal"> 164</span>
<span class="normal"> 165</span>
<span class="normal"> 166</span>
<span class="normal"> 167</span>
<span class="normal"> 168</span>
<span class="normal"> 169</span>
<span class="normal"> 170</span>
<span class="normal"> 171</span>
<span class="normal"> 172</span>
<span class="normal"> 173</span>
<span class="normal"> 174</span>
<span class="normal"> 175</span>
<span class="normal"> 176</span>
<span class="normal"> 177</span>
<span class="normal"> 178</span>
<span class="normal"> 179</span>
<span class="normal"> 180</span>
<span class="normal"> 181</span>
<span class="normal"> 182</span>
<span class="normal"> 183</span>
<span class="normal"> 184</span>
<span class="normal"> 185</span>
<span class="normal"> 186</span>
<span class="normal"> 187</span>
<span class="normal"> 188</span>
<span class="normal"> 189</span>
<span class="normal"> 190</span>
<span class="normal"> 191</span>
<span class="normal"> 192</span>
<span class="normal"> 193</span>
<span class="normal"> 194</span>
<span class="normal"> 195</span>
<span class="normal"> 196</span>
<span class="normal"> 197</span>
<span class="normal"> 198</span>
<span class="normal"> 199</span>
<span class="normal"> 200</span>
<span class="normal"> 201</span>
<span class="normal"> 202</span>
<span class="normal"> 203</span>
<span class="normal"> 204</span>
<span class="normal"> 205</span>
<span class="normal"> 206</span>
<span class="normal"> 207</span>
<span class="normal"> 208</span>
<span class="normal"> 209</span>
<span class="normal"> 210</span>
<span class="normal"> 211</span>
<span class="normal"> 212</span>
<span class="normal"> 213</span>
<span class="normal"> 214</span>
<span class="normal"> 215</span>
<span class="normal"> 216</span>
<span class="normal"> 217</span>
<span class="normal"> 218</span>
<span class="normal"> 219</span>
<span class="normal"> 220</span>
<span class="normal"> 221</span>
<span class="normal"> 222</span>
<span class="normal"> 223</span>
<span class="normal"> 224</span>
<span class="normal"> 225</span>
<span class="normal"> 226</span>
<span class="normal"> 227</span>
<span class="normal"> 228</span>
<span class="normal"> 229</span>
<span class="normal"> 230</span>
<span class="normal"> 231</span>
<span class="normal"> 232</span>
<span class="normal"> 233</span>
<span class="normal"> 234</span>
<span class="normal"> 235</span>
<span class="normal"> 236</span>
<span class="normal"> 237</span>
<span class="normal"> 238</span>
<span class="normal"> 239</span>
<span class="normal"> 240</span>
<span class="normal"> 241</span>
<span class="normal"> 242</span>
<span class="normal"> 243</span>
<span class="normal"> 244</span>
<span class="normal"> 245</span>
<span class="normal"> 246</span>
<span class="normal"> 247</span>
<span class="normal"> 248</span>
<span class="normal"> 249</span>
<span class="normal"> 250</span>
<span class="normal"> 251</span>
<span class="normal"> 252</span>
<span class="normal"> 253</span>
<span class="normal"> 254</span>
<span class="normal"> 255</span>
<span class="normal"> 256</span>
<span class="normal"> 257</span>
<span class="normal"> 258</span>
<span class="normal"> 259</span>
<span class="normal"> 260</span>
<span class="normal"> 261</span>
<span class="normal"> 262</span>
<span class="normal"> 263</span>
<span class="normal"> 264</span>
<span class="normal"> 265</span>
<span class="normal"> 266</span>
<span class="normal"> 267</span>
<span class="normal"> 268</span>
<span class="normal"> 269</span>
<span class="normal"> 270</span>
<span class="normal"> 271</span>
<span class="normal"> 272</span>
<span class="normal"> 273</span>
<span class="normal"> 274</span>
<span class="normal"> 275</span>
<span class="normal"> 276</span>
<span class="normal"> 277</span>
<span class="normal"> 278</span>
<span class="normal"> 279</span>
<span class="normal"> 280</span>
<span class="normal"> 281</span>
<span class="normal"> 282</span>
<span class="normal"> 283</span>
<span class="normal"> 284</span>
<span class="normal"> 285</span>
<span class="normal"> 286</span>
<span class="normal"> 287</span>
<span class="normal"> 288</span>
<span class="normal"> 289</span>
<span class="normal"> 290</span>
<span class="normal"> 291</span>
<span class="normal"> 292</span>
<span class="normal"> 293</span>
<span class="normal"> 294</span>
<span class="normal"> 295</span>
<span class="normal"> 296</span>
<span class="normal"> 297</span>
<span class="normal"> 298</span>
<span class="normal"> 299</span>
<span class="normal"> 300</span>
<span class="normal"> 301</span>
<span class="normal"> 302</span>
<span class="normal"> 303</span>
<span class="normal"> 304</span>
<span class="normal"> 305</span>
<span class="normal"> 306</span>
<span class="normal"> 307</span>
<span class="normal"> 308</span>
<span class="normal"> 309</span>
<span class="normal"> 310</span>
<span class="normal"> 311</span>
<span class="normal"> 312</span>
<span class="normal"> 313</span>
<span class="normal"> 314</span>
<span class="normal"> 315</span>
<span class="normal"> 316</span>
<span class="normal"> 317</span>
<span class="normal"> 318</span>
<span class="normal"> 319</span>
<span class="normal"> 320</span>
<span class="normal"> 321</span>
<span class="normal"> 322</span>
<span class="normal"> 323</span>
<span class="normal"> 324</span>
<span class="normal"> 325</span>
<span class="normal"> 326</span>
<span class="normal"> 327</span>
<span class="normal"> 328</span>
<span class="normal"> 329</span>
<span class="normal"> 330</span>
<span class="normal"> 331</span>
<span class="normal"> 332</span>
<span class="normal"> 333</span>
<span class="normal"> 334</span>
<span class="normal"> 335</span>
<span class="normal"> 336</span>
<span class="normal"> 337</span>
<span class="normal"> 338</span>
<span class="normal"> 339</span>
<span class="normal"> 340</span>
<span class="normal"> 341</span>
<span class="normal"> 342</span>
<span class="normal"> 343</span>
<span class="normal"> 344</span>
<span class="normal"> 345</span>
<span class="normal"> 346</span>
<span class="normal"> 347</span>
<span class="normal"> 348</span>
<span class="normal"> 349</span>
<span class="normal"> 350</span>
<span class="normal"> 351</span>
<span class="normal"> 352</span>
<span class="normal"> 353</span>
<span class="normal"> 354</span>
<span class="normal"> 355</span>
<span class="normal"> 356</span>
<span class="normal"> 357</span>
<span class="normal"> 358</span>
<span class="normal"> 359</span>
<span class="normal"> 360</span>
<span class="normal"> 361</span>
<span class="normal"> 362</span>
<span class="normal"> 363</span>
<span class="normal"> 364</span>
<span class="normal"> 365</span>
<span class="normal"> 366</span>
<span class="normal"> 367</span>
<span class="normal"> 368</span>
<span class="normal"> 369</span>
<span class="normal"> 370</span>
<span class="normal"> 371</span>
<span class="normal"> 372</span>
<span class="normal"> 373</span>
<span class="normal"> 374</span>
<span class="normal"> 375</span>
<span class="normal"> 376</span>
<span class="normal"> 377</span>
<span class="normal"> 378</span>
<span class="normal"> 379</span>
<span class="normal"> 380</span>
<span class="normal"> 381</span>
<span class="normal"> 382</span>
<span class="normal"> 383</span>
<span class="normal"> 384</span>
<span class="normal"> 385</span>
<span class="normal"> 386</span>
<span class="normal"> 387</span>
<span class="normal"> 388</span>
<span class="normal"> 389</span>
<span class="normal"> 390</span>
<span class="normal"> 391</span>
<span class="normal"> 392</span>
<span class="normal"> 393</span>
<span class="normal"> 394</span>
<span class="normal"> 395</span>
<span class="normal"> 396</span>
<span class="normal"> 397</span>
<span class="normal"> 398</span>
<span class="normal"> 399</span>
<span class="normal"> 400</span>
<span class="normal"> 401</span>
<span class="normal"> 402</span>
<span class="normal"> 403</span>
<span class="normal"> 404</span>
<span class="normal"> 405</span>
<span class="normal"> 406</span>
<span class="normal"> 407</span>
<span class="normal"> 408</span>
<span class="normal"> 409</span>
<span class="normal"> 410</span>
<span class="normal"> 411</span>
<span class="normal"> 412</span>
<span class="normal"> 413</span>
<span class="normal"> 414</span>
<span class="normal"> 415</span>
<span class="normal"> 416</span>
<span class="normal"> 417</span>
<span class="normal"> 418</span>
<span class="normal"> 419</span>
<span class="normal"> 420</span>
<span class="normal"> 421</span>
<span class="normal"> 422</span>
<span class="normal"> 423</span>
<span class="normal"> 424</span>
<span class="normal"> 425</span>
<span class="normal"> 426</span>
<span class="normal"> 427</span>
<span class="normal"> 428</span>
<span class="normal"> 429</span>
<span class="normal"> 430</span>
<span class="normal"> 431</span>
<span class="normal"> 432</span>
<span class="normal"> 433</span>
<span class="normal"> 434</span>
<span class="normal"> 435</span>
<span class="normal"> 436</span>
<span class="normal"> 437</span>
<span class="normal"> 438</span>
<span class="normal"> 439</span>
<span class="normal"> 440</span>
<span class="normal"> 441</span>
<span class="normal"> 442</span>
<span class="normal"> 443</span>
<span class="normal"> 444</span>
<span class="normal"> 445</span>
<span class="normal"> 446</span>
<span class="normal"> 447</span>
<span class="normal"> 448</span>
<span class="normal"> 449</span>
<span class="normal"> 450</span>
<span class="normal"> 451</span>
<span class="normal"> 452</span>
<span class="normal"> 453</span>
<span class="normal"> 454</span>
<span class="normal"> 455</span>
<span class="normal"> 456</span>
<span class="normal"> 457</span>
<span class="normal"> 458</span>
<span class="normal"> 459</span>
<span class="normal"> 460</span>
<span class="normal"> 461</span>
<span class="normal"> 462</span>
<span class="normal"> 463</span>
<span class="normal"> 464</span>
<span class="normal"> 465</span>
<span class="normal"> 466</span>
<span class="normal"> 467</span>
<span class="normal"> 468</span>
<span class="normal"> 469</span>
<span class="normal"> 470</span>
<span class="normal"> 471</span>
<span class="normal"> 472</span>
<span class="normal"> 473</span>
<span class="normal"> 474</span>
<span class="normal"> 475</span>
<span class="normal"> 476</span>
<span class="normal"> 477</span>
<span class="normal"> 478</span>
<span class="normal"> 479</span>
<span class="normal"> 480</span>
<span class="normal"> 481</span>
<span class="normal"> 482</span>
<span class="normal"> 483</span>
<span class="normal"> 484</span>
<span class="normal"> 485</span>
<span class="normal"> 486</span>
<span class="normal"> 487</span>
<span class="normal"> 488</span>
<span class="normal"> 489</span>
<span class="normal"> 490</span>
<span class="normal"> 491</span>
<span class="normal"> 492</span>
<span class="normal"> 493</span>
<span class="normal"> 494</span>
<span class="normal"> 495</span>
<span class="normal"> 496</span>
<span class="normal"> 497</span>
<span class="normal"> 498</span>
<span class="normal"> 499</span>
<span class="normal"> 500</span>
<span class="normal"> 501</span>
<span class="normal"> 502</span>
<span class="normal"> 503</span>
<span class="normal"> 504</span>
<span class="normal"> 505</span>
<span class="normal"> 506</span>
<span class="normal"> 507</span>
<span class="normal"> 508</span>
<span class="normal"> 509</span>
<span class="normal"> 510</span>
<span class="normal"> 511</span>
<span class="normal"> 512</span>
<span class="normal"> 513</span>
<span class="normal"> 514</span>
<span class="normal"> 515</span>
<span class="normal"> 516</span>
<span class="normal"> 517</span>
<span class="normal"> 518</span>
<span class="normal"> 519</span>
<span class="normal"> 520</span>
<span class="normal"> 521</span>
<span class="normal"> 522</span>
<span class="normal"> 523</span>
<span class="normal"> 524</span>
<span class="normal"> 525</span>
<span class="normal"> 526</span>
<span class="normal"> 527</span>
<span class="normal"> 528</span>
<span class="normal"> 529</span>
<span class="normal"> 530</span>
<span class="normal"> 531</span>
<span class="normal"> 532</span>
<span class="normal"> 533</span>
<span class="normal"> 534</span>
<span class="normal"> 535</span>
<span class="normal"> 536</span>
<span class="normal"> 537</span>
<span class="normal"> 538</span>
<span class="normal"> 539</span>
<span class="normal"> 540</span>
<span class="normal"> 541</span>
<span class="normal"> 542</span>
<span class="normal"> 543</span>
<span class="normal"> 544</span>
<span class="normal"> 545</span>
<span class="normal"> 546</span>
<span class="normal"> 547</span>
<span class="normal"> 548</span>
<span class="normal"> 549</span>
<span class="normal"> 550</span>
<span class="normal"> 551</span>
<span class="normal"> 552</span>
<span class="normal"> 553</span>
<span class="normal"> 554</span>
<span class="normal"> 555</span>
<span class="normal"> 556</span>
<span class="normal"> 557</span>
<span class="normal"> 558</span>
<span class="normal"> 559</span>
<span class="normal"> 560</span>
<span class="normal"> 561</span>
<span class="normal"> 562</span>
<span class="normal"> 563</span>
<span class="normal"> 564</span>
<span class="normal"> 565</span>
<span class="normal"> 566</span>
<span class="normal"> 567</span>
<span class="normal"> 568</span>
<span class="normal"> 569</span>
<span class="normal"> 570</span>
<span class="normal"> 571</span>
<span class="normal"> 572</span>
<span class="normal"> 573</span>
<span class="normal"> 574</span>
<span class="normal"> 575</span>
<span class="normal"> 576</span>
<span class="normal"> 577</span>
<span class="normal"> 578</span>
<span class="normal"> 579</span>
<span class="normal"> 580</span>
<span class="normal"> 581</span>
<span class="normal"> 582</span>
<span class="normal"> 583</span>
<span class="normal"> 584</span>
<span class="normal"> 585</span>
<span class="normal"> 586</span>
<span class="normal"> 587</span>
<span class="normal"> 588</span>
<span class="normal"> 589</span>
<span class="normal"> 590</span>
<span class="normal"> 591</span>
<span class="normal"> 592</span>
<span class="normal"> 593</span>
<span class="normal"> 594</span>
<span class="normal"> 595</span>
<span class="normal"> 596</span>
<span class="normal"> 597</span>
<span class="normal"> 598</span>
<span class="normal"> 599</span>
<span class="normal"> 600</span>
<span class="normal"> 601</span>
<span class="normal"> 602</span>
<span class="normal"> 603</span>
<span class="normal"> 604</span>
<span class="normal"> 605</span>
<span class="normal"> 606</span>
<span class="normal"> 607</span>
<span class="normal"> 608</span>
<span class="normal"> 609</span>
<span class="normal"> 610</span>
<span class="normal"> 611</span>
<span class="normal"> 612</span>
<span class="normal"> 613</span>
<span class="normal"> 614</span>
<span class="normal"> 615</span>
<span class="normal"> 616</span>
<span class="normal"> 617</span>
<span class="normal"> 618</span>
<span class="normal"> 619</span>
<span class="normal"> 620</span>
<span class="normal"> 621</span>
<span class="normal"> 622</span>
<span class="normal"> 623</span>
<span class="normal"> 624</span>
<span class="normal"> 625</span>
<span class="normal"> 626</span>
<span class="normal"> 627</span>
<span class="normal"> 628</span>
<span class="normal"> 629</span>
<span class="normal"> 630</span>
<span class="normal"> 631</span>
<span class="normal"> 632</span>
<span class="normal"> 633</span>
<span class="normal"> 634</span>
<span class="normal"> 635</span>
<span class="normal"> 636</span>
<span class="normal"> 637</span>
<span class="normal"> 638</span>
<span class="normal"> 639</span>
<span class="normal"> 640</span>
<span class="normal"> 641</span>
<span class="normal"> 642</span>
<span class="normal"> 643</span>
<span class="normal"> 644</span>
<span class="normal"> 645</span>
<span class="normal"> 646</span>
<span class="normal"> 647</span>
<span class="normal"> 648</span>
<span class="normal"> 649</span>
<span class="normal"> 650</span>
<span class="normal"> 651</span>
<span class="normal"> 652</span>
<span class="normal"> 653</span>
<span class="normal"> 654</span>
<span class="normal"> 655</span>
<span class="normal"> 656</span>
<span class="normal"> 657</span>
<span class="normal"> 658</span>
<span class="normal"> 659</span>
<span class="normal"> 660</span>
<span class="normal"> 661</span>
<span class="normal"> 662</span>
<span class="normal"> 663</span>
<span class="normal"> 664</span>
<span class="normal"> 665</span>
<span class="normal"> 666</span>
<span class="normal"> 667</span>
<span class="normal"> 668</span>
<span class="normal"> 669</span>
<span class="normal"> 670</span>
<span class="normal"> 671</span>
<span class="normal"> 672</span>
<span class="normal"> 673</span>
<span class="normal"> 674</span>
<span class="normal"> 675</span>
<span class="normal"> 676</span>
<span class="normal"> 677</span>
<span class="normal"> 678</span>
<span class="normal"> 679</span>
<span class="normal"> 680</span>
<span class="normal"> 681</span>
<span class="normal"> 682</span>
<span class="normal"> 683</span>
<span class="normal"> 684</span>
<span class="normal"> 685</span>
<span class="normal"> 686</span>
<span class="normal"> 687</span>
<span class="normal"> 688</span>
<span class="normal"> 689</span>
<span class="normal"> 690</span>
<span class="normal"> 691</span>
<span class="normal"> 692</span>
<span class="normal"> 693</span>
<span class="normal"> 694</span>
<span class="normal"> 695</span>
<span class="normal"> 696</span>
<span class="normal"> 697</span>
<span class="normal"> 698</span>
<span class="normal"> 699</span>
<span class="normal"> 700</span>
<span class="normal"> 701</span>
<span class="normal"> 702</span>
<span class="normal"> 703</span>
<span class="normal"> 704</span>
<span class="normal"> 705</span>
<span class="normal"> 706</span>
<span class="normal"> 707</span>
<span class="normal"> 708</span>
<span class="normal"> 709</span>
<span class="normal"> 710</span>
<span class="normal"> 711</span>
<span class="normal"> 712</span>
<span class="normal"> 713</span>
<span class="normal"> 714</span>
<span class="normal"> 715</span>
<span class="normal"> 716</span>
<span class="normal"> 717</span>
<span class="normal"> 718</span>
<span class="normal"> 719</span>
<span class="normal"> 720</span>
<span class="normal"> 721</span>
<span class="normal"> 722</span>
<span class="normal"> 723</span>
<span class="normal"> 724</span>
<span class="normal"> 725</span>
<span class="normal"> 726</span>
<span class="normal"> 727</span>
<span class="normal"> 728</span>
<span class="normal"> 729</span>
<span class="normal"> 730</span>
<span class="normal"> 731</span>
<span class="normal"> 732</span>
<span class="normal"> 733</span>
<span class="normal"> 734</span>
<span class="normal"> 735</span>
<span class="normal"> 736</span>
<span class="normal"> 737</span>
<span class="normal"> 738</span>
<span class="normal"> 739</span>
<span class="normal"> 740</span>
<span class="normal"> 741</span>
<span class="normal"> 742</span>
<span class="normal"> 743</span>
<span class="normal"> 744</span>
<span class="normal"> 745</span>
<span class="normal"> 746</span>
<span class="normal"> 747</span>
<span class="normal"> 748</span>
<span class="normal"> 749</span>
<span class="normal"> 750</span>
<span class="normal"> 751</span>
<span class="normal"> 752</span>
<span class="normal"> 753</span>
<span class="normal"> 754</span>
<span class="normal"> 755</span>
<span class="normal"> 756</span>
<span class="normal"> 757</span>
<span class="normal"> 758</span>
<span class="normal"> 759</span>
<span class="normal"> 760</span>
<span class="normal"> 761</span>
<span class="normal"> 762</span>
<span class="normal"> 763</span>
<span class="normal"> 764</span>
<span class="normal"> 765</span>
<span class="normal"> 766</span>
<span class="normal"> 767</span>
<span class="normal"> 768</span>
<span class="normal"> 769</span>
<span class="normal"> 770</span>
<span class="normal"> 771</span>
<span class="normal"> 772</span>
<span class="normal"> 773</span>
<span class="normal"> 774</span>
<span class="normal"> 775</span>
<span class="normal"> 776</span>
<span class="normal"> 777</span>
<span class="normal"> 778</span>
<span class="normal"> 779</span>
<span class="normal"> 780</span>
<span class="normal"> 781</span>
<span class="normal"> 782</span>
<span class="normal"> 783</span>
<span class="normal"> 784</span>
<span class="normal"> 785</span>
<span class="normal"> 786</span>
<span class="normal"> 787</span>
<span class="normal"> 788</span>
<span class="normal"> 789</span>
<span class="normal"> 790</span>
<span class="normal"> 791</span>
<span class="normal"> 792</span>
<span class="normal"> 793</span>
<span class="normal"> 794</span>
<span class="normal"> 795</span>
<span class="normal"> 796</span>
<span class="normal"> 797</span>
<span class="normal"> 798</span>
<span class="normal"> 799</span>
<span class="normal"> 800</span>
<span class="normal"> 801</span>
<span class="normal"> 802</span>
<span class="normal"> 803</span>
<span class="normal"> 804</span>
<span class="normal"> 805</span>
<span class="normal"> 806</span>
<span class="normal"> 807</span>
<span class="normal"> 808</span>
<span class="normal"> 809</span>
<span class="normal"> 810</span>
<span class="normal"> 811</span>
<span class="normal"> 812</span>
<span class="normal"> 813</span>
<span class="normal"> 814</span>
<span class="normal"> 815</span>
<span class="normal"> 816</span>
<span class="normal"> 817</span>
<span class="normal"> 818</span>
<span class="normal"> 819</span>
<span class="normal"> 820</span>
<span class="normal"> 821</span>
<span class="normal"> 822</span>
<span class="normal"> 823</span>
<span class="normal"> 824</span>
<span class="normal"> 825</span>
<span class="normal"> 826</span>
<span class="normal"> 827</span>
<span class="normal"> 828</span>
<span class="normal"> 829</span>
<span class="normal"> 830</span>
<span class="normal"> 831</span>
<span class="normal"> 832</span>
<span class="normal"> 833</span>
<span class="normal"> 834</span>
<span class="normal"> 835</span>
<span class="normal"> 836</span>
<span class="normal"> 837</span>
<span class="normal"> 838</span>
<span class="normal"> 839</span>
<span class="normal"> 840</span>
<span class="normal"> 841</span>
<span class="normal"> 842</span>
<span class="normal"> 843</span>
<span class="normal"> 844</span>
<span class="normal"> 845</span>
<span class="normal"> 846</span>
<span class="normal"> 847</span>
<span class="normal"> 848</span>
<span class="normal"> 849</span>
<span class="normal"> 850</span>
<span class="normal"> 851</span>
<span class="normal"> 852</span>
<span class="normal"> 853</span>
<span class="normal"> 854</span>
<span class="normal"> 855</span>
<span class="normal"> 856</span>
<span class="normal"> 857</span>
<span class="normal"> 858</span>
<span class="normal"> 859</span>
<span class="normal"> 860</span>
<span class="normal"> 861</span>
<span class="normal"> 862</span>
<span class="normal"> 863</span>
<span class="normal"> 864</span>
<span class="normal"> 865</span>
<span class="normal"> 866</span>
<span class="normal"> 867</span>
<span class="normal"> 868</span>
<span class="normal"> 869</span>
<span class="normal"> 870</span>
<span class="normal"> 871</span>
<span class="normal"> 872</span>
<span class="normal"> 873</span>
<span class="normal"> 874</span>
<span class="normal"> 875</span>
<span class="normal"> 876</span>
<span class="normal"> 877</span>
<span class="normal"> 878</span>
<span class="normal"> 879</span>
<span class="normal"> 880</span>
<span class="normal"> 881</span>
<span class="normal"> 882</span>
<span class="normal"> 883</span>
<span class="normal"> 884</span>
<span class="normal"> 885</span>
<span class="normal"> 886</span>
<span class="normal"> 887</span>
<span class="normal"> 888</span>
<span class="normal"> 889</span>
<span class="normal"> 890</span>
<span class="normal"> 891</span>
<span class="normal"> 892</span>
<span class="normal"> 893</span>
<span class="normal"> 894</span>
<span class="normal"> 895</span>
<span class="normal"> 896</span>
<span class="normal"> 897</span>
<span class="normal"> 898</span>
<span class="normal"> 899</span>
<span class="normal"> 900</span>
<span class="normal"> 901</span>
<span class="normal"> 902</span>
<span class="normal"> 903</span>
<span class="normal"> 904</span>
<span class="normal"> 905</span>
<span class="normal"> 906</span>
<span class="normal"> 907</span>
<span class="normal"> 908</span>
<span class="normal"> 909</span>
<span class="normal"> 910</span>
<span class="normal"> 911</span>
<span class="normal"> 912</span>
<span class="normal"> 913</span>
<span class="normal"> 914</span>
<span class="normal"> 915</span>
<span class="normal"> 916</span>
<span class="normal"> 917</span>
<span class="normal"> 918</span>
<span class="normal"> 919</span>
<span class="normal"> 920</span>
<span class="normal"> 921</span>
<span class="normal"> 922</span>
<span class="normal"> 923</span>
<span class="normal"> 924</span>
<span class="normal"> 925</span>
<span class="normal"> 926</span>
<span class="normal"> 927</span>
<span class="normal"> 928</span>
<span class="normal"> 929</span>
<span class="normal"> 930</span>
<span class="normal"> 931</span>
<span class="normal"> 932</span>
<span class="normal"> 933</span>
<span class="normal"> 934</span>
<span class="normal"> 935</span>
<span class="normal"> 936</span>
<span class="normal"> 937</span>
<span class="normal"> 938</span>
<span class="normal"> 939</span>
<span class="normal"> 940</span>
<span class="normal"> 941</span>
<span class="normal"> 942</span>
<span class="normal"> 943</span>
<span class="normal"> 944</span>
<span class="normal"> 945</span>
<span class="normal"> 946</span>
<span class="normal"> 947</span>
<span class="normal"> 948</span>
<span class="normal"> 949</span>
<span class="normal"> 950</span>
<span class="normal"> 951</span>
<span class="normal"> 952</span>
<span class="normal"> 953</span>
<span class="normal"> 954</span>
<span class="normal"> 955</span>
<span class="normal"> 956</span>
<span class="normal"> 957</span>
<span class="normal"> 958</span>
<span class="normal"> 959</span>
<span class="normal"> 960</span>
<span class="normal"> 961</span>
<span class="normal"> 962</span>
<span class="normal"> 963</span>
<span class="normal"> 964</span>
<span class="normal"> 965</span>
<span class="normal"> 966</span>
<span class="normal"> 967</span>
<span class="normal"> 968</span>
<span class="normal"> 969</span>
<span class="normal"> 970</span>
<span class="normal"> 971</span>
<span class="normal"> 972</span>
<span class="normal"> 973</span>
<span class="normal"> 974</span>
<span class="normal"> 975</span>
<span class="normal"> 976</span>
<span class="normal"> 977</span>
<span class="normal"> 978</span>
<span class="normal"> 979</span>
<span class="normal"> 980</span>
<span class="normal"> 981</span>
<span class="normal"> 982</span>
<span class="normal"> 983</span>
<span class="normal"> 984</span>
<span class="normal"> 985</span>
<span class="normal"> 986</span>
<span class="normal"> 987</span>
<span class="normal"> 988</span>
<span class="normal"> 989</span>
<span class="normal"> 990</span>
<span class="normal"> 991</span>
<span class="normal"> 992</span>
<span class="normal"> 993</span>
<span class="normal"> 994</span>
<span class="normal"> 995</span>
<span class="normal"> 996</span>
<span class="normal"> 997</span>
<span class="normal"> 998</span>
<span class="normal"> 999</span>
<span class="normal">1000</span>
<span class="normal">1001</span>
<span class="normal">1002</span>
<span class="normal">1003</span>
<span class="normal">1004</span>
<span class="normal">1005</span>
<span class="normal">1006</span>
<span class="normal">1007</span>
<span class="normal">1008</span>
<span class="normal">1009</span>
<span class="normal">1010</span>
<span class="normal">1011</span>
<span class="normal">1012</span>
<span class="normal">1013</span>
<span class="normal">1014</span>
<span class="normal">1015</span>
<span class="normal">1016</span>
<span class="normal">1017</span>
<span class="normal">1018</span>
<span class="normal">1019</span>
<span class="normal">1020</span>
<span class="normal">1021</span>
<span class="normal">1022</span>
<span class="normal">1023</span>
<span class="normal">1024</span>
<span class="normal">1025</span>
<span class="normal">1026</span>
<span class="normal">1027</span>
<span class="normal">1028</span>
<span class="normal">1029</span>
<span class="normal">1030</span>
<span class="normal">1031</span>
<span class="normal">1032</span>
<span class="normal">1033</span>
<span class="normal">1034</span>
<span class="normal">1035</span>
<span class="normal">1036</span>
<span class="normal">1037</span>
<span class="normal">1038</span>
<span class="normal">1039</span>
<span class="normal">1040</span>
<span class="normal">1041</span>
<span class="normal">1042</span>
<span class="normal">1043</span>
<span class="normal">1044</span>
<span class="normal">1045</span>
<span class="normal">1046</span>
<span class="normal">1047</span>
<span class="normal">1048</span>
<span class="normal">1049</span>
<span class="normal">1050</span>
<span class="normal">1051</span>
<span class="normal">1052</span>
<span class="normal">1053</span>
<span class="normal">1054</span>
<span class="normal">1055</span>
<span class="normal">1056</span>
<span class="normal">1057</span>
<span class="normal">1058</span>
<span class="normal">1059</span>
<span class="normal">1060</span>
<span class="normal">1061</span>
<span class="normal">1062</span>
<span class="normal">1063</span>
<span class="normal">1064</span>
<span class="normal">1065</span>
<span class="normal">1066</span>
<span class="normal">1067</span>
<span class="normal">1068</span>
<span class="normal">1069</span>
<span class="normal">1070</span>
<span class="normal">1071</span>
<span class="normal">1072</span>
<span class="normal">1073</span>
<span class="normal">1074</span>
<span class="normal">1075</span>
<span class="normal">1076</span>
<span class="normal">1077</span>
<span class="normal">1078</span>
<span class="normal">1079</span>
<span class="normal">1080</span>
<span class="normal">1081</span>
<span class="normal">1082</span>
<span class="normal">1083</span>
<span class="normal">1084</span>
<span class="normal">1085</span>
<span class="normal">1086</span>
<span class="normal">1087</span>
<span class="normal">1088</span>
<span class="normal">1089</span>
<span class="normal">1090</span>
<span class="normal">1091</span>
<span class="normal">1092</span>
<span class="normal">1093</span>
<span class="normal">1094</span>
<span class="normal">1095</span>
<span class="normal">1096</span>
<span class="normal">1097</span>
<span class="normal">1098</span>
<span class="normal">1099</span>
<span class="normal">1100</span>
<span class="normal">1101</span>
<span class="normal">1102</span>
<span class="normal">1103</span>
<span class="normal">1104</span>
<span class="normal">1105</span>
<span class="normal">1106</span>
<span class="normal">1107</span>
<span class="normal">1108</span>
<span class="normal">1109</span>
<span class="normal">1110</span>
<span class="normal">1111</span>
<span class="normal">1112</span>
<span class="normal">1113</span>
<span class="normal">1114</span>
<span class="normal">1115</span>
<span class="normal">1116</span>
<span class="normal">1117</span>
<span class="normal">1118</span>
<span class="normal">1119</span>
<span class="normal">1120</span>
<span class="normal">1121</span>
<span class="normal">1122</span>
<span class="normal">1123</span>
<span class="normal">1124</span>
<span class="normal">1125</span>
<span class="normal">1126</span>
<span class="normal">1127</span>
<span class="normal">1128</span>
<span class="normal">1129</span>
<span class="normal">1130</span>
<span class="normal">1131</span>
<span class="normal">1132</span>
<span class="normal">1133</span>
<span class="normal">1134</span>
<span class="normal">1135</span>
<span class="normal">1136</span>
<span class="normal">1137</span>
<span class="normal">1138</span>
<span class="normal">1139</span>
<span class="normal">1140</span>
<span class="normal">1141</span>
<span class="normal">1142</span>
<span class="normal">1143</span>
<span class="normal">1144</span>
<span class="normal">1145</span>
<span class="normal">1146</span>
<span class="normal">1147</span>
<span class="normal">1148</span>
<span class="normal">1149</span>
<span class="normal">1150</span>
<span class="normal">1151</span>
<span class="normal">1152</span>
<span class="normal">1153</span>
<span class="normal">1154</span>
<span class="normal">1155</span>
<span class="normal">1156</span>
<span class="normal">1157</span>
<span class="normal">1158</span>
<span class="normal">1159</span>
<span class="normal">1160</span>
<span class="normal">1161</span>
<span class="normal">1162</span>
<span class="normal">1163</span>
<span class="normal">1164</span>
<span class="normal">1165</span>
<span class="normal">1166</span>
<span class="normal">1167</span>
<span class="normal">1168</span>
<span class="normal">1169</span>
<span class="normal">1170</span>
<span class="normal">1171</span>
<span class="normal">1172</span>
<span class="normal">1173</span>
<span class="normal">1174</span>
<span class="normal">1175</span>
<span class="normal">1176</span>
<span class="normal">1177</span>
<span class="normal">1178</span>
<span class="normal">1179</span>
<span class="normal">1180</span>
<span class="normal">1181</span>
<span class="normal">1182</span>
<span class="normal">1183</span>
<span class="normal">1184</span>
<span class="normal">1185</span>
<span class="normal">1186</span>
<span class="normal">1187</span>
<span class="normal">1188</span>
<span class="normal">1189</span>
<span class="normal">1190</span>
<span class="normal">1191</span>
<span class="normal">1192</span>
<span class="normal">1193</span>
<span class="normal">1194</span>
<span class="normal">1195</span>
<span class="normal">1196</span>
<span class="normal">1197</span>
<span class="normal">1198</span>
<span class="normal">1199</span>
<span class="normal">1200</span>
<span class="normal">1201</span>
<span class="normal">1202</span>
<span class="normal">1203</span>
<span class="normal">1204</span>
<span class="normal">1205</span>
<span class="normal">1206</span>
<span class="normal">1207</span>
<span class="normal">1208</span>
<span class="normal">1209</span>
<span class="normal">1210</span>
<span class="normal">1211</span>
<span class="normal">1212</span>
<span class="normal">1213</span>
<span class="normal">1214</span>
<span class="normal">1215</span>
<span class="normal">1216</span>
<span class="normal">1217</span>
<span class="normal">1218</span>
<span class="normal">1219</span>
<span class="normal">1220</span>
<span class="normal">1221</span>
<span class="normal">1222</span>
<span class="normal">1223</span>
<span class="normal">1224</span>
<span class="normal">1225</span>
<span class="normal">1226</span>
<span class="normal">1227</span>
<span class="normal">1228</span>
<span class="normal">1229</span>
<span class="normal">1230</span>
<span class="normal">1231</span>
<span class="normal">1232</span>
<span class="normal">1233</span>
<span class="normal">1234</span>
<span class="normal">1235</span>
<span class="normal">1236</span>
<span class="normal">1237</span>
<span class="normal">1238</span>
<span class="normal">1239</span>
<span class="normal">1240</span>
<span class="normal">1241</span>
<span class="normal">1242</span>
<span class="normal">1243</span>
<span class="normal">1244</span>
<span class="normal">1245</span>
<span class="normal">1246</span>
<span class="normal">1247</span>
<span class="normal">1248</span>
<span class="normal">1249</span>
<span class="normal">1250</span>
<span class="normal">1251</span>
<span class="normal">1252</span>
<span class="normal">1253</span>
<span class="normal">1254</span>
<span class="normal">1255</span>
<span class="normal">1256</span>
<span class="normal">1257</span>
<span class="normal">1258</span>
<span class="normal">1259</span>
<span class="normal">1260</span>
<span class="normal">1261</span>
<span class="normal">1262</span>
<span class="normal">1263</span>
<span class="normal">1264</span>
<span class="normal">1265</span>
<span class="normal">1266</span>
<span class="normal">1267</span>
<span class="normal">1268</span>
<span class="normal">1269</span>
<span class="normal">1270</span>
<span class="normal">1271</span>
<span class="normal">1272</span>
<span class="normal">1273</span>
<span class="normal">1274</span>
<span class="normal">1275</span>
<span class="normal">1276</span>
<span class="normal">1277</span>
<span class="normal">1278</span>
<span class="normal">1279</span>
<span class="normal">1280</span>
<span class="normal">1281</span>
<span class="normal">1282</span>
<span class="normal">1283</span>
<span class="normal">1284</span>
<span class="normal">1285</span>
<span class="normal">1286</span>
<span class="normal">1287</span>
<span class="normal">1288</span>
<span class="normal">1289</span>
<span class="normal">1290</span>
<span class="normal">1291</span>
<span class="normal">1292</span>
<span class="normal">1293</span>
<span class="normal">1294</span>
<span class="normal">1295</span>
<span class="normal">1296</span>
<span class="normal">1297</span>
<span class="normal">1298</span>
<span class="normal">1299</span>
<span class="normal">1300</span>
<span class="normal">1301</span>
<span class="normal">1302</span>
<span class="normal">1303</span>
<span class="normal">1304</span>
<span class="normal">1305</span>
<span class="normal">1306</span>
<span class="normal">1307</span>
<span class="normal">1308</span>
<span class="normal">1309</span>
<span class="normal">1310</span>
<span class="normal">1311</span>
<span class="normal">1312</span>
<span class="normal">1313</span>
<span class="normal">1314</span>
<span class="normal">1315</span>
<span class="normal">1316</span>
<span class="normal">1317</span>
<span class="normal">1318</span>
<span class="normal">1319</span>
<span class="normal">1320</span>
<span class="normal">1321</span>
<span class="normal">1322</span>
<span class="normal">1323</span>
<span class="normal">1324</span>
<span class="normal">1325</span>
<span class="normal">1326</span>
<span class="normal">1327</span>
<span class="normal">1328</span>
<span class="normal">1329</span>
<span class="normal">1330</span>
<span class="normal">1331</span>
<span class="normal">1332</span>
<span class="normal">1333</span>
<span class="normal">1334</span>
<span class="normal">1335</span>
<span class="normal">1336</span>
<span class="normal">1337</span>
<span class="normal">1338</span>
<span class="normal">1339</span>
<span class="normal">1340</span>
<span class="normal">1341</span>
<span class="normal">1342</span>
<span class="normal">1343</span>
<span class="normal">1344</span>
<span class="normal">1345</span>
<span class="normal">1346</span>
<span class="normal">1347</span>
<span class="normal">1348</span>
<span class="normal">1349</span>
<span class="normal">1350</span>
<span class="normal">1351</span>
<span class="normal">1352</span>
<span class="normal">1353</span>
<span class="normal">1354</span>
<span class="normal">1355</span>
<span class="normal">1356</span>
<span class="normal">1357</span>
<span class="normal">1358</span>
<span class="normal">1359</span>
<span class="normal">1360</span>
<span class="normal">1361</span>
<span class="normal">1362</span>
<span class="normal">1363</span>
<span class="normal">1364</span>
<span class="normal">1365</span>
<span class="normal">1366</span>
<span class="normal">1367</span>
<span class="normal">1368</span>
<span class="normal">1369</span>
<span class="normal">1370</span>
<span class="normal">1371</span>
<span class="normal">1372</span>
<span class="normal">1373</span>
<span class="normal">1374</span>
<span class="normal">1375</span>
<span class="normal">1376</span>
<span class="normal">1377</span>
<span class="normal">1378</span>
<span class="normal">1379</span>
<span class="normal">1380</span>
<span class="normal">1381</span>
<span class="normal">1382</span>
<span class="normal">1383</span>
<span class="normal">1384</span>
<span class="normal">1385</span>
<span class="normal">1386</span>
<span class="normal">1387</span>
<span class="normal">1388</span>
<span class="normal">1389</span>
<span class="normal">1390</span>
<span class="normal">1391</span>
<span class="normal">1392</span>
<span class="normal">1393</span>
<span class="normal">1394</span>
<span class="normal">1395</span>
<span class="normal">1396</span>
<span class="normal">1397</span>
<span class="normal">1398</span>
<span class="normal">1399</span>
<span class="normal">1400</span>
<span class="normal">1401</span>
<span class="normal">1402</span>
<span class="normal">1403</span>
<span class="normal">1404</span>
<span class="normal">1405</span>
<span class="normal">1406</span>
<span class="normal">1407</span>
<span class="normal">1408</span>
<span class="normal">1409</span>
<span class="normal">1410</span>
<span class="normal">1411</span>
<span class="normal">1412</span>
<span class="normal">1413</span>
<span class="normal">1414</span>
<span class="normal">1415</span>
<span class="normal">1416</span>
<span class="normal">1417</span>
<span class="normal">1418</span>
<span class="normal">1419</span>
<span class="normal">1420</span>
<span class="normal">1421</span>
<span class="normal">1422</span>
<span class="normal">1423</span>
<span class="normal">1424</span>
<span class="normal">1425</span>
<span class="normal">1426</span>
<span class="normal">1427</span>
<span class="normal">1428</span>
<span class="normal">1429</span>
<span class="normal">1430</span>
<span class="normal">1431</span>
<span class="normal">1432</span>
<span class="normal">1433</span>
<span class="normal">1434</span>
<span class="normal">1435</span>
<span class="normal">1436</span>
<span class="normal">1437</span>
<span class="normal">1438</span>
<span class="normal">1439</span>
<span class="normal">1440</span>
<span class="normal">1441</span>
<span class="normal">1442</span>
<span class="normal">1443</span>
<span class="normal">1444</span>
<span class="normal">1445</span>
<span class="normal">1446</span>
<span class="normal">1447</span>
<span class="normal">1448</span>
<span class="normal">1449</span>
<span class="normal">1450</span>
<span class="normal">1451</span>
<span class="normal">1452</span>
<span class="normal">1453</span>
<span class="normal">1454</span>
<span class="normal">1455</span>
<span class="normal">1456</span>
<span class="normal">1457</span>
<span class="normal">1458</span>
<span class="normal">1459</span>
<span class="normal">1460</span>
<span class="normal">1461</span>
<span class="normal">1462</span>
<span class="normal">1463</span>
<span class="normal">1464</span>
<span class="normal">1465</span>
<span class="normal">1466</span>
<span class="normal">1467</span>
<span class="normal">1468</span>
<span class="normal">1469</span>
<span class="normal">1470</span>
<span class="normal">1471</span>
<span class="normal">1472</span>
<span class="normal">1473</span>
<span class="normal">1474</span>
<span class="normal">1475</span>
<span class="normal">1476</span>
<span class="normal">1477</span>
<span class="normal">1478</span>
<span class="normal">1479</span>
<span class="normal">1480</span>
<span class="normal">1481</span>
<span class="normal">1482</span>
<span class="normal">1483</span>
<span class="normal">1484</span>
<span class="normal">1485</span>
<span class="normal">1486</span>
<span class="normal">1487</span>
<span class="normal">1488</span>
<span class="normal">1489</span>
<span class="normal">1490</span>
<span class="normal">1491</span>
<span class="normal">1492</span>
<span class="normal">1493</span>
<span class="normal">1494</span>
<span class="normal">1495</span>
<span class="normal">1496</span>
<span class="normal">1497</span>
<span class="normal">1498</span>
<span class="normal">1499</span>
<span class="normal">1500</span>
<span class="normal">1501</span>
<span class="normal">1502</span>
<span class="normal">1503</span>
<span class="normal">1504</span>
<span class="normal">1505</span>
<span class="normal">1506</span>
<span class="normal">1507</span>
<span class="normal">1508</span>
<span class="normal">1509</span>
<span class="normal">1510</span>
<span class="normal">1511</span>
<span class="normal">1512</span>
<span class="normal">1513</span>
<span class="normal">1514</span>
<span class="normal">1515</span>
<span class="normal">1516</span>
<span class="normal">1517</span>
<span class="normal">1518</span>
<span class="normal">1519</span>
<span class="normal">1520</span>
<span class="normal">1521</span>
<span class="normal">1522</span>
<span class="normal">1523</span>
<span class="normal">1524</span>
<span class="normal">1525</span>
<span class="normal">1526</span>
<span class="normal">1527</span>
<span class="normal">1528</span>
<span class="normal">1529</span>
<span class="normal">1530</span>
<span class="normal">1531</span>
<span class="normal">1532</span>
<span class="normal">1533</span>
<span class="normal">1534</span>
<span class="normal">1535</span>
<span class="normal">1536</span>
<span class="normal">1537</span>
<span class="normal">1538</span>
<span class="normal">1539</span>
<span class="normal">1540</span>
<span class="normal">1541</span>
<span class="normal">1542</span>
<span class="normal">1543</span>
<span class="normal">1544</span>
<span class="normal">1545</span>
<span class="normal">1546</span>
<span class="normal">1547</span>
<span class="normal">1548</span>
<span class="normal">1549</span>
<span class="normal">1550</span>
<span class="normal">1551</span>
<span class="normal">1552</span>
<span class="normal">1553</span>
<span class="normal">1554</span>
<span class="normal">1555</span>
<span class="normal">1556</span>
<span class="normal">1557</span>
<span class="normal">1558</span>
<span class="normal">1559</span>
<span class="normal">1560</span>
<span class="normal">1561</span>
<span class="normal">1562</span>
<span class="normal">1563</span>
<span class="normal">1564</span>
<span class="normal">1565</span>
<span class="normal">1566</span>
<span class="normal">1567</span>
<span class="normal">1568</span>
<span class="normal">1569</span>
<span class="normal">1570</span>
<span class="normal">1571</span>
<span class="normal">1572</span>
<span class="normal">1573</span>
<span class="normal">1574</span>
<span class="normal">1575</span>
<span class="normal">1576</span>
<span class="normal">1577</span>
<span class="normal">1578</span>
<span class="normal">1579</span>
<span class="normal">1580</span>
<span class="normal">1581</span>
<span class="normal">1582</span>
<span class="normal">1583</span>
<span class="normal">1584</span>
<span class="normal">1585</span>
<span class="normal">1586</span>
<span class="normal">1587</span>
<span class="normal">1588</span>
<span class="normal">1589</span>
<span class="normal">1590</span>
<span class="normal">1591</span>
<span class="normal">1592</span>
<span class="normal">1593</span>
<span class="normal">1594</span>
<span class="normal">1595</span>
<span class="normal">1596</span>
<span class="normal">1597</span>
<span class="normal">1598</span>
<span class="normal">1599</span>
<span class="normal">1600</span>
<span class="normal">1601</span>
<span class="normal">1602</span>
<span class="normal">1603</span>
<span class="normal">1604</span>
<span class="normal">1605</span>
<span class="normal">1606</span>
<span class="normal">1607</span>
<span class="normal">1608</span>
<span class="normal">1609</span>
<span class="normal">1610</span>
<span class="normal">1611</span>
<span class="normal">1612</span>
<span class="normal">1613</span>
<span class="normal">1614</span>
<span class="normal">1615</span>
<span class="normal">1616</span>
<span class="normal">1617</span>
<span class="normal">1618</span>
<span class="normal">1619</span>
<span class="normal">1620</span>
<span class="normal">1621</span>
<span class="normal">1622</span>
<span class="normal">1623</span>
<span class="normal">1624</span>
<span class="normal">1625</span>
<span class="normal">1626</span>
<span class="normal">1627</span>
<span class="normal">1628</span>
<span class="normal">1629</span>
<span class="normal">1630</span>
<span class="normal">1631</span>
<span class="normal">1632</span>
<span class="normal">1633</span>
<span class="normal">1634</span>
<span class="normal">1635</span>
<span class="normal">1636</span>
<span class="normal">1637</span>
<span class="normal">1638</span>
<span class="normal">1639</span>
<span class="normal">1640</span>
<span class="normal">1641</span>
<span class="normal">1642</span>
<span class="normal">1643</span>
<span class="normal">1644</span>
<span class="normal">1645</span>
<span class="normal">1646</span>
<span class="normal">1647</span>
<span class="normal">1648</span>
<span class="normal">1649</span>
<span class="normal">1650</span>
<span class="normal">1651</span>
<span class="normal">1652</span>
<span class="normal">1653</span>
<span class="normal">1654</span>
<span class="normal">1655</span>
<span class="normal">1656</span>
<span class="normal">1657</span>
<span class="normal">1658</span>
<span class="normal">1659</span>
<span class="normal">1660</span>
<span class="normal">1661</span>
<span class="normal">1662</span>
<span class="normal">1663</span>
<span class="normal">1664</span>
<span class="normal">1665</span>
<span class="normal">1666</span>
<span class="normal">1667</span>
<span class="normal">1668</span>
<span class="normal">1669</span>
<span class="normal">1670</span>
<span class="normal">1671</span>
<span class="normal">1672</span>
<span class="normal">1673</span>
<span class="normal">1674</span>
<span class="normal">1675</span>
<span class="normal">1676</span>
<span class="normal">1677</span>
<span class="normal">1678</span>
<span class="normal">1679</span>
<span class="normal">1680</span>
<span class="normal">1681</span>
<span class="normal">1682</span>
<span class="normal">1683</span>
<span class="normal">1684</span>
<span class="normal">1685</span>
<span class="normal">1686</span>
<span class="normal">1687</span>
<span class="normal">1688</span>
<span class="normal">1689</span>
<span class="normal">1690</span>
<span class="normal">1691</span>
<span class="normal">1692</span>
<span class="normal">1693</span>
<span class="normal">1694</span>
<span class="normal">1695</span>
<span class="normal">1696</span>
<span class="normal">1697</span>
<span class="normal">1698</span>
<span class="normal">1699</span>
<span class="normal">1700</span>
<span class="normal">1701</span>
<span class="normal">1702</span>
<span class="normal">1703</span>
<span class="normal">1704</span>
<span class="normal">1705</span>
<span class="normal">1706</span>
<span class="normal">1707</span>
<span class="normal">1708</span>
<span class="normal">1709</span>
<span class="normal">1710</span>
<span class="normal">1711</span>
<span class="normal">1712</span>
<span class="normal">1713</span>
<span class="normal">1714</span>
<span class="normal">1715</span>
<span class="normal">1716</span>
<span class="normal">1717</span>
<span class="normal">1718</span>
<span class="normal">1719</span>
<span class="normal">1720</span>
<span class="normal">1721</span>
<span class="normal">1722</span>
<span class="normal">1723</span>
<span class="normal">1724</span>
<span class="normal">1725</span>
<span class="normal">1726</span>
<span class="normal">1727</span>
<span class="normal">1728</span>
<span class="normal">1729</span>
<span class="normal">1730</span>
<span class="normal">1731</span>
<span class="normal">1732</span>
<span class="normal">1733</span>
<span class="normal">1734</span>
<span class="normal">1735</span>
<span class="normal">1736</span>
<span class="normal">1737</span>
<span class="normal">1738</span>
<span class="normal">1739</span>
<span class="normal">1740</span>
<span class="normal">1741</span>
<span class="normal">1742</span>
<span class="normal">1743</span>
<span class="normal">1744</span>
<span class="normal">1745</span>
<span class="normal">1746</span>
<span class="normal">1747</span>
<span class="normal">1748</span>
<span class="normal">1749</span>
<span class="normal">1750</span>
<span class="normal">1751</span>
<span class="normal">1752</span>
<span class="normal">1753</span>
<span class="normal">1754</span>
<span class="normal">1755</span>
<span class="normal">1756</span>
<span class="normal">1757</span>
<span class="normal">1758</span>
<span class="normal">1759</span>
<span class="normal">1760</span>
<span class="normal">1761</span>
<span class="normal">1762</span>
<span class="normal">1763</span>
<span class="normal">1764</span>
<span class="normal">1765</span>
<span class="normal">1766</span>
<span class="normal">1767</span>
<span class="normal">1768</span>
<span class="normal">1769</span>
<span class="normal">1770</span>
<span class="normal">1771</span>
<span class="normal">1772</span>
<span class="normal">1773</span>
<span class="normal">1774</span>
<span class="normal">1775</span>
<span class="normal">1776</span>
<span class="normal">1777</span>
<span class="normal">1778</span>
<span class="normal">1779</span>
<span class="normal">1780</span>
<span class="normal">1781</span>
<span class="normal">1782</span>
<span class="normal">1783</span>
<span class="normal">1784</span>
<span class="normal">1785</span>
<span class="normal">1786</span>
<span class="normal">1787</span>
<span class="normal">1788</span>
<span class="normal">1789</span>
<span class="normal">1790</span>
<span class="normal">1791</span>
<span class="normal">1792</span>
<span class="normal">1793</span>
<span class="normal">1794</span>
<span class="normal">1795</span>
<span class="normal">1796</span>
<span class="normal">1797</span>
<span class="normal">1798</span>
<span class="normal">1799</span>
<span class="normal">1800</span>
<span class="normal">1801</span>
<span class="normal">1802</span>
<span class="normal">1803</span>
<span class="normal">1804</span>
<span class="normal">1805</span>
<span class="normal">1806</span>
<span class="normal">1807</span>
<span class="normal">1808</span>
<span class="normal">1809</span>
<span class="normal">1810</span>
<span class="normal">1811</span>
<span class="normal">1812</span>
<span class="normal">1813</span>
<span class="normal">1814</span>
<span class="normal">1815</span>
<span class="normal">1816</span>
<span class="normal">1817</span>
<span class="normal">1818</span>
<span class="normal">1819</span>
<span class="normal">1820</span>
<span class="normal">1821</span>
<span class="normal">1822</span>
<span class="normal">1823</span>
<span class="normal">1824</span>
<span class="normal">1825</span>
<span class="normal">1826</span>
<span class="normal">1827</span>
<span class="normal">1828</span>
<span class="normal">1829</span>
<span class="normal">1830</span>
<span class="normal">1831</span>
<span class="normal">1832</span>
<span class="normal">1833</span>
<span class="normal">1834</span>
<span class="normal">1835</span>
<span class="normal">1836</span>
<span class="normal">1837</span>
<span class="normal">1838</span>
<span class="normal">1839</span>
<span class="normal">1840</span>
<span class="normal">1841</span>
<span class="normal">1842</span>
<span class="normal">1843</span>
<span class="normal">1844</span>
<span class="normal">1845</span>
<span class="normal">1846</span>
<span class="normal">1847</span>
<span class="normal">1848</span>
<span class="normal">1849</span>
<span class="normal">1850</span>
<span class="normal">1851</span>
<span class="normal">1852</span>
<span class="normal">1853</span>
<span class="normal">1854</span>
<span class="normal">1855</span>
<span class="normal">1856</span>
<span class="normal">1857</span>
<span class="normal">1858</span>
<span class="normal">1859</span>
<span class="normal">1860</span>
<span class="normal">1861</span>
<span class="normal">1862</span>
<span class="normal">1863</span>
<span class="normal">1864</span>
<span class="normal">1865</span>
<span class="normal">1866</span>
<span class="normal">1867</span>
<span class="normal">1868</span>
<span class="normal">1869</span>
<span class="normal">1870</span>
<span class="normal">1871</span>
<span class="normal">1872</span>
<span class="normal">1873</span>
<span class="normal">1874</span>
<span class="normal">1875</span>
<span class="normal">1876</span>
<span class="normal">1877</span>
<span class="normal">1878</span>
<span class="normal">1879</span>
<span class="normal">1880</span>
<span class="normal">1881</span>
<span class="normal">1882</span>
<span class="normal">1883</span>
<span class="normal">1884</span>
<span class="normal">1885</span>
<span class="normal">1886</span>
<span class="normal">1887</span>
<span class="normal">1888</span>
<span class="normal">1889</span>
<span class="normal">1890</span>
<span class="normal">1891</span>
<span class="normal">1892</span>
<span class="normal">1893</span>
<span class="normal">1894</span>
<span class="normal">1895</span>
<span class="normal">1896</span>
<span class="normal">1897</span>
<span class="normal">1898</span>
<span class="normal">1899</span>
<span class="normal">1900</span>
<span class="normal">1901</span>
<span class="normal">1902</span>
<span class="normal">1903</span>
<span class="normal">1904</span>
<span class="normal">1905</span>
<span class="normal">1906</span>
<span class="normal">1907</span>
<span class="normal">1908</span>
<span class="normal">1909</span>
<span class="normal">1910</span>
<span class="normal">1911</span>
<span class="normal">1912</span>
<span class="normal">1913</span>
<span class="normal">1914</span>
<span class="normal">1915</span>
<span class="normal">1916</span>
<span class="normal">1917</span>
<span class="normal">1918</span>
<span class="normal">1919</span>
<span class="normal">1920</span>
<span class="normal">1921</span>
<span class="normal">1922</span>
<span class="normal">1923</span>
<span class="normal">1924</span>
<span class="normal">1925</span>
<span class="normal">1926</span>
<span class="normal">1927</span>
<span class="normal">1928</span>
<span class="normal">1929</span>
<span class="normal">1930</span>
<span class="normal">1931</span>
<span class="normal">1932</span>
<span class="normal">1933</span>
<span class="normal">1934</span>
<span class="normal">1935</span>
<span class="normal">1936</span>
<span class="normal">1937</span>
<span class="normal">1938</span>
<span class="normal">1939</span>
<span class="normal">1940</span>
<span class="normal">1941</span>
<span class="normal">1942</span>
<span class="normal">1943</span>
<span class="normal">1944</span>
<span class="normal">1945</span>
<span class="normal">1946</span>
<span class="normal">1947</span>
<span class="normal">1948</span>
<span class="normal">1949</span>
<span class="normal">1950</span>
<span class="normal">1951</span>
<span class="normal">1952</span>
<span class="normal">1953</span>
<span class="normal">1954</span>
<span class="normal">1955</span>
<span class="normal">1956</span>
<span class="normal">1957</span>
<span class="normal">1958</span>
<span class="normal">1959</span>
<span class="normal">1960</span>
<span class="normal">1961</span>
<span class="normal">1962</span>
<span class="normal">1963</span>
<span class="normal">1964</span>
<span class="normal">1965</span>
<span class="normal">1966</span>
<span class="normal">1967</span>
<span class="normal">1968</span>
<span class="normal">1969</span>
<span class="normal">1970</span>
<span class="normal">1971</span>
<span class="normal">1972</span>
<span class="normal">1973</span>
<span class="normal">1974</span>
<span class="normal">1975</span>
<span class="normal">1976</span>
<span class="normal">1977</span>
<span class="normal">1978</span>
<span class="normal">1979</span>
<span class="normal">1980</span>
<span class="normal">1981</span>
<span class="normal">1982</span>
<span class="normal">1983</span>
<span class="normal">1984</span>
<span class="normal">1985</span>
<span class="normal">1986</span>
<span class="normal">1987</span>
<span class="normal">1988</span>
<span class="normal">1989</span>
<span class="normal">1990</span>
<span class="normal">1991</span>
<span class="normal">1992</span>
<span class="normal">1993</span>
<span class="normal">1994</span>
<span class="normal">1995</span>
<span class="normal">1996</span>
<span class="normal">1997</span>
<span class="normal">1998</span>
<span class="normal">1999</span>
<span class="normal">2000</span>
<span class="normal">2001</span>
<span class="normal">2002</span>
<span class="normal">2003</span>
<span class="normal">2004</span>
<span class="normal">2005</span>
<span class="normal">2006</span>
<span class="normal">2007</span>
<span class="normal">2008</span>
<span class="normal">2009</span>
<span class="normal">2010</span>
<span class="normal">2011</span>
<span class="normal">2012</span>
<span class="normal">2013</span>
<span class="normal">2014</span>
<span class="normal">2015</span>
<span class="normal">2016</span>
<span class="normal">2017</span>
<span class="normal">2018</span>
<span class="normal">2019</span>
<span class="normal">2020</span>
<span class="normal">2021</span>
<span class="normal">2022</span>
<span class="normal">2023</span>
<span class="normal">2024</span>
<span class="normal">2025</span>
<span class="normal">2026</span>
<span class="normal">2027</span>
<span class="normal">2028</span>
<span class="normal">2029</span>
<span class="normal">2030</span>
<span class="normal">2031</span>
<span class="normal">2032</span>
<span class="normal">2033</span>
<span class="normal">2034</span>
<span class="normal">2035</span>
<span class="normal">2036</span>
<span class="normal">2037</span>
<span class="normal">2038</span>
<span class="normal">2039</span>
<span class="normal">2040</span>
<span class="normal">2041</span>
<span class="normal">2042</span>
<span class="normal">2043</span>
<span class="normal">2044</span>
<span class="normal">2045</span>
<span class="normal">2046</span>
<span class="normal">2047</span>
<span class="normal">2048</span>
<span class="normal">2049</span>
<span class="normal">2050</span>
<span class="normal">2051</span>
<span class="normal">2052</span>
<span class="normal">2053</span>
<span class="normal">2054</span>
<span class="normal">2055</span>
<span class="normal">2056</span>
<span class="normal">2057</span>
<span class="normal">2058</span>
<span class="normal">2059</span>
<span class="normal">2060</span>
<span class="normal">2061</span>
<span class="normal">2062</span>
<span class="normal">2063</span>
<span class="normal">2064</span>
<span class="normal">2065</span>
<span class="normal">2066</span>
<span class="normal">2067</span>
<span class="normal">2068</span>
<span class="normal">2069</span>
<span class="normal">2070</span>
<span class="normal">2071</span>
<span class="normal">2072</span>
<span class="normal">2073</span>
<span class="normal">2074</span>
<span class="normal">2075</span>
<span class="normal">2076</span>
<span class="normal">2077</span>
<span class="normal">2078</span>
<span class="normal">2079</span>
<span class="normal">2080</span>
<span class="normal">2081</span>
<span class="normal">2082</span>
<span class="normal">2083</span>
<span class="normal">2084</span>
<span class="normal">2085</span>
<span class="normal">2086</span>
<span class="normal">2087</span>
<span class="normal">2088</span>
<span class="normal">2089</span>
<span class="normal">2090</span>
<span class="normal">2091</span>
<span class="normal">2092</span>
<span class="normal">2093</span>
<span class="normal">2094</span>
<span class="normal">2095</span>
<span class="normal">2096</span>
<span class="normal">2097</span>
<span class="normal">2098</span>
<span class="normal">2099</span>
<span class="normal">2100</span>
<span class="normal">2101</span>
<span class="normal">2102</span>
<span class="normal">2103</span>
<span class="normal">2104</span>
<span class="normal">2105</span>
<span class="normal">2106</span>
<span class="normal">2107</span>
<span class="normal">2108</span>
<span class="normal">2109</span>
<span class="normal">2110</span>
<span class="normal">2111</span>
<span class="normal">2112</span>
<span class="normal">2113</span>
<span class="normal">2114</span>
<span class="normal">2115</span>
<span class="normal">2116</span>
<span class="normal">2117</span>
<span class="normal">2118</span>
<span class="normal">2119</span>
<span class="normal">2120</span>
<span class="normal">2121</span>
<span class="normal">2122</span>
<span class="normal">2123</span>
<span class="normal">2124</span>
<span class="normal">2125</span>
<span class="normal">2126</span>
<span class="normal">2127</span>
<span class="normal">2128</span>
<span class="normal">2129</span>
<span class="normal">2130</span>
<span class="normal">2131</span>
<span class="normal">2132</span>
<span class="normal">2133</span>
<span class="normal">2134</span>
<span class="normal">2135</span>
<span class="normal">2136</span>
<span class="normal">2137</span>
<span class="normal">2138</span>
<span class="normal">2139</span>
<span class="normal">2140</span>
<span class="normal">2141</span>
<span class="normal">2142</span>
<span class="normal">2143</span>
<span class="normal">2144</span>
<span class="normal">2145</span>
<span class="normal">2146</span>
<span class="normal">2147</span>
<span class="normal">2148</span>
<span class="normal">2149</span>
<span class="normal">2150</span>
<span class="normal">2151</span>
<span class="normal">2152</span>
<span class="normal">2153</span>
<span class="normal">2154</span>
<span class="normal">2155</span>
<span class="normal">2156</span>
<span class="normal">2157</span>
<span class="normal">2158</span>
<span class="normal">2159</span>
<span class="normal">2160</span>
<span class="normal">2161</span>
<span class="normal">2162</span>
<span class="normal">2163</span>
<span class="normal">2164</span>
<span class="normal">2165</span>
<span class="normal">2166</span>
<span class="normal">2167</span>
<span class="normal">2168</span>
<span class="normal">2169</span>
<span class="normal">2170</span>
<span class="normal">2171</span>
<span class="normal">2172</span>
<span class="normal">2173</span>
<span class="normal">2174</span>
<span class="normal">2175</span>
<span class="normal">2176</span>
<span class="normal">2177</span>
<span class="normal">2178</span>
<span class="normal">2179</span>
<span class="normal">2180</span>
<span class="normal">2181</span>
<span class="normal">2182</span>
<span class="normal">2183</span>
<span class="normal">2184</span>
<span class="normal">2185</span>
<span class="normal">2186</span>
<span class="normal">2187</span>
<span class="normal">2188</span>
<span class="normal">2189</span>
<span class="normal">2190</span>
<span class="normal">2191</span>
<span class="normal">2192</span>
<span class="normal">2193</span>
<span class="normal">2194</span>
<span class="normal">2195</span>
<span class="normal">2196</span>
<span class="normal">2197</span>
<span class="normal">2198</span>
<span class="normal">2199</span>
<span class="normal">2200</span>
<span class="normal">2201</span>
<span class="normal">2202</span>
<span class="normal">2203</span>
<span class="normal">2204</span>
<span class="normal">2205</span>
<span class="normal">2206</span>
<span class="normal">2207</span>
<span class="normal">2208</span>
<span class="normal">2209</span>
<span class="normal">2210</span>
<span class="normal">2211</span>
<span class="normal">2212</span>
<span class="normal">2213</span>
<span class="normal">2214</span>
<span class="normal">2215</span>
<span class="normal">2216</span>
<span class="normal">2217</span>
<span class="normal">2218</span>
<span class="normal">2219</span>
<span class="normal">2220</span>
<span class="normal">2221</span>
<span class="normal">2222</span>
<span class="normal">2223</span>
<span class="normal">2224</span>
<span class="normal">2225</span>
<span class="normal">2226</span>
<span class="normal">2227</span>
<span class="normal">2228</span>
<span class="normal">2229</span>
<span class="normal">2230</span>
<span class="normal">2231</span>
<span class="normal">2232</span>
<span class="normal">2233</span>
<span class="normal">2234</span>
<span class="normal">2235</span>
<span class="normal">2236</span>
<span class="normal">2237</span>
<span class="normal">2238</span>
<span class="normal">2239</span>
<span class="normal">2240</span>
<span class="normal">2241</span>
<span class="normal">2242</span>
<span class="normal">2243</span>
<span class="normal">2244</span>
<span class="normal">2245</span>
<span class="normal">2246</span>
<span class="normal">2247</span>
<span class="normal">2248</span>
<span class="normal">2249</span>
<span class="normal">2250</span>
<span class="normal">2251</span>
<span class="normal">2252</span>
<span class="normal">2253</span>
<span class="normal">2254</span>
<span class="normal">2255</span>
<span class="normal">2256</span>
<span class="normal">2257</span>
<span class="normal">2258</span>
<span class="normal">2259</span>
<span class="normal">2260</span>
<span class="normal">2261</span>
<span class="normal">2262</span>
<span class="normal">2263</span>
<span class="normal">2264</span></pre></div></td><td class="code"><div><pre><div id="l1" class="code_block"><span class="c">%====================================================================</span>
</div><div id="l2" class="code_block">
</div><div id="l3" class="code_block"><span class="k">\chapter</span><span class="nb">{</span>Using Tabling in XSB: A Tutorial Introduction<span class="nb">}</span> 
</div><div id="l4" class="code_block"><span class="k">\label</span><span class="nb">{</span>chap:TablingOverview<span class="nb">}</span>
</div><div id="l5" class="code_block">
</div><div id="l6" class="code_block">XSB has two ways of evaluating predicates.  The default is to use
</div><div id="l7" class="code_block">Prolog-style evaluation, but by using various declarations a
</div><div id="l8" class="code_block">programmer can also use tabled resolution which can provide a
</div><div id="l9" class="code_block">different, more declarative programming style than Prolog.  In this
</div><div id="l10" class="code_block">section we discuss various aspects of tabling and their implementation
</div><div id="l11" class="code_block">in XSB<span class="k">\@</span>.  Our aim in this section is to provide a user with enough
</div><div id="l12" class="code_block">information to be able to program productively with tables in XSB<span class="k">\@</span>.
</div><div id="l13" class="code_block">It is best to read this tutorial with a copy of XSB handy, since much
</div><div id="l14" class="code_block">of the information is presented through a series of exercises.
</div><div id="l15" class="code_block">
</div><div id="l16" class="code_block">For the theoretically inclined, XSB uses SLG resolution which can
</div><div id="l17" class="code_block">compute queries to non-floundering normal programs under the
</div><div id="l18" class="code_block">well-founded semantics~<span class="k">\cite</span><span class="nb">{</span>VGRS91<span class="nb">}</span>, and is guaranteed to terminate
</div><div id="l19" class="code_block">when these programs have the <span class="nb">{</span><span class="k">\em</span> bounded term-depth property<span class="nb">}</span>.  This
</div><div id="l20" class="code_block">tutorial covers only enough of the theory of tabling to explain how to
</div><div id="l21" class="code_block">program in XSB<span class="k">\@</span>.  For those interested, the web site contains papers
</div><div id="l22" class="code_block">covering in detail various aspects of tabling (often through the links
</div><div id="l23" class="code_block">for individuals involved in XSB)<span class="k">\@</span>.  An overview of SLG resolution,
</div><div id="l24" class="code_block">and practical evaluation strategies for it, are provided
</div><div id="l25" class="code_block">in~<span class="k">\cite</span><span class="nb">{</span>ChWa96,Swif99b,SaSW99,FSW98<span class="nb">}</span>.  The engine of XSB, the
</div><div id="l26" class="code_block">SLG-WAM, is an extension of the WAM <span class="k">\cite</span><span class="nb">{</span>DHWa83,AitK90<span class="nb">}</span>, and is
</div><div id="l27" class="code_block">described in~<span class="k">\cite</span><span class="nb">{</span>SaSw98,RRSSW98,JFLP-Scheduling,SaSW96,
</div><div id="l28" class="code_block">  ChSW95,CAT@PLILP-98,TST99,CuSW99b,CuiW00,CaSW02,MarS08b,Swif09a,MarS10,SwiW10a<span class="nb">}</span>
</div><div id="l29" class="code_block">as it is implemented in <span class="k">\version</span><span class="nb">{}</span> and its performance
</div><div id="l30" class="code_block">analyzed. Examples of large-scale applications that use tabling are
</div><div id="l31" class="code_block">overviewed in~<span class="k">\cite</span><span class="nb">{</span>syntactica, semantica, CoDS96, DRW96, RRRSSW97,
</div><div id="l32" class="code_block">  Boul97,CuSW99a,GSTPD00,SwiW12<span class="nb">}</span>.
</div><div id="l33" class="code_block">
</div><div id="l34" class="code_block"><span class="c">%=====================================================================</span>
</div><div id="l35" class="code_block">
</div><div id="l36" class="code_block"><span class="k">\section</span><span class="nb">{</span>Tabling in the Context of a Prolog System<span class="nb">}</span>
</div><div id="l37" class="code_block"><span class="k">\label</span><span class="nb">{</span>tabling<span class="nb">_</span>env<span class="nb">}</span>
</div><div id="l38" class="code_block">
</div><div id="l39" class="code_block">Before describing how to program using tabling it is perhaps
</div><div id="l40" class="code_block">worthwhile to review some of the goals of XSB&#39;s implementation of
</div><div id="l41" class="code_block">tabling.  Among them are:
</div><div id="l42" class="code_block"><span class="k">\begin</span><span class="nb">{</span>enumerate<span class="nb">}</span>
</div><div id="l43" class="code_block"><span class="k">\item</span>	To execute tabled predicates at the speed of compiled Prolog.
</div><div id="l44" class="code_block"><span class="k">\item</span>	To ensure that the speed of compiled Prolog is not slowed
</div><div id="l45" class="code_block">	significantly by adding the option of tabling.
</div><div id="l46" class="code_block"><span class="k">\item</span>	To ensure that the functionality of Prolog is not compromised
</div><div id="l47" class="code_block"> 	by support for tabling.
</div><div id="l48" class="code_block"><span class="k">\item</span>   To provide Prolog functionality in tabled predicates and
</div><div id="l49" class="code_block">	operators whenever it is semantically sensible to do so.
</div><div id="l50" class="code_block"><span class="k">\item</span>	To provide standard predicates to manipulate tables
</div><div id="l51" class="code_block">	taken as data structures in themselves.
</div><div id="l52" class="code_block"><span class="k">\end</span><span class="nb">{</span>enumerate<span class="nb">}</span>
</div><div id="l53" class="code_block">
</div><div id="l54" class="code_block">Goals 1 and 2 are addressed by XSB&#39;s engine, which in <span class="k">\version</span><span class="nb">{}</span> is
</div><div id="l55" class="code_block">based on a virtual machine called the SLG-WAM<span class="k">\@</span>.  The overhead for SLD
</div><div id="l56" class="code_block">resolution using this machine is small, and usually less than 5<span class="k">\%</span>.
</div><div id="l57" class="code_block">Thus when XSB is used simply as a Prolog system (i.e., no tabling is
</div><div id="l58" class="code_block">used), it is reasonably competitive with other Prolog implementations
</div><div id="l59" class="code_block">based on a WAM emulator written in C or assembly.  For example, when
</div><div id="l60" class="code_block">compiled as a threaded interpreter (see Chapter~<span class="k">\ref</span><span class="nb">{</span>system<span class="nb">}</span>) XSB
</div><div id="l61" class="code_block"><span class="k">\version\</span> is about two times slower than Quintus 3.1.1 or emulated
</div><div id="l62" class="code_block">SICStus Prolog 3.1.
</div><div id="l63" class="code_block"><span class="c">%</span>
</div><div id="l64" class="code_block">Goals 3, 4 and 5 have been nearly met, but there are a few instances
</div><div id="l65" class="code_block">in which interaction of tabling with a Prolog construct has not been
</div><div id="l66" class="code_block">accomplished, or is perhaps impossible.  Accordingly we discuss these
</div><div id="l67" class="code_block">instances throughout this chapter.  XSB is still under development
</div><div id="l68" class="code_block">however, so that future versions may support more transparent mixing
</div><div id="l69" class="code_block">of Prolog and tabled code.
</div><div id="l70" class="code_block"><span class="k">\comment</span><span class="nb">{</span>
</div><div id="l71" class="code_block"> (e.g. allowing tabled predicates in the
</div><div id="l72" class="code_block">scope of <span class="k">\verb</span>|<span class="k">\+</span>/1|) or adding Prolog functionality to tabled
</div><div id="l73" class="code_block">predicates or operators (e.g. allowing non-ground negation in <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l74" class="code_block">tnot/1<span class="nb">}</span>).
</div><div id="l75" class="code_block"><span class="nb">}</span>
</div><div id="l76" class="code_block"><span class="c">%=====================================================================</span>
</div><div id="l77" class="code_block">
</div><div id="l78" class="code_block"><span class="k">\section</span><span class="nb">{</span>Definite Programs<span class="nb">}</span>
</div><div id="l79" class="code_block"><span class="k">\label</span><span class="nb">{</span>sec:def<span class="nb">}</span>
</div><div id="l80" class="code_block">
</div><div id="l81" class="code_block">Definite programs, also called <span class="k">\emph</span><span class="nb">{</span>Horn Clause Programs<span class="nb">}</span>, are Prolog
</div><div id="l82" class="code_block">programs without negation or aggregation.  In XSB, this means without
</div><div id="l83" class="code_block">the <span class="k">\verb</span>|<span class="k">\+</span>/1|, <span class="nb">{</span><span class="k">\tt</span> fail<span class="k">\_if</span>/1<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> not/1<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> tnot/1<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l84" class="code_block">  setof/3<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> bagof/3<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> tt findall/3<span class="nb">}</span> or other aggregation
</div><div id="l85" class="code_block">operators.  Consider the Prolog program
</div><div id="l86" class="code_block"><span class="k">\begin</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l87" class="code_block"><span class="k">\begin</span><span class="nb">{</span>minipage<span class="nb">}{</span>3.8in<span class="nb">}</span>
</div><div id="l88" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l89" class="code_block">path(X,Y) :- path(X,Z), edge(Z,Y).
</div><div id="l90" class="code_block">path(X,Y) :- edge(X,Y).
</div><div id="l91" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>						       
</div><div id="l92" class="code_block"><span class="k">\end</span><span class="nb">{</span>minipage<span class="nb">}</span>
</div><div id="l93" class="code_block"><span class="k">\end</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l94" class="code_block">together with the query <span class="nb">{</span><span class="k">\tt</span> ?- path(1,Y)<span class="nb">}</span>.  This program has a
</div><div id="l95" class="code_block">simple, declarative meaning: there is a path from <span class="nb">{</span><span class="k">\tt</span> X<span class="nb">}</span> to <span class="nb">{</span><span class="k">\tt</span> Y<span class="nb">}</span>
</div><div id="l96" class="code_block">if there is a path from <span class="nb">{</span><span class="k">\tt</span> X<span class="nb">}</span> to some node <span class="nb">{</span><span class="k">\tt</span> Z<span class="nb">}</span> and there is an
</div><div id="l97" class="code_block">edge from <span class="nb">{</span><span class="k">\tt</span> Z<span class="nb">}</span> to <span class="nb">{</span><span class="k">\tt</span> Y<span class="nb">}</span>, or if there is an edge from <span class="nb">{</span><span class="k">\tt</span> X<span class="nb">}</span> to
</div><div id="l98" class="code_block"><span class="nb">{</span><span class="k">\tt</span> Y<span class="nb">}</span><span class="k">\@</span>.  Prolog, however, enters into an infinite loop when
</div><div id="l99" class="code_block">computing an answer to this query.  The inability of Prolog to answer
</div><div id="l100" class="code_block">such queries, which arise frequently, comprises one of its major
</div><div id="l101" class="code_block">limitations as an implementation of logic.
</div><div id="l102" class="code_block">
</div><div id="l103" class="code_block">A number of approaches have been developed to address this problem by
</div><div id="l104" class="code_block">reusing partial answers to the query <span class="nb">{</span><span class="k">\tt</span> path(1,Y)<span class="nb">}</span>
</div><div id="l105" class="code_block"><span class="k">\cite</span><span class="nb">{</span>Diet87,TaSa86,BMSU86,Viei89,Walk93<span class="nb">}</span>.  The ideas behind these
</div><div id="l106" class="code_block">algorithms can be described in the following manner.  Calls to tabled
</div><div id="l107" class="code_block">predicates, such as <span class="nb">{</span><span class="k">\tt</span> path(1,Y)<span class="nb">}</span> in the above example, are stored
</div><div id="l108" class="code_block">in a searchable structure together with their proven instances.  This
</div><div id="l109" class="code_block">collection of <span class="k">\emph</span><span class="nb">{</span>tabled subgoals<span class="nb">}</span> paired with their <span class="k">\emph</span><span class="nb">{</span>answers<span class="nb">}</span>,
</div><div id="l110" class="code_block">generally referred to as a <span class="k">\emph</span><span class="nb">{</span>table<span class="nb">}</span>, is consulted whenever a new
</div><div id="l111" class="code_block">call, <span class="s">$</span><span class="nb">C</span><span class="s">$</span>, to a tabled predicate is issued.  If <span class="s">$</span><span class="nb">C</span><span class="s">$</span> is sufficiently
</div><div id="l112" class="code_block">similar to a tabled subgoal <span class="s">$</span><span class="nb">S</span><span class="s">$</span>, then the set of answers, <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span>,
</div><div id="l113" class="code_block">associated with <span class="s">$</span><span class="nb">S</span><span class="s">$</span> may be used to satisfy <span class="s">$</span><span class="nb">C</span><span class="s">$</span>.
</div><div id="l114" class="code_block"><span class="c">%\footnote{We use</span>
</div><div id="l115" class="code_block"><span class="c">%the term ``answer set&#39;&#39; to describe the set of answers associated with</span>
</div><div id="l116" class="code_block"><span class="c">%a given subgoal during a given state of computation.  As such, it has</span>
</div><div id="l117" class="code_block"><span class="c">%no relation to the use of the term ``answer set&#39;&#39; in the non-monotonic</span>
</div><div id="l118" class="code_block"><span class="c">%literature.}\@.  </span>
</div><div id="l119" class="code_block">In such instances, <span class="s">$</span><span class="nb">C</span><span class="s">$</span> is resolved against the answers in <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span>, and
</div><div id="l120" class="code_block">hence we refer to the call <span class="s">$</span><span class="nb">C</span><span class="s">$</span> as a
</div><div id="l121" class="code_block"><span class="k">\emph</span><span class="nb">{</span>consumer<span class="nb">}</span><span class="k">\index</span><span class="nb">{</span>tabling!consumer<span class="nb">}</span> of <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span> (or <span class="s">$</span><span class="nb">S</span><span class="s">$</span>)<span class="k">\@</span>.  If there
</div><div id="l122" class="code_block">is no such <span class="s">$</span><span class="nb">S</span><span class="s">$</span>, then <span class="s">$</span><span class="nb">C</span><span class="s">$</span> is entered into the table and is resolved
</div><div id="l123" class="code_block">against program clauses as in Prolog~---~i.e., using SLD~resolution.
</div><div id="l124" class="code_block">As each answer is derived during this process, it is inserted into the
</div><div id="l125" class="code_block">table entry associated with <span class="s">$</span><span class="nb">C</span><span class="s">$</span> if it contains information not already
</div><div id="l126" class="code_block">in <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span><span class="k">\@</span>.  In this second case, we refer to <span class="s">$</span><span class="nb">C</span><span class="s">$</span> as a
</div><div id="l127" class="code_block"><span class="k">\emph</span><span class="nb">{</span>generator<span class="nb">}</span>, or <span class="k">\emph</span><span class="nb">{</span>producer<span class="nb">}</span><span class="k">\index</span><span class="nb">{</span>tabling!producer,
</div><div id="l128" class="code_block">  generator<span class="nb">}</span>, as resolution of <span class="s">$</span><span class="nb">C</span><span class="s">$</span> in this manner produces the answers
</div><div id="l129" class="code_block">stored in its table entry.  If the answer is in fact added to this
</div><div id="l130" class="code_block">set, then it is additionally scheduled to be returned to all consumers
</div><div id="l131" class="code_block">of <span class="s">$</span><span class="nb">C</span><span class="s">$</span><span class="k">\@</span>.  If instead it is rejected as redundant, then the evaluation
</div><div id="l132" class="code_block">simply fails and backtracks to generate more answers.
</div><div id="l133" class="code_block">
</div><div id="l134" class="code_block">Notice that since consuming subgoals resolve against unique answers
</div><div id="l135" class="code_block">rather than repeatedly against program clauses, tabling will terminate
</div><div id="l136" class="code_block">whenever
</div><div id="l137" class="code_block"><span class="k">\begin</span><span class="nb">{</span>enumerate<span class="nb">}</span>
</div><div id="l138" class="code_block"><span class="k">\item</span> a finite number of subgoals are encountered during query
</div><div id="l139" class="code_block">      evaluation, and
</div><div id="l140" class="code_block"><span class="k">\item</span> each of these subgoals has a finite number of answers.
</div><div id="l141" class="code_block"><span class="k">\end</span><span class="nb">{</span>enumerate<span class="nb">}</span>
</div><div id="l142" class="code_block">Indeed, it can be proven that for any program with the <span class="k">\emph</span><span class="nb">{</span>bounded
</div><div id="l143" class="code_block">term depth property<span class="nb">}</span>~---~roughly, where all terms generated in a
</div><div id="l144" class="code_block">program have a maximum depth~---~SLG computation will terminate.
</div><div id="l145" class="code_block">These programs include the important class of <span class="k">\emph</span><span class="nb">{</span>Datalog<span class="nb">}</span> programs.
</div><div id="l146" class="code_block">
</div><div id="l147" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l148" class="code_block">Predicates can be declared tabled in a variety of ways.  A common form
</div><div id="l149" class="code_block">is the compiler directive <span class="k">\stdrefindex</span><span class="nb">{</span>table/1<span class="nb">}</span>
</div><div id="l150" class="code_block"><span class="sb">\[</span>
</div><div id="l151" class="code_block"><span class="nb">	</span><span class="nv">\verb</span><span class="nb">|:</span><span class="o">-</span><span class="nb"> table | P_</span><span class="m">1</span><span class="nb">, </span><span class="nv">\ldots</span><span class="nb">, P_n.</span>
</div><div id="l152" class="code_block"><span class="s">\]</span>
</div><div id="l153" class="code_block">where each <span class="s">$</span><span class="nb">P_i</span><span class="s">$</span> is a predicate indicator or callable term.  More
</div><div id="l154" class="code_block">generally 
</div><div id="l155" class="code_block"><span class="sb">\[</span>
</div><div id="l156" class="code_block"><span class="nb">	</span><span class="nv">\verb</span><span class="nb">|:</span><span class="o">-</span><span class="nb"> table | P_</span><span class="m">1</span><span class="nb">, </span><span class="nv">\ldots</span><span class="nb">, P_n</span><span class="nv">\</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> as</span><span class="nv">\</span><span class="nb"> }Options.</span>
</div><div id="l157" class="code_block"><span class="s">\]</span>
</div><div id="l158" class="code_block">allows a user to specify different types of tabling through <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l159" class="code_block">  Options<span class="nb">}</span> along with other properties of the designated predicates
</div><div id="l160" class="code_block">For static predicates, these directives must be added to the file
</div><div id="l161" class="code_block">containing the clauses of the predicate(s) to be tabled, and the
</div><div id="l162" class="code_block">directives cause the predicates to be compiled with
</div><div id="l163" class="code_block">tabling~<span class="k">\footnote</span><span class="nb">{</span>In <span class="k">\version</span>, tabling does not work together with
</div><div id="l164" class="code_block">  multi-file predicates.<span class="nb">}</span>.  For dynamic predicates, the executable
</div><div id="l165" class="code_block">directives
</div><div id="l166" class="code_block"><span class="sb">\[</span>
</div><div id="l167" class="code_block"><span class="nb">       </span><span class="nv">\verb</span><span class="nb">| ?</span><span class="o">-</span><span class="nb"> table | P_</span><span class="m">1</span><span class="nb">, </span><span class="nv">\ldots</span><span class="nb"> P_n.</span>
</div><div id="l168" class="code_block"><span class="s">\]</span>
</div><div id="l169" class="code_block">and 
</div><div id="l170" class="code_block"><span class="sb">\[</span>
</div><div id="l171" class="code_block"><span class="nb">	</span><span class="nv">\verb</span><span class="nb">|?</span><span class="o">-</span><span class="nb"> table | P_</span><span class="m">1</span><span class="nb">, </span><span class="nv">\ldots</span><span class="nb">, P_n</span><span class="nv">\</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> as</span><span class="nv">\</span><span class="nb"> }Options.</span>
</div><div id="l172" class="code_block"><span class="s">\]</span>
</div><div id="l173" class="code_block">cause a <span class="s">$</span><span class="nb">P_i</span><span class="s">$</span> to be tabled (with the appropriate options) if no
</div><div id="l174" class="code_block">clauses have been asserted for <span class="s">$</span><span class="nb">P_i</span><span class="s">$</span>.
</div><div id="l175" class="code_block">
</div><div id="l176" class="code_block"><span class="k">\paragraph</span><span class="nb">{</span>Exercises<span class="nb">}</span>
</div><div id="l177" class="code_block">Unless otherwise noted, the file
</div><div id="l178" class="code_block"><span class="k">\textup</span><span class="nb">{</span><span class="k">\texttt</span><span class="nb">{</span><span class="k">\$</span>XSB<span class="k">\_DIR</span>/examples/table<span class="k">\_examples</span>.P<span class="nb">}}</span> contains all
</div><div id="l179" class="code_block">the code for the running examples in this section.  Invoke XSB with its
</div><div id="l180" class="code_block">default settings (i.e., don&#39;t supply additional options) when working
</div><div id="l181" class="code_block">through the following exercises.
</div><div id="l182" class="code_block">
</div><div id="l183" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l184" class="code_block">Consult <span class="k">\textup</span><span class="nb">{</span><span class="k">\texttt</span><span class="nb">{</span><span class="k">\$</span>XSB<span class="k">\_DIR</span>/examples/table<span class="k">\_examples</span>.P<span class="nb">}}</span> into
</div><div id="l185" class="code_block">XSB and and try the goal
</div><div id="l186" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l187" class="code_block">         ?- path(1,X).
</div><div id="l188" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l189" class="code_block">and continue typing <span class="k">\verb</span>|;&lt;RETURN&gt;| until you have exhausted all
</div><div id="l190" class="code_block">answers.  Now, try rewriting the <span class="k">\code</span><span class="nb">{</span>path/2<span class="nb">}</span> predicate as it would
</div><div id="l191" class="code_block">be written in Prolog~---~and without a tabling declaration.  Will it
</div><div id="l192" class="code_block">now terminate for the provided <span class="nb">{</span><span class="k">\tt</span> edge/2<span class="nb">}</span> relation?  (Remember, in
</div><div id="l193" class="code_block">XSB you can always hit <span class="k">\verb</span>|&lt;ctrl&gt;-C| if you go into an infinite
</div><div id="l194" class="code_block">loop).<span class="k">\fillBox</span>
</div><div id="l195" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l196" class="code_block">
</div><div id="l197" class="code_block">The return of answers in tabling aids in filtering out redundant
</div><div id="l198" class="code_block">computations -- indeed it is this property which makes tabling
</div><div id="l199" class="code_block">terminate for many classes of programs.  The <span class="nb">{</span><span class="k">\tt</span> same generation<span class="nb">}</span>
</div><div id="l200" class="code_block">program furnishes a case of the usefulness of tabling for optimizing a
</div><div id="l201" class="code_block">Prolog program.
</div><div id="l202" class="code_block">
</div><div id="l203" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>ex:samegen<span class="nb">}</span>
</div><div id="l204" class="code_block">If you are <span class="nb">{</span><span class="k">\em</span> still<span class="nb">}</span> curious, load in the file <span class="nb">{</span><span class="k">\tt</span> cyl.P<span class="nb">}</span> in the
</div><div id="l205" class="code_block"><span class="k">\verb</span>|<span class="s">$</span><span class="nb">XSB_DIR</span><span class="o">/</span><span class="nb">examples| directory using the command.</span>
</div><div id="l206" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l207" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> load_dync</span><span class="o">(</span><span class="nb">cyl.P</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l208" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l209" class="code_block"><span class="nb">and then type the query</span>
</div><div id="l210" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l211" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> same_generation</span><span class="o">(</span><span class="nb">X,X</span><span class="o">)</span><span class="nb">,fail.</span>
</div><div id="l212" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l213" class="code_block"><span class="nb">Now rewrite the {</span><span class="nv">\tt</span><span class="nb"> same</span><span class="nv">\_</span><span class="nb">generation</span><span class="o">/</span><span class="m">2</span><span class="nb">} program so that it does not</span>
</div><div id="l214" class="code_block"><span class="nb">use tabling and retry the same query.  What happens?  </span><span class="o">(</span><span class="nb">Be</span>
</div><div id="l215" class="code_block"><span class="nb">patient~</span><span class="o">---</span><span class="nb">~or use </span><span class="nv">\verb</span><span class="nb">|&lt;ctrl&gt;</span><span class="o">-</span><span class="nb">C|</span><span class="o">)</span><span class="nb">.</span><span class="nv">\fillBox</span>
</div><div id="l216" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l217" class="code_block">
</div><div id="l218" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise}</span>
</div><div id="l219" class="code_block"><span class="nb">The file {</span><span class="nv">\tt</span><span class="nb"> table</span><span class="nv">\_</span><span class="nb">examples.P} contains a set of facts</span>
</div><div id="l220" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l221" class="code_block"><span class="nb">         ordered_goal</span><span class="o">(</span><span class="nb">one</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l222" class="code_block"><span class="nb">         ordered_goal</span><span class="o">(</span><span class="nb">two</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l223" class="code_block"><span class="nb">         ordered_goal</span><span class="o">(</span><span class="nb">three</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l224" class="code_block"><span class="nb">         ordered_goal</span><span class="o">(</span><span class="nb">four</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l225" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l226" class="code_block"><span class="nb">Clearly, the query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> ordered</span><span class="nv">\_</span><span class="nb">goal</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} will return the answers</span>
</div><div id="l227" class="code_block"><span class="nb">in the expected order.  {</span><span class="nv">\tt</span><span class="nb"> table</span><span class="nv">\_</span><span class="nb">examples.P} also contains a predicate</span>
</div><div id="l228" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l229" class="code_block"><span class="nb">         :</span><span class="o">-</span><span class="nb"> table table_ordered_goal</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l230" class="code_block"><span class="nb">         table_ordered_goal</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> ordered_goal</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l231" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l232" class="code_block"><span class="nb">which simply calls {</span><span class="nv">\tt</span><span class="nb"> ordered</span><span class="nv">\_</span><span class="nb">goal</span><span class="o">/</span><span class="m">1</span><span class="nb">} and tables its answers</span>
</div><div id="l233" class="code_block"><span class="o">(</span><span class="nb">tabling is unnecessary in this case, and is only used for</span>
</div><div id="l234" class="code_block"><span class="nb">illustration</span><span class="o">)</span><span class="nb">.  Call the query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> table</span><span class="nv">\_</span><span class="nb">ordered</span><span class="nv">\_</span><span class="nb">goal</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} and</span>
</div><div id="l235" class="code_block"><span class="nb">backtrack through the answers.  In what order are the answers</span>
</div><div id="l236" class="code_block"><span class="nb">returned?</span>
</div><div id="l237" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l238" class="code_block"><span class="c">%-------------------------------------------------------------------------</span>
</div><div id="l239" class="code_block"><span class="nv">\comment</span><span class="nb">{</span>
</div><div id="l240" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise}</span>
</div><div id="l241" class="code_block"><span class="nb">Consult this file into XSB and type the query</span>
</div><div id="l242" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l243" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="m">1</span><span class="nb">,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l244" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l245" class="code_block"><span class="nb">and continue typing </span><span class="nv">\verb</span><span class="nb">|;&lt;RETURN&gt;| until you have exhausted all</span>
</div><div id="l246" class="code_block"><span class="nb">answers.  Type the query again.  Can you guess why the order of</span>
</div><div id="l247" class="code_block"><span class="nb">answers is different?  Now type</span>
</div><div id="l248" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l249" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> abolish_all_tables.</span>
</div><div id="l250" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l251" class="code_block"><span class="nb">and retry the </span><span class="nv">\code</span><span class="nb">{path</span><span class="o">/</span><span class="m">2</span><span class="nb">} query.</span><span class="nv">\fillBox</span>
</div><div id="l252" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l253" class="code_block"><span class="nb">}</span>
</div><div id="l254" class="code_block"><span class="c">%-------------------------------------------------------------------------</span>
</div><div id="l255" class="code_block"><span class="nv">\index</span><span class="nb">{termination}</span>
</div><div id="l256" class="code_block"><span class="nb">The examples stress two differences between tabling and SLD resolution</span>
</div><div id="l257" class="code_block"><span class="nb">beyond termination properties.  First, that each solution to a tabled</span>
</div><div id="l258" class="code_block"><span class="nb">subgoal is returned only once~</span><span class="o">---</span><span class="nb">~a property that is helpful not only</span>
</div><div id="l259" class="code_block"><span class="nb">for {</span><span class="nv">\tt</span><span class="nb"> path</span><span class="o">/</span><span class="m">2</span><span class="nb">} but also for {</span><span class="nv">\tt</span><span class="nb"> same</span><span class="nv">\_</span><span class="nb">generation</span><span class="o">/</span><span class="m">2</span><span class="nb">} which</span>
</div><div id="l260" class="code_block"><span class="nb">terminates in Prolog.  Second, because answers are sometimes obtained</span>
</div><div id="l261" class="code_block"><span class="nb">using program clauses and sometimes using the table, answers may be</span>
</div><div id="l262" class="code_block"><span class="nb">returned in an unaccustomed order.</span>
</div><div id="l263" class="code_block">
</div><div id="l264" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{Tabling Dynamic Predicates}</span>
</div><div id="l265" class="code_block">
</div><div id="l266" class="code_block"><span class="nb">Dynamic predicates may be tabled just as static predicates, as the</span>
</div><div id="l267" class="code_block"><span class="nb">following exercise shows.</span>
</div><div id="l268" class="code_block">
</div><div id="l269" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise}</span>
</div><div id="l270" class="code_block"><span class="nb">For instance, restart XSB and at the prompt type the directive</span>
</div><div id="l271" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l272" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> table</span><span class="o">(</span><span class="nb">dyn_path</span><span class="o">/</span><span class="m">2</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l273" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l274" class="code_block"><span class="nb">and </span>
</div><div id="l275" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l276" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> load_dyn</span><span class="o">(</span><span class="nb">dyn_examples</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l277" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l278" class="code_block"><span class="nb">Try the queries to {</span><span class="nv">\tt</span><span class="nb"> path</span><span class="o">/</span><span class="m">2</span><span class="nb">} of the previous examples.  Note that</span>
</div><div id="l279" class="code_block"><span class="nb">it is important to dynamically load {</span><span class="nv">\tt</span><span class="nb"> dyn</span><span class="nv">\_</span><span class="nb">examples.P} </span><span class="o">---</span>
</div><div id="l280" class="code_block"><span class="nb">otherwise the code in the file will be compiled without knowledge of</span>
</div><div id="l281" class="code_block"><span class="nb">the tabling declaration.</span><span class="nv">\fillBox</span>
</div><div id="l282" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l283" class="code_block">
</div><div id="l284" class="code_block"><span class="nb">In general, as long as the directive {</span><span class="nv">\tt</span><span class="nb"> table</span><span class="o">/</span><span class="m">1</span><span class="nb">} is executed before</span>
</div><div id="l285" class="code_block"><span class="nb">asserting </span><span class="o">(</span><span class="nb">or dynamically loading</span><span class="o">)</span><span class="nb"> the predicates referred to in the</span>
</div><div id="l286" class="code_block"><span class="nb">directive, any dynamic predicate can be tabled.</span>
</div><div id="l287" class="code_block">
</div><div id="l288" class="code_block"><span class="nv">\index</span><span class="nb">{termination}</span>
</div><div id="l289" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{Letting XSB Decide What to Table}</span>
</div><div id="l290" class="code_block"><span class="nb">Other tabling declarations are also provided.  Often it is tedious to</span>
</div><div id="l291" class="code_block"><span class="nb">decide which predicates must be tabled.  To address this, XSB can</span>
</div><div id="l292" class="code_block"><span class="nb">automatically table predicates in files.  The declaration {</span><span class="nv">\tt</span>
</div><div id="l293" class="code_block"><span class="nb">  auto</span><span class="nv">\_</span><span class="nb">table}</span><span class="nv">\index</span><span class="nb">{declarations</span><span class="o">!</span><span class="nv">\texttt</span><span class="nb">{auto</span><span class="nv">\_</span><span class="nb">table}} chooses predicates to table</span>
</div><div id="l294" class="code_block"><span class="nb">to assist in termination, while {</span><span class="nv">\tt</span>
</div><div id="l295" class="code_block"><span class="nb">  suppl</span><span class="nv">\_</span><span class="nb">table}</span><span class="nv">\index</span><span class="nb">{declarations</span><span class="o">!</span><span class="nv">\texttt</span><span class="nb">{suppl</span><span class="nv">\_</span><span class="nb">table}} chooses predicates to</span>
</div><div id="l296" class="code_block"><span class="nb">table to optimize data</span><span class="o">-</span><span class="nb">oriented queries.  Both are explained in</span>
</div><div id="l297" class="code_block"><span class="nv">\refsec</span><span class="nb">{sec:CompilerOptions}.~</span><span class="nv">\footnote</span><span class="nb">{The reader may have noted that</span>
</div><div id="l298" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> table</span><span class="o">/</span><span class="m">1</span><span class="nb">}, is referred to as a </span><span class="nv">\emph</span><span class="nb">{directive}, while {</span><span class="nv">\tt</span>
</div><div id="l299" class="code_block"><span class="nb">    auto</span><span class="nv">\_</span><span class="nb">table</span><span class="o">/</span><span class="m">0</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> suppl</span><span class="nv">\_</span><span class="nb">table</span><span class="o">/</span><span class="m">0</span><span class="nb">} were referred to as</span>
</div><div id="l300" class="code_block"><span class="nb">  </span><span class="nv">\emph</span><span class="nb">{declarations}.  The difference is that at the command line,</span>
</div><div id="l301" class="code_block"><span class="nb">  user can execute a directive but not a compiler declaration.}.</span>
</div><div id="l302" class="code_block">
</div><div id="l303" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l304" class="code_block">
</div><div id="l305" class="code_block"><span class="nv">\subsection</span><span class="nb">{Call Variance vs. Call Subsumption}</span>
</div><div id="l306" class="code_block"><span class="nv">\label</span><span class="nb">{sec:SimilarityMeasures}</span>
</div><div id="l307" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">similarity measures}</span>
</div><div id="l308" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption}</span>
</div><div id="l309" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">answer subsumption}</span>
</div><div id="l310" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call variance}</span>
</div><div id="l311" class="code_block">
</div><div id="l312" class="code_block"><span class="nb">The above description gives a general characterization of tabled</span>
</div><div id="l313" class="code_block"><span class="nb">evaluation for definite programs but glosses over certain details.  In</span>
</div><div id="l314" class="code_block"><span class="nb">particular, we have not specified the criteria for </span>
</div><div id="l315" class="code_block"><span class="nv">\begin</span><span class="nb">{itemize}</span>
</div><div id="l316" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Call Similarity} </span><span class="o">--</span><span class="nb"> whereby a newly issued subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is</span>
</div><div id="l317" class="code_block"><span class="nb">  determined to be ``sufficiently similar&#39;&#39; to a tabled subgoal</span>
</div><div id="l318" class="code_block"><span class="nb">  </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> so that </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> can use the answers from the table of</span>
</div><div id="l319" class="code_block"><span class="nb">  </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> rather than re</span><span class="o">-</span><span class="nb">deriving its own answers.  In the first</span>
</div><div id="l320" class="code_block"><span class="nb">  case where </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> uses answers of a tabled subgoal it is termed a</span>
</div><div id="l321" class="code_block"><span class="nb">  consumer; in the second case when </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> produces its own answers it is</span>
</div><div id="l322" class="code_block"><span class="nb">  called a generator or producer.</span>
</div><div id="l323" class="code_block"><span class="c">%</span>
</div><div id="l324" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Answer Similarity} </span><span class="o">--</span><span class="nb"> whereby a derived answer to a tabled</span>
</div><div id="l325" class="code_block"><span class="nb">  subgoal is determined to contain information similar to that already</span>
</div><div id="l326" class="code_block"><span class="nb">  in the set of answers for that subgoal.</span>
</div><div id="l327" class="code_block"><span class="nv">\end</span><span class="nb">{itemize}</span>
</div><div id="l328" class="code_block"><span class="nb">Different measures of similarity are possible.  XSB&#39;s engine supports</span>
</div><div id="l329" class="code_block"><span class="nb">two measures for call similarity: variance and subsumption.  XSB&#39;s</span>
</div><div id="l330" class="code_block"><span class="nb">engine supports a variance</span><span class="o">-</span><span class="nb">based measure for answer similarity, but</span>
</div><div id="l331" class="code_block"><span class="nb">allows users to program other measures in certain cases.  We discuss</span>
</div><div id="l332" class="code_block"><span class="nb">call similarity here, but defer the discussion of answer similarity</span>
</div><div id="l333" class="code_block"><span class="nb">until Section~</span><span class="nv">\ref</span><span class="nb">{sec:table</span><span class="o">-</span><span class="nb">aggregation}.</span>
</div><div id="l334" class="code_block">
</div><div id="l335" class="code_block"><span class="c">% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</span>
</div><div id="l336" class="code_block">
</div><div id="l337" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Determining Call Similarity via Variance}</span>
</div><div id="l338" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call variance} </span>
</div><div id="l339" class="code_block"><span class="c">%</span>
</div><div id="l340" class="code_block"><span class="nb">By default, XSB determines that a subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is similar to a tabled</span>
</div><div id="l341" class="code_block"><span class="nb">subgoal </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> if </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is a {</span><span class="nv">\em</span><span class="nb"> variant} of </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb">, that is if</span>
</div><div id="l342" class="code_block"><span class="s">$</span>S<span class="s">$</span><span class="nb"> and </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> are identical up to variable</span>
</div><div id="l343" class="code_block"><span class="nb">renaming~</span><span class="nv">\footnote</span><span class="nb">{Formally, </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> and </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> are variants if they</span>
</div><div id="l344" class="code_block"><span class="nb">  have an mgu </span><span class="s">$</span><span class="k">\theta</span><span class="s">$</span><span class="nb"> such that the domain and range of </span><span class="s">$</span><span class="k">\theta</span>1<span class="s">$</span>
</div><div id="l345" class="code_block"><span class="nb">  consists only of variables.}.  As an example {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X,Y,X</span><span class="o">)</span><span class="nb">} is a</span>
</div><div id="l346" class="code_block"><span class="nb">variant of {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">A,B,A</span><span class="o">)</span><span class="nb">}, but not of {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X,Y,Y</span><span class="o">)</span><span class="nb">}, or {</span><span class="nv">\tt</span>
</div><div id="l347" class="code_block"><span class="nb">  p</span><span class="o">(</span><span class="nb">X,Y,Z</span><span class="o">)</span><span class="nb">}.  Under variance</span><span class="o">-</span><span class="nb">based call similarity, or {</span><span class="nv">\em</span><span class="nb"> call</span>
</div><div id="l348" class="code_block"><span class="nb">  variance}, when a tabled subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is encountered, a search for a</span>
</div><div id="l349" class="code_block"><span class="nb">table entry containing a variant subgoal </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> is performed.</span>
</div><div id="l350" class="code_block"><span class="nb">Notice that if </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nb"> exists, then </span><span class="nv">\emph</span><span class="nb">{all} of its answers are</span>
</div><div id="l351" class="code_block"><span class="nb">also answers to </span><span class="s">$</span>S<span class="s">$</span><span class="nb">, and therefore will be resolved against it.  Call</span>
</div><div id="l352" class="code_block"><span class="nb">variance was used in the original formulation of SLG resolution</span>
</div><div id="l353" class="code_block"><span class="nv">\cite</span><span class="nb">{ChWa</span><span class="m">96</span><span class="nb">} for the evaluation of normal logic programs according to</span>
</div><div id="l354" class="code_block"><span class="nb">the well</span><span class="o">-</span><span class="nb">founded semantics and interacts well with many of Prolog&#39;s</span>
</div><div id="l355" class="code_block"><span class="nb">extra</span><span class="o">-</span><span class="nb">logical constructs.</span>
</div><div id="l356" class="code_block">
</div><div id="l357" class="code_block">
</div><div id="l358" class="code_block"><span class="nv">\comment</span><span class="nb">{ Likewise, when an answer </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> is derived for a producing</span>
</div><div id="l359" class="code_block"><span class="nb">  subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb">, </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> is inserted into the answer set </span><span class="s">$</span><span class="k">\cA</span><span class="s">$</span><span class="nb"> of </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> if and</span>
</div><div id="l360" class="code_block"><span class="nb">  only if </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> does not already exist in </span><span class="s">$</span><span class="k">\cA</span><span class="s">$</span><span class="nb">~</span><span class="o">---</span><span class="nb">~that is, if there is</span>
</div><div id="l361" class="code_block"><span class="nb">  no variant of </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> already present in </span><span class="s">$</span><span class="k">\cA</span><span class="s">$</span><span class="nv">\@</span><span class="nb">.  The insertion of </span><span class="s">$</span>A<span class="s">$</span><span class="nb">,</span>
</div><div id="l362" class="code_block"><span class="nb">  therefore, leads to the return of </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> to consumers of </span><span class="s">$</span>S<span class="s">$</span><span class="nv">\@</span><span class="nb">.</span>
</div><div id="l363" class="code_block"><span class="nb">  However, the return of only the most general answers to a consumer,</span>
</div><div id="l364" class="code_block"><span class="nb">  referred to as </span><span class="nv">\emph</span><span class="nb">{answer subsumption}, can be flexibly programmed</span>
</div><div id="l365" class="code_block"><span class="nb">  as discussed in Section~{</span><span class="nv">\ref</span><span class="nb">{sec:table</span><span class="o">-</span><span class="nb">aggregation}} }</span>
</div><div id="l366" class="code_block">
</div><div id="l367" class="code_block"><span class="c">% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</span>
</div><div id="l368" class="code_block">
</div><div id="l369" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Determining Call Similarity via Subsumption}</span>
</div><div id="l370" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption}</span>
</div><div id="l371" class="code_block">
</div><div id="l372" class="code_block"><span class="nb">Call similarity can also be based on {</span><span class="nv">\em</span><span class="nb"> call subsumption}.  A term</span>
</div><div id="l373" class="code_block"><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb"> </span><span class="nv">\emph</span><span class="nb">{subsumes} a term </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb"> if </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb"> is more specific than</span>
</div><div id="l374" class="code_block"><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb">~</span><span class="nv">\footnote</span><span class="nb">{Formally, </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb"> subsumes </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb"> if there is a</span>
</div><div id="l375" class="code_block"><span class="nb">  substitution </span><span class="s">$</span><span class="k">\theta</span><span class="s">$</span><span class="nb"> whose domain consists only of variables from</span>
</div><div id="l376" class="code_block"><span class="nb">  </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb"> such that </span><span class="s">$</span>T<span class="nb">_</span>1<span class="k">\theta</span> = T<span class="nb">_</span>2<span class="s">$</span><span class="nb">.}.  Furthermore, we say that </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span>
</div><div id="l377" class="code_block"><span class="nv">\emph</span><span class="nb">{properly subsumes} </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb"> if </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb"> subsumes </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb">, but is not a</span>
</div><div id="l378" class="code_block"><span class="nb">variant of </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb">.  Under call subsumption, when a tabled subgoal </span><span class="s">$</span>S<span class="s">$</span>
</div><div id="l379" class="code_block"><span class="nb">is encountered, a search is performed for a table entry containing a</span>
</div><div id="l380" class="code_block"><span class="nb">{</span><span class="nv">\em</span><span class="nb"> subsuming} subgoal </span><span class="s">$</span>S<span class="nb">_{</span>tab<span class="nb">}</span><span class="s">$</span><span class="nv">\@</span><span class="nb">.  Notice that, if such an entry</span>
</div><div id="l381" class="code_block"><span class="nb">exists, then its answer set </span><span class="s">$</span><span class="k">\cA</span><span class="s">$</span><span class="nb"> logically contains all the solutions</span>
</div><div id="l382" class="code_block"><span class="nb">to satisfy </span><span class="s">$</span>C<span class="s">$</span><span class="nv">\@</span><span class="nb">.  The subset of answers </span><span class="s">$</span><span class="k">\cA</span>&#39; <span class="k">\subseteq</span> <span class="k">\cA</span><span class="s">$</span><span class="nb"> which</span>
</div><div id="l383" class="code_block"><span class="nb">unify with </span><span class="s">$</span>C<span class="s">$</span><span class="nb"> are said to be </span><span class="nv">\emph</span><span class="nb">{relevant to} </span><span class="s">$</span>C<span class="s">$</span><span class="nv">\@</span><span class="nb">.  </span>
</div><div id="l384" class="code_block">
</div><div id="l385" class="code_block"><span class="nb">Notice that call subsumption permits greater reuse of computed</span>
</div><div id="l386" class="code_block"><span class="nb">results, thus avoiding even more program resolution, and thereby can</span>
</div><div id="l387" class="code_block"><span class="nb">lead to time and space performances superior to call variance.  In</span>
</div><div id="l388" class="code_block"><span class="nb">addition, beginning with Version </span><span class="m">3</span><span class="nb">.</span><span class="m">2</span><span class="nb">, call</span><span class="o">-</span><span class="nb">subsumption based tabling</span>
</div><div id="l389" class="code_block"><span class="nb">fully supports well</span><span class="o">-</span><span class="nb">founded negation under the default local</span>
</div><div id="l390" class="code_block"><span class="nb">scheduling strategy.  However, there are downsides to this paradigm.</span>
</div><div id="l391" class="code_block"><span class="nb">First of all, subsumptively tabled predicates do not interact well</span>
</div><div id="l392" class="code_block"><span class="nb">with certain Prolog constructs with which variant</span><span class="o">-</span><span class="nb">tabled predicates</span>
</div><div id="l393" class="code_block"><span class="nb">can </span><span class="o">(</span><span class="nb">see Example~</span><span class="nv">\ref</span><span class="nb">{example:sub</span><span class="o">-</span><span class="nb">fail} below</span><span class="o">)</span><span class="nb">.  Second, call</span>
</div><div id="l394" class="code_block"><span class="nb">subsumption does not yet support calls with tabled attributed</span>
</div><div id="l395" class="code_block"><span class="nb">variables or answer subsumption~</span><span class="nv">\footnote</span><span class="nb">{Beginning with Version </span><span class="m">3</span><span class="nb">.</span><span class="m">2</span><span class="nb">,</span>
</div><div id="l396" class="code_block"><span class="nb">  XSB supports attributed variables in answers under call subsumption,</span>
</div><div id="l397" class="code_block"><span class="nb">  although not in calls.}.</span>
</div><div id="l398" class="code_block"><span class="nv">\index</span><span class="nb">{attributed variables}</span>
</div><div id="l399" class="code_block">
</div><div id="l400" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption}</span>
</div><div id="l401" class="code_block"><span class="nv">\begin</span><span class="nb">{example} </span><span class="nv">\rm</span><span class="nb"> </span>
</div><div id="l402" class="code_block"><span class="nb">The terms </span><span class="s">$</span>T<span class="nb">_</span>1<span class="s">$</span><span class="nb">: {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">Y</span><span class="o">)</span><span class="nb">,X,</span><span class="m">1</span><span class="o">)</span><span class="nb">} and </span><span class="s">$</span>T<span class="nb">_</span>2<span class="s">$</span><span class="nb">:~{</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">Z</span><span class="o">)</span><span class="nb">,U,</span><span class="m">1</span><span class="o">)</span><span class="nb">} are</span>
</div><div id="l403" class="code_block"><span class="nv">\emph</span><span class="nb">{variants} as one can be made to look like the other by a</span>
</div><div id="l404" class="code_block"><span class="nb">renaming of the variables.  Therefore, each </span><span class="nv">\emph</span><span class="nb">{subsumes} the other. </span><span class="nv">\\</span>
</div><div id="l405" class="code_block"><span class="nv">\noindent</span><span class="nb"> The term </span><span class="s">$</span>t<span class="nb">_</span>3<span class="s">$</span><span class="nb">: {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">Y</span><span class="o">)</span><span class="nb">,X,</span><span class="m">1</span><span class="o">)</span><span class="nb">} </span><span class="nv">\emph</span><span class="nb">{subsumes} the term</span>
</div><div id="l406" class="code_block"><span class="s">$</span>t<span class="nb">_</span>4<span class="s">$</span><span class="nb">:~{</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">Z</span><span class="o">)</span><span class="nb">,Z,</span><span class="m">1</span><span class="o">)</span><span class="nb">}.  However, they are </span><span class="nv">\emph</span><span class="nb">{not variants}.  Hence</span>
</div><div id="l407" class="code_block"><span class="s">$</span>t<span class="nb">_</span>3<span class="s">$</span><span class="nb"> </span><span class="nv">\emph</span><span class="nb">{properly subsumes}~</span><span class="s">$</span>t<span class="nb">_</span>4<span class="s">$</span><span class="nb">.</span><span class="nv">\fillBox</span>
</div><div id="l408" class="code_block"><span class="nv">\end</span><span class="nb">{example}</span>
</div><div id="l409" class="code_block">
</div><div id="l410" class="code_block"><span class="nb">The above examples show how a variant</span><span class="o">-</span><span class="nb">based tabled evaluation can</span>
</div><div id="l411" class="code_block"><span class="nb">reduce certain redundant subcomputations over SLD</span><span class="nv">\@</span><span class="nb">.  However, even</span>
</div><div id="l412" class="code_block"><span class="nb">more redundancy can be eliminated, as the following example shows.</span>
</div><div id="l413" class="code_block">
</div><div id="l414" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:VarVsSub} </span><span class="nv">\rm</span>
</div><div id="l415" class="code_block"><span class="nb">Begin by abolishing all tables in XSB, and then type the following query</span>
</div><div id="l416" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l417" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> abolish_all_tables.</span>
</div><div id="l418" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">, fail.</span>
</div><div id="l419" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l420" class="code_block"><span class="nb">Notice that only a single table entry is created during the evaluation</span>
</div><div id="l421" class="code_block"><span class="nb">of this query.  You can check that this is the case by invoking the</span>
</div><div id="l422" class="code_block"><span class="nb">following query</span>
</div><div id="l423" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l424" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> get_calls_for_table</span><span class="o">(</span><span class="nb">path</span><span class="o">/</span><span class="m">2</span><span class="nb">,Call</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l425" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l426" class="code_block"><span class="nb">Now evaluate the query</span>
</div><div id="l427" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l428" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">, fail.</span>
</div><div id="l429" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l430" class="code_block"><span class="nb">and again check the subgoals in the table.  Notice that two more have</span>
</div><div id="l431" class="code_block"><span class="nb">been added.  Further notice that these new subgoals are</span>
</div><div id="l432" class="code_block"><span class="nv">\emph</span><span class="nb">{subsumed} by that of the original entry.  Correspondingly, the</span>
</div><div id="l433" class="code_block"><span class="nb">answers derived for these newer subgoals are already present in the</span>
</div><div id="l434" class="code_block"><span class="nb">original entry.  You can check the answers contained in a table entry</span>
</div><div id="l435" class="code_block"><span class="nb">by invoking </span><span class="nv">\code</span><span class="nb">{get</span><span class="nv">\_</span><span class="nb">returns</span><span class="nv">\_</span><span class="nb">for</span><span class="nv">\_</span><span class="nb">call</span><span class="o">/</span><span class="m">2</span><span class="nb">} on a tabled subgoal.  For</span>
</div><div id="l436" class="code_block"><span class="nb">example:</span>
</div><div id="l437" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l438" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> get_returns_for_call</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="m">1</span><span class="nb">,_</span><span class="o">)</span><span class="nb">,Answer</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l439" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l440" class="code_block"><span class="nb">Compare these answers to those of </span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">} and </span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l441" class="code_block"><span class="nb">Notice that the same answer can, and in this case does, appear in</span>
</div><div id="l442" class="code_block"><span class="nb">multiple table entries.</span>
</div><div id="l443" class="code_block">
</div><div id="l444" class="code_block"><span class="nb">Now, let&#39;s again abolish all the tables and change the evaluation</span>
</div><div id="l445" class="code_block"><span class="nb">strategy of </span><span class="nv">\code</span><span class="nb">{path</span><span class="o">/</span><span class="m">2</span><span class="nb">} to use subsumption.</span>
</div><div id="l446" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l447" class="code_block"><span class="nb">	 ?</span><span class="o">-</span><span class="nb"> abolish_all_tables.</span>
</div><div id="l448" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> table path</span><span class="o">/</span><span class="m">2</span><span class="nb"> as subsumptive.</span>
</div><div id="l449" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l450" class="code_block"><span class="nb">And re</span><span class="o">-</span><span class="nb">perform the first few queries:</span>
</div><div id="l451" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l452" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">,fail.</span>
</div><div id="l453" class="code_block"><span class="nb">	 ?</span><span class="o">-</span><span class="nb"> get_calls_for_table</span><span class="o">(</span><span class="nb">path</span><span class="o">/</span><span class="m">2</span><span class="nb">,Call</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l454" class="code_block"><span class="nb">	 ?</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l455" class="code_block"><span class="nb">	 ?</span><span class="o">-</span><span class="nb"> get_calls_for_table</span><span class="o">(</span><span class="nb">path</span><span class="o">/</span><span class="m">2</span><span class="nb">,Call</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l456" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l457" class="code_block"><span class="nb">Notice that this time the table has not changed</span><span class="o">!</span><span class="nb">  Only a single entry</span>
</div><div id="l458" class="code_block"><span class="nb">is present, that for the original query </span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l459" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l460" class="code_block"><span class="c">%</span>
</div><div id="l461" class="code_block"><span class="nb">When using call subsumption, XSB is able to recognize a greater range</span>
</div><div id="l462" class="code_block"><span class="nb">of ``redundant&#39;&#39; queries and thereby make greater use of previously</span>
</div><div id="l463" class="code_block"><span class="nb">computed answers.  The result is that less program resolution is</span>
</div><div id="l464" class="code_block"><span class="nb">performed and less redundancy is present in the table.  However,</span>
</div><div id="l465" class="code_block"><span class="nb">subsumption is not a panacea.  The elimination of redundant answers</span>
</div><div id="l466" class="code_block"><span class="nb">depends upon the presence of a subsuming subgoal in the table when the</span>
</div><div id="l467" class="code_block"><span class="nb">call to </span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">} is made.  If the order of these queries were</span>
</div><div id="l468" class="code_block"><span class="nb">reversed, one would find that the same entries would be present in</span>
</div><div id="l469" class="code_block"><span class="nb">this table as the one constructed under variant</span><span class="o">-</span><span class="nb">based evaluation.</span>
</div><div id="l470" class="code_block">
</div><div id="l471" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption}</span>
</div><div id="l472" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Declarations for Call Variance and Call Subsumption}</span>
</div><div id="l473" class="code_block"><span class="nb">By default tabled predicate use call variance.  However, call</span>
</div><div id="l474" class="code_block"><span class="nb">subsumption can be made the default by giving XSB the </span><span class="nv">\verb</span><span class="nb">|</span><span class="o">-</span><span class="nb">S| option</span>
</div><div id="l475" class="code_block"><span class="nb">at invocation </span><span class="o">(</span><span class="nb">refer to </span><span class="nv">\refsec</span><span class="nb">{sec:EmuOptions}</span><span class="o">)</span><span class="nb">.  More versatile</span>
</div><div id="l476" class="code_block"><span class="nb">constructs are provided by XSB so that the tabling method can be</span>
</div><div id="l477" class="code_block"><span class="nb">selected on a </span><span class="nv">\emph</span><span class="nb">{per predicate} basis.  Use of the directive</span>
</div><div id="l478" class="code_block">
</div><div id="l479" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> table p</span><span class="o">/</span><span class="nb">n as subsumptive}</span>
</div><div id="l480" class="code_block">
</div><div id="l481" class="code_block"><span class="nb">or </span>
</div><div id="l482" class="code_block">
</div><div id="l483" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> table p</span><span class="o">/</span><span class="nb">n as variant}</span>
</div><div id="l484" class="code_block">
</div><div id="l485" class="code_block"><span class="nb">described in </span><span class="nv">\refsec</span><span class="nb">{sec:TablePred:Decl&amp;Mod}, ensures that a tabled</span>
</div><div id="l486" class="code_block"><span class="nb">predicate is evaluated using the desired strategy regardless of the</span>
</div><div id="l487" class="code_block"><span class="nb">default tabling strategy.</span>
</div><div id="l488" class="code_block"><span class="nv">\index</span><span class="nb">{declarations</span><span class="o">!</span><span class="nv">\texttt</span><span class="nb">{table</span><span class="nv">\</span><span class="nb"> as}}</span>
</div><div id="l489" class="code_block">
</div><div id="l490" class="code_block"><span class="c">%----------------------------------------------------------------------</span>
</div><div id="l491" class="code_block">
</div><div id="l492" class="code_block"><span class="nv">\subsection</span><span class="nb">{Table Scheduling Strategies} </span><span class="nv">\label</span><span class="nb">{section:scheduling}</span>
</div><div id="l493" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">scheduling strategies}</span>
</div><div id="l494" class="code_block">
</div><div id="l495" class="code_block"><span class="nb">Recall that SLD resolution works by selecting a goal from a list of</span>
</div><div id="l496" class="code_block"><span class="nb">goals to be proved, and selecting a program clause </span><span class="s">$</span>C<span class="s">$</span><span class="nb"> to resolve</span>
</div><div id="l497" class="code_block"><span class="nb">against that goal.  During resolution of a top level goal </span><span class="s">$</span>G<span class="s">$</span><span class="nb">, if the</span>
</div><div id="l498" class="code_block"><span class="nb">list of unresolved goals becomes empty, </span><span class="s">$</span>G<span class="s">$</span><span class="nb"> succeeds, while if there</span>
</div><div id="l499" class="code_block"><span class="nb">is no program clause to resolve against the selected goal from the</span>
</div><div id="l500" class="code_block"><span class="nb">list resolution against </span><span class="s">$</span>G<span class="s">$</span><span class="nb"> fails.  In Prolog clauses are selected in</span>
</div><div id="l501" class="code_block"><span class="nb">the order they are asserted, while literals are selected in a</span>
</div><div id="l502" class="code_block"><span class="nb">left</span><span class="o">-</span><span class="nb">to</span><span class="o">-</span><span class="nb">right selection strategy.  Other strategies are possible for</span>
</div><div id="l503" class="code_block"><span class="nb">SLD, and in fact completeness of SLD for definite programs depends on</span>
</div><div id="l504" class="code_block"><span class="nb">a non</span><span class="o">-</span><span class="nb">fixed literal selection strategy.  This is why Prolog, which has</span>
</div><div id="l505" class="code_block"><span class="nb">a fixed literal selection strategy is not complete for definite</span>
</div><div id="l506" class="code_block"><span class="nb">programs, even when they have bounded term</span><span class="o">-</span><span class="nb">depth.</span>
</div><div id="l507" class="code_block">
</div><div id="l508" class="code_block"><span class="nb">Because tabling uses program clause resolution, the two parameters of</span>
</div><div id="l509" class="code_block"><span class="nb">clause selection and literal selection also apply to tabling.  Tabling</span>
</div><div id="l510" class="code_block"><span class="nb">makes use of a dynamic literal selection strategy for certain</span>
</div><div id="l511" class="code_block"><span class="nb">non</span><span class="o">-</span><span class="nb">stratified programs </span><span class="o">(</span><span class="nb">via the delaying mechanism described in</span>
</div><div id="l512" class="code_block"><span class="nb">Section~</span><span class="nv">\ref</span><span class="nb">{negation</span><span class="o">!</span><span class="nb">unstratified}</span><span class="o">)</span><span class="nb">, but uses the same left</span><span class="o">-</span><span class="nb">to</span><span class="o">-</span><span class="nb">right</span>
</div><div id="l513" class="code_block"><span class="nb">literal selection strategy as Prolog for definite programs.  However,</span>
</div><div id="l514" class="code_block"><span class="nb">in tabling there is also a choice of when to return derived answers to</span>
</div><div id="l515" class="code_block"><span class="nb">subgoals that consume these answers.  While full discussion of</span>
</div><div id="l516" class="code_block"><span class="nb">scheduling strategies for tabling is not covered here</span>
</div><div id="l517" class="code_block"><span class="o">(</span><span class="nb">see~</span><span class="nv">\cite</span><span class="nb">{JFLP</span><span class="o">-</span><span class="nb">Scheduling}</span><span class="o">)</span><span class="nb"> we discuss two scheduling strategies</span>
</div><div id="l518" class="code_block"><span class="nb">that have been implemented for XSB </span><span class="nv">\version</span><span class="nb">~</span><span class="nv">\footnote</span><span class="nb">{Many other</span>
</div><div id="l519" class="code_block"><span class="nb">  scheduling strategies are possible.  For instance, </span><span class="nv">\cite</span><span class="nb">{FrSW</span><span class="m">97</span><span class="nb">}</span>
</div><div id="l520" class="code_block"><span class="nb">  describes a tabling strategy implemented for the SLG</span><span class="o">-</span><span class="nb">WAM that</span>
</div><div id="l521" class="code_block"><span class="nb">  emulates magic sets under semi</span><span class="o">-</span><span class="nb">naive evaluation.  This scheduling</span>
</div><div id="l522" class="code_block"><span class="nb">  strategy, however, is not available in </span><span class="nv">\version</span><span class="nb">{} of XSB.}.</span>
</div><div id="l523" class="code_block">
</div><div id="l524" class="code_block"><span class="nv">\begin</span><span class="nb">{itemize}</span>
</div><div id="l525" class="code_block">
</div><div id="l526" class="code_block"><span class="nv">\index</span><span class="nb">{strongly connected components </span><span class="o">(</span><span class="nb">SCCs</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l527" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Local Scheduling} Local Scheduling depends on the notion of</span>
</div><div id="l528" class="code_block"><span class="nb">  a {</span><span class="nv">\em</span><span class="nb"> subgoal dependency graph}.  For the state of a tabled</span>
</div><div id="l529" class="code_block"><span class="nb">  evaluation, a non</span><span class="o">-</span><span class="nb">completed tabled subgoal </span><span class="s">$</span>S<span class="nb">_</span>1<span class="s">$</span><span class="nb"> directly depends on</span>
</div><div id="l530" class="code_block"><span class="nb">  a non</span><span class="o">-</span><span class="nb">completed subgoal </span><span class="s">$</span>S<span class="nb">_</span>2<span class="s">$</span><span class="nb"> when </span><span class="s">$</span>S<span class="nb">_</span>2<span class="s">$</span><span class="nb"> is in the SLG tree for</span>
</div><div id="l531" class="code_block"><span class="nb">  </span><span class="s">$</span>S<span class="nb">_</span>1<span class="s">$</span><span class="nb"> </span><span class="o">--</span><span class="nb"> that is when </span><span class="s">$</span>S<span class="nb">_</span>2<span class="s">$</span><span class="nb"> is called by </span><span class="s">$</span>S<span class="nb">_</span>1<span class="s">$</span><span class="nb"> without any</span>
</div><div id="l532" class="code_block"><span class="nb">  intervening tabled predicate.  The edges of the subgoal dependency</span>
</div><div id="l533" class="code_block"><span class="nb">  graph are then these direct dependency relations, so that the</span>
</div><div id="l534" class="code_block"><span class="nb">  subgoal dependency graph is directed.  As mentioned, the subgoal</span>
</div><div id="l535" class="code_block"><span class="nb">  dependency graph reflects a given state of a tabled evaluation and</span>
</div><div id="l536" class="code_block"><span class="nb">  so may changed as the evaluation proceeds, as new tabled subgoals</span>
</div><div id="l537" class="code_block"><span class="nb">  are encountered, or encountered in different contexts, as tables</span>
</div><div id="l538" class="code_block"><span class="nb">  complete, and so on.  As with any directed graph, the subgoal</span>
</div><div id="l539" class="code_block"><span class="nb">  dependency graph can be divided up into strongly connected</span>
</div><div id="l540" class="code_block"><span class="nb">  components, consisting of tabled subgoals that depend on one</span>
</div><div id="l541" class="code_block"><span class="nb">  another.  Local scheduling then fully evaluates each maximal SCC </span><span class="o">(</span><span class="nb">a</span>
</div><div id="l542" class="code_block"><span class="nb">  SCC that does not depend on another SCC</span><span class="o">)</span><span class="nb"> before returning answers to</span>
</div><div id="l543" class="code_block"><span class="nb">  any subgoal outside of the SCC~</span><span class="nv">\footnote</span><span class="nb">{XSB&#39;s implementation</span>
</div><div id="l544" class="code_block"><span class="nb">    maintains a slight over</span><span class="o">-</span><span class="nb">approximation of SCCs </span><span class="o">--</span><span class="nb"> see</span>
</div><div id="l545" class="code_block"><span class="nb">    </span><span class="nv">\cite</span><span class="nb">{JFLP</span><span class="o">-</span><span class="nb">Scheduling}.}.</span>
</div><div id="l546" class="code_block">
</div><div id="l547" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Batched Scheduling} Unlike Local Scheduling, Batched</span>
</div><div id="l548" class="code_block"><span class="nb">  Scheduling allows answers to be returned outside of a maximal SCC as</span>
</div><div id="l549" class="code_block"><span class="nb">  they are derived, and thus resembles Prolog&#39;s tuple at a time</span>
</div><div id="l550" class="code_block"><span class="nb">  scheduling.  </span>
</div><div id="l551" class="code_block"><span class="nv">\end</span><span class="nb">{itemize}</span>
</div><div id="l552" class="code_block">
</div><div id="l553" class="code_block"><span class="nb">Both Local and Batched Scheduling have their advantages, and we list</span>
</div><div id="l554" class="code_block"><span class="nb">points of comparison.</span>
</div><div id="l555" class="code_block">
</div><div id="l556" class="code_block"><span class="nv">\begin</span><span class="nb">{itemize}</span>
</div><div id="l557" class="code_block">
</div><div id="l558" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Time for left recursion} Batched Scheduling is somewhat</span>
</div><div id="l559" class="code_block"><span class="nb">  faster than Local Scheduling for left recursion as Local Scheduling</span>
</div><div id="l560" class="code_block"><span class="nb">  imposes overhead to prevent answers from being returned outside of</span>
</div><div id="l561" class="code_block"><span class="nb">  a maximal SCC.  </span>
</div><div id="l562" class="code_block">
</div><div id="l563" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Time to first answer}  Because Batched Scheduling returns</span>
</div><div id="l564" class="code_block"><span class="nb">  answers out of an SCC eagerly, it is faster to derive the first</span>
</div><div id="l565" class="code_block"><span class="nb">  answer to a tabled predicate.</span>
</div><div id="l566" class="code_block">
</div><div id="l567" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Stack space} Local evaluation generally requires less space</span>
</div><div id="l568" class="code_block"><span class="nb">  than batched evaluation as it fully explores a maximal SCC,</span>
</div><div id="l569" class="code_block"><span class="nb">  completes the SCC&#39;s subgoals, reclaims space, and then moves on to a</span>
</div><div id="l570" class="code_block"><span class="nb">  new SCC.  </span>
</div><div id="l571" class="code_block">
</div><div id="l572" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Integration with cuts} As discussed in</span>
</div><div id="l573" class="code_block"><span class="nb">  Exercise~</span><span class="nv">\ref</span><span class="nb">{ex:nocut} and throughout Section~</span><span class="nv">\ref</span><span class="nb">{sec:cuts}, Local</span>
</div><div id="l574" class="code_block"><span class="nb">  Scheduling integrates better with cuts, although this is partly</span>
</div><div id="l575" class="code_block"><span class="nb">  because tabled subgoals may be fully evaluated before the cut takes</span>
</div><div id="l576" class="code_block"><span class="nb">  effect. </span>
</div><div id="l577" class="code_block">
</div><div id="l578" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Efficiency for call subsumption} Because Local Evaluation</span>
</div><div id="l579" class="code_block"><span class="nb">  completes tables earlier than Batched Evaluation it may be faster</span>
</div><div id="l580" class="code_block"><span class="nb">  for some uses of call subsumption, as subsumed calls can make use of</span>
</div><div id="l581" class="code_block"><span class="nb">  completed subsuming tables.</span>
</div><div id="l582" class="code_block">
</div><div id="l583" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\em</span><span class="nb"> Negation and tabled aggregation} As will be shown below,</span>
</div><div id="l584" class="code_block"><span class="nb">  Local Scheduling is superior for tabled aggregation as only optimal</span>
</div><div id="l585" class="code_block"><span class="nb">  answers are returned out of a maximal SCC.  Local Scheduling also</span>
</div><div id="l586" class="code_block"><span class="nb">  can be more efficient for non</span><span class="o">-</span><span class="nb">stratified negation as it may allow</span>
</div><div id="l587" class="code_block"><span class="nb">  delayed answers that are later simplified away to avoid being</span>
</div><div id="l588" class="code_block"><span class="nb">  propagated.</span>
</div><div id="l589" class="code_block"><span class="nv">\end</span><span class="nb">{itemize}</span>
</div><div id="l590" class="code_block">
</div><div id="l591" class="code_block"><span class="nb">On the whole, advantages of Local Scheduling outweigh the advantages of</span>
</div><div id="l592" class="code_block"><span class="nb">Batched Scheduling, and for this reason Local Scheduling is the</span>
</div><div id="l593" class="code_block"><span class="nb">default scheduling strategy for </span><span class="nv">\version</span><span class="nb">{} of XSB.  XSB can be</span>
</div><div id="l594" class="code_block"><span class="nb">configured to use batched scheduling via the configuration option {</span><span class="nv">\tt</span>
</div><div id="l595" class="code_block"><span class="nb">  </span><span class="o">--</span><span class="nb">enable</span><span class="o">-</span><span class="nb">batched</span><span class="o">-</span><span class="nb">scheduling} and remaking XSB</span><span class="nv">\@</span><span class="nb">.  This will not</span>
</div><div id="l596" class="code_block"><span class="nb">affect the default version of XSB, which will also remain available.</span>
</div><div id="l597" class="code_block">
</div><div id="l598" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l599" class="code_block">
</div><div id="l600" class="code_block"><span class="nv">\subsection</span><span class="nb">{Interaction Between Prolog Constructs and Tabling}</span>
</div><div id="l601" class="code_block">
</div><div id="l602" class="code_block"><span class="nb">Tabling integrates well with most non</span><span class="o">-</span><span class="nb">pure aspects of Prolog.</span>
</div><div id="l603" class="code_block"><span class="nb">Predicates with side</span><span class="o">-</span><span class="nb">effects like {</span><span class="nv">\tt</span><span class="nb"> read</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> write</span><span class="o">/</span><span class="m">1</span><span class="nb">} can</span>
</div><div id="l604" class="code_block"><span class="nb">be used freely in tabled predicates as long as it is remembered that</span>
</div><div id="l605" class="code_block"><span class="nb">only the first call to a goal will execute program clauses while the</span>
</div><div id="l606" class="code_block"><span class="nb">rest will look up answers from a table.  However, other extra</span><span class="o">-</span><span class="nb">logical</span>
</div><div id="l607" class="code_block"><span class="nb">constructs like the cut </span><span class="o">(</span><span class="nv">\texttt</span><span class="nb">{</span><span class="o">!</span><span class="nb">}</span><span class="o">)</span><span class="nb"> pose greater difficulties.</span>
</div><div id="l608" class="code_block"><span class="nb">Tabling with call subsumption is also theoretically precluded from</span>
</div><div id="l609" class="code_block"><span class="nb">correct interaction with certain meta</span><span class="o">-</span><span class="nb">logical predicates.</span>
</div><div id="l610" class="code_block">
</div><div id="l611" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Cuts and Tabling} </span><span class="nv">\label</span><span class="nb">{sec:cuts}</span>
</div><div id="l612" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">cuts}</span>
</div><div id="l613" class="code_block">
</div><div id="l614" class="code_block"><span class="nb">The semantics for cuts in Prolog is largely operational, and is</span>
</div><div id="l615" class="code_block"><span class="nb">usually defined based on an ordered traversal of an SLD search tree.</span>
</div><div id="l616" class="code_block"><span class="nb">Tabling, of course, has a different operational semantics than Prolog</span>
</div><div id="l617" class="code_block"><span class="o">--</span><span class="nb"> it uses SLG trees rather than SLD trees, for instance </span><span class="o">--</span><span class="nb"> so it is</span>
</div><div id="l618" class="code_block"><span class="nb">not surprising that the interaction of tabling with cuts is</span>
</div><div id="l619" class="code_block"><span class="nb">operational.  In Prolog, the semantics for a cut can be expressed in</span>
</div><div id="l620" class="code_block"><span class="nb">the following manner: a cut executed in the body of a predicate </span><span class="s">$</span>P<span class="s">$</span>
</div><div id="l621" class="code_block"><span class="nb">frames from the top </span><span class="o">(</span><span class="nb">youngest end</span><span class="o">)</span><span class="nb"> of the choice point stack down to</span>
</div><div id="l622" class="code_block"><span class="nb">and including the call for </span><span class="s">$</span>P<span class="s">$</span><span class="nb">.  In XSB {</span><span class="nv">\em</span><span class="nb"> a cut is allowed to</span>
</div><div id="l623" class="code_block"><span class="nb">  succeed as long as it does not cut over a choice point for a</span>
</div><div id="l624" class="code_block"><span class="nb">  non</span><span class="o">-</span><span class="nb">completed tabled subgoal, otherwise, the computation aborts}.</span>
</div><div id="l625" class="code_block"><span class="nb">This means, among other matters, that the validity of a cut depends on</span>
</div><div id="l626" class="code_block"><span class="nb">the {</span><span class="nv">\em</span><span class="nb"> scheduling strategy} used for tabling, that is on the</span>
</div><div id="l627" class="code_block"><span class="nb">strategy used to determine when an answer is to be returned to a</span>
</div><div id="l628" class="code_block"><span class="nb">consuming subgoal.  Scheduling strategy was discussed</span>
</div><div id="l629" class="code_block"><span class="nb">Section~</span><span class="nv">\ref</span><span class="nb">{section:scheduling}: for now, we assume that XSB&#39;s</span>
</div><div id="l630" class="code_block"><span class="nb">default local scheduling is used in the examples for cuts.</span>
</div><div id="l631" class="code_block">
</div><div id="l632" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:nocut}</span>
</div><div id="l633" class="code_block"><span class="nb">Consider the program</span>
</div><div id="l634" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l635" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table cut_p</span><span class="o">/</span><span class="m">1</span><span class="nb">, cut_q</span><span class="o">/</span><span class="m">1</span><span class="nb">, cut_r</span><span class="o">/</span><span class="m">0</span><span class="nb">, cut_s</span><span class="o">/</span><span class="m">0</span><span class="nb">.</span>
</div><div id="l636" class="code_block">
</div><div id="l637" class="code_block"><span class="nb">cut_p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> cut_q</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">, cut_r.</span>
</div><div id="l638" class="code_block"><span class="nb">cut_r :</span><span class="o">-</span><span class="nb"> cut_s.</span>
</div><div id="l639" class="code_block"><span class="nb">cut_s :</span><span class="o">-</span><span class="nb"> cut_q</span><span class="o">(</span><span class="nb">_</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l640" class="code_block"><span class="nb">cut_q</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">.   cut_q</span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l641" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l642" class="code_block"><span class="nb">What solutions are derived for the goal {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}</span><span class="nv">\@</span><span class="nb">?  Suppose</span>
</div><div id="l643" class="code_block"><span class="nb">that {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">} were rewritten as</span>
</div><div id="l644" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l645" class="code_block"><span class="nb">cut_p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> cut_q</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">, once</span><span class="o">(</span><span class="nb">cut_r</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l646" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l647" class="code_block"><span class="nb">How should this cut over a table affect the answers generated for {</span><span class="nv">\tt</span>
</div><div id="l648" class="code_block"><span class="nb">cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">}?  What happens if you rewrite {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">} in this way and</span>
</div><div id="l649" class="code_block"><span class="nb">compile it in XSB?</span><span class="nv">\fillBox</span>
</div><div id="l650" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l651" class="code_block">
</div><div id="l652" class="code_block"><span class="nb">In Exercise </span><span class="nv">\ref</span><span class="nb">{ex:nocut}, {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">} should</span>
</div><div id="l653" class="code_block"><span class="nb">both be true.  Thus, the cut in the literal {</span><span class="nv">\tt</span><span class="nb"> once</span><span class="o">(</span><span class="nb">cut</span><span class="nv">\_</span><span class="nb">r</span><span class="o">)</span><span class="nb">} must</span>
</div><div id="l654" class="code_block"><span class="nb">not inadvertently cut away solutions that are demanded by {</span><span class="nv">\tt</span>
</div><div id="l655" class="code_block"><span class="nb">  cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">}.  In the default local scheduling of XSB </span><span class="nv">\version</span><span class="nb">{} tabled</span>
</div><div id="l656" class="code_block"><span class="nb">subgoals are fully evaluated whenever possible before returning any of</span>
</div><div id="l657" class="code_block"><span class="nb">their answers.  Thus the first call {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">q</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} in the body of the</span>
</div><div id="l658" class="code_block"><span class="nb">clause for {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">} is fully evaluated before proceeding to the</span>
</div><div id="l659" class="code_block"><span class="nb">goal {</span><span class="nv">\tt</span><span class="nb"> once</span><span class="o">(</span><span class="nb">cut</span><span class="nv">\_</span><span class="nb">r</span><span class="o">)</span><span class="nb">}.  Because of this any choice points for {</span><span class="nv">\tt</span>
</div><div id="l660" class="code_block"><span class="nb">  cut</span><span class="nv">\_</span><span class="nb">q</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} are to a completed table.  For other scheduling</span>
</div><div id="l661" class="code_block"><span class="nb">strategies, such as batched scheduling, non</span><span class="o">-</span><span class="nb">completed choice points</span>
</div><div id="l662" class="code_block"><span class="nb">for {</span><span class="nv">\tt</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">1</span><span class="nb">} may be present on the choice point stack so that the</span>
</div><div id="l663" class="code_block"><span class="nb">cut would be disallowed.  In addition, it is also possible to</span>
</div><div id="l664" class="code_block"><span class="nb">construct examples where a cut is allowed if call variance is used,</span>
</div><div id="l665" class="code_block"><span class="nb">but not if call subsumption is used.</span>
</div><div id="l666" class="code_block">
</div><div id="l667" class="code_block"><span class="nv">\begin</span><span class="nb">{example}</span>
</div><div id="l668" class="code_block"><span class="nb">A further example of using cuts in a tabled predicate is a tabled</span>
</div><div id="l669" class="code_block"><span class="nb">meta</span><span class="o">-</span><span class="nb">interpreter.</span>
</div><div id="l670" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l671" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table demo</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l672" class="code_block">
</div><div id="l673" class="code_block"><span class="nb">demo</span><span class="o">(</span><span class="nb">true</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l674" class="code_block"><span class="nb">demo</span><span class="o">((</span><span class="nb">A,B</span><span class="o">))</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> </span><span class="o">!</span><span class="nb">, demo</span><span class="o">(</span><span class="nb">A</span><span class="o">)</span><span class="nb">, demo</span><span class="o">(</span><span class="nb">B</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l675" class="code_block"><span class="nb">demo</span><span class="o">(</span><span class="nb">C</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> call</span><span class="o">(</span><span class="nb">C</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l676" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l677" class="code_block"><span class="nb">More elaborate tabled meta</span><span class="o">-</span><span class="nb">interpreters can be extremely useful, for</span>
</div><div id="l678" class="code_block"><span class="nb">instance to implement various extensions of definite or normal</span>
</div><div id="l679" class="code_block"><span class="nb">programs.</span><span class="nv">\fillBox</span>
</div><div id="l680" class="code_block"><span class="nv">\end</span><span class="nb">{example}</span>
</div><div id="l681" class="code_block">
</div><div id="l682" class="code_block"><span class="nb">In XSB&#39;s compilation, the cut above is compiled so that it is valid to</span>
</div><div id="l683" class="code_block"><span class="nb">use with either local or batched </span><span class="o">(</span><span class="nb">a non</span><span class="o">-</span><span class="nb">default</span><span class="o">)</span><span class="nb"> evaluation.  An</span>
</div><div id="l684" class="code_block"><span class="nb">example of a cut that is valid neither in batched nor in local</span>
</div><div id="l685" class="code_block"><span class="nb">evaluation is as follows.</span>
</div><div id="l686" class="code_block">
</div><div id="l687" class="code_block"><span class="nv">\begin</span><span class="nb">{example} </span><span class="nv">\label</span><span class="nb">{ex:cutTable}</span>
</div><div id="l688" class="code_block"><span class="nb">Consider the program</span>
</div><div id="l689" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l690" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table cut_a</span><span class="o">/</span><span class="m">1</span><span class="nb">, cut_b</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l691" class="code_block">
</div><div id="l692" class="code_block"><span class="nb">cut_a</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> cut_b</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l693" class="code_block"><span class="nb">cut_a</span><span class="o">(</span><span class="nb">a</span><span class="m">1</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l694" class="code_block">
</div><div id="l695" class="code_block"><span class="nb">cut_b</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> cut_a</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l696" class="code_block"><span class="nb">cut_b</span><span class="o">(</span><span class="nb">b</span><span class="m">1</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l697" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l698" class="code_block"><span class="nb">For this program the goal {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> cut</span><span class="nv">\_</span><span class="nb">a</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} produces two answers, as</span>
</div><div id="l699" class="code_block"><span class="nb">expected: {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> b</span><span class="m">1</span><span class="nb">}.  However, replacing the first class</span>
</div><div id="l700" class="code_block"><span class="nb">of the above program with </span>
</div><div id="l701" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l702" class="code_block"><span class="nb">cut_a</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> once</span><span class="o">(</span><span class="nb">cut_b</span><span class="o">(</span><span class="nb">X</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l703" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l704" class="code_block"><span class="nb">will abort both in batched or in local evaluation.</span>
</div><div id="l705" class="code_block"><span class="nv">\fillBox</span>
</div><div id="l706" class="code_block"><span class="nv">\end</span><span class="nb">{example}</span>
</div><div id="l707" class="code_block">
</div><div id="l708" class="code_block"><span class="nb">To summarize, the behavior of cuts with tables depends on dynamic</span>
</div><div id="l709" class="code_block"><span class="nb">operational properties, and we have seen examples of programs in which</span>
</div><div id="l710" class="code_block"><span class="nb">a cut is valid in both local and batched scheduling, in local but not</span>
</div><div id="l711" class="code_block"><span class="nb">batched scheduling, and in neither batched nor local scheduling.  In</span>
</div><div id="l712" class="code_block"><span class="nb">general, any program and goal that allows cuts in batched scheduling</span>
</div><div id="l713" class="code_block"><span class="nb">will allow them in local scheduling as well, and there are programs</span>
</div><div id="l714" class="code_block"><span class="nb">for which cuts are allowed in local scheduling but not in batched.</span>
</div><div id="l715" class="code_block">
</div><div id="l716" class="code_block"><span class="nb">Finally, we note that in </span><span class="nv">\version</span><span class="nb">{} of XSB a ``cut&#39;&#39; over tables</span>
</div><div id="l717" class="code_block"><span class="nb">implicitly occurs when the user makes a call to a tabled predicate</span>
</div><div id="l718" class="code_block"><span class="nb">from the interpreter level, but does not generate all solutions.  This</span>
</div><div id="l719" class="code_block"><span class="nb">commonly occurs in batched scheduling, but can also occur in local</span>
</div><div id="l720" class="code_block"><span class="nb">scheduling if an exception occurs.  In such a case, the user will see</span>
</div><div id="l721" class="code_block"><span class="nb">the warning {</span><span class="nv">\tt</span><span class="nb"> &quot;Removing incomplete tables...&quot;} appear.  Any</span>
</div><div id="l722" class="code_block"><span class="nb">complete tables will not be removed.  They can be abolished by using</span>
</div><div id="l723" class="code_block"><span class="nb">one of XSB&#39;s predicates for abolishing tables.</span>
</div><div id="l724" class="code_block">
</div><div id="l725" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Call Subumption and Meta</span><span class="o">-</span><span class="nb">Logical Predicates}</span>
</div><div id="l726" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption</span><span class="o">!</span><span class="nb">interaction with meta</span><span class="o">-</span><span class="nb">logical predicates}</span>
</div><div id="l727" class="code_block">
</div><div id="l728" class="code_block"><span class="nb">Meta</span><span class="o">-</span><span class="nb">logical predicates like {</span><span class="nv">\tt</span><span class="nb"> var</span><span class="o">/</span><span class="m">1</span><span class="nb">} can be used to filter the</span>
</div><div id="l729" class="code_block"><span class="nb">choices made during an evaluation.  However, this is dangerous when</span>
</div><div id="l730" class="code_block"><span class="nb">used in conjunction with call subsumption, since call subsumption</span>
</div><div id="l731" class="code_block"><span class="nb">assumes that if a specific relation holds~</span><span class="o">---</span><span class="nb">~e.g.,</span>
</div><div id="l732" class="code_block"><span class="nv">\texttt</span><span class="nb">{p</span><span class="o">(</span><span class="nb">a</span><span class="o">)</span><span class="nb">}~</span><span class="o">---</span><span class="nb">~then a more general query~</span><span class="o">---</span><span class="nb">~e.g.,</span>
</div><div id="l733" class="code_block"><span class="nv">\texttt</span><span class="nb">{p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}~</span><span class="o">---</span><span class="nb">~will also hold.</span>
</div><div id="l734" class="code_block">
</div><div id="l735" class="code_block"><span class="nv">\begin</span><span class="nb">{example}</span><span class="nv">\label</span><span class="nb">{example:sub</span><span class="o">-</span><span class="nb">fail}</span>
</div><div id="l736" class="code_block"><span class="nb">Consider the following simple program</span>
</div><div id="l737" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l738" class="code_block"><span class="nb">        p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> var</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">, X </span><span class="o">=</span><span class="nb"> a.</span>
</div><div id="l739" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l740" class="code_block"><span class="nb">to which the queries</span>
</div><div id="l741" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l742" class="code_block"><span class="nb">        ?</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l743" class="code_block"><span class="nb">        ?</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">a</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l744" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l745" class="code_block"><span class="nb">are posed.  Let us compare the outcome of these queries when</span>
</div><div id="l746" class="code_block"><span class="nv">\code</span><span class="nb">{p</span><span class="o">/</span><span class="m">1</span><span class="nb">} is </span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">~a Prolog predicate, </span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">~a variant</span><span class="o">-</span><span class="nb">tabled predicate,</span>
</div><div id="l747" class="code_block"><span class="nb">and </span><span class="o">(</span><span class="m">3</span><span class="o">)</span><span class="nb">~a subsumptive</span><span class="o">-</span><span class="nb">tabled predicate.</span>
</div><div id="l748" class="code_block">
</div><div id="l749" class="code_block"><span class="nb">Both Prolog and variant</span><span class="o">-</span><span class="nb">based tabling yield the same solutions:</span>
</div><div id="l750" class="code_block"><span class="nv">\code</span><span class="nb">{X </span><span class="o">=</span><span class="nb"> a}</span><span class="nv">\,</span><span class="nb"> and</span><span class="nv">\,</span><span class="nb"> </span><span class="nv">\code</span><span class="nb">{no}, respectively.  Under call subsumption,</span>
</div><div id="l751" class="code_block"><span class="nb">the query </span><span class="nv">\verb</span><span class="nb">|?</span><span class="o">-</span><span class="nb">|</span><span class="s">$</span><span class="k">\;</span><span class="s">$</span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.} likewise results in the solution</span>
</div><div id="l752" class="code_block"><span class="nv">\code</span><span class="nb">{X </span><span class="o">=</span><span class="nb"> a}.  However, the query </span><span class="nv">\verb</span><span class="nb">|?</span><span class="o">-</span><span class="nb">|</span><span class="s">$</span><span class="k">\;</span><span class="s">$</span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="nb">a</span><span class="o">)</span><span class="nb">.}  is</span>
</div><div id="l753" class="code_block"><span class="nb">subsumed by the tabled subgoal </span><span class="nv">\code</span><span class="nb">{p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}~</span><span class="o">---</span><span class="nb">~which was entered into</span>
</div><div id="l754" class="code_block"><span class="nb">the table when that query was issued~</span><span class="o">---</span><span class="nb">~resulting in the incorrect</span>
</div><div id="l755" class="code_block"><span class="nb">answer </span><span class="nv">\code</span><span class="nb">{yes}.</span><span class="nv">\fillBox</span>
</div><div id="l756" class="code_block"><span class="nv">\end</span><span class="nb">{example}</span>
</div><div id="l757" class="code_block"><span class="c">%</span>
</div><div id="l758" class="code_block"><span class="nb">As this example shows, </span><span class="nv">\emph</span><span class="nb">{incorrect answers} can result from using</span>
</div><div id="l759" class="code_block"><span class="nb">meta</span><span class="o">-</span><span class="nb">logical with subsumptive predicates in this way.</span>
</div><div id="l760" class="code_block">
</div><div id="l761" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l762" class="code_block">
</div><div id="l763" class="code_block"><span class="nv">\subsection</span><span class="nb">{Potential Pitfalls in Tabling}</span>
</div><div id="l764" class="code_block"><span class="nv">\label</span><span class="nb">{sec:TablingPitfalls}</span>
</div><div id="l765" class="code_block">
</div><div id="l766" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Over</span><span class="o">-</span><span class="nb">Tabling}</span>
</div><div id="l767" class="code_block"><span class="nb">While the judicious use of tabling can make some programs faster, its</span>
</div><div id="l768" class="code_block"><span class="nb">indiscriminate use can make other programs slower.  Naively tabling</span>
</div><div id="l769" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> append</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l770" class="code_block"><span class="nv">\begin</span><span class="nb">{center}</span>
</div><div id="l771" class="code_block"><span class="nv">\begin</span><span class="nb">{minipage}{</span><span class="m">3</span><span class="nb">.</span><span class="m">5</span><span class="nb">in}</span>
</div><div id="l772" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l773" class="code_block"><span class="nb">append</span><span class="o">([]</span><span class="nb">,L,L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l774" class="code_block"><span class="nb">append</span><span class="o">([</span><span class="nb">H|T</span><span class="o">]</span><span class="nb">,L,</span><span class="o">[</span><span class="nb">H|T</span><span class="m">1</span><span class="o">])</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> append</span><span class="o">(</span><span class="nb">T,L,T</span><span class="m">1</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l775" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}						       </span>
</div><div id="l776" class="code_block"><span class="nv">\end</span><span class="nb">{minipage}</span>
</div><div id="l777" class="code_block"><span class="nv">\end</span><span class="nb">{center}</span>
</div><div id="l778" class="code_block"><span class="nb">is one such example.  Doing so can, in the worst case, copy </span><span class="s">$</span>N<span class="s">$</span>
</div><div id="l779" class="code_block"><span class="nb">sublists of the first and third arguments into the table, transforming</span>
</div><div id="l780" class="code_block"><span class="nb">a linear algorithm into a quadratic one.</span>
</div><div id="l781" class="code_block">
</div><div id="l782" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:append}</span>
</div><div id="l783" class="code_block"><span class="nb">If you need convincing that tabling can sometimes slow a query down,</span>
</div><div id="l784" class="code_block"><span class="nb">type the query:</span>
</div><div id="l785" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l786" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> genlist</span><span class="o">(</span><span class="m">1000</span><span class="nb">,L</span><span class="o">)</span><span class="nb">, prolog_append</span><span class="o">(</span><span class="nb">L,</span><span class="o">[</span><span class="nb">a</span><span class="o">]</span><span class="nb">,Out</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l787" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l788" class="code_block"><span class="nb">and then type the query</span>
</div><div id="l789" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l790" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> genlist</span><span class="o">(</span><span class="m">1000</span><span class="nb">,L</span><span class="o">)</span><span class="nb">, table_append</span><span class="o">(</span><span class="nb">L,</span><span class="o">[</span><span class="nb">a</span><span class="o">]</span><span class="nb">,Out</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l791" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l792" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> append</span><span class="o">/</span><span class="m">3</span><span class="nb">} is a particularly bad predicate to table.  Type the query</span>
</div><div id="l793" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l794" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> table_append</span><span class="o">(</span><span class="nb">L,</span><span class="o">[</span><span class="nb">a</span><span class="o">]</span><span class="nb">,Out</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l795" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l796" class="code_block"><span class="nb">leaving off the call to {</span><span class="nv">\tt</span><span class="nb"> genlist</span><span class="o">/</span><span class="m">2</span><span class="nb">}, and backtrack through a few answers.</span>
</div><div id="l797" class="code_block"><span class="nb">Will {</span><span class="nv">\tt</span><span class="nb"> table</span><span class="nv">\_</span><span class="nb">append</span><span class="o">/</span><span class="m">3</span><span class="nb">} ever succeed for this predicate?  Why not?</span>
</div><div id="l798" class="code_block">
</div><div id="l799" class="code_block"><span class="nb">Suppose DCG predicates </span><span class="o">(</span><span class="nb">Section </span><span class="nv">\ref</span><span class="nb">{DCGs}</span><span class="o">)</span><span class="nb"> are defined to be tabled.</span>
</div><div id="l800" class="code_block"><span class="nb">How is this similar to tabling append?</span><span class="nv">\fillBox</span>
</div><div id="l801" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l802" class="code_block"><span class="c">%</span>
</div><div id="l803" class="code_block"><span class="nb">We note that XSB has special mechanisms for handling tabled DCGs.  See</span>
</div><div id="l804" class="code_block"><span class="nb">Section </span><span class="nv">\ref</span><span class="nb">{DCGs} for details.</span>
</div><div id="l805" class="code_block">
</div><div id="l806" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Tabled Predicates and Tracing}</span>
</div><div id="l807" class="code_block"><span class="nb">Another issue to be aware of when using tabling in XSB is tracing.</span>
</div><div id="l808" class="code_block"><span class="nb">XSB&#39;s tracer is a standard </span><span class="m">4</span><span class="o">-</span><span class="nb">port tracer that interacts with the</span>
</div><div id="l809" class="code_block"><span class="nb">engine at each call, exit, redo, and failure of a predicate </span><span class="o">(</span><span class="nb">see</span>
</div><div id="l810" class="code_block"><span class="nb">Chapter </span><span class="nv">\ref</span><span class="nb">{debugging}</span><span class="o">)</span><span class="nb">.  When tabled predicates are traced, these</span>
</div><div id="l811" class="code_block"><span class="nb">events may occur in unexpected ways, as the following example shows.</span>
</div><div id="l812" class="code_block">
</div><div id="l813" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:scc}</span>
</div><div id="l814" class="code_block">
</div><div id="l815" class="code_block"><span class="nb">Consider a tabled evaluation when the query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> a</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">} is given</span>
</div><div id="l816" class="code_block"><span class="nb">to the following program</span>
</div><div id="l817" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l818" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table mut_ret_a</span><span class="o">/</span><span class="m">2</span><span class="nb">, mut_ret_b</span><span class="o">/</span><span class="m">2</span><span class="nb">.</span>
</div><div id="l819" class="code_block"><span class="nb">mut_ret_a</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> mut_ret_d</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l820" class="code_block"><span class="nb">mut_ret_a</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> mut_ret_b</span><span class="o">(</span><span class="nb">X,Z</span><span class="o">)</span><span class="nb">,mut_ret_c</span><span class="o">(</span><span class="nb">Z,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l821" class="code_block">
</div><div id="l822" class="code_block"><span class="nb">mut_ret_b</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> mut_ret_c</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l823" class="code_block"><span class="nb">mut_ret_b</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> mut_ret_a</span><span class="o">(</span><span class="nb">X,Z</span><span class="o">)</span><span class="nb">,mut_ret_d</span><span class="o">(</span><span class="nb">Z,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l824" class="code_block">
</div><div id="l825" class="code_block"><span class="nb">mut_ret_c</span><span class="o">(</span><span class="m">2</span><span class="nb">,</span><span class="m">2</span><span class="o">)</span><span class="nb">.      mut_ret_c</span><span class="o">(</span><span class="m">3</span><span class="nb">,</span><span class="m">3</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l826" class="code_block">
</div><div id="l827" class="code_block"><span class="nb">mut_ret_d</span><span class="o">(</span><span class="m">0</span><span class="nb">,</span><span class="m">1</span><span class="o">)</span><span class="nb">.	     mut_ret_d</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="o">)</span><span class="nb">.     mut_ret_d</span><span class="o">(</span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l828" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l829" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">a</span><span class="o">(</span><span class="m">0</span><span class="nb">,</span><span class="m">1</span><span class="o">)</span><span class="nb">} can be derived immediately from the first</span>
</div><div id="l830" class="code_block"><span class="nb">clause of {</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">a</span><span class="o">/</span><span class="m">2</span><span class="nb">}.  All other answers to the query depend</span>
</div><div id="l831" class="code_block"><span class="nb">on answers to the subgoal {</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">b</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">} which arises in the</span>
</div><div id="l832" class="code_block"><span class="nb">evaluation of the second clause of {</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">a</span><span class="o">/</span><span class="m">2</span><span class="nb">}.  Each answer</span>
</div><div id="l833" class="code_block"><span class="nb">to {</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">b</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">} in turn depends on an answer to {</span><span class="nv">\tt</span>
</div><div id="l834" class="code_block"><span class="nb">mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">a</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">}, so that the evaluation switches back and forth</span>
</div><div id="l835" class="code_block"><span class="nb">between deriving answers for {</span><span class="nv">\tt</span><span class="nb"> mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">a</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">} and {</span><span class="nv">\tt</span>
</div><div id="l836" class="code_block"><span class="nb">mut</span><span class="nv">\_</span><span class="nb">ret</span><span class="nv">\_</span><span class="nb">b</span><span class="o">(</span><span class="m">0</span><span class="nb">,X</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l837" class="code_block">
</div><div id="l838" class="code_block"><span class="nb">Try tracing this evaluation, using creep and skip.  Do you find the</span>
</div><div id="l839" class="code_block"><span class="nb">behavior intuitive or not?</span><span class="nv">\fillBox</span>
</div><div id="l840" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l841" class="code_block">
</div><div id="l842" class="code_block"><span class="c">%=====================================================================</span>
</div><div id="l843" class="code_block">
</div><div id="l844" class="code_block"><span class="nv">\section</span><span class="nb">{Normal Programs}</span>
</div><div id="l845" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">negation}</span>
</div><div id="l846" class="code_block"><span class="nb">Normal programs extend definite programs to include default negation,</span>
</div><div id="l847" class="code_block"><span class="nb">which posits a fact as false if all attempts to prove it fail.  As</span>
</div><div id="l848" class="code_block"><span class="nb">shown in Example </span><span class="nv">\ref</span><span class="nb">{ex:Russell}, which presented one of Russell&#39;s</span>
</div><div id="l849" class="code_block"><span class="nb">paradoxes as a logic program, the addition of default negation allows</span>
</div><div id="l850" class="code_block"><span class="nb">logic programs to express contradictions.  As a result, some</span>
</div><div id="l851" class="code_block"><span class="nb">assertions, such as {</span><span class="nv">\tt</span><span class="nb"> shaves</span><span class="o">(</span><span class="nb">barber,barber</span><span class="o">)</span><span class="nb">} may be undefined,</span>
</div><div id="l852" class="code_block"><span class="nb">although other facts, such as {</span><span class="nv">\tt</span><span class="nb"> shaves</span><span class="o">(</span><span class="nb">barber,mayor</span><span class="o">)</span><span class="nb">} may be true.</span>
</div><div id="l853" class="code_block"><span class="nb">Formally, the meaning of normal programs may be given using the {</span><span class="nv">\em</span>
</div><div id="l854" class="code_block"><span class="nb">well</span><span class="o">-</span><span class="nb">founded semantics} and it is this semantics that XSB adopts for</span>
</div><div id="l855" class="code_block"><span class="nb">negation </span><span class="o">(</span><span class="nb">we note that in </span><span class="nv">\version</span><span class="nb">{} the well</span><span class="o">-</span><span class="nb">founded semantics is</span>
</div><div id="l856" class="code_block"><span class="nb">implemented only for variant</span><span class="o">-</span><span class="nb">based tabling</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l857" class="code_block">
</div><div id="l858" class="code_block"><span class="nv">\subsection</span><span class="nb">{Stratified Normal Programs}</span>
</div><div id="l859" class="code_block"><span class="nv">\index</span><span class="nb">{negation</span><span class="o">!</span><span class="nb">stratified}</span>
</div><div id="l860" class="code_block">
</div><div id="l861" class="code_block"><span class="nb">Before considering the full well</span><span class="o">-</span><span class="nb">founded semantics, we discuss how XSB</span>
</div><div id="l862" class="code_block"><span class="nb">can be used to evaluate programs with {</span><span class="nv">\em</span><span class="nb"> stratified negation}.</span>
</div><div id="l863" class="code_block"><span class="nb">Intuitively, a program uses stratified negation whenever there is no</span>
</div><div id="l864" class="code_block"><span class="nb">recursion through negation.  Indeed, most programmers, most of the</span>
</div><div id="l865" class="code_block"><span class="nb">time, use stratified negation.  </span>
</div><div id="l866" class="code_block"><span class="c">%Refining this intuition can lead to an</span>
</div><div id="l867" class="code_block"><span class="c">%array of stratification classes which we will discuss in Section</span>
</div><div id="l868" class="code_block"><span class="c">%\ref{sec:nonstrat}.</span>
</div><div id="l869" class="code_block">
</div><div id="l870" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:win</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l871" class="code_block"><span class="nb">The program</span>
</div><div id="l872" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l873" class="code_block"><span class="nb">         win</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> move</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">,tnot</span><span class="o">(</span><span class="nb">win</span><span class="o">(</span><span class="nb">Y</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l874" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l875" class="code_block"><span class="nb">is stratified when the {</span><span class="nv">\tt</span><span class="nb"> move</span><span class="o">/</span><span class="m">2</span><span class="nb">} relation is a binary tree.  To see</span>
</div><div id="l876" class="code_block"><span class="nb">this, load the files </span><span class="nv">\textup</span><span class="nb">{</span><span class="nv">\texttt</span><span class="nb">{tree</span><span class="m">1</span><span class="nb">k.P}} and</span>
</div><div id="l877" class="code_block"><span class="nv">\textup</span><span class="nb">{</span><span class="nv">\texttt</span><span class="nb">{table</span><span class="nv">\_</span><span class="nb">examples.P}} from the directory</span>
</div><div id="l878" class="code_block"><span class="nv">\textup</span><span class="nb">{</span><span class="nv">\texttt</span><span class="nb">{</span><span class="nv">\$</span><span class="nb">XSB</span><span class="nv">\_</span><span class="nb">DIR</span><span class="o">/</span><span class="nb">examples}} and type the query</span>
</div><div id="l879" class="code_block"><span class="c">%</span>
</div><div id="l880" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l881" class="code_block"><span class="nb">         ?</span><span class="o">-</span><span class="nb"> win</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l882" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l883" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">} calls {</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">} through negation, {</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">} calls</span>
</div><div id="l884" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">(</span><span class="m">4</span><span class="o">)</span><span class="nb">} through negation, and so on, but no subgoal ever calls</span>
</div><div id="l885" class="code_block"><span class="nb">itself recursively through negation.</span>
</div><div id="l886" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l887" class="code_block">
</div><div id="l888" class="code_block"><span class="nb">The previous example of {</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">/</span><span class="m">1</span><span class="nb">} over a binary tree is a simple</span>
</div><div id="l889" class="code_block"><span class="nb">instance of a stratified program, but it does not even require</span>
</div><div id="l890" class="code_block"><span class="nb">tabling.  A more complex example is presented below.</span>
</div><div id="l891" class="code_block">
</div><div id="l892" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise} </span><span class="nv">\label</span><span class="nb">{ex:lrd}</span>
</div><div id="l893" class="code_block"><span class="nb">Consider the query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> lrd</span><span class="nv">\_</span><span class="nb">s} to the following program</span>
</div><div id="l894" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l895" class="code_block"><span class="nb">lrd_p:</span><span class="o">-</span><span class="nb"> lrd_q,tnot</span><span class="o">(</span><span class="nb">lrd_r</span><span class="o">)</span><span class="nb">,tnot</span><span class="o">(</span><span class="nb">lrd_s</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l896" class="code_block"><span class="nb">lrd_q:</span><span class="o">-</span><span class="nb"> lrd_r,tnot</span><span class="o">(</span><span class="nb">lrd_p</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l897" class="code_block"><span class="nb">lrd_r:</span><span class="o">-</span><span class="nb"> lrd_p,tnot</span><span class="o">(</span><span class="nb">lrd_q</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l898" class="code_block"><span class="nb">lrd_s:</span><span class="o">-</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">lrd_p</span><span class="o">)</span><span class="nb">,tnot</span><span class="o">(</span><span class="nb">lrd_q</span><span class="o">)</span><span class="nb">,tnot</span><span class="o">(</span><span class="nb">lrd_r</span><span class="o">)</span><span class="nb">. </span>
</div><div id="l899" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l900" class="code_block"><span class="nb">Should {</span><span class="nv">\tt</span><span class="nb"> lrd</span><span class="nv">\_</span><span class="nb">s} be true or false?  Try it in XSB</span><span class="nv">\@</span><span class="nb">.  Using the</span>
</div><div id="l901" class="code_block"><span class="nb">intuitive definition of ``stratified&#39;&#39; as not using recursion through</span>
</div><div id="l902" class="code_block"><span class="nb">negation, is this program stratified?  Would the program still be</span>
</div><div id="l903" class="code_block"><span class="nb">stratified if the order of the literals in the body of clauses for</span>
</div><div id="l904" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> lrd</span><span class="nv">\_</span><span class="nb">p}, {</span><span class="nv">\tt</span><span class="nb"> lrd</span><span class="nv">\_</span><span class="nb">q}, or {</span><span class="nv">\tt</span><span class="nb"> lrd</span><span class="nv">\_</span><span class="nb">r} were changed?</span>
</div><div id="l905" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l906" class="code_block">
</div><div id="l907" class="code_block"><span class="nb">The rules for {</span><span class="nv">\tt</span><span class="nb"> p}, {</span><span class="nv">\tt</span><span class="nb"> q} and {</span><span class="nv">\tt</span><span class="nb"> r} are involved in a positive</span>
</div><div id="l908" class="code_block"><span class="nb">loop, and no answers are ever produced.  Each of these atoms can be</span>
</div><div id="l909" class="code_block"><span class="nb">failed, thereby proving {</span><span class="nv">\tt</span><span class="nb"> s}.  Exercise </span><span class="nv">\ref</span><span class="nb">{ex:lrd} thus</span>
</div><div id="l910" class="code_block"><span class="nb">illustrates an instance of how tabling differs from Prolog in</span>
</div><div id="l911" class="code_block"><span class="nb">executing stratified programs since Prolog would not fail finitely for</span>
</div><div id="l912" class="code_block"><span class="nb">this program~</span><span class="nv">\footnote</span><span class="nb">{</span><span class="nv">\LRD</span><span class="nb"> stratification may be reminiscent of the</span>
</div><div id="l913" class="code_block"><span class="nb">  Subgoal Dependency Graphs of Section~</span><span class="nv">\ref</span><span class="nb">{section:scheduling} but</span>
</div><div id="l914" class="code_block"><span class="nb">  differ in several respects, most notably in that stratification</span>
</div><div id="l915" class="code_block"><span class="nb">  considers only cycles through negative dependencies.}.</span>
</div><div id="l916" class="code_block">
</div><div id="l917" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{Completely Evaluated Subgoals}</span>
</div><div id="l918" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">complete evaluation}</span>
</div><div id="l919" class="code_block">
</div><div id="l920" class="code_block"><span class="nb">Knowing when a subgoal is completely evaluated can be useful when</span>
</div><div id="l921" class="code_block"><span class="nb">programming with tabling.  Simply put, a subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is {</span><span class="nv">\em</span><span class="nb"> completely</span>
</div><div id="l922" class="code_block"><span class="nb">evaluated} if an evaluation can produce no more answers for </span><span class="s">$</span>S<span class="s">$</span><span class="nv">\@</span><span class="nb">.  The</span>
</div><div id="l923" class="code_block"><span class="nb">computational strategy of XSB makes great use of complete evaluation</span>
</div><div id="l924" class="code_block"><span class="nb">so that understanding this concept and its implications can be of</span>
</div><div id="l925" class="code_block"><span class="nb">great help to a programmer.</span>
</div><div id="l926" class="code_block">
</div><div id="l927" class="code_block"><span class="nb">Consider a simple approach to incorporating negation into tabling.</span>
</div><div id="l928" class="code_block"><span class="nb">Each time a negative goal is called, a separate table is opened for</span>
</div><div id="l929" class="code_block"><span class="nb">the negative call.  This evaluation of the call is carried on to</span>
</div><div id="l930" class="code_block"><span class="nb">termination.  If the evaluation terminates, its answers if any, are</span>
</div><div id="l931" class="code_block"><span class="nb">used to determine the success of failure of the calling goal.  This</span>
</div><div id="l932" class="code_block"><span class="nb">general mechanism underlies early formulations for tabling stratified</span>
</div><div id="l933" class="code_block"><span class="nb">programs </span><span class="nv">\cite</span><span class="nb">{KeTo</span><span class="m">88</span><span class="nb">,Seki</span><span class="m">89</span><span class="nb">}.  Of course this method may not be</span>
</div><div id="l934" class="code_block"><span class="nb">efficient.  Every time a new negative goal is called, a new table must</span>
</div><div id="l935" class="code_block"><span class="nb">be started, and run to termination.  We would like to use information</span>
</div><div id="l936" class="code_block"><span class="nb">already derived from the computation to answer a new query, if at all</span>
</div><div id="l937" class="code_block"><span class="nb">possible </span><span class="o">---</span><span class="nb"> just as with definite programs.</span>
</div><div id="l938" class="code_block">
</div><div id="l939" class="code_block"><span class="nv">\index</span><span class="nb">{tabled subgoals</span><span class="o">!</span><span class="nb">incomplete}</span>
</div><div id="l940" class="code_block"><span class="nv">\index</span><span class="nb">{tabled subgoals</span><span class="o">!</span><span class="nb">complete}</span>
</div><div id="l941" class="code_block"><span class="nb">XSB addresses this problem by keeping track of the {</span><span class="nv">\em</span><span class="nb"> state} of each</span>
</div><div id="l942" class="code_block"><span class="nb">subgoal in the table.  A call can have a state of {</span><span class="nv">\em</span><span class="nb"> complete}, {</span><span class="nv">\em</span>
</div><div id="l943" class="code_block"><span class="nb">incomplete} or {</span><span class="nv">\em</span><span class="nb"> not</span><span class="nv">\_</span><span class="nb">yet</span><span class="nv">\_</span><span class="nb">called}.  </span>
</div><div id="l944" class="code_block"><span class="c">%The value $not\_yet\_called$</span>
</div><div id="l945" class="code_block"><span class="c">%means that there is in fact no table entry.  </span>
</div><div id="l946" class="code_block"><span class="nb">Calls that do have table entries may be either </span><span class="s">$</span>complete<span class="s">$</span><span class="nb"> or</span>
</div><div id="l947" class="code_block"><span class="s">$</span>incomplete<span class="s">$</span><span class="nb">.  A subgoal in a table is marked </span><span class="s">$</span>complete<span class="s">$</span><span class="nb"> only after it</span>
</div><div id="l948" class="code_block"><span class="nb">is determined to be completely evaluated; otherwise the subgoal is</span>
</div><div id="l949" class="code_block"><span class="s">$</span>incomplete<span class="s">$</span><span class="nb">.  If a tabled subgoal is not present in the table, it is</span>
</div><div id="l950" class="code_block"><span class="nb">termed {</span><span class="nv">\em</span><span class="nb"> not</span><span class="nv">\_</span><span class="nb">yet</span><span class="nv">\_</span><span class="nb">called}.  XSB contains predicates that allow a</span>
</div><div id="l951" class="code_block"><span class="nb">user to examine the state of a given table </span><span class="o">(</span><span class="nb">Section</span>
</div><div id="l952" class="code_block"><span class="nv">\ref</span><span class="nb">{sec:TablingPredicates}</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l953" class="code_block">
</div><div id="l954" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">early completion of subgoals} </span>
</div><div id="l955" class="code_block"><span class="nb">There are in fact two ways that a tabled subgoal </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> can be determined</span>
</div><div id="l956" class="code_block"><span class="nb">to be completely evaluated.  If </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is part of an SCC </span><span class="s">$</span><span class="k">\cS</span><span class="s">$</span><span class="nb">, </span><span class="o">(</span><span class="nb">a</span>
</div><div id="l957" class="code_block"><span class="nb">mutually recorsive component</span><span class="o">)</span><span class="nb">, then </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> can be completed once it is</span>
</div><div id="l958" class="code_block"><span class="nb">ensure that all resolution steps have been done to all subgoals in</span>
</div><div id="l959" class="code_block"><span class="s">$</span><span class="k">\cS</span><span class="s">$</span><span class="nb">.  Otherwise, if there is a derivation of an answer that is</span>
</div><div id="l960" class="code_block"><span class="nb">identical to </span><span class="s">$</span>S<span class="s">$</span><span class="nb">, </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> can be completed before the rest of the subgoals</span>
</div><div id="l961" class="code_block"><span class="nb">in </span><span class="s">$</span><span class="k">\cS</span><span class="s">$</span><span class="nb"> since further evaluation of </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> itself will not produce</span>
</div><div id="l962" class="code_block"><span class="nb">useful information.  In this case, we sometimes say that </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> is {</span><span class="nv">\em</span>
</div><div id="l963" class="code_block"><span class="nb">  early completed}.</span>
</div><div id="l964" class="code_block">
</div><div id="l965" class="code_block"><span class="nb">Using these concepts, we can overview how tabled negation is evaluated</span>
</div><div id="l966" class="code_block"><span class="nb">for stratified programs.  If a literal {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">S</span><span class="o">)</span><span class="nb">} is called, where</span>
</div><div id="l967" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> S} is a tabled subgoal, the evaluation checks the state of {</span><span class="nv">\tt</span>
</div><div id="l968" class="code_block"><span class="nb">S}.  If {</span><span class="nv">\tt</span><span class="nb"> S} is </span><span class="s">$</span>complete<span class="s">$</span><span class="nb"> the engine simply determines whether the</span>
</div><div id="l969" class="code_block"><span class="nb">table contains an answer for {</span><span class="nv">\tt</span><span class="nb"> S}.  Otherwise the engine </span><span class="s">$</span>suspends<span class="s">$</span>
</div><div id="l970" class="code_block"><span class="nb">the computation path leading to {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">S</span><span class="o">)</span><span class="nb">} until {</span><span class="nv">\tt</span><span class="nb"> S} is</span>
</div><div id="l971" class="code_block"><span class="nb">completed </span><span class="o">(</span><span class="nb">and calls {</span><span class="nv">\tt</span><span class="nb"> S} if necessary</span><span class="o">)</span><span class="nb">.  Whenever a suspended</span>
</div><div id="l972" class="code_block"><span class="nb">subgoal {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">S</span><span class="o">)</span><span class="nb">} is completed with no answers, the engine resumes</span>
</div><div id="l973" class="code_block"><span class="nb">the evaluation at the point where it had been suspended.  We note that</span>
</div><div id="l974" class="code_block"><span class="nb">because of this behavior, tracing programs that heavily use negation</span>
</div><div id="l975" class="code_block"><span class="nb">may produce behavior unexpected by the user.</span>
</div><div id="l976" class="code_block">
</div><div id="l977" class="code_block">
</div><div id="l978" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} vs. </span><span class="nv">\not</span><span class="nb"> }</span>
</div><div id="l979" class="code_block"><span class="nv">\predrefindex</span><span class="nb">{tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l980" class="code_block"><span class="nv">\index</span><span class="nb">{</span><span class="nv">\texttt</span><span class="nb">{</span><span class="s">$</span><span class="k">\backslash</span><span class="s">$</span><span class="o">+/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l981" class="code_block"><span class="nb">Subject to some semantic restrictions, an XSB programmer can intermix</span>
</div><div id="l982" class="code_block"><span class="nb">the use of tabled negation </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb"> with Prolog&#39;s negation</span>
</div><div id="l983" class="code_block"><span class="o">(</span><span class="nv">\not</span><span class="nb">, or equivalently {</span><span class="nv">\tt</span><span class="nb"> fail</span><span class="nv">\_</span><span class="nb">if</span><span class="o">/</span><span class="m">1</span><span class="nb">} or {</span><span class="nv">\tt</span><span class="nb"> not</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb">.  These</span>
</div><div id="l984" class="code_block"><span class="nb">restrictions are discussed in detail below </span><span class="o">---</span><span class="nb"> for now we focus on</span>
</div><div id="l985" class="code_block"><span class="nb">differences in behavior or these two predicates in stratified</span>
</div><div id="l986" class="code_block"><span class="nb">programs.  Recall that </span><span class="s">$</span><span class="nb">{</span><span class="k">\tt</span> &#39;<span class="k">\backslash</span>+&#39;(S)<span class="nb">}</span><span class="s">$</span><span class="nb"> calls </span><span class="s">$</span>S<span class="s">$</span><span class="nb"> and if </span><span class="s">$</span>S<span class="s">$</span>
</div><div id="l987" class="code_block"><span class="nb">has a solution, Prolog executes a cut over the subtree created by</span>
</div><div id="l988" class="code_block"><span class="s">$</span><span class="nb">{</span><span class="k">\tt</span> &#39;<span class="k">\backslash</span>+&#39;(S)<span class="nb">}</span><span class="s">$</span><span class="nb">, and fails.  {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} on the other hand,</span>
</div><div id="l989" class="code_block"><span class="nb">does not execute a cut, so that all subgoals in the computation path</span>
</div><div id="l990" class="code_block"><span class="nb">begun by the negative call will be completely evaluated.  The major</span>
</div><div id="l991" class="code_block"><span class="nb">reason for not executing the cut is to ensure that XSB evaluates</span>
</div><div id="l992" class="code_block"><span class="nb">ground queries to Datalog programs with negation with polynomial data</span>
</div><div id="l993" class="code_block"><span class="nb">complexity.  As seen </span><span class="nv">\cite</span><span class="nb">{ChWa</span><span class="m">96</span><span class="nb">}, this property cannot be preserved</span>
</div><div id="l994" class="code_block"><span class="nb">if negation ``cuts&#39;&#39; over tables.</span>
</div><div id="l995" class="code_block">
</div><div id="l996" class="code_block"><span class="nb">There are other small differences between {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} and </span><span class="nv">\not</span><span class="nb"> </span>
</div><div id="l997" class="code_block"><span class="nv">\</span><span class="nb"> illustrated in the following exercise.</span>
</div><div id="l998" class="code_block">
</div><div id="l999" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise}</span>
</div><div id="l1000" class="code_block"><span class="nb">In general, making a call to non</span><span class="o">-</span><span class="nb">ground negative subgoal in Prolog may</span>
</div><div id="l1001" class="code_block"><span class="nb">be unsound </span><span class="o">(</span><span class="nb">cf. </span><span class="nv">\cite</span><span class="nb">{Lloy</span><span class="m">84</span><span class="nb">}</span><span class="o">)</span><span class="nb">, but the following program illustrates</span>
</div><div id="l1002" class="code_block"><span class="nb">a case in which non</span><span class="o">-</span><span class="nb">ground negation is sound.</span>
</div><div id="l1003" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1004" class="code_block"><span class="nb">ngr_p:</span><span class="o">-</span><span class="nb"> </span><span class="nv">\+</span><span class="nb"> ngr_p</span><span class="o">(</span><span class="nb">_</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1005" class="code_block"><span class="nb">ngr_p</span><span class="o">(</span><span class="nb">a</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1006" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1007" class="code_block"><span class="nb">One tabled analog is </span>
</div><div id="l1008" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1009" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table ngr_tp</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l1010" class="code_block"><span class="nb">ngr_tp</span><span class="o">(</span><span class="nb">a</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1011" class="code_block">
</div><div id="l1012" class="code_block"><span class="nb">ngr_tp:</span><span class="o">-</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">ngr_tp</span><span class="o">(</span><span class="nb">_</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l1013" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1014" class="code_block"><span class="nv">\version</span><span class="nb">{} of XSB will flounder on the call to {</span><span class="nv">\tt</span><span class="nb"> ngr</span><span class="nv">\_</span><span class="nb">tp}, but not</span>
</div><div id="l1015" class="code_block"><span class="nb">on the call to {</span><span class="nv">\tt</span><span class="nb"> ngr</span><span class="nv">\_</span><span class="nb">p</span><span class="o">/</span><span class="m">0</span><span class="nb">}.  On the other hand if {</span><span class="nv">\tt</span><span class="nb"> sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l1016" class="code_block"><span class="nb">is used</span>
</div><div id="l1017" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1018" class="code_block"><span class="nb">ngr_skp:</span><span class="o">-</span><span class="nb"> sk_not</span><span class="o">(</span><span class="nb">ngr_tp</span><span class="o">(</span><span class="nb">_</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l1019" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1020" class="code_block"><span class="nb">the non</span><span class="o">-</span><span class="nb">ground semantics is allowed.  </span>
</div><div id="l1021" class="code_block"><span class="nv">\end</span><span class="nb">{exercise}</span>
</div><div id="l1022" class="code_block">
</div><div id="l1023" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">} works by</span>
</div><div id="l1024" class="code_block"><span class="nb">asserting a new tabled subgoal, abstractly </span>
</div><div id="l1025" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1026" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table &#39;_</span><span class="s">$</span>ngr<span class="nb">_</span>tp&#39;
</div><div id="l1027" class="code_block">&#39;<span class="nb">_</span><span class="s">$</span><span class="nb">skolem_ngr_tp&#39; :</span><span class="o">-</span><span class="nb"> ngr_tp</span><span class="o">(</span><span class="nb">_</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1028" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1029" class="code_block"><span class="nb">to avoid the problem with variables.  In addition, since {</span><span class="nv">\tt</span>
</div><div id="l1030" class="code_block"><span class="nb">  sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">} creates a new tabled predicate, it can be used to call</span>
</div><div id="l1031" class="code_block"><span class="nb">non</span><span class="o">-</span><span class="nb">tabled predicates as well, ensuring tabling.</span>
</div><div id="l1032" class="code_block">
</div><div id="l1033" class="code_block"><span class="nb">The description of {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} in Section </span><span class="nv">\ref</span><span class="nb">{sec:control} describes</span>
</div><div id="l1034" class="code_block"><span class="nb">other small differences between </span><span class="nv">\not</span><span class="nb"> </span><span class="nv">\</span><span class="nb"> and {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} as implemented</span>
</div><div id="l1035" class="code_block"><span class="nb">in XSB</span><span class="nv">\@</span><span class="nb">. Before leaving the subject of stratification, we note that the</span>
</div><div id="l1036" class="code_block"><span class="nb">concepts of stratification also underly XSB&#39;s evaluation of tabled</span>
</div><div id="l1037" class="code_block"><span class="nb">findall: {</span><span class="nv">\tt</span><span class="nb"> tfindall</span><span class="o">/</span><span class="m">3</span><span class="nb">}.  Here, the idea is that a program is</span>
</div><div id="l1038" class="code_block"><span class="nb">stratified if it contains no loop through tabled findall </span><span class="o">(</span><span class="nb">See the</span>
</div><div id="l1039" class="code_block"><span class="nb">description of predicate {</span><span class="nv">\tt</span><span class="nb"> tfindall</span><span class="o">/</span><span class="m">3</span><span class="nb">} on</span>
</div><div id="l1040" class="code_block"><span class="nb">page~</span><span class="nv">\pageref</span><span class="nb">{tfindall</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1041" class="code_block">
</div><div id="l1042" class="code_block"><span class="nv">\subsection</span><span class="nb">{Non</span><span class="o">-</span><span class="nb">stratified Programs}</span>
</div><div id="l1043" class="code_block"><span class="nv">\index</span><span class="nb">{negation</span><span class="o">!</span><span class="nb">unstratified}</span>
</div><div id="l1044" class="code_block"><span class="nv">\label</span><span class="nb">{negation</span><span class="o">!</span><span class="nb">unstratified}</span>
</div><div id="l1045" class="code_block">
</div><div id="l1046" class="code_block"><span class="nb">As discussed above, in stratified programs, facts are either true or</span>
</div><div id="l1047" class="code_block"><span class="nb">false, while in non</span><span class="o">-</span><span class="nb">stratified programs facts may also be undefined.</span>
</div><div id="l1048" class="code_block"><span class="nb">XSB represents undefined facts as {</span><span class="nv">\em</span><span class="nb"> conditional answers}.</span>
</div><div id="l1049" class="code_block">
</div><div id="l1050" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{Conditional Answers}</span>
</div><div id="l1051" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">conditional answers}</span>
</div><div id="l1052" class="code_block">
</div><div id="l1053" class="code_block"><span class="nv">\begin</span><span class="nb">{exercise}</span>
</div><div id="l1054" class="code_block"><span class="nb">Consider the behavior of the {</span><span class="nv">\tt</span><span class="nb"> win</span><span class="o">/</span><span class="m">1</span><span class="nb">} predicate from Exercise</span>
</div><div id="l1055" class="code_block"><span class="nv">\ref</span><span class="nb">{ex:win</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l1056" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1057" class="code_block"><span class="nb">         win</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">:</span><span class="o">-</span><span class="nb"> move</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">,tnot</span><span class="o">(</span><span class="nb">win</span><span class="o">(</span><span class="nb">Y</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l1058" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1059" class="code_block"><span class="nb">when the when the {</span><span class="nv">\tt</span><span class="nb"> move</span><span class="o">/</span><span class="m">2</span><span class="nb">} relation is a cycle.  Load the file</span>
</div><div id="l1060" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\verb</span><span class="nb">|</span><span class="s">$</span>XSB<span class="nb">_</span>DIR/examples|cycle1k.P<span class="nb">}</span> into XSB and again type the
</div><div id="l1061" class="code_block">query <span class="nb">{</span><span class="k">\tt</span> ?- win(1)<span class="nb">}</span>.  Does the query succeed?  Try <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1062" class="code_block">tnot(win(1))<span class="nb">}</span>.
</div><div id="l1063" class="code_block">
</div><div id="l1064" class="code_block">Now query the table with the standard XSB predicate <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1065" class="code_block">get<span class="k">\_residual</span>/2<span class="nb">}</span>, e.g. <span class="nb">{</span><span class="k">\tt</span> ?- get<span class="k">\_residual</span>(win(1),X)<span class="nb">}</span>.  Can you guess
</div><div id="l1066" class="code_block">what is happening with this non-stratified program?
</div><div id="l1067" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1068" class="code_block">
</div><div id="l1069" class="code_block">The predicate <span class="nb">{</span><span class="k">\tt</span> get<span class="k">\_residual</span>/2<span class="nb">}</span> (Section <span class="k">\ref</span><span class="nb">{</span>sec:TablingPredicates<span class="nb">}</span>)
</div><div id="l1070" class="code_block">unifies its first argument with a tabled subgoal and its second
</div><div id="l1071" class="code_block">argument with the (possibly empty) delay list of that subgoal.  The
</div><div id="l1072" class="code_block">truth of the subgoal is taken to be conditional on the truth of the
</div><div id="l1073" class="code_block">elements in the delay list.  Thus <span class="nb">{</span><span class="k">\tt</span> win(1)<span class="nb">}</span> is conditional on <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1074" class="code_block">tnot(win(2))<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> win(2)<span class="nb">}</span> in <span class="nb">{</span><span class="k">\tt</span> tnot(win(3))<span class="nb">}</span> and so on until <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1075" class="code_block">win(1023)<span class="nb">}</span> which is conditional on <span class="nb">{</span><span class="k">\tt</span> win(1)<span class="nb">}</span>.
</div><div id="l1076" class="code_block">
</div><div id="l1077" class="code_block">From the perspective of the well-founded semantics, <span class="nb">{</span><span class="k">\tt</span> win(1)<span class="nb">}</span> is
</div><div id="l1078" class="code_block">undefined.  Informally, true answers in the well-founded semantics are
</div><div id="l1079" class="code_block">those that have a (tabled) derivation.  False answers are those for
</div><div id="l1080" class="code_block">which all possible derivations fail --- either finitely as in Prolog
</div><div id="l1081" class="code_block">or by failing positive loops.  <span class="nb">{</span><span class="k">\tt</span> win(1)<span class="nb">}</span> fits in neither of these
</div><div id="l1082" class="code_block">cases -- there is no proof of <span class="nb">{</span><span class="k">\tt</span> win(1)<span class="nb">}</span>, yet it does not fail in
</div><div id="l1083" class="code_block">the sense given above and is thus undefined.
</div><div id="l1084" class="code_block">
</div><div id="l1085" class="code_block">However this explanation does not account for why undefined answers
</div><div id="l1086" class="code_block">should be represented as conditional answers, or why a query with a
</div><div id="l1087" class="code_block">conditional answer <span class="nb">{</span><span class="k">\em</span> and<span class="nb">}</span> its negation should both succeed.  These
</div><div id="l1088" class="code_block">features arise from the proof strategy of XSB, which we now examine in
</div><div id="l1089" class="code_block">more detail.
</div><div id="l1090" class="code_block">
</div><div id="l1091" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>ex:simpl<span class="nb">}</span>
</div><div id="l1092" class="code_block">Consider the program
</div><div id="l1093" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1094" class="code_block">:- table simpl<span class="nb">_</span>p/1,simpl<span class="nb">_</span>r/0,simpl<span class="nb">_</span>s/0.
</div><div id="l1095" class="code_block">simpl<span class="nb">_</span>p(X):- tnot(simpl<span class="nb">_</span>s).
</div><div id="l1096" class="code_block">
</div><div id="l1097" class="code_block">simpl<span class="nb">_</span>s:- tnot(simpl<span class="nb">_</span>r).
</div><div id="l1098" class="code_block">simpl<span class="nb">_</span>s:- simpl<span class="nb">_</span>p(X).
</div><div id="l1099" class="code_block">
</div><div id="l1100" class="code_block">simpl<span class="nb">_</span>r:- tnot(simpl<span class="nb">_</span>s),simpl<span class="nb">_</span>r.
</div><div id="l1101" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1102" class="code_block">Try the query <span class="nb">{</span><span class="k">\tt</span> ?- simpl<span class="k">\_p</span>(X)<span class="nb">}</span>.  If you have a copy of XSB defined
</div><div id="l1103" class="code_block">using Batched Scheduling load the examples program and query <span class="nb">{</span><span class="k">\tt</span> ?-
</div><div id="l1104" class="code_block">  simpl<span class="k">\_p</span>(X)<span class="nb">}</span> -- be sure to backtrack through all possible answers.
</div><div id="l1105" class="code_block">Now try the query again.  What could possibly account for the
</div><div id="l1106" class="code_block">difference in behavior between Local and Batched Scheduling?
</div><div id="l1107" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1108" class="code_block">
</div><div id="l1109" class="code_block">At this point, it is worthwhile to examine closely the evaluation of
</div><div id="l1110" class="code_block">the program in Exercise <span class="k">\ref</span><span class="nb">{</span>ex:simpl<span class="nb">}</span>.  The query <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_p</span>(X)<span class="nb">}</span>
</div><div id="l1111" class="code_block">calls <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_s</span><span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_r</span><span class="nb">}</span> and executes the portion of
</div><div id="l1112" class="code_block">the program shown below in bold:
</div><div id="l1113" class="code_block"><span class="k">\begin</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1114" class="code_block"><span class="k">\begin</span><span class="nb">{</span>tabular<span class="nb">}{</span>l<span class="nb">}</span>
</div><div id="l1115" class="code_block"><span class="nb">{</span><span class="k">\bf</span> simpl<span class="k">\_p</span>(X):- tnot(simpl<span class="k">\_s</span>).<span class="nb">}</span> <span class="k">\\</span>
</div><div id="l1116" class="code_block"><span class="k">\\</span>
</div><div id="l1117" class="code_block"><span class="nb">{</span><span class="k">\bf</span> simpl<span class="k">\_s:</span>- tnot(simpl<span class="k">\_r</span>).<span class="nb">}</span> <span class="k">\\</span>
</div><div id="l1118" class="code_block"><span class="nb">{</span><span class="k">\bf</span> simpl<span class="k">\_s:</span>- simpl<span class="k">\_p</span>(X).<span class="nb">}</span> <span class="k">\\</span>
</div><div id="l1119" class="code_block"><span class="k">\\</span>
</div><div id="l1120" class="code_block"><span class="nb">{</span><span class="k">\bf</span> simpl<span class="k">\_r:</span>- tnot(simpl<span class="k">\_s</span>)<span class="nb">}</span>,<span class="nb">{</span><span class="k">\it</span> simpl<span class="k">\_r</span>.<span class="nb">}</span>
</div><div id="l1121" class="code_block"><span class="k">\end</span><span class="nb">{</span>tabular<span class="nb">}</span>
</div><div id="l1122" class="code_block"><span class="k">\end</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1123" class="code_block">Based on evaluating only the bold literals, the three atoms are all
</div><div id="l1124" class="code_block">undefined since they are neither proved true, nor fail.  However if
</div><div id="l1125" class="code_block">the evaluation could only look at the literal in italics, <span class="nb">{</span><span class="k">\em</span>
</div><div id="l1126" class="code_block">  simpl<span class="k">\_r</span><span class="nb">}</span>, it would discover that <span class="nb">{</span><span class="k">\em</span> simpl<span class="k">\_r</span><span class="nb">}</span> is involved in a
</div><div id="l1127" class="code_block">positive loop and, since there is only one clause for <span class="nb">{</span><span class="k">\em</span> simpl<span class="k">\_r</span><span class="nb">}</span>,
</div><div id="l1128" class="code_block">the evaluation could conclude that the atom was false.  This is
</div><div id="l1129" class="code_block">exactly what XSB does, it <span class="nb">{</span><span class="k">\em</span> delays<span class="nb">}</span> the evaluation of <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1130" class="code_block">  tnot(simpl<span class="k">\_s</span>)<span class="nb">}</span> in the clause for <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_r</span><span class="nb">}</span> and looks ahead to
</div><div id="l1131" class="code_block">the next literal in the body of that clause.  This action of looking
</div><div id="l1132" class="code_block">ahead of a negative literal is called <span class="nb">{</span><span class="k">\em</span> delaying<span class="nb">}</span>.  A delayed
</div><div id="l1133" class="code_block">literal is moved into the <span class="nb">{</span><span class="k">\em</span> delay list<span class="nb">}</span> of a current path of
</div><div id="l1134" class="code_block">computation.  Whenever an answer is derived, the delay list of the
</div><div id="l1135" class="code_block">current path of computation is copied into the table.  If the delay
</div><div id="l1136" class="code_block">list is empty, the answer is unconditional; otherwise it is
</div><div id="l1137" class="code_block">conditional.  Of course, for definite programs any answers will be
</div><div id="l1138" class="code_block">unconditional --- we therefore omitted delay lists when discussing
</div><div id="l1139" class="code_block">such programs.
</div><div id="l1140" class="code_block">
</div><div id="l1141" class="code_block">In the above program, delaying occurs for the negative literals in
</div><div id="l1142" class="code_block">clauses for <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_p</span>(X)<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_s</span><span class="nb">}</span>, and <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_r</span><span class="nb">}</span>.
</div><div id="l1143" class="code_block">In the first two cases, conditional answers can be derived, while in
</div><div id="l1144" class="code_block">the third, <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_r</span><span class="nb">}</span> will fail as mentioned above.  Delayed
</div><div id="l1145" class="code_block">literals eventually become evaluated through <span class="nb">{</span><span class="k">\em</span> simplification<span class="nb">}</span>.
</div><div id="l1146" class="code_block">Consider an answer of the form 
</div><div id="l1147" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1148" class="code_block">simpl<span class="nb">_</span>p(X):- tnot(simpl<span class="nb">_</span>s)|
</div><div id="l1149" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1150" class="code_block">where the <span class="nb">{</span><span class="k">\tt</span> |<span class="nb">}</span> is used to represent the end of the delay list.  If,
</div><div id="l1151" class="code_block">after the answer is copied into the table, <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_s</span><span class="nb">}</span> turns out to
</div><div id="l1152" class="code_block">be false, (after being initially delayed), the answer can become
</div><div id="l1153" class="code_block">unconditional.  If <span class="nb">{</span><span class="k">\tt</span> simpl<span class="k">\_s</span><span class="nb">}</span> turns out to be true, the answer
</div><div id="l1154" class="code_block">should be removed, it is false.
</div><div id="l1155" class="code_block">
</div><div id="l1156" class="code_block">In fact, it is this last case that occurs in Exercise <span class="k">\ref</span><span class="nb">{</span>ex:simpl<span class="nb">}</span>.
</div><div id="l1157" class="code_block">The answer
</div><div id="l1158" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1159" class="code_block">simpl<span class="nb">_</span>p(X):- tnot(simpl<span class="nb">_</span>s)|
</div><div id="l1160" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1161" class="code_block">is derived, and returned to the user (XSB does not currently print out
</div><div id="l1162" class="code_block">the delay list).  The answer is then removed through simplification so
</div><div id="l1163" class="code_block">that when the query is re-executed, the answer does not appear.
</div><div id="l1164" class="code_block">
</div><div id="l1165" class="code_block">We will examine in detail how to alter the XSB interface so that
</div><div id="l1166" class="code_block">evaluation of the well-founded semantics need not be confusing.  It is
</div><div id="l1167" class="code_block">worthwhile to note that the behavior just described is uncommon.
</div><div id="l1168" class="code_block">
</div><div id="l1169" class="code_block"><span class="k">\version\</span> of XSB handles dynamically stratified programs through
</div><div id="l1170" class="code_block">delaying negative literals when it becomes necessary to look to their
</div><div id="l1171" class="code_block">right in a clause, and then simplifying away the delayed literals when
</div><div id="l1172" class="code_block">and if their truth value becomes known.  However, to ensure
</div><div id="l1173" class="code_block">efficiency, literals are never delayed unless the engine determines
</div><div id="l1174" class="code_block">them to not to be stratified under the <span class="k">\LRD\</span> evaluation method.
</div><div id="l1175" class="code_block">
</div><div id="l1176" class="code_block"><span class="k">\paragraph</span><span class="nb">{</span>When Conditional Answers are Needed<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>sec:lrd<span class="nb">}</span>
</div><div id="l1177" class="code_block">
</div><div id="l1178" class="code_block">A good Prolog programmer uses the order of literals in the body of a
</div><div id="l1179" class="code_block">clause to make her program more efficient.  However, as seen in the
</div><div id="l1180" class="code_block">previous section, delaying can break the order that literals are
</div><div id="l1181" class="code_block">evaluated within the body of a clause.  It then becomes natural to ask
</div><div id="l1182" class="code_block">if any guarantees can be made that XSB is not delaying literals
</div><div id="l1183" class="code_block">unnecessarily.
</div><div id="l1184" class="code_block">
</div><div id="l1185" class="code_block">Such a guarantee can in fact be made, using the concept of <span class="nb">{</span><span class="k">\em</span>
</div><div id="l1186" class="code_block">dynamic stratification<span class="nb">}</span> <span class="k">\cite</span><span class="nb">{</span>Przy89d<span class="nb">}</span>.  Without going into the
</div><div id="l1187" class="code_block">formalism of dynamic stratification, we note that a program is
</div><div id="l1188" class="code_block">dynamically stratified if and only if it has a two-valued model.  It
</div><div id="l1189" class="code_block">is also known that computation of queries to dynamically
</div><div id="l1190" class="code_block">stratified programs is not possible under any fixed strategy for
</div><div id="l1191" class="code_block">selecting literals within the body of a clause.  In other words, some
</div><div id="l1192" class="code_block">mechanism for breaking the fixed-order literal selection strategy must
</div><div id="l1193" class="code_block">be used, such as delaying.
</div><div id="l1194" class="code_block">
</div><div id="l1195" class="code_block">However, by redefining dynamic stratification to use an arbitrary
</div><div id="l1196" class="code_block">fixed-order literal selection strategy (such as the left-to-right
</div><div id="l1197" class="code_block">strategy of Prolog), a new kind of stratification is characterized,
</div><div id="l1198" class="code_block">called <span class="nb">{</span><span class="k">\em</span> Left-to-Right Dynamic Stratification<span class="nb">}</span>, or <span class="nb">{</span><span class="k">\em</span>
</div><div id="l1199" class="code_block">LRD-stratification<span class="nb">}</span>.  <span class="k">\LRD</span><span class="nb">{}</span> is not as powerful as dynamic
</div><div id="l1200" class="code_block">stratification, but is more powerful than other fixed-order
</div><div id="l1201" class="code_block">stratification methods, and it can be shown that for ground programs,
</div><div id="l1202" class="code_block">XSB delays only when programs are not <span class="k">\LRD</span>.  In the language of
</div><div id="l1203" class="code_block"><span class="k">\cite</span><span class="nb">{</span>SaSW99<span class="nb">}</span> XSB is <span class="nb">{</span><span class="k">\em</span> delay minimal<span class="nb">}</span>.
</div><div id="l1204" class="code_block">
</div><div id="l1205" class="code_block"><span class="k">\paragraph</span><span class="nb">{</span>Programming in the Well-founded Semantics<span class="nb">}</span>
</div><div id="l1206" class="code_block"><span class="k">\index</span><span class="nb">{</span>well-founded semantics<span class="nb">}</span>
</div><div id="l1207" class="code_block">
</div><div id="l1208" class="code_block">XSB delays literals for non-<span class="k">\LRD</span><span class="nb">{}</span> programs and later simplifies them
</div><div id="l1209" class="code_block">away.  In Local Scheduling, all simplification will be done before the
</div><div id="l1210" class="code_block">first answer is returned to the user.  In Batched Scheduling it is
</div><div id="l1211" class="code_block">usually better to make a top-level call for a predicate, <span class="nb">{</span><span class="k">\tt</span> p<span class="nb">}</span> as
</div><div id="l1212" class="code_block">follows:
</div><div id="l1213" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1214" class="code_block">?- p,fail ; p.
</div><div id="l1215" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1216" class="code_block">when the second <span class="nb">{</span><span class="k">\tt</span> p<span class="nb">}</span> in this query is called, all simplification on
</div><div id="l1217" class="code_block"><span class="nb">{</span><span class="k">\tt</span> p<span class="nb">}</span> will have been performed.  However, this query will succeed if
</div><div id="l1218" class="code_block"><span class="nb">{</span><span class="k">\tt</span> p<span class="nb">}</span> is true <span class="nb">{</span><span class="k">\em</span> or<span class="nb">}</span> undefined.
</div><div id="l1219" class="code_block">
</div><div id="l1220" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>ex:true-val<span class="nb">}</span>
</div><div id="l1221" class="code_block">Write a predicate <span class="nb">{</span><span class="k">\tt</span> wfs<span class="k">\_call</span>(+Tpred,?Val)<span class="nb">}</span> such that if <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1222" class="code_block">Tpred<span class="nb">}</span> is a ground call to a tabled predicate, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1223" class="code_block">wfs<span class="k">\_call</span>(+Tpred,?Val)<span class="nb">}</span> calls <span class="nb">{</span><span class="k">\tt</span> Tpred<span class="nb">}</span> and unifies <span class="nb">{</span><span class="k">\tt</span> Val<span class="nb">}</span> with
</div><div id="l1224" class="code_block">the truth value of <span class="nb">{</span><span class="k">\tt</span> Tpred<span class="nb">}</span> under the well-founded semantics.
</div><div id="l1225" class="code_block"><span class="nb">{</span><span class="k">\em</span> Hint: use <span class="nb">{</span><span class="k">\tt</span> get<span class="k">\_residual</span>/2<span class="nb">}}</span>.
</div><div id="l1226" class="code_block">
</div><div id="l1227" class="code_block">How would you modify <span class="nb">{</span><span class="k">\tt</span> wfs<span class="k">\_call</span>(?Tpred,?Val)<span class="nb">}</span> so that it properly
</div><div id="l1228" class="code_block">handled cases in which <span class="nb">{</span><span class="k">\tt</span> Tpred<span class="nb">}</span> is non-ground.
</div><div id="l1229" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1230" class="code_block">
</div><div id="l1231" class="code_block"><span class="k">\paragraph*</span><span class="nb">{</span>Trouble in Paradise: Answer Completion<span class="nb">}</span>
</div><div id="l1232" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer completion<span class="nb">}</span>
</div><div id="l1233" class="code_block">
</div><div id="l1234" class="code_block">The engine for XSB performs both program clause and answer resolution,
</div><div id="l1235" class="code_block">along with delay and simplification.  What it does not do is to
</div><div id="l1236" class="code_block">perform an operation called <span class="nb">{</span><span class="k">\em</span> answer completion<span class="nb">}</span> which is needed in
</div><div id="l1237" class="code_block">certain (pathological?) programs.
</div><div id="l1238" class="code_block">
</div><div id="l1239" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1240" class="code_block">Consider the following program:
</div><div id="l1241" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1242" class="code_block">:- table ac<span class="nb">_</span>p/1,ac<span class="nb">_</span>r/0,ac<span class="nb">_</span>s/0.
</div><div id="l1243" class="code_block">ac<span class="nb">_</span>p(X):- ac<span class="nb">_</span>p(X).
</div><div id="l1244" class="code_block">ac<span class="nb">_</span>p(X):- tnot(ac<span class="nb">_</span>s).
</div><div id="l1245" class="code_block">
</div><div id="l1246" class="code_block">ac<span class="nb">_</span>s:- tnot(ac<span class="nb">_</span>r).
</div><div id="l1247" class="code_block">ac<span class="nb">_</span>s:- ac<span class="nb">_</span>p(X).
</div><div id="l1248" class="code_block">
</div><div id="l1249" class="code_block">ac<span class="nb">_</span>r:- tnot(ac<span class="nb">_</span>s),ac<span class="nb">_</span>r.
</div><div id="l1250" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1251" class="code_block">Using either the predicate from Exercise <span class="k">\ref</span><span class="nb">{</span>ex:true-val<span class="nb">}</span> or some
</div><div id="l1252" class="code_block">other method, determine the truth value of <span class="nb">{</span><span class="k">\tt</span> ac<span class="k">\_p</span>(X)<span class="nb">}</span>.  What
</div><div id="l1253" class="code_block">should the value be?  (hint: what is the value of <span class="nb">{</span><span class="k">\tt</span> ac<span class="k">\_s</span>/1<span class="nb">}</span>?).
</div><div id="l1254" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1255" class="code_block">
</div><div id="l1256" class="code_block">For certain programs, XSB will delay a literal (such as <span class="nb">{</span><span class="k">\tt</span> ac<span class="k">\_p</span>(X)<span class="nb">}</span>
</div><div id="l1257" class="code_block">that it will not be able to later simplify away.  In such a case, an
</div><div id="l1258" class="code_block">operation, called <span class="nb">{</span><span class="k">\em</span> answer completion<span class="nb">}</span> is needed to remove the
</div><div id="l1259" class="code_block">clause
</div><div id="l1260" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1261" class="code_block">      ac<span class="nb">_</span>p(X):- ac<span class="nb">_</span>p(X)|
</div><div id="l1262" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1263" class="code_block">Without answer completion, XSB may consider some answers to be
</div><div id="l1264" class="code_block">undefined rather than false.  It is thus is sound, but not complete
</div><div id="l1265" class="code_block">for terminating programs to the well-founded semantics.  Answer
</div><div id="l1266" class="code_block">completion is not available for <span class="k">\version</span><span class="nb">{}</span> of XSB, as it is expensive
</div><div id="l1267" class="code_block">and the need for answer completion arises rarely in practice.  However
</div><div id="l1268" class="code_block">answer completion will be included at some level in future versions of
</div><div id="l1269" class="code_block">XSB<span class="k">\@</span>.
</div><div id="l1270" class="code_block">
</div><div id="l1271" class="code_block"><span class="k">\subsection</span><span class="nb">{</span>On Beyond Zebra: Implementing Other Semantics for
</div><div id="l1272" class="code_block">Non-stratified Programs<span class="nb">}</span>
</div><div id="l1273" class="code_block"><span class="k">\index</span><span class="nb">{</span>stable models<span class="nb">}</span>
</div><div id="l1274" class="code_block">
</div><div id="l1275" class="code_block">The Well-founded semantics is not the only semantics for
</div><div id="l1276" class="code_block">non-stratified programs.  XSB can be used to (help) implement other
</div><div id="l1277" class="code_block">semantics that lie in one of two classes.  1) Semantics that extend
</div><div id="l1278" class="code_block">the well-founded semantics to include new program constructs; or 2)
</div><div id="l1279" class="code_block">semantics that contain the well-founded partial model as a submodel.
</div><div id="l1280" class="code_block">
</div><div id="l1281" class="code_block">An example of a semantics of class 1) is (WFSX) <span class="k">\cite</span><span class="nb">{</span>ADP95<span class="nb">}</span>, which
</div><div id="l1282" class="code_block">adds explicit (or provable) negation to the default negation used by
</div><div id="l1283" class="code_block">the Well-founded semantics.  The addition of explicit negation in
</div><div id="l1284" class="code_block">WFSX, can be useful for modeling problems in domains such as diagnosis
</div><div id="l1285" class="code_block">and hierarchical reasoning, or domains that require updates
</div><div id="l1286" class="code_block"><span class="k">\cite</span><span class="nb">{</span>LePe98<span class="nb">}</span>, as logic programs.  WFSX is embeddable into the
</div><div id="l1287" class="code_block">well-founded semantics; and this embedding gives rise to an XSB
</div><div id="l1288" class="code_block">meta-interpreter, or, more efficiently, to the preprocessor described
</div><div id="l1289" class="code_block">in Section <span class="nb">{</span><span class="k">\it</span> Extended Logic Programs<span class="nb">}</span> in Volume 2.  See
</div><div id="l1290" class="code_block"><span class="k">\cite</span><span class="nb">{</span>Swif99a<span class="nb">}</span> for an overview of the process of implementing
</div><div id="l1291" class="code_block">extensions of the well-founded semantics.
</div><div id="l1292" class="code_block">
</div><div id="l1293" class="code_block">An example of a semantics of class 2) is the stable model semantics.
</div><div id="l1294" class="code_block">Every stable model of a program contains the well-founded partial
</div><div id="l1295" class="code_block">model as a submodel.  As a result, the XSB can be used to evaluate
</div><div id="l1296" class="code_block">stable model semantics through the <span class="nb">{</span><span class="k">\em</span> residual program<span class="nb">}</span>, to which we
</div><div id="l1297" class="code_block">now turn.
</div><div id="l1298" class="code_block">
</div><div id="l1299" class="code_block"><span class="k">\paragraph*</span><span class="nb">{</span>The Residual Program<span class="nb">}</span>
</div><div id="l1300" class="code_block">
</div><div id="l1301" class="code_block">Given a program <span class="s">$</span><span class="nb">P</span><span class="s">$</span> and query <span class="s">$</span><span class="nb">Q</span><span class="s">$</span>, the residual program for <span class="s">$</span><span class="nb">Q</span><span class="s">$</span> and
</div><div id="l1302" class="code_block"><span class="s">$</span><span class="nb">P</span><span class="s">$</span> consists of all (conditional and unconditional) answers created in
</div><div id="l1303" class="code_block">the complete evaluation of <span class="s">$</span><span class="nb">Q</span><span class="s">$</span><span class="k">\@</span>.  
</div><div id="l1304" class="code_block">
</div><div id="l1305" class="code_block"><span class="k">\begin</span><span class="nb">{</span>exercise<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>ex:pos-delay<span class="nb">}</span>
</div><div id="l1306" class="code_block">Consider the following program.
</div><div id="l1307" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1308" class="code_block">     :- table ppgte<span class="nb">_</span>p/0,ppgte<span class="nb">_</span>q/0,ppgte<span class="nb">_</span>r/0,ppgte<span class="nb">_</span>s/0,
</div><div id="l1309" class="code_block">              ppgte<span class="nb">_</span>t/0,ppgte<span class="nb">_</span>u/0,ppgte<span class="nb">_</span>v/0.
</div><div id="l1310" class="code_block">     ppgte<span class="nb">_</span>p:- ppgte<span class="nb">_</span>q.          ppgte<span class="nb">_</span>p:- ppgte<span class="nb">_</span>r.
</div><div id="l1311" class="code_block">
</div><div id="l1312" class="code_block">     ppgte<span class="nb">_</span>q:- ppgte<span class="nb">_</span>s.          ppgte<span class="nb">_</span>r:- ppgte<span class="nb">_</span>u.
</div><div id="l1313" class="code_block">     ppgte<span class="nb">_</span>q:- ppgte<span class="nb">_</span>t.          ppgte<span class="nb">_</span>r:- ppgte<span class="nb">_</span>v.
</div><div id="l1314" class="code_block">
</div><div id="l1315" class="code_block">     ppgte<span class="nb">_</span>s:- ppgte<span class="nb">_</span>w.          ppgte<span class="nb">_</span>u:- undefined.
</div><div id="l1316" class="code_block">     ppgte<span class="nb">_</span>t:- ppgte<span class="nb">_</span>x.          ppgte<span class="nb">_</span>v:- undefined.
</div><div id="l1317" class="code_block">
</div><div id="l1318" class="code_block">     ppgte<span class="nb">_</span>w:- ppgte(1).         ppgte<span class="nb">_</span>x:- ppgte(0).
</div><div id="l1319" class="code_block">     ppgte<span class="nb">_</span>w:- undefined.        ppgte<span class="nb">_</span>x:- undefined.
</div><div id="l1320" class="code_block">
</div><div id="l1321" class="code_block">     ppgte(0).
</div><div id="l1322" class="code_block">
</div><div id="l1323" class="code_block">     :- table undefined/0.
</div><div id="l1324" class="code_block">     undefined:- tnot(undefined).
</div><div id="l1325" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1326" class="code_block">Write a routine that uses <span class="nb">{</span><span class="k">\tt</span> get<span class="k">\_residual</span>/2<span class="nb">}</span> to print out the
</div><div id="l1327" class="code_block">residual program for the query <span class="nb">{</span><span class="k">\tt</span> ?- ppgte<span class="k">\_p</span>,fail<span class="nb">}</span>.  Try altering the
</div><div id="l1328" class="code_block">tabling declarations, in particular by making <span class="nb">{</span><span class="k">\tt</span> ppgte<span class="k">\_q</span>/0<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1329" class="code_block">ppgte<span class="k">\_r</span>/0<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> ppgte<span class="k">\_s</span>/0<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> ppgte<span class="k">\_t</span>/0<span class="nb">}</span> non-tabled.  What
</div><div id="l1330" class="code_block">effect does altering the tabling declarations have on the residual
</div><div id="l1331" class="code_block">program?
</div><div id="l1332" class="code_block"><span class="k">\end</span><span class="nb">{</span>exercise<span class="nb">}</span>
</div><div id="l1333" class="code_block">
</div><div id="l1334" class="code_block">When XSB returns a conditional answer to a literal <span class="s">$</span><span class="nb">L</span><span class="s">$</span>, it does not
</div><div id="l1335" class="code_block">propagate the delay list of the conditional answer, but rather delays
</div><div id="l1336" class="code_block"><span class="s">$</span><span class="nb">L</span><span class="s">$</span> itself, even if <span class="s">$</span><span class="nb">L</span><span class="s">$</span> does not occur in a negative loop.  This has
</div><div id="l1337" class="code_block">the advantage of ensuring that delayed literals are not propagated
</div><div id="l1338" class="code_block">exponentially through conditional answers.
</div><div id="l1339" class="code_block">
</div><div id="l1340" class="code_block"><span class="k">\paragraph*</span><span class="nb">{</span>Stable Models<span class="nb">}</span>
</div><div id="l1341" class="code_block"><span class="k">\index</span><span class="nb">{</span>negation!stable models<span class="nb">}</span>
</div><div id="l1342" class="code_block">
</div><div id="l1343" class="code_block">Stable models are one of the most popular semantics for non-stratified
</div><div id="l1344" class="code_block">programs.  The intuition behind the stable model semantics for a
</div><div id="l1345" class="code_block">ground program <span class="s">$</span><span class="nb">P</span><span class="s">$</span> can be seen as follows.  Each negative literal <span class="s">$</span><span class="nb">not</span>
</div><div id="l1346" class="code_block"><span class="nb">L</span><span class="s">$</span> in <span class="s">$</span><span class="nb">P</span><span class="s">$</span> is treated as a special kind of atom called an <span class="nb">{</span><span class="k">\em</span>
</div><div id="l1347" class="code_block">assumption<span class="nb">}</span>.  To compute the stable model, a guess is made about
</div><div id="l1348" class="code_block">whether each assumption is true or false, creating an assumption set,
</div><div id="l1349" class="code_block"><span class="s">$</span><span class="nb">A</span><span class="s">$</span><span class="k">\@</span>.  Once an assumption set is given, negative literals do not need
</div><div id="l1350" class="code_block">to be evaluated as in the well-founded semantics; rather an evaluation
</div><div id="l1351" class="code_block">treats a negative literal as an atom that succeeds or fails depending
</div><div id="l1352" class="code_block">on whether it is true or false in <span class="s">$</span><span class="nb">A</span><span class="s">$</span><span class="k">\@</span>.
</div><div id="l1353" class="code_block">
</div><div id="l1354" class="code_block"><span class="k">\begin</span><span class="nb">{</span>example<span class="nb">}</span>
</div><div id="l1355" class="code_block">Consider the simple, non-stratified program
</div><div id="l1356" class="code_block"><span class="k">\begin</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1357" class="code_block"><span class="k">\begin</span><span class="nb">{</span>Prog<span class="nb">}</span>
</div><div id="l1358" class="code_block">writes<span class="k">\_manual</span>(terry)-<span class="s">$</span><span class="nv">\neg</span><span class="s">$</span>writes<span class="k">\_manual</span>(kostis),has<span class="k">\_time</span>(terry). <span class="k">\\</span>
</div><div id="l1359" class="code_block">writes<span class="k">\_manual</span>(kostis)-<span class="s">$</span><span class="nv">\neg</span><span class="s">$</span>writes<span class="k">\_manual</span>(terry),has<span class="k">\_time</span>(kostis). <span class="k">\\</span>
</div><div id="l1360" class="code_block">has<span class="k">\_time</span>(terry). <span class="k">\\</span>
</div><div id="l1361" class="code_block">has<span class="k">\_time</span>(kostis). <span class="k">\\</span>
</div><div id="l1362" class="code_block"><span class="k">\end</span><span class="nb">{</span>Prog<span class="nb">}</span>
</div><div id="l1363" class="code_block"><span class="k">\end</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1364" class="code_block">there are two stable models of this program: in one <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1365" class="code_block">writes<span class="k">\_manual</span>(terry)<span class="nb">}</span> is true, and in another <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1366" class="code_block">writes<span class="k">\_manual</span>(kostis)<span class="nb">}</span> is true.  In the Well-Founded model, neither
</div><div id="l1367" class="code_block">of these literals is true.  The residual program for the above program
</div><div id="l1368" class="code_block">is
</div><div id="l1369" class="code_block"><span class="k">\begin</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1370" class="code_block"><span class="k">\begin</span><span class="nb">{</span>Prog<span class="nb">}</span>
</div><div id="l1371" class="code_block">writes<span class="k">\_manual</span>(terry)-<span class="s">$</span><span class="nv">\neg</span><span class="s">$</span>writes<span class="k">\_manual</span>(kostis). <span class="k">\\</span>
</div><div id="l1372" class="code_block">writes<span class="k">\_manual</span>(kostis)-<span class="s">$</span><span class="nv">\neg</span><span class="s">$</span>writes<span class="k">\_manual</span>(terry). <span class="k">\\</span>
</div><div id="l1373" class="code_block">has<span class="k">\_time</span>(terry). <span class="k">\\</span>
</div><div id="l1374" class="code_block">has<span class="k">\_time</span>(kostis). <span class="k">\\</span>
</div><div id="l1375" class="code_block"><span class="k">\end</span><span class="nb">{</span>Prog<span class="nb">}</span>
</div><div id="l1376" class="code_block"><span class="k">\end</span><span class="nb">{</span>center<span class="nb">}</span>
</div><div id="l1377" class="code_block"><span class="k">\end</span><span class="nb">{</span>example<span class="nb">}</span>
</div><div id="l1378" class="code_block">
</div><div id="l1379" class="code_block">Computing stable models is an intractable problem, meaning that any
</div><div id="l1380" class="code_block">algorithm to evaluate stable models may have to fall back on
</div><div id="l1381" class="code_block">generating possible assumption sets, in pathological cases.  For a
</div><div id="l1382" class="code_block">ground program, if it is ensured that residual clauses are produced
</div><div id="l1383" class="code_block">for <span class="nb">{</span><span class="k">\em</span> all<span class="nb">}</span> atoms, using the residual program may bring a
</div><div id="l1384" class="code_block">performance gain since the search space of algorithms to compute
</div><div id="l1385" class="code_block">stable models will be correspondingly reduced.  In fact, by using XSB
</div><div id="l1386" class="code_block">in conjunction with a Stable Model generator, Smodels <span class="k">\cite</span><span class="nb">{</span>NiSi97<span class="nb">}</span>,
</div><div id="l1387" class="code_block">an efficient system has been devised for model checking of concurrent
</div><div id="l1388" class="code_block">systems that is 10-20 times faster than competing systems
</div><div id="l1389" class="code_block"><span class="k">\cite</span><span class="nb">{</span>LiRS98<span class="nb">}</span>.  In addition, using the XASP package (see the separate
</div><div id="l1390" class="code_block">manual, <span class="k">\cite</span><span class="nb">{</span>CaSW02a<span class="nb">}</span> in XSB&#39;s packages directory) a consistency
</div><div id="l1391" class="code_block">checker for description logics has also been created <span class="k">\cite</span><span class="nb">{</span>Swif04<span class="nb">}</span>.
</div><div id="l1392" class="code_block">
</div><div id="l1393" class="code_block"><span class="c">%----------------------------------------------------------------------</span>
</div><div id="l1394" class="code_block">
</div><div id="l1395" class="code_block"><span class="k">\section</span><span class="nb">{</span>Answer Subsumption<span class="nb">}</span>  <span class="k">\label</span><span class="nb">{</span>sec:table-aggregation<span class="nb">}</span>
</div><div id="l1396" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1397" class="code_block">
</div><div id="l1398" class="code_block"><span class="c">%</span>
</div><div id="l1399" class="code_block">By default XSB adds an answer <span class="s">$</span><span class="nb">A</span><span class="s">$</span> to a table <span class="s">$</span><span class="nb">T</span><span class="s">$</span> only if <span class="s">$</span><span class="nb">A</span><span class="s">$</span> is not a
</div><div id="l1400" class="code_block">variant of some other answer already in <span class="s">$</span><span class="nb">T</span><span class="s">$</span>, a technique termed <span class="nb">{</span><span class="k">\em</span>
</div><div id="l1401" class="code_block">  answer variance<span class="nb">}</span>.  While answer variance is sufficient to allow
</div><div id="l1402" class="code_block">tabling to compute the well-founded semantics and to terminate for
</div><div id="l1403" class="code_block">programs with bounded term-depth, other choices of when and how to add
</div><div id="l1404" class="code_block">an answer can be made.  Using <span class="nb">{</span><span class="k">\em</span> partial order answer subsumption<span class="nb">}</span>,
</div><div id="l1405" class="code_block"><span class="s">$</span><span class="nb">A</span><span class="s">$</span> would be added to <span class="s">$</span><span class="nb">T</span><span class="s">$</span> only if <span class="s">$</span><span class="nb">A</span><span class="s">$</span> is maximal with respect to other
</div><div id="l1406" class="code_block">answers in <span class="s">$</span><span class="nb">T</span><span class="s">$</span> according to a given partial order <span class="s">$</span><span class="nb">&gt;_O</span><span class="s">$</span>. Furthermore
</div><div id="l1407" class="code_block">if <span class="s">$</span><span class="nb">A</span><span class="s">$</span> is added, any answers in <span class="s">$</span><span class="nb">T</span><span class="s">$</span> that <span class="s">$</span><span class="nb">A</span><span class="s">$</span> subsumes (i.e., is
</div><div id="l1408" class="code_block">greater than in <span class="s">$</span><span class="nb">&gt;_O</span><span class="s">$</span>) are deleted.  When using <span class="nb">{</span><span class="k">\em</span> lattice answer
</div><div id="l1409" class="code_block">  subsumption<span class="nb">}</span>, <span class="s">$</span><span class="nb">A</span><span class="s">$</span> itself may not be added to <span class="s">$</span><span class="nb">T</span><span class="s">$</span>, rather the join is
</div><div id="l1410" class="code_block">taken of <span class="s">$</span><span class="nb">A</span><span class="s">$</span> and another answer <span class="s">$</span><span class="nb">A&#39;</span><span class="s">$</span> in <span class="s">$</span><span class="nb">T</span><span class="s">$</span>, with <span class="s">$</span><span class="nb">A&#39;</span><span class="s">$</span> being deleted.
</div><div id="l1411" class="code_block">Despite its conceptual simplicity, answer subsumption can be a
</div><div id="l1412" class="code_block">powerful tool.  Partial order answer subsumption allows a table to
</div><div id="l1413" class="code_block">retain only answers that are maximal according to a metric or to a
</div><div id="l1414" class="code_block">preference relation; lattice answer subsumption can form the basis of
</div><div id="l1415" class="code_block">multi-valued logics, quantitative logics, and of abstract
</div><div id="l1416" class="code_block">interpretations for programs and process logics.
</div><div id="l1417" class="code_block"><span class="c">%</span>
</div><div id="l1418" class="code_block">
</div><div id="l1419" class="code_block"><span class="c">%------------------------------------------------------------------------</span>
</div><div id="l1420" class="code_block"><span class="k">\subsection</span><span class="nb">{</span>Types of Answer Subsumption<span class="nb">}</span>
</div><div id="l1421" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1422" class="code_block">
</div><div id="l1423" class="code_block"><span class="k">\subsubsection</span><span class="nb">{</span>Partial Order Answer Subsumption.<span class="nb">}</span>
</div><div id="l1424" class="code_block"><span class="c">% </span>
</div><div id="l1425" class="code_block">We illustrate the use of partial oder answer subsumption through a
</div><div id="l1426" class="code_block">shortest-path predicate (Figure~<span class="k">\ref</span><span class="nb">{</span>fig:sp-preds<span class="nb">}</span>) that counts the
</div><div id="l1427" class="code_block">number of edges between two vertices.
</div><div id="l1428" class="code_block"><span class="c">%</span>
</div><div id="l1429" class="code_block"><span class="k">\begin</span><span class="nb">{</span>figure<span class="nb">}</span>[htb]
</div><div id="l1430" class="code_block"><span class="nb">{</span><span class="k">\small</span>
</div><div id="l1431" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1432" class="code_block">sp(X,Y,1):- edge(X,Y).
</div><div id="l1433" class="code_block">sp(X,Z,N):- sp(X,Y,N1),edge(Y,Z),N is N1 + 1.
</div><div id="l1434" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1435" class="code_block"><span class="nb">}</span> 
</div><div id="l1436" class="code_block"><span class="k">\caption</span><span class="nb">{</span>A Shortest Path Predicate<span class="nb">}</span><span class="k">\label</span><span class="nb">{</span>fig:sp-preds<span class="nb">}</span>
</div><div id="l1437" class="code_block"><span class="k">\end</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1438" class="code_block">
</div><div id="l1439" class="code_block">As mentioned above, partial-order answer subsumption retains in a
</div><div id="l1440" class="code_block">table <span class="s">$</span><span class="nb">T</span><span class="s">$</span> only those answers that are maximal according to a given
</div><div id="l1441" class="code_block">partial order <span class="s">$</span><span class="nb">&gt;_O</span><span class="s">$</span>.  In the case of the shortest-path predicate of
</div><div id="l1442" class="code_block">Figure~<span class="k">\ref</span><span class="nb">{</span>fig:sp-preds<span class="nb">}</span>, <span class="s">$</span><span class="nb">sp</span><span class="o">(</span><span class="nb">A_</span><span class="m">1</span><span class="nb">,A_</span><span class="m">2</span><span class="nb">,A_</span><span class="m">3</span><span class="o">)</span><span class="nb"> &gt;_O sp</span><span class="o">(</span><span class="nb">B_</span><span class="m">1</span><span class="nb">,B_</span><span class="m">2</span><span class="nb">,B_</span><span class="m">3</span><span class="o">)</span><span class="s">$</span> if,
</div><div id="l1443" class="code_block"><span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="nb"> </span><span class="o">=</span><span class="nb"> B_</span><span class="m">1</span><span class="s">$</span>, <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="nb"> </span><span class="o">=</span><span class="nb"> B_</span><span class="m">2</span><span class="s">$</span>, and <span class="s">$</span><span class="nb">A_</span><span class="m">3</span><span class="nb"> &lt; B_</span><span class="m">3</span><span class="s">$</span>.  Note that that minimal
</div><div id="l1444" class="code_block">distances are maximal in <span class="s">$</span><span class="nb">&lt;_O</span><span class="s">$</span>, and that <span class="s">$</span><span class="nb">&lt;_O</span><span class="s">$</span> is undefined if <span class="s">$</span><span class="nb">A_</span><span class="m">3</span><span class="s">$</span>
</div><div id="l1445" class="code_block">or <span class="s">$</span><span class="nb">B_</span><span class="m">3</span><span class="s">$</span> is non-numeric.  In XSB, partial order answer subsumption
</div><div id="l1446" class="code_block">is specified for <span class="nb">{</span><span class="k">\tt</span> sp/3<span class="nb">}</span> using the declaration
</div><div id="l1447" class="code_block"><span class="c">%</span>
</div><div id="l1448" class="code_block"><span class="nb">{</span><span class="k">\small</span>
</div><div id="l1449" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1450" class="code_block">  :- table sp(<span class="nb">_</span>,<span class="nb">_</span>,po(&lt;/2)).
</div><div id="l1451" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1452" class="code_block"><span class="nb">}</span>
</div><div id="l1453" class="code_block"><span class="c">%</span>
</div><div id="l1454" class="code_block"><span class="k">\noindent</span>
</div><div id="l1455" class="code_block">In a given state of computation, only those answers that are maximal
</div><div id="l1456" class="code_block">according to <span class="s">$</span><span class="nb">&gt;_O</span><span class="s">$</span> are available for resolution.  Thus, for a finite
</div><div id="l1457" class="code_block">graph with cycles, <span class="nb">{</span><span class="k">\tt</span> sp/3<span class="nb">}</span> will terminate using answer subsumption,
</div><div id="l1458" class="code_block">but not with answer variance.  Other partial orders beyond distance
</div><div id="l1459" class="code_block">metrics may be useful.  For instance, <span class="s">$</span><span class="nb">&gt;_O</span><span class="s">$</span> may specify a preference
</div><div id="l1460" class="code_block">ordering between derived atoms so that answer subsumption provides an
</div><div id="l1461" class="code_block">alternative to default-based methods for computing preferences.
</div><div id="l1462" class="code_block">
</div><div id="l1463" class="code_block"><span class="k">\subsubsection</span><span class="nb">{</span>Lattice Answer Subsumption.<span class="nb">}</span>
</div><div id="l1464" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1465" class="code_block">An upper semi-lattice is a partial order for which any two elements
</div><div id="l1466" class="code_block">have a unique least upper bound.  Because the ordering for the third
</div><div id="l1467" class="code_block">argument of <span class="nb">{</span><span class="k">\tt</span> sp/3<span class="nb">}</span> is total, it also forms an upper semi-lattice,
</div><div id="l1468" class="code_block">and so can be computed using lattice answer subsumption.
</div><div id="l1469" class="code_block">~<span class="k">\footnote</span><span class="nb">{</span>The terminology lattice answer subsumption is employed even
</div><div id="l1470" class="code_block">  though only the join of the lattice is used.<span class="nb">}</span>.  In XSB lattice
</div><div id="l1471" class="code_block">answer subsumption for <span class="nb">{</span><span class="k">\tt</span> sp/3<span class="nb">}</span> is declared as
</div><div id="l1472" class="code_block"><span class="c">%</span>
</div><div id="l1473" class="code_block"><span class="nb">{</span><span class="k">\small</span>
</div><div id="l1474" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1475" class="code_block">  :- table sp(<span class="nb">_</span>,<span class="nb">_</span>,lattice(min/3)).
</div><div id="l1476" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1477" class="code_block"><span class="nb">}</span>
</div><div id="l1478" class="code_block"><span class="c">%</span>
</div><div id="l1479" class="code_block"><span class="k">\noindent</span>
</div><div id="l1480" class="code_block">with <span class="nb">{</span><span class="k">\tt</span> min/3<span class="nb">}</span> defined as <span class="nb">{</span><span class="k">\tt</span> min(X,Y,Z):- Z is min(X,Y).<span class="nb">}</span> 
</div><div id="l1481" class="code_block">Operationally, this means that whenever an answer
</div><div id="l1482" class="code_block"><span class="s">$</span><span class="nb">sp</span><span class="o">(</span><span class="nb">A_</span><span class="m">1</span><span class="nb">,A_</span><span class="m">2</span><span class="nb">,A_</span><span class="m">3</span><span class="o">)</span><span class="s">$</span> is derived, if there is another answer
</div><div id="l1483" class="code_block"><span class="s">$</span><span class="nb">sp</span><span class="o">(</span><span class="nb">B_</span><span class="m">1</span><span class="nb">,B_</span><span class="m">2</span><span class="nb">,B_</span><span class="m">3</span><span class="o">)</span><span class="s">$</span> where <span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="nb"> </span><span class="o">=</span><span class="nb"> B_</span><span class="m">1</span><span class="s">$</span> and <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="nb"> </span><span class="o">=</span><span class="nb"> B_</span><span class="m">2</span><span class="s">$</span> the join <span class="s">$</span><span class="nb">J_</span><span class="m">3</span><span class="s">$</span> of
</div><div id="l1484" class="code_block"><span class="s">$</span><span class="nb">A_</span><span class="m">3</span><span class="s">$</span> and <span class="s">$</span><span class="nb">B_</span><span class="m">3</span><span class="s">$</span> is taken, and only <span class="s">$</span><span class="nb">sp</span><span class="o">(</span><span class="nb">A_</span><span class="m">1</span><span class="nb">,A_</span><span class="m">2</span><span class="nb">,J_</span><span class="m">3</span><span class="o">)</span><span class="s">$</span> is available for
</div><div id="l1485" class="code_block">resolution.  As with a partial order, the join operation
</div><div id="l1486" class="code_block">ensures termination for shortest path over a finite graph with cycles.
</div><div id="l1487" class="code_block"><span class="k">\index</span><span class="nb">{</span>termination!answer subsumption<span class="nb">}</span>
</div><div id="l1488" class="code_block">
</div><div id="l1489" class="code_block">As the following proposition shows, lattice answer subsumption can be
</div><div id="l1490" class="code_block">modeled either starting with a lattice, or starting with a function
</div><div id="l1491" class="code_block">with appropriate properties.
</div><div id="l1492" class="code_block"><span class="k">\begin</span><span class="nb">{</span>proposition<span class="nb">}</span>
</div><div id="l1493" class="code_block">Let <span class="nb">{</span><span class="k">\em</span> op<span class="nb">}</span> be an associative, commutative, and idempotent binary
</div><div id="l1494" class="code_block">function.  Then there is a partial order <span class="s">$</span><span class="nb">P</span><span class="s">$</span>, such that <span class="s">$</span><span class="nb">P</span><span class="s">$</span> is an
</div><div id="l1495" class="code_block">upper semi-lattice with join <span class="nb">{</span><span class="k">\em</span> op<span class="nb">}</span>.
</div><div id="l1496" class="code_block"><span class="k">\end</span><span class="nb">{</span>proposition<span class="nb">}</span>
</div><div id="l1497" class="code_block"><span class="c">% </span>
</div><div id="l1498" class="code_block">Conversely, if a function does not have the above properties, it is
</div><div id="l1499" class="code_block">not suitable for lattice answer subsumption.  Accordingly the
</div><div id="l1500" class="code_block">aggregate functions count and sum cannot be computed using lattice
</div><div id="l1501" class="code_block">answer subsumption~<span class="k">\footnote</span><span class="nb">{</span>Since count and sum are not idempotent
</div><div id="l1502" class="code_block">  their semantics is based on multi-sets, rather than sets.
</div><div id="l1503" class="code_block">  Incorporating these as tabling features requires modifying their
</div><div id="l1504" class="code_block">  semantics to be set-based, in a manner similar to aggregation ASP
</div><div id="l1505" class="code_block">  systems.<span class="nb">}</span>.
</div><div id="l1506" class="code_block"><span class="c">%</span>
</div><div id="l1507" class="code_block">Lattice answer subsumption has a variety of applications.
</div><div id="l1508" class="code_block"><span class="k">\cite</span><span class="nb">{</span>SwiW10a<span class="nb">}</span> shows how it is used for social-network analysis and
</div><div id="l1509" class="code_block">Section~<span class="k">\ref</span><span class="nb">{</span>sec:mv<span class="nb">}</span> shows its use for an application of multi-valued
</div><div id="l1510" class="code_block">logics, <span class="k">\cite</span><span class="nb">{</span>Swif99a<span class="nb">}</span> describes how a similar formalism can implement
</div><div id="l1511" class="code_block">a quantitative logic, and <span class="k">\cite</span><span class="nb">{</span>RigS10<span class="nb">}</span> describes how XSB&#39;s <span class="nb">{</span><span class="k">\tt</span> PITA<span class="nb">}</span>
</div><div id="l1512" class="code_block">package is based on answer subsumption (see Volume 2 of this manual).
</div><div id="l1513" class="code_block">
</div><div id="l1514" class="code_block"><span class="k">\subsubsection</span><span class="nb">{</span>Partial Order Answer Subsumption with Abstraction.<span class="nb">}</span>
</div><div id="l1515" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1516" class="code_block">Computation over an abstract domain may require certain maximal
</div><div id="l1517" class="code_block">answers to be abstracted.  In many cases, abstraction can be modeled
</div><div id="l1518" class="code_block">by a join operation, but in others the abstraction represents an
</div><div id="l1519" class="code_block">implicit induction step in the following sense. Given a set <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span> of
</div><div id="l1520" class="code_block">answers, it may be detected that the program computed does not have a
</div><div id="l1521" class="code_block">finite model.  An abstraction operation then is applied so that <span class="s">$</span><span class="nv">\cA</span><span class="s">$</span>
</div><div id="l1522" class="code_block">and its extensions can be symbolically represented by a single answer
</div><div id="l1523" class="code_block"><span class="s">$</span><span class="nb">A</span><span class="s">$</span>.  Using answer subsumption, this abstraction can be taken only if
</div><div id="l1524" class="code_block">needed during program execution.  Abstractly, partial order answer
</div><div id="l1525" class="code_block">subsumption with abstraction uses the declaration <span class="nb">{</span><span class="k">\small</span>
</div><div id="l1526" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1527" class="code_block">:- table p(<span class="nb">_</span>,<span class="nb">_</span>,po(rel/2,abs/3)).
</div><div id="l1528" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1529" class="code_block"><span class="nb">}</span> 
</div><div id="l1530" class="code_block"><span class="c">%</span>
</div><div id="l1531" class="code_block"><span class="k">\noindent</span>
</div><div id="l1532" class="code_block">where <span class="nb">{</span><span class="k">\tt</span> rel/2<span class="nb">}</span> is a partial order, and <span class="nb">{</span><span class="k">\tt</span> abs/3<span class="nb">}</span> is the
</div><div id="l1533" class="code_block">abstraction operation.  Section~<span class="k">\ref</span><span class="nb">{</span>sec:abs-int<span class="nb">}</span> provides a detailed
</div><div id="l1534" class="code_block">example of how such an approach is used to analyze a process logic.
</div><div id="l1535" class="code_block">
</div><div id="l1536" class="code_block"><span class="k">\subsection</span><span class="nb">{</span>Examples of Answer Subsumption<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>sec:answer-subsumption-examples<span class="nb">}</span>
</div><div id="l1537" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1538" class="code_block">
</div><div id="l1539" class="code_block"><span class="k">\subsubsection</span><span class="nb">{</span>Answer Subsumption and Abstract Interpretation<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>sec:abs-int<span class="nb">}</span>
</div><div id="l1540" class="code_block"><span class="c">%</span>
</div><div id="l1541" class="code_block">Net-style formalisms, such as Petri Nets, Workflow Nets, etc. have
</div><div id="l1542" class="code_block">been used extensively for process modeling.  Reachability is a central
</div><div id="l1543" class="code_block">problem in analyzing properties of such nets, to which properties such
</div><div id="l1544" class="code_block">as liveness, deadlock-freedom, and the existence of home states can be
</div><div id="l1545" class="code_block">reduced.  However, many interesting net formalisms cannot guarantee a
</div><div id="l1546" class="code_block">finite number of configurations in a given net, so abstraction methods
</div><div id="l1547" class="code_block">must be applied for their analysis.
</div><div id="l1548" class="code_block"><span class="k">\index</span><span class="nb">{</span>answer abstraction<span class="nb">}</span>
</div><div id="l1549" class="code_block">
</div><div id="l1550" class="code_block"><span class="c">%\dsw{Should say</span>
</div><div id="l1551" class="code_block"><span class="c">%that a transition removes one token from the places that are the</span>
</div><div id="l1552" class="code_block"><span class="c">%sources of its input edges and adds one token to each place at the</span>
</div><div id="l1553" class="code_block"><span class="c">%target of each of its output edges.  Also I don&#39;t see a</span>
</div><div id="l1554" class="code_block"><span class="c">%``configuration&#39;&#39; in figure 7; that should be some number of tokens</span>
</div><div id="l1555" class="code_block"><span class="c">%at each place, no?}</span>
</div><div id="l1556" class="code_block">For instance, the lack of finiteness is a problem in analyzing
</div><div id="l1557" class="code_block">Place/Transition (PT) Nets.  PT nets have no guard conditions or
</div><div id="l1558" class="code_block">after-effects, and do not distinguish between token types.  However,
</div><div id="l1559" class="code_block">PT nets do allow a place to hold more than one token, leading to a
</div><div id="l1560" class="code_block">potentially infinite number of configurations.  This can be seen in
</div><div id="l1561" class="code_block">the simple network of Figure~<span class="k">\ref</span><span class="nb">{</span>fig:ptnet<span class="nb">}</span> (from~<span class="k">\cite</span><span class="nb">{</span>DesR98<span class="nb">}</span>) in
</div><div id="l1562" class="code_block">which transitions are denoted by squares and places by circles.  Each
</div><div id="l1563" class="code_block">transition removes one token from the places that are the sources
</div><div id="l1564" class="code_block">of its input edges and adds one token to each place at the target of
</div><div id="l1565" class="code_block">each of its output edges.  Starting from the configuration in
</div><div id="l1566" class="code_block">Figure~<span class="k">\ref</span><span class="nb">{</span>fig:ptnet<span class="nb">}</span>, repeated application of transition <span class="nb">{</span><span class="k">\tt</span> t1<span class="nb">}</span>
</div><div id="l1567" class="code_block">leads to place <span class="nb">{</span><span class="k">\tt</span> s2<span class="nb">}</span> containing an unbounded number of tokens;
</div><div id="l1568" class="code_block">repeated application of the sequence <span class="nb">{</span><span class="k">\tt</span> t1,t2,t3,t4<span class="nb">}</span> leads to place
</div><div id="l1569" class="code_block"><span class="nb">{</span><span class="k">\tt</span> s4<span class="nb">}</span> containing an unbounded number of tokens.
</div><div id="l1570" class="code_block"><span class="c">%</span>
</div><div id="l1571" class="code_block"><span class="k">\begin</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1572" class="code_block"><span class="k">\centering</span>
</div><div id="l1573" class="code_block"><span class="k">\includegraphics</span><span class="na">[width=0.5\textwidth]</span><span class="nb">{</span>omegaNet<span class="nb">}</span>
</div><div id="l1574" class="code_block"><span class="c">%%\epsfig{file=omegaNet,width=.5\textwidth}</span>
</div><div id="l1575" class="code_block"><span class="k">\caption</span><span class="nb">{</span>A PT-net and configuration with an infinite number of reachable configurations<span class="nb">}</span> 
</div><div id="l1576" class="code_block"><span class="k">\label</span><span class="nb">{</span>fig:ptnet<span class="nb">}</span>
</div><div id="l1577" class="code_block"><span class="k">\end</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1578" class="code_block"><span class="c">%</span>
</div><div id="l1579" class="code_block">
</div><div id="l1580" class="code_block">Despite such examples, reachability in PT nets is decidable and can be
</div><div id="l1581" class="code_block">determined using an abstraction method called <span class="s">$</span><span class="nv">\omega</span><span class="s">$</span>-sequences, (see
</div><div id="l1582" class="code_block">e.g. <span class="k">\cite</span><span class="nb">{</span>DesR98<span class="nb">}</span>).  The main idea in determining <span class="s">$</span><span class="nv">\omega</span><span class="s">$</span> sequences
</div><div id="l1583" class="code_block">is to define a partial order <span class="s">$</span><span class="nv">\geq</span><span class="nb">_{</span><span class="nv">\omega</span><span class="nb">}</span><span class="s">$</span> on configurations as
</div><div id="l1584" class="code_block">follows.  If configurations <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> and <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span> are both reachable, <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span>
</div><div id="l1585" class="code_block">and <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span> have tokens in the same set <span class="s">$</span><span class="nb">PL</span><span class="s">$</span> of places, <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> has at
</div><div id="l1586" class="code_block">least as many tokens in each place as <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span>, and there exists a
</div><div id="l1587" class="code_block">non-empty <span class="s">$</span><span class="nb">PL_{sub} </span><span class="nv">\subseteq</span><span class="nb"> PL</span><span class="s">$</span>, such that for each <span class="s">$</span><span class="nb">pl </span><span class="nv">\in</span>
</div><div id="l1588" class="code_block"><span class="nb">Pl_{sub}</span><span class="s">$</span> <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> has strictly more tokens than <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span>, then <span class="s">$</span><span class="nb">C_</span><span class="m">1</span>
</div><div id="l1589" class="code_block"><span class="nb">&gt;_{</span><span class="nv">\omega</span><span class="nb">} C_</span><span class="m">2</span><span class="s">$</span>.  When evaluating reachability, if <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span> is reached
</div><div id="l1590" class="code_block">first, and then <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> was subsequently reached, <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> is abstracted by
</div><div id="l1591" class="code_block">marking each place in <span class="s">$</span><span class="nb">PL_{sub}</span><span class="s">$</span> with the special token <span class="s">$</span><span class="nv">\omega</span><span class="s">$</span> which
</div><div id="l1592" class="code_block">is taken to be greater than any integer.  If <span class="s">$</span><span class="nb">C_</span><span class="m">1</span><span class="s">$</span> was reached first
</div><div id="l1593" class="code_block">and then <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span>, <span class="s">$</span><span class="nb">C_</span><span class="m">2</span><span class="s">$</span> is treated as having already been seen.
</div><div id="l1594" class="code_block">
</div><div id="l1595" class="code_block">Tabling combined with partial order answer subsumption requires
</div><div id="l1596" class="code_block">slightly over 100 lines of code to model reachability in PT nets using
</div><div id="l1597" class="code_block"><span class="s">$</span><span class="nv">\omega</span><span class="s">$</span>-sequences.  Due to space restrictions, the program cannot be
</div><div id="l1598" class="code_block">fully described here, but the top-level reachability predicate is
</div><div id="l1599" class="code_block">shown in Figure~<span class="k">\ref</span><span class="nb">{</span>fig:ptnetcode<span class="nb">}</span>.  Despite its succinctness, it can
</div><div id="l1600" class="code_block">evaluate reachability in networks with millions of states in a few
</div><div id="l1601" class="code_block">minutes.  This use of tabling to determine reachability in PT nets can
</div><div id="l1602" class="code_block">be seen as a special case of tabling for abstract interpretation
</div><div id="l1603" class="code_block">(cf. <span class="k">\cite</span><span class="nb">{</span>KaKa93<span class="nb">}</span> and other works).  However the framework for answer
</div><div id="l1604" class="code_block">subsumption described here allows tabling to be used to efficiently
</div><div id="l1605" class="code_block">perform abstract interpretation within a general Prolog system
</div><div id="l1606" class="code_block"><span class="c">%</span>
</div><div id="l1607" class="code_block"><span class="k">\begin</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1608" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1609" class="code_block">:- table reachable(<span class="nb">_</span>,po(omega<span class="nb">_</span>gte/2,omega<span class="nb">_</span>abs/3)).
</div><div id="l1610" class="code_block">reachable(InConf,NewConf):-
</div><div id="l1611" class="code_block">        reachable(InConf,NewConf),
</div><div id="l1612" class="code_block">        hasTransition(Conf,NewConf).
</div><div id="l1613" class="code_block">reachable(InConf,NewConf):- hasTransition(InConf,NewConf).
</div><div id="l1614" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1615" class="code_block"><span class="k">\caption</span><span class="nb">{</span>Top-level predicate for PT net reachability<span class="nb">}</span>
</div><div id="l1616" class="code_block"><span class="k">\label</span><span class="nb">{</span>fig:ptnetcode<span class="nb">}</span>
</div><div id="l1617" class="code_block"><span class="k">\end</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1618" class="code_block">
</div><div id="l1619" class="code_block"><span class="k">\subsubsection</span><span class="nb">{</span>Scalability for multi-valued and quantitative logics<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>sec:mv<span class="nb">}</span>
</div><div id="l1620" class="code_block"><span class="k">\index</span><span class="nb">{</span>tabling!answer subsumption<span class="nb">}</span>
</div><div id="l1621" class="code_block"><span class="c">%</span>
</div><div id="l1622" class="code_block">The technique of program justification (cf. e.g. <span class="k">\cite</span><span class="nb">{</span>PGDRR04<span class="nb">}</span>) has
</div><div id="l1623" class="code_block">been used for debugging tabled programs that cannot be debugged by
</div><div id="l1624" class="code_block">traditional means.  Here, we consider justification in the context of
</div><div id="l1625" class="code_block">the Silk system, currently under development at Vulcan, Inc.  Silk is
</div><div id="l1626" class="code_block">a commercial knowledge representation and rule system built on top of
</div><div id="l1627" class="code_block">Flora-2, which is implemented using XSB.  One of the salient features
</div><div id="l1628" class="code_block">of Silk is its default reasoning, which is based on a parameterized
</div><div id="l1629" class="code_block">argumentation theory evaluated under the well-founded
</div><div id="l1630" class="code_block">semantics~<span class="k">\cite</span><span class="nb">{</span>WGKFL09<span class="nb">}</span>.  One issue in using Silk is that knowledge
</div><div id="l1631" class="code_block">engineers must have a way of understanding the reasoning of the
</div><div id="l1632" class="code_block">system, a task complicated by the use of the well-founded semantics
</div><div id="l1633" class="code_block">and the intricacies of the argumentation theory.  We describe an
</div><div id="l1634" class="code_block">experimental approach to justification of Silk-style argumentation
</div><div id="l1635" class="code_block">theories using multi-valued logics.
</div><div id="l1636" class="code_block">
</div><div id="l1637" class="code_block">As noted in~<span class="k">\cite</span><span class="nb">{</span>WGKFL09<span class="nb">}</span>, argumentation theories in Silk are usually
</div><div id="l1638" class="code_block">extensions of the default theories of Courteous Logic Programs (CLP)
</div><div id="l1639" class="code_block">and are based on two user-defined predicates: <span class="nb">{</span><span class="k">\tt</span> opposes/2<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l1640" class="code_block">  overrides/2<span class="nb">}</span>.  Two atoms <span class="nb">{</span><span class="k">\em</span> oppose<span class="nb">}</span> each other if no model of a
</div><div id="l1641" class="code_block">program can contain both atoms: an atom and its explicit negation
</div><div id="l1642" class="code_block">oppose each other, but opposition can capture many other types of
</div><div id="l1643" class="code_block">contradictions.  Given two opposing atoms, one atom may <span class="nb">{</span><span class="k">\em</span> override<span class="nb">}</span>
</div><div id="l1644" class="code_block">the other, and so be given preference.  For atoms <span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="s">$</span> and <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="s">$</span>, if
</div><div id="l1645" class="code_block"><span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="s">$</span> and <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="s">$</span> are both derivable and oppose each other but neither
</div><div id="l1646" class="code_block">overrides the other, <span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="s">$</span> and <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="s">$</span> mutually <span class="nb">{</span><span class="k">\em</span> rebut<span class="nb">}</span> each other.
</div><div id="l1647" class="code_block">If in addition <span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="s">$</span>, say, overrides <span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="s">$</span>, <span class="s">$</span><span class="nb">A_</span><span class="m">1</span><span class="s">$</span> <span class="nb">{</span><span class="k">\em</span> refutes<span class="nb">}</span>
</div><div id="l1648" class="code_block"><span class="s">$</span><span class="nb">A_</span><span class="m">2</span><span class="s">$</span>~<span class="k">\footnote</span><span class="nb">{</span>In~<span class="k">\cite</span><span class="nb">{</span>WGKFL09<span class="nb">}</span> argumentation theories are built on
</div><div id="l1649" class="code_block">  named rules, here we base them on derived atoms.<span class="nb">}</span>.  Within Silk and
</div><div id="l1650" class="code_block">Flora-2, the compilation of an argumentation theory ensures that
</div><div id="l1651" class="code_block">rebutted atoms have an undefined truth value, as do atoms that refute
</div><div id="l1652" class="code_block">themselves (i.e. if the <span class="nb">{</span><span class="k">\tt</span> overrides/2<span class="nb">}</span> predicate is cyclic).
</div><div id="l1653" class="code_block">However, for justification, it is meaningful to distinguish those
</div><div id="l1654" class="code_block">facts that are undefined due to a negative loop in the argumentation
</div><div id="l1655" class="code_block">theory from those that are undefined due to a negative loop in the
</div><div id="l1656" class="code_block">program itself.  In addition, it is meaningful to distinguish an atom
</div><div id="l1657" class="code_block">that is true because it overrides some other atom, from an atom whose
</div><div id="l1658" class="code_block">derivation does not depend on the argumentation theory.  Similar
</div><div id="l1659" class="code_block">distinctions can be made for default false literals leading to the
</div><div id="l1660" class="code_block">truth lattice shown in Figure~<span class="k">\ref</span><span class="nb">{</span>fig:courteous<span class="nb">}</span>.
</div><div id="l1661" class="code_block"><span class="k">\begin</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1662" class="code_block"><span class="k">\comment</span><span class="nb">{</span>
</div><div id="l1663" class="code_block"><span class="k">\small</span><span class="nb">{</span>
</div><div id="l1664" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1665" class="code_block">:- table defeated/1.
</div><div id="l1666" class="code_block">defeated(A):-  defeated<span class="nb">_</span>by(A,<span class="nb">_</span>B).       defeated(A):-  defeats(A,<span class="nb">_</span>B).
</div><div id="l1667" class="code_block">
</div><div id="l1668" class="code_block">defeated<span class="nb">_</span>by(A,B):- refutes(B,A),B.      defeats(A,B):- refutes(A,B),B.	        
</div><div id="l1669" class="code_block">defeated<span class="nb">_</span>by(A,B):- rebuts(B,A),B.       defeats(A,B):- rebuts(A,B),B.		
</div><div id="l1670" class="code_block">
</div><div id="l1671" class="code_block">refutes(A,B):- conflicts(A,B), overrides(A,B).
</div><div id="l1672" class="code_block">rebuts(A,B):- conflicts(A,B).
</div><div id="l1673" class="code_block">
</div><div id="l1674" class="code_block">conflicts(A,B):- opposes(A,B),A.        conflicts(A,B):- opposes(B,A),A.
</div><div id="l1675" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1676" class="code_block"><span class="nb">}}</span>
</div><div id="l1677" class="code_block"><span class="k">\centering</span>
</div><div id="l1678" class="code_block"><span class="k">\includegraphics</span><span class="na">[width=0.45\textwidth]</span><span class="nb">{</span>courteous2<span class="nb">}</span>
</div><div id="l1679" class="code_block"><span class="c">%%\epsfig{file=courteous2,width=.45\textwidth}</span>
</div><div id="l1680" class="code_block"><span class="k">\caption</span><span class="nb">{</span>A Truth Lattice for a Simplified Version of Courteous Argumentation Theory<span class="nb">}</span> 
</div><div id="l1681" class="code_block"><span class="k">\label</span><span class="nb">{</span>fig:courteous<span class="nb">}</span>
</div><div id="l1682" class="code_block"><span class="k">\end</span><span class="nb">{</span>figure<span class="nb">}</span>
</div><div id="l1683" class="code_block"><span class="c">%</span>
</div><div id="l1684" class="code_block">
</div><div id="l1685" class="code_block"><span class="k">\subsection</span><span class="nb">{</span>Term-Sets<span class="nb">}</span>
</div><div id="l1686" class="code_block">
</div><div id="l1687" class="code_block">XSB provides support for a programming technique for representing sets
</div><div id="l1688" class="code_block">of terms, called term-sets.  (While it is not closely related to
</div><div id="l1689" class="code_block">answer subsumption, it is partially implemented through tabling and a
</div><div id="l1690" class="code_block">table declaration, and so this facility is documented here.)
</div><div id="l1691" class="code_block">
</div><div id="l1692" class="code_block">We begin in an example.  We can represent a set of Prolog terms by
</div><div id="l1693" class="code_block">using a particular term of the form <span class="k">\verb</span>|<span class="nb">{</span>Var:Goal<span class="nb">}</span>| where Goal has
</div><div id="l1694" class="code_block">(only) <span class="k">\verb</span>|Var| free in it.  Then we will use this <span class="k">\emph</span><span class="nb">{</span>set-term<span class="nb">}</span> to
</div><div id="l1695" class="code_block">represent the set of terms obtained by evaluating <span class="k">\verb</span>|Goal| and
</div><div id="l1696" class="code_block">taking the values of <span class="k">\verb</span>|Var| that are obtained.  I.e., they would
</div><div id="l1697" class="code_block">be the terms in the list <span class="k">\verb</span>|L| returned by the Prolog call to
</div><div id="l1698" class="code_block"><span class="k">\verb</span>|setof(Var,Goal,L)|. For example, the set-term:
</div><div id="l1699" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1700" class="code_block"><span class="nb">{</span>X : member(X,[a,b,c])<span class="nb">}</span>
</div><div id="l1701" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1702" class="code_block">represents the set of terms <span class="k">\verb</span>|<span class="nb">{</span>a,b,c<span class="nb">}</span>|.
</div><div id="l1703" class="code_block">
</div><div id="l1704" class="code_block">Now a <span class="k">\emph</span><span class="nb">{</span>term-set<span class="nb">}</span> is a Prolog term that may contain set-terms as
</div><div id="l1705" class="code_block">subterms.  For example,
</div><div id="l1706" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1707" class="code_block">m(<span class="nb">{</span>X:member(X,[a,b,c])<span class="nb">}</span>,g(d,<span class="nb">{</span>Y:member(Y,[e,f,g])<span class="nb">}</span>),h)
</div><div id="l1708" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1709" class="code_block">is a term-set, and it represents the set of terms obtained from it by
</div><div id="l1710" class="code_block">replacing (recursively) any embeded set-term by a term in that
</div><div id="l1711" class="code_block">set-term.  So the above term-set represents the 9 terms:
</div><div id="l1712" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1713" class="code_block">m(a,g(d,e),h)        m(a,g(d,f),h)        m(a,g(d,g),h)
</div><div id="l1714" class="code_block">m(b,g(d,e),h)        m(b,g(d,f),h)        m(b,g(d,g),h)
</div><div id="l1715" class="code_block">m(c,g(d,e),h)        m(c,g(d,f),h)        m(c,g(d,g),h)
</div><div id="l1716" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1717" class="code_block">This example shows an advantage of this representation.  Say a
</div><div id="l1718" class="code_block">term-set has <span class="s">$</span><span class="nb">k</span><span class="s">$</span> sub-set-terms each of which is of the member form in
</div><div id="l1719" class="code_block">this example where each member has a list of atoms of length <span class="s">$</span><span class="nb">n</span><span class="s">$</span>.  To
</div><div id="l1720" class="code_block">represent this set of terms explicitly takes <span class="s">$</span><span class="nb">O</span><span class="o">(</span><span class="nb">n^k</span><span class="o">)</span><span class="s">$</span> space, whereas
</div><div id="l1721" class="code_block">to represent them with the term-set takes only <span class="s">$</span><span class="nb">O</span><span class="o">(</span><span class="nb">n </span><span class="nv">\times</span><span class="nb"> k</span><span class="o">)</span><span class="s">$</span> space.  So a
</div><div id="l1722" class="code_block">term-set representation can take exponentially less space than an
</div><div id="l1723" class="code_block">explicit representation.
</div><div id="l1724" class="code_block">
</div><div id="l1725" class="code_block">It is relatively easy to write a predicate, <span class="nb">{</span><span class="k">\tt</span> member<span class="k">\_termset</span>/2<span class="nb">}</span>,
</div><div id="l1726" class="code_block">which takes a variable and a term-set
</div><div id="l1727" class="code_block">and non<span class="k">\-</span>deterministically generates all concrete terms represented by
</div><div id="l1728" class="code_block">the term-set, called <span class="k">\emph</span><span class="nb">{</span>extensionalizing<span class="nb">}</span> the term-set.  Some care
</div><div id="l1729" class="code_block">must be taken since a call to goal to extensionalize a set-term may
</div><div id="l1730" class="code_block">itself return a term-set.  Also term-sets can be self-recursive and
</div><div id="l1731" class="code_block">thus represent infinitely many Prolog terms.  For example, consider
</div><div id="l1732" class="code_block">the term-set:
</div><div id="l1733" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1734" class="code_block"><span class="nb">{</span>X : p(X)<span class="nb">}</span> where
</div><div id="l1735" class="code_block">  p(a).
</div><div id="l1736" class="code_block">  p(f(<span class="nb">{</span>X:p(X)<span class="nb">}</span>)).
</div><div id="l1737" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1738" class="code_block">This term-set contains the infinitely many terms:
</div><div id="l1739" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1740" class="code_block">a, f(a), f(f(a)), f(f(f(a))), ...
</div><div id="l1741" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1742" class="code_block">
</div><div id="l1743" class="code_block">A particularly intriguing use of term-sets is in conjuntion with
</div><div id="l1744" class="code_block">tabling.  Consider the term-set <span class="k">\verb</span>|<span class="nb">{</span>X:p(1,2,X)<span class="nb">}</span>| where <span class="nb">{</span><span class="k">\tt</span> p/3<span class="nb">}</span> is
</div><div id="l1745" class="code_block">tabled.  If <span class="k">\verb</span>|p(1,2,<span class="nb">_}</span>| has been called and so its table is
</div><div id="l1746" class="code_block">filled, then extensionalizing the previous term-set is just a table
</div><div id="l1747" class="code_block">lookup; in some sense we can think of such a term-set a standing for a
</div><div id="l1748" class="code_block">pointer into a table to a set of terms.  This can be elegantly used to
</div><div id="l1749" class="code_block">solve an important problem in handling parse trees in context-free
</div><div id="l1750" class="code_block">parsing.
</div><div id="l1751" class="code_block">
</div><div id="l1752" class="code_block">Consider the following DCG for the language a*:
</div><div id="l1753" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1754" class="code_block">:- table a/3.
</div><div id="l1755" class="code_block">a(a(P1,P2)) --&gt; a(P1),a(P2).
</div><div id="l1756" class="code_block">a(a) --&gt; [a].
</div><div id="l1757" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1758" class="code_block">which recognizes a string and constructs its parse trees.
</div><div id="l1759" class="code_block">
</div><div id="l1760" class="code_block">To generate all answers, this DCG will take time exponential in the
</div><div id="l1761" class="code_block">length of the input string; not surprising since there are
</div><div id="l1762" class="code_block">exponentially many parses.  But say we give it an input string of <span class="s">$</span><span class="nb">n</span><span class="s">$</span>
</div><div id="l1763" class="code_block"><span class="nb">{</span><span class="k">\tt</span> a<span class="nb">}</span>&#39;s followed by one <span class="nb">{</span><span class="k">\tt</span> b<span class="nb">}</span>.  In this case it will take
</div><div id="l1764" class="code_block">exponential time to fail, since it will construct all the
</div><div id="l1765" class="code_block">exponentially many partial parse trees.  We would like the grammar in
</div><div id="l1766" class="code_block">this case to fail in polynomial time.  By representing the parse trees
</div><div id="l1767" class="code_block">as a term-set, while recognizing the string, and then after the string
</div><div id="l1768" class="code_block">is recognized, extensionalize the set-term representing the parse
</div><div id="l1769" class="code_block">trees, we can get the behavior we want.  The set-term representing the
</div><div id="l1770" class="code_block">parse trees for any grammar will be constructed in polynomial time;
</div><div id="l1771" class="code_block">the extensionalization will take exponential time only if there are
</div><div id="l1772" class="code_block">exponentially many parses.
</div><div id="l1773" class="code_block">
</div><div id="l1774" class="code_block">We can cause XSB to automatically use the term-set representation by
</div><div id="l1775" class="code_block">adding to the above program the declaration:
</div><div id="l1776" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1777" class="code_block">:- table a(termset,<span class="nb">_</span>,<span class="nb">_</span>).
</div><div id="l1778" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1779" class="code_block">which tells XSB to use the term-set representation of the first
</div><div id="l1780" class="code_block">argument of <span class="nb">{</span><span class="k">\tt</span> a/3<span class="nb">}</span>.
</div><div id="l1781" class="code_block">
</div><div id="l1782" class="code_block">With this declaration, XSB will transform the above program into the
</div><div id="l1783" class="code_block">following:
</div><div id="l1784" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l1785" class="code_block">:- table a/3.
</div><div id="l1786" class="code_block">
</div><div id="l1787" class="code_block">a(a(P1,P2),S0,S) :- &#39;<span class="nb">_</span><span class="s">$</span><span class="nb">a&#39;</span><span class="o">(</span><span class="nb">P</span><span class="m">1</span><span class="nb">,S</span><span class="m">0</span><span class="nb">,S</span><span class="m">1</span><span class="o">)</span><span class="nb">,&#39;_</span><span class="s">$</span>a&#39;(P2,S1,S).
</div><div id="l1788" class="code_block">a(a,S0,S1) --&gt; &#39;C&#39;(S0,a,S1).
</div><div id="l1789" class="code_block">
</div><div id="l1790" class="code_block">:- table &#39;<span class="nb">_</span><span class="s">$</span><span class="nb">a&#39;</span><span class="o">/</span><span class="m">3</span><span class="nb"> as subsumptive.</span>
</div><div id="l1791" class="code_block"><span class="nb">&#39;_</span><span class="s">$</span>a&#39;(<span class="nb">{</span>X:&#39;<span class="nb">_</span><span class="s">$</span><span class="nb">a&#39;</span><span class="o">(</span><span class="nb">X,S</span><span class="m">0</span><span class="nb">,S</span><span class="o">)</span><span class="nb">},S</span><span class="m">0</span><span class="nb">,S</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> a</span><span class="o">(</span><span class="nb">_,S</span><span class="m">0</span><span class="nb">,S</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1792" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1793" class="code_block"><span class="nb">A new predicate {</span><span class="nv">\tt</span><span class="nb"> &#39;</span><span class="nv">\_\$</span><span class="nb">a&#39;</span><span class="o">/</span><span class="m">3</span><span class="nb">} is introduced, and all calls to the</span>
</div><div id="l1794" class="code_block"><span class="nb">original predicate {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">3</span><span class="nb">} are replaced by calls to the new one.  It</span>
</div><div id="l1795" class="code_block"><span class="nb">is defined to call the original {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">3</span><span class="nb">} but to return the term</span><span class="o">-</span><span class="nb">set</span>
</div><div id="l1796" class="code_block"><span class="nb">instead of the concrete parse tree in the argument declared to be a</span>
</div><div id="l1797" class="code_block"><span class="nb">term</span><span class="o">-</span><span class="nb">set.</span>
</div><div id="l1798" class="code_block">
</div><div id="l1799" class="code_block"><span class="nb">We can see that a call to {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">3</span><span class="nb">} in this new program will have</span>
</div><div id="l1800" class="code_block"><span class="nb">exactly as many answers as the corresponding call to {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">2</span><span class="nb">} in the</span>
</div><div id="l1801" class="code_block"><span class="nb">original recognizing DCG, since given values for {</span><span class="nv">\tt</span><span class="nb"> S</span><span class="m">0</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> S}, a</span>
</div><div id="l1802" class="code_block"><span class="nb">call to {</span><span class="nv">\tt</span><span class="nb"> &#39;</span><span class="nv">\_\$</span><span class="nb">a&#39;</span><span class="o">/</span><span class="m">2</span><span class="nb">} returns only one value in its first argument.</span>
</div><div id="l1803" class="code_block"><span class="nb">So a call to {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">3</span><span class="nb">} with have the polynomial complexity of the</span>
</div><div id="l1804" class="code_block"><span class="nb">recognizer.  So now with this representation to get the concrete parse</span>
</div><div id="l1805" class="code_block"><span class="nb">tree for a string, one writes, for example:</span>
</div><div id="l1806" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1807" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> a</span><span class="o">(</span><span class="nb">Pts,</span><span class="o">[</span><span class="nb">a,a,a,a,a,a,a</span><span class="o">]</span><span class="nb">,</span><span class="o">[])</span><span class="nb">, member_termset</span><span class="o">(</span><span class="nb">Parse,Pts</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1808" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1809" class="code_block"><span class="nb">which uses the term</span><span class="o">-</span><span class="nb">set representation while recognizing the input</span>
</div><div id="l1810" class="code_block"><span class="nb">string, and then extensionalizes it to the produce the actual parse</span>
</div><div id="l1811" class="code_block"><span class="nb">tree.  With this way of handling parse trees in arbitrary context</span><span class="o">-</span><span class="nb">free</span>
</div><div id="l1812" class="code_block"><span class="nb">grammars, the complexity of parsing to create the term</span><span class="o">-</span><span class="nb">set is always</span>
</div><div id="l1813" class="code_block"><span class="nb">polynomial, and then extensionalizing the term</span><span class="o">-</span><span class="nb">set may be exponential</span>
</div><div id="l1814" class="code_block"><span class="nb">if all parses are desired and there are exponentially many of them.</span>
</div><div id="l1815" class="code_block"><span class="nb">Of course, if the parsing call to {</span><span class="nv">\tt</span><span class="nb"> a</span><span class="o">/</span><span class="m">3</span><span class="nb">} fails, then there is no</span>
</div><div id="l1816" class="code_block"><span class="nb">extensionalization to do, and the process is polynomial.</span>
</div><div id="l1817" class="code_block">
</div><div id="l1818" class="code_block"><span class="nb">Note that the transformation uses subsumptive tabling for the newly</span>
</div><div id="l1819" class="code_block"><span class="nb">introduced auxiliary predicate.  This is important for this example,</span>
</div><div id="l1820" class="code_block"><span class="nb">since the parsing calls to {</span><span class="nv">\tt</span><span class="nb"> &#39;</span><span class="nv">\_\$</span><span class="nb">a&#39;</span><span class="o">/</span><span class="m">3</span><span class="nb">} will normally have {</span><span class="nv">\tt</span><span class="nb"> S</span><span class="m">0</span><span class="nb">}</span>
</div><div id="l1821" class="code_block"><span class="nb">bound and {</span><span class="nv">\tt</span><span class="nb"> S} free, yet when extensionalizing the constructed</span>
</div><div id="l1822" class="code_block"><span class="nb">term</span><span class="o">-</span><span class="nb">set to obtain the parse trees, the calls will have both {</span><span class="nv">\tt</span><span class="nb"> S</span><span class="m">0</span><span class="nb">}</span>
</div><div id="l1823" class="code_block"><span class="nb">and {</span><span class="nv">\tt</span><span class="nb"> S} bound.  We do not want to recompute the parse during</span>
</div><div id="l1824" class="code_block"><span class="nb">extensionalizion, which would happen were we to be using variant</span>
</div><div id="l1825" class="code_block"><span class="nb">tabling, and so we use subsumptive tabling.</span>
</div><div id="l1826" class="code_block">
</div><div id="l1827" class="code_block"><span class="nb">Problems in graph traversal provide another example of the effective</span>
</div><div id="l1828" class="code_block"><span class="nb">use of term</span><span class="o">-</span><span class="nb">sets.  For graph reachability, we have the very familiar:</span>
</div><div id="l1829" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1830" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table reach</span><span class="o">/</span><span class="m">2</span><span class="nb">.</span>
</div><div id="l1831" class="code_block"><span class="nb">reach</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> edge</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1832" class="code_block"><span class="nb">reach</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> reach</span><span class="o">(</span><span class="nb">X,Z</span><span class="o">)</span><span class="nb">, edge</span><span class="o">(</span><span class="nb">Z,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1833" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1834" class="code_block"><span class="nb">which is linear in the number of edges in the graph.  But say that we</span>
</div><div id="l1835" class="code_block"><span class="nb">now want to construct the path from X to Y when Y </span><span class="nv">\emph</span><span class="nb">{is} reachable</span>
</div><div id="l1836" class="code_block"><span class="nb">from X.  One simple way to do it </span><span class="o">(</span><span class="nb">collecting the intermediate nodes in</span>
</div><div id="l1837" class="code_block"><span class="nb">the path in reverse order</span><span class="o">)</span><span class="nb"> is:</span>
</div><div id="l1838" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1839" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table path</span><span class="o">/</span><span class="m">3</span><span class="nb">.</span>
</div><div id="l1840" class="code_block"><span class="nb">path</span><span class="o">(</span><span class="nb">X,Y,</span><span class="o">[])</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> edge</span><span class="o">(</span><span class="nb">X,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1841" class="code_block"><span class="nb">path</span><span class="o">(</span><span class="nb">X,Y,</span><span class="o">[</span><span class="nb">Z|Path</span><span class="o">])</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> path</span><span class="o">(</span><span class="nb">X,Z,Path</span><span class="o">)</span><span class="nb">, edge</span><span class="o">(</span><span class="nb">Z,Y</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1842" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1843" class="code_block"><span class="nb">For an acyclic edge graph, this works fine, but for a graph with</span>
</div><div id="l1844" class="code_block"><span class="nb">cycles, this will go into an infinite loop.  Indeed, it must, since in</span>
</div><div id="l1845" class="code_block"><span class="nb">a cyclic graph there </span><span class="nv">\emph</span><span class="nb">{are} infinitely many different paths between</span>
</div><div id="l1846" class="code_block"><span class="nb">some nodes.  However, we can use term</span><span class="o">-</span><span class="nb">set to handle this situation</span>
</div><div id="l1847" class="code_block"><span class="nb">more flexibly.  We modify the above program by adding:</span>
</div><div id="l1848" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1849" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table path</span><span class="o">(</span><span class="nb">_,_,termset</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1850" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1851" class="code_block"><span class="nb">With this declaration, every call to {</span><span class="nv">\tt</span><span class="nb"> path</span><span class="o">/</span><span class="m">3</span><span class="nb">} </span><span class="o">(</span><span class="nb">for a finite edge</span>
</div><div id="l1852" class="code_block"><span class="nb">graph</span><span class="o">)</span><span class="nb"> will terminate in time linear in the number of edges.  And all</span>
</div><div id="l1853" class="code_block"><span class="nb">the paths will be presented in the term</span><span class="o">-</span><span class="nb">set returned in the third</span>
</div><div id="l1854" class="code_block"><span class="nb">argument.  Here we have an advantage similar to the one we had in the</span>
</div><div id="l1855" class="code_block"><span class="nb">grammar example above: if there is no path from our source to our</span>
</div><div id="l1856" class="code_block"><span class="nb">target node, we will find that out in linear time.  Without the</span>
</div><div id="l1857" class="code_block"><span class="nb">term</span><span class="o">-</span><span class="nb">set declaration, this might take exponential time, while the</span>
</div><div id="l1858" class="code_block"><span class="nb">program builds all the paths to all the nodes that </span><span class="nv">\emph</span><span class="nb">{are} reachable</span>
</div><div id="l1859" class="code_block"><span class="nb">from our source node.  Also, if we want only </span><span class="nv">\emph</span><span class="nb">{one} possible path</span>
</div><div id="l1860" class="code_block"><span class="nb">from our source to our target, we can easily retrieve only one member</span>
</div><div id="l1861" class="code_block"><span class="nb">of the term</span><span class="o">-</span><span class="nb">set during extensionalization, and the whole process is</span>
</div><div id="l1862" class="code_block"><span class="nb">still linear.</span>
</div><div id="l1863" class="code_block">
</div><div id="l1864" class="code_block"><span class="nb">Now consider what happens with when the graph has cycles.  In this</span>
</div><div id="l1865" class="code_block"><span class="nb">case, the term</span><span class="o">-</span><span class="nb">set may be recursive and represent the infinitely many</span>
</div><div id="l1866" class="code_block"><span class="nb">paths between nodes.  For example, the term</span><span class="o">-</span><span class="nb">set representing all paths</span>
</div><div id="l1867" class="code_block"><span class="nb">from {</span><span class="nv">\tt</span><span class="nb"> a} to {</span><span class="nv">\tt</span><span class="nb"> a} in the graph with a single edge from {</span><span class="nv">\tt</span><span class="nb"> a} to</span>
</div><div id="l1868" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> a} will have the same structure as the example of an infinite</span>
</div><div id="l1869" class="code_block"><span class="nb">term</span><span class="o">-</span><span class="nb">set given at the beginning of this subsection.  Once the path</span>
</div><div id="l1870" class="code_block"><span class="nb">term</span><span class="o">-</span><span class="nb">set is constructed </span><span class="o">(</span><span class="nb">in time linear in the number of edges for a</span>
</div><div id="l1871" class="code_block"><span class="nb">single source</span><span class="o">)</span><span class="nb">, producing paths reduces to processing the term</span><span class="o">-</span><span class="nb">set</span>
</div><div id="l1872" class="code_block"><span class="nb">structure.  For example to generate all paths between nodes which do</span>
</div><div id="l1873" class="code_block"><span class="nb">not contain repeated intermediate nodes, one could write an</span>
</div><div id="l1874" class="code_block"><span class="nb">extensionalization predicate that passes a list of term</span><span class="o">-</span><span class="nb">sets in the</span>
</div><div id="l1875" class="code_block"><span class="nb">process of being expanded, and refuse to re</span><span class="o">-</span><span class="nb">expand one currently being</span>
</div><div id="l1876" class="code_block"><span class="nb">expanded.  This is the technique often used in Prolog without tabling</span>
</div><div id="l1877" class="code_block"><span class="nb">to compute reachability in cyclic graphs.</span>
</div><div id="l1878" class="code_block">
</div><div id="l1879" class="code_block"><span class="nb">All of these examples can be seen as special cases of constructing</span>
</div><div id="l1880" class="code_block"><span class="nb">proof trees or justifications of goals.  Indeed, term</span><span class="o">-</span><span class="nb">sets could be</span>
</div><div id="l1881" class="code_block"><span class="nb">effectively used in the construction of a justification or explanation</span>
</div><div id="l1882" class="code_block"><span class="nb">system.</span>
</div><div id="l1883" class="code_block">
</div><div id="l1884" class="code_block"><span class="nv">\index</span><span class="nb">{termination</span><span class="o">!</span><span class="nb">subgoal abstraction}</span>
</div><div id="l1885" class="code_block"><span class="nv">\index</span><span class="nb">{termination</span><span class="o">!</span><span class="nb">bounded rationality}</span>
</div><div id="l1886" class="code_block"><span class="nv">\section</span><span class="nb">{Tabling for Termination}</span>
</div><div id="l1887" class="code_block"><span class="c">%</span>
</div><div id="l1888" class="code_block"><span class="nb">As noted throughout this manual, tabling adds important termination</span>
</div><div id="l1889" class="code_block"><span class="nb">properties to programs and queries.  In this section we state more</span>
</div><div id="l1890" class="code_block"><span class="nb">precisely what these termination properties are, and how the</span>
</div><div id="l1891" class="code_block"><span class="nb">properties can be strengthened through declarations and settings for</span>
</div><div id="l1892" class="code_block"><span class="nb">{</span><span class="nv">\em</span><span class="nb"> subgoal abstraction} and for bounded rationality through {</span><span class="nv">\em</span>
</div><div id="l1893" class="code_block"><span class="nb">  answer abstraction}.</span>
</div><div id="l1894" class="code_block">
</div><div id="l1895" class="code_block"><span class="nb">Before doing so, it is important to set the context for where issues</span>
</div><div id="l1896" class="code_block"><span class="nb">of termination may arise.  Consider first a pure normal program in</span>
</div><div id="l1897" class="code_block"><span class="nb">which every predicate is tabled.  This means a program where rules may</span>
</div><div id="l1898" class="code_block"><span class="nb">only call other rules, possibly through negation </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} or {</span><span class="nv">\tt</span>
</div><div id="l1899" class="code_block"><span class="nb">  sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">} in XSB</span><span class="o">)</span><span class="nb">; but where there are no calls to builtins for</span>
</div><div id="l1900" class="code_block"><span class="nb">arithmetic, all</span><span class="o">-</span><span class="nb">solutions predicates, or other built</span><span class="o">-</span><span class="nb">ins.  If such a</span>
</div><div id="l1901" class="code_block"><span class="nb">fully</span><span class="o">-</span><span class="nb">tabled pure normal program does not have function symbols, XSB</span>
</div><div id="l1902" class="code_block"><span class="nb">will always terminate for any query.  For instance, XSB will terminate</span>
</div><div id="l1903" class="code_block"><span class="nb">for fully tabled pure datalog programs </span><span class="o">--</span><span class="nb"> even if the head of a rule</span>
</div><div id="l1904" class="code_block"><span class="nb">is ``unsafe&#39;&#39; in that it contains variables that do not occur in the</span>
</div><div id="l1905" class="code_block"><span class="nb">body of that rule~</span><span class="nv">\footnote</span><span class="nb">{Evaluations that call non</span><span class="o">-</span><span class="nb">ground negative</span>
</div><div id="l1906" class="code_block"><span class="nb">  literals will terminate through floundering, although this can be</span>
</div><div id="l1907" class="code_block"><span class="nb">  avoided in most cases by using {</span><span class="nv">\tt</span><span class="nb"> sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">}.}.</span>
</div><div id="l1908" class="code_block">
</div><div id="l1909" class="code_block"><span class="nb">While datalog programs are useful for certain kinds of knowledge</span>
</div><div id="l1910" class="code_block"><span class="nb">representation, they are not powerful enough for general programming</span>
</div><div id="l1911" class="code_block"><span class="nb">as they do not allow recursive structures such as lists.  Thus, for</span>
</div><div id="l1912" class="code_block"><span class="nb">the rest of this section we consider pure programs that may contain</span>
</div><div id="l1913" class="code_block"><span class="nb">function symbols.  Consider a pure definite program in which every</span>
</div><div id="l1914" class="code_block"><span class="nb">predicate is tabled.  Such a program would call each tabled subgoal</span>
</div><div id="l1915" class="code_block"><span class="o">(</span><span class="nb">up to variance</span><span class="o">)</span><span class="nb"> exactly once if call variance were used, and at most</span>
</div><div id="l1916" class="code_block"><span class="nb">once if call subsumption were used.  In addition, tabling guarantees</span>
</div><div id="l1917" class="code_block"><span class="nb">that each answer will be returned to each call to a tabled subgoal at</span>
</div><div id="l1918" class="code_block"><span class="nb">most once.  This means that there are two sources of non</span><span class="o">-</span><span class="nb">termination.</span>
</div><div id="l1919" class="code_block"><span class="nb">Either there can be an infinite number of subgoals, or there can be an</span>
</div><div id="l1920" class="code_block"><span class="nb">infinite number of answers~</span><span class="nv">\footnote</span><span class="nb">{Using the forest of trees model</span>
</div><div id="l1921" class="code_block"><span class="nb">  of tabling </span><span class="o">(</span><span class="nb">cf. Section~</span><span class="nv">\ref</span><span class="nb">{sec:forest</span><span class="o">-</span><span class="nb">trace}</span><span class="o">)</span><span class="nb"> non</span><span class="o">-</span><span class="nb">termination</span>
</div><div id="l1922" class="code_block"><span class="nb">  requires that there are an infinite number of trees or that at least</span>
</div><div id="l1923" class="code_block"><span class="nb">  one tree have infinite size.}.</span>
</div><div id="l1924" class="code_block">
</div><div id="l1925" class="code_block"><span class="nv">\paragraph</span><span class="nb">{An Infinite Number of Subgoals}</span>
</div><div id="l1926" class="code_block"><span class="c">%</span>
</div><div id="l1927" class="code_block"><span class="nb">If a definite program produces an infinite number of subgoals {</span><span class="nv">\em</span>
</div><div id="l1928" class="code_block"><span class="nb">  but} has a finite number of answers, the program can be made to</span>
</div><div id="l1929" class="code_block"><span class="nb">terminate by abstracting the subgoal.  For instance, consider the</span>
</div><div id="l1930" class="code_block"><span class="nb">program fragment:</span>
</div><div id="l1931" class="code_block"><span class="c">%</span>
</div><div id="l1932" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1933" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table p</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l1934" class="code_block"><span class="nb">p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l1935" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1936" class="code_block"><span class="c">%</span>
</div><div id="l1937" class="code_block"><span class="nb">The goal {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">} can create an infinite number of tabled</span>
</div><div id="l1938" class="code_block"><span class="nb">subgoals: {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">))</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">)))</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">))))</span><span class="nb">} and so</span>
</div><div id="l1939" class="code_block"><span class="nb">on.  Note that since all of the subgoals are ground, none subsume one</span>
</div><div id="l1940" class="code_block"><span class="nb">another, so that call subsumption will not help here, </span><span class="o">(</span><span class="nb">although it</span>
</div><div id="l1941" class="code_block"><span class="nb">would help if the goal were {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1942" class="code_block">
</div><div id="l1943" class="code_block"><span class="nv">\paragraph</span><span class="o">*</span><span class="nb">{Infinite Answers}</span>
</div><div id="l1944" class="code_block"><span class="c">%</span>
</div><div id="l1945" class="code_block"><span class="nb">Of course, subgoal abstraction can&#39;t handle cases where there are an</span>
</div><div id="l1946" class="code_block"><span class="nb">infinite number of answers, as in the program fragment:</span>
</div><div id="l1947" class="code_block"><span class="c">%</span>
</div><div id="l1948" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1949" class="code_block"><span class="nb">p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1950" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1951" class="code_block"><span class="c">%</span>
</div><div id="l1952" class="code_block"><span class="nb">when given the query {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}.  </span>
</div><div id="l1953" class="code_block">
</div><div id="l1954" class="code_block"><span class="nb">We consider each case in turn.</span>
</div><div id="l1955" class="code_block">
</div><div id="l1956" class="code_block"><span class="nv">\subsection</span><span class="nb">{Subgoal Abstraction}</span>
</div><div id="l1957" class="code_block"><span class="c">%</span>
</div><div id="l1958" class="code_block"><span class="nb">In a nutshell, subgoal abstraction allows a goal like {</span><span class="nv">\tt</span>
</div><div id="l1959" class="code_block"><span class="nb">  p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">))))</span><span class="nb">} to be rewritten as </span>
</div><div id="l1960" class="code_block">
</div><div id="l1961" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">)))</span><span class="nb">,X </span><span class="o">=</span><span class="nb"> f</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">}.  </span>
</div><div id="l1962" class="code_block">
</div><div id="l1963" class="code_block"><span class="nv">\noindent</span>
</div><div id="l1964" class="code_block"><span class="nb">If all subgoals that have a term depth </span><span class="o">(</span><span class="nb">or term size</span><span class="o">)</span><span class="nb"> over a given</span>
</div><div id="l1965" class="code_block"><span class="nb">finite threshold are abstracted, any query can produce only a finite</span>
</div><div id="l1966" class="code_block"><span class="nb">number of subgoals </span><span class="o">(</span><span class="nb">since there are a finite number of predicate,</span>
</div><div id="l1967" class="code_block"><span class="nb">function and constant symbols in any program</span><span class="o">)</span><span class="nb">. If a program is</span>
</div><div id="l1968" class="code_block"><span class="nb">definite, it can be shown that any query to a program will terminate</span>
</div><div id="l1969" class="code_block"><span class="nb">if that program uses subgoal abstraction~</span><span class="nv">\cite</span><span class="nb">{TaSa</span><span class="m">86</span><span class="nb">}.</span>
</div><div id="l1970" class="code_block"><span class="c">%</span>
</div><div id="l1971" class="code_block"><span class="nb">For normal programs, the situation is not much different at a</span>
</div><div id="l1972" class="code_block"><span class="nb">conceptual level.  A goal such as {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">))))</span><span class="nb">} would</span>
</div><div id="l1973" class="code_block"><span class="nb">execute as {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">)))</span><span class="nb">} and then ensure that none of the answers</span>
</div><div id="l1974" class="code_block"><span class="nb">to this goal have a binding for {</span><span class="nv">\tt</span><span class="nb"> X} that allows it to unify with</span>
</div><div id="l1975" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> f</span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb">}.  Using this intuition, it can be shown that if a program</span>
</div><div id="l1976" class="code_block"><span class="nb">has a two</span><span class="o">-</span><span class="nb">valued well</span><span class="o">-</span><span class="nb">founded model and a finite number of true</span>
</div><div id="l1977" class="code_block"><span class="nb">answers it will terminate using tabling with subgoal</span>
</div><div id="l1978" class="code_block"><span class="nb">abstraction~</span><span class="nv">\cite</span><span class="nb">{RigS</span><span class="m">11</span><span class="nb">b}.</span>
</div><div id="l1979" class="code_block">
</div><div id="l1980" class="code_block"><span class="nb">Despite its theoretical power, subgoal abstraction can also cause</span>
</div><div id="l1981" class="code_block"><span class="nb">problems if used indiscriminately.  if the second argument of the</span>
</div><div id="l1982" class="code_block"><span class="nb">subgoal</span>
</div><div id="l1983" class="code_block"><span class="c">%</span>
</div><div id="l1984" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1985" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> member</span><span class="o">(</span><span class="nb">e,</span><span class="o">[</span><span class="nb">a,b,c,d,e</span><span class="o">])</span>
</div><div id="l1986" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1987" class="code_block"><span class="c">%</span>
</div><div id="l1988" class="code_block"><span class="nb">is abstracted forming the goal</span>
</div><div id="l1989" class="code_block"><span class="c">%</span>
</div><div id="l1990" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1991" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> member</span><span class="o">(</span><span class="nb">e,</span><span class="o">[</span><span class="nb">a,b,c|X</span><span class="o">])</span>
</div><div id="l1992" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1993" class="code_block"><span class="c">%</span>
</div><div id="l1994" class="code_block"><span class="nb">leading to an infinite number of answers.  a goal that terminates</span>
</div><div id="l1995" class="code_block"><span class="nb">without abstraction will not terminate after abstraction.  Note that</span>
</div><div id="l1996" class="code_block"><span class="nb">any program containing {</span><span class="nv">\tt</span><span class="nb"> member</span><span class="o">/</span><span class="m">2</span><span class="nb">} and at least one constant does</span>
</div><div id="l1997" class="code_block"><span class="nb">not have a finite model.  While an experienced programmer would never</span>
</div><div id="l1998" class="code_block"><span class="nb">want to table {</span><span class="nv">\tt</span><span class="nb"> member</span><span class="o">/</span><span class="m">2</span><span class="nb">}, he well may want to table a grammar or</span>
</div><div id="l1999" class="code_block"><span class="nb">other program that performs recursion through a finite structure.</span>
</div><div id="l2000" class="code_block">
</div><div id="l2001" class="code_block"><span class="nv">\subsubsection</span><span class="nb">{Declaring Subgoal Abstraction}</span>
</div><div id="l2002" class="code_block"><span class="c">%</span>
</div><div id="l2003" class="code_block"><span class="nb">The implementation of subgoal abstraction in XSB is still in progress.</span>
</div><div id="l2004" class="code_block"><span class="nb">Abstraction can be performed for goals called positively; but not for</span>
</div><div id="l2005" class="code_block"><span class="nb">goals called negatively including {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> sk</span><span class="nv">\_</span><span class="nb">not</span><span class="o">/</span><span class="m">1</span><span class="nb">};</span>
</div><div id="l2006" class="code_block"><span class="nb">rather, such goals will throw an exception if they surpass the</span>
</div><div id="l2007" class="code_block"><span class="nb">specified depth.  Subgoal abstraction is only implemented for call</span>
</div><div id="l2008" class="code_block"><span class="nb">variance, and currently is only settable globally, and not on a</span>
</div><div id="l2009" class="code_block"><span class="nb">predicate</span><span class="o">-</span><span class="nb">by</span><span class="o">-</span><span class="nb">predicate basis.</span>
</div><div id="l2010" class="code_block">
</div><div id="l2011" class="code_block"><span class="nv">\index</span><span class="nb">{Prolog flags</span><span class="o">!</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">action}}</span>
</div><div id="l2012" class="code_block"><span class="nv">\index</span><span class="nb">{Prolog flags</span><span class="o">!</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth}}</span>
</div><div id="l2013" class="code_block"><span class="nb">Default subgoal abstraction can be declared by setting the Prolog flags</span>
</div><div id="l2014" class="code_block"><span class="c">%</span>
</div><div id="l2015" class="code_block"><span class="nv">\bi</span>
</div><div id="l2016" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth} to the desired maximal depth; and</span>
</div><div id="l2017" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">action} to {</span><span class="nv">\tt</span><span class="nb"> abstract}</span>
</div><div id="l2018" class="code_block"><span class="nv">\ei</span>
</div><div id="l2019" class="code_block"><span class="c">%</span>
</div><div id="l2020" class="code_block"><span class="o">(</span><span class="nb">cf. pg. </span><span class="nv">\pageref</span><span class="nb">{prolog</span><span class="o">-</span><span class="nb">flags}</span><span class="o">)</span><span class="nb">. </span>
</div><div id="l2021" class="code_block"><span class="c">%</span>
</div><div id="l2022" class="code_block"><span class="nb">Unless otherwise specified, XSB starts up with {</span><span class="nv">\tt</span>
</div><div id="l2023" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">action} set to {</span><span class="nv">\tt</span><span class="nb"> error} and {</span><span class="nv">\tt</span>
</div><div id="l2024" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth} set to the maximum integer possible</span>
</div><div id="l2025" class="code_block"><span class="nb">under the compilation method for which XSB has been configured.  Under</span>
</div><div id="l2026" class="code_block"><span class="nb">this default behavior, XSB will throw an error if a subgoal has depth</span>
</div><div id="l2027" class="code_block"><span class="nb">greater than {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth}.  As an alternate to</span>
</div><div id="l2028" class="code_block"><span class="nb">setting flags, XSB can be called with the command</span><span class="o">-</span><span class="nb">line arguments {</span><span class="nv">\tt</span>
</div><div id="l2029" class="code_block"><span class="nb">  </span><span class="o">--</span><span class="nb">max</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">action a} and {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">--</span><span class="nb">max</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth n} where</span>
</div><div id="l2030" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> n} is the size of the desired depth.</span>
</div><div id="l2031" class="code_block">
</div><div id="l2032" class="code_block"><span class="nv">\subsection</span><span class="nb">{Bounded Rationality through Answer Abstraction}</span>
</div><div id="l2033" class="code_block"><span class="c">%</span>
</div><div id="l2034" class="code_block"><span class="nb">In XSB, a programmer can use a form of answer abstraction called {</span><span class="nv">\em</span>
</div><div id="l2035" class="code_block"><span class="nb">  bounded</span><span class="o">-</span><span class="nb">rationality} to ensure that only a finite number of answers</span>
</div><div id="l2036" class="code_block"><span class="nb">are generated by a query.  For instance if the query {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">} to the</span>
</div><div id="l2037" class="code_block"><span class="nb">program</span>
</div><div id="l2038" class="code_block"><span class="c">%</span>
</div><div id="l2039" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2040" class="code_block"><span class="nb">p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))</span><span class="nb"> :</span><span class="o">-</span><span class="nb"> p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.  </span>
</div><div id="l2041" class="code_block"><span class="nb">p</span><span class="o">(</span><span class="m">0</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2042" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2043" class="code_block"><span class="c">%</span>
</div><div id="l2044" class="code_block"><span class="nb">were evaluated using this approach with a depth limit of </span><span class="m">3</span><span class="nb">, the</span>
</div><div id="l2045" class="code_block"><span class="nb">answers, {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="m">0</span><span class="o">)</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">0</span><span class="o">))</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">0</span><span class="o">)))</span><span class="nb">} and {</span><span class="nv">\tt</span>
</div><div id="l2046" class="code_block"><span class="nb">  p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))))</span><span class="nb">} would be generated, {</span><span class="nv">\em</span><span class="nb"> however} {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))))</span><span class="nb">}</span>
</div><div id="l2047" class="code_block"><span class="nb">would have the truth value of {</span><span class="nv">\em</span><span class="nb"> undefined}.  Note that by doing</span>
</div><div id="l2048" class="code_block"><span class="nb">things in this way, both of the goals {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">0</span><span class="o">))))</span><span class="nb">}, and {</span><span class="nv">\tt</span>
</div><div id="l2049" class="code_block"><span class="nb">  p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">))))</span><span class="nb">} will unify with {</span><span class="nv">\tt</span><span class="nb"> p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))))</span><span class="nb">} and so will</span>
</div><div id="l2050" class="code_block"><span class="nb">succeed with a truth value of {</span><span class="nv">\em</span><span class="nb"> undefined}.  Similarly {</span><span class="nv">\tt</span>
</div><div id="l2051" class="code_block"><span class="nb">  tnot</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">0</span><span class="o">)))))</span><span class="nb">}, and {</span><span class="nv">\tt</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="o">)))))</span><span class="nb">} will both</span>
</div><div id="l2052" class="code_block"><span class="nb">succeed with a value of {</span><span class="nv">\em</span><span class="nb"> undefined} </span><span class="o">(</span><span class="nb">perhaps better called {</span><span class="nv">\em</span>
</div><div id="l2053" class="code_block"><span class="nb">  unknown} in this context</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2054" class="code_block"><span class="c">%</span>
</div><div id="l2055" class="code_block"><span class="nb">Since all predicates and function symbols have a maximum arity </span><span class="o">(</span><span class="m">256</span><span class="nb"> in</span>
</div><div id="l2056" class="code_block"><span class="nb">XSB</span><span class="o">)</span><span class="nb"> bounding the depth of an answer ensures that only a finite number</span>
</div><div id="l2057" class="code_block"><span class="nb">of answers are returned</span>
</div><div id="l2058" class="code_block"><span class="nv">\footnote</span><span class="nb">{If a program has a infinite number of true answers and a</span>
</div><div id="l2059" class="code_block"><span class="nb">  finite numebr of false answers, one possible approach might be to</span>
</div><div id="l2060" class="code_block"><span class="nb">  ``dualize&#39;&#39; the program so that only false answers are computed.</span>
</div><div id="l2061" class="code_block"><span class="nb">  However, since most programs with function symbols have an infinite</span>
</div><div id="l2062" class="code_block"><span class="nb">  number of both true and false answers, this approach won&#39;t work in</span>
</div><div id="l2063" class="code_block"><span class="nb">  general.}.</span>
</div><div id="l2064" class="code_block">
</div><div id="l2065" class="code_block">
</div><div id="l2066" class="code_block"><span class="nb">Semantically XSB is computing an approximation to the three</span><span class="o">-</span><span class="nb">valued</span>
</div><div id="l2067" class="code_block"><span class="nb">well</span><span class="o">-</span><span class="nb">founded model of a program, called a {</span><span class="nv">\em</span><span class="nb"> bounded model}.  To see</span>
</div><div id="l2068" class="code_block"><span class="nb">this, suppose the proof of a query </span><span class="s">$</span>Q<span class="s">$</span><span class="nb"> does not depend on negation.</span>
</div><div id="l2069" class="code_block"><span class="nb">If </span><span class="s">$</span>Q<span class="s">$</span><span class="nb"> has a derivation that does not require any answers whose depth</span>
</div><div id="l2070" class="code_block"><span class="nb">is more than </span><span class="s">$</span>n<span class="s">$</span><span class="nb">, it is proven as usual.  Similarly, if </span><span class="s">$</span>Q<span class="s">$</span><span class="nb"> is false</span>
</div><div id="l2071" class="code_block"><span class="nb">in the well</span><span class="o">-</span><span class="nb">founded model of a program, and none of the subgoals</span>
</div><div id="l2072" class="code_block"><span class="nb">explored in the derivation of </span><span class="s">$</span>Q<span class="s">$</span><span class="nb"> derive answers whose depth is</span>
</div><div id="l2073" class="code_block"><span class="nb">greater than </span><span class="s">$</span>n<span class="s">$</span><span class="nb">, XSB will derive that </span><span class="s">$</span>Q<span class="s">$</span><span class="nb"> is false.  Thus, the</span>
</div><div id="l2074" class="code_block"><span class="nb">approximation that XSB computes is {</span><span class="nv">\em</span><span class="nb"> informationally sound} in the</span>
</div><div id="l2075" class="code_block"><span class="nb">sense that no incorrect answer will be derived, although sone answers</span>
</div><div id="l2076" class="code_block"><span class="nb">won&#39;t be known that might have been if the depth bound had been set</span>
</div><div id="l2077" class="code_block"><span class="nb">lower.  Due to the halting problem, there is no way to know in general</span>
</div><div id="l2078" class="code_block"><span class="nb">what depth to set for answer abstraction, or whether any bound needs</span>
</div><div id="l2079" class="code_block"><span class="nb">to be set at all.</span>
</div><div id="l2080" class="code_block">
</div><div id="l2081" class="code_block"><span class="nb">If a bounded model is derived, answers that are undefined in the</span>
</div><div id="l2082" class="code_block"><span class="nb">well</span><span class="o">-</span><span class="nb">founded model can be distinguished from answers that are</span>
</div><div id="l2083" class="code_block"><span class="nb">undefined through bounded rationality.  If an answer </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> was</span>
</div><div id="l2084" class="code_block"><span class="nb">abstracted due to a depth check </span><span class="o">(</span><span class="nb">and for no other reason</span><span class="o">)</span><span class="nb">, the query</span>
</div><div id="l2085" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> get</span><span class="nv">\_</span><span class="nb">residual</span><span class="o">(</span><span class="nb">A,Delay</span><span class="o">)</span><span class="nb">} would bind {</span><span class="nv">\tt</span><span class="nb"> Delay} to {</span><span class="nv">\tt</span>
</div><div id="l2086" class="code_block"><span class="nb">  </span><span class="o">[</span><span class="nb">brat</span><span class="nv">\_</span><span class="nb">undefined</span><span class="o">]</span><span class="nb">}, where {</span><span class="nv">\tt</span><span class="nb"> brat</span><span class="nv">\_</span><span class="nb">undefined</span><span class="o">/</span><span class="m">0</span><span class="nb">} is simply a predicate defined as</span>
</div><div id="l2087" class="code_block">
</div><div id="l2088" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> brat</span><span class="nv">\_</span><span class="nb">undefined:</span><span class="o">-</span><span class="nb"> tnot</span><span class="o">(</span><span class="nb">brat</span><span class="nv">\_</span><span class="nb">undefined</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l2089" class="code_block">
</div><div id="l2090" class="code_block"><span class="nv">\noindent</span>
</div><div id="l2091" class="code_block"><span class="nb">which in a delay list indicates that an answer was made undefined</span>
</div><div id="l2092" class="code_block"><span class="nb">through bounded</span><span class="o">-</span><span class="nb">rationality based answer abstraction.</span>
</div><div id="l2093" class="code_block">
</div><div id="l2094" class="code_block"><span class="nv">\index</span><span class="nb">{</span><span class="nv">\texttt</span><span class="nb">{explain</span><span class="nv">\_</span><span class="nb">u</span><span class="nv">\_</span><span class="nb">value</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l2095" class="code_block"><span class="nb">The XSB predicate</span>
</div><div id="l2096" class="code_block">
</div><div id="l2097" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> explain</span><span class="nv">\_</span><span class="nb">u</span><span class="nv">\_</span><span class="nb">val</span><span class="o">(+</span><span class="nb">Answer,?Reason,?Type</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l2098" class="code_block">
</div><div id="l2099" class="code_block"><span class="nv">\noindent</span>
</div><div id="l2100" class="code_block"><span class="nb">can be used to query why {</span><span class="nv">\tt</span><span class="nb"> Answer} is undefined.  {</span><span class="nv">\tt</span><span class="nb"> Reason} may</span>
</div><div id="l2101" class="code_block"><span class="nb">be either {</span><span class="nv">\tt</span><span class="nb"> bounded</span><span class="nv">\_</span><span class="nb">rationality} or {</span><span class="nv">\tt</span><span class="nb"> negative</span><span class="nv">\_</span><span class="nb">loops}.  {</span><span class="nv">\tt</span>
</div><div id="l2102" class="code_block"><span class="nb">  Type} may be either {</span><span class="nv">\tt</span><span class="nb"> direct} or {</span><span class="nv">\tt</span><span class="nb"> indirect}.  {</span><span class="nv">\tt</span>
</div><div id="l2103" class="code_block"><span class="nb">  bounded</span><span class="nv">\_</span><span class="nb">rationality} is considered direct if {</span><span class="nv">\tt</span><span class="nb"> Answer} itself</span>
</div><div id="l2104" class="code_block"><span class="nb">has been abstracted; otherwise it is indirect.  {</span><span class="nv">\tt</span><span class="nb"> negative</span><span class="nv">\_</span><span class="nb">loops}</span>
</div><div id="l2105" class="code_block"><span class="nb">is considered direct if {</span><span class="nv">\tt</span><span class="nb"> Answer} is involved in a loop through</span>
</div><div id="l2106" class="code_block"><span class="nb">negation based on delay dependencies; otherwise it is considered</span>
</div><div id="l2107" class="code_block"><span class="nb">direct.  Thus, the predicate may succeed for more than one reason, but</span>
</div><div id="l2108" class="code_block"><span class="nb">for each reason there is at most one type,</span>
</div><div id="l2109" class="code_block">
</div><div id="l2110" class="code_block"><span class="nv">\begin</span><span class="nb">{example} </span><span class="nv">\rm</span>
</div><div id="l2111" class="code_block"><span class="nb">After executing the query {</span><span class="nv">\tt</span><span class="nb"> m} to the program</span>
</div><div id="l2112" class="code_block"><span class="c">%</span>
</div><div id="l2113" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2114" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> table m</span><span class="o">/</span><span class="m">0</span><span class="nb">, p</span><span class="o">/</span><span class="m">0</span><span class="nb">, q</span><span class="o">/</span><span class="m">0</span><span class="nb">, r</span><span class="o">/</span><span class="m">0</span><span class="nb">, s</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l2115" class="code_block"><span class="nb">m:</span><span class="o">-</span><span class="nb"> p.</span>
</div><div id="l2116" class="code_block">
</div><div id="l2117" class="code_block"><span class="nb">p:</span><span class="o">-</span><span class="nb"> q,tnot p.                 p:</span><span class="o">-</span><span class="nb"> s</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="m">0</span><span class="o">)))))</span><span class="nb">.</span>
</div><div id="l2118" class="code_block">
</div><div id="l2119" class="code_block"><span class="nb">q:</span><span class="o">-</span><span class="nb"> tnot r.                   r:</span><span class="o">-</span><span class="nb"> tnot q.</span>
</div><div id="l2120" class="code_block">
</div><div id="l2121" class="code_block"><span class="nb">s</span><span class="o">(</span><span class="nb">f</span><span class="o">(</span><span class="nb">X</span><span class="o">))</span><span class="nb">:</span><span class="o">-</span><span class="nb"> s</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.               s</span><span class="o">(</span><span class="m">0</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2122" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2123" class="code_block"><span class="c">%</span>
</div><div id="l2124" class="code_block"><span class="nb">where the bounded rationality depth has been set to </span><span class="m">3</span><span class="nb">.  the query {</span><span class="nv">\tt</span>
</div><div id="l2125" class="code_block"><span class="nb"> explain</span><span class="nv">\_</span><span class="nb">u</span><span class="nv">\_</span><span class="nb">value</span><span class="o">(</span><span class="nb">p,Reason,Type</span><span class="o">)</span><span class="nb">} will bind {</span><span class="nv">\tt</span><span class="nb"> Reason} to {</span><span class="nv">\tt</span>
</div><div id="l2126" class="code_block"><span class="nb"> negative</span><span class="nv">\_</span><span class="nb">loops} and {</span><span class="nv">\tt</span><span class="nb"> Type} to {</span><span class="nv">\tt</span><span class="nb"> direct} and also {</span><span class="nv">\tt</span><span class="nb"> Reason}</span>
</div><div id="l2127" class="code_block"><span class="nb"> to {</span><span class="nv">\tt</span><span class="nb"> bounded</span><span class="nv">\_</span><span class="nb">rationality} and {</span><span class="nv">\tt</span><span class="nb"> Type} to {</span><span class="nv">\tt</span><span class="nb"> indirect}.  Note</span>
</div><div id="l2128" class="code_block"><span class="nb"> that {</span><span class="nv">\tt</span><span class="nb"> p} also indirectly depends on {</span><span class="nv">\tt</span><span class="nb"> q} which is itself</span>
</div><div id="l2129" class="code_block"><span class="nb"> involved in a loop through negation.</span>
</div><div id="l2130" class="code_block"><span class="nv">\end</span><span class="nb">{example}</span>
</div><div id="l2131" class="code_block">
</div><div id="l2132" class="code_block"><span class="nv">\subsubsection</span><span class="nb">{Using Bounded Rationality}</span>
</div><div id="l2133" class="code_block"><span class="c">%</span>
</div><div id="l2134" class="code_block"><span class="nb">Bounded rationality is currently implemented only for tabling with</span>
</div><div id="l2135" class="code_block"><span class="nb">call variance, and lists are not currently included in the depth</span>
</div><div id="l2136" class="code_block"><span class="nb">check.  At this point bounded rationality is only settable globally,</span>
</div><div id="l2137" class="code_block"><span class="nb">and not on a predicate</span><span class="o">-</span><span class="nb">by</span><span class="o">-</span><span class="nb">predicate basis.</span>
</div><div id="l2138" class="code_block">
</div><div id="l2139" class="code_block"><span class="nv">\index</span><span class="nb">{Prolog flags</span><span class="o">!</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">action}}</span>
</div><div id="l2140" class="code_block"><span class="nv">\index</span><span class="nb">{Prolog flags</span><span class="o">!</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">depth}}</span>
</div><div id="l2141" class="code_block"><span class="c">%</span>
</div><div id="l2142" class="code_block"><span class="nb">Unless otherwise specified, XSB starts up with {</span><span class="nv">\tt</span>
</div><div id="l2143" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">action} and {</span><span class="nv">\tt</span>
</div><div id="l2144" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">list</span><span class="nv">\_</span><span class="nb">action} set to {</span><span class="nv">\tt</span><span class="nb"> error} and {</span><span class="nv">\tt</span>
</div><div id="l2145" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">depth} and {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">depth} set</span>
</div><div id="l2146" class="code_block"><span class="nb">to the maximum integer possible under the compilation method for which</span>
</div><div id="l2147" class="code_block"><span class="nb">XSB has been configured.  Under this default behavior, XSB will throw</span>
</div><div id="l2148" class="code_block"><span class="nb">an error if a subgoal has depth greater than {</span><span class="nv">\tt</span>
</div><div id="l2149" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">subgoal</span><span class="nv">\_</span><span class="nb">depth}.  Bounded rationality can be declared by</span>
</div><div id="l2150" class="code_block"><span class="nb">setting the Prolog flags</span>
</div><div id="l2151" class="code_block"><span class="c">%</span>
</div><div id="l2152" class="code_block"><span class="nv">\bi</span>
</div><div id="l2153" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">depth} to the desired maximal depth; and</span>
</div><div id="l2154" class="code_block"><span class="nv">\item</span><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">action} to {</span><span class="nv">\tt</span><span class="nb"> bounded</span><span class="nv">\_</span><span class="nb">rationality}.  </span>
</div><div id="l2155" class="code_block"><span class="nv">\ei</span>
</div><div id="l2156" class="code_block"><span class="c">%</span>
</div><div id="l2157" class="code_block"><span class="o">(</span><span class="nb">cf. pg. </span><span class="nv">\pageref</span><span class="nb">{prolog</span><span class="o">-</span><span class="nb">flags}</span><span class="o">)</span><span class="nb">. {</span><span class="nv">\tt</span><span class="nb"> bounded</span><span class="nv">\_</span><span class="nb">rationality} is not</span>
</div><div id="l2158" class="code_block"><span class="nb">currently an accepted value for the flag {</span><span class="nv">\tt</span>
</div><div id="l2159" class="code_block"><span class="nb">  max</span><span class="nv">\_</span><span class="nb">table</span><span class="nv">\_</span><span class="nb">answer</span><span class="nv">\_</span><span class="nb">list</span><span class="nv">\_</span><span class="nb">action}.</span>
</div><div id="l2160" class="code_block">
</div><div id="l2161" class="code_block"><span class="c">%\subsection{Summary of Techniques for Termination}</span>
</div><div id="l2162" class="code_block"><span class="c">%</span>
</div><div id="l2163" class="code_block"><span class="c">%%Apart from these two cases, a tabled evaluation will be finite and so</span>
</div><div id="l2164" class="code_block"><span class="c">%will terminate.  Of course this is a theoretical argument, and</span>
</div><div id="l2165" class="code_block"><span class="c">%termination could require a long time or a lot of memory.  For normal</span>
</div><div id="l2166" class="code_block"><span class="c">%programs, the causes of non-termination turn out to be basically the</span>
</div><div id="l2167" class="code_block"><span class="c">%same as for definite programs.  The causes of non-termination for</span>
</div><div id="l2168" class="code_block"><span class="c">%programs that contain arithmetic builtins are more complex, and may</span>
</div><div id="l2169" class="code_block"><span class="c">%depend on the behavior of the constraint domain used.</span>
</div><div id="l2170" class="code_block">
</div><div id="l2171" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l2172" class="code_block"><span class="nv">\input</span><span class="nb">{incr_tabling}</span>
</div><div id="l2173" class="code_block"><span class="c">%--------------------------------------------------------------------</span>
</div><div id="l2174" class="code_block">
</div><div id="l2175" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call subsumption}</span>
</div><div id="l2176" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">call variance}</span>
</div><div id="l2177" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">answer subsumption}</span>
</div><div id="l2178" class="code_block"><span class="nv">\index</span><span class="nb">{tabling</span><span class="o">!</span><span class="nb">incremental}</span>
</div><div id="l2179" class="code_block">
</div><div id="l2180" class="code_block"><span class="nv">\section</span><span class="nb">{Compatability of Tabling Modes and Predicate Attributes}</span>
</div><div id="l2181" class="code_block"><span class="c">%</span>
</div><div id="l2182" class="code_block"><span class="nb">As discussed in this chapter, there are several choices for how to</span>
</div><div id="l2183" class="code_block"><span class="nb">table a predicate. Either call subsumption or call variance may be</span>
</div><div id="l2184" class="code_block"><span class="nb">used, incremental tabling might or might not be used, and answer</span>
</div><div id="l2185" class="code_block"><span class="nb">subsumption might or might not be used.  Furthermore, a tabled</span>
</div><div id="l2186" class="code_block"><span class="nb">predicate, like any other predicate, may be static or dynamic and</span>
</div><div id="l2187" class="code_block"><span class="nb">thread shared or thread private.  Together, there are </span><span class="m">48</span><span class="nb"> different</span>
</div><div id="l2188" class="code_block"><span class="nb">combinations, not all of which are supported in </span><span class="nv">\version\</span><span class="nb"> of XSB.  To</span>
</div><div id="l2189" class="code_block"><span class="nb">analyze further, all combinations are supported for call</span><span class="o">-</span><span class="nb">variance and</span>
</div><div id="l2190" class="code_block"><span class="nb">for thread private predicates.  However, call subsumption has not been</span>
</div><div id="l2191" class="code_block"><span class="nb">fully integrated with dynamic code or thread shared predicates, and</span>
</div><div id="l2192" class="code_block"><span class="nb">cannot currently be combined with incremental tabling or with answer</span>
</div><div id="l2193" class="code_block"><span class="nb">subumption.  Similarly incremental tabling is not yet supported in the</span>
</div><div id="l2194" class="code_block"><span class="nb">multi</span><span class="o">-</span><span class="nb">threaded engine </span><span class="o">(</span><span class="nb">it is supported for ``thread private&#39;&#39;</span>
</div><div id="l2195" class="code_block"><span class="nb">computations only in the sequential engine</span><span class="o">)</span><span class="nb">.  The compatabilities are</span>
</div><div id="l2196" class="code_block"><span class="nb">listed in Table~</span><span class="nv">\ref</span><span class="nb">{table:table}.  Further combinations will be</span>
</div><div id="l2197" class="code_block"><span class="nb">supported in future versions of XSB as resources allow.</span>
</div><div id="l2198" class="code_block">
</div><div id="l2199" class="code_block"><span class="nb">The combinations in Table~</span><span class="nv">\ref</span><span class="nb">{table:table} allow full well</span><span class="o">-</span><span class="nb">founded</span>
</div><div id="l2200" class="code_block"><span class="nb">computation, constrained variables in calls and answers </span><span class="o">(</span><span class="nb">including the</span>
</div><div id="l2201" class="code_block"><span class="nb">residual program</span><span class="o">)</span><span class="nb">, and safe space reclamation, with the following</span>
</div><div id="l2202" class="code_block"><span class="nb">exceptions.  Answer subsumption does support non lrd</span><span class="o">-</span><span class="nb">stratified</span>
</div><div id="l2203" class="code_block"><span class="nb">programs; and call subsumption does not yet support attributed</span>
</div><div id="l2204" class="code_block"><span class="nb">variables in calls.  </span><span class="nv">\index</span><span class="nb">{attributed variables}</span>
</div><div id="l2205" class="code_block">
</div><div id="l2206" class="code_block"><span class="nv">\begin</span><span class="nb">{table}</span>
</div><div id="l2207" class="code_block"><span class="nv">\begin</span><span class="nb">{center}</span>
</div><div id="l2208" class="code_block"><span class="nb">{</span><span class="nv">\small</span>
</div><div id="l2209" class="code_block"><span class="nv">\begin</span><span class="nb">{tabular}{llllll}</span><span class="nv">\hline</span><span class="nb"> </span><span class="nv">\hline</span>
</div><div id="l2210" class="code_block"><span class="c">%variant/subsumptive &amp; dynamic/static &amp; shared/private &amp; incremental/opaque  &amp; answer subsumption  \\</span>
</div><div id="l2211" class="code_block"><span class="nb">variant &amp;	    static &amp; 	   private &amp;	  nonincremental &amp;      no answer subsumption  &amp;  yes </span><span class="nv">\\</span>
</div><div id="l2212" class="code_block"><span class="nb">variant &amp;	    static &amp;	   private &amp;	  nonincremental &amp;      answer subsumption     &amp;  yes </span><span class="nv">\\</span>
</div><div id="l2213" class="code_block"><span class="nb">variant	&amp;	    static &amp;	   private &amp;      opaque &amp;             no answer subsumption  &amp;  yes </span><span class="nv">\\</span>
</div><div id="l2214" class="code_block"><span class="nb">variant &amp;	    static &amp;	   private &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2215" class="code_block"><span class="nb">variant &amp;	    static &amp;	   private &amp;	  incremental &amp;         no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2216" class="code_block"><span class="nb">variant &amp;	    static &amp;	   private &amp;      incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2217" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  nonincremental &amp;      no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2218" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  nonincremental &amp;      answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2219" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2220" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2221" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  incremental &amp;       no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2222" class="code_block"><span class="nb">variant &amp;	    static &amp;	   shared &amp;	  incremental &amp;          answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2223" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  nonincremental &amp;      no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2224" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  nonincremental &amp;      answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2225" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2226" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2227" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  incremental &amp;         no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2228" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   private &amp;	  incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2229" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  nonincremental &amp;      no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2230" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  nonincremental &amp;      answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2231" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2232" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2233" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  incremental &amp;         no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2234" class="code_block"><span class="nb">variant &amp;	    dynamic &amp;	   shared &amp;	  incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2235" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  nonincremental &amp;      no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2236" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  nonincremental &amp;      answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2237" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2238" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2239" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  incremental &amp;         no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2240" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   private &amp;	  incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2241" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  nonincremental &amp;      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2242" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  nonincremental &amp;      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2243" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2244" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2245" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  incremental &amp;       no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2246" class="code_block"><span class="nb">subsumptive &amp;	    static &amp;	   shared &amp;	  incremental &amp;          answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2247" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;	  nonincremental &amp;      no answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2248" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;	  nonincremental &amp;      answer subsumption &amp;	yes </span><span class="nv">\\</span>
</div><div id="l2249" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2250" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2251" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;	  incremental &amp;         no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2252" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   private &amp;   	  incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2253" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   shared &amp;	  nonincremental &amp;      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2254" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   shared &amp;	  nonincremental &amp;      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2255" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   shared &amp;	  opaque &amp;	      no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2256" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   shared &amp;	  opaque &amp;	      answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2257" class="code_block"><span class="nb">subsumptive &amp;	    dynamic &amp;	   shared &amp;	  incremental &amp;         no answer subsumption &amp;	no </span><span class="nv">\\</span>
</div><div id="l2258" class="code_block"><span class="nb">subsumptive &amp;  	    dynamic &amp;	   shared &amp;	  incremental &amp;         answer subsumption &amp;	no </span><span class="nv">\\</span><span class="nb"> </span><span class="nv">\hline</span><span class="nb"> </span><span class="nv">\hline</span><span class="nb"> </span>
</div><div id="l2259" class="code_block"><span class="nv">\end</span><span class="nb">{tabular}</span>
</div><div id="l2260" class="code_block"><span class="nb">}</span>
</div><div id="l2261" class="code_block"><span class="nv">\end</span><span class="nb">{center}</span>
</div><div id="l2262" class="code_block"><span class="nv">\caption</span><span class="nb">{Support for different tabling modes in XSB </span><span class="nv">\version</span><span class="nb">}</span>
</div><div id="l2263" class="code_block"><span class="nv">\label</span><span class="nb">{table:table}</span>
</div><div id="l2264" class="code_block"><span class="nv">\end</span><span class="nb">{table}</span>
</div></pre></div></td></tr></table></div>

      
    </div>
  

                    </div>
                    
                    
                </div>
            



        </div>
    </section>
      

    <footer class="sandiego">
    <div class="as-row">
        <div class="footer-wrapper">
            <nav aria-label="Site Links" role="navigation">
                <section>
                    <div class="as-h2">SourceForge</div>
                    <ul>
                    
                        <li><a href="/create/" title="Create a Project">Create a Project</a></li>
                    
                        <li><a href="/directory/" title="Open Source Software Directory">Open Source Software</a></li>
                        <li><a href="/software/" title="Business Software Directory">Business Software</a></li>
                        
                            
                            <li><a href="/top" title="Top Open Source Projects">Top Downloaded Projects</a></li>
                        

                    </ul>
                </section>
            </nav>
            <nav aria-label="Company Links" role="navigation">
                <section>
                    <div class="as-h2">Company</div>
                    <ul>
                        <li><a href="/about">About</a></li>
                        <li><a href="/about/leadership" title="Open Source Software Directory">Team</a></li>
                        <li class="h-card">
                            <address>
                                <span class="p-name p-org">SourceForge Headquarters</span><br>
                                <span class="p-street-address">225 Broadway Suite 1600</span><br>
                                <span class="p-locality">San Diego, CA <span class="p-postal-code">92101</span></span><br>
                                <span class="p-tel">+1 (858) 422-6466</span><br>
                            </address>
                        </li>
                        <li id="social">
                            
<span></span>
<a href="https://twitter.com/sourceforge" class="twitter" rel="nofollow" target="_blank" title="SourceForge on X">


<svg  class="vertical-icon-fix" data-name="twitter" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1684 408q-67 98-162 167 1 14 1 42 0 130-38 259.5t-115.5 248.5-184.5 210.5-258 146-323 54.5q-271 0-496-145 35 4 78 4 225 0 401-138-105-2-188-64.5t-114-159.5q33 5 61 5 43 0 85-11-112-23-185.5-111.5t-73.5-205.5v-4q68 38 146 41-66-44-105-115t-39-154q0-88 44-163 121 149 294.5 238.5t371.5 99.5q-8-38-8-74 0-134 94.5-228.5t228.5-94.5q140 0 236 102 109-21 205-78-37 115-142 178 93-10 186-50z"/></svg></a>
<a href="https://fosstodon.org/@sourceforge" rel="me nofollow" target="_blank" title="SourceForge on Mastodon">


<svg  class="vertical-icon-fix" data-name="mastodon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M433 179.11c0-97.2-63.71-125.7-63.71-125.7-62.52-28.7-228.56-28.4-290.48 0 0 0-63.72 28.5-63.72 125.7 0 115.7-6.6 259.4 105.63 289.1 40.51 10.7 75.32 13 103.33 11.4 50.81-2.8 79.32-18.1 79.32-18.1l-1.7-36.9s-36.31 11.4-77.12 10.1c-40.41-1.4-83-4.4-89.63-54a102.54 102.54 0 0 1-.9-13.9c85.63 20.9 158.65 9.1 178.75 6.7 56.12-6.7 105-41.3 111.23-72.9 9.8-49.8 9-121.5 9-121.5zm-75.12 125.2h-46.63v-114.2c0-49.7-64-51.6-64 6.9v62.5h-46.33V197c0-58.5-64-56.6-64-6.9v114.2H90.19c0-122.1-5.2-147.9 18.41-175 25.9-28.9 79.82-30.8 103.83 6.1l11.6 19.5 11.6-19.5c24.11-37.1 78.12-34.8 103.83-6.1 23.71 27.3 18.4 53 18.4 175z"/></svg></a>
<a href="https://www.facebook.com/sourceforgenet/" class="facebook" rel="nofollow" target="_blank" title="SourceForge on Facebook">


<svg  data-name="facebook" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1343 12v264h-157q-86 0-116 36t-30 108v189h293l-39 296h-254v759h-306v-759h-255v-296h255v-218q0-186 104-288.5t277-102.5q147 0 228 12z"/></svg></a>
<a href="https://www.linkedin.com/company/sourceforge.net" class="linkedin" rel="nofollow" target="_blank" title="SourceForge on LinkedIn">


<svg  data-name="linkedin" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M477 625v991h-330v-991h330zm21-306q1 73-50.5 122t-135.5 49h-2q-82 0-132-49t-50-122q0-74 51.5-122.5t134.5-48.5 133 48.5 51 122.5zm1166 729v568h-329v-530q0-105-40.5-164.5t-126.5-59.5q-63 0-105.5 34.5t-63.5 85.5q-11 30-11 81v553h-329q2-399 2-647t-1-296l-1-48h329v144h-2q20-32 41-56t56.5-52 87-43.5 114.5-15.5q171 0 275 113.5t104 332.5z"/></svg></a>

<a href="/user/newsletters" rel=nofollow class="newsletter" title="Subscribe to our newsletter">


<svg  class="vertical-icon-fix" data-name="mmSF_11mail" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 42 42" enable-background="new 0 0 42 42" xml:space="preserve"><path fill="#FFFFFF" d="M0,6v30h42V6H0z M24.2,21.2c-0.8,0.8-2.3,2-3.2,2c-0.9,0-2.4-1.2-3.2-2L5.8,9.7h30.3L24.2,21.2z M13.7,21l-9.9,9.4V11.6L13.7,21z M15.7,23L15.7,23c0.5,0.5,2.9,2.9,5.3,2.9c2.4,0,4.8-2.4,5.2-2.8l0.1-0.1l9.8,9.4H5.8L15.7,23z M28.3,21l9.9-9.5v18.9L28.3,21z"/></svg></a>

<span></span>
                        </li>
                    </ul>
                </section>
            </nav>
             <nav aria-label="Resources Links" role="navigation">
                <section>
                    <div class="as-h2">Resources</div>
                    <ul>
                        
                            <li><a href="/support" title="Support Section">Support</a></li>
                            <li><a href="/p/forge/documentation/Docs%20Home/" title="Site Documentation">Site Documentation</a></li>
                        
                        <li><a href="https://fosstodon.org/@sourceforgestatus" title="Site Status" rel="me nofollow">Site Status</a></li>
                        <li><a href="/reviews" title="Reviews" rel="me nofollow">SourceForge Reviews</a></li>

                    </ul>
                </section>
            </nav>
            <section class="footer-logo">
                <a href="/" title="Home" class="sf-logo">
                    
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
                </a>
            </section>
        </div>
    </div>
    <section class="l-nav-bottom">
        <nav class="row">
            
                
            
        
    <div class="columns small-12 large-6 copyright-notice">
        &copy; 2025 Slashdot Media. All Rights Reserved.
    </div>
    <div class="columns large-6 links links-right">
        

    
    

    <a href="https://slashdotmedia.com/terms-of-use" target="_blank" title="Terms" rel="nofollow">Terms</a>
    <a href="https://slashdotmedia.com/privacy-statement/" target="_blank" title="Privacy" rel="nofollow">Privacy</a>

    
    
    

    
        <a href="https://slashdotmedia.com/opt-out-choices/" target="_blank" title="Opt Out" rel="nofollow">Opt Out</a>
    

    
        <a href="https://slashdotmedia.com/contact/" target="_blank" title="Advertise" rel="nofollow">Advertise</a>
    
    </div>
        </nav>
    </section>

    </footer>
    





    
    
    <div id="newsletter-floating" class="sandiego newsletter-floating-new">
        <a class="close-button btn-closer" data-close aria-label="Close modal">
            <span aria-hidden="true">&times;</span>
        </a>
        <div class="as-h2">Want the latest updates on software, tech news, and AI?</div>
        <div class="row">
            <div class="column small-2 medium-2 large-2" style="padding-left: 0px; padding-right: 0px;"><img src="/images/sandiego/sf_email_icon.svg"  alt="" /></div>
            <div class="as-h3 column small-10 medium-10 large-10">Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.</div>
        </div>
        <form action="/user/newsletters/" method="post">
            <div class="row">
              <input class="newsletter-input" type="email" placeholder="Enter your email address" autocomplete="off" name="newsletter_email"
                     value="">
              <input type="hidden" name="source" value="floating">
              <button type="submit" class="button blue newsletter-button">Submit</button>
            </div>
        </form>
    </div>
    






</div>


<div id="messages">
    
</div>


    <!-- ew:body_js -->


    <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1753456284/_ew_/_slim/js?href=allura%2Fjs%2Fjquery.notify.js%3Ballura%2Fjs%2Fjquery.tooltipster.js%3Ballura%2Fjs%2Fallura-base.js%3Ballura%2Fjs%2Fchecklist.js%3Ballura%2Fjs%2Fadmin_modal.js%3Bjs%2Fjquery.lightbox_me.js%3Ballura%2Fjs%2Fmemorable.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fshared.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsticky.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Fchrome.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Futilities.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.core.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.mediaQuery.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.keyboard.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.box.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.nest.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.dropdownMenu.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.offcanvas.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.toggler.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Fproject.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Fjquery.typeahead.min.js%3Ballura%2Fjs%2Fmaximize-content.js"></script>

    
<!-- /ew:body_js -->



    <!-- ew:body_js_tail -->


    <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1753456284/_ew_/_slim/js?href=theme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.triggers.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.reveal.min.js"></script>

    
<!-- /ew:body_js_tail -->




<script type="text/javascript">(function() {
  $('#access_urls .btn').click(function(evt){
    evt.preventDefault();
    var parent = $(this).parents('.btn-bar');
    var checkout_cmd = $(this).attr('data-url');
    $(parent).find('input').val(checkout_cmd);
    $(parent).find('span').text($(this).attr('title')+' access');
    $(this).parent().children('.btn').removeClass('active');
    $(this).addClass('active');
    if (checkout_cmd.indexOf(' http://') !== -1 || checkout_cmd.indexOf(' https://') !== -1 ) {
      $('#http-2fa-msg').show();
    } else {
      $('#http-2fa-msg').hide();
    }
  });
  $('#access_urls .btn').first().click();

  
  var repo_status = document.getElementById('repo_status');
  // The repo_status div will only be present if repo.status != 'ready'
  if (repo_status) {
    $('.spinner').show()
    var delay = 500;
    function check_status() {
        $.get('/p/xsb/src/status', function(data) {
            if (data.status === 'ready') {
                $('.spinner').hide()
                $('#repo_status h2').html('Repo status: ready. <a href="." rel="nofollow">Click here to refresh this page.</a>');
            }
            else {
                $('#repo_status h2 span').html(data.status);
                if (delay < 60000){
                    delay = delay * 2;
                }
                window.setTimeout(check_status, delay);
            }
        });
    }
    var status_checker = window.setTimeout(check_status, delay);
    
  }
}());
</script>

<script type="text/javascript">(function() {
  $(window).on('hashchange', function(e) {
    var hash = window.location.hash.substring(1);
    if ('originalEvent' in e && 'oldURL' in e.originalEvent) {
      $('#' + e.originalEvent.oldURL.split('#')[1]).css('background-color', 'transparent');
    }
    if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
      $('#' + hash).css('background-color', '#ffff99');
    }
  }).trigger('hashchange');

  var clicks = 0;
  $('.code_block').each(function(index, element) {
    $(element).on('click', function() {
      // Trick to ignore double and triple clicks
      clicks++;
      if (clicks === 1) {
        setTimeout(function() {
          if (clicks === 1) {
            var hash = window.location.hash.substring(1);
            if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
              $('#' + hash).css('background-color', 'transparent');
            }
            $(element).css('background-color', '#ffff99');
            window.history.pushState({}, document.title, window.location.pathname + window.location.search + '#' + $(element).attr('id'));
          }
          clicks = 0;
        }, 500);
      }
    });
  });
}());
</script>


    


    
    
    <noscript><p><img src="https://analytics.slashdotmedia.com/index.php?idsite=39" style="border:0;position:absolute;top:0;" alt="" /></p></noscript>
    
    <script>
        $(document).foundation();
    </script>
    








    

<script>
    (function () {
        function load_bombora() {
            /*global _ml:true, window */
            _ml = window._ml || {};
            
            _ml.eid = '771';
            _ml.fp = '8e037856-8140-4387-a5a5-957978b7a356';  
            var s = document.getElementsByTagName('script')[0], cd = new Date(), mltag = document.createElement('script');
            mltag.type = 'text/javascript';
            mltag.async = true;
            mltag.defer = true;
            mltag.src = '//ml314.com/tag.aspx?' + cd.getDate() + cd.getMonth() + cd.getFullYear();
            s.parentNode.insertBefore(mltag, s);
        }
        bizx.cmp.ifConsent({ purposes: 'all', vendors: 'bombora'}, load_bombora);
    })();
</script>




<script>
    $(document).ready(function () {
        $(".tooltip, .m-tooltip").each(function(){
            let $el = $(this);
            $el.tooltipster({
                animation: 'fade',
                delay: 200,
                theme: 'tooltipster-light',
                trigger: 'hover',
                position: $el.data('position') || 'right',
                iconCloning: false,
                maxWidth: 300,
                contentAsHTML: true,
                interactive: true
            }).focus(function () {
                $(this).tooltipster('show');
            }).blur(function () {
                $(this).tooltipster('hide');
            });
        });
    });
</script>

    



<script type="text/javascript">
    bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'google-analytics'}, function () {
        /* jshint ignore:start */
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
        /* jshint ignore:end */

        window.dataLayer = window.dataLayer || [];
        function gtag(){ window.dataLayer.push(arguments); }
        window.gtag = window.gtag || gtag;
        bizx.cmp.embedScript("https://www.googletagmanager.com/gtag/js");
        gtag('js', new Date());
        gtag('set', {
            'page_location': 'https://sourceforge.net/p/xsb/src/7607/tree/trunk/XSB/docs/userman/tables.tex',
        });
    });
</script>










<script>
        function gam(id){
            bizx.cmp.ifConsent({ purposes: 'all' }, function () {
                bizx.cmp.embedScript(`https://pagead2.googlesyndication.com/pagead/js/pcd.js?${id}`,
                    true,  // async
                    'head', // location
                    null, // callback
                    false, // defer
                    {id: `google-pcd-tag-${id}`, 'data-audience-pixel': 'dc_iu=/41014381/DFPAudiencePixel;dc_seg=' + id});
            });
        }

        
            gam("8901705213");gam("8901712041");</script>

<script type="text/javascript">
    /*global ga, gtag */

    
        
        bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'google-analytics'}, function () {
            gtag('config', 'G-1H226E4E4L', {
                
                send_page_view: false,
                'SF_Page_Type': '', 
                user_properties: {
                    'SF_Logged_in': 'Logged Out', 
                },
                'devicePixelRatio': SF.devicePixelRatio, 
            });
            gtag('event', 'page_view', { send_to: 'G-1H226E4E4L' });
        });
    
    
    
        
</script>

</body>
</html>