Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Apr 5, 2012
0 parents commit 019a921
Show file tree
Hide file tree
Showing 52 changed files with 4,750 additions and 0 deletions.
106 changes: 106 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
LIBS=-L$(CURDIR) -L$(ARB_FLINT_LIB_DIR) -L$(ARB_MPIR_LIB_DIR) -L$(ARB_MPFR_LIB_DIR) -larb -lflint -lmpir -lmpfr -lm
LIBS2=-L$(ARB_FLINT_LIB_DIR) -L$(ARB_MPIR_LIB_DIR) -L$(ARB_MPFR_LIB_DIR) -lmpir -lmpfr -lflint -lm
INCS=-I$(CURDIR) -I$(ARB_MPIR_INCLUDE_DIR) -I$(ARB_MPFR_INCLUDE_DIR) -I$(ARB_FLINT_INCLUDE_DIR)
LINKLIBS=$(ARB_MPIR_LIB_DIR)/libmpir.a $(ARB_MPFR_LIB_DIR)/libmpfr.a $(ARB_FLINT_LIB_DIR)/libflint.so

LD_LIBRARY_PATH:=${CURDIR}:${ARB_FLINT_LIB_DIR}:${ARB_MPFR_LIB_DIR}:${ARB_MPIR_LIB_DIR}:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
export

SOURCES = $(wildcard *.c)

HEADERS = $(wildcard *.h)

OBJS = $(patsubst %.c, build/%.o, $(SOURCES))

LOBJS = $(patsubst %.c, build/%.lo, $(SOURCES))

