From 3f0510629e422e979b57d3f93791937912a4183a 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. * Created vim files to implement syntax highlighting for configuration files. * Multiple bug fixes --- src/meantools_expand.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 src/meantools_expand.c (limited to 'src/meantools_expand.c') diff --git a/src/meantools_expand.c b/src/meantools_expand.c new file mode 100644 index 0000000..2586ff5 --- /dev/null +++ b/src/meantools_expand.c @@ -0,0 +1,166 @@ +/* +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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "meantools_expand.h" + +#include +#include +#include "cli_parser.h" +#include "parse_file.h" +#include "polynomial.h" +#include "array.h" +#include "fields.h" + + +#define CP_FLAG_NAMESPACE 1 +// read command line arguments +int tool_expand_read_args(int argc, const char* argv[], Str_Array* str_args, Meantools_Options* opts){ + // file to read the polynomial from in flow mode + const char* file=""; + // whether a file was specified on the command-line + int exists_file=0; + // flag + int flag=0; + int i; + char* ptr; + + // defaults + // no namespace + (*opts).namespace.length=-1; + + + // loop over arguments + for(i=2;inamespace)); + flag=0; + } + // read file name from command-line + else{ + file=argv[i]; + exists_file=1; + } + } + + read_config_file(str_args, file, 1-exists_file); + + return(0); +} + + +// expand a polynomial +int tool_expand(Str_Array str_args, Meantools_Options opts){ + // index of the entry in the input file + int arg_index; + // input polynomial + Polynomial polynomial; + // fields table + Fields_Table fields; + // preprocessor variables + Variables variables; + + // parse fields + if(opts.namespace.length>=0){ + arg_index=find_str_arg_ns("fields", opts.namespace, str_args); + } + else{ + arg_index=find_str_arg("fields", str_args); + } + if(arg_index<0){ + fprintf(stderr,"error: no fields entry in the configuration file\n"); + exit(-1); + } + else{ + parse_input_fields(str_args.strs[arg_index],&fields); + } + + // parse variables + // must precede id_table, virtual_fields, identities and input_polynomial + if(opts.namespace.length>=0){ + arg_index=find_str_arg_ns("preprocessor_variables", opts.namespace, str_args); + } + else{ + arg_index=find_str_arg("preprocessor_variables", str_args); + } + if(arg_index>=0){ + parse_input_variables(str_args.strs[arg_index],&variables); + } + else{ + init_Variables(&variables,1); + } + + // parse virtual_fields + if(opts.namespace.length>=0){ + arg_index=find_str_arg_ns("virtual_fields", opts.namespace, str_args); + } + else{ + arg_index=find_str_arg("virtual_fields", str_args); + } + if(arg_index>=0){ + parse_input_virtual_fields(str_args.strs[arg_index], &fields, variables); + } + + // parse identities + if(opts.namespace.length>=0){ + arg_index=find_str_arg_ns("identities", opts.namespace, str_args); + } + else{ + arg_index=find_str_arg("identities", str_args); + } + if(arg_index>=0){ + parse_input_identities(str_args.strs[arg_index],&fields, variables); + } + + // parse input polynomial + if(opts.namespace.length>=0){ + arg_index=find_str_arg_ns("input_polynomial", opts.namespace, str_args); + } + else{ + arg_index=find_str_arg("input_polynomial", str_args); + } + if(arg_index>=0){ + parse_input_polynomial(str_args.strs[arg_index], &polynomial, fields, variables); + } + else{ + fprintf(stderr,"error: no input polynomial entry in the configuration file\n"); + exit(-1); + } + + // print polynomial + polynomial_print(polynomial); + + // free memory + free_Variables(variables); + free_Fields_Table(fields); + free_Polynomial(polynomial); + + if(opts.namespace.length>=0){ + free_Char_Array(opts.namespace); + } + return(0); +} -- cgit v1.2.3-70-g09d2