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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*-----------------------------------------------------------------------
File : che_fcode_featurearrays.c
Author: Stephan Schulz
Contents
Implementation of arrays associating FunCodes and numeric features.
Copyright 1998-2020 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.
Changes
Created: Thu Feb 20 21:57:25 CET 2003
-----------------------------------------------------------------------*/
#include "che_fcode_featurearrays.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: feature_compare_function()
//
// Compare two featuresortcells and return <0, =0, >0 as for
// strcmp().
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
static int feature_compare_function(const void* e1,
const void* e2)
{
const FCodeFeatureSort_p entry1 = (const FCodeFeatureSort_p)e1;
const FCodeFeatureSort_p entry2 = (const FCodeFeatureSort_p)e2;
int res;
if((res = entry1->key0-entry2->key0))
{
return res;
}
if((res = entry1->key1-entry2->key1))
{
return res;
}
if((res = entry1->key2-entry2->key2))
{
return res;
}
if((res = entry1->key3-entry2->key3))
{
return res;
}
/* if((res = entry1->freq-entry2->freq))
{
return res;
}*/
return entry1->pos_rank-entry2->pos_rank;
}
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: FCodeFeatureArrayAlloc()
//
// Allocate an initialized FCodeFeature array.
//
// Global Variables: -
//
// Side Effects : Memory operations
//
/----------------------------------------------------------------------*/
FCodeFeatureArray_p FCodeFeatureArrayAlloc(Sig_p sig, ClauseSet_p axioms)
{
FCodeFeatureArray_p handle;
FunCode i;
long array_size = sizeof(long)*(sig->f_count+1);
long *rank_array = SizeMalloc(array_size);
long *dist_array = SizeMalloc(array_size);
long *conjdist_array = SizeMalloc(array_size);
long *axiomdist_array = SizeMalloc(array_size);
long rank = 0;
handle = FCodeFeatureArrayCellAlloc();
handle->size = sig->f_count+1;
handle->array = SizeMalloc(handle->size*sizeof(FCodeFeatureSortCell));
for(i=1; i<= sig->f_count; i++)
{
rank_array[i] = 0;
dist_array[i] = 0;
conjdist_array[i] = 0;
}
ClauseSetComputeFunctionRanks(axioms, rank_array, &rank);
ClauseSetAddSymbolDistribution(axioms, dist_array);
ClauseSetAddConjSymbolDistribution(axioms, conjdist_array);
ClauseSetAddAxiomSymbolDistribution(axioms, axiomdist_array);
for(i=1; i<= sig->f_count; i++)
{
handle->array[i].key0 = 0;
handle->array[i].key1 = 0;
handle->array[i].key2 = 0;
handle->array[i].key3 = 0;
handle->array[i].freq = dist_array[i];
handle->array[i].conjfreq = conjdist_array[i];
handle->array[i].axiomfreq = axiomdist_array[i];
handle->array[i].pos_rank = rank_array[i];
handle->array[i].symbol = i;
}
SizeFree(rank_array, array_size);
SizeFree(dist_array, array_size);
SizeFree(conjdist_array, array_size);
SizeFree(axiomdist_array, array_size);
return handle;
}
/*-----------------------------------------------------------------------
//
// Function: FCodeFeatureArrayUpdateOccKey()
//
// Update key0 based on the occurrence of the symbols in axioms,
// conjectures, or both.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
void FCodeFeatureArrayUpdateOccKey(FCodeFeatureArray_p array, OrderParms_p oparms)
{
FunCode i;
for(i=1; i< array->size; i++)
{
if(array->array[i].conjfreq)
{
if(array->array[i].axiomfreq)
{
array->array[i].key0 += oparms->conj_axiom_mod;
}
else
{
array->array[i].key0 += oparms->conj_only_mod;
}
}
else if(array->array[i].axiomfreq)
{
array->array[i].key0 += oparms->axiom_only_mod;
}
}
}
/*-----------------------------------------------------------------------
//
// Function: FCodeFeatureArrayUpdateSymbKey()
//
// Update key0 based on the occurrence of the symbols in axioms,
// conjectures, or both.
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
void FCodeFeatureArrayUpdateSymbKey(FCodeFeatureArray_p array, Sig_p sig,
OrderParms_p oparms)
{
FunCode i;
for(i=1; i< array->size; i++)
{
if(SigQueryFuncProp(sig, i, FPSkolemSymbol))
{
array->array[i].key0 += oparms->skolem_mod;
}
if(SigQueryFuncProp(sig, i, FPDefPred))
{
array->array[i].key0 += oparms->defpred_mod;
}
}
}
/*-----------------------------------------------------------------------
//
// Function: FCodeFeatureArrayFree()
//
// Free an FCodeFeatureArray.
//
// Global Variables: -
//
// Side Effects : Memory operations.
//
/----------------------------------------------------------------------*/
void FCodeFeatureArrayFree(FCodeFeatureArray_p junk)
{
SizeFree(junk->array, junk->size * sizeof(FCodeFeatureSortCell));
FCodeFeatureArrayCellFree(junk);
}
/*-----------------------------------------------------------------------
//
// Function: FCodeFeatureArraySort()
//
// Sort an array according to feature_compare_function()
//
// Global Variables: -
//
// Side Effects : Sorts the array
//
/----------------------------------------------------------------------*/
void FCodeFeatureArraySort(FCodeFeatureArray_p array)
{
qsort(&(array->array[SIG_TRUE_CODE+1]),
array->size-(SIG_TRUE_CODE+1),
sizeof(FCodeFeatureSortCell),
feature_compare_function);
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|