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
This commit is contained in:
Ian Jauslin 2022-06-14 09:26:07 +02:00
parent 469bdc8071
commit 3f0510629e
73 changed files with 3510 additions and 852 deletions

View File

@ -1,3 +1,42 @@
1.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
1.4: 1.4:
* Support MPFR floats in numkondo. * Support MPFR floats in numkondo.

View File

@ -1,4 +1,4 @@
## Copyright 2015 Ian Jauslin ## Copyright 2015-2022 Ian Jauslin
## ##
## Licensed under the Apache License, Version 2.0 (the "License"); ## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License. ## you may not use this file except in compliance with the License.
@ -62,10 +62,10 @@ SRCDIR=./src
OBJDIR=./objs OBJDIR=./objs
# objects # objects
LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o rcc_mpfr.o tools.o) LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o rcc_mpfr.o symbolic_parser.o tree.o tools.o)
MEANKONDO_OBJS = $(addprefix $(OBJDIR)/,meankondo.o mean.o) MEANKONDO_OBJS = $(addprefix $(OBJDIR)/,meankondo.o determinant.o mean.o)
NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o flow_mpfr.o) NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o flow_mpfr.o)
MEANTOOLS_OBJS = $(addprefix $(OBJDIR)/,meantools.o meantools_exp.o meantools_deriv.o meantools_eval.o) MEANTOOLS_OBJS = $(addprefix $(OBJDIR)/,meantools.o meantools_deriv.o meantools_eval.o meantools_expand.o)
KONDO_PP_OBJS = $(addprefix $(OBJDIR)/,kondo_preprocess.o kondo.o) KONDO_PP_OBJS = $(addprefix $(OBJDIR)/,kondo_preprocess.o kondo.o)

View File

