Ian Jauslin
summaryrefslogtreecommitdiff
blob: 6aff76d90705f1c88ef7f79bd39ae246e9185eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
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.
*/

/*
Represent a polynomial as a list of monomials with factors
*/

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H

#include "types.h"

// allocate memory
int init_Polynomial(Polynomial* polynomial,int size);
// free memory
int free_Polynomial(Polynomial polynomial);

// resize the memory allocated to a polynomial
int resize_polynomial(Polynomial* polynomial,int new_size);

// copy a polynomial
int polynomial_cpy(Polynomial input, Polynomial* output);
int polynomial_cpy_noinit(Polynomial input, Polynomial* output);

// append an element to a polynomial
int polynomial_append(Int_Array monomial, Int_Array factor, Number num, Polynomial* output);
int polynomial_append_noinit(Int_Array monomial, Int_Array factor, Number num, Polynomial* output);
// noinit, and if there already exists an element with the same monomial and factor, then just add numbers
int polynomial_append_noinit_inplace(Int_Array monomial, Int_Array factor, Number num, Polynomial* output);

// concatenate two polynomials
int polynomial_concat(Polynomial input, Polynomial* output);
int polynomial_concat_noinit(Polynomial input, Polynomial* output);
int polynomial_concat_noinit_inplace(Polynomial input, Polynomial* output);

// add polynomials
int polynomial_add_chain(Polynomial input, Polynomial* inout, Fields_Table fields);
// add polynomials (noinit)
int polynomial_add_chain_noinit(Polynomial input, Polynomial* inout, Fields_Table fields);

// multiply a polynomial by a scalar
int polynomial_multiply_scalar(Polynomial polynomial, Number num);
int polynomial_multiply_Qscalar(Polynomial polynomial, Q q);

// change the sign of the monomials in a polynomial
int polynomial_conjugate(Polynomial polynomial);

// returns an initialized polynomial, equal to 1
Polynomial polynomial_one();
// returns an initialized polynomial, equal to 0
Polynomial polynomial_zero();

// check whether a polynomial is 0
int polynomial_is_zero(Polynomial poly);

// compute V^p
int polynomial_power(Polynomial input_polynomial, Polynomial* output, int power, Fields_Table fields);
// compute V*W
int polynomial_prod(Polynomial input1, Polynomial input2, Polynomial* output, Fields_Table fields);
int polynomial_prod_chain_nosimplify(Polynomial input, Polynomial* inout, Fields_Table fields);
int polynomial_prod_chain(Polynomial input, Polynomial* inout, Fields_Table fields);
// exp(V)
int polynomial_exponential(Polynomial input_polynomial,Polynomial* output, Fields_Table fields);
// log(1+W)
int polynomial_logarithm(Polynomial input_polynomial, Polynomial* output, Fields_Table fields);

// check whether a monomial vanishes
int check_monomial(Int_Array monomial, Fields_Table fields);
// check whether the product of two monomials will vanish
int check_monomial_willnot_vanish(Int_Array monomial1, Int_Array monomial2, Fields_Table fields);
// check whether one can add a term to a monomial without creating repetitions
int check_monomial_addterm(Int_Array monomial, Int_Array term, Fields_Table fields);
// check whether a monomial vanishes or has unmatched +/- fields
int check_monomial_match(Int_Array monomial, Fields_Table fields);
// remove terms with more plus internal fields than minus ones
int remove_unmatched_plusminus(Polynomial* polynomial, Fields_Table fields);

// denominator of a multinomal factor: m1!m2!...
int multinomial(int power,int* terms);

// simplify a Polynomial
int polynomial_simplify(Polynomial* polynomial, Fields_Table fields);
// sort a polynomial
int polynomial_sort(Polynomial* polynomial, int begin, int end);
// exchange two terms (for the sorting algorithm)
int exchange_polynomial_terms(int i, int j, Polynomial* polynomial);

// sort a monomial (with sign coming from exchanging two Fermions)
int monomial_sort(Int_Array monomial, Fields_Table fields, int* sign);
// without noncommuting terms
int monomial_sort_nonc(Int_Array monomial, int begin, int end, Fields_Table fields, int* sign);
// order fields: parameter, external, internal
int compare_monomial_terms(Int_Array monomial, int pos1, int pos2, Fields_Table fields);
// exchange two fields (with sign)
int exchange_monomial_terms(Int_Array monomial, int pos1, int pos2, Fields_Table fields, int* sign);

// sort a monomial by putting each group together
int monomial_sort_groups(Int_Array monomial, Fields_Table fields, Groups groups, int* sign);
// without noncommuting terms
int monomial_sort_groups_nonc(Int_Array monomial, int begin, int end, Fields_Table fields, Groups groups, int* sign);
// order fields: group, then parameter, external, internal
int compare_monomial_terms_groups(Int_Array monomial, int pos1, int pos2, Fields_Table fields, Groups groups);

// convert and idtable to a polynomial
int idtable_to_polynomial(Id_Table idtable, Polynomial* polynomial);

// replace the factors in a polynomial as prescribed by an equation in the form of a Grouped_Polynomial
int replace_factors(Grouped_Polynomial equations, Polynomial* polynomial);

// print a polynomial
int polynomial_sprint(Polynomial polynomial, Char_Array* output);
int polynomial_print(Polynomial polynomial);
// read a polynomial
int Char_Array_to_Polynomial(Char_Array str_polynomial,Polynomial* output);
int str_to_Polynomial(char* str_polynomial,Polynomial* output);

//------------------------ Polynomial_Matrix --------------------------
// init
int init_Polynomial_Matrix(Polynomial_Matrix* matrix, int length);
int free_Polynomial_Matrix(Polynomial_Matrix matrix);

#endif