diff options
Diffstat (limited to 'src/number.h')
-rw-r--r-- | src/number.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/number.h b/src/number.h new file mode 100644 index 0000000..4095f9c --- /dev/null +++ b/src/number.h @@ -0,0 +1,120 @@ +/* +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. +*/ + +/* +Numerical constants (rational numbers and their square roots (including \sqrt{-1}=i)) +*/ + +#ifndef NUMBER_H +#define NUMBER_H + +#include "types.h" + +// init +int init_Number(Number* number, int memory); +int free_Number(Number number); + +// copy +int number_cpy(Number input, Number* output); +int number_cpy_noinit(Number input, Number* output); + +// resize memory +int number_resize(Number* number, int newsize); + +// add a value +int number_append(Q scalar, int base, Number* output); + +// concatenate +int number_concat(Number input, Number* output); + +// special numbers +Number number_zero(); +Number number_one(); + +// find a base element +int number_find_base(int base, Number number); + +// sort +int number_sort(Number number, int begin, int end); +// exchange terms (for sorting) +int number_exchange_terms(int index1, int index2, Number number); + +// checks whether two numbers are equal +int number_compare(Number x1, Number x2); + +// add (write result to second element) +int number_add_chain(Number input, Number* inout); +// add a single element +int number_add_elem(Q scalar, int base, Number* inout); +// create a new number +int number_add(Number x1, Number x2, Number* out); +// return the number +Number number_add_ret(Number x1, Number x_2); + +// multiply +int number_prod(Number x1, Number x2, Number* out); +// write to second number +int number_prod_chain(Number input, Number* inout); +// return result +Number number_prod_ret(Number x1, Number x2); + +// multiply by a rational +int number_Qprod_chain(Q q, Number* inout); +// write to output +int number_Qprod(Q q, Number x, Number* inout); +// return result +Number number_Qprod_ret(Q q, Number x); + +// inverse +int number_inverse_inplace(Number* inout); +// write to output +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_chain(Number x1, Number* inout); +Number number_quot_ret(Number x1, Number x2); + +// remove 0's +int number_simplify(Number in, Number* out); + +// check whether a number is 0 +int number_is_zero(Number x); + +// approximate numerical expression +long double number_double_val(Number x); + +// print to string +int number_sprint(Number number, Char_Array* out); +// print to stdout +int number_print(Number number); +// read from a string +int str_to_Number(char* str, Number* number); +// char array input +int char_array_to_Number(Char_Array cstr_num, Number* number); + + +//------------------------ Number_Matrix -------------------------- +// init +int init_Number_Matrix(Number_Matrix* matrix, int length); +int free_Number_Matrix(Number_Matrix matrix); + +// Pauli matrices +int Pauli_matrix(int i, Number_Matrix* output); + +#endif |