LIB_SOURCES = $(SOURCES) $(foreach dir, $(BUILD_DIRS), $(wildcard $(dir)/*.c))

LIB_OBJS = $(patsubst %.c, build/%.lo, $(LIB_SOURCES))

EXMP_SOURCES = $(wildcard examples/*.c)

TEST_SOURCES = $(wildcard test/*.c)

PROF_SOURCES = $(wildcard profile/*.c)

EXMPS = $(patsubst %.c, %, $(EXMP_SOURCES))

TESTS = $(patsubst %.c, %, $(TEST_SOURCES))

PROFS = $(patsubst %.c, %, $(PROF_SOURCES))

all: all-dirs $(OBJS) recursive library

all-dirs:
$(foreach dir, $(BUILD_DIRS), mkdir -p build/$(dir);)

clean:
$(foreach dir, $(BUILD_DIRS), export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir) clean;)
rm -f $(OBJS) $(LOBJS) $(TESTS) $(PROFS) $(EXMPS) $(ARB_LIB) libarb.a
rm -rf build

distclean: clean
rm -f Makefile

dist:
git archive --format tar --prefix arb-0.0/ trunk > ../arb-0.0.tar; gzip ../arb-0.0.tar

profile: all profiler.o
mkdir -p build/profile
$(foreach prog, $(PROFS), $(CC) -O2 -std=c99 $(INCS) $(prog).c profiler.o -o build/$(prog) $(LIBS);)
$(foreach dir, $(BUILD_DIRS), mkdir -p build/$(dir)/profile; export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir) profile;)

recursive:
$(foreach dir, $(BUILD_DIRS), export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir);)

examples: all $(LOBJS) library
mkdir -p build/examples
$(foreach prog, $(EXMPS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o build/$(prog) $(LIBS);)

check: $(ARB_LIB)
ifndef MOD
mkdir -p build/test
$(foreach prog, $(TESTS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o build/$(prog) $(LIBS);)
$(foreach prog, $(TESTS), build/$(prog);)
$(foreach dir, $(BUILD_DIRS), mkdir -p build/$(dir)/test; export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir) check;)
else
$(foreach dir, $(MOD), mkdir -p build/$(dir)/test; export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir) check;)
endif

library: library-recursive $(OBJS) $(LIB_OBJS)
mkdir -p build
ifdef ARB_SHARED
$(CC) -fPIC -shared $(LIB_OBJS) $(LIBS2) -o $(ARB_LIB)
endif
ifdef ARB_STATIC
$(AR) rcs libarb.a $(OBJS) $(LINKLIBS)
endif

library-recursive:
$(foreach dir, $(BUILD_DIRS), mkdir -p build/$(dir); export BUILD_DIR=../build/$(dir); $(MAKE) -C $(dir) library;)

$(ARB_LIB): library

install: library
mkdir -p $(PREFIX)/lib
mkdir -p $(PREFIX)/include
ifdef ARB_SHARED
cp $(ARB_LIB) $(PREFIX)/lib
endif
ifdef ARB_STATIC
cp libarb.a $(PREFIX)/lib
endif
cp *.h $(PREFIX)/include

.PHONY: profile library library-recursive recursive clean check check-recursive all

build/%.lo: %.c
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@

build/%.o: %.c
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@

BUILD_DIRS = arb

6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is an experimental C library implementing arbitrary-precision ball arithmetic on top of FLINT (http://flintlib.org/). Planned future additions include more functions, complex numbers, polynomial balls, and matrix balls. When the code stabilizes, it might get merged back into FLINT.

Author: Fredrik Johansson <fredrik.johansson@gmail.com>

The build scripts are copied from FLINT and were written by Bill Hart.

161 changes: 161 additions & 0 deletions arb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*=============================================================================
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 ARB_H
#define ARB_H

#include <stdio.h>
#include <mpir.h>
#include <mpfr.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq.h"

typedef struct
{
fmpz mid;
fmpz exp;
fmpz rad;
long prec;
}
arb_struct;

#define arb_midref(x) (&(x)->mid)
#define arb_expref(x) (&(x)->exp)
#define arb_radref(x) (&(x)->rad)
#define arb_prec(x) ((x)->prec)

typedef arb_struct arb_t[1];

void arb_init(arb_t x, long prec);
void arb_clear(arb_t x);
void arb_set(arb_t x, const arb_t y);

void arb_randtest(arb_t x, flint_rand_t state, long exp_bits);
void arb_debug(const arb_t x);

void arb_set_fmpz(arb_t x, const fmpz_t c);
void arb_set_si(arb_t x, long c);
void arb_set_ui(arb_t x, ulong c);

int arb_contains_zero(const arb_t x);
int arb_contains_ui(const arb_t x, ulong z);
int arb_contains_fmpq(const arb_t x, const fmpq_t q);
int arb_contains_fmpz(const arb_t x, const fmpz_t z);
int arb_contains_mpfr(const arb_t x, const mpfr_t z);

void arb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const arb_t x);

void _arb_get_mpfr(mpfr_t f, const fmpz_t mid, const fmpz_t exp, mpfr_rnd_t rnd);
void arb_get_mpfr(mpfr_t f, const arb_t x, mpfr_rnd_t rnd);

static __inline__ void
_arb_normalise(arb_t x)
{
fmpz c = *arb_midref(x);

if (COEFF_IS_MPZ(c))
{
long limbs, shift;
__mpz_struct * z = COEFF_TO_PTR(c);

limbs = mpz_size(z);
shift = FLINT_BITS * (limbs-1) - arb_prec(x);

if (shift > 0)
{
mpz_tdiv_q_2exp(z, z, shift);
_fmpz_demote_val(arb_midref(x));
fmpz_add_ui(arb_expref(x), arb_expref(x), shift);

if (fmpz_is_zero(arb_radref(x)))
{
*arb_radref(x) = 1UL;
}
else
{
fmpz_cdiv_q_2exp(arb_radref(x), arb_radref(x), shift);
fmpz_add_ui(arb_radref(x), arb_radref(x), 1UL);
}
}
}
}

static __inline__ void
arb_zero(arb_t x)
{
fmpz_zero(arb_midref(x));
fmpz_zero(arb_expref(x));
fmpz_zero(arb_radref(x));
}

void arb_set_si(arb_t x, long c);
void arb_set_ui(arb_t x, unsigned long c);
void arb_set_fmpz(arb_t x, const fmpz_t c);
void _arb_set_fmpq(arb_t x, const fmpz_t p, const fmpz_t q);
void arb_set_fmpq(arb_t x, const fmpq_t c);

void arb_add(arb_t z, const arb_t x, const arb_t y);
void arb_sub(arb_t z, const arb_t x, const arb_t y);
void arb_mul(arb_t z, const arb_t x, const arb_t y);
void arb_addmul(arb_t z, const arb_t x, const arb_t y);
void arb_submul(arb_t z, const arb_t x, const arb_t y);
void arb_div(arb_t c, const arb_t a, const arb_t b);

void arb_mul_si(arb_t y, const arb_t x, long c);

void arb_sqrt_fmpz(arb_t x, const fmpz_t n);
void arb_sqrt_ui(arb_t x, ulong n);
void arb_log_ui(arb_t x, ulong n);

void arb_add_error_2exp(arb_t x, long c);

void arb_const_pi_chudnovsky(arb_t x);
void arb_const_euler_brent_mcmillan(arb_t x);
void arb_const_zeta3_bsplit(arb_t x);
void arb_zeta_ui_bsplit(arb_t x, ulong s);

/* fmpz extras */

static __inline__ void
_fmpz_set_si_small(fmpz_t x, long c)
{
_fmpz_demote(x);
*x = c;
}

static __inline__ void
_fmpz_mul_abs(fmpz_t f, const fmpz_t g, const fmpz_t h)
{
fmpz_mul(f, g, h);
fmpz_abs(f, f);
}

void _fmpz_addmul_abs(fmpz_t, const fmpz_t, const fmpz_t);

void _fmpz_addmul_abs_ui(fmpz_t, const fmpz_t, ulong x);


#endif
42 changes: 42 additions & 0 deletions arb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
Loading

0 comments on commit 019a921

Please sign in to comment.