mirror of
https://github.com/vale981/arb
synced 2025-03-05 09:21:38 -05:00
initial code for complex numbers and polynomials
This commit is contained in:
parent
561446b94b
commit
c305ff6338
17 changed files with 981 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
260
fmpcb.h
Normal file
260
fmpcb.h
Normal file
|
@ -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
|
43
fmpcb/Makefile
Normal file
43
fmpcb/Makefile
Normal file
|
@ -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
|
||||
|
44
fmpcb/printd.c
Normal file
44
fmpcb/printd.c
Normal file
|
@ -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)");
|
||||
}
|
97
fmpcb_poly.h
Normal file
97
fmpcb_poly.h
Normal file
|
@ -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
|
43
fmpcb_poly/Makefile
Normal file
43
fmpcb_poly/Makefile
Normal file
|
@ -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
|
||||
|
37
fmpcb_poly/clear.c
Normal file
37
fmpcb_poly/clear.c
Normal file
|
@ -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);
|
||||
}
|
52
fmpcb_poly/derivative.c
Normal file
52
fmpcb_poly/derivative.c
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
69
fmpcb_poly/evaluate.c
Normal file
69
fmpcb_poly/evaluate.c
Normal file
|
@ -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);
|
||||
}
|
46
fmpcb_poly/fit_length.c
Normal file
46
fmpcb_poly/fit_length.c
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
41
fmpcb_poly/init.c
Normal file
41
fmpcb_poly/init.c
Normal file
|
@ -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);
|
||||
}
|
37
fmpcb_poly/normalise.c
Normal file
37
fmpcb_poly/normalise.c
Normal file
|
@ -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;
|
||||
}
|
43
fmpcb_poly/printd.c
Normal file
43
fmpcb_poly/printd.c
Normal file
|
@ -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("]");
|
||||
}
|
36
fmpcb_poly/set.c
Normal file
36
fmpcb_poly/set.c
Normal file
|
@ -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);
|
||||
}
|
42
fmpcb_poly/set2_fmpq_poly.c
Normal file
42
fmpcb_poly/set2_fmpq_poly.c
Normal file
|
@ -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);
|
||||
}
|
50
fmpcb_poly/set2_fmprb_poly.c
Normal file
50
fmpcb_poly/set2_fmprb_poly.c
Normal file
|
@ -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);
|
||||
}
|
40
fmpcb_poly/set_length.c
Normal file
40
fmpcb_poly/set_length.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Reference in a new issue