From 167980ea437881ec56186332370afcc169f2e4dd Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Tue, 14 Jun 2022 09:26:07 +0200 Subject: Update to v1.5. The update to version 1.5 is rather substantial, and introduces some minor backward-incompatibilities: * The header "#!symbols" has been replaced by "#!virtual_fields" * Multiplying polynomials using the '*' symbol is no longer supported (or, rather, the symbolic capabilities of meankondo were enhanced, and the syntax has been changed). * 'meantools exp' has been removed (its functionality is now handled by other means) * 'meantoolds derive' has been replaced by 'meantools differentiate' * The symbolic capabilities were enhanced: polynomials can now be multiplied, added, exponentiated, and their logarithms can be taken directly in the configuration file. * The flow equation can now be processed after being computed using the various "#!postprocess_*" entries. * Deprecated kondo_preprocess. * Compute the mean using an LU decomposition if possible. * More detailed checks for syntax errors in configuration file. * Check that different '#!group' entries are indeed uncorrelated. * New flags in meankondo: '-p' and '-A'. * New tool: meantools expand. * Improve conversion to LaTeX using meantools-convert * Assign terms randomly to different threads. * Multiple bug fixes --- src/fields.c | 273 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 229 insertions(+), 44 deletions(-) (limited to 'src/fields.c') diff --git a/src/fields.c b/src/fields.c index bfd1f39..7be84df 100644 --- a/src/fields.c +++ b/src/fields.c @@ -1,5 +1,5 @@ /* -Copyright 2015 Ian Jauslin +Copyright 2015-2022 Ian Jauslin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,6 +23,13 @@ limitations under the License. #include "polynomial.h" #include "array.h" #include "rational.h" +#include "tree.h" + +//--------------------------------------------------------------------- +// +// Fields_Table +// +//--------------------------------------------------------------------- // init and free for Fields_Table int init_Fields_Table(Fields_Table* fields){ @@ -30,7 +37,7 @@ int init_Fields_Table(Fields_Table* fields){ init_Int_Array(&((*fields).external),FIELDS_SIZE); init_Int_Array(&((*fields).internal),FIELDS_SIZE); init_Identities(&((*fields).ids), FIELDS_SIZE); - init_Symbols(&((*fields).symbols), FIELDS_SIZE); + init_Virtual_fields(&((*fields).virtual_fields), FIELDS_SIZE); init_Int_Array(&((*fields).fermions),FIELDS_SIZE); init_Int_Array(&((*fields).noncommuting),FIELDS_SIZE); return(0); @@ -40,7 +47,7 @@ int free_Fields_Table(Fields_Table fields){ free_Int_Array(fields.external); free_Int_Array(fields.internal); free_Identities(fields.ids); - free_Symbols(fields.symbols); + free_Virtual_fields(fields.virtual_fields); free_Int_Array(fields.fermions); free_Int_Array(fields.noncommuting); return(0); @@ -57,11 +64,11 @@ int field_type(int index, Fields_Table fields){ else if(int_array_find(abs(index), fields.internal)>=0){ return(FIELD_INTERNAL); } - else if(intlist_find(fields.symbols.indices, fields.symbols.length, index)>=0){ - return(FIELD_SYMBOL); + else if(intlist_find(fields.virtual_fields.indices, fields.virtual_fields.length, index)>=0){ + return(FIELD_VIRTUAL); } - fprintf(stderr,"error: index %d is neither a parameter nor an external or an internal field, nor a symbol\n",index); + fprintf(stderr,"error: index %d is neither a parameter nor an external or an internal field, nor a virtual field\n",index); exit(-1); } @@ -86,7 +93,11 @@ int is_noncommuting(int index, Fields_Table fields){ } -// ------------------ Identities -------------------- +//--------------------------------------------------------------------- +// +// Identities +// +//--------------------------------------------------------------------- // allocate memory int init_Identities(Identities* identities,int size){ @@ -314,6 +325,11 @@ int int_array_is_subarray_noncommuting(Int_Array input, Int_Array test_array, Fi int match_nc; int first=-1; + // cannot fit + if(test_array.length=test_array.length || test_array.values[i+j]!=input.values[j]){ match_nc=0; } } @@ -359,57 +375,61 @@ int int_array_is_subarray_noncommuting(Int_Array input, Int_Array test_array, Fi } -// ------------------ Symbols -------------------- +//--------------------------------------------------------------------- +// +// Virtual_fields +// +//--------------------------------------------------------------------- // allocate memory -int init_Symbols(Symbols* symbols,int size){ - (*symbols).indices=calloc(size,sizeof(int)); - (*symbols).expr=calloc(size,sizeof(Polynomial)); - (*symbols).length=0; - (*symbols).memory=size; +int init_Virtual_fields(Virtual_fields* virtual_fields,int size){ + (*virtual_fields).indices=calloc(size,sizeof(int)); + (*virtual_fields).expr=calloc(size,sizeof(Polynomial)); + (*virtual_fields).length=0; + (*virtual_fields).memory=size; return(0); } // free memory -int free_Symbols(Symbols symbols){ +int free_Virtual_fields(Virtual_fields virtual_fields){ int i; - for(i=0;i=(*output).memory){ - resize_symbols(output,2*(*output).memory+1); + resize_virtual_fields(output,2*(*output).memory+1); } // copy and allocate @@ -436,12 +456,12 @@ int symbols_append(int index, Polynomial expr, Symbols* output){ (*output).length++; return(0); } -// append an element to a symbols without allocating memory -int symbols_append_noinit(int index, Polynomial expr, Symbols* output){ +// append an element to a virtual_fields without allocating memory +int virtual_fields_append_noinit(int index, Polynomial expr, Virtual_fields* output){ int offset=(*output).length; if((*output).length>=(*output).memory){ - resize_symbols(output,2*(*output).memory+1); + resize_virtual_fields(output,2*(*output).memory+1); } // copy without allocating @@ -452,18 +472,22 @@ int symbols_append_noinit(int index, Polynomial expr, Symbols* output){ return(0); } -// concatenate two symbolss -int symbols_concat(Symbols input, Symbols* output){ +// concatenate two virtual_fields +int virtual_fields_concat(Virtual_fields input, Virtual_fields* output){ int i; for(i=0;i=(*output).memory){ + resize_variables(output,2*(*output).memory+1); + } + + // copy and allocate + char_array_cpy(var_name,(*output).var_names+offset); + tree_cpy(symbol_tree,(*output).symbol_trees+offset); + // increment length + (*output).length++; + return(0); +} +// append an element to a variables collection without allocating memory +int variables_append_noinit(Char_Array var_name, Tree symbol_tree, Variables* output){ + int offset=(*output).length; + + if((*output).length>=(*output).memory){ + resize_variables(output,2*(*output).memory+1); + } + + // copy without allocating + (*output).var_names[offset]=var_name; + (*output).symbol_trees[offset]=symbol_tree; + // increment length + (*output).length++; + return(0); +} + +// concatenate two variables collections +int variables_concat(Variables input, Variables* output){ + int i; + for(i=0;i