From c305ff633853ddcecffd85cbb16ef52f8b047334 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Sun, 14 Oct 2012 16:30:01 +0200 Subject: [PATCH] initial code for complex numbers and polynomials --- Makefile.in | 2 +- fmpcb.h | 260 +++++++++++++++++++++++++++++++++++ fmpcb/Makefile | 43 ++++++ fmpcb/printd.c | 44 ++++++ fmpcb_poly.h | 97 +++++++++++++ fmpcb_poly/Makefile | 43 ++++++ fmpcb_poly/clear.c | 37 +++++ fmpcb_poly/derivative.c | 52 +++++++ fmpcb_poly/evaluate.c | 69 ++++++++++ fmpcb_poly/fit_length.c | 46 +++++++ fmpcb_poly/init.c | 41 ++++++ fmpcb_poly/normalise.c | 37 +++++ fmpcb_poly/printd.c | 43 ++++++ fmpcb_poly/set.c | 36 +++++ fmpcb_poly/set2_fmpq_poly.c | 42 ++++++ fmpcb_poly/set2_fmprb_poly.c | 50 +++++++ fmpcb_poly/set_length.c | 40 ++++++ 17 files changed, 981 insertions(+), 1 deletion(-) create mode 100644 fmpcb.h create mode 100644 fmpcb/Makefile create mode 100644 fmpcb/printd.c create mode 100644 fmpcb_poly.h create mode 100644 fmpcb_poly/Makefile create mode 100644 fmpcb_poly/clear.c create mode 100644 fmpcb_poly/derivative.c create mode 100644 fmpcb_poly/evaluate.c create mode 100644 fmpcb_poly/fit_length.c create mode 100644 fmpcb_poly/init.c create mode 100644 fmpcb_poly/normalise.c create mode 100644 fmpcb_poly/printd.c create mode 100644 fmpcb_poly/set.c create mode 100644 fmpcb_poly/set2_fmpq_poly.c create mode 100644 fmpcb_poly/set2_fmprb_poly.c create mode 100644 fmpcb_poly/set_length.c diff --git a/Makefile.in b/Makefile.in index 26a911c9..831b81d5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -102,5 +102,5 @@ build/%.lo: %.c build/%.o: %.c $(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@ -BUILD_DIRS = fmpr fmprb fmprb_poly fmprb_mat fmpz_holonomic +BUILD_DIRS = fmpr fmprb fmprb_poly fmprb_mat fmpz_holonomic fmpcb fmpcb_poly diff --git a/fmpcb.h b/fmpcb.h new file mode 100644 index 00000000..2c859bd5 --- /dev/null +++ b/fmpcb.h @@ -0,0 +1,260 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#ifndef FMPCB_H +#define FMPCB_H + +#include "fmpr.h" +#include "fmprb.h" + +typedef struct +{ + fmprb_struct real; + fmprb_struct imag; +} +fmpcb_struct; + +typedef fmpcb_struct fmpcb_t[1]; + +#define fmpcb_realref(x) (&(x)->real) +#define fmpcb_imagref(x) (&(x)->imag) + + +static __inline__ void +fmpcb_init(fmpcb_t x) +{ + fmprb_init(fmpcb_realref(x)); + fmprb_init(fmpcb_imagref(x)); +} + +static __inline__ void +fmpcb_clear(fmpcb_t x) +{ + fmprb_clear(fmpcb_realref(x)); + fmprb_clear(fmpcb_imagref(x)); +} + +static __inline__ int +fmpcb_is_zero(const fmpcb_t z) +{ + return fmprb_is_zero(fmpcb_realref(z)) && fmprb_is_zero(fmpcb_imagref(z)); +} + +static __inline__ int +fmpcb_is_exact(const fmpcb_t z) +{ + return fmprb_is_exact(fmpcb_realref(z)) && fmprb_is_exact(fmpcb_imagref(z)); +} + + +static __inline__ void +fmpcb_zero(fmpcb_t z) +{ + fmprb_zero(fmpcb_realref(z)); + fmprb_zero(fmpcb_imagref(z)); +} + +static __inline__ void +fmpcb_one(fmpcb_t z) +{ + fmprb_one(fmpcb_realref(z)); + fmprb_zero(fmpcb_imagref(z)); +} + +static __inline__ void +fmpcb_onei(fmpcb_t z) +{ + fmprb_zero(fmpcb_realref(z)); + fmprb_one(fmpcb_imagref(z)); +} + +static __inline__ void +fmpcb_set(fmpcb_t z, const fmpcb_t x) +{ + fmprb_set(fmpcb_realref(z), fmpcb_realref(x)); + fmprb_set(fmpcb_imagref(z), fmpcb_imagref(x)); +} + +static __inline__ void +fmpcb_swap(fmpcb_t z, fmpcb_t x) +{ + fmprb_swap(fmpcb_realref(z), fmpcb_realref(x)); + fmprb_swap(fmpcb_imagref(z), fmpcb_imagref(x)); +} + +static __inline__ void +fmpcb_add(fmpcb_t z, const fmpcb_t x, const fmpcb_t y, long prec) +{ + fmprb_add(fmpcb_realref(z), fmpcb_realref(x), fmpcb_realref(y), prec); + fmprb_add(fmpcb_imagref(z), fmpcb_imagref(x), fmpcb_imagref(y), prec); +} + +static __inline__ void +fmpcb_sub(fmpcb_t z, const fmpcb_t x, const fmpcb_t y, long prec) +{ + fmprb_sub(fmpcb_realref(z), fmpcb_realref(x), fmpcb_realref(y), prec); + fmprb_sub(fmpcb_imagref(z), fmpcb_imagref(x), fmpcb_imagref(y), prec); +} + +static __inline__ void +fmpcb_neg(fmpcb_t z, const fmpcb_t x) +{ + fmprb_neg(fmpcb_realref(z), fmpcb_realref(x)); + fmprb_neg(fmpcb_imagref(z), fmpcb_imagref(x)); +} + +static __inline__ void +fmpcb_mul_ui(fmpcb_t z, const fmpcb_t x, ulong y, long prec) +{ + fmprb_mul_ui(fmpcb_realref(z), fmpcb_realref(x), y, prec); + fmprb_mul_ui(fmpcb_imagref(z), fmpcb_imagref(x), y, prec); +} + +static __inline__ void +fmpcb_mul_fmprb(fmpcb_t z, const fmpcb_t x, const fmprb_t y, long prec) +{ + fmprb_mul(fmpcb_realref(z), fmpcb_realref(x), y, prec); + fmprb_mul(fmpcb_imagref(z), fmpcb_imagref(x), y, prec); +} + +static __inline__ void +fmpcb_mul_onei(fmpcb_t z, const fmpcb_t x) +{ + if (z == x) + { + fmprb_swap(fmpcb_realref(z), fmpcb_imagref(z)); + fmprb_neg(fmpcb_realref(z), fmpcb_realref(z)); + } + else + { + fmprb_neg(fmpcb_realref(z), fmpcb_imagref(x)); + fmprb_set(fmpcb_imagref(z), fmpcb_realref(x)); + } +} + + +static __inline__ void +fmpcb_mul(fmpcb_t z, const fmpcb_t x, const fmpcb_t y, long prec) +{ +#define a fmpcb_realref(x) +#define b fmpcb_imagref(x) +#define c fmpcb_realref(y) +#define d fmpcb_imagref(y) + +/* + TODO: use these optimizations, but fix aliasing issues + + if (fmprb_is_zero(b)) + { + fmpcb_mul_fmprb(z, y, a, prec); + } + else if (fmprb_is_zero(d)) + { + fmpcb_mul_fmprb(z, x, c, prec); + } + else if (fmprb_is_zero(a)) + { + fmpcb_mul_fmprb(z, y, b, prec); + fmpcb_mul_i(z, z); + } + else if (fmprb_is_zero(c)) + { + fmpcb_mul_fmprb(z, x, d, prec); + fmpcb_mul_i(z, z); + } + else +*/ + { + fmprb_t t, u, v; + + fmprb_init(t); + fmprb_init(u); + fmprb_init(v); + + fmprb_add(t, a, b, prec); + fmprb_add(u, c, d, prec); + fmprb_mul(v, t, u, prec); + + fmprb_mul(t, a, c, prec); + fmprb_mul(u, b, d, prec); + + fmprb_sub(fmpcb_realref(z), t, u, prec); + fmprb_sub(fmpcb_imagref(z), v, t, prec); + fmprb_sub(fmpcb_imagref(z), fmpcb_imagref(z), u, prec); + + fmprb_clear(t); + fmprb_clear(u); + fmprb_clear(v); + } + +#undef a +#undef b +#undef c +#undef d +} + +static __inline__ void +fmpcb_inv(fmpcb_t z, const fmpcb_t x, long prec) +{ + fmprb_t t; + fmprb_init(t); + +#define a fmpcb_realref(x) +#define b fmpcb_imagref(x) + + fmprb_mul(t, a, a, prec); + fmprb_addmul(t, b, b, prec); + + fmprb_div(fmpcb_realref(z), a, t, prec); + fmprb_div(fmpcb_imagref(z), b, t, prec); + + fmprb_neg(fmpcb_imagref(z), fmpcb_imagref(z)); + +#undef a +#undef b + + fmprb_clear(t); +} + + +static __inline__ void +_fmpcb_vec_zero(fmpcb_struct * A, long n) +{ + long i; + for (i = 0; i < n; i++) + fmpcb_zero(A + i); +} + +static __inline__ void +_fmpcb_vec_set(fmpcb_struct * res, const fmpcb_struct * vec, long len) +{ + long i; + for (i = 0; i < len; i++) + fmpcb_set(res + i, vec + i); +} + +void fmpcb_printd(const fmpcb_t z, long digits); + +#endif diff --git a/fmpcb/Makefile b/fmpcb/Makefile new file mode 100644 index 00000000..c7e54132 --- /dev/null +++ b/fmpcb/Makefile @@ -0,0 +1,43 @@ +SOURCES = $(wildcard *.c) + +OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(SOURCES)) + +LIB_OBJS = $(patsubst %.c, $(BUILD_DIR)/%.lo, $(SOURCES)) + +TEST_SOURCES = $(wildcard test/*.c) + +PROF_SOURCES = $(wildcard profile/*.c) + +TUNE_SOURCES = $(wildcard tune/*.c) + +TESTS = $(patsubst %.c, %, $(TEST_SOURCES)) + +PROFS = $(patsubst %.c, %, $(PROF_SOURCES)) + +TUNE = $(patsubst %.c, %, $(TUNE_SOURCES)) + +all: $(OBJS) + +library: $(LIB_OBJS) + +profile: + $(foreach prog, $(PROFS), $(CC) -O2 -std=c99 $(INCS) $(prog).c ../profiler.o -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + +tune: $(TUNE_SOURCES) + $(foreach prog, $(TUNE), $(CC) -O2 -std=c99 $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + +$(BUILD_DIR)/%.o: %.c + $(CC) $(CFLAGS) -c $(INCS) $< -o $@ + +$(BUILD_DIR)/%.lo: %.c + $(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@ + +clean: + rm -rf $(BUILD_DIR) + +check: library + $(foreach prog, $(TESTS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + $(foreach prog, $(TESTS), $(BUILD_DIR)/$(prog);) + +.PHONY: profile clean check all + diff --git a/fmpcb/printd.c b/fmpcb/printd.c new file mode 100644 index 00000000..b04268a1 --- /dev/null +++ b/fmpcb/printd.c @@ -0,0 +1,44 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb.h" + +void +fmpcb_printd(const fmpcb_t z, long digits) +{ + printf("("); + fmpr_printd(fmprb_midref(fmpcb_realref(z)), digits); + printf(" + "); + fmpr_printd(fmprb_midref(fmpcb_imagref(z)), digits); + printf("j)"); + + printf(" +/- "); + + printf("("); + fmpr_printd(fmprb_radref(fmpcb_realref(z)), 3); + printf(", "); + fmpr_printd(fmprb_radref(fmpcb_imagref(z)), 3); + printf("j)"); +} diff --git a/fmpcb_poly.h b/fmpcb_poly.h new file mode 100644 index 00000000..30f1ead6 --- /dev/null +++ b/fmpcb_poly.h @@ -0,0 +1,97 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#ifndef FMPCB_POLY_H +#define FMPCB_POLY_H + +#include "fmpcb.h" +#include "fmprb_poly.h" + +typedef struct +{ + fmpcb_struct * coeffs; + long length; + long alloc; +} +fmpcb_poly_struct; + +typedef fmpcb_poly_struct fmpcb_poly_t[1]; + + +/* Memory management */ + +void fmpcb_poly_init(fmpcb_poly_t poly); + +void fmpcb_poly_init2(fmpcb_poly_t poly, long len); + +void fmpcb_poly_clear(fmpcb_poly_t poly); + +void fmpcb_poly_fit_length(fmpcb_poly_t poly, long len); + +void _fmpcb_poly_set_length(fmpcb_poly_t poly, long len); + +void _fmpcb_poly_normalise(fmpcb_poly_t poly); + +static __inline__ void +fmpcb_poly_swap(fmpcb_poly_t poly1, fmpcb_poly_t poly2) +{ + fmpcb_poly_struct t = *poly1; + *poly1 = *poly2; + *poly2 = t; +} + +static __inline__ long fmpcb_poly_length(const fmpcb_poly_t poly) +{ + return poly->length; +} + +static __inline__ void fmpcb_poly_zero(fmpcb_poly_t poly) +{ + poly->length = 0; +} + +static __inline__ void +fmpcb_poly_one(fmpcb_poly_t poly) +{ + fmpcb_poly_fit_length(poly, 1); + fmpcb_one(poly->coeffs); + _fmpcb_poly_set_length(poly, 1); +} + +void fmpcb_poly_printd(const fmpcb_poly_t poly, long digits); + +void _fmpcb_poly_evaluate(fmpcb_t res, const fmpcb_struct * f, long len, const fmpcb_t a, long prec); + +void fmpcb_poly_evaluate(fmpcb_t res, const fmpcb_poly_t f, const fmpcb_t a, long prec); + +void _fmpcb_poly_derivative(fmpcb_struct * res, const fmpcb_struct * poly, long len, long prec); + +void fmpcb_poly_derivative(fmpcb_poly_t res, const fmpcb_poly_t poly, long prec); + +void fmpcb_poly_set2_fmprb_poly(fmpcb_poly_t poly, const fmprb_poly_t re, const fmprb_poly_t im); + +void fmpcb_poly_set2_fmpq_poly(fmpcb_poly_t poly, const fmpq_poly_t re, const fmpq_poly_t im, long prec); + +#endif diff --git a/fmpcb_poly/Makefile b/fmpcb_poly/Makefile new file mode 100644 index 00000000..c7e54132 --- /dev/null +++ b/fmpcb_poly/Makefile @@ -0,0 +1,43 @@ +SOURCES = $(wildcard *.c) + +OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(SOURCES)) + +LIB_OBJS = $(patsubst %.c, $(BUILD_DIR)/%.lo, $(SOURCES)) + +TEST_SOURCES = $(wildcard test/*.c) + +PROF_SOURCES = $(wildcard profile/*.c) + +TUNE_SOURCES = $(wildcard tune/*.c) + +TESTS = $(patsubst %.c, %, $(TEST_SOURCES)) + +PROFS = $(patsubst %.c, %, $(PROF_SOURCES)) + +TUNE = $(patsubst %.c, %, $(TUNE_SOURCES)) + +all: $(OBJS) + +library: $(LIB_OBJS) + +profile: + $(foreach prog, $(PROFS), $(CC) -O2 -std=c99 $(INCS) $(prog).c ../profiler.o -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + +tune: $(TUNE_SOURCES) + $(foreach prog, $(TUNE), $(CC) -O2 -std=c99 $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + +$(BUILD_DIR)/%.o: %.c + $(CC) $(CFLAGS) -c $(INCS) $< -o $@ + +$(BUILD_DIR)/%.lo: %.c + $(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@ + +clean: + rm -rf $(BUILD_DIR) + +check: library + $(foreach prog, $(TESTS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;) + $(foreach prog, $(TESTS), $(BUILD_DIR)/$(prog);) + +.PHONY: profile clean check all + diff --git a/fmpcb_poly/clear.c b/fmpcb_poly/clear.c new file mode 100644 index 00000000..19044f31 --- /dev/null +++ b/fmpcb_poly/clear.c @@ -0,0 +1,37 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_clear(fmpcb_poly_t poly) +{ + long i; + + for (i = 0; i < poly->alloc; i++) + fmpcb_clear(poly->coeffs + i); + + flint_free(poly->coeffs); +} diff --git a/fmpcb_poly/derivative.c b/fmpcb_poly/derivative.c new file mode 100644 index 00000000..65a579fc --- /dev/null +++ b/fmpcb_poly/derivative.c @@ -0,0 +1,52 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +_fmpcb_poly_derivative(fmpcb_struct * res, const fmpcb_struct * poly, long len, long prec) +{ + long i; + + for (i = 1; i < len; i++) + fmpcb_mul_ui(res + i - 1, poly + i, i, prec); +} + +void +fmpcb_poly_derivative(fmpcb_poly_t res, const fmpcb_poly_t poly, long prec) +{ + long len = poly->length; + + if (len < 2) + { + fmpcb_poly_zero(res); + } + else + { + fmpcb_poly_fit_length(res, len - 1); + _fmpcb_poly_derivative(res->coeffs, poly->coeffs, len, prec); + _fmpcb_poly_set_length(res, len - 1); + } +} diff --git a/fmpcb_poly/evaluate.c b/fmpcb_poly/evaluate.c new file mode 100644 index 00000000..e676273b --- /dev/null +++ b/fmpcb_poly/evaluate.c @@ -0,0 +1,69 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +_fmpcb_poly_evaluate(fmpcb_t res, const fmpcb_struct * f, long len, + const fmpcb_t a, long prec) +{ + if (len == 0) + { + fmpcb_zero(res); + } + else if (len == 1 || fmpcb_is_zero(a)) + { + fmpcb_set(res, f); + } + else + { + long i = len - 1; + fmpcb_t t; + + fmpcb_init(t); + fmpcb_set(res, f + i); + for (i = len - 2; i >= 0; i--) + { + fmpcb_mul(t, res, a, prec); + fmpcb_add(res, f + i, t, prec); + } + fmpcb_clear(t); + } +} + +void +fmpcb_poly_evaluate(fmpcb_t res, const fmpcb_poly_t f, const fmpcb_t a, long prec) +{ + if (res == a) + { + fmpcb_t t; + fmpcb_init(t); + _fmpcb_poly_evaluate(t, f->coeffs, f->length, a, prec); + fmpcb_swap(res, t); + fmpcb_clear(t); + } + else + _fmpcb_poly_evaluate(res, f->coeffs, f->length, a, prec); +} diff --git a/fmpcb_poly/fit_length.c b/fmpcb_poly/fit_length.c new file mode 100644 index 00000000..53faa544 --- /dev/null +++ b/fmpcb_poly/fit_length.c @@ -0,0 +1,46 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_fit_length(fmpcb_poly_t poly, long len) +{ + long i; + + if (len > poly->alloc) + { + if (len < 2 * poly->alloc) + len = 2 * poly->alloc; + + poly->coeffs = flint_realloc(poly->coeffs, + len * sizeof(fmpcb_struct)); + + for (i = poly->alloc; i < len; i++) + fmpcb_init(poly->coeffs + i); + + poly->alloc = len; + } +} diff --git a/fmpcb_poly/init.c b/fmpcb_poly/init.c new file mode 100644 index 00000000..f7113777 --- /dev/null +++ b/fmpcb_poly/init.c @@ -0,0 +1,41 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_init(fmpcb_poly_t poly) +{ + poly->coeffs = NULL; + poly->length = 0; + poly->alloc = 0; +} + +void +fmpcb_poly_init2(fmpcb_poly_t poly, long len) +{ + fmpcb_poly_init(poly); + fmpcb_poly_fit_length(poly, len); +} diff --git a/fmpcb_poly/normalise.c b/fmpcb_poly/normalise.c new file mode 100644 index 00000000..15b6d1dc --- /dev/null +++ b/fmpcb_poly/normalise.c @@ -0,0 +1,37 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +_fmpcb_poly_normalise(fmpcb_poly_t poly) +{ + long i; + + for (i = poly->length - 1; + (i >= 0) && fmpcb_is_zero(poly->coeffs + i); i--); + + poly->length = i + 1; +} diff --git a/fmpcb_poly/printd.c b/fmpcb_poly/printd.c new file mode 100644 index 00000000..5bd0bb57 --- /dev/null +++ b/fmpcb_poly/printd.c @@ -0,0 +1,43 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_printd(const fmpcb_poly_t poly, long digits) +{ + long i; + + printf("["); + + for (i = 0; i < poly->length; i++) + { + fmpcb_printd(poly->coeffs + i, digits); + if (i + 1 < poly->length) + printf("\n"); + } + + printf("]"); +} diff --git a/fmpcb_poly/set.c b/fmpcb_poly/set.c new file mode 100644 index 00000000..d40440fd --- /dev/null +++ b/fmpcb_poly/set.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_set(fmpcb_poly_t dest, const fmpcb_poly_t src) +{ + long len = fmpcb_poly_length(src); + + fmpcb_poly_fit_length(dest, len); + _fmpcb_vec_set(dest->coeffs, src->coeffs, len); + _fmpcb_poly_set_length(dest, len); +} diff --git a/fmpcb_poly/set2_fmpq_poly.c b/fmpcb_poly/set2_fmpq_poly.c new file mode 100644 index 00000000..3d627214 --- /dev/null +++ b/fmpcb_poly/set2_fmpq_poly.c @@ -0,0 +1,42 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_set2_fmpq_poly(fmpcb_poly_t poly, const fmpq_poly_t re, const fmpq_poly_t im, long prec) +{ + fmprb_poly_t t, u; + fmprb_poly_init(t); + fmprb_poly_init(u); + + fmprb_poly_set_fmpq_poly(t, re, prec); + fmprb_poly_set_fmpq_poly(u, im, prec); + + fmpcb_poly_set2_fmprb_poly(poly, t, u); + + fmprb_poly_clear(t); + fmprb_poly_clear(u); +} diff --git a/fmpcb_poly/set2_fmprb_poly.c b/fmpcb_poly/set2_fmprb_poly.c new file mode 100644 index 00000000..8be119d5 --- /dev/null +++ b/fmpcb_poly/set2_fmprb_poly.c @@ -0,0 +1,50 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +fmpcb_poly_set2_fmprb_poly(fmpcb_poly_t poly, const fmprb_poly_t re, const fmprb_poly_t im) +{ + long i, rlen, ilen, len; + + rlen = fmprb_poly_length(re); + ilen = fmprb_poly_length(im); + len = FLINT_MAX(rlen, ilen); + + fmpcb_poly_fit_length(poly, len); + + for (i = 0; i < rlen; i++) + fmprb_set(fmpcb_realref(poly->coeffs + i), re->coeffs + i); + for (i = rlen; i < len; i++) + fmprb_zero(fmpcb_realref(poly->coeffs + i)); + + for (i = 0; i < ilen; i++) + fmprb_set(fmpcb_imagref(poly->coeffs + i), im->coeffs + i); + for (i = ilen; i < len; i++) + fmprb_zero(fmpcb_imagref(poly->coeffs + i)); + + _fmpcb_poly_set_length(poly, len); +} diff --git a/fmpcb_poly/set_length.c b/fmpcb_poly/set_length.c new file mode 100644 index 00000000..29e86707 --- /dev/null +++ b/fmpcb_poly/set_length.c @@ -0,0 +1,40 @@ +/*============================================================================= + + This file is part of ARB. + + ARB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + ARB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ARB; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2012 Fredrik Johansson + +******************************************************************************/ + +#include "fmpcb_poly.h" + +void +_fmpcb_poly_set_length(fmpcb_poly_t poly, long len) +{ + long i; + + if (poly->length > len) + { + for (i = len; i < poly->length; i++) + fmpcb_zero(poly->coeffs + i); + } + + poly->length = len; +}