@ -1,7 +1,7 @@
<html> <html>
<head> <head>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <!--<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>-->
<!--<script type="text/javascript" src="/usr/share/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>--> <script type="text/javascript" src="/usr/share/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
<style> <style>
body { body {
@ -69,10 +69,10 @@
</head> </head>
<body> <body>
<h1 style="margin-bottom:50pt;">meankondo <span style="margin-left:10pt;font-size:18pt">v1.4</span></h1> <h1 style="margin-bottom:50pt;">meankondo <span style="margin-left:10pt;font-size:18pt">v1.5</span></h1>
<p> <p>
This is the official documentation for <b>meankondo</b>, version 1.4. The aim of this document is not to give a technical description of how to use the various programs bundled with <b>meankondo</b>, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how <b>meankondo</b> approaches the computation of flow equations, and how its programs can be made to interact with one another to compute various quantities. For a more technical description, see the man pages included with the <b>meankondo</b> source code. For a more theoretical discussion of Fermionic hierarchical models, see <a href="http://ian.jauslin.org/publications/15bgj">[G.Benfatto, G.Gallavotti, I.Jauslin, 2015]</a>. This is the official documentation for <b>meankondo</b>, version 1.5. The aim of this document is not to give a technical description of how to use the various programs bundled with <b>meankondo</b>, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how <b>meankondo</b> approaches the computation of flow equations, and how its programs can be made to interact with one another to compute various quantities. For a more technical description, see the man pages included with the <b>meankondo</b> source code. For a more theoretical discussion of Fermionic hierarchical models, see <a href="http://ian.jauslin.org/publications/15bgj">[G.Benfatto, G.Gallavotti, I.Jauslin, 2015]</a>.
</p> </p>
<h2 style="margin-top:50pt;">Table of contents</h2> <h2 style="margin-top:50pt;">Table of contents</h2>
@ -92,9 +92,9 @@
</ul> </ul>
<li class="toc_sec"><a href="#operations">Operations on flow equations</a></li> <li class="toc_sec"><a href="#operations">Operations on flow equations</a></li>
<ul> <ul>
<li class="toc_sub"><a href="#processing">Pre- and post-processing</a></li>
<li class="toc_sub"><a href="#numerical_evaluation">Numerical Evaluation</a></li> <li class="toc_sub"><a href="#numerical_evaluation">Numerical Evaluation</a></li>
<li class="toc_sub"><a href="#exponentiation">Exponentiation</a></li> <li class="toc_sub"><a href="#differentiation">Differentiation</a></li>
<li class="toc_sub"><a href="#derivation">Derivation</a></li>
</ul> </ul>
<li class="toc_sec"><a href="#exactness">Comments on the exactness of the computation</a></li> <li class="toc_sec"><a href="#exactness">Comments on the exactness of the computation</a></li>
<li class="toc_sec"><a href="#authors">Authors</a></li> <li class="toc_sec"><a href="#authors">Authors</a></li>
@ -107,13 +107,9 @@
<ul> <ul>
<li><b>meankondo</b>: computes the flow equation.</li> <li><b>meankondo</b>: computes the flow equation.</li>
<li><b>numkondo</b>: iterate the flow equation numerically.</li> <li><b>numkondo</b>: iterate the flow equation numerically.</li>
<li><b>meantools</b>: tools to exponentiate, derive and evaluate a flow equation.</li> <li><b>meantools</b>: tools to take products, sums, exponentials or logairhtms, differentiate or evaluate a flow equation.</li>
<li><b>meantools-convert</b>: python script to convert a flow equation to C, javascript or LaTeX code.</li> <li><b>meantools-convert</b>: python script to convert a flow equation to C, javascript or LaTeX code.</li>
</ul> </ul>
as well as <i>pre-processors</i>, whose purpose is to help with writing configuration files for specific models:
<ul>
<li><b>kondo_preprocess</b>: hierarchical Kondo model.</li>
</ul>
In addition, <b>meankondo</b> includes a library, <b>libkondo</b>, which can either be compiled as a <i>shared</i> or a <i>static</i> object, and contains the various structures and functions <b>meankondo</b> is built with. In addition, <b>meankondo</b> includes a library, <b>libkondo</b>, which can either be compiled as a <i>shared</i> or a <i>static</i> object, and contains the various structures and functions <b>meankondo</b> is built with.
</p> </p>
@ -127,13 +123,13 @@
</p> </p>
<p> <p>
Given a configuration file 'config', the flow equation can be computed by Given a configuration file 'config.mk', the flow equation can be computed by
<code class="codeblock"> <code class="codeblock">
meankondo config meankondo config.mk
</code> </code>
and it can be iterated for, say, 100 steps starting from \(\ell_0^{[m]}=-0.01\) using and it can be iterated for, say, 100 steps starting from \(\ell_0^{[m]}=-0.01\) using
<code class="codeblock"> <code class="codeblock">
meankondo -C config | numkondo -N 100 -I "0:-0.01" meankondo -C config.mk | numkondo -N 100 -I "0:-0.01"
</code> </code>
</p> </p>
@ -150,7 +146,7 @@
<li><b>external</b>: which are organized in pairs, and are denoted by \((\Psi_i^+,\Psi_i^-)\) for \(i\in\{1,\cdots,E\}\). <li><b>external</b>: which are organized in pairs, and are denoted by \((\Psi_i^+,\Psi_i^-)\) for \(i\in\{1,\cdots,E\}\).
<li><b>super-external</b>: which denoted by \(H_i\) for \(i\in\{1,\cdots,X\}\) (the only difference with external fields is that super-external fields are not in pairs, which is a seemingly innocuous difference; but super-external fields are meant to be used for different purposes as external fields (see <a href="#flow_equation_definition">Definition</a> below)). <li><b>super-external</b>: which denoted by \(H_i\) for \(i\in\{1,\cdots,X\}\) (the only difference with external fields is that super-external fields are not in pairs, which is a seemingly innocuous difference; but super-external fields are meant to be used for different purposes as external fields (see <a href="#flow_equation_definition">Definition</a> below)).
</ul> </ul>
The fields are used as a basis for a complex algebra, so that we can take products and linear combinations of fields (in other words, the concept of <i>polynomials over the fields</i> is well defined). Some of the fields (<i>Fermions</i>) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (<i>Bosons</i>) commute. Which fields are Fermions and which are Bosons is specified in the <code>#!fields</code> entry in the configuration file. <b>(Warning: As of version 1.4, all internal fields must be Fermions.)</b> The fields are used as a basis for a complex algebra, so that we can take products and linear combinations of fields (in other words, the concept of <i>polynomials over the fields</i> is well defined). Some of the fields (<i>Fermions</i>) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (<i>Bosons</i>) commute. Which fields are Fermions and which are Bosons is specified in the <code>#!fields</code> entry in the configuration file. <b>(Warning: As of version 1.5, all internal fields must be Fermions.)</b>
</p> </p>
<p> <p>
In the configuration file of the <b>meankondo</b> program, the fields are specified in the <code>#!fields</code> entry. In the configuration file of the <b>meankondo</b> program, the fields are specified in the <code>#!fields</code> entry.
@ -174,6 +170,16 @@
In the configuration file of the <b>meankondo</b> program, the propagator is specified in the <code>#!propagator</code> entry. Note that <b>meankondo</b> recognizes numeric propagators as well as symbolic ones. In the configuration file of the <b>meankondo</b> program, the propagator is specified in the <code>#!propagator</code> entry. Note that <b>meankondo</b> recognizes numeric propagators as well as symbolic ones.
</p> </p>
<p>
It is convenient to re-expres the Wick rule in determinant form: if \(M\) is the \(n\times n\) matrix whose entries are \(M_{a,b}=\langle\psi_{i_a}^+\psi_{j_b}^-\rangle\), then
$$
\langle\psi_{i_1}^+\psi_{j_1}^-\cdots\psi_{i_n}^+\psi_{j_n}^-\rangle=
\det(M).
$$
<b>meankondo</b> implements an algorithm, based on an <i>LU decomposition</i>, to compute \(\det(M)\) in \(O(n^3)\) operations. However, when performing the LU decomposition, elements of \(M\) are divided, and since polynomial divisions are not supported in <b>meankondo</b>, the LU decomposition will only be performed if every entry of the propagator is numeric. If the propagator has symbolic entries, then <b>meankondo</b> computes the means summing over permutations, which requires \(O(n!)\) operations but does not require divisions.
</p>
<h2 class="section" id="flow_equation">Flow equation</h2> <h2 class="section" id="flow_equation">Flow equation</h2>
<p> <p>
In this section, we discuss what flow equations are, and how <b>meankondo</b> computes them. In this section, we discuss what flow equations are, and how <b>meankondo</b> computes them.
@ -247,7 +253,16 @@
<h2 class="section" id="operations">Operations on flow equations</h2> <h2 class="section" id="operations">Operations on flow equations</h2>
<p> <p>
In this section we describe the various operations on flow equations that the tools bundled with <b>meankondo</b> support. In this section we describe the various operations on flow equations that <b>meankondo</b> and the tools bundled with it support.
</p>
<h3 class="subsection" id="processing">Pre- and post-processing</h3>
<p>
<b>meankondo</b> can perform operations on the effective potential before and after applying the renormalization group transformation. This is useful, for instance, if the effective potential is expressed as an expontential: \(exp(W)\), in which case the input polynomial can be exponentiated before the computation, and the logarithm taken after the computation. To do this, <b>meankondo</b> implements some basic symbolic processing. For the syntax of the symbolic processing, see the <b>man</b> pages bundled with <b>meankondo</b>. The pre-processing is done in the <code>#!input_polynomial</code> configuration entry, and the post-processing can be done in the <code>#!postprocess_operation</code>, <code>#!postprocess_flow_equation</code> or <code>#!numerical_postprocess_operation</code> entries. In addition, <b>meantoolds expand</b> can be used to compute sums, products, exponentials and logarithms of effective potentials.
</p>
<p>
There are subtle differences between using <code>#!postprocess_operation</code>, <code>#!postprocess_flow_equation</code> and <code>#!numerical_postprocess_operation</code>. With <code>#!postprocess_operation</code>, the post-processing operation is done immediately after having computed the average. With <code>#!postprocess_flow_equation</code> and <code>#!numerical_postprocess_operation</code>, the avergae is first turned into a flow equation, and then the post-processing is applied to each equation. The main difference is in the handling of the constant term of the polynomials, see the <b>man</b> for details. The <code>numerical</code> entry is to be used for the numerical evaluation of the flow only, using <b>numkondo</b>.
</p> </p>
<h3 class="subsection" id="numerical_evaluation">Numerical evaluation</h3> <h3 class="subsection" id="numerical_evaluation">Numerical evaluation</h3>
@ -259,27 +274,18 @@
Numerical evaluation is handled in a straightforward manner, but for the following consideration. As was mentioned in <a href="#flow_equation_computation">Computation</a>, \(\mathcal R\) is a polynomial in \((\underline\ell,C^{-1}(\underline\ell))\), and when evaluating \(\mathcal R(\underline\ell)\), <b>meankondo</b> first evaluates \(C\) and the computes \(\ell'_n(\underline\ell)\). Numerical evaluation is handled in a straightforward manner, but for the following consideration. As was mentioned in <a href="#flow_equation_computation">Computation</a>, \(\mathcal R\) is a polynomial in \((\underline\ell,C^{-1}(\underline\ell))\), and when evaluating \(\mathcal R(\underline\ell)\), <b>meankondo</b> first evaluates \(C\) and the computes \(\ell'_n(\underline\ell)\).
</p> </p>
<h3 class="subsection" id="exponentiation">Exponentiation</h3> <h3 class="subsection" id="differentiation">Differentiation</h3>
<p> <p>
Oftentimes the renormalization group flow is expressed in terms of an exponential of an effective potential \(\exp(W)\), in which case the exponential must be computed before it can be processed by <b>meankondo</b>: This feature was introduced to compute the susceptibility in the hierarchical Kondo model. In that case, some of the running coupling constants depend on the field, \(h\), and the susceptibility is expressed as a derivative of \(C(\underline\ell(h))\) with respect to \(h\). To that end, we wrote <b>meantools differentiate</b> to compute the derivatives of a flow equation with respect to an external variable.
$$
\exp(W)=1+V.
$$
This is handled by <b>meantools exp</b>, which computes the running coupling constants appearing in \(V\) in terms of those in \(W\).
</p>
<h3 class="subsection" id="derivation">Derivation</h3>
<p>
This feature was introduced to compute the susceptibility in the hierarchical Kondo model. In that case, some of the running coupling constants depend on the field, \(h\), and the susceptibility is expressed as a derivative of \(C(\underline\ell(h))\) with respect to \(h\). To that end, we wrote <b>meantools derive</b> to compute the derivatives of a flow equation with respect to an external variable.
</p> </p>
<p> <p>
The input of <b>meantools derive</b> consists in a flow equation and a collection of variables \(X\subset\{1,\cdots,p\}\). Each running coupling constant \(\ell_i\) for \(i\in X\) is assumed to depend on an external parameter, \(h\). The flow equation is then derived with respect to \(h\): for every \(n\in\{1,\cdots,p\}\), the derivative of \(\ell_n'(\underline\ell)\) with respect to \(h\) in terms of \(\partial_h\ell_i\) for \(i\in X\) is computed. It is then appended to the input flow equation. The input of <b>meantools differentiate</b> consists in a flow equation and a collection of variables \(X\subset\{1,\cdots,p\}\). Each running coupling constant \(\ell_i\) for \(i\in X\) is assumed to depend on an external parameter, \(h\). The flow equation is then differentiated with respect to \(h\): for every \(n\in\{1,\cdots,p\}\), the derivative of \(\ell_n'(\underline\ell)\) with respect to \(h\) in terms of \(\partial_h\ell_i\) for \(i\in X\) is computed. It is then appended to the input flow equation.
</p> </p>
<h2 class="section" id="exactness">Comments on the exactness of the computation</h2> <h2 class="section" id="exactness">Comments on the exactness of the computation</h2>
<p> <p>
The computation of the flow equation, as well as its exponentiation and derivation, are <i>exact</i> in the sense that they only involve operations on integers and are not subject to truncations. The coefficients appearing in the flow equation are therefore <i>exact</i>. This statement has one major caveat: integer operations are only correct as long as the integers involved are not too large. The precise meaning of "not too large" is system dependent. In the source code, integers relating to flow equation coefficients are declared with the <code>long int</code> type, which, at least using the C library <b>meankondo</b> was tested with (that is <code>glibc 2.21</code>), means integers are encoded on 64 bits on 64-bit systems and 32 bits on 32-bit systems. All operations are therefore exact as long as all integers are in \([-2^{31},2^{31}-1]\) on 64-bit systems and \([-2^{15},2^{15}-1]\) on 32-bit systems. The computation of the flow equation, as well as all the operations done on it, are <i>exact</i> in the sense that they only involve operations on integers and are not subject to truncations. The coefficients appearing in the flow equation are therefore <i>exact</i>. This statement has one major caveat: integer operations are only correct as long as the integers involved are not too large. The precise meaning of "not too large" is system dependent. In the source code, integers relating to flow equation coefficients are declared with the <code>long int</code> type, which, at least using the C library <b>meankondo</b> was tested with (that is <code>glibc 2.21</code>), means integers are encoded on 64 bits on 64-bit systems and 32 bits on 32-bit systems. All operations are therefore exact as long as all integers are in \([-2^{31},2^{31}-1]\) on 64-bit systems and \([-2^{15},2^{15}-1]\) on 32-bit systems.
</p> </p>
<!--<p> <!--<p>

View File

@ -0,0 +1,7 @@
" Vim ftdetect file
" Language: meankondo
" Maintainer: Ian Jauslin <ian.jauslin@roma1.infn.it>
" Last Change: 2015-12-09
" URL: http://ian.jauslin.org/software/meankondo
"
au BufRead,BufNewFile *.mk set filetype=meankondo

View File

@ -0,0 +1,8 @@
" Vim ftplugin file
" Language: meankondo
" Maintainer: Ian Jauslin <ian.jauslin@roma1.infn.it>
" Last Change: 2015-12-09
" URL: http://ian.jauslin.org/software/meankondo
"
set mps+=<:>

View File

@ -0,0 +1,111 @@
" Vim syntax file
" Language: meankondo
" Maintainer: Ian Jauslin <ian.jauslin@roma1.infn.it>
" Last Change: 2022-06-06
" URL: http://ian.jauslin.org/software/meankondo
"
if exists("b:current_syntax")
finish
endif
" Comments
syn match Comment '#.*'
" Regions
syn region FieldsRegion matchgroup=configHeader start='#!fields' end='&' transparent contains=Comment,Separator,FieldHeader,FieldInField,Equal
syn region VariablesRegion matchgroup=configHeader start='#!preprocessor_variables' end='&' transparent contains=@Globals,VariableHeader
syn region IdTableRegion matchgroup=configHeader start='#!id_table' end='&' transparent contains=@Globals,RegionHeader
syn region SymbolsRegion matchgroup=configHeader start='#!symbols' end='&' transparent contains=@Globals,VariableHeader
syn region PolynomialRegion matchgroup=configHeader start='#!input_polynomial' end='&' transparent
syn region PolynomialRegion matchgroup=configHeader start='#!postprocess_operation' end='&' transparent
syn region PolynomialRegion matchgroup=configHeader start='#!postprocess_flow_equation' end='&' transparent
syn region PolynomialRegion matchgroup=configHeader start='#!numerical_postprocess_operation' end='&' transparent
syn region PropagatorRegion matchgroup=configHeader start='#!propagator' end='&' transparent contains=Comment,Number,NumberBase,Separator,FieldInProp,Equal,NumberInProp
syn region IdentitiesRegion matchgroup=configHeader start='#!identities' end='&' transparent
syn region GroupsRegion matchgroup=configHeader start='#!groups' end='&' transparent contains=Comment,Separator,FieldHeader,FieldInField,Equal,GroupParenthesis
syn region LabelsRegion matchgroup=configHeader start='#!labels' end='&' transparent contains=String,RegionHeader,Separator,Comment,Equal
syn region FlowEquationRegion matchgroup=configHeader start='#!flow_equation' end='&' transparent
syn region InitCdRegion matchgroup=configHeader start='#!initial_condition' end='&' transparent contains=Comment,Separator,RegionHeader,Equal,NumberInInit,InitHeader
syn region DerivVarsRegion matchgroup=configHeader start='#!variables' end='&' transparent contains=Comment,Separator,FieldHeader,FieldInField,Equal,VarAll
" Generic syntax
syn match Field '\[f[-0-9]\+\]'
syn match Factor '\[l[-0-9]\+\]'
syn match Factor '\[d*% *[-0-9]\+\]' contains=Deriv
syn match ConstantF '\[d*C *[0-9]\+\]' contains=Deriv
syn match ConstantD '\[/C *[0-9]\+ *\^ *[0-9]\+\]'
syn match Deriv 'd' contained
syn match Variables '\$[^>]*'
syn match Number '<[-/0-9]*>'
syn match Number '([-/0-9]*)'
syn match NumberBase 's{[-/0-9]*}'
syn match NumberBase '(s{[-/0-9]*})'
syn match Operator '[*+]'
syn match Operator '%exp'
syn match Operator '%log_1'
syn match Separator ','
syn match Equal '[:=]'
syn cluster Globals contains=Comment,Field,Factor,Constant,Variables,Number,NumberBase,Operator,Separator,Equal
" Fields
syn keyword FieldHeader i contained
syn keyword FieldHeader x contained
syn keyword FieldHeader h contained
syn keyword FieldHeader f contained
syn keyword FieldHeader a contained
syn match FieldInField '[-0-9]\+' contained
" Variables
syn match VariableHeader '^[^=,]*='he=e-1 contained contains=Equal
" Groups
syn match GroupParenthesis '[()]' contained
" Propagator
syn match FieldInProp '[0-9]\+ *[;:]'he=e-1 contained contains=Equal,NumberInProp
syn match NumberInProp ': *[-/()0-9s{}]*'hs=s+1 contained
" IdTable
syn match RegionHeader '[0-9]\+:'he=e-1 contained contains=Equal
" Labels
syn match String '"[^"]*"'hs=s+1,he=e-1 contained
" Initial condition
syn match InitHeader '[0-9]\+:'he=e-1 contained contains=Equal,NumberInInit
syn match NumberInInit ': *[-.e0-9]*'hs=s+1 contained
" Variables
syn keyword VarAll all contained
" Colors
hi Comment ctermfg=cyan
hi configHeader ctermfg=red
hi Field ctermfg=Lightblue
hi Factor ctermfg=Lightblue
hi ConstantF ctermfg=Lightblue
hi ConstantD ctermfg=Lightgreen
hi Deriv ctermfg=red
hi Header ctermfg=Lightgreen
hi Variables ctermfg=yellow
hi Number ctermfg=green
hi NumberBase ctermfg=green
hi Separator ctermfg=red
hi Equal ctermfg=Lightred
hi Operator ctermfg=magenta
hi String ctermfg=magenta
hi NumberInInit ctermfg=magenta
hi def link FieldInField Field
hi def link VariableHeader Variables
hi def link FieldInProp Field
hi def link FieldHeader Header
hi def link NumberInProp Number
hi def link SeparatorInProp Separator
hi def link RegionHeader Header
hi def link InitHeader Header
hi def link GroupParenthesis Separator
hi def link VarAll Field

View File

@ -1,5 +1,5 @@
.Dd $Mdocdate: September 22 2015 $ .Dd $Mdocdate: February 3 2016 $
.Dt kondo_preprocess 1.4 .Dt kondo_preprocess 1.5
.Os .Os
.Sh NAME .Sh NAME
.Nm kondo_preprocess .Nm kondo_preprocess
@ -13,11 +13,21 @@ for the Kondo model
.Pp .Pp
.Nm .Nm
.Fl v .Fl v
.Sh DEPRECATION NOTICE
The use of
.Nm
is deprecated as of
.Sy meankondo
v1.5.
.Pp
Similar functionality can be obtained rather easily using the enhanced symbolic capabilities introduced in v1.5, which are more flexible than
.Nm .
.Pp
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
generates a configuration file to be read by generates a configuration file to be read by
.Sy meankondo .Sy meankondo
for the Kondo model. It generates the '#!fields', '#!symbols', '#!identities', '#!groups', '#!propagator', '#!input_polynomial' and '#!id_table' entries from special '#!propagator', '#!input_polynomial' and '#!id_table' entries, which are much more synthetic than those needed for the Kondo model. for the Kondo model. It generates the '#!fields', '#!virtual_fields', '#!identities', '#!groups', '#!propagator', '#!input_polynomial' and '#!id_table' entries from special '#!propagator', '#!input_polynomial' and '#!id_table' entries, which are much more synthetic than those needed for the Kondo model.
.Pp .Pp
The quantities in the configuration file are expressed in terms of the observables A and B, which we do not define here, as well as the magnetic field h. The quantities in the configuration file are expressed in terms of the observables A and B, which we do not define here, as well as the magnetic field h.
.Pp .Pp
@ -32,14 +42,7 @@ is part of a set of tools to compute and manipulate Fermionic hierarchical flows
: numerical evaluation of flow equations. : numerical evaluation of flow equations.
.It .It
.Sy meantools, meantools-convert .Sy meantools, meantools-convert
: perform various operations on flow equations (derivation, exponentiation, evaluation and conversion to other formats). : perform various operations on flow equations (differentiation, products, sums, exponentials and logarithms of flow equations, evaluation and conversion to other formats).
.El
.Pp
as well as the following pre-processors, which generate configuration files for their associated model:
.Bl -bullet
.It
.Sy kondo_proprocess
: Kondo model
.El .El
.Pp .Pp
.Sh COMMAND-LINE ARGUMENTS .Sh COMMAND-LINE ARGUMENTS
@ -73,13 +76,13 @@ up to the following differences.
.It .It
The fields can be specified as scalar products of A's and B's. For each n in {1,...,dimension}, The fields can be specified as scalar products of A's and B's. For each n in {1,...,dimension},
.Nm .Nm
defines An and Bn, as well as symbols for scalar products of the form defines An and Bn, as well as virtual fields for scalar products of the form
.D1 [f An.An] .D1 [f An.An]
.D1 [f Bn.Bn] .D1 [f Bn.Bn]
.D1 [f An.Bn] .D1 [f An.Bn]
.D1 [f An.h] .D1 [f An.h]
.D1 [f Bn.h] .D1 [f Bn.h]
In addition, a vector product symbol is defined for (AnxBn).h : In addition, a vector product virtual field is defined for (AnxBn).h :
.D1 [f AnxBn.h] .D1 [f AnxBn.h]
.Pp .Pp
.It .It
@ -101,7 +104,7 @@ Scalar products of A's and B's may also be specified using the '<#.#>' syntax:
.D1 <An.h> .D1 <An.h>
.D1 <Bn.h> .D1 <Bn.h>
.Pp .Pp
The difference between '[f #.#]' and '<#.#>' is that the former corresponds to a '#!symbols' entry whereas the latter is replaced by its corresponding polynomial when The difference between '[f #.#]' and '<#.#>' is that the former corresponds to a '#!virtual_fields' entry whereas the latter is replaced by its corresponding polynomial when
.Nm .Nm
reads it (see reads it (see
.Sx meankondo Ns (1)). .Sx meankondo Ns (1)).
@ -114,7 +117,7 @@ A vector 't=(t1,t2,t3)' of Pauli matrices (satisfying the Pauli commutation rela
.D1 <a.t> .D1 <a.t>
.D1 <b.t> .D1 <b.t>
.Pp .Pp
Note that the '<#,#>' must be used since these scalar products do not commute whereas '#!symbols' entries must commute (see Note that the '<#,#>' must be used since these scalar products do not commute whereas '#!virtual_fiields' entries must commute (see
.Sx meankondo Ns (1)). .Sx meankondo Ns (1)).
.Pp .Pp
.It .It
@ -161,7 +164,7 @@ Example:
.D1 A1;A2: 1 , A2;A1: -1 , B1;B2: s{-1} , B2;B1: (-1)s{-1} .D1 A1;A2: 1 , A2;A1: -1 , B1;B2: s{-1} , B2;B1: (-1)s{-1}
.Pp .Pp
.It Sy extra entries .It Sy extra entries
If there is a '#!symbols' or an '#!identities' entry in the configuration file, then they are appended to the end of those entries in the new configuration file. If there is a '#!virtual_fields' or an '#!identities' entry in the configuration file, then they are appended to the end of those entries in the new configuration file.
.Pp .Pp
Any other entry is appended to the new configuration file. This can be useful to pipe the output to tools other than Any other entry is appended to the new configuration file. This can be useful to pipe the output to tools other than
.Sy meankondo .Sy meankondo

View File

@ -1,5 +1,5 @@
.Dd $Mdocdate: September 22 2015 $ .Dd $Mdocdate: June 6 2022 $
.Dt meankondo 1.4 .Dt meankondo 1.5
.Os .Os
.Sh NAME .Sh NAME
.Nm meankondo .Nm meankondo
@ -8,6 +8,8 @@
.Nm .Nm
.Op Fl t Ar threads .Op Fl t Ar threads
.Op Fl C .Op Fl C
.Op Fl p
.Op Fl A
.Op Ar config_file .Op Ar config_file
.Pp .Pp
.Nm .Nm
@ -29,14 +31,7 @@ is part of a set of tools to compute and manipulate Fermionic hierarchical flows
: numerical evaluation of flow equations. : numerical evaluation of flow equations.
.It .It
.Sy meantools, meantools-convert .Sy meantools, meantools-convert
: perform various operations on flow equations (derivation, exponentiation, evaluation and conversion to other formats). : perform various operations on flow equations (differentiation, products, sums, exponentials and logarithms of flow equations, evaluation and conversion to other formats).
.El
.Pp
as well as the following pre-processors, which generate configuration files for their associated model:
.Bl -bullet
.It
.Sy kondo_proprocess
: Kondo model
.El .El
.Pp .Pp
.Sh COMMAND-LINE ARGUMENTS .Sh COMMAND-LINE ARGUMENTS
@ -47,6 +42,10 @@ The number of threads to use for the computation.
Format the output so it can be piped to Format the output so it can be piped to
.Sy numkondo , .Sy numkondo ,
that is, instead of printing the flow equation, print a full configuration file containing the flow equation as well as all the other entries of the configuration file that do not pertain to the computation of the flow equation. that is, instead of printing the flow equation, print a full configuration file containing the flow equation as well as all the other entries of the configuration file that do not pertain to the computation of the flow equation.
.It Fl p
Print the progress of the computation.
.It Fl A
Compute the average of the effective potential, but do not write the result as a flow equation.
.It Fl v .It Fl v
Print version information and exit. Print version information and exit.
.El .El
@ -70,13 +69,15 @@ A list of the fields of the model.
The fields entry contains 5 lines which start with 'i:', 'x:', 'h:', 'f:' and 'a:'. Each of these is followed by a ',' separated list of field indices, which are positive integers. The fields entry contains 5 lines which start with 'i:', 'x:', 'h:', 'f:' and 'a:'. Each of these is followed by a ',' separated list of field indices, which are positive integers.
.Bl -bullet .Bl -bullet
.It .It
The indices following 'i' correspond to internal fields, which are integrated out using the Wick rule and the propagator provided in the '#!propagator' entry. Each internal field is associated a conjugate field, whose index is the opposite of the field's index (e.g. 'i:101' defines a field whose index is -101) The indices following 'i' correspond to internal fields, which are integrated out using the Wick rule and the propagator provided in the '#!propagator' entry. Each internal field is associated a conjugate field, whose index is the opposite of the field's index (e.g. 'i:101' defines two fields whose indices are 101 and -101).
.It .It
The indices following 'x' correspond to external fields that are associated conjugate field (e.g. 'x:100' defines a field whose index is -100). External indices may not appear as internal indices. The indices following 'x' correspond to external fields that are associated conjugate field (e.g. 'x:100' defines two fields whose indices are 100 and -100). External indices may not appear as internal indices.
.It .It
The indices following 'h' correspond to external fields that are not associated a conjugate field. External indices may not appear as internal indices. The indices following 'h' correspond to external fields that are not associated a conjugate field. External indices may not appear as internal indices.
.It .It
The 'f' line specifies which of the internal and external indices are Fermions, i.e. which fields anti-commute. The fields appearing in the 'f' line should also either appear in the 'i' or 'x' line. WARNING: for the moment, only cases in which all of the internal fields are Fermions are supported. The 'f' line specifies which of the internal and external indices are Fermions, i.e. which fields anti-commute. The fields appearing in the 'f' line should also either appear in the 'i' or 'x' line.
.Pp
WARNING: only cases in which all of the internal fields are Fermions are supported.
.It .It
The 'a' line specifies a list of external fields listed in the 'h' entry that do not commute with each other. Specifying fields in this entry will prevent The 'a' line specifies a list of external fields listed in the 'h' entry that do not commute with each other. Specifying fields in this entry will prevent
.Nm .Nm
@ -96,14 +97,43 @@ The propagator of the model.
.Pp .Pp
The propagator entry is a ',' separated list whose elements are of the form The propagator entry is a ',' separated list whose elements are of the form
.D1 index1;index2: polynomial .D1 index1;index2: polynomial
where index1 and index2 are internal indices, and polynomial is a polynomial (see the POLYNOMIALS section below for information on how to format polynomials). The polynomial must not depend on the internal fields. Note that a number is a special type of polynomial, so propagators with numerical entries are handled by where 'index1' and 'index2' are internal indices, and 'polynomial' is a polynomial (see the POLYNOMIALS section below for information on how to format polynomials). The polynomial must not depend on the internal fields. Note that a number is a special type of polynomial, so propagators with numerical entries are handled by
.Nm .Nm
just as easily as propagators with symbolic entries. Such an entry means that just as easily as propagators with symbolic entries. Such an entry means that
.D1 <psi_{index1}^-psi_{index2}^+> = polynomial. .D1 <psi_{index1}^-psi_{index2}^+> = polynomial.
.Pp .Pp
Note that if the entries of the propagator are numbers instead of polynomials, then the Wick rule is implemented using a determinant instead of a sum over permutations, which is a lot faster for large monomials. Since the efficient computation of determinants requires divisions, polynomial entries in the propagator make the computation awkward, and
.Nm
falls back to implementing the Wick rule as a sum over permutations.
.Pp
Example: Example:
.D1 101;102: 1 , 102;101: -1 , 201;202: s{-1} + (-1)[l10] , 202;201: (-1)s{-1} + [l10] .D1 101;102: 1 , 102;101: -1 , 201;202: s{-1} + (-1)[l10] , 202;201: (-1)s{-1} + [l10]
.Pp .Pp
.It Sy #!input_polynomial
The polynomial whose mean we wish to compute in order to calculate the flow equation.
.Pp
The format of the polynomial is that specified in the POLYNOMIALS section.
.Pp
.It Sy #!preprocessor_variables
In order to simplify configuration files, symbolic variables can be defined. When
.Nm
reads the configuration file, it replaces every variable with its value (a process which is referred to as "preprocessing").
.Pp
The preprocessor_variables entry is a ',' separated list, whose elements are of the form
.D1 variable_name=value
where 'variable_name' is a string that is not 'OUT', 'FLOW' or 'RCC', and may not contain any of the following characters: '$', '<', '>', '*', '+', '%'; and 'value' is a polynomial, formatted as described in the POLYNOMIALS section. The variable names 'OUT' 'FLOW' and 'RCC' are reserved and cannot be used. Note that 'value' can contain other preprocessor variables. There is no safeguard against self-referencing definitions that may cause infinite loops.
.Pp
A variable can be used throughout the configuration file by using the format '<$variable_name>'. Whenever '<$variable_name>' is encountered, it is replaced by its corresponding value. The order in which the variables are defined is irrelevant, since
.Nm
reads all variables definitions before replacing variables in the configuration file.
.Pp
Spaces surrounding the variable name are ignored.
.Pp
Example:
.D1 psi1 = [f1]+[f-1],
.D1 psi2 = [f2]+[f-2],
.D1 A = <$psi1>*<$psi2>
.Pp
.It Sy #!identities .It Sy #!identities
Identities satisfied by some of the fields (optional entry). Identities satisfied by some of the fields (optional entry).
.Pp .Pp
@ -111,7 +141,9 @@ In some cases, some of the quantities involved in a model will satisfy an identi
.Pp .Pp
The identities entry is a ',' separated list, whose elements are of the form The identities entry is a ',' separated list, whose elements are of the form
.D1 monomial=polynomial .D1 monomial=polynomial
where monomial represents the left side of the identity and is a sequence of field indices of the form '[f index1][f index2]...' and polynomial represents the right side of the identity (see the POLYNOMIALS section below for information on how to format polynomials). where 'monomial' represents the left side of the identity and is a sequence of field indices of the form '[f index1][f index2]...' and 'polynomial' represents the right side of the identity (see the POLYNOMIALS section below for information on how to format polynomials).
.Pp
Identities could be used to reproduce the functionality of preprocessor variables, though it is less convenient (see COMMENT ON PREPROCESSOR VARIABLES, IDENTITIES AND VIRTUAL FIELDS).
.Pp .Pp
Example: Example:
.D1 [f301][f301]=(1)+(-1)[f302][f302]+(-1)[f303][f303], .D1 [f301][f301]=(1)+(-1)[f302][f302]+(-1)[f303][f303],
@ -121,37 +153,30 @@ Example:
.Pp .Pp
This entry is optional. This entry is optional.
.Pp .Pp
.It Sy #!symbols .It Sy #!virtual_fields
Symbolic variables used as shortcuts for more complicated expressions (optional entry). Virtual fields are used to keep the memory footprint of
.Pp
In order to simplify long expressions, symbolic variables can be defined in this entry. Each variable is assigned an index, which is a positive integer that must be different from any of the internal and external indices defined in the '#!fields' entry.
.Pp
Seemingly similar functionality can be achieved using an '#!identity' entry (see above), though symbols are handled differently from identities. Indeed, while identities are simplified out of the polynomials as soon as they occur, symbols are only resolved when
.Nm .Nm
computes the mean of the input polynomial. Using symbols can thereby be a lot faster than using identities. However, as is mentioned below, symbols must commute with each other and all other fields, whereas identities can be made to be fermionic or non-commuting. small, even when the input polynomial contains many terms.
.Pp .Pp
The symbols entry is a ',' separated list, whose elements are of the form Every term of the input polynomial is parsed and stored when the configuration file is read, which may require large amounts of memory. In order to avoid this, some terms of the input polynomial can be grouped together and stored as a single virtual field, which only occupies as much memory as a single field.
.Pp
A virtual field is identified by an index, which must be different from those of the fields defined in the '#!fields' entry.
.Pp
The virtual_fields entry is a ',' separated list, whose elements are of the form
.D1 index= polynomial .D1 index= polynomial
where index is the index of the variable and polynomial is the expression it stands for (see the POLYNOMIALS section below for information on how to format polynomials). Note that polynomial can contain other symbolic variables. There is no safeguard against self-referencing definitions that may cause infinite loops. where 'index' is the index of the virtual_field and 'polynomial' is the expression it stands for (see the POLYNOMIALS section below for information on how to format polynomials). Note that 'polynomial' can contain other virtual fields. There is no safeguard against self-referencing definitions that may cause infinite loops.
.Pp .Pp
WARNING: Symbols are assumed to commute with each other and all other Fermions. They should therefore not represent quantities that do not commute (e.g. odd monomials of fermions or non-commuting objects specified in the 'a:' entry in the '#!fields' entry). WARNING: Virtual fields are assumed to commute with each other and all other Fermions. They should therefore not represent quantities that do not commute (e.g. odd monomials of Fermions or non-commuting objects specified in the 'a:' entry in the '#!fields' entry).
.Pp
Virtual fields could be used to reproduce the functionality of commuting preprocessor variables (see COMMENT ON PREPROCESSOR VARIABLES, IDENTITIES AND VIRTUAL FIELDS).
.Pp .Pp
Example: Example:
.D1 1001= (-1)[f-100][f100] + (-1)[f-101][f101] , 2001=[f-100][f100] + [f-201][f201] .D1 1001= (-1)[f-100][f100] + (-1)[f-101][f101] , 2001=[f-100][f100] + [f-201][f201]
.Pp .Pp
This entry is optional. This entry is optional.
.Pp .Pp
.It Sy #!input_polynomial
The polynomial whose mean we wish to compute in order to calculate the flow equation.
.Pp
The format of the polynomial is that specified in the POLYNOMIALS section. In addition, the polynomial can be specified as the product of other polynomials:
.D1 polynomial1 * polynomial2 * ...
Note that there are no parentheses, and therefore, products cannot be nested, nor can a product of polynomials be summed with another polynomial.
.Pp
Example:
.D1 (1) + (1/2)[l1][f1001] * (1) + (1/2)[l2][f2001]
.It Sy #!id_table .It Sy #!id_table
The idtable used to identify the running coupling constants. The idtable is used to identify the running coupling constants.
.Pp .Pp
Once the mean of the input polynomial has been computed, we are left with a polynomial of the external fields and the running coupling constants that were in the input polynomial. In order to compute a flow equation from this average, Once the mean of the input polynomial has been computed, we are left with a polynomial of the external fields and the running coupling constants that were in the input polynomial. In order to compute a flow equation from this average,
.Nm .Nm
@ -159,7 +184,7 @@ uses an idtable to identify which of the monomials of the average contribute to
.Pp .Pp
The id_table entry is a ',' separated list, whose elements are of the form The id_table entry is a ',' separated list, whose elements are of the form
.D1 rcc: polynomial .D1 rcc: polynomial
where rcc is the index of the corresponding running coupling constant, which is a non-negative integer, and polynomial is the polynomial to which rcc refers to (which is a polynomial of the external fields). where 'rcc' is the index of the corresponding running coupling constant, which is a non-negative integer, and 'polynomial' is the polynomial to which 'rcc' refers to (which is a polynomial of the external fields).
.Pp .Pp
Example: Example:
.D1 1:(-1)[f-100][f100] , 2:[f-200][f200] .D1 1:(-1)[f-100][f100] , 2:[f-200][f200]
@ -172,10 +197,6 @@ computes the mean of a monomial containing elements of different groups, it fact
.Nm .Nm
does not repeatedly try to pair independent fields. does not repeatedly try to pair independent fields.
.Pp .Pp
WARNING:
.Nm
assumes that the symbols and fields in each group are independent but does not check that they are. If symbols or fields that are not independent are put in different groups, or if some are in a group while others are not in any group, then the resulting flow equation may be wrong.
.Pp
The groups entry is a list of collections of fields or symbols of the following form The groups entry is a list of collections of fields or symbols of the following form
.D1 (index1,index2,...) .D1 (index1,index2,...)
.Pp .Pp
@ -183,15 +204,80 @@ Example:
.D1 (1001,1002) (2001,2002) .D1 (1001,1002) (2001,2002)
.Pp .Pp
This entry is optional. This entry is optional.
.It Sy #!postprocess_operation
An operation that is done after having computed the mean of the input polynomial. (optional entry)
.Pp
The format of this entry is a polynomial, as specified in the POLYNOMIALS section.
.Pp
When this entry is present in the configuration,
.Nm
creates a preprocessor variable named 'OUT', which contains the mean of the input polynomial, and can be used in the postprocessing.
.Pp
Example:
To multiply the mean of the input polynomial by 8:
.D1 <<8>*<$OUT>>
.Pp
This entry is optional.
.It Sy #!postprocess_flow_equation
This entry is similar to 'posprocess_operation', except that the operation is performed on the flow equation, that is, it is performed after having grouped the polynomial. (optional entry)
.Pp
The main difference with carrying out the operation in this way is that the constant term gets handles differently. Whereas 'postprocess_operation' gets applied to the entire polynomial, 'postprocess_flow_equation' is applied to each running coupling constant in the flow equation except the constant term. This is quite useful when the operation is not a polynomial function, such as log_1 or exp.
.Pp
The format of this entry is a polynomial, as specified in the POLYNOMIALS section.
.Pp
When this entry is present in the configuration,
.Nm
creates a preprocessor variable named 'FLOW', which contains the polynomial obtained by adding each term in the id_table, and can be used in the postprocessing.
.Pp
Example:
To take the logarithm of the flow equation:
.D1 <%log_1<$FLOW>>
.Pp
This entry is optional.
.It Sy #!numerical_postprocess_operation
An operation that is done at each step of an eventual numerical computation done with numkondo. (optional entry)
.Pp
This is similar in spirit to the 'postprocess_flow_equation' entry, except that the postprocessing is entirely numerical (no symbolic operations are performed).
.Pp
The format of this entry is a polynomial, as specified in the POLYNOMIALS section.
.Pp
When this entry is present in the configuration,
.Nm
creates a preprocessor variable named 'RCC', which contains the polynomial obtained by adding each term in the id_table, and can be used in the postprocessing.
.Pp
When this entry is present in the configuration along with the -C option,
.Nm
will add a 'preprocessor_operation' entry in the configuration file to be piped to numkondo.
.Pp
Example:
To take the logarithm of the polynomial:
.D1 <%log_1<$RCC>>
.Pp
This entry is optional.
.Pp
.El .El
.Pp .Pp
.Sh COMMENT ON PREPROCESSOR VARIABLES, IDENTITIES AND VIRTUAL FIELDS
On the surface, preprocessor variables, identities and virtual fields can be used to perform similar tasks, but
.Nm
handles them in very different ways.
.Pp
A preprocessor variable could be replaced by an identity by introducing an extra field corresponding to the variable, and using an identity to make
.Nm
replace the extra field by its definition. Using a preprocessor variable will, however, be more convenient since no extra field needs to be introduced.
.Pp
Virtual fields could also play the role of preprocessor variables, in that they can be used to simplify the configuration file. However, virtual fields are not replaced by their corresponding expression until their average is computed, and, in the various manipulations required to carry out the computations, the monomials containing virtual fields will be manipulated and virtual fields commuted with other fields. As a consequence, virtual fields must commute with all other fields, which severely limits their potential role as a preprocessor variable.
.Pp
In short, preprocessor variables are meant to be used to simplify the configuration file, identities, to implement identities between fields, and virtual fields to reduce the memory footprint of
.Nm .
.Pp
.Sh NUMBERS .Sh NUMBERS
.Nm .Nm
can parse rational numbers and linear combinations of square roots of integers (positive or negative (which is how complex numbers are implemented)) with rational coefficients (i.e. elements of the field extension of Q generated by sqrt(Z)). can parse rational numbers and linear combinations of square roots of integers (positive or negative (which is how complex numbers are implemented)) with rational coefficients (i.e. elements of the field extension of Q generated by sqrt(Z)).
.Pp .Pp
A number is a '+' separated list whose elements are of the form A number is a '+' separated list whose elements are of the form
.D1 (a/b)s{r} .D1 (a/b)s{r}
where a and r are integers and b is a positive integer. s{r} stands for sqrt(r). where 'a' and 'r' are integers and 'b' is a positive integer. 's{r}' stands for 'sqrt(r)'.
.Pp .Pp
If a=b, then the number may be written as 's{r}'. If b=1, then it can be '(a)s{r}'. If r=1, then it can be 'a/b'. If b=r=1, then it can be 'a'. If a=b, then the number may be written as 's{r}'. If b=1, then it can be '(a)s{r}'. If r=1, then it can be 'a/b'. If b=r=1, then it can be 'a'.
.Pp .Pp
@ -199,7 +285,10 @@ Example:
.D1 (1/2)s{2} + (-1)s{-1} + 3/2 .D1 (1/2)s{2} + (-1)s{-1} + 3/2
.Pp .Pp
.Sh POLYNOMIALS .Sh POLYNOMIALS
Polynomials are '+' separated lists of monomials. Each monomial is a sequence of numbers, rccs and fields. .Nm
implements some elementary symbolic algebra in order to parse polynomials.
.Pp
The format of polynomials is defined recursively. If the polynomial contains no '<', then it is said to be 'terminal'. Terminal polynomials are '+' separated lists of monomials. Each monomial is a sequence of numbers, rccs and fields.
.Bl -bullet .Bl -bullet
.It .It
Numbers are enclosed between '(' and ')'. If there are several numbers in a monomial, then they are multiplied. Numbers are enclosed between '(' and ')'. If there are several numbers in a monomial, then they are multiplied.
@ -211,8 +300,17 @@ Fields are non-vanishing indices enclosed between '[f' and ']'. Fields must eith
.Pp .Pp
If the numerical factor of a monomial is 1, then it can be dropped. However, even if the numerical factor is a single integer, its '(' and ')' delimiters cannot be omitted. If the numerical factor of a monomial is 1, then it can be dropped. However, even if the numerical factor is a single integer, its '(' and ')' delimiters cannot be omitted.
.Pp .Pp
If the polynomial is not terminal, then it is of the form
.D1 <polynomial>operation<polynomial>
where 'operation' is either '+' or '*', or
.D1 <%func<polynomial>>
where 'func' is 'exp' or 'log_1'. '<%exp<P>>' returns the exponential of P, whereas '<%log_1<P>>' returns log(1+P).
.Pp
.Nm
parses polynomials by recursing through this structure, adding and multiplying terminal polynomials when '+' and '*' operations are encountered, and taking exponentials and logarithms when '%exp' or '%log_1' are encountered.
.Pp
Example: Example:
.D1 (1) + ((3/2)s{2} + (-1)s{-1} + 3)[l1][l2][f100][f1001][f101] + [l1][f101] + (3)[l2] .D1 <(1)+((3/2)s{2}+(-1)s{-1}+3)[l1][l2][f100][f1001][f101]>*<%exp<[l1][f101]+(3)[l2]>>
.Pp .Pp
.Sh OUTPUT .Sh OUTPUT
.Nm .Nm
@ -232,5 +330,4 @@ returns 0 on success and -1 on error.
.Sx numkondo Ns (1) , .Sx numkondo Ns (1) ,
.Sx meantools Ns (1) , .Sx meantools Ns (1) ,
.Sx meantools-convert Ns (1) , .Sx meantools-convert Ns (1) ,
.Sx kondo_preprocess Ns (1)
.Pp .Pp

View File

@ -1,5 +1,5 @@
.Dd $Mdocdate: September 22 2015 $ .Dd $Mdocdate: June 6 2022 $
.Dt meantools-convert 1.4 .Dt meantools-convert 1.5
.Os .Os
.Sh NAME .Sh NAME
.Nm meantools-convert .Nm meantools-convert
@ -43,14 +43,7 @@ is part of a set of tools to compute and manipulate Fermionic hierarchical flows
: numerical evaluation of flow equations. : numerical evaluation of flow equations.
.It .It
.Sy meantools, meantools-convert .Sy meantools, meantools-convert
: perform various operations on flow equations (derivation, exponentiation, evaluation and conversion to other formats). : perform various operations on flow equations (differentiation, products, sums, exponentials and logarithms of flow equations, evaluation and conversion to other formats).
.El
.Pp
as well as the following pre-processors, which generate configuration files for their associated model:
.Bl -bullet
.It
.Sy kondo_proprocess
: Kondo model
.El .El
.Pp .Pp
.Sh COMMAND-LINE ARGUMENTS .Sh COMMAND-LINE ARGUMENTS
@ -133,5 +126,4 @@ returns 0 on success and -1 on error.
.Sx meankondo Ns (1) .Sx meankondo Ns (1)
.Sx numkondo Ns (1) , .Sx numkondo Ns (1) ,
.Sx meantools Ns (1) , .Sx meantools Ns (1) ,
.Sx kondo_preprocess Ns (1)
.Pp .Pp

View File

@ -1,16 +1,12 @@
.Dd $Mdocdate: September 22 2015 $ .Dd $Mdocdate: June 6 2022 $
.Dt meantools 1.4 .Dt meantools 1.5
.Os .Os
.Sh NAME .Sh NAME
.Nm meantools .Nm meantools
.Nd A tool to manipulate flow equations .Nd A tool to manipulate flow equations
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Sy exp .Sy differentiate
.Op Ar config_file
.Pp
.Nm
.Sy derive
.Op Fl d Ar nderivs .Op Fl d Ar nderivs
.Op Fl V Ar variables .Op Fl V Ar variables
.Op Fl C .Op Fl C
@ -23,11 +19,16 @@
.Op Fl E Ar max_exponent .Op Fl E Ar max_exponent
.Op Ar config_file .Op Ar config_file
.Pp .Pp
.Nm
.Sy expand
.Op Fl N Ar namespace
.OpAr config_file
.Pp
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
performs various operations on flow equations generated by performs various operations on flow equations generated by
.Sy meankondo. .Sy meankondo.
Namely, it can exponentiate, derive and evaluate flow equations. Namely, it can differentiate and evaluate flow equations, as well as perform elementary operations on polynomials.
.Pp .Pp
.Nm .Nm
is part of a set of tools to compute and manipulate Fermionic hierarchical flows: is part of a set of tools to compute and manipulate Fermionic hierarchical flows:
@ -40,45 +41,11 @@ is part of a set of tools to compute and manipulate Fermionic hierarchical flows
: numerical evaluation of flow equations. : numerical evaluation of flow equations.
.It .It
.Sy meantools, meantools-convert .Sy meantools, meantools-convert
: perform various operations on flow equations (derivation, exponentiation, evaluation and conversion to other formats). : perform various operations on flow equations (differentiation, products, sums, exponentials and logarithms of flow equations, evaluation and conversion to other formats).
.El .El
.Pp .Pp
as well as the following pre-processors, which generate configuration files for their associated model: .Sh DIFFERENTIATE
.Bl -bullet When run with the 'differentiate' command,
.It
.Sy kondo_proprocess
: Kondo model
.El
.Pp
.Sh EXP
When run with the 'exp' command,
.Nm
computes the exponential of a flow equation. All the required parameters are set in the configuration file, which it either reads from the file provided on the command line, or from stdin.
.Pp
The syntax for the configuration file is the same as for
.Sx meankondo Ns (1) ,
and will not be belaboured here. The supported entries are
.Bl -tag -width Ds
.It Sy #!input_polynomial
The polynomial whose exponential is to be computed.
.Pp
.It Sy #!fields
The fields appearing in the polynomial
.Pp
.It Sy #!symbols
Symbolic variables (optional entry).
.Pp
.It Sy #!identities
identities between fields (optional entry).
.Pp
.It Sy #!id_table
The idtable used to compute a flow equation from the polynomial.
.El
.Pp
The resulting flow equation is written to stdout.
.Pp
.Sh DERIVE
When run with the 'derive' command,
.Nm .Nm
computes derivatives of a flow equation provided in the configuration file, which can either be passed as a command-line argument or through stdin. computes derivatives of a flow equation provided in the configuration file, which can either be passed as a command-line argument or through stdin.
.Pp .Pp
@ -86,7 +53,7 @@ The derivatives are derivatives with respect to an extra virtual parameter, whic
.Pp .Pp
When multiple derivatives are taken, the flow equation becomes a flow equation for the rccs, their derivatives, second derivatives, and so forth... When multiple derivatives are taken, the flow equation becomes a flow equation for the rccs, their derivatives, second derivatives, and so forth...
.Pp .Pp
This operation can be useful, for instance, to compute moments in an interacting system, in which the generating functional can be expressed as an effective potential depending on a parameter with respect to which the result of the integration should be derived. The 'derive' command writes the flow equation for the derived rccs, from which the quantities of interest can be computed. This operation can be useful, for instance, to compute moments in an interacting system, in which the generating functional can be expressed as an effective potential depending on a parameter with respect to which the result of the integration should be differentiated. The 'differentiate' command writes the flow equation for the differentiated rccs, from which the quantities of interest can be computed.
.Pp .Pp
.Sy Command-line arguments: .Sy Command-line arguments:
.Bl -tag -width Ds .Bl -tag -width Ds
@ -97,7 +64,7 @@ The variables that depend on the extra virtual parameter (defaults to all) (WARN
.Nm .Nm
would interpret the argument as being a flag, for example, write '-V "0,-1"' instead of '-V "-1,0"'). would interpret the argument as being a flag, for example, write '-V "0,-1"' instead of '-V "-1,0"').
.Pp .Pp
Can either be a ',' separated list if indices or 'all' to derive with respect to all available variables. Can either be a ',' separated list if indices or 'all' to differentiate with respect to all available variables.
.It Fl C .It Fl C
Format the output so it can be piped to Format the output so it can be piped to
.Sy numkondo , .Sy numkondo ,
@ -106,10 +73,10 @@ that is, instead of printing the flow equation, print a full configuration file
.Pp .Pp
.Sy Configuration file: .Sy Configuration file:
.Pp .Pp
The configuration file contains the flow equation to derive, and optionally a list of variables (similar to the '-V' flag). The following entries are supported: The configuration file contains the flow equation to differentiate, and optionally a list of variables (similar to the '-V' flag). The following entries are supported:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Sy #!flow_equation .It Sy #!flow_equation
The flow equation to derive. The flow equation to differentiate.
.Pp .Pp
The syntax is identical to that in The syntax is identical to that in
.Sx numkondo Ns (1) . .Sx numkondo Ns (1) .
@ -169,9 +136,49 @@ If the '-R' flag is provided on the command-line, this entry is ignored.
.Pp .Pp
The result of the evaluation is written to stdout, and is formatted is such a way that it can be used as an initial condition for The result of the evaluation is written to stdout, and is formatted is such a way that it can be used as an initial condition for
.Pp .Pp
.Sh EXPAND
When run with the 'expand' command,
.Nm
expands the preprocessor variables in the input polynomial, provided in the configuration file, which can either be passed as a command-line argument or through stdin, and prints the result.
.Pp
.Sy Command-line arguments:
.Bl -tag -width Ds
.It Fl N Ar namespace
If the configuration file is to be used to perform other operations, it may be convenient to specify the input polynomial for the 'expand' command alongside another '#!input_polynomial' entry, used for some other computation. This is made possible by namespaces.
.Pp
If a namespace is provided to
.Nm
on the command line, then it will search for the entries in the configuration file in the form
.D1 #!namespace:header
and default to #!header if no such header is present.
.Pp
In this way, the configuration file can, for instance, contain a '#!namspace:input_polynomial' entry for this computation, as well as a '#!input_polynomial' entry, to be used for some other purpose, all the while using the same '#!fields', '#!preprocessor_variables', '#!virtual_fields' and '#!identities' entries.
.El
.Pp
.Sy Configuration file:
.Pp
The supported entries are
.Bl -tag -width Ds
.It Sy #!input_polynomial
The polynomial whose exponential is to be computed.
.Pp
.It Sy #!fields
The fields appearing in the polynomial.
.Pp
.It Sy #!preprocessor_variables
Preprocessor variables (optional entry).
.Pp
.It Sy #!virtual_fields
Virtual fields (optional entry).
.Pp
.It Sy #!identities
identities between fields (optional entry).
.El
.Pp
The result is written to stdout.
.Pp
.Sh SEE ALSO .Sh SEE ALSO
.Sx meankondo Ns (1) , .Sx meankondo Ns (1) ,
.Sx numkondo Ns (1) , .Sx numkondo Ns (1) ,
.Sx meantools-convert Ns (1) , .Sx meantools-convert Ns (1) ,
.Sx kondo_preprocess Ns (1)
.Pp .Pp

View File

@ -1,5 +1,5 @@
.Dd $Mdocdate: September 22 2015 $ .Dd $Mdocdate: June 6 2022 $
.Dt numkondo 1.4 .Dt numkondo 1.5
.Os .Os
.Sh NAME .Sh NAME
.Nm numkondo .Nm numkondo
@ -29,14 +29,7 @@ is part of a set of tools to compute and manipulate Fermionic hierarchical flows
: numerical evaluation of flow equations. : numerical evaluation of flow equations.
.It .It
.Sy meantools, meantools-convert .Sy meantools, meantools-convert
: perform various operations on flow equations (derivation, exponentiation, evaluation and conversion to other formats). : perform various operations on flow equations (differentiation, products, sums, exponentials and logarithms of flow equations, evaluation and conversion to other formats).
.El
.Pp
as well as the following pre-processors, which generate configuration files for their associated model:
.Bl -bullet
.It
.Sy kondo_proprocess
: Kondo model
.El .El
.Pp .Pp
.Sh COMMAND-LINE ARGUMENTS .Sh COMMAND-LINE ARGUMENTS
@ -167,5 +160,4 @@ returns 0 on success and -1 on error.
.Sx meankondo Ns (1) , .Sx meankondo Ns (1) ,
.Sx meantools Ns (1) , .Sx meantools Ns (1) ,
.Sx meantools-convert Ns (1) , .Sx meantools-convert Ns (1) ,
.Sx kondo_preprocess Ns (1)
.Pp .Pp

View File

@ -1,4 +1,4 @@
## Copyright 2015 Ian Jauslin ## Copyright 2015-2022 Ian Jauslin
## ##
## Licensed under the Apache License, Version 2.0 (the "License"); ## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License. ## you may not use this file except in compliance with the License.

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
## Copyright 2015 Ian Jauslin ## Copyright 2015-2022 Ian Jauslin
## ##
## Licensed under the Apache License, Version 2.0 (the "License"); ## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License. ## you may not use this file except in compliance with the License.
@ -76,8 +76,8 @@ def latex_engine(argv,text):
i=1 i=1
# defaults # defaults
lsym="\\ell" lsym=r'\\ell'
Lsym="\\ell'" Lsym=r'\\ell'
Csym="C" Csym="C"
oneline=1 oneline=1
while (i<argc): while (i<argc):
@ -171,6 +171,10 @@ def convert_latex(text, lsym, Lsym, Csym, oneline):
# remove extra space # remove extra space
text=re.sub(r' {2,}',' ',text) text=re.sub(r' {2,}',' ',text)
# remove unnecessary 1's
text=re.sub(r'\(-1\)\[',r'-[',text)
text=re.sub(r'\(1\)\[',r'[',text)
# replace left hand side variables # replace left hand side variables
text=re.sub(r'\[(d*)C *([0-9]*)\] =',r'@\1'+Csym+r'_{\2} =', text) text=re.sub(r'\[(d*)C *([0-9]*)\] =',r'@\1'+Csym+r'_{\2} =', text)
text=re.sub(r'\[(d*)% *([0-9]*)\] =',r'@\1'+Lsym+r'_{\2} =', text) text=re.sub(r'\[(d*)% *([0-9]*)\] =',r'@\1'+Lsym+r'_{\2} =', text)
@ -213,7 +217,11 @@ def convert_latex(text, lsym, Lsym, Csym, oneline):
# fractions # fractions
text=re.sub(r'\((-?)([0-9]*)/([0-9]*)\)',r'\1\\frac{\2}{\3}',text) text=re.sub(r'\((-?)([0-9]*)/([0-9]*)\)',r'\1\\frac{\2}{\3}',text)
# numbers # numbers
text=re.sub(r'\(([-0-9]*)\)',r'\1',text) #text=re.sub(r'\(([-0-9]*)\)',r'\1',text)
# fix signs
text=re.sub(r'\+-',r'-',text)
return(text) return(text)

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -72,6 +72,14 @@ int int_array_append(int val, Int_Array* output){
return(0); return(0);
} }
// add a value only if it is not already present
int int_array_append_unique(int val, Int_Array* output){
if(int_array_find(val,*output)<0){
int_array_append(val,output);
}
return(0);
}
// concatenate // concatenate
int int_array_concat(Int_Array input, Int_Array* output){ int int_array_concat(Int_Array input, Int_Array* output){
int i; int i;
@ -87,6 +95,15 @@ int int_array_concat(Int_Array input, Int_Array* output){
return(0); return(0);
} }
// concat but only add values that are not already present in the array
int int_array_concat_unique(Int_Array input, Int_Array* output){
int i;
for(i=0;i<input.length;i++){
int_array_append_unique(input.values[i],output);
}
return(0);
}
// find (does not assume the array is sorted) // find (does not assume the array is sorted)
int int_array_find(int val, Int_Array array){ int int_array_find(int val, Int_Array array){
int i; int i;
@ -199,7 +216,12 @@ int int_array_print(Int_Array array){
for(i=0;i<array.length-1;i++){ for(i=0;i<array.length-1;i++){
printf("%d,",array.values[i]); printf("%d,",array.values[i]);
} }
if(array.length>0){
printf("%d)",array.values[array.length-1]); printf("%d)",array.values[array.length-1]);
}
else{
printf(")");
}
return(0); return(0);
} }
@ -334,6 +356,19 @@ int char_array_concat(Char_Array input, Char_Array* output){
return(0); return(0);
} }
// substring
int char_array_substring(Char_Array str, int begin, int end, Char_Array* substr){
int i;
if(begin>end || begin<0 || end>=str.length){
fprintf(stderr,"error: cannot extract a substring [%d,%d] from a string of length %d\n", begin, end, str.length);
exit(-1);
}
init_Char_Array(substr,end-begin);
for(i=begin;i<=end;i++){
char_array_append(str.str[i],substr);
}
return(0);
}
// convert to char* // convert to char*
@ -343,7 +378,7 @@ int char_array_to_str(Char_Array input, char** output){
for(i=0;i<input.length;i++){ for(i=0;i<input.length;i++){
(*output)[i]=input.str[i]; (*output)[i]=input.str[i];
} }
if((*output)[input.length-1]!='\0'){ if(input.length==0 || (*output)[input.length-1]!='\0'){
(*output)[input.length]='\0'; (*output)[input.length]='\0';
} }
return(0); return(0);
@ -371,6 +406,34 @@ int str_to_char_array(char* str, Char_Array* output){
return(0); return(0);
} }
// compare char_array's
int char_array_cmp(Char_Array char_array1, Char_Array char_array2){
int j;
if(char_array1.length!=char_array2.length){
return(0);
}
for(j=0;j<char_array1.length && j<char_array2.length;j++){
if(char_array1.str[j]!=char_array2.str[j]){
return(0);
}
}
return(1);
}
// compare a char_array and a char*
int char_array_cmp_str(Char_Array char_array, char* str){
int j;
for(j=0;j<char_array.length && str[j]!='\0';j++){
if(char_array.str[j]!=str[j]){
return(0);
}
}
if(j==char_array.length && str[j]=='\0'){
return(1);
}
return(0);
}
// format strings // format strings
int char_array_snprintf(Char_Array* output, char* fmt, ...){ int char_array_snprintf(Char_Array* output, char* fmt, ...){

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -34,8 +34,12 @@ int int_array_resize(Int_Array* array, int newsize);
// add a value // add a value
int int_array_append(int val, Int_Array* output); int int_array_append(int val, Int_Array* output);
// add a value only if it is not already present
int int_array_append_unique(int val, Int_Array* output);
// concatenate // concatenate
int int_array_concat(Int_Array input, Int_Array* output); int int_array_concat(Int_Array input, Int_Array* output);
// concat but only add values that are not already present in the array
int int_array_concat_unique(Int_Array input, Int_Array* output);
// find (does not assume the array is sorted) // find (does not assume the array is sorted)
int int_array_find(int val, Int_Array array); int int_array_find(int val, Int_Array array);
@ -75,6 +79,9 @@ int char_array_append_str(char* str, Char_Array* output);
// concatenate // concatenate
int char_array_concat(Char_Array input, Char_Array* output); int char_array_concat(Char_Array input, Char_Array* output);
// substring
int char_array_substring(Char_Array str, int begin, int end, Char_Array* substr);
// convert to char* // convert to char*
int char_array_to_str(Char_Array input, char** output); int char_array_to_str(Char_Array input, char** output);
// noinit (changes the size of input if needed) // noinit (changes the size of input if needed)
@ -82,6 +89,11 @@ char* char_array_to_str_noinit(Char_Array* input);
// convert from char* // convert from char*
int str_to_char_array(char* str, Char_Array* output); int str_to_char_array(char* str, Char_Array* output);
// compare char_array's
int char_array_cmp(Char_Array char_array1, Char_Array char_array2);
// compare a char_array and a char*
int char_array_cmp_str(Char_Array char_array, char* str);
// format strings // format strings
int char_array_snprintf(Char_Array* output, char* fmt, ...); int char_array_snprintf(Char_Array* output, char* fmt, ...);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -121,3 +121,23 @@ int find_str_arg(char* title, Str_Array str_args){
} }
} }
// find a string argument with the specified title
// namespace support
int find_str_arg_ns(char* title, Char_Array namespace, Str_Array str_args){
Char_Array buffer;
int ret;
// append namespace to title
char_array_cpy(namespace,&buffer);
char_array_append(':',&buffer);
char_array_append_str(title,&buffer);
// check whether the namespace entry exists
ret=find_str_arg(char_array_to_str_noinit(&buffer), str_args);
free_Char_Array(buffer);
// if not, use global entry
if(ret==-1){
return(find_str_arg(title, str_args));
}
return(ret);
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -30,6 +30,8 @@ int read_config_file(Str_Array* str_args, const char* file, int read_from_stdin)
int get_str_arg_title(Char_Array str_arg, Char_Array* out); int get_str_arg_title(Char_Array str_arg, Char_Array* out);
// find a string argument with the specified title // find a string argument with the specified title
int find_str_arg(char* title, Str_Array str_args); int find_str_arg(char* title, Str_Array str_args);
// namespace support
int find_str_arg_ns(char* title, Char_Array namespace, Str_Array str_args);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -202,6 +202,235 @@ int coefficient_simplify(Coefficient* coefficient){
return(0); return(0);
} }
// put all terms under a common denominator and simplify the resulting fraction
int coefficient_simplify_rational(Coefficient constant, Coefficient* coefficient){
int ret;
Coefficient remainder;
Coefficient quotient;
Coefficient quotient_prev;
Coefficient out;
int power;
int max_power;
// common denominator
coefficient_common_denominator(constant, coefficient);
// init
init_Coefficient(&out, COEF_SIZE);
// simplify, one power at a time
// largest power (larger powers are at the end)
max_power=(*coefficient).denoms[(*coefficient).length-1].power;
quotient_prev=*coefficient;
for(power=max_power;power>=1;power--){
ret=coefficient_simplify_fraction(constant, quotient_prev, &remainder, &quotient);
// if fail to simplify, stop
if(ret<0){
if(power<max_power){
coefficient_concat_noinit(quotient_prev, &out);
}
else{
coefficient_concat(quotient_prev, &out);
}
break;
}
// add to output
coefficient_concat_noinit(remainder, &out);
}
// if the factorization always succeeded
if(max_power>=1 && power==0){
coefficient_concat_noinit(quotient, &out);
}
coefficient_simplify(&out);
// set coefficient to out
free_Coefficient(*coefficient);
*coefficient=out;
return 0;
}
// put all terms under a common denominator
// only supports coefficients with only one constant
int coefficient_common_denominator(Coefficient constant, Coefficient* coefficient){
int max_power;
int i,j;
Coefficient tmp;
Coefficient out;
Coefficient* C_n;
init_Coefficient(&out, COEF_SIZE);
// largest power (larger powers are at the end)
max_power=(*coefficient).denoms[(*coefficient).length-1].power;
// store powers of the constant
C_n=calloc(sizeof(Coefficient), max_power-1);
for(i=0;i<max_power-1;i++){
// start from previous product
if(i==0){
coefficient_cpy(constant, C_n+i);
}
else{
coefficient_cpy(C_n[i-1], C_n+i);
}
// multiply by constant
coefficient_prod_chain(constant, C_n+i);
}
// multiply each term
for (i=0;i<(*coefficient).length;i++){
init_Coefficient(&tmp, COEF_SIZE);
// start with numerator
coefficient_append_noinit((*coefficient).factors[i], (*coefficient).nums[i], (*coefficient).denoms[i], &tmp);
// multiply
if((*coefficient).denoms[i].power<max_power){
if((*coefficient).denoms[i].power==max_power-1){
coefficient_prod_chain(constant, &tmp);
}
else{
coefficient_prod_chain(C_n[max_power-(*coefficient).denoms[i].power-2], &tmp);
}
}
// set denom
for(j=0;j<tmp.length;j++){
tmp.denoms[j].power=max_power;
}
// add to out
coefficient_concat_noinit(tmp, &out);
}
// free C_n
for(i=0;i<max_power-1;i++){
free_Coefficient(C_n[i]);
}
free(C_n);
// free coefficient vectors
free((*coefficient).factors);
free((*coefficient).nums);
free((*coefficient).denoms);
// set output
*coefficient=out;
coefficient_simplify(coefficient);
return(0);
}
// simplify coefficient / constant
// returns both the remainder and the quotient
// assumes both coefficient and constant are ordered with the highest order terms last
int coefficient_simplify_fraction(Coefficient constant, Coefficient coefficient, Coefficient* remainder, Coefficient* out){
Coefficient tmp;
int step_counter=0;
int max_order;
int i,j,k;
Int_Array rfactors;
if(constant.length==0){
// nothing to do
return 0;
}
coefficient_cpy(coefficient, remainder);
init_Coefficient(out, COEF_SIZE);
// continue until (*remainder) is of lower order than constant
while((*remainder).length>0 && (*remainder).factors[(*remainder).length-1].length>=constant.factors[constant.length-1].length){
step_counter++;
// interrupt if too long
if(step_counter>=coefficient.length*100){
free_Coefficient(*remainder);
free_Coefficient(*out);
return -1;
}
// try to find a term in the constant that divides the last term of the (*remainder)
rfactors=(*remainder).factors[(*remainder).length-1];
// highest order in constant
max_order=constant.factors[constant.length-1].length;
// start from one of the highest order term and look for a common factor
for(i=constant.length-1; i>=0; i--){
// fail: no highest order terms have been matched
if(constant.factors[i].length<max_order){
free_Coefficient(*remainder);
free_Coefficient(*out);
return -2;
}
// check whether the term can be a factor of the last term of the (*remainder)
if(int_array_is_subarray_ordered(constant.factors[i], rfactors)==1){
// extract the factors that are not in constant
init_Coefficient(&tmp, constant.length);
// init with one term
tmp.length=1;
init_Int_Array(tmp.factors,MONOMIAL_SIZE);
for(j=0,k=0;j<rfactors.length;j++){
// check that index is not in constant
if(k<constant.factors[i].length){
if(rfactors.values[j]!=constant.factors[i].values[k]){
int_array_append(rfactors.values[j],tmp.factors);
}
else{
// move to next term in constant
k++;
}
}
}
// numerical prefactor: term in the (*remainder) / term in the constant
number_quot((*remainder).nums[(*remainder).length-1], constant.nums[i], tmp.nums);
// denominator (dummy)
tmp.denoms[0]=(*remainder).denoms[(*remainder).length-1];
// add to out
coefficient_concat(tmp, out);
// multiply by -1
Q minus_1;
minus_1.numerator=-1;
minus_1.denominator=1;
number_Qprod_chain(minus_1, tmp.nums);
// multiply by constant
coefficient_prod_chain(constant, &tmp);
// add to remainder
coefficient_concat(tmp, remainder);
// free memory
free_Coefficient(tmp);
// simplify
coefficient_simplify(remainder);
break;
}
}
}
// success!
// decrease power of constant
for(i=0;i<(*out).length;i++){
(*out).denoms[i].power=(*out).denoms[i].power-1;
}
return(0);
}
// sort the terms in an equation (quicksort algorithm) // sort the terms in an equation (quicksort algorithm)
int sort_coefficient(Coefficient* coefficient, int begin, int end){ int sort_coefficient(Coefficient* coefficient, int begin, int end){
int i; int i;
@ -251,7 +480,7 @@ int exchange_coefficient_terms(int i, int j, Coefficient* coefficient){
return(0); return(0);
} }
// derive a coefficient with respect to an index // differentiate a coefficient with respect to an index
int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output){ int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output){
int i,j; int i,j;
// temp list of indices // temp list of indices
@ -325,7 +554,7 @@ int coefficient_deriv(Coefficient input, int index, Coefficient* output){
} }
/* /*
// derive a coefficient with respect to an index (as a polynomial) (does not derive the 1/(1+C)^p ) // differentiate a coefficient with respect to an index (as a polynomial) (does not differentiate the 1/(1+C)^p )
int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output){ int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output){
int i; int i;
// temp list of indices // temp list of indices
@ -365,7 +594,7 @@ int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output){
return(0); return(0);
} }
// derive a monomial with respect to an index // differentiate a monomial with respect to an index
int monomial_deriv(Int_Array factor, int index, Int_Array* out_factor, int* match_count){ int monomial_deriv(Int_Array factor, int index, Int_Array* out_factor, int* match_count){
int j; int j;
@ -414,14 +643,14 @@ int coefficient_prod(Coefficient coef1, Coefficient coef2, Coefficient* output){
int_array_concat(coef2.factors[j],&factor); int_array_concat(coef2.factors[j],&factor);
// don't throw an error if the power is 0 // don't throw an error if the power is 0
if(coef2.denoms[i].power==0){ if(coef2.denoms[j].power==0){
coef2.denoms[i].index=coef1.denoms[i].index; coef2.denoms[j].index=coef1.denoms[i].index;
} }
else if(coef1.denoms[i].power==0){ else if(coef1.denoms[i].power==0){
coef1.denoms[i].index=coef2.denoms[i].index; coef1.denoms[i].index=coef2.denoms[j].index;
} }
if(coef1.denoms[i].index!=coef2.denoms[j].index){ if(coef1.denoms[i].index!=coef2.denoms[j].index){
fprintf(stderr,"error: cannot multiply flow equations with different constants\n"); fprintf(stderr,"error: cannot multiply flow equations with different constants: got %d and %d\n", coef1.denoms[i].index, coef2.denoms[j].index);
exit(-1); exit(-1);
} }
denom=coef1.denoms[i]; denom=coef1.denoms[i];

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -48,12 +48,20 @@ int coefficient_concat_noinit(Coefficient input, Coefficient* output);
// simplify a Coefficient // simplify a Coefficient
int coefficient_simplify(Coefficient* coefficient); int coefficient_simplify(Coefficient* coefficient);
// put all terms under a common denominator and simplify the resulting fraction
int coefficient_simplify_rational(Coefficient constant, Coefficient* coefficient);
// put all terms under a common denominator
int coefficient_common_denominator(Coefficient constant, Coefficient* coefficient);
// simplify coefficient / constant
int coefficient_simplify_fraction(Coefficient constant, Coefficient coefficient, Coefficient* remainder, Coefficient* out);
// sort the terms in an equation (quicksort algorithm) // sort the terms in an equation (quicksort algorithm)
int sort_coefficient(Coefficient* coefficient, int begin, int end); int sort_coefficient(Coefficient* coefficient, int begin, int end);
// exchange two terms (for the sorting algorithm) // exchange two terms (for the sorting algorithm)
int exchange_coefficient_terms(int i, int j, Coefficient* coefficient); int exchange_coefficient_terms(int i, int j, Coefficient* coefficient);
// derive a coefficient with respect to an index (as a polynomial) (does not derive the 1/(1+C)^p ) // differentiate a coefficient with respect to an index (as a polynomial) (does not differentiate the 1/(1+C)^p )
int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output); int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output);
int coefficient_deriv(Coefficient input, int index, Coefficient* output); int coefficient_deriv(Coefficient input, int index, Coefficient* output);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -33,10 +33,16 @@ limitations under the License.
#define EQUATION_SIZE 20 #define EQUATION_SIZE 20
// number of fields // number of fields
#define FIELDS_SIZE 50 #define FIELDS_SIZE 50
// number of variables
#define VARIABLES_SIZE 10
// number of elements in numbers // number of elements in numbers
#define NUMBER_SIZE 5 #define NUMBER_SIZE 5
// number of elements in a group // number of elements in a group
#define GROUP_SIZE 5 #define GROUP_SIZE 5
// number of children per node in a symbol_tree
#define SYMBOL_TREE_SIZE 2
// size of character string in symbol tree
#define SYMBOL_TREE_LABEL_SIZE 10
// display options // display options
@ -55,6 +61,6 @@ limitations under the License.
#define FIELD_PARAMETER 1 #define FIELD_PARAMETER 1
#define FIELD_EXTERNAL 2 #define FIELD_EXTERNAL 2
#define FIELD_INTERNAL 3 #define FIELD_INTERNAL 3
#define FIELD_SYMBOL 4 #define FIELD_VIRTUAL 4
#endif #endif

93
src/determinant.c Normal file
View File

@ -0,0 +1,93 @@
#include "determinant.h"
#include "number.h"
#include "rational.h"
#include "definitions.cpp"
// determinant of a matrix
// replaces the matrix by its LU decomposition
int determinant_inplace(Number_Matrix M, Number* out){
int i;
int sign_correction;
LU_dcmp_inplace(M, &sign_correction);
if(sign_correction==0){
*out=number_zero();
return(0);
}
*out=number_one();
if(sign_correction==-1){
number_Qprod_chain(quot(-1,1), out);
}
for(i=0;i<M.length;i++){
number_prod_chain(M.matrix[i][i], out);
}
return(0);
}
// LU decomposition
// uses pivoting to avoid dividing by 0
// the sign_correction should be multiplied to the determinant to obtain the right value
// if dividing by 0 is unavoidable, then the determinant is 0, and sign_correction is set to 0
int LU_dcmp_inplace(Number_Matrix M, int* sign_correction){
int i,j,k,pivot;
Number tmp;
*sign_correction=1;
for(j=0;j<M.length;j++){
for(i=0;i<=j;i++){
for(k=0;k<i;k++){
// -M[i][k]*M[k][j]
number_prod(M.matrix[i][k], M.matrix[k][j], &tmp);
number_Qprod_chain(quot(-1,1), &tmp);
number_add_chain(tmp, M.matrix[i]+j);
free_Number(tmp);
}
}
for(i=j+1;i<M.length;i++){
for(k=0;k<j;k++){
// -M[i][k]*M[k][j]
number_prod(M.matrix[i][k], M.matrix[k][j], &tmp);
number_Qprod_chain(quot(-1,1), &tmp);
number_add_chain(tmp, M.matrix[i]+j);
free_Number(tmp);
}
}
// pivot if M[j][j]==0
// find first M[j][j] that is not 0
for(pivot=j;pivot<M.length && number_is_zero(M.matrix[pivot][j])==1;pivot++){}
// no non-zero M[j][j] left: return
if(pivot>=M.length){
*sign_correction=0;
return(0);
}
// pivot if needed
if(pivot!=j){
for(k=0;k<M.length;k++){
tmp=M.matrix[j][k];
M.matrix[j][k]=M.matrix[pivot][k];
M.matrix[pivot][k]=tmp;
}
*sign_correction*=-1;
}
for(i=j+1;i<M.length;i++){
// do not use the inplace algorithm if M[j][j] has more than one terms, since it would be modified by the inplace function
if(M.matrix[j][j].length<=1){
number_quot_inplace(M.matrix[i]+j, M.matrix[j]+j);
}
else{
number_quot_chain(M.matrix[i]+j, M.matrix[j][j]);
}
}
}
return(0);
}

17
src/determinant.h Normal file
View File

@ -0,0 +1,17 @@
/*
Compute the determinant of a number matrix
*/
#ifndef DETERMINANT_H
#define DETERMINANT_H
#include "types.h"
// determinant of a matrix
int determinant_inplace(Number_Matrix M, Number* out);
// LU decomposition
int LU_dcmp_inplace(Number_Matrix M, int* sign_correction);
#endif

View File

@ -1,28 +0,0 @@
/*
Copyright 2015 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 "expansions.h"
#include <stdio.h>
#include <stdlib.h>
#include "definitions.cpp"
#include "tools.h"
#include "array.h"
#include "polynomial.h"
#include "number.h"
#include "rational.h"

View File

@ -1,34 +0,0 @@
/*
Copyright 2015 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.
*/
/*
Compute exp(V) and log(1+W)
*/
#ifndef EXPANSIONS_H
#define EXPANSIONS_H
#include "polynomial.h"
#include "fields.h"
// exp(V)
int expand_exponential(Polynomial input_polynomial,Polynomial* output, Fields_Table fields);
// log(1+W)
int expand_logarithm(Polynomial input_polynomial, Polynomial* output, Fields_Table fields);
#endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with 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 "polynomial.h"
#include "array.h" #include "array.h"
#include "rational.h" #include "rational.h"
#include "tree.h"
//---------------------------------------------------------------------
//
// Fields_Table
//
//---------------------------------------------------------------------
// init and free for Fields_Table // init and free for Fields_Table
int init_Fields_Table(Fields_Table* fields){ 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).external),FIELDS_SIZE);
init_Int_Array(&((*fields).internal),FIELDS_SIZE); init_Int_Array(&((*fields).internal),FIELDS_SIZE);
init_Identities(&((*fields).ids), 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).fermions),FIELDS_SIZE);
init_Int_Array(&((*fields).noncommuting),FIELDS_SIZE); init_Int_Array(&((*fields).noncommuting),FIELDS_SIZE);
return(0); return(0);
@ -40,7 +47,7 @@ int free_Fields_Table(Fields_Table fields){
free_Int_Array(fields.external); free_Int_Array(fields.external);
free_Int_Array(fields.internal); free_Int_Array(fields.internal);
free_Identities(fields.ids); free_Identities(fields.ids);
free_Symbols(fields.symbols); free_Virtual_fields(fields.virtual_fields);
free_Int_Array(fields.fermions); free_Int_Array(fields.fermions);
free_Int_Array(fields.noncommuting); free_Int_Array(fields.noncommuting);
return(0); return(0);
@ -57,11 +64,11 @@ int field_type(int index, Fields_Table fields){
else if(int_array_find(abs(index), fields.internal)>=0){ else if(int_array_find(abs(index), fields.internal)>=0){
return(FIELD_INTERNAL); return(FIELD_INTERNAL);
} }
else if(intlist_find(fields.symbols.indices, fields.symbols.length, index)>=0){ else if(intlist_find(fields.virtual_fields.indices, fields.virtual_fields.length, index)>=0){
return(FIELD_SYMBOL); 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); exit(-1);
} }
@ -86,7 +93,11 @@ int is_noncommuting(int index, Fields_Table fields){
} }
// ------------------ Identities -------------------- //---------------------------------------------------------------------
//
// Identities
//
//---------------------------------------------------------------------
// allocate memory // allocate memory
int init_Identities(Identities* identities,int size){ 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 match_nc;
int first=-1; int first=-1;
// cannot fit
if(test_array.length<input.length){
return(-1);
}
// bound noncommuting elements // bound noncommuting elements
while(is_noncommuting(input.values[post_nc], fields)==1){ while(is_noncommuting(input.values[post_nc], fields)==1){
post_nc++; post_nc++;
@ -324,7 +340,7 @@ int int_array_is_subarray_noncommuting(Int_Array input, Int_Array test_array, Fi
match_nc=1; match_nc=1;
} }
for(j=1;j<post_nc;j++){ for(j=1;j<post_nc;j++){
if(test_array.values[i+j]!=input.values[j]){ if(i+j>=test_array.length || test_array.values[i+j]!=input.values[j]){
match_nc=0; 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 // allocate memory
int init_Symbols(Symbols* symbols,int size){ int init_Virtual_fields(Virtual_fields* virtual_fields,int size){
(*symbols).indices=calloc(size,sizeof(int)); (*virtual_fields).indices=calloc(size,sizeof(int));
(*symbols).expr=calloc(size,sizeof(Polynomial)); (*virtual_fields).expr=calloc(size,sizeof(Polynomial));
(*symbols).length=0; (*virtual_fields).length=0;
(*symbols).memory=size; (*virtual_fields).memory=size;
return(0); return(0);
} }
// free memory // free memory
int free_Symbols(Symbols symbols){ int free_Virtual_fields(Virtual_fields virtual_fields){
int i; int i;
for(i=0;i<symbols.length;i++){ for(i=0;i<virtual_fields.length;i++){
free_Polynomial(symbols.expr[i]); free_Polynomial(virtual_fields.expr[i]);
} }
free(symbols.indices); free(virtual_fields.indices);
free(symbols.expr); free(virtual_fields.expr);
return(0); return(0);
} }
// resize // resize
int resize_symbols(Symbols* symbols,int new_size){ int resize_virtual_fields(Virtual_fields* virtual_fields,int new_size){
Symbols new_symbols; Virtual_fields new_virtual_fields;
int i; int i;
init_Symbols(&new_symbols,new_size); init_Virtual_fields(&new_virtual_fields,new_size);
for(i=0;i<(*symbols).length;i++){ for(i=0;i<(*virtual_fields).length;i++){
new_symbols.indices[i]=(*symbols).indices[i]; new_virtual_fields.indices[i]=(*virtual_fields).indices[i];
new_symbols.expr[i]=(*symbols).expr[i]; new_virtual_fields.expr[i]=(*virtual_fields).expr[i];
} }
new_symbols.length=(*symbols).length; new_virtual_fields.length=(*virtual_fields).length;
free((*symbols).indices); free((*virtual_fields).indices);
free((*symbols).expr); free((*virtual_fields).expr);
*symbols=new_symbols; *virtual_fields=new_virtual_fields;
return(0); return(0);
} }
// copy // copy
int symbols_cpy(Symbols input, Symbols* output){ int virtual_fields_cpy(Virtual_fields input, Virtual_fields* output){
init_Symbols(output,input.length); init_Virtual_fields(output,input.length);
symbols_cpy_noinit(input,output); virtual_fields_cpy_noinit(input,output);
return(0); return(0);
} }
int symbols_cpy_noinit(Symbols input, Symbols* output){ int virtual_fields_cpy_noinit(Virtual_fields input, Virtual_fields* output){
int i; int i;
if((*output).memory<input.length){ if((*output).memory<input.length){
fprintf(stderr,"error: trying to copy a symbols collection of length %d to another with memory %d\n",input.length,(*output).memory); fprintf(stderr,"error: trying to copy a virtual fields collection of length %d to another with memory %d\n",input.length,(*output).memory);
exit(-1); exit(-1);
} }
for(i=0;i<input.length;i++){ for(i=0;i<input.length;i++){
@ -421,12 +441,12 @@ int symbols_cpy_noinit(Symbols input, Symbols* output){
return(0); return(0);
} }
// append an element to a symbols // append an element to a virtual_fields
int symbols_append(int index, Polynomial expr, Symbols* output){ int virtual_fields_append(int index, Polynomial expr, Virtual_fields* output){
int offset=(*output).length; int offset=(*output).length;
if((*output).length>=(*output).memory){ if((*output).length>=(*output).memory){
resize_symbols(output,2*(*output).memory+1); resize_virtual_fields(output,2*(*output).memory+1);
} }
// copy and allocate // copy and allocate
@ -436,12 +456,12 @@ int symbols_append(int index, Polynomial expr, Symbols* output){
(*output).length++; (*output).length++;
return(0); return(0);
} }
// append an element to a symbols without allocating memory // append an element to a virtual_fields without allocating memory
int symbols_append_noinit(int index, Polynomial expr, Symbols* output){ int virtual_fields_append_noinit(int index, Polynomial expr, Virtual_fields* output){
int offset=(*output).length; int offset=(*output).length;
if((*output).length>=(*output).memory){ if((*output).length>=(*output).memory){
resize_symbols(output,2*(*output).memory+1); resize_virtual_fields(output,2*(*output).memory+1);
} }
// copy without allocating // copy without allocating
@ -452,18 +472,22 @@ int symbols_append_noinit(int index, Polynomial expr, Symbols* output){
return(0); return(0);
} }
// concatenate two symbolss // concatenate two virtual_fields
int symbols_concat(Symbols input, Symbols* output){ int virtual_fields_concat(Virtual_fields input, Virtual_fields* output){
int i; int i;
for(i=0;i<input.length;i++){ for(i=0;i<input.length;i++){
symbols_append(input.indices[i],input.expr[i],output); virtual_fields_append(input.indices[i],input.expr[i],output);
} }
return(0); return(0);
} }
// ------------------ Groups -------------------- //---------------------------------------------------------------------
//
// Groups
//
//---------------------------------------------------------------------
// allocate memory // allocate memory
int init_Groups(Groups* groups,int size){ int init_Groups(Groups* groups,int size){
@ -570,3 +594,164 @@ int find_group(int index, Groups groups){
} }
return(-1); return(-1);
} }
//---------------------------------------------------------------------
//
// Variables
//
//---------------------------------------------------------------------
// allocate memory
int init_Variables(Variables* variables,int size){
(*variables).var_names=calloc(size,sizeof(Char_Array));
(*variables).symbol_trees=calloc(size,sizeof(Tree));
(*variables).length=0;
(*variables).memory=size;
return(0);
}
// free memory
int free_Variables(Variables variables){
int i;
for(i=0;i<variables.length;i++){
free_Char_Array(variables.var_names[i]);
free_Tree(variables.symbol_trees[i]);
}
free(variables.var_names);
free(variables.symbol_trees);
return(0);
}
// resize
int resize_variables(Variables* variables,int new_size){
Variables new_variables;
int i;
init_Variables(&new_variables,new_size);
for(i=0;i<(*variables).length;i++){
new_variables.var_names[i]=(*variables).var_names[i];
new_variables.symbol_trees[i]=(*variables).symbol_trees[i];
}
new_variables.length=(*variables).length;
free((*variables).var_names);
free((*variables).symbol_trees);
*variables=new_variables;
return(0);
}
// copy
int variables_cpy(Variables input, Variables* output){
init_Variables(output,input.length);
variables_cpy_noinit(input,output);
return(0);
}
int variables_cpy_noinit(Variables input, Variables* output){
int i;
if((*output).memory<input.length){
fprintf(stderr,"error: trying to copy a variables collection of length %d to another with memory %d\n",input.length,(*output).memory);
exit(-1);
}
for(i=0;i<input.length;i++){
char_array_cpy(input.var_names[i], (*output).var_names+i);
tree_cpy(input.symbol_trees[i],(*output).symbol_trees+i);
}
(*output).length=input.length;
return(0);
}
// append an element to a variables collection
int variables_append(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 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<input.length;i++){
variables_append(input.var_names[i], input.symbol_trees[i], output);
}
return(0);
}
// find a variable matching a var_name
int variables_find_var(Char_Array name, Variables variables, Tree* output){
Char_Array varname;
int i;
// drop inital '$'
char_array_substring(name, 1, name.length-1, &varname);
for(i=0;i<variables.length;i++){
if(char_array_cmp(varname, variables.var_names[i])==1){
tree_cpy(variables.symbol_trees[i], output);
break;
}
}
// error if no variable was found
if(i==variables.length){
fprintf(stderr, "error: variable '$%s' not found\n",char_array_to_str_noinit(&varname));
exit(-1);
}
free_Char_Array(varname);
return(0);
}
// add a polynomials as a new named variable
int add_polynomial_to_variables(char* name, Polynomial polynomial, Variables* variables){
// save polynomial to string (to convert it to a variable, it must first be a string)
Char_Array poly_str;
Char_Array out_name;
Tree out_tree;
init_Char_Array(&poly_str, STR_SIZE);
polynomial_sprint(polynomial, &poly_str);
// convert name to Char_Array
init_Char_Array(&out_name,STR_SIZE);
char_array_append_str(name, &out_name);
// trivial tree containing the polynomial
init_Tree(&out_tree,0,poly_str.length);
tree_set_label(poly_str, &out_tree);
free_Char_Array(poly_str);
// add variable
variables_append(out_name, out_tree, variables);
free_Tree(out_tree);
free_Char_Array(out_name);
return 0;
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -21,6 +21,9 @@ limitations under the License.
#include "types.h" #include "types.h"
// Fields_Table
// init // init
int init_Fields_Table(Fields_Table* fields); int init_Fields_Table(Fields_Table* fields);
int free_Fields_Table(Fields_Table fields); int free_Fields_Table(Fields_Table fields);
@ -33,6 +36,8 @@ int is_fermion(int index, Fields_Table fields);
int is_noncommuting(int index, Fields_Table fields); int is_noncommuting(int index, Fields_Table fields);
// Identities
// init // init
int init_Identities(Identities* identities,int size); int init_Identities(Identities* identities,int size);
int free_Identities(Identities identities); int free_Identities(Identities identities);
@ -57,25 +62,29 @@ int resolve_ids(Polynomial* polynomial, Fields_Table fields);
int int_array_is_subarray_noncommuting(Int_Array input, Int_Array test_array, Fields_Table fields); int int_array_is_subarray_noncommuting(Int_Array input, Int_Array test_array, Fields_Table fields);
// Virtual_fields
// init // init
int init_Symbols(Symbols* symbols,int size); int init_Virtual_fields(Virtual_fields* virtual_fields,int size);
int free_Symbols(Symbols symbols); int free_Virtual_fields(Virtual_fields virtual_fields);
// resize // resize
int resize_symbols(Symbols* symbols,int new_size); int resize_virtual_fields(Virtual_fields* virtual_fields,int new_size);
// copy // copy
int symbols_cpy(Symbols input, Symbols* output); int virtual_fields_cpy(Virtual_fields input, Virtual_fields* output);
int symbols_cpy_noinit(Symbols input, Symbols* output); int virtual_fields_cpy_noinit(Virtual_fields input, Virtual_fields* output);
// append an element to a symbols // append an element to a virtual_fields
int symbols_append(int index, Polynomial expr, Symbols* output); int virtual_fields_append(int index, Polynomial expr, Virtual_fields* output);
int symbols_append_noinit(int index, Polynomial expr, Symbols* output); int virtual_fields_append_noinit(int index, Polynomial expr, Virtual_fields* output);
// concatenate two symbolss // concatenate two virtual_fields
int symbols_concat(Symbols input, Symbols* output); int virtual_fields_concat(Virtual_fields input, Virtual_fields* output);
// Groups
// init // init
int init_Groups(Groups* groups,int size); int init_Groups(Groups* groups,int size);
int free_Groups(Groups groups); int free_Groups(Groups groups);
@ -98,5 +107,32 @@ int groups_concat(Groups input, Groups* output);
int find_group(int index, Groups groups); int find_group(int index, Groups groups);
// Variables
// allocate memory
int init_Variables(Variables* variables,int size);
// free memory
int free_Variables(Variables variables);
// resize
int resize_variables(Variables* variables,int new_size);
// copy
int variables_cpy(Variables input, Variables* output);
int variables_cpy_noinit(Variables input, Variables* output);
// append an element to a variables collection
int variables_append(Char_Array var_name, Tree symbol_tree, Variables* output);
int variables_append_noinit(Char_Array var_name, Tree symbol_tree, Variables* output);
// concatenate two variables collections
int variables_concat(Variables input, Variables* output);
// find a variable matching a var_name
int variables_find_var(Char_Array name, Variables variables, Tree* output);
// add a polynomials as a new named variable
int add_polynomial_to_variables(char* name, Polynomial polynomial, Variables* variables);
#define FIELDS_H_DONE #define FIELDS_H_DONE
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -25,14 +25,20 @@ limitations under the License.
#include "array.h" #include "array.h"
#include "coefficient.h" #include "coefficient.h"
#include "rcc.h" #include "rcc.h"
#include "grouped_polynomial.h"
// compute flow numerically, no exponentials // compute flow numerically, no exponentials
int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, int niter, int display_mode){ int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Grouped_Polynomial postprocess_flow_equation, Labels labels, int niter, int display_mode){
// running coupling contants // running coupling contants
RCC rccs=init; RCC rccs=init;
// for printing
RCC rcc_print;
int i,j; int i,j;
// init printing rcc
init_RCC(&rcc_print, rccs.length);
if(display_mode==DISPLAY_NUMERICAL){ if(display_mode==DISPLAY_NUMERICAL){
// print labels // print labels
printf("%5s ","n"); printf("%5s ","n");
@ -42,23 +48,59 @@ int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, in
printf("\n\n"); printf("\n\n");
// print initial values // print initial values
RCC_cpy_noinit(rccs,&rcc_print);
if(postprocess_flow_equation.length>0){
// ignore constants
for(j=0;j<rcc_print.length;j++){
if(rcc_print.indices[j]<0){
rcc_print.values[j]=1.;
}
}
evaleq(rcc_print, rcc_print, postprocess_flow_equation);
}
printf("%5d ",0); printf("%5d ",0);
for(j=0;j<rccs.length;j++){ for(j=0;j<rcc_print.length;j++){
// use constants from rcc
if(rcc_print.indices[j]<0){
printf("% 14.7Le ",rccs.values[j]); printf("% 14.7Le ",rccs.values[j]);
} }
else{
printf("% 14.7Le ",rcc_print.values[j]);
}
}
printf("\n"); printf("\n");
} }
for(i=0;i<niter;i++){ for(i=0;i<niter;i++){
// compute a single step // compute a single step
step_flow(&rccs, flow_equation); step_flow(&rccs, flow_equation);
// convert ls to alphas
// print
if(postprocess_flow_equation.length>0){
RCC_cpy_noinit(rccs,&rcc_print);
// ignore constants
for(j=0;j<rcc_print.length;j++){
if(rcc_print.indices[j]<0){
rcc_print.values[j]=1.;
}
}
evaleq(rcc_print, rcc_print, postprocess_flow_equation);
}
else{
RCC_cpy_noinit(rccs,&rcc_print);
}
if(display_mode==DISPLAY_NUMERICAL){ if(display_mode==DISPLAY_NUMERICAL){
// print the result // print the result
printf("%5d ",i+1); printf("%5d ",i+1);
for(j=0;j<rccs.length;j++){ for(j=0;j<rcc_print.length;j++){
// use constants from rcc
if(rcc_print.indices[j]<0){
printf("% 14.7Le ",rccs.values[j]); printf("% 14.7Le ",rccs.values[j]);
} }
else{
printf("% 14.7Le ",rcc_print.values[j]);
}
}
printf("\n"); printf("\n");
} }
} }
@ -74,8 +116,23 @@ int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, in
} }
if(display_mode==DISPLAY_FINAL){ if(display_mode==DISPLAY_FINAL){
RCC_print(rccs); if(postprocess_flow_equation.length>0){
RCC_cpy_noinit(rccs,&rcc_print);
// ignore constants
for(j=0;j<rcc_print.length;j++){
if(rcc_print.indices[j]<0){
rcc_print.values[j]=1.;
} }
}
evaleq(rcc_print, rcc_print, postprocess_flow_equation);
}
else{
RCC_cpy_noinit(rccs,&rcc_print);
}
RCC_print(rcc_print);
}
free_RCC(rcc_print);
return(0); return(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ Compute flow numerically
#include "types.h" #include "types.h"
// compute flow // compute flow
int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, int niter, int display_mode); int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Grouped_Polynomial postprocess_flow_equation, Labels labels, int niter, int display_mode);
// single step // single step
int step_flow(RCC* rccs, Grouped_Polynomial flow_equation); int step_flow(RCC* rccs, Grouped_Polynomial flow_equation);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -32,14 +32,21 @@ limitations under the License.
#include "coefficient.h" #include "coefficient.h"
#include "flow.h" #include "flow.h"
#include "rcc_mpfr.h" #include "rcc_mpfr.h"
#include "grouped_polynomial.h"
// compute flow numerically // compute flow numerically
int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels labels, int niter, int display_mode){ int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Grouped_Polynomial postprocess_flow_equation, Labels labels, int niter, int display_mode){
// running coupling contants // running coupling contants
RCC_mpfr rccs=init; RCC_mpfr rccs=init;
int i,j; int i,j;
// for printing
RCC_mpfr rcc_print;
// init printing rcc
init_RCC_mpfr(&rcc_print, rccs.length);
if(display_mode==DISPLAY_NUMERICAL){ if(display_mode==DISPLAY_NUMERICAL){
// print labels // print labels
@ -50,23 +57,56 @@ int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels
printf("\n\n"); printf("\n\n");
// print initial values // print initial values
RCC_mpfr_cpy_noinit(rccs,&rcc_print);
if(postprocess_flow_equation.length>0){
// ignore constants
for(j=0;j<rcc_print.length;j++){
if(rcc_print.indices[j]<0){
mpfr_set_ui(rcc_print.values[j], 1, MPFR_RNDN);
}
}
evaleq_mpfr(rcc_print, rccs, postprocess_flow_equation);
}
printf("%5d ",0); printf("%5d ",0);
for(j=0;j<rccs.length;j++){ for(j=0;j<rcc_print.length;j++){
// use constants from rcc
if(rcc_print.indices[j]<0){
mpfr_printf("% 14.7Re ",rccs.values[j]); mpfr_printf("% 14.7Re ",rccs.values[j]);
} }
else{
mpfr_printf("% 14.7Re ",rcc_print.values[j]);
}
}
printf("\n"); printf("\n");
} }
for(i=0;i<niter;i++){ for(i=0;i<niter;i++){
// compute a single step // compute a single step
step_flow_mpfr(&rccs, flow_equation); step_flow_mpfr(&rccs, flow_equation);
// convert ls to alphas
// print
RCC_mpfr_cpy_noinit(rccs,&rcc_print);
if(postprocess_flow_equation.length>0){
// ignore constants
for(j=0;j<rcc_print.length;j++){
if(rcc_print.indices[j]<0){
mpfr_set_ui(rcc_print.values[j], 1, MPFR_RNDN);
}
}
evaleq_mpfr(rcc_print, rccs, postprocess_flow_equation);
}
if(display_mode==DISPLAY_NUMERICAL){ if(display_mode==DISPLAY_NUMERICAL){
// print the result // print the result
printf("%5d ",i+1); printf("%5d ",i+1);
for(j=0;j<rccs.length;j++){ for(j=0;j<rcc_print.length;j++){
// use constants from rcc
if(rcc_print.indices[j]<0){
mpfr_printf("% 14.7Re ",rccs.values[j]); mpfr_printf("% 14.7Re ",rccs.values[j]);
} }
else{
mpfr_printf("% 14.7Re ",rcc_print.values[j]);
}
}
printf("\n"); printf("\n");
} }
} }
@ -82,9 +122,16 @@ int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels
} }
if(display_mode==DISPLAY_FINAL){ if(display_mode==DISPLAY_FINAL){
RCC_mpfr_print(rccs); if(postprocess_flow_equation.length>0){
evaleq_mpfr(rcc_print, rccs, postprocess_flow_equation);
}
else{
rcc_print=rccs;
}
RCC_mpfr_print(rcc_print);
} }
free_RCC_mpfr(rcc_print);
return(0); return(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ Compute flow numerically
#include "types.h" #include "types.h"
// compute flow // compute flow
int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels labels, int niter, int display_mode); int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Grouped_Polynomial postprocess_flow_equation, Labels labels, int niter, int display_mode);
// single step // single step
int step_flow_mpfr(RCC_mpfr* rccs, Grouped_Polynomial flow_equation); int step_flow_mpfr(RCC_mpfr* rccs, Grouped_Polynomial flow_equation);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -205,9 +205,9 @@ int group_polynomial(Polynomial polynomial, Grouped_Polynomial* grouped_polynomi
if(index==-2){ if(index==-2){
fprintf(stderr,"error: monomial ("); fprintf(stderr,"error: monomial (");
for(j=0;j<polynomial.monomials[i].length;j++){ for(j=0;j<remainder.monomials[i].length;j++){
fprintf(stderr,"%d", polynomial.monomials[i].values[j]); fprintf(stderr,"%d", remainder.monomials[i].values[j]);
if(j<polynomial.monomials[i].length-1){ if(j<remainder.monomials[i].length-1){
fprintf(stderr,","); fprintf(stderr,",");
} }
} }
@ -436,7 +436,7 @@ int simplify_grouped_polynomial(Grouped_Polynomial* polynomial){
} }
// derive a flow equation with respect to an unknown variable // differentiate a flow equation with respect to an unknown variable
// equivalent to DB.dl where dl are symbols for the derivatives of the indices in the flow equation with respect to the unknown variable // equivalent to DB.dl where dl are symbols for the derivatives of the indices in the flow equation with respect to the unknown variable
// indices specifies the list of indices that depend on the variable // indices specifies the list of indices that depend on the variable
int flow_equation_derivx(Grouped_Polynomial flow_equation, Int_Array indices, Grouped_Polynomial* dflow){ int flow_equation_derivx(Grouped_Polynomial flow_equation, Int_Array indices, Grouped_Polynomial* dflow){
@ -487,7 +487,7 @@ int flow_equation_derivx(Grouped_Polynomial flow_equation, Int_Array indices, Gr
/* /*
// derive a flow equation with respect to an index // differentiate a flow equation with respect to an index
int flow_equation_deriv(Grouped_Polynomial flow_equation, int index, Grouped_Polynomial* output){ int flow_equation_deriv(Grouped_Polynomial flow_equation, int index, Grouped_Polynomial* output){
int i,k; int i,k;
// temp list of indices // temp list of indices
@ -603,7 +603,7 @@ int grouped_polynomial_print(Grouped_Polynomial grouped_polynomial, char lhs_pre
init_Char_Array(&buffer, STR_SIZE); init_Char_Array(&buffer, STR_SIZE);
coefficient_sprint(grouped_polynomial.coefs[i],&buffer,9,rhs_pre); coefficient_sprint(grouped_polynomial.coefs[i],&buffer,9,rhs_pre);
if(buffer.length>0){ if(buffer.length>0){
printf("%s",buffer.str); printf("%s",char_array_to_str_noinit(&buffer));
} }
free_Char_Array(buffer); free_Char_Array(buffer);
@ -732,29 +732,33 @@ int char_array_to_Grouped_Polynomial(Char_Array str, Grouped_Polynomial* output)
} }
// eValuate an equation on a vector // evaluate an equation on a vector
int evaleq(RCC* rccs, Grouped_Polynomial poly){ int evaleq(RCC out, RCC in, Grouped_Polynomial poly){
int i; int i;
long double* res=calloc((*rccs).length,sizeof(long double)); long double* res=calloc(out.length,sizeof(long double));
if((*rccs).length!=poly.length){ if(in.length!=poly.length){
fprintf(stderr, "error: trying to evaluate an flow equation with %d components on an rcc with %d\n",poly.length,(*rccs).length); fprintf(stderr, "error: trying to evaluate a flow equation with %d components on an rcc with %d\n",poly.length,in.length);
exit(-1);
}
if(out.length!=poly.length){
fprintf(stderr, "error: trying to write the output of a flow equation with %d components on an rcc with %d\n",poly.length,out.length);
exit(-1); exit(-1);
} }
// initialize vectors to 0 // initialize vectors to 0 in an auxiliary vector (to allow for out=in without interference)
for(i=0;i<(*rccs).length;i++){ for(i=0;i<in.length;i++){
res[i]=0.; res[i]=0.;
} }
// for each equation // for each equation
for(i=0;i<poly.length;i++){ for(i=0;i<poly.length;i++){
evalcoef(*rccs, poly.coefs[i], res+i); evalcoef(in, poly.coefs[i], res+i);
} }
// copy res to rccs // copy res to rccs
for(i=0;i<(*rccs).length;i++){ for(i=0;i<out.length;i++){
(*rccs).values[i]=res[i]; out.values[i]=res[i];
} }
// free memory // free memory
@ -763,25 +767,29 @@ int evaleq(RCC* rccs, Grouped_Polynomial poly){
} }
// evaluate an equation on a vector (using mpfr floats) // evaluate an equation on a vector (using mpfr floats)
int evaleq_mpfr(RCC_mpfr* rccs, Grouped_Polynomial poly){ int evaleq_mpfr(RCC_mpfr out, RCC_mpfr in, Grouped_Polynomial poly){
int i; int i;
mpfr_t* res; mpfr_t* res;
if((*rccs).length!=poly.length){ if(in.length!=poly.length){
fprintf(stderr, "error: trying to evaluate an flow equation with %d components on an rcc with %d\n",poly.length,(*rccs).length); fprintf(stderr, "error: trying to evaluate a flow equation with %d components on an rcc with %d\n",poly.length,in.length);
exit(-1);
}
if(out.length!=poly.length){
fprintf(stderr, "error: trying to write the output of a flow equation with %d components on an rcc with %d\n",poly.length,out.length);
exit(-1); exit(-1);
} }
res=calloc((*rccs).length,sizeof(mpfr_t)); res=calloc(out.length,sizeof(mpfr_t));
// for each equation // for each equation
for(i=0;i<poly.length;i++){ for(i=0;i<poly.length;i++){
evalcoef_mpfr(*rccs, poly.coefs[i], res[i]); evalcoef_mpfr(in, poly.coefs[i], res[i]);
} }
// copy res to rccs // copy res to rccs
for(i=0;i<(*rccs).length;i++){ for(i=0;i<out.length;i++){
mpfr_set((*rccs).values[i], res[i], MPFR_RNDN); mpfr_set(out.values[i], res[i], MPFR_RNDN);
mpfr_clear(res[i]); mpfr_clear(res[i]);
} }
@ -791,3 +799,85 @@ int evaleq_mpfr(RCC_mpfr* rccs, Grouped_Polynomial poly){
} }
// compose two flow equations (replace the rcc's of flow1 by the right hand side of flow2)
int compose_flow_equations(Grouped_Polynomial flow1, Grouped_Polynomial flow2, Grouped_Polynomial* out){
if(flow1.length!=flow2.length){
fprintf(stderr, "error: trying to compose two flow equations of different size\n");
exit(-1);
}
int i,j,k;
Coefficient constant;
// init
init_Grouped_Polynomial(out, flow1.length);
(*out).length=flow1.length;
// init constant (so we can tell when the constant was not found)
constant.length=0;
// loop over rcc's
for(i=0;i<flow1.length;i++){
// set indices
(*out).indices[i]=flow1.indices[i];
// passthrough constant terms
if((*out).indices[i]<0){
int index=intlist_find_err(flow2.indices,flow2.length,(*out).indices[i]);
coefficient_cpy(flow2.coefs[index], (*out).coefs+i);
constant=flow2.coefs[index];
continue;
}
// init
init_Coefficient((*out).coefs+i, COEF_SIZE);
// loop over terms
for(j=0;j<flow1.coefs[i].length;j++){
Coefficient tmp_coef;
// init
init_Coefficient(&tmp_coef, COEF_SIZE);
// init factor
Int_Array tmp_factor;
init_Int_Array(&tmp_factor, MONOMIAL_SIZE);
// init denom
coef_denom denom;
// index should be that appearing in flow2
if(flow2.coefs[i].length<1){
fprintf(stderr,"error: composing two flow equations: the %d-th term in the flow equation is empty\n",flow1.indices[i]);
exit(-1);
}
denom.index=flow2.coefs[i].denoms[0].index;
denom.power=0;
// init num
Number tmp_num;
number_cpy(flow1.coefs[i].nums[j], &tmp_num);
// init coefficient with numerical prefactor
coefficient_append_noinit(tmp_factor, tmp_num, denom, &tmp_coef);
// loop over factors
for(k=0;k<flow1.coefs[i].factors[j].length;k++){
// multiply factors together
coefficient_prod_chain(flow2.coefs[intlist_find_err(flow2.indices,flow2.length,flow1.coefs[i].factors[j].values[k])], &tmp_coef);
}
// add to out
coefficient_concat_noinit(tmp_coef, (*out).coefs+i);
}
}
// simplify fractions
if(constant.length!=0){
for(i=0;i<(*out).length;i++){
if((*out).indices[i]>=0){
// reduce them to a common denominator (not much is gained from trying to simplify them)
coefficient_common_denominator(constant, (*out).coefs+i);
//coefficient_simplify_rational(constant, (*out).coefs+i);
}
}
}
return(0);
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ int find_id(Int_Array monomial, Id_Table idtable, int start);
// simplify grouped polynomial // simplify grouped polynomial
int simplify_grouped_polynomial(Grouped_Polynomial* polynomial); int simplify_grouped_polynomial(Grouped_Polynomial* polynomial);
// derive a flow equation with respect to an unknown variable // differentiate a flow equation with respect to an unknown variable
int flow_equation_derivx(Grouped_Polynomial flow_equation, Int_Array indices, Grouped_Polynomial* dflow); int flow_equation_derivx(Grouped_Polynomial flow_equation, Int_Array indices, Grouped_Polynomial* dflow);
// print a grouped polynomial // print a grouped polynomial
@ -69,8 +69,10 @@ int grouped_polynomial_print(Grouped_Polynomial grouped_polynomial, char lhs_pre
int char_array_to_Grouped_Polynomial(Char_Array str, Grouped_Polynomial* output); int char_array_to_Grouped_Polynomial(Char_Array str, Grouped_Polynomial* output);
// evaluate an equation on an RCC // evaluate an equation on an RCC
int evaleq(RCC* rccs, Grouped_Polynomial poly); int evaleq(RCC out, RCC in, Grouped_Polynomial poly);
// evaluate an equation on a vector (using mpfr floats) // evaluate an equation on a vector (using mpfr floats)
int evaleq_mpfr(RCC_mpfr* rccs, Grouped_Polynomial poly); int evaleq_mpfr(RCC_mpfr out, RCC_mpfr in, Grouped_Polynomial poly);
// compose two flow equations (replace the rcc's of flow1 by the right hand side of flow2)
int compose_flow_equations(Grouped_Polynomial flow1, Grouped_Polynomial flow2, Grouped_Polynomial* out);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ limitations under the License.
#define KONDO_SPIN 2 #define KONDO_SPIN 2
// offsets for indices of A, B, h and t // offsets for indices of A, B, h and t
// order matters for symbols table // order matters for virtual_fields table
#define KONDO_A_OFFSET 1 #define KONDO_A_OFFSET 1
#define KONDO_B_OFFSET 2 #define KONDO_B_OFFSET 2
#define KONDO_H_OFFSET 3 #define KONDO_H_OFFSET 3
@ -72,6 +72,7 @@ limitations under the License.
int kondo_generate_conf(Str_Array* str_args, int box_count){ int kondo_generate_conf(Str_Array* str_args, int box_count){
Str_Array new_args; Str_Array new_args;
Fields_Table fields; Fields_Table fields;
Variables variables;
Char_Array tmp_str; Char_Array tmp_str;
int arg_index; int arg_index;
int i; int i;
@ -83,16 +84,19 @@ int kondo_generate_conf(Str_Array* str_args, int box_count){
kondo_fields_table(box_count, &tmp_str, &fields); kondo_fields_table(box_count, &tmp_str, &fields);
str_array_append_noinit(tmp_str, &new_args); str_array_append_noinit(tmp_str, &new_args);
// symbols // dummy variables
kondo_symbols(&tmp_str, box_count, &fields); init_Variables(&variables,1);
arg_index=find_str_arg("symbols", *str_args);
// virtual fields
kondo_virtual_fields(&tmp_str, box_count, &fields);
arg_index=find_str_arg("virtual_fields", *str_args);
if(arg_index>=0){ if(arg_index>=0){
if(tmp_str.length>0){ if(tmp_str.length>0){
char_array_snprintf(&tmp_str,",\n"); char_array_snprintf(&tmp_str,",\n");
} }
char_array_concat((*str_args).strs[arg_index], &tmp_str); char_array_concat((*str_args).strs[arg_index], &tmp_str);
} }
parse_input_symbols(tmp_str, &fields); parse_input_virtual_fields(tmp_str, &fields, variables);
str_array_append_noinit(tmp_str, &new_args); str_array_append_noinit(tmp_str, &new_args);
// identities // identities
@ -104,7 +108,7 @@ int kondo_generate_conf(Str_Array* str_args, int box_count){
} }
char_array_concat((*str_args).strs[arg_index], &tmp_str); char_array_concat((*str_args).strs[arg_index], &tmp_str);
} }
parse_input_identities(tmp_str, &fields); parse_input_identities(tmp_str, &fields, variables);
str_array_append_noinit(tmp_str, &new_args); str_array_append_noinit(tmp_str, &new_args);
// groups // groups
@ -136,7 +140,7 @@ int kondo_generate_conf(Str_Array* str_args, int box_count){
// copy remaining entries // copy remaining entries
for(i=0;i<(*str_args).length;i++){ for(i=0;i<(*str_args).length;i++){
get_str_arg_title((*str_args).strs[i], &title); get_str_arg_title((*str_args).strs[i], &title);
if(str_cmp(title.str, "symbols")==0 &&\ if(str_cmp(title.str, "virtual_fields")==0 &&\
str_cmp(title.str, "identities")==0 &&\ str_cmp(title.str, "identities")==0 &&\
str_cmp(title.str, "propagator")==0 &&\ str_cmp(title.str, "propagator")==0 &&\
str_cmp(title.str, "input_polynomial")==0 &&\ str_cmp(title.str, "input_polynomial")==0 &&\
@ -149,6 +153,7 @@ int kondo_generate_conf(Str_Array* str_args, int box_count){
} }
free_Fields_Table(fields); free_Fields_Table(fields);
free_Variables(variables);
free_Str_Array(*str_args); free_Str_Array(*str_args);
*str_args=new_args; *str_args=new_args;
@ -250,15 +255,15 @@ int kondo_fields_table(int box_count, Char_Array* str_fields, Fields_Table* fiel
} }
// generate Kondo symbols // generate Kondo virtual_fields
int kondo_symbols(Char_Array* str_symbols, int box_count, Fields_Table* fields){ int kondo_virtual_fields(Char_Array* str_virtual_fields, int box_count, Fields_Table* fields){
int i,j,k,l; int i,j,k,l;
Char_Array tmp_str; Char_Array tmp_str;
Polynomial poly; Polynomial poly;
char letters[3]={'A','B','h'}; char letters[3]={'A','B','h'};
init_Char_Array(str_symbols, STR_SIZE); init_Char_Array(str_virtual_fields, STR_SIZE);
char_array_snprintf(str_symbols, "#!symbols\n"); char_array_snprintf(str_virtual_fields, "#!virtual_fields\n");
// loop over box index // loop over box index
for(i=1;i<=box_count;i++){ for(i=1;i<=box_count;i++){
@ -267,7 +272,7 @@ int kondo_symbols(Char_Array* str_symbols, int box_count, Fields_Table* fields){
// loop over space dimension // loop over space dimension
for(k=0;k<KONDO_DIM;k++){ for(k=0;k<KONDO_DIM;k++){
// write index // write index
char_array_snprintf(str_symbols, "%d=", 100*(10*(KONDO_A_OFFSET+j)+k)+i); char_array_snprintf(str_virtual_fields, "%d=", 100*(10*(KONDO_A_OFFSET+j)+k)+i);
// write the name of the scalar product // write the name of the scalar product
init_Char_Array(&tmp_str, 6); init_Char_Array(&tmp_str, 6);
char_array_snprintf(&tmp_str, "%c%d%d", letters[j], k, i); char_array_snprintf(&tmp_str, "%c%d%d", letters[j], k, i);
@ -275,10 +280,10 @@ int kondo_symbols(Char_Array* str_symbols, int box_count, Fields_Table* fields){
kondo_resolve_ABht(tmp_str.str, &poly, *fields); kondo_resolve_ABht(tmp_str.str, &poly, *fields);
free_Char_Array(tmp_str); free_Char_Array(tmp_str);
// write to output // write to output
polynomial_sprint(poly, str_symbols); polynomial_sprint(poly, str_virtual_fields);
free_Polynomial(poly); free_Polynomial(poly);
// add , // add ,
char_array_snprintf(str_symbols,",\n"); char_array_snprintf(str_virtual_fields,",\n");
} }
} }
} }
@ -290,46 +295,46 @@ int kondo_symbols(Char_Array* str_symbols, int box_count, Fields_Table* fields){
for(j=0;j<3;j++){ for(j=0;j<3;j++){
for(k=0;k<3;k++){ for(k=0;k<3;k++){
// write index // write index
char_array_snprintf(str_symbols, "%d=", 1000*(10*(KONDO_A_OFFSET+j)+KONDO_A_OFFSET+k)+i); char_array_snprintf(str_virtual_fields, "%d=", 1000*(10*(KONDO_A_OFFSET+j)+KONDO_A_OFFSET+k)+i);
for(l=0;l<KONDO_DIM;l++){ for(l=0;l<KONDO_DIM;l++){
char_array_snprintf(str_symbols, "(1)"); char_array_snprintf(str_virtual_fields, "(1)");
if(j<2){ if(j<2){
char_array_snprintf(str_symbols,"[f%d]", 100*(10*(KONDO_A_OFFSET+j)+l)+i); char_array_snprintf(str_virtual_fields,"[f%d]", 100*(10*(KONDO_A_OFFSET+j)+l)+i);
} }
else{ else{
char_array_snprintf(str_symbols,"[f%d]", 10*(10*(KONDO_A_OFFSET+j)+l)); char_array_snprintf(str_virtual_fields,"[f%d]", 10*(10*(KONDO_A_OFFSET+j)+l));
} }
if(k<2){ if(k<2){
char_array_snprintf(str_symbols,"[f%d]", 100*(10*(KONDO_A_OFFSET+k)+l)+i); char_array_snprintf(str_virtual_fields,"[f%d]", 100*(10*(KONDO_A_OFFSET+k)+l)+i);
} }
else{ else{
char_array_snprintf(str_symbols,"[f%d]", 10*(10*(KONDO_A_OFFSET+k)+l)); char_array_snprintf(str_virtual_fields,"[f%d]", 10*(10*(KONDO_A_OFFSET+k)+l));
} }
if(l<KONDO_DIM-1){ if(l<KONDO_DIM-1){
char_array_append('+',str_symbols); char_array_append('+',str_virtual_fields);
} }
} }
// add , // add ,
char_array_snprintf(str_symbols,",\n"); char_array_snprintf(str_virtual_fields,",\n");
} }
} }
} }
// vector products // vector products
for(i=1;i<=box_count;i++){ for(i=1;i<=box_count;i++){
char_array_snprintf(str_symbols, "%d=", 100*(100*(KONDO_A_OFFSET)+10*KONDO_B_OFFSET+KONDO_H_OFFSET)+i); char_array_snprintf(str_virtual_fields, "%d=", 100*(100*(KONDO_A_OFFSET)+10*KONDO_B_OFFSET+KONDO_H_OFFSET)+i);
for(l=0;l<KONDO_DIM;l++){ for(l=0;l<KONDO_DIM;l++){
// remember (-1 %3 = -1) // remember (-1 %3 = -1)
char_array_snprintf(str_symbols, "(1)[f%d][f%d][f%d]+(-1)[f%d][f%d][f%d]", 100*(10*KONDO_A_OFFSET+((l+1)%KONDO_DIM))+i, 100*(10*KONDO_B_OFFSET+((l+2)%KONDO_DIM))+i, 10*(10*KONDO_H_OFFSET+l), 100*(10*KONDO_A_OFFSET+((l+2)%KONDO_DIM))+i, 100*(10*KONDO_B_OFFSET+((l+1)%KONDO_DIM))+i, 10*(10*KONDO_H_OFFSET+l)); char_array_snprintf(str_virtual_fields, "(1)[f%d][f%d][f%d]+(-1)[f%d][f%d][f%d]", 100*(10*KONDO_A_OFFSET+((l+1)%KONDO_DIM))+i, 100*(10*KONDO_B_OFFSET+((l+2)%KONDO_DIM))+i, 10*(10*KONDO_H_OFFSET+l), 100*(10*KONDO_A_OFFSET+((l+2)%KONDO_DIM))+i, 100*(10*KONDO_B_OFFSET+((l+1)%KONDO_DIM))+i, 10*(10*KONDO_H_OFFSET+l));
if(l<KONDO_DIM-1){ if(l<KONDO_DIM-1){
char_array_append('+',str_symbols); char_array_append('+',str_virtual_fields);
} }
} }
// add , // add ,
if(i<box_count){ if(i<box_count){
char_array_snprintf(str_symbols,",\n"); char_array_snprintf(str_virtual_fields,",\n");
} }
} }
@ -778,13 +783,13 @@ int parse_kondo_polynomial_str(char* str_polynomial, Polynomial* output, Fields_
// if polynomial exists, add to each monomial // if polynomial exists, add to each monomial
if(tmp_poly.length>0){ if(tmp_poly.length>0){
for(i=0;i<tmp_poly.length;i++){ for(i=0;i<tmp_poly.length;i++){
int_array_append(get_symbol_index(buffer), tmp_poly.monomials+i); int_array_append(get_virtual_field_index(buffer), tmp_poly.monomials+i);
} }
} }
// if not, create a new term in the polynomial // if not, create a new term in the polynomial
else{ else{
init_Int_Array(&tmp_monomial, MONOMIAL_SIZE); init_Int_Array(&tmp_monomial, MONOMIAL_SIZE);
int_array_append(get_symbol_index(buffer), &tmp_monomial); int_array_append(get_virtual_field_index(buffer), &tmp_monomial);
init_Int_Array(&dummy_factor, 1); init_Int_Array(&dummy_factor, 1);
polynomial_append_noinit(tmp_monomial, dummy_factor, number_one(), &tmp_poly); polynomial_append_noinit(tmp_monomial, dummy_factor, number_one(), &tmp_poly);
} }
@ -1387,8 +1392,8 @@ int get_offsets_index(char* str, int* offset1, int* offset2, int* index){
return(0); return(0);
} }
// get the index of the symbol corresponding to a given string // get the index of the virtual_field corresponding to a given string
int get_symbol_index(char* str){ int get_virtual_field_index(char* str){
char* ptr; char* ptr;
int offset=-1; int offset=-1;
int index=0; int index=0;
@ -1439,7 +1444,7 @@ int get_symbol_index(char* str){
if(offset==-1){ if(offset==-1){
return(-1); return(-1);
} }
// no symbol for h or t // no virtual field for h or t
if(offset==KONDO_H_OFFSET || offset==KONDO_T_OFFSET){ if(offset==KONDO_H_OFFSET || offset==KONDO_T_OFFSET){
return(10*(10*offset+dim)); return(10*(10*offset+dim));
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -27,10 +27,10 @@ int kondo_generate_conf(Str_Array* str_args, int box_count);
// generate the Kondo fields table // generate the Kondo fields table
int kondo_fields_table(int box_count, Char_Array* str_fields, Fields_Table* fields); int kondo_fields_table(int box_count, Char_Array* str_fields, Fields_Table* fields);
// generate Kondo symbols // generate Kondo virtual_fields
int kondo_symbols(Char_Array* str_symbols, int box_count, Fields_Table* fields); int kondo_virtual_fields(Char_Array* str_virtual_fields, int box_count, Fields_Table* fields);
// generate Kondo symbols (older method: one symbol for each scalar product) // generate Kondo virtual_fields (older method: one virtual_field for each scalar product)
int kondo_symbols_scalarprod(Char_Array* str_symbols, int box_count, Fields_Table* fields); int kondo_virtual_fields_scalarprod(Char_Array* str_virtual_fields, int box_count, Fields_Table* fields);
// generate Kondo groups (groups of independent variables) // generate Kondo groups (groups of independent variables)
int kondo_groups(Char_Array* str_groups, int box_count); int kondo_groups(Char_Array* str_groups, int box_count);
@ -71,6 +71,6 @@ int kondo_resolve_scalar_prod_symbols(char* str, Polynomial* output);
int get_offset_index(char* str, int* offset, int* index); int get_offset_index(char* str, int* offset, int* index);
// get the offsets and index of a scalar product // get the offsets and index of a scalar product
int get_offsets_index(char* str, int* offset1, int* offset2, int* index); int get_offsets_index(char* str, int* offset1, int* offset2, int* index);
// get the index of the symbol corresponding to a given string // get the index of the virtual_field corresponding to a given string
int get_symbol_index(char* str); int get_virtual_field_index(char* str);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -104,6 +104,11 @@ for(i=1;i<argc;i++){
// number of dimensions // number of dimensions
else if (flag==CP_FLAG_DIMENSION){ else if (flag==CP_FLAG_DIMENSION){
sscanf(argv[i],"%d",&((*opts).dimension)); sscanf(argv[i],"%d",&((*opts).dimension));
// check value of the dimension
if((*opts).dimension<=0 || (*opts).dimension>=4){
fprintf(stderr,"error: kondo_preprocess only supports dimensions 1, 2 and 3 (got %d)\n",(*opts).dimension);
exit(-1);
}
flag=0; flag=0;
} }
// read file name from command-line // read file name from command-line

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ As of version 1.0, the mean of a monomial is computed directly
#include "array.h" #include "array.h"
#include "fields.h" #include "fields.h"
#include "number.h" #include "number.h"
#include "determinant.h"
// mean of a monomial // mean of a monomial
int mean(Int_Array monomial, Polynomial* out, Fields_Table fields, Polynomial_Matrix propagator){ int mean(Int_Array monomial, Polynomial* out, Fields_Table fields, Polynomial_Matrix propagator){
@ -61,10 +62,79 @@ int mean(Int_Array monomial, Polynomial* out, Fields_Table fields, Polynomial_Ma
// compute the mean of a monomial of internal fields (with split + and -) // compute the mean of a monomial of internal fields (with split + and -)
int mean_internal(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields){ int mean_internal(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields){
int ret;
Number num;
if(internal_plus.length!=internal_minus.length){ if(internal_plus.length!=internal_minus.length){
fprintf(stderr,"error: monomial contains unmatched +/- fields\n"); fprintf(stderr,"error: monomial contains unmatched +/- fields\n");
exit(-1); exit(-1);
} }
ret=mean_determinant(internal_plus, internal_minus, &num, propagator, fields);
// cannot compute the mean as a determinant, use permutations
// can be because some fields are not Fermions
// can be because the propagator has non-numeric values (inverting polynomials is not implemented, and would be required for the computation of the determinant)
if(ret==-1){
mean_permutations(internal_plus, internal_minus, out, propagator, fields);
}
else{
polynomial_multiply_scalar(*out, num);
free_Number(num);
}
return(0);
}
// compute the mean of a monomial by computing a determinant
// can only be used if all of the propagators are numbers
int mean_determinant(Int_Array internal_plus, Int_Array internal_minus, Number* out, Polynomial_Matrix propagator, Fields_Table fields){
Number_Matrix M;
int n=internal_minus.length;
int i,j;
int a,b;
int sign;
init_Number_Matrix(&M,n);
// extra sign: the monomial is sorted in such a way that minus fields are on the left of plus fields, but the determinant formula requires the fields to be alternated +-
if((n+1)/2%2==1){
sign=-1;
}
else{
sign=1;
}
// construct matrix
for(i=0;i<n;i++){
a=intlist_find_err(propagator.indices, propagator.length, internal_plus.values[i]);
for(j=0;j<n;j++){
b=intlist_find_err(propagator.indices, propagator.length, -internal_minus.values[j]);
// ignore 0
if(propagator.matrix[a][b].length!=0){
// check whether the fields are Fermions, and whether the entry is a number
if(is_fermion(internal_plus.values[i], fields)==0 || is_fermion(internal_minus.values[j], fields)==0 || polynomial_is_number(propagator.matrix[a][b])==0){
free_Number_Matrix(M);
return(-1);
}
number_add_chain(propagator.matrix[a][b].nums[0], M.matrix[i]+j);
}
}
}
// compute determinant
determinant_inplace(M, out);
number_Qprod_chain(quot(sign,1), out);
free_Number_Matrix(M);
return(0);
}
// compute the mean of a monomial by summing over permutations
int mean_permutations(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields){
int n=internal_minus.length; int n=internal_minus.length;
// pairing as an array of positions // pairing as an array of positions
int* pairing=calloc(n,sizeof(int)); int* pairing=calloc(n,sizeof(int));
@ -118,7 +188,7 @@ int mean_internal(Int_Array internal_plus, Int_Array internal_minus, Polynomial*
pairing_sign=permutation_signature(pairing,n); pairing_sign=permutation_signature(pairing,n);
} }
// only simplify in mean_symbols // only simplify in mean_virtual_fields
polynomial_prod_chain_nosimplify(num_summed,out,fields); polynomial_prod_chain_nosimplify(num_summed,out,fields);
free_Polynomial(num_summed); free_Polynomial(num_summed);
free(pairing); free(pairing);
@ -346,10 +416,10 @@ int get_internals(Int_Array monomial, Int_Array* internal_plus, Int_Array* inter
} }
// compute the mean of a monomial containing symbolic expressions // compute the mean of a monomial containing virtual fields
// keep track of which means were already computed // keep track of which means were already computed
int mean_symbols(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed){ int mean_virtual_fields(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed){
Int_Array symbol_list; Int_Array virtual_field_list;
int i; int i;
int power; int power;
int* current_term; int* current_term;
@ -375,43 +445,43 @@ int mean_symbols(Int_Array monomial, Polynomial* output, Fields_Table fields, Po
} }
} }
init_Int_Array(&symbol_list, monomial.length); init_Int_Array(&virtual_field_list, monomial.length);
init_Int_Array(&base_monomial, monomial.length); init_Int_Array(&base_monomial, monomial.length);
// generate symbols list // generate virtual_fields list
for(i=0;i<monomial.length;i++){ for(i=0;i<monomial.length;i++){
if(field_type(monomial.values[i], fields)==FIELD_SYMBOL){ if(field_type(monomial.values[i], fields)==FIELD_VIRTUAL){
int_array_append(intlist_find_err(fields.symbols.indices, fields.symbols.length, monomial.values[i]), &symbol_list); int_array_append(intlist_find_err(fields.virtual_fields.indices, fields.virtual_fields.length, monomial.values[i]), &virtual_field_list);
} }
else{ else{
int_array_append(monomial.values[i], &base_monomial); int_array_append(monomial.values[i], &base_monomial);
} }
} }
power=symbol_list.length; power=virtual_field_list.length;
// trivial case // trivial case
if(power==0){ if(power==0){
mean(monomial, &mean_num, fields, propagator); mean(monomial, &mean_num, fields, propagator);
polynomial_concat_noinit(mean_num, output); polynomial_concat_noinit(mean_num, output);
free_Int_Array(symbol_list); free_Int_Array(virtual_field_list);
free_Int_Array(base_monomial); free_Int_Array(base_monomial);
return(0); return(0);
} }
else{ else{
// initialize current term to a position that has no repetitions // initialize current term to a position that has no repetitions
current_term=calloc(power,sizeof(int)); current_term=calloc(power,sizeof(int));
exists_next=init_prod(current_term, symbol_list, fields, power, base_monomial)+1; exists_next=init_prod(current_term, virtual_field_list, fields, power, base_monomial)+1;
} }
// loop over terms; the loop stops when all the pointers are at the end of the first symbol // loop over terms; the loop stops when all the pointers are at the end of the first virtual field
while(exists_next==1){ while(exists_next==1){
// construct monomial // construct monomial
int_array_cpy(base_monomial, &tmp_monomial); int_array_cpy(base_monomial, &tmp_monomial);
tmp_num=number_one(); tmp_num=number_one();
for(i=0;i<power;i++){ for(i=0;i<power;i++){
int_array_concat(fields.symbols.expr[symbol_list.values[i]].monomials[current_term[i]], &tmp_monomial); int_array_concat(fields.virtual_fields.expr[virtual_field_list.values[i]].monomials[current_term[i]], &tmp_monomial);
number_prod_chain(fields.symbols.expr[symbol_list.values[i]].nums[current_term[i]], &tmp_num); number_prod_chain(fields.virtual_fields.expr[virtual_field_list.values[i]].nums[current_term[i]], &tmp_num);
} }
// check whether the monomial vanishes // check whether the monomial vanishes
if(check_monomial_match(tmp_monomial, fields)==1){ if(check_monomial_match(tmp_monomial, fields)==1){
@ -432,7 +502,7 @@ int mean_symbols(Int_Array monomial, Polynomial* output, Fields_Table fields, Po
free_Int_Array(tmp_monomial); free_Int_Array(tmp_monomial);
// next term // next term
exists_next=next_prod(current_term, symbol_list, fields, power, base_monomial)+1; exists_next=next_prod(current_term, virtual_field_list, fields, power, base_monomial)+1;
// simplfiy every 25 steps (improves both memory usage and performance) // simplfiy every 25 steps (improves both memory usage and performance)
@ -451,13 +521,13 @@ int mean_symbols(Int_Array monomial, Polynomial* output, Fields_Table fields, Po
// free memory // free memory
free(current_term); free(current_term);
free_Int_Array(symbol_list); free_Int_Array(virtual_field_list);
free_Int_Array(base_monomial); free_Int_Array(base_monomial);
return(0); return(0);
} }
// first term in product with no repetitions // first term in product with no repetitions
int init_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int power, Int_Array base_monomial){ int init_prod(int* current_term, Int_Array virtual_field_list, Fields_Table fields, int power, Int_Array base_monomial){
// index we want to increment // index we want to increment
int move=0; int move=0;
// tmp monomial // tmp monomial
@ -474,7 +544,7 @@ int init_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int
// loop until move is out of range // loop until move is out of range
while(move>=0 && move<power){ while(move>=0 && move<power){
// move // move
current_term[move]=next_term_norepeat(current_term[move], fields.symbols.expr[symbol_list.values[move]], &monomial, fields); current_term[move]=next_term_norepeat(current_term[move], fields.virtual_fields.expr[virtual_field_list.values[move]], &monomial, fields);
// if the next term does not exist, then move previous index // if the next term does not exist, then move previous index
if(current_term[move]==-1){ if(current_term[move]==-1){
move--; move--;
@ -495,7 +565,7 @@ int init_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int
} }
// next term in product with no repetitions // next term in product with no repetitions
int next_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int power, Int_Array base_monomial){ int next_prod(int* current_term, Int_Array virtual_field_list, Fields_Table fields, int power, Int_Array base_monomial){
// index we want to increment // index we want to increment
int move=power-1; int move=power-1;
// tmp monomial // tmp monomial
@ -506,13 +576,13 @@ int next_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int
init_Int_Array(&monomial, base_monomial.length+5*power); init_Int_Array(&monomial, base_monomial.length+5*power);
int_array_cpy_noinit(base_monomial, &monomial); int_array_cpy_noinit(base_monomial, &monomial);
for(i=0;i<=move;i++){ for(i=0;i<=move;i++){
int_array_concat(fields.symbols.expr[symbol_list.values[i]].monomials[current_term[i]],&monomial); int_array_concat(fields.virtual_fields.expr[virtual_field_list.values[i]].monomials[current_term[i]],&monomial);
} }
// loop until move is out of range // loop until move is out of range
while(move>=0 && move<power){ while(move>=0 && move<power){
// move // move
current_term[move]=next_term_norepeat(current_term[move], fields.symbols.expr[symbol_list.values[move]], &monomial, fields); current_term[move]=next_term_norepeat(current_term[move], fields.virtual_fields.expr[virtual_field_list.values[move]], &monomial, fields);
// if the next term does not exist, then move previous index // if the next term does not exist, then move previous index
if(current_term[move]==-1){ if(current_term[move]==-1){
move--; move--;
@ -623,13 +693,13 @@ int mean_groups(Int_Array monomial, Polynomial* output, Fields_Table fields, Pol
int group=-2; int group=-2;
int next_group=-2; int next_group=-2;
Polynomial tmp_poly; Polynomial tmp_poly;
int sign; int sign=1;
init_Polynomial(output, MONOMIAL_SIZE); init_Polynomial(output, MONOMIAL_SIZE);
// check whether there are symbols // check whether there are virtual fields
// IMPORTANT: the symbols must be at the end of the monomial // IMPORTANT: the virtual fields must be at the end of the monomial
if(monomial.length==0 || field_type(monomial.values[monomial.length-1], fields)!=FIELD_SYMBOL){ if(monomial.length==0 || field_type(monomial.values[monomial.length-1], fields)!=FIELD_VIRTUAL){
// mean // mean
mean(monomial, &num_mean, fields, propagator); mean(monomial, &num_mean, fields, propagator);
// add to output // add to output
@ -650,7 +720,7 @@ int mean_groups(Int_Array monomial, Polynomial* output, Fields_Table fields, Pol
} }
// if group changes, take mean // if group changes, take mean
if((i>0 && next_group!=group) || i==monomial.length){ if((i>0 && next_group!=group) || i==monomial.length){
mean_symbols(tmp_monomial, &tmp_poly, fields, propagator, groups, computed); mean_virtual_fields(tmp_monomial, &tmp_poly, fields, propagator, groups, computed);
// if zero // if zero
if(polynomial_is_zero(tmp_poly)==1){ if(polynomial_is_zero(tmp_poly)==1){
// set output to 0 // set output to 0
@ -702,10 +772,11 @@ struct mean_args{
Fields_Table fields; Fields_Table fields;
Polynomial_Matrix propagator; Polynomial_Matrix propagator;
Groups groups; Groups groups;
int print_progress;
}; };
// multithreaded // multithreaded
int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads){ int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress){
int i; int i;
Polynomial thread_polys[threads]; Polynomial thread_polys[threads];
pthread_t thread_ids[threads]; pthread_t thread_ids[threads];
@ -720,11 +791,15 @@ int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Pol
args[i].fields=fields; args[i].fields=fields;
args[i].propagator=propagator; args[i].propagator=propagator;
args[i].groups=groups; args[i].groups=groups;
args[i].print_progress=print_progress;
} }
// split polynomial // split polynomial
// randomly choose the thread
// see random number generator
srand(time(NULL));
for(i=0;i<len;i++){ for(i=0;i<len;i++){
polynomial_append((*polynomial).monomials[i], (*polynomial).factors[i], (*polynomial).nums[i], thread_polys+(i % threads)); polynomial_append((*polynomial).monomials[i], (*polynomial).factors[i], (*polynomial).nums[i], thread_polys+(rand() % threads));
} }
// start threads // start threads
@ -750,12 +825,12 @@ int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Pol
// mean for one of the threads // mean for one of the threads
void* polynomial_mean_thread(void* mean_args){ void* polynomial_mean_thread(void* mean_args){
struct mean_args *args=mean_args; struct mean_args *args=mean_args;
polynomial_mean((*args).polynomial,(*args).fields,(*args).propagator,(*args).groups); polynomial_mean((*args).polynomial,(*args).fields,(*args).propagator,(*args).groups, (*args).print_progress);
return(NULL); return(NULL);
} }
// single threaded version // single threaded version
int polynomial_mean(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups){ int polynomial_mean(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int print_progress){
int i,j; int i,j;
Polynomial output; Polynomial output;
Polynomial tmp_poly; Polynomial tmp_poly;
@ -769,7 +844,9 @@ int polynomial_mean(Polynomial* polynomial, Fields_Table fields, Polynomial_Matr
// mean of each monomial // mean of each monomial
for(i=0;i<(*polynomial).length;i++){ for(i=0;i<(*polynomial).length;i++){
if(print_progress==1){
fprintf(stderr,"computing %d of %d means\n",i,(*polynomial).length-1); fprintf(stderr,"computing %d of %d means\n",i,(*polynomial).length-1);
}
mean_groups((*polynomial).monomials[i], &tmp_poly, fields, propagator, groups, &computed); mean_groups((*polynomial).monomials[i], &tmp_poly, fields, propagator, groups, &computed);
// write factors // write factors

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -28,6 +28,12 @@ int mean(Int_Array monomial, Polynomial* out, Fields_Table fields, Polynomial_Ma
// compute the mean of a monomial of internal fields (with split + and -) // compute the mean of a monomial of internal fields (with split + and -)
int mean_internal(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields); int mean_internal(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields);
// compute the mean of a monomial by computing a determinant
int mean_determinant(Int_Array internal_plus, Int_Array internal_minus, Number* out, Polynomial_Matrix propagator,Fields_Table fields);
// compute the mean of a monomial by summing over permutations
int mean_permutations(Int_Array internal_plus, Int_Array internal_minus, Polynomial* out, Polynomial_Matrix propagator, Fields_Table fields);
// first pairing with a non-vanishing propagator // first pairing with a non-vanishing propagator
int init_pairing(int* pairing, int* mask, int n, Polynomial_Matrix propagator, int* indices_plus, int* indices_minus); int init_pairing(int* pairing, int* mask, int n, Polynomial_Matrix propagator, int* indices_plus, int* indices_minus);
// next pairing with a non-vanishing propagator // next pairing with a non-vanishing propagator
@ -43,12 +49,12 @@ int mean_internal_slow(Int_Array internal_plus, Int_Array internal_minus, Number
// requires the monomial to be sorted (for the sign to be correct) // requires the monomial to be sorted (for the sign to be correct)
int get_internals(Int_Array monomial, Int_Array* internal_plus, Int_Array* internal_minus, Int_Array* others, Fields_Table fields); int get_internals(Int_Array monomial, Int_Array* internal_plus, Int_Array* internal_minus, Int_Array* others, Fields_Table fields);
// compute the mean of a monomial containing symbolic expressions // compute the mean of a monomial containing virtual fields
int mean_symbols(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed); int mean_virtual_fields(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed);
// first term in product with no repetitions // first term in product with no repetitions
int init_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int power, Int_Array base_monomial); int init_prod(int* current_term, Int_Array virtual_field_list, Fields_Table fields, int power, Int_Array base_monomial);
// next term in product with no repetitions // next term in product with no repetitions
int next_prod(int* current_term, Int_Array symbol_list, Fields_Table fields, int power, Int_Array base_monomial); int next_prod(int* current_term, Int_Array virtual_field_list, Fields_Table fields, int power, Int_Array base_monomial);
// find the next term in a polynomial that can be multiplied to a given monomial and add it to the monomial // find the next term in a polynomial that can be multiplied to a given monomial and add it to the monomial
int next_term_norepeat(int start, Polynomial polynomial, Int_Array* monomial, Fields_Table fields); int next_term_norepeat(int start, Polynomial polynomial, Int_Array* monomial, Fields_Table fields);
@ -62,9 +68,9 @@ int sort_fermions(int* array, int begin, int end, int* sign);
int mean_groups(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed); int mean_groups(Int_Array monomial, Polynomial* output, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, Identities* computed);
// compute the mean of a polynomial // compute the mean of a polynomial
int polynomial_mean(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups); int polynomial_mean(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int print_progress);
// multithreaded // multithreaded
int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads); int polynomial_mean_multithread(Polynomial* polynomial, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress);
// single thread mean // single thread mean
void* polynomial_mean_thread(void* mean_args); void* polynomial_mean_thread(void* mean_args);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -17,7 +17,7 @@ limitations under the License.
/* /*
meankondo meankondo
A simple tool to compute the renormalization group flow for Fermionic hierarchical models A tool to compute the renormalization group flow for Fermionic hierarchical models
*/ */
@ -49,15 +49,19 @@ A simple tool to compute the renormalization group flow for Fermionic hierarchic
#include "mean.h" #include "mean.h"
// various string operations // various string operations
#include "istring.h" #include "istring.h"
// symbolic trees
# include "tree.h"
// read cli arguments // read cli arguments
int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meankondo_Options* opts); int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meankondo_Options* opts);
// print usage message // print usage message
int print_usage_meankondo(); int print_usage_meankondo();
// check consistency of options
int check_meankondo_opts(Meankondo_Options opts);
// compute flow // compute flow
int compute_flow(Str_Array str_args, Meankondo_Options opts); int compute_flow(Str_Array str_args, Meankondo_Options opts);
// compute the flow equation // compute average
int compute_flow_equation(Polynomial init_poly, Id_Table idtable, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, Grouped_Polynomial* flow_equation); int compute_average(Polynomial init_poly, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress, Polynomial* exp_poly);
int main (int argc, const char* argv[]){ int main (int argc, const char* argv[]){
@ -69,6 +73,9 @@ int main (int argc, const char* argv[]){
// read command-line arguments // read command-line arguments
read_args_meankondo(argc,argv,&str_args,&opts); read_args_meankondo(argc,argv,&str_args,&opts);
// check command-line arguments
check_meankondo_opts(opts);
// warning message if representing rational numbers as floats // warning message if representing rational numbers as floats
#ifdef RATIONAL_AS_FLOAT #ifdef RATIONAL_AS_FLOAT
fprintf(stderr,"info: representing rational numbers using floats\n"); fprintf(stderr,"info: representing rational numbers using floats\n");
@ -101,6 +108,10 @@ int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meanko
(*opts).threads=1; (*opts).threads=1;
// do not chain // do not chain
(*opts).chain=0; (*opts).chain=0;
// do not print progress
(*opts).print_progress=0;
// print the flow equation
(*opts).group_poly=1;
// loop over arguments // loop over arguments
for(i=1;i<argc;i++){ for(i=1;i<argc;i++){
@ -116,6 +127,13 @@ int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meanko
case 'C': case 'C':
(*opts).chain=1; (*opts).chain=1;
break; break;
// print progress
case 'p':
(*opts).print_progress=1;
break;
case 'A':
(*opts).group_poly=0;
break;
// print version // print version
case 'v': case 'v':
printf("meankondo " VERSION "\n"); printf("meankondo " VERSION "\n");
@ -147,7 +165,16 @@ int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meanko
// print usage message // print usage message
int print_usage_meankondo(){ int print_usage_meankondo(){
printf("\nusage:\n meankondo [-t threads] [-C] <filename>\n\n"); printf("\nusage:\n meankondo [-t threads] [-C] [-p] [-A] <filename>\n\n");
return(0);
}
// check consistency of options
int check_meankondo_opts(Meankondo_Options opts){
if(opts.chain==1 && opts.group_poly==0){
fprintf(stderr,"aborting: the '-C' and '-A' options are incompatible\n");
exit(-1);
}
return(0); return(0);
} }
@ -163,6 +190,8 @@ int compute_flow(Str_Array str_args, Meankondo_Options opts){
Fields_Table fields; Fields_Table fields;
// their propagator // their propagator
Polynomial_Matrix propagator; Polynomial_Matrix propagator;
// preprocessor variables
Variables variables;
// initial polynomial // initial polynomial
Polynomial init_poly; Polynomial init_poly;
// list of rccs // list of rccs
@ -171,6 +200,8 @@ int compute_flow(Str_Array str_args, Meankondo_Options opts){
Groups groups; Groups groups;
// flow equation // flow equation
Grouped_Polynomial flow_equation; Grouped_Polynomial flow_equation;
// polynomial produced by the averaging operation
Polynomial exp_poly;
// parse fields // parse fields
@ -183,29 +214,38 @@ int compute_flow(Str_Array str_args, Meankondo_Options opts){
parse_input_fields(str_args.strs[arg_index],&fields); parse_input_fields(str_args.strs[arg_index],&fields);
} }
// parse variables
// must precede id_table, virtual_fields, identities and input_polynomial
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 id table // parse id table
if(opts.group_poly==1){
arg_index=find_str_arg("id_table", str_args); arg_index=find_str_arg("id_table", str_args);
if(arg_index<0){ if(arg_index<0){
fprintf(stderr,"error: no id table entry in the configuration file\n"); fprintf(stderr,"error: no id table entry in the configuration file\n");
exit(-1); exit(-1);
} }
else{ else{
parse_input_id_table(str_args.strs[arg_index],&idtable, fields); parse_input_id_table(str_args.strs[arg_index],&idtable, fields, variables);
}
} }
// parse symbols // parse virtual_fields
arg_index=find_str_arg("symbols", str_args); arg_index=find_str_arg("virtual_fields", str_args);
if(arg_index>=0){ if(arg_index>=0){
parse_input_symbols(str_args.strs[arg_index],&fields); parse_input_virtual_fields(str_args.strs[arg_index], &fields, variables);
}
else{
init_Symbols(&(fields.symbols),1);
} }
// parse input polynomial // parse input polynomial
arg_index=find_str_arg("input_polynomial", str_args); arg_index=find_str_arg("input_polynomial", str_args);
if(arg_index>=0){ if(arg_index>=0){
parse_input_polynomial(str_args.strs[arg_index],&init_poly, fields); parse_input_polynomial(str_args.strs[arg_index],&init_poly, fields, variables);
} }
else{ else{
fprintf(stderr,"error: no input polynomial entry in the configuration file\n"); fprintf(stderr,"error: no input polynomial entry in the configuration file\n");
@ -225,41 +265,90 @@ int compute_flow(Str_Array str_args, Meankondo_Options opts){
// parse identities // parse identities
arg_index=find_str_arg("identities", str_args); arg_index=find_str_arg("identities", str_args);
if(arg_index>=0){ if(arg_index>=0){
parse_input_identities(str_args.strs[arg_index],&fields); parse_input_identities(str_args.strs[arg_index],&fields, variables);
}
else{
init_Identities(&(fields.ids),1);
} }
// parse groups // parse groups (must come after virtual_fields and propagator)
arg_index=find_str_arg("groups", str_args); arg_index=find_str_arg("groups", str_args);
if(arg_index>=0){ if(arg_index>=0){
parse_input_groups(str_args.strs[arg_index],&groups); parse_input_groups(str_args.strs[arg_index],&groups, propagator, fields);
} }
else{ else{
init_Groups(&groups, 1); init_Groups(&groups, 1);
} }
// flow equation // compute the average
compute_flow_equation(init_poly, idtable, fields, propagator, groups, opts.threads, &flow_equation); compute_average(init_poly, fields, propagator, groups, opts.threads, opts.print_progress, &exp_poly);
free_Polynomial(init_poly); free_Polynomial(init_poly);
free_Polynomial_Matrix(propagator); free_Polynomial_Matrix(propagator);
free_Fields_Table(fields);
free_Groups(groups); free_Groups(groups);
// parse postprocessing entry
arg_index=find_str_arg("postprocess_operation", str_args);
if(arg_index>=0){
add_polynomial_to_variables("OUT", exp_poly, &variables);
// parse postprocess entry
Polynomial postprocess_operation;
parse_input_polynomial(str_args.strs[arg_index], &postprocess_operation, fields, variables);
// replace exp_poly
free_Polynomial(exp_poly);
exp_poly=postprocess_operation;
}
if(opts.group_poly==1){
// flow equation
group_polynomial(exp_poly, &flow_equation, idtable, fields);
}
// postprocess flow equation
arg_index=find_str_arg("postprocess_flow_equation", str_args);
if(arg_index>=0){
Polynomial flow_polynomial;
// polynomial made of the rcc's multiplied by the corresponding fields (parsed from idtable)
idtable_to_polynomial(idtable, &flow_polynomial);
// add to variables
add_polynomial_to_variables("FLOW", flow_polynomial, &variables);
free_Polynomial(flow_polynomial);
// parse postprocess entry
Polynomial postprocess_polynomial;
parse_input_polynomial(str_args.strs[arg_index], &postprocess_polynomial, fields, variables);
// convert to flow equation
Grouped_Polynomial postprocess_flow_equation;
group_polynomial(postprocess_polynomial, &postprocess_flow_equation, idtable, fields);
free_Polynomial(postprocess_polynomial);
// apply postprocessing to flow equation
Grouped_Polynomial new_flow;
compose_flow_equations(postprocess_flow_equation, flow_equation, &new_flow);
free_Grouped_Polynomial(postprocess_flow_equation);
// replace flow_equation
free_Grouped_Polynomial(flow_equation);
flow_equation=new_flow;
}
// if chain then print config file // if chain then print config file
if(opts.chain==1){ if(opts.chain==1){
for(i=0;i<str_args.length;i++){ for(i=0;i<str_args.length;i++){
// check whether to print the str_arg // check whether to print the str_arg
get_str_arg_title(str_args.strs[i], &arg_header); get_str_arg_title(str_args.strs[i], &arg_header);
if (\ if (\
str_cmp(arg_header.str, "symbols")==0 &&\ str_cmp(arg_header.str, "variables")==0 &&\
str_cmp(arg_header.str, "virtual_fields")==0 &&\
str_cmp(arg_header.str, "groups")==0 &&\ str_cmp(arg_header.str, "groups")==0 &&\
str_cmp(arg_header.str, "fields")==0 &&\ str_cmp(arg_header.str, "fields")==0 &&\
str_cmp(arg_header.str, "identities")==0 &&\ str_cmp(arg_header.str, "identities")==0 &&\
str_cmp(arg_header.str, "propagator")==0 &&\ str_cmp(arg_header.str, "propagator")==0 &&\
str_cmp(arg_header.str, "input_polynomial")==0 &&\ str_cmp(arg_header.str, "input_polynomial")==0 &&\
str_cmp(arg_header.str, "id_table")==0 ){ str_cmp(arg_header.str, "id_table")==0 &&\
str_cmp(arg_header.str, "postprocess_operation")==0 &&\
str_cmp(arg_header.str, "numerical_postprocess_operation")==0
){
printf("%s\n&\n",str_args.strs[i].str); printf("%s\n&\n",str_args.strs[i].str);
} }
free_Char_Array(arg_header); free_Char_Array(arg_header);
@ -268,34 +357,66 @@ int compute_flow(Str_Array str_args, Meankondo_Options opts){
printf("#!flow_equation\n"); printf("#!flow_equation\n");
} }
// print flow equation // print result
if(opts.group_poly==1){
grouped_polynomial_print(flow_equation,'%','%'); grouped_polynomial_print(flow_equation,'%','%');
// free memory // free memory
free_Id_Table(idtable);
free_Grouped_Polynomial(flow_equation); free_Grouped_Polynomial(flow_equation);
}
else{
polynomial_print(exp_poly);
}
// free memory
free_Polynomial(exp_poly);
// parse numerical_postprocessing entry
arg_index=find_str_arg("numerical_postprocess_operation", str_args);
if(arg_index>=0){
Polynomial rcc_polynomial;
// polynomial made of the rcc's multiplied by the corresponding fields (parsed from idtable)
idtable_to_polynomial(idtable, &rcc_polynomial);
// add to variables
add_polynomial_to_variables("RCC", rcc_polynomial, &variables);
free_Polynomial(rcc_polynomial);
// parse postprocess entry
Polynomial numerical_postprocess_operation;
parse_input_polynomial(str_args.strs[arg_index], &numerical_postprocess_operation, fields, variables);
// convert to flow equation
Grouped_Polynomial numerical_postprocess_flow_equation;
group_polynomial(numerical_postprocess_operation, &numerical_postprocess_flow_equation, idtable, fields);
free_Polynomial(numerical_postprocess_operation);
// print postprocessing flow equation
printf("\n&\n#!postprocess_operation\n");
grouped_polynomial_print(numerical_postprocess_flow_equation,'%','%');
free_Grouped_Polynomial(numerical_postprocess_flow_equation);
}
if(opts.group_poly==1){
free_Id_Table(idtable);
}
free_Fields_Table(fields);
free_Variables(variables);
return(0); return(0);
} }
// compute the flow equation // compute average
int compute_flow_equation(Polynomial init_poly, Id_Table idtable, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, Grouped_Polynomial* flow_equation){ int compute_average(Polynomial init_poly, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress, Polynomial* exp_poly){
// expectation polynomial_cpy(init_poly,exp_poly);
Polynomial exp_poly;
polynomial_cpy(init_poly,&exp_poly);
// average // average
if(threads>1){ if(threads>1){
polynomial_mean_multithread(&exp_poly, fields, propagator, groups, threads); polynomial_mean_multithread(exp_poly, fields, propagator, groups, threads, print_progress);
} }
else{ else{
polynomial_mean(&exp_poly, fields, propagator, groups); polynomial_mean(exp_poly, fields, propagator, groups, print_progress);
} }
// grouped representation of expanded_poly
group_polynomial(exp_poly,flow_equation,idtable, fields);
free_Polynomial(exp_poly);
return(0); return(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -39,13 +39,13 @@ Utility to perform various operations on flow equations
// string functions // string functions
#include "istring.h" #include "istring.h"
// tools // tools
#include "meantools_exp.h"
#include "meantools_deriv.h" #include "meantools_deriv.h"
#include "meantools_eval.h" #include "meantools_eval.h"
#include "meantools_expand.h"
#define EXP_COMMAND 1 #define DERIV_COMMAND 1
#define DERIV_COMMAND 2 #define EVAL_COMMAND 2
#define EVAL_COMMAND 3 #define EXPAND_COMMAND 3
// read cli arguments // read cli arguments
int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meantools_Options* opts); int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meantools_Options* opts);
@ -63,12 +63,12 @@ int main (int argc, const char* argv[]){
read_args_meantools(argc,argv,&str_args, &opts); read_args_meantools(argc,argv,&str_args, &opts);
switch(opts.command){ switch(opts.command){
case EXP_COMMAND: tool_exp(str_args);
break;
case DERIV_COMMAND: tool_deriv(str_args,opts); case DERIV_COMMAND: tool_deriv(str_args,opts);
break; break;
case EVAL_COMMAND: tool_eval(str_args,opts); case EVAL_COMMAND: tool_eval(str_args,opts);
break; break;
case EXPAND_COMMAND: tool_expand(str_args,opts);
break;
} }
//free memory //free memory
@ -86,11 +86,7 @@ int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meanto
exit(-1); exit(-1);
} }
if(str_cmp((char*)argv[1],"exp")==1){ if(str_cmp((char*)argv[1],"differentiate")==1){
(*opts).command=EXP_COMMAND;
tool_exp_read_args(argc, argv, str_args);
}
else if(str_cmp((char*)argv[1],"derive")==1){
(*opts).command=DERIV_COMMAND; (*opts).command=DERIV_COMMAND;
tool_deriv_read_args(argc, argv, str_args, opts); tool_deriv_read_args(argc, argv, str_args, opts);
} }
@ -98,6 +94,10 @@ int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meanto
(*opts).command=EVAL_COMMAND; (*opts).command=EVAL_COMMAND;
tool_eval_read_args(argc, argv, str_args, opts); tool_eval_read_args(argc, argv, str_args, opts);
} }
else if(str_cmp((char*)argv[1],"expand")==1){
(*opts).command=EXPAND_COMMAND;
tool_expand_read_args(argc, argv, str_args, opts);
}
else{ else{
print_usage_meantools(); print_usage_meantools();
exit(-1); exit(-1);
@ -108,9 +108,6 @@ int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meanto
// print usage message // print usage message
int print_usage_meantools(){ int print_usage_meantools(){
printf("\nusage:\n meantools exp [config_file]\n meantools derive [-d derivatives] [-V variables] [-C] [config_file]\n meantools eval [-R values] [-P precision] [-E max_exponent] [config_file]\n\n"); printf("\nusage:\n meantools differentiate [-d derivatives] [-V variables] [-C] [config_file]\n meantools eval [-R values] [-P precision] [-E max_exponent] [config_file]\n meantools expand [-N namespace] [config_file]\n\n");
return(0); return(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -42,9 +42,9 @@ int tool_deriv_read_args(int argc, const char* argv[], Str_Array* str_args, Mean
char* ptr; char* ptr;
// defaults // defaults
// derive once // differentiate once
(*opts).deriv_derivs=1; (*opts).deriv_derivs=1;
// derive with respect to all variables // differentiate with respect to all variables
(*opts).deriv_vars.length=-1; (*opts).deriv_vars.length=-1;
// do not chain // do not chain
(*opts).chain=0; (*opts).chain=0;
@ -77,7 +77,7 @@ int tool_deriv_read_args(int argc, const char* argv[], Str_Array* str_args, Mean
} }
// variables // variables
else if(flag==CP_FLAG_VARS){ else if(flag==CP_FLAG_VARS){
// if the argument is "all" then derive wrt all variables // if the argument is "all" then differentiate wrt all variables
if(str_cmp((char*)argv[i],"all")){ if(str_cmp((char*)argv[i],"all")){
(*opts).deriv_vars.length=-2; (*opts).deriv_vars.length=-2;
} }
@ -101,7 +101,7 @@ int tool_deriv_read_args(int argc, const char* argv[], Str_Array* str_args, Mean
} }
// derive a flow equation // differentiate a flow equation
int tool_deriv(Str_Array str_args, Meantools_Options opts){ int tool_deriv(Str_Array str_args, Meantools_Options opts){
// index of the entry in the input file // index of the entry in the input file
int arg_index; int arg_index;
@ -158,7 +158,7 @@ int tool_deriv(Str_Array str_args, Meantools_Options opts){
get_str_arg_title(str_args.strs[i], &arg_header); get_str_arg_title(str_args.strs[i], &arg_header);
if (\ if (\
str_cmp(arg_header.str, "flow_equation")==0 &&\ str_cmp(arg_header.str, "flow_equation")==0 &&\
str_cmp(arg_header.str, "symbols")==0 &&\ str_cmp(arg_header.str, "virtual_fields")==0 &&\
str_cmp(arg_header.str, "groups")==0 &&\ str_cmp(arg_header.str, "groups")==0 &&\
str_cmp(arg_header.str, "fields")==0 &&\ str_cmp(arg_header.str, "fields")==0 &&\
str_cmp(arg_header.str, "identities")==0 &&\ str_cmp(arg_header.str, "identities")==0 &&\
@ -208,7 +208,7 @@ int flow_equation_derivative(int n, Int_Array variables, Grouped_Polynomial flow
// free tmpflow // free tmpflow
free_Grouped_Polynomial(tmpflow); free_Grouped_Polynomial(tmpflow);
// add the derived indices as variables for the next derivative // add the differentiated indices as variables for the next derivative
for(i=0;i<variables.length;i++){ for(i=0;i<variables.length;i++){
if(variables.values[i]>=0){ if(variables.values[i]>=0){
int_array_append((j+1)*DOFFSET+variables.values[i], &indices); int_array_append((j+1)*DOFFSET+variables.values[i], &indices);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -21,7 +21,7 @@ limitations under the License.
// read arguments // read arguments
int tool_deriv_read_args(int argc, const char* argv[], Str_Array* str_args, Meantools_Options* opts); int tool_deriv_read_args(int argc, const char* argv[], Str_Array* str_args, Meantools_Options* opts);
// derive a flow equation // differentiate a flow equation
int tool_deriv(Str_Array str_args, Meantools_Options opts); int tool_deriv(Str_Array str_args, Meantools_Options opts);
// n first derivatives of a flow equation wrt to variables // n first derivatives of a flow equation wrt to variables
int flow_equation_derivative(int n, Int_Array variables, Grouped_Polynomial flow_equation, Grouped_Polynomial* flow_equation_derivs); int flow_equation_derivative(int n, Int_Array variables, Grouped_Polynomial flow_equation, Grouped_Polynomial* flow_equation_derivs);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -163,12 +163,12 @@ int tool_eval(Str_Array str_args, Meantools_Options opts){
// evaluate // evaluate
if(mpfr_flag==0){ if(mpfr_flag==0){
evaleq(&rccs, flow_equation); evaleq(rccs, rccs, flow_equation);
RCC_print(rccs); RCC_print(rccs);
free_RCC(rccs); free_RCC(rccs);
} }
else{ else{
evaleq_mpfr(&rccs_mpfr, flow_equation); evaleq_mpfr(rccs_mpfr, rccs_mpfr, flow_equation);
RCC_mpfr_print(rccs_mpfr); RCC_mpfr_print(rccs_mpfr);
free_RCC_mpfr(rccs_mpfr); free_RCC_mpfr(rccs_mpfr);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,130 +0,0 @@
/*
Copyright 2015 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_exp.h"
#include <stdio.h>
#include <stdlib.h>
#include "parse_file.h"
#include "cli_parser.h"
#include "polynomial.h"
#include "fields.h"
#include "grouped_polynomial.h"
#include "idtable.h"
// read command line arguments
int tool_exp_read_args(int argc, const char* argv[], Str_Array* str_args){
// 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;
if(argc>=3){
file=argv[2];
exists_file=1;
}
read_config_file(str_args, file, 1-exists_file);
return(0);
}
// compute the exponential of the input polynomial
int tool_exp(Str_Array str_args){
// index of the entry in the input file
int arg_index;
// list of fields
Fields_Table fields;
// input polynomial
Polynomial poly;
// exp as a polynomial
Polynomial exp_poly;
// list of rccs
Id_Table idtable;
// exp
Grouped_Polynomial exp;
int i,j;
// parse fields
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 id table
arg_index=find_str_arg("id_table", str_args);
if(arg_index<0){
fprintf(stderr,"error: no id table entry in the configuration file\n");
exit(-1);
}
else{
parse_input_id_table(str_args.strs[arg_index],&idtable, fields);
}
// parse input polynomial
arg_index=find_str_arg("input_polynomial", str_args);
if(arg_index>=0){
parse_input_polynomial(str_args.strs[arg_index],&poly, fields);
}
else{
fprintf(stderr,"error: no input polynomial entry in the configuration file\n");
exit(-1);
}
// parse symbols
arg_index=find_str_arg("symbols", str_args);
if(arg_index>=0){
parse_input_symbols(str_args.strs[arg_index],&fields);
}
else{
init_Symbols(&(fields.symbols),1);
}
// parse identities
arg_index=find_str_arg("identities", str_args);
if(arg_index>=0){
parse_input_identities(str_args.strs[arg_index],&fields);
}
else{
init_Identities(&(fields.ids),1);
}
// exp(V)
polynomial_exponential(poly,&exp_poly, fields);
// grouped representation
group_polynomial(exp_poly, &exp, idtable, fields);
free_Polynomial(exp_poly);
free_Polynomial(poly);
// no denominators
for(i=0;i<exp.length;i++){
for(j=0;j<exp.coefs[i].length;j++){
exp.coefs[i].denoms[j].power=0;
}
}
grouped_polynomial_print(exp,'%','%');
// free memory
free_Fields_Table(fields);
free_Id_Table(idtable);
free_Grouped_Polynomial(exp);
return(0);
}

166
src/meantools_expand.c Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#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;i<argc;i++){
// flag
if(argv[i][0]=='-'){
for(ptr=((char*)argv[i])+1;*ptr!='\0';ptr++){
switch(*ptr){
// number of derivatives
case 'N':
flag=CP_FLAG_NAMESPACE;
break;
}
}
}
// namespace
else if(flag==CP_FLAG_NAMESPACE){
str_to_char_array((char*)argv[i], &(opts->namespace));
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);
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,14 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
#ifndef MEANTOOLS_EXP_H #ifndef MEANTOOLS_EXPAND_H
#define MEANTOOLS_EXP_H #define MEANTOOLS_EXPAND_H
#include "types.h" #include "types.h"
// read arguments // read arguments
int tool_exp_read_args(int argc, const char* argv[], Str_Array* str_args); int tool_expand_read_args(int argc, const char* argv[], Str_Array* str_args, Meantools_Options* opts);
// compute the exponential of the input polynomial // expand a flow equation
int tool_exp(Str_Array str_args); int tool_expand(Str_Array str_args, Meantools_Options opts);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ limitations under the License.
#include "tools.h" #include "tools.h"
#include "rational.h" #include "rational.h"
#include "array.h" #include "array.h"
#include "parse_file.h"
// init // init
int init_Number(Number* number, int memory){ int init_Number(Number* number, int memory){
@ -271,50 +272,107 @@ Number number_Qprod_ret(Q q, Number x){
return(ret); return(ret);
} }
// inverse // quotient of two numbers
int number_inverse_inplace(Number* inout){ // recursively simplify numerator/denominator until denominator only has one term
int i; // the output is set to 'numerator'
for(i=0;i<(*inout).length;i++){ // both numerator and denominator may be changed by this function
if((*inout).base[i]>0){ // this algorithm is not optimal in cases where denominator has several terms, in particular if their bases are large
(*inout).scalars[i]=Q_inverse((*inout).scalars[i]); // it is optimal if denominator only has one term
(*inout).scalars[i].denominator*=(*inout).base[i]; int number_quot_inplace(Number* numerator, Number* denominator){
Number tmp;
int i,factor;
switch((*denominator).length){
// error
case 0:
fprintf(stderr,"error: attempting to invert 0\n");
exit(-1);
break;
// trivial case
case 1:
// trivial base
if((*denominator).base[0]==1){
number_Qprod_chain(Q_inverse((*denominator).scalars[0]), numerator);
} }
else if((*inout).base[i]<0){ // non-trivial base
(*inout).scalars[i]=Q_inverse((*inout).scalars[i]); else{
(*inout).scalars[i].denominator*=-(*inout).base[i]; // set tmp=1/denominator
(*inout).scalars[i].numerator*=-1; tmp=number_one();
tmp.base[0]=(*denominator).base[0];
tmp.scalars[0].denominator=(*denominator).scalars[0].numerator*abs((*denominator).base[0]);
if((*denominator).base[0]>0){
tmp.scalars[0].numerator=(*denominator).scalars[0].denominator;
}
else if((*denominator).base[0]<0){
tmp.scalars[0].numerator=-(*denominator).scalars[0].denominator;
} }
else{ else{
fprintf(stderr,"error: attempting to invert 0\n"); fprintf(stderr,"error: attempting to invert 0\n");
exit(-1); exit(-1);
} }
number_prod_chain(tmp, numerator);
} }
break;
default:
// find non-trivial basis
for(i=0;(*denominator).base[i]==1;i++){}
// smallest prime factor of the base
if((*denominator).base[i]<0){
factor=-1;
}
else if((*denominator).base[i]==2){
factor=2;
}
else{
// COMMENT: this is not optimal, but, provided the basis is not too large, this should not be a problem
for(factor=3;is_factor(factor, (*denominator).base[i])==0;factor=factor+2){}
}
// tmp is set to ((terms that k does not divide)-(terms that k divides))
// tmp will be multiplied to numerator and denominator
init_Number(&tmp,(*denominator).length);
// find all terms whose base is a multiple of k
for(i=0;i<(*denominator).length;i++){
if(is_factor(factor, (*denominator).base[i])){
// add to tmp with a - sign
number_add_elem(quot(-(*denominator).scalars[i].numerator,(*denominator).scalars[i].denominator), (*denominator).base[i], &tmp);
}
else{
// add to tmp
number_add_elem((*denominator).scalars[i], (*denominator).base[i], &tmp);
}
}
number_prod_chain(tmp, numerator);
number_prod_chain(tmp, denominator);
free_Number(tmp);
// recurse
number_quot_inplace(numerator, denominator);
}
return(0); return(0);
} }
// write to output
int number_inverse(Number input, Number* output){
number_cpy(input,output);
number_inverse_inplace(output);
return(0);
}
// return result
Number number_inverse_ret(Number x){
Number ret;
number_inverse(x,&ret);
return(ret);
}
// quotient // not inplace
int number_quot(Number x1, Number x2, Number* output){ int number_quot(Number x1, Number x2, Number* output){
Number inv; Number numerator, denominator;
number_inverse(x2, &inv); number_cpy(x1, &numerator);
number_prod(x1, inv, output); number_cpy(x2, &denominator);
free_Number(inv); number_quot_inplace(&numerator, &denominator);
*output=numerator;
free_Number(denominator);
return(0); return(0);
} }
int number_quot_chain(Number x1, Number* inout){ int number_quot_chain(Number* inout, Number x2){
number_inverse_inplace(inout); Number tmp;
number_prod_chain(x1, inout); number_quot(*inout,x2,&tmp);
free_Number(*inout);
*inout=tmp;
return(0); return(0);
} }
Number number_quot_ret(Number x1, Number x2){ Number number_quot_ret(Number x1, Number x2){
@ -419,7 +477,7 @@ int number_print(Number number){
Char_Array buffer; Char_Array buffer;
init_Char_Array(&buffer,5*number.length); init_Char_Array(&buffer,5*number.length);
number_sprint(number, &buffer); number_sprint(number, &buffer);
printf("%s",buffer.str); printf("%s",char_array_to_str_noinit(&buffer));
return(0); return(0);
} }
@ -434,18 +492,54 @@ int str_to_Number(char* str, Number* number){
char* buffer_ptr=buffer; char* buffer_ptr=buffer;
Q num; Q num;
int base; int base;
// whether there are parentheses in the string int ret;
int exist_parenthesis=0; int j;
char* aux_str;
int aux_free=0;
init_Number(number, NUMBER_SIZE); init_Number(number, NUMBER_SIZE);
// check whether the string is blank (return 0 in that case)
for(ptr=str;*ptr!='\0';ptr++){
if(*ptr!=' ' && *ptr!='\n'){
break;
}
}
// blank string
if(*ptr=='\0'){
number_add_elem(quot(0,1), 1, number);
free(buffer);
return(0);
}
// init num and base // init num and base
// init to 0 so that if str is empty, then the number is set to 0 num=quot(1,1);
num=quot(0,1);
base=1; base=1;
// check whether the str only contains a rational number, and add parentheses
// keep rtack of the length of str
for(j=0,ptr=str;*ptr!='\0';j++,ptr++){
if((*ptr<'0' || *ptr>'9') && *ptr!='-' && *ptr!='/'){
break;
}
}
// only rational
if(*ptr=='\0'){
aux_str=calloc(j+3,sizeof(char));
aux_str[0]='(';
for(j=0,ptr=str;*ptr!='\0';ptr++,j++){
aux_str[j+1]=*ptr;
}
aux_str[j+1]=')';
aux_str[j+2]='\0';
aux_free=1;
}
else{
aux_str=str;
}
mode=PP_NULL_MODE; mode=PP_NULL_MODE;
for(ptr=str;*ptr!='\0';ptr++){ for(ptr=aux_str;*ptr!='\0';ptr++){
switch(*ptr){ switch(*ptr){
// read number // read number
case '(': case '(':
@ -453,7 +547,10 @@ int str_to_Number(char* str, Number* number){
// init base // init base
base=1; base=1;
mode=PP_NUM_MODE; mode=PP_NUM_MODE;
exist_parenthesis=1; }
else{
fprintf(stderr,"syntax error: misplaced '(' in number '%s'\n",str);
exit(-1);
} }
break; break;
case ')': case ')':
@ -463,6 +560,10 @@ int str_to_Number(char* str, Number* number){
*buffer_ptr='\0'; *buffer_ptr='\0';
mode=PP_NULL_MODE; mode=PP_NULL_MODE;
} }
else{
fprintf(stderr,"syntax error: mismatched ')' in number '%s'\n",str);
exit(-1);
}
break; break;
// read sqrt // read sqrt
@ -474,16 +575,26 @@ int str_to_Number(char* str, Number* number){
if(mode==PP_NULL_MODE){ if(mode==PP_NULL_MODE){
mode=PP_SQRT_MODE; mode=PP_SQRT_MODE;
} }
// if there is a square root, then do not read a fraction (see end of loop) else{
exist_parenthesis=1; fprintf(stderr,"syntax error: misplaced '{' in number '%s'\n",str);
exit(-1);
}
break; break;
case '}': case '}':
if(mode==PP_SQRT_MODE){ if(mode==PP_SQRT_MODE){
sscanf(buffer,"%d",&base); ret=read_int(buffer,&base);
if(ret<0){
fprintf(stderr,"syntax error: number base should be an integer, got '%s' in '%s'",buffer,str);
exit(-1);
}
buffer_ptr=buffer; buffer_ptr=buffer;
*buffer_ptr='\0'; *buffer_ptr='\0';
mode=PP_NULL_MODE; mode=PP_NULL_MODE;
} }
else{
fprintf(stderr,"syntax error: mismatched '}' in number '%s'\n",str);
exit(-1);
}
break; break;
// write num // write num
@ -494,24 +605,40 @@ int str_to_Number(char* str, Number* number){
num=quot(0,1); num=quot(0,1);
base=1; base=1;
} }
else{
fprintf(stderr,"syntax error: misplaced '+' in number '%s'\n",str);
exit(-1);
}
break; break;
// ignore 's', ' ' and '\n'
case 's':break;
case ' ':break;
case '\n':break;
default: default:
if(mode!=PP_NULL_MODE){ if(mode!=PP_NULL_MODE){
buffer_ptr=str_addchar(buffer_ptr,*ptr); buffer_ptr=str_addchar(buffer_ptr,*ptr);
} }
else{
fprintf(stderr,"syntax error: unrecognized character '%c' in number '%s'\n",*ptr,str);
exit(-1);
}
break; break;
} }
} }
// last step
if(mode==PP_NULL_MODE){ if(mode==PP_NULL_MODE){
if(exist_parenthesis==0){
str_to_Q(str, &num);
}
number_add_elem(num, base, number); number_add_elem(num, base, number);
} }
else{
fprintf(stderr,"syntax error: mismatched '(' in number '%s'\n",str);
exit(-1);
}
if(aux_free==1){
free(aux_str);
}
free(buffer); free(buffer);
return(0); return(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -78,16 +78,11 @@ int number_Qprod(Q q, Number x, Number* inout);
// return result // return result
Number number_Qprod_ret(Q q, Number x); Number number_Qprod_ret(Q q, Number x);
// inverse // quotient of two numbers
int number_inverse_inplace(Number* inout); int number_quot_inplace(Number* numerator, Number* denominator);
// write to output // not inplace
int number_inverse(Number input, Number* output);
// return result
Number number_inverse_ret(Number x);
// quotient
int number_quot(Number x1, Number x2, Number* output); int number_quot(Number x1, Number x2, Number* output);
int number_quot_chain(Number x1, Number* inout); int number_quot_chain(Number* inout, Number x2);
Number number_quot_ret(Number x1, Number x2); Number number_quot_ret(Number x1, Number x2);
// remove 0's // remove 0's

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -86,12 +86,6 @@ int read_args_numkondo(int argc,const char* argv[], Str_Array* str_args, Numkond
// whether a file was specified on the command-line // whether a file was specified on the command-line
int exists_file=0; int exists_file=0;
// if there are no arguments
if(argc==1){
print_usage_numkondo();
exit(-1);
}
// defaults // defaults
// display entire flow // display entire flow
(*opts).display_mode=DISPLAY_NUMERICAL; (*opts).display_mode=DISPLAY_NUMERICAL;
@ -193,6 +187,8 @@ int numflow(Str_Array str_args, Numkondo_Options opts){
Grouped_Polynomial flow_equation; Grouped_Polynomial flow_equation;
// whether or not to use mpfr floats // whether or not to use mpfr floats
int mpfr_flag=0; int mpfr_flag=0;
// postprocess flow equation
Grouped_Polynomial postprocess_flow_equation;
// set mpfr defaults // set mpfr defaults
if(opts.mpfr_prec!=0){ if(opts.mpfr_prec!=0){
@ -205,7 +201,7 @@ int numflow(Str_Array str_args, Numkondo_Options opts){
} }
// parse id table // parse labels
arg_index=find_str_arg("labels", str_args); arg_index=find_str_arg("labels", str_args);
if(arg_index<0){ if(arg_index<0){
fprintf(stderr,"error: no labels entry in the configuration file\n"); fprintf(stderr,"error: no labels entry in the configuration file\n");
@ -225,6 +221,16 @@ int numflow(Str_Array str_args, Numkondo_Options opts){
char_array_to_Grouped_Polynomial(str_args.strs[arg_index], &flow_equation); char_array_to_Grouped_Polynomial(str_args.strs[arg_index], &flow_equation);
} }
// parse postprocess operation
arg_index=find_str_arg("postprocess_operation", str_args);
if(arg_index>=0){
char_array_to_Grouped_Polynomial(str_args.strs[arg_index], &postprocess_flow_equation);
}
else{
init_Grouped_Polynomial(&postprocess_flow_equation,1);
}
// initial conditions // initial conditions
// check they were not specified on the command line // check they were not specified on the command line
if(opts.eval_rccstring.length==-1){ if(opts.eval_rccstring.length==-1){
@ -252,17 +258,18 @@ int numflow(Str_Array str_args, Numkondo_Options opts){
} }
if(mpfr_flag==0){ if(mpfr_flag==0){
numerical_flow(flow_equation, init_cd, labels, opts.niter, opts.display_mode); numerical_flow(flow_equation, init_cd, postprocess_flow_equation, labels, opts.niter, opts.display_mode);
free_RCC(init_cd); free_RCC(init_cd);
} }
else{ else{
numerical_flow_mpfr(flow_equation, init_cd_mpfr, labels, opts.niter, opts.display_mode); numerical_flow_mpfr(flow_equation, init_cd_mpfr, postprocess_flow_equation, labels, opts.niter, opts.display_mode);
free_RCC_mpfr(init_cd_mpfr); free_RCC_mpfr(init_cd_mpfr);
} }
// free memory // free memory
free_Labels(labels); free_Labels(labels);
free_Grouped_Polynomial(postprocess_flow_equation);
free_Grouped_Polynomial(flow_equation); free_Grouped_Polynomial(flow_equation);
return(0); return(0);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -23,26 +23,43 @@ Parse the input file
#include "types.h" #include "types.h"
// read a positive integer from a string
int read_positive_int(char* str, int* out);
// read an integer from a string
int read_int(char* str, int* out);
// read an long int from a string
int read_long_int(char* str, long int* out);
// read a long double
int read_long_double(char* str, long double* out);
// parse fields list // parse fields list
int parse_input_fields(Char_Array str_fields, Fields_Table* fields); int parse_input_fields(Char_Array str_fields, Fields_Table* fields);
// parse symbols list // parse virtual_fields list
int parse_input_symbols(Char_Array str_symbols, Fields_Table* fields); int parse_input_virtual_fields(Char_Array str_virtual_fields, Fields_Table* fields, Variables variables);
// parse groups of independent fields // parse groups of independent fields
int parse_input_groups(Char_Array str_groups, Groups* groups); int parse_input_groups(Char_Array str_groups, Groups* groups, Polynomial_Matrix propagator, Fields_Table fields);
// check that the members of groups are independent (assuming the virtual_fields and propagator were already parsed)
int check_groups(Groups groups, Polynomial_Matrix propagator, Fields_Table fields);
// list of fields involved in a list of virtual_fields
int fields_in_virtual_field_list(Int_Array indices, Fields_Table fields, Int_Array* output);
// parse variables list
int parse_input_variables(Char_Array str_variables, Variables* variables);
// parse identities between fields // parse identities between fields
int parse_input_identities(Char_Array str_identities, Fields_Table* fields); int parse_input_identities(Char_Array str_identities, Fields_Table* fields, Variables variables);
// parse propagator // parse propagator
int parse_input_propagator(Char_Array str_propagator, Polynomial_Matrix* propagator, Fields_Table fields); int parse_input_propagator(Char_Array str_propagator, Polynomial_Matrix* propagator, Fields_Table fields);
// parse input polynomial // parse input polynomial
int parse_input_polynomial(Char_Array str_polynomial, Polynomial* output, Fields_Table fields); int parse_input_polynomial(Char_Array str_polynomial, Polynomial* output, Fields_Table fields, Variables variables);
// parse id table // parse id table
int parse_input_id_table(Char_Array str_idtable, Id_Table* idtable, Fields_Table fields); int parse_input_id_table(Char_Array str_idtable, Id_Table* idtable, Fields_Table fields, Variables variables);
// parse a list of labels // parse a list of labels
int parse_labels(Char_Array str_labels, Labels* labels); int parse_labels(Char_Array str_labels, Labels* labels);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ limitations under the License.
#include "array.h" #include "array.h"
#include "number.h" #include "number.h"
#include "fields.h" #include "fields.h"
#include "parse_file.h"
// allocate memory // allocate memory
@ -368,7 +369,7 @@ int polynomial_prod_chain_nosimplify(Polynomial input, Polynomial* inout, Fields
Int_Array out_monomial; Int_Array out_monomial;
Int_Array out_factor; Int_Array out_factor;
Number out_num; Number out_num;
// save length of inout (which changes during the loop // save length of inout (which changes during the loop)
int inout_length=(*inout).length; int inout_length=(*inout).length;
// first position in input which can multiply a term of inout without vanishing // first position in input which can multiply a term of inout without vanishing
int firstpos; int firstpos;
@ -630,8 +631,8 @@ int remove_unmatched_plusminus(Polynomial* polynomial, Fields_Table fields){
match_internals--; match_internals--;
} }
} }
// don't remove a term containing symbols // don't remove a term containing virtual_field
else if(type==FIELD_SYMBOL){ else if(type==FIELD_VIRTUAL){
match_internals=0; match_internals=0;
break; break;
} }
@ -1093,7 +1094,7 @@ int polynomial_print(Polynomial polynomial){
Char_Array buffer; Char_Array buffer;
init_Char_Array(&buffer, STR_SIZE); init_Char_Array(&buffer, STR_SIZE);
polynomial_sprint(polynomial, &buffer); polynomial_sprint(polynomial, &buffer);
printf("%s",buffer.str); printf("%s",char_array_to_str_noinit(&buffer));
free_Char_Array(buffer); free_Char_Array(buffer);
return(0); return(0);
} }
@ -1104,7 +1105,7 @@ int polynomial_print(Polynomial polynomial){
#define PP_MONOMIAL_MODE 2 #define PP_MONOMIAL_MODE 2
#define PP_FACTOR_MODE 3 #define PP_FACTOR_MODE 3
#define PP_NUMBER_MODE 4 #define PP_NUMBER_MODE 4
int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){ int Char_Array_to_Polynomial(Char_Array str_polynomial, Polynomial* output){
// buffer // buffer
char* buffer=calloc(str_polynomial.length+1,sizeof(char)); char* buffer=calloc(str_polynomial.length+1,sizeof(char));
char* buffer_ptr=buffer; char* buffer_ptr=buffer;
@ -1115,6 +1116,7 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
int comment=0; int comment=0;
int i,j; int i,j;
int parenthesis_count=0; int parenthesis_count=0;
int ret;
// allocate memory // allocate memory
init_Polynomial(output,POLY_SIZE); init_Polynomial(output,POLY_SIZE);
@ -1174,6 +1176,10 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
init_Int_Array(&factor, MONOMIAL_SIZE); init_Int_Array(&factor, MONOMIAL_SIZE);
num=number_one(); num=number_one();
} }
else{
fprintf(stderr,"syntax error: misplaced '+' in polynomial\n");
exit(-1);
}
break; break;
// enter monomial or factor mode // enter monomial or factor mode
@ -1181,6 +1187,10 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
if(mode==PP_NULL_MODE){ if(mode==PP_NULL_MODE){
mode=PP_BRACKET_MODE; mode=PP_BRACKET_MODE;
} }
else{
fprintf(stderr,"syntax error: misplaced '[' in polynomial\n");
exit(-1);
}
break; break;
// factor mode // factor mode
case 'l': case 'l':
@ -1189,6 +1199,10 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
buffer_ptr=buffer; buffer_ptr=buffer;
*buffer_ptr='\0'; *buffer_ptr='\0';
} }
else{
fprintf(stderr,"syntax error: misplaced 'l' in polynomial\n");
exit(-1);
}
break; break;
// monomial mode // monomial mode
case 'f': case 'f':
@ -1197,16 +1211,30 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
buffer_ptr=buffer; buffer_ptr=buffer;
*buffer_ptr='\0'; *buffer_ptr='\0';
} }
else{
fprintf(stderr,"syntax error: misplaced 'j' in polynomial\n");
exit(-1);
}
break; break;
// read monomial or factor // read monomial or factor
case ']': case ']':
sscanf(buffer,"%d",&i); sscanf(buffer,"%d",&i);
ret=read_int(buffer,&i);
if(ret<0){
fprintf(stderr,"syntax error: in polynomial, expected integer field or factor index, got '%s'\n",buffer);
exit(-1);
}
if(mode==PP_FACTOR_MODE){ if(mode==PP_FACTOR_MODE){
int_array_append(i,&factor); int_array_append(i,&factor);
} }
else if(mode==PP_MONOMIAL_MODE){ else if(mode==PP_MONOMIAL_MODE){
int_array_append(i,&monomial); int_array_append(i,&monomial);
} }
else{
fprintf(stderr,"syntax error: mismatched ']' in polynomial\n");
exit(-1);
}
// switch back to null mode // switch back to null mode
mode=PP_NULL_MODE; mode=PP_NULL_MODE;
break; break;
@ -1224,6 +1252,10 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
parenthesis_count++; parenthesis_count++;
buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]); buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]);
} }
else{
fprintf(stderr,"syntax error: misplaced '(' in polynomial\n");
exit(-1);
}
break; break;
case ')': case ')':
if(mode==PP_NUMBER_MODE){ if(mode==PP_NUMBER_MODE){
@ -1240,11 +1272,14 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]); buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]);
} }
} }
else{
fprintf(stderr,"syntax error: mismatched ')' in polynomial\n");
exit(-1);
}
break; break;
// characters to ignore // characters to ignore
case ' ':break; case ' ':break;
case '&':break;
case '\n':break; case '\n':break;
// comments // comments
@ -1257,6 +1292,10 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
// write to buffer // write to buffer
buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]); buffer_ptr=str_addchar(buffer_ptr,str_polynomial.str[j]);
} }
else{
fprintf(stderr,"syntax error: in polynomial, unrecognized character '%c'\n",str_polynomial.str[j]);
exit(-1);
}
break; break;
} }
} }
@ -1270,7 +1309,7 @@ int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output){
} }
// with str input // with str input
int str_to_Polynomial(char* str_polynomial,Polynomial* output){ int str_to_Polynomial(char* str_polynomial, Polynomial* output){
Char_Array buffer; Char_Array buffer;
str_to_char_array(str_polynomial, &buffer); str_to_char_array(str_polynomial, &buffer);
Char_Array_to_Polynomial(buffer, output); Char_Array_to_Polynomial(buffer, output);
@ -1278,6 +1317,15 @@ int str_to_Polynomial(char* str_polynomial,Polynomial* output){
return(0); return(0);
} }
// check whether the polynomial is a constant
int polynomial_is_number(Polynomial poly){
if(poly.length==0 || (poly.length==1 && poly.monomials[0].length==0 && poly.factors[0].length==0)){
return(1);
}
else{
return(0);
}
}
// -------------------- Polynomial_Matrix --------------------- // -------------------- Polynomial_Matrix ---------------------
@ -1307,3 +1355,16 @@ int free_Polynomial_Matrix(Polynomial_Matrix matrix){
free(matrix.indices); free(matrix.indices);
return(0); return(0);
} }
// check whether the entries are numbers
int polynomial_matrix_is_numeric(Polynomial_Matrix matrix){
int i,j;
for(i=0;i<matrix.length;i++){
for(j=0;j<matrix.length;j++){
if(polynomial_is_number(matrix.matrix[i][j])==0){
return(0);
}
}
}
return(1);
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -124,12 +124,18 @@ int replace_factors(Grouped_Polynomial equations, Polynomial* polynomial);
int polynomial_sprint(Polynomial polynomial, Char_Array* output); int polynomial_sprint(Polynomial polynomial, Char_Array* output);
int polynomial_print(Polynomial polynomial); int polynomial_print(Polynomial polynomial);
// read a polynomial // read a polynomial
int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output); int Char_Array_to_Polynomial(Char_Array str_polynomial, Polynomial* output);
int str_to_Polynomial(char* str_polynomial,Polynomial* output); int str_to_Polynomial(char* str_polynomial, Polynomial* output);
// check whether the polynomial is a constant
int polynomial_is_number(Polynomial poly);
//------------------------ Polynomial_Matrix -------------------------- //------------------------ Polynomial_Matrix --------------------------
// init // init
int init_Polynomial_Matrix(Polynomial_Matrix* matrix, int length); int init_Polynomial_Matrix(Polynomial_Matrix* matrix, int length);
int free_Polynomial_Matrix(Polynomial_Matrix matrix); int free_Polynomial_Matrix(Polynomial_Matrix matrix);
// check whether the entries are numbers
int polynomial_matrix_is_numeric(Polynomial_Matrix matrix);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ limitations under the License.
#include <mpfr.h> #include <mpfr.h>
#include "istring.h" #include "istring.h"
#include "array.h" #include "array.h"
#include "parse_file.h"
Q quot(long int p, long int q){ Q quot(long int p, long int q){
Q ret; Q ret;
@ -171,13 +172,18 @@ int str_to_Q(char* str, Q* num){
int mode; int mode;
char* buffer=calloc(str_len(str)+1,sizeof(char)); char* buffer=calloc(str_len(str)+1,sizeof(char));
char* buffer_ptr=buffer; char* buffer_ptr=buffer;
int ret;
*num=quot(0,1); *num=quot(0,1);
mode=PP_NUMERATOR_MODE; mode=PP_NUMERATOR_MODE;
for(ptr=str;*ptr!='\0';ptr++){ for(ptr=str;*ptr!='\0';ptr++){
if(*ptr=='/'){ if(*ptr=='/'){
sscanf(buffer,"%ld",&((*num).numerator)); ret=read_long_int(buffer,&((*num).numerator));
if(ret<0){
fprintf(stderr,"syntax error: numerator should be an integer, got '%s' in '%s'\n",buffer,str);
exit(-1);
}
buffer_ptr=buffer; buffer_ptr=buffer;
*buffer_ptr='\0'; *buffer_ptr='\0';
mode=PP_DENOMINATOR_MODE; mode=PP_DENOMINATOR_MODE;
@ -189,10 +195,18 @@ int str_to_Q(char* str, Q* num){
// last step // last step
if(mode==PP_NUMERATOR_MODE){ if(mode==PP_NUMERATOR_MODE){
sscanf(buffer,"%ld",&((*num).numerator)); ret=read_long_int(buffer,&((*num).numerator));
if(ret<0){
fprintf(stderr,"syntax error: numerator should be an integer, got '%s' in '%s'\n",buffer,str);
exit(-1);
}
} }
else if(mode==PP_DENOMINATOR_MODE){ else if(mode==PP_DENOMINATOR_MODE){
sscanf(buffer,"%ld",&((*num).denominator)); ret=read_long_int(buffer,&((*num).denominator));
if(ret<0){
fprintf(stderr,"syntax error: numerator should be an integer, got '%s' in '%s'\n",buffer,str);
exit(-1);
}
} }
free(buffer); free(buffer);

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -49,6 +49,13 @@ int RCC_cpy(RCC input,RCC* output){
} }
return(0); return(0);
} }
int RCC_cpy_noinit(RCC input,RCC* output){
int i;
for(i=0;i<input.length;i++){
RCC_set_elem(input.values[i], input.indices[i], output, i);
}
return(0);
}
// concatenate rccs // concatenate rccs
int RCC_concat(RCC rccs1, RCC rccs2, RCC* output){ int RCC_concat(RCC rccs1, RCC rccs2, RCC* output){

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ int free_RCC(RCC rccs);
int RCC_set_elem(long double value, int index, RCC* rcc, int pos); int RCC_set_elem(long double value, int index, RCC* rcc, int pos);
// copy // copy
int RCC_cpy(RCC input,RCC* output); int RCC_cpy(RCC input,RCC* output);
int RCC_cpy_noinit(RCC input,RCC* output);
// concatenate 2 rccs // concatenate 2 rccs
int RCC_concat(RCC rccs1, RCC rccs2, RCC* output); int RCC_concat(RCC rccs1, RCC rccs2, RCC* output);
// append an rcc to another // append an rcc to another

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -65,6 +65,13 @@ int RCC_mpfr_cpy(RCC_mpfr input,RCC_mpfr* output){
} }
return(0); return(0);
} }
int RCC_mpfr_cpy_noinit(RCC_mpfr input,RCC_mpfr* output){
int i;
for(i=0;i<input.length;i++){
RCC_mpfr_set_elem(input.values[i], input.indices[i], output, i);
}
return(0);
}
// concatenate rcc_mpfr // concatenate rcc_mpfr
int RCC_mpfr_concat(RCC_mpfr rcc_mpfr1, RCC_mpfr rcc_mpfr2, RCC_mpfr* output){ int RCC_mpfr_concat(RCC_mpfr rcc_mpfr1, RCC_mpfr rcc_mpfr2, RCC_mpfr* output){

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -32,6 +32,7 @@ int free_RCC_mpfr(RCC_mpfr rcc_mpfr);
int RCC_mpfr_set_elem(mpfr_t value, int index, RCC_mpfr* rcc_mpfr, int pos); int RCC_mpfr_set_elem(mpfr_t value, int index, RCC_mpfr* rcc_mpfr, int pos);
// copy // copy
int RCC_mpfr_cpy(RCC_mpfr input,RCC_mpfr* output); int RCC_mpfr_cpy(RCC_mpfr input,RCC_mpfr* output);
int RCC_mpfr_cpy_noinit(RCC_mpfr input,RCC_mpfr* output);
// concatenate 2 rcc_mpfr_mpfr // concatenate 2 rcc_mpfr_mpfr
int RCC_mpfr_concat(RCC_mpfr rcc_mpfr_mpfr1, RCC_mpfr rcc_mpfr_mpfr2, RCC_mpfr* output); int RCC_mpfr_concat(RCC_mpfr rcc_mpfr_mpfr1, RCC_mpfr rcc_mpfr_mpfr2, RCC_mpfr* output);
// append an rcc_mpfr to another // append an rcc_mpfr to another

330
src/symbolic_parser.c Normal file
View File

@ -0,0 +1,330 @@
/*
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 "symbolic_parser.h"
#include <stdlib.h>
#include <stdio.h>
#include "tree.h"
#include "definitions.cpp"
#include "array.h"
#include "istring.h"
#include "fields.h"
#include "polynomial.h"
#define SP_NULL_MODE 0
#define SP_FUNCTION_MODE 1
// parse a symbolic expression from a char_array
int parse_symbolic_expression(Char_Array str, Fields_Table fields, Variables variables, Polynomial* polynomial){
Tree symbol_tree;
char_array_to_symbol_tree(str, &symbol_tree);
resolve_symbol_tree(symbol_tree, fields, variables, polynomial);
free_Tree(symbol_tree);
return(0);
}
// from char*
int parse_symbolic_expression_str(char* str, Fields_Table fields, Variables variables, Polynomial* polynomial){
Char_Array char_array;
str_to_char_array(str,&char_array);
parse_symbolic_expression(char_array, fields, variables, polynomial);
free_Char_Array(char_array);
return(0);
}
// compute the symbol tree from a string
int char_array_to_symbol_tree(Char_Array str, Tree* symbol_tree){
// buffer
char* buffer=calloc(str.length+1,sizeof(char));
char* buffer_ptr=buffer;
Tree child;
int match;
Char_Array nodestr;
Char_Array label;
Char_Array str_clean;
int mode;
int comment=0;
int j;
int gotanode=0;
// allocate memory
init_Tree(symbol_tree,SYMBOL_TREE_SIZE, SYMBOL_TREE_LABEL_SIZE);
// remove comments, ' ' and '\n'
init_Char_Array(&str_clean,str.length);
for(j=0;j<str.length;j++){
if(comment==1){
if(str.str[j]=='\n'){
comment=0;
}
}
else{
switch(str.str[j]){
case ' ':break;
case '\n':break;
// comments
case '#':
comment=1;
break;
default:
char_array_append(str.str[j],&str_clean);
break;
}
}
}
// if the string contains no '<', then trivial tree
for(j=0;j<str_clean.length;j++){
if(str_clean.str[j]=='<'){
break;
}
}
// no '<': trivial tree
if(j==str_clean.length){
tree_set_label(str_clean, symbol_tree);
free(buffer);
free_Char_Array(str_clean);
return(0);
}
*buffer_ptr='\0';
// loop over the input string
// start in null mode
mode=SP_NULL_MODE;
for(j=0;j<str_clean.length;j++){
switch(str_clean.str[j]){
// new node
case '<':
// find matching bracket
match=matching_bracket(str_clean,j);
// check whether it exists
if(match<0){
fprintf(stderr,"syntax error: unmatched brackets in %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
// extract substring until bracket
char_array_substring(str_clean,j+1,match-1,&nodestr);
// check whether node is trivial
if(j==0 && match==str_clean.length-1){
free_Tree(*symbol_tree);
char_array_to_symbol_tree(nodestr, symbol_tree);
free_Char_Array(nodestr);
j=match;
break;
}
// parse subexpression
char_array_to_symbol_tree(nodestr, &child);
free_Char_Array(nodestr);
// add child to tree
tree_append_child_noinit(child, symbol_tree);
// boolean indicating a node has been found
gotanode=1;
// set next position after the node
j=match;
// if function mode, then check that the match is at the end of the node
if(mode==SP_FUNCTION_MODE){
if(match<str_clean.length-1){
fprintf(stderr,"syntax error: functions must occupy an entire node (e.g. <%%exp<...>>), got %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
else{
// set label
str_to_char_array(buffer,&label);
tree_set_label(label,symbol_tree);
free_Char_Array(label);
}
}
break;
// function
case '%':
if(j>0){
fprintf(stderr,"syntax error: functions must occupy an entire node (e.g. <%%exp<...>>), got %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
mode=SP_FUNCTION_MODE;
break;
// product
case '*':
if(gotanode==0){
fprintf(stderr,"syntax error: '*' is not preceded by a node in %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
if(j>=str_clean.length-1){
fprintf(stderr,"syntax error: '*' cannot be at the end of an expression, got %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
// set label
init_Char_Array(&label,1);
char_array_append('*',&label);
tree_set_label(label,symbol_tree);
free_Char_Array(label);
// next child
char_array_substring(str_clean,j+1,str_clean.length-1,&nodestr);
// parse subexpression
char_array_to_symbol_tree(nodestr, &child);
free_Char_Array(nodestr);
// append next child
tree_append_child_noinit(child, symbol_tree);
// make it stop
j=str_clean.length-1;
break;
// sum
case '+':
if(gotanode==0){
fprintf(stderr,"syntax error: '+' is not preceded by a node in %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
if(j>=str_clean.length-1){
fprintf(stderr,"syntax error: '+' cannot be at the end of an expression, got %s\n",char_array_to_str_noinit(&str));
exit(-1);
}
// set label
init_Char_Array(&label,1);
char_array_append('+',&label);
tree_set_label(label,symbol_tree);
free_Char_Array(label);
// next child
char_array_substring(str_clean,j+1,str_clean.length-1,&nodestr);
// parse subexpression
char_array_to_symbol_tree(nodestr, &child);
free_Char_Array(nodestr);
// append next child
tree_append_child_noinit(child, symbol_tree);
// make it stop
j=str_clean.length-1;
break;
default:
if(mode!=SP_NULL_MODE){
// write to buffer
buffer_ptr=str_addchar(buffer_ptr,str_clean.str[j]);
}
break;
}
}
free_Char_Array(str_clean);
free(buffer);
return(0);
}
// from char*
int str_to_symbol_tree(char* str, Tree* symbol_tree){
Char_Array char_array;
str_to_char_array(str,&char_array);
char_array_to_symbol_tree(char_array,symbol_tree);
free_Char_Array(char_array);
return(0);
}
// find matching '<' and '>'
int matching_bracket(Char_Array str, int start){
int bracket_count=0;
int i;
for(i=start;i<str.length;i++){
if(str.str[i]=='<'){
bracket_count++;
}
else if(str.str[i]=='>'){
bracket_count--;
if(bracket_count==0){
return(i);
}
}
}
// if the function has not returned, then no matching bracket
return(-1);
}
// resolve a symbol tree to its corresponding polynomial
int resolve_symbol_tree(Tree symbol_tree, Fields_Table fields, Variables variables, Polynomial* output){
Polynomial poly;
Tree variable_tree;
// trivial tree
if(symbol_tree.length==0){
// variable
if(symbol_tree.root_label.length>0 && symbol_tree.root_label.str[0]=='$'){
variables_find_var(symbol_tree.root_label, variables, &variable_tree);
resolve_symbol_tree(variable_tree, fields, variables, output);
free_Tree(variable_tree);
}
//polynomial
else{
Char_Array_to_Polynomial(symbol_tree.root_label, output);
}
}
// exp
else if (char_array_cmp_str(symbol_tree.root_label,"exp")==1){
if(symbol_tree.length!=1){
fprintf(stderr,"syntax error: exp must have 1 argument\n");
exit(-1);
}
resolve_symbol_tree(symbol_tree.children[0], fields, variables, &poly);
polynomial_exponential(poly, output, fields);
free_Polynomial(poly);
}
// log
else if (char_array_cmp_str(symbol_tree.root_label,"log_1")==1){
if(symbol_tree.length!=1){
fprintf(stderr,"syntax error: log_1 must have 1 argument\n");
exit(-1);
}
resolve_symbol_tree(symbol_tree.children[0], fields, variables, &poly);
polynomial_logarithm(poly, output, fields);
free_Polynomial(poly);
}
// product
else if (char_array_cmp_str(symbol_tree.root_label,"*")==1){
if(symbol_tree.length!=2){
fprintf(stderr,"syntax error: '*' must have 2 arguments\n");
exit(-1);
}
resolve_symbol_tree(symbol_tree.children[0], fields, variables, output);
resolve_symbol_tree(symbol_tree.children[1], fields, variables, &poly);
polynomial_prod_chain(poly, output, fields);
free_Polynomial(poly);
}
// sum
else if (char_array_cmp_str(symbol_tree.root_label,"+")==1){
if(symbol_tree.length!=2){
fprintf(stderr,"syntax error: '+' must have 2 arguments\n");
exit(-1);
}
resolve_symbol_tree(symbol_tree.children[0], fields, variables, output);
resolve_symbol_tree(symbol_tree.children[1], fields, variables, &poly);
polynomial_add_chain_noinit(poly, output, fields);
}
else{
fprintf(stderr,"syntax error: unrecognized operation '%s'\n",char_array_to_str_noinit(&(symbol_tree.root_label)));
exit(-1);
}
return(0);
}

42
src/symbolic_parser.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
/*
parse symbolic expressions
*/
#ifndef SYMBOLIC_PARSER_H
#define SYMBOLIC_PARSER_H
#include "types.h"
// parse a symbolic expression from a char_array
int parse_symbolic_expression(Char_Array str, Fields_Table fields, Variables variables, Polynomial* polynomial);
// from char*
int parse_symbolic_expression_str(char* str, Fields_Table fields, Variables variables, Polynomial* polynomial);
// compute the symbol tree from a string
int char_array_to_symbol_tree(Char_Array str, Tree* symbol_tree);
// from char*
int str_to_symbol_tree(char* str, Tree* symbol_tree);
// find matching '<' and '>'
int matching_bracket(Char_Array str, int start);
// resolve a symbol tree to its corresponding polynomial
int resolve_symbol_tree(Tree symbol_tree, Fields_Table fields, Variables variables, Polynomial* output);
#endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -140,3 +140,13 @@ int min(int x1, int x2){
return(x2); return(x2);
} }
} }
// check whether a divides b
int is_factor(int a, int b){
if(b-a*(b/a)==0){
return(1);
}
else{
return(0);
}
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -46,4 +46,7 @@ int intlist_find_err(int* list, int size, int x);
int max(int x1, int x2); int max(int x1, int x2);
int min(int x1, int x2); int min(int x1, int x2);
// check whether a divides b
int is_factor(int a, int b);
#endif #endif

117
src/tree.c Normal file
View File

@ -0,0 +1,117 @@
/*
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 "tree.h"
#include <stdlib.h>
#include <stdio.h>
#include "array.h"
// init
int init_Tree(Tree* tree, int memory_children, int memory_label){
init_Char_Array(&(tree->root_label),memory_label);
(*tree).children=calloc(memory_children,sizeof(Tree));
(*tree).memory=memory_children;
(*tree).length=0;
return(0);
}
int free_Tree(Tree tree){
int i;
free_Char_Array(tree.root_label);
for(i=0;i<tree.length;i++){
free_Tree(tree.children[i]);
}
free(tree.children);
return(0);
}
// copy
int tree_cpy(Tree input, Tree* output){
init_Tree(output,input.length, input.root_label.length);
tree_cpy_noinit(input,output);
return(0);
}
int tree_cpy_noinit(Tree input, Tree* output){
int i;
if((*output).memory<input.length){
fprintf(stderr,"error: trying to copy a tree of length %d to another with memory %d\n",input.length, (*output).memory);
exit(-1);
}
char_array_cpy_noinit(input.root_label,&(output->root_label));
for(i=0;i<input.length;i++){
tree_cpy(input.children[i],(*output).children+i);
}
(*output).length=input.length;
return(0);
}
// resize memory
int tree_resize(Tree* tree, int newsize){
Tree new_tree;
init_Tree(&new_tree,newsize,tree->root_label.memory);
tree_cpy_noinit(*tree,&new_tree);
free_Tree(*tree);
*tree=new_tree;
return(0);
}
// set label
int tree_set_label(Char_Array label, Tree* tree){
if(label.length > tree->root_label.memory){
char_array_resize(&(tree->root_label),label.length);
}
char_array_cpy_noinit(label,&(tree->root_label));
return(0);
}
// add a child to a tree
int tree_append_child(Tree child, Tree* output){
if((*output).length>=(*output).memory){
tree_resize(output,2*(*output).memory+1);
}
tree_cpy(child,(*output).children+(*output).length);
(*output).length++;
return(0);
}
// add a child to a tree without allocating memory for the new child
int tree_append_child_noinit(Tree child, Tree* output){
if((*output).length>=(*output).memory){
tree_resize(output,2*(*output).memory+1);
}
(*output).children[(*output).length]=child;
(*output).length++;
return(0);
}
// concatenate the children of two trees
int tree_concat_children(Tree input, Tree* output){
int i;
for(i=0;i<input.length;i++){
tree_append_child(input.children[i],output);
}
return(0);
}
// noinit
int tree_concat_children_noinit(Tree input, Tree* output){
int i;
for(i=0;i<input.length;i++){
tree_append_child_noinit(input.children[i],output);
}
// free input array
free(input.children);
return(0);
}

48
src/tree.h Normal file
View File

@ -0,0 +1,48 @@
/*
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.
*/
/* Trees */
#ifndef TREE_H
#define TREE_H
#include "types.h"
int init_Tree(Tree* tree, int memory_children, int memory_label);
int free_Tree(Tree tree);
// copy
int tree_cpy(Tree input, Tree* output);
int tree_cpy_noinit(Tree input, Tree* output);
// resize memory
int tree_resize(Tree* tree, int newsize);
// set label
int tree_set_label(Char_Array label, Tree* tree);
// add a child to a tree
int tree_append_child(Tree tree, Tree* output);
// add a child to a tree without allocating memory for the new child
int tree_append_child_noinit(Tree tree, Tree* output);
// concatenate the children of two trees
int tree_concat_children(Tree input, Tree* output);
// noinit
int tree_concat_children_noinit(Tree input, Tree* output);
#endif

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2015 Ian Jauslin Copyright 2015-2022 Ian Jauslin
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -71,6 +71,15 @@ typedef struct Str_Array{
int memory; int memory;
} Str_Array; } Str_Array;
// tree
typedef struct Tree Tree;
struct Tree{
Char_Array root_label;
Tree* children;
int length;
int memory;
};
// polynomial // polynomial
typedef struct Polynomial{ typedef struct Polynomial{
Int_Array* monomials; Int_Array* monomials;
@ -133,13 +142,21 @@ typedef struct Identities{
int memory; int memory;
} Identities; } Identities;
// symbolic expressions // virtual_fields
typedef struct Symbols{ typedef struct Virtual_fields{
int* indices; int* indices;
Polynomial* expr; Polynomial* expr;
int length; int length;
int memory; int memory;
} Symbols; } Virtual_fields;
// variables used in symbolic expressions
typedef struct Variables{
Char_Array* var_names;
Tree* symbol_trees;
int length;
int memory;
} Variables;
// groups of independent fields // groups of independent fields
typedef struct Groups{ typedef struct Groups{
@ -159,10 +176,10 @@ typedef struct Fields_Table{
// identities between fields // identities between fields
Identities ids; Identities ids;
// symbolic expressions (commuting) // symbolic expressions (commuting)
Symbols symbols; Virtual_fields virtual_fields;
// list of anti-commuting variables (fields or symbols) // list of anti-commuting variables
Int_Array fermions; Int_Array fermions;
// list of non-commuting variables (fields or symbols) // list of non-commuting variables
Int_Array noncommuting; Int_Array noncommuting;
} Fields_Table; } Fields_Table;
@ -187,6 +204,8 @@ typedef struct Id_Table{
typedef struct Meankondo_Options{ typedef struct Meankondo_Options{
int threads; int threads;
int chain; int chain;
int print_progress;
int group_poly;
} Meankondo_Options; } Meankondo_Options;
typedef struct Numkondo_Options{ typedef struct Numkondo_Options{
@ -203,6 +222,7 @@ typedef struct Meantools_Options{
Int_Array deriv_vars; Int_Array deriv_vars;
Char_Array eval_rccstring; Char_Array eval_rccstring;
int chain; int chain;
Char_Array namespace;
mpfr_prec_t mpfr_prec; mpfr_prec_t mpfr_prec;
mpfr_exp_t mpfr_emax; mpfr_exp_t mpfr_emax;
} Meantools_Options; } Meantools_Options;