1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*-----------------------------------------------------------------------
File : cte_lambda.h
Author: Petar Vukmirovic
Contents
Functions that implement main operations of lambda calculus
Copyright 1998-2018 by the author.
This code is released under the GNU General Public Licence and
the GNU Lesser General Public License.
See the file COPYING in the main E directory for details..
Run "eprover -h" for contact information.
Created: Wed Mar 24 15:54:00 CET 2021
-----------------------------------------------------------------------*/
#ifndef CTE_LAMBDA
#define CTE_LAMBDA
#include <ccl_tformulae.h>
#include <ccl_pdtrees.h>
#include <cte_termbanks.h>
#include <cte_subst.h>
/*---------------------------------------------------------------------*/
/* Exported Functions and Variables */
/*---------------------------------------------------------------------*/
TFormula_p NamedLambdaSNF(TB_p terms, TFormula_p t);
TFormula_p LambdaToForall(TB_p terms, TFormula_p t);
TFormula_p LiftLambdas(TB_p terms, TFormula_p t, PStack_p definitions,
PDTree_p liftings);
/*-----------------------------------------------------------------------
//
// Function: ApplyTerms()
//
// Fills var_stack with abstracted variables and returns the body of lambda
// For example, given ^[X]:(^[Y]:s), varstack = [Y, X] and s is returned
//
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static inline Term_p ApplyTerms(TB_p terms, Term_p head, PStack_p args)
{
Term_p res = head;
long len = PStackGetSP(args);
if(!PStackEmpty(args))
{
if(TermIsVar(head) || TermIsLambda(head))
{
res = TermTopAlloc(SIG_PHONY_APP_CODE, len+1);
res->args[0] = head;
for(long i=1; i<=len; i++)
{
res->args[i] = PStackElementP(args, i-1);
}
}
else
{
res = TermTopAlloc(head->f_code, head->arity + len);
for(int i=0; i<head->arity; i++)
{
res->args[i] = head->args[i];
}
for(int i=0; i < len; i++)
{
res->args[head->arity + i] = PStackElementP(args, i);
}
}
}
assert(PStackEmpty(args) || res->type == NULL); // type will be inferred and checked
return PStackEmpty(args) ? res : TBTermTopInsert(terms, res);
}
/*-----------------------------------------------------------------------
//
// Function: AbstractVars()
//
// Abstract var_prefix over matrix. Variable at the top of the stack
// is the first one to abstract. Does not change the stack.
//
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static inline Term_p AbstractVars(TB_p terms, Term_p matrix, PStack_p var_prefix)
{
int num_vars = PStackGetSP(var_prefix);
Term_p res = matrix;
while(num_vars)
{
Term_p lambda = TermTopAlloc(SIG_NAMED_LAMBDA_CODE, 2);
lambda->args[0] = PStackElementP(var_prefix, --num_vars);
lambda->args[1] = res;
res = TBTermTopInsert(terms, lambda);
}
return res;
}
/*-----------------------------------------------------------------------
//
// Function: UnfoldLambda()
//
// Fills var_stack with abstracted variables and returns the body of lambda
// For example, given ^[X]:(^[Y]:s), varstack = [Y, X] and s is returned
//
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static inline Term_p UnfoldLambda(Term_p lambda, PStack_p var_stack)
{
while(TermIsLambda(lambda))
{
PStackPushP(var_stack, lambda->args[0]);
lambda = lambda->args[1];
}
return lambda;
}
#endif
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|