Ian Jauslin
summaryrefslogtreecommitdiff
blob: a7a151c0a2a3f1ad704b587a0104d834167b3c4a (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
/*
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.
*/

/*
Coefficients represent the collection of terms which appear
 on the right hand side of a single flow equation.

They are used as an elementary building block of grouped polynomials.
*/

#ifndef COEFFICIENT_H
#define COEFFICIENT_H

#include "types.h"

// allocate memory
int init_Coefficient(Coefficient* coef,int size);
// free memory
int free_Coefficient(Coefficient coef);

// copy a coefficient
int coefficient_cpy(Coefficient input, Coefficient* output);
int coefficient_cpy_noinit(Coefficient input, Coefficient* output);

// resize the memory allocated to a coefficient
int resize_Coefficient(Coefficient* coefficient,int new_size);

// append an element to a coefficient
int coefficient_append(Int_Array factor,Number num, coef_denom denom, Coefficient* output);
int coefficient_append_noinit(Int_Array factor, Number num, coef_denom denom, Coefficient* output);

// concatenate coefficients and simplify result
int coefficient_concat(Coefficient input, Coefficient* output);
int coefficient_concat_noinit(Coefficient input, Coefficient* output);

// simplify a Coefficient
int coefficient_simplify(Coefficient* coefficient);
// sort the terms in an equation (quicksort algorithm)
int sort_coefficient(Coefficient* coefficient, int begin, int end);
// exchange two terms (for the sorting algorithm)
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 )
int coefficient_deriv_noinit(Coefficient input, int index, Coefficient* output);
int coefficient_deriv(Coefficient input, int index, Coefficient* output);

// product of two coefficients
int coefficient_prod(Coefficient coef1, Coefficient coef2, Coefficient* output);
// product of coefficients, output replaces the second coefficient
int coefficient_prod_chain(Coefficient in, Coefficient* inout);

// print coefficient
int coefficient_sprint(Coefficient coef, Char_Array* output, int offset, char index_pre);

// read from a string
int char_array_to_Coefficient(Char_Array str_coef, Coefficient* output);
int str_to_Coefficient(char* str, Coefficient* output);

// compare coefficient denominators
int coef_denom_cmp(coef_denom denom1, coef_denom denom2);

// evaluate a coefficient on a vector
int evalcoef(RCC rccs, Coefficient coef, long double* out);

#endif