-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Split arb_pow_fmpz_binexp
into a ui
and mpz
version and implement proper arb_sqr
#396
Open
albinahlback
wants to merge
12
commits into
flintlib:master
Choose a base branch
from
albinahlback:arf_sqr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
500c3ee
Add nn_sqr_2 and arf_sqr_special
albinahlback 0bc4896
Fix faulty comment
albinahlback 135a520
Add test for nn_sqr_2
albinahlback 5f9770c
Split up pow_fmpz_binexp into a mpz and ui version
albinahlback 37fba37
Add _fmpz_2times_fast for setting 2*x+c
albinahlback 363527b
Remove unneccessary declaration
albinahlback 241252f
Add arf_sqr_via_mpfr and arf_sqr_rnd_down
albinahlback 56201d2
Remove sgnbit in arf_sqr_rnd_down
albinahlback 872863b
Add proper arb_sqr
albinahlback 487051b
Add docstrings for the new functions
albinahlback efd8f3b
Fix test for arb_sqr
albinahlback 780afe8
Fix arf_sqr_special and de-inline it
albinahlback File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
Copyright (C) 2012, 2013 Fredrik Johansson | ||
Copyright (C) 2021 Albin Ahlbäck | ||
|
||
This file is part of Arb. | ||
|
||
Arb is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU Lesser General Public License (LGPL) as published | ||
by the Free Software Foundation; either version 2.1 of the License, or | ||
(at your option) any later version. See <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "arb.h" | ||
|
||
void | ||
_arb_pow_mpz_binexp(arb_t y, const arb_t b, mpz_srcptr e, slong prec) | ||
{ | ||
slong i, wp, bits; | ||
|
||
if (e->_mp_size < 0) | ||
{ | ||
__mpz_struct f = { 1, 0, NULL }; | ||
f._mp_size = -(e->_mp_size); | ||
f._mp_d = e->_mp_d; | ||
|
||
if (arb_is_exact(b)) | ||
{ | ||
_arb_pow_mpz_binexp(y, b, &f, prec + 2); | ||
arb_inv(y, y, prec); | ||
} | ||
else | ||
{ | ||
arb_inv(y, b, prec + mpz_sizeinbase(e, 2) + 2); | ||
_arb_pow_mpz_binexp(y, y, &f, prec); | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (y == b) | ||
{ | ||
arb_t t; | ||
arb_init(t); | ||
arb_set(t, b); | ||
_arb_pow_mpz_binexp(y, t, e, prec); | ||
arb_clear(t); | ||
return; | ||
} | ||
|
||
arb_set(y, b); | ||
|
||
bits = mpz_sizeinbase(e, 2); | ||
wp = ARF_PREC_ADD(prec, bits); | ||
|
||
for (i = bits - 2; i >= 0; i--) | ||
{ | ||
arb_sqr(y, y, wp); | ||
if (mpz_tstbit(e, i)) | ||
arb_mul(y, y, b, wp); | ||
} | ||
} | ||
|
||
void | ||
arb_pow_ui_binexp(arb_t y, const arb_t b, ulong e, slong prec) | ||
{ | ||
slong i, wp, bits; | ||
|
||
if (e <= 2) | ||
{ | ||
if (e == 0) | ||
arb_one(y); | ||
else if (e == 1) | ||
arb_set_round(y, b, prec); | ||
else | ||
arb_sqr(y, b, prec); | ||
return; | ||
} | ||
|
||
if (y == b) | ||
{ | ||
arb_t t; | ||
arb_init(t); | ||
arb_set(t, b); | ||
arb_pow_ui_binexp(y, t, e, prec); | ||
arb_clear(t); | ||
return; | ||
} | ||
|
||
arb_set(y, b); | ||
|
||
bits = FLINT_BIT_COUNT(e); | ||
wp = ARF_PREC_ADD(prec, bits); | ||
|
||
for (i = bits - 2; i >= 0; i--) | ||
{ | ||
arb_sqr(y, y, wp); | ||
if (((WORD(1) << i) & e) != 0) | ||
arb_mul(y, y, b, wp); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright (C) 2021 Albin Ahlbäck | ||
|
||
This file is part of Arb. | ||
|
||
Arb is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU Lesser General Public License (LGPL) as published | ||
by the Free Software Foundation; either version 2.1 of the License, or | ||
(at your option) any later version. See <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "arb.h" | ||
|
||
void | ||
arb_pow_si(arb_t y, const arb_t b, slong e, slong prec) | ||
{ | ||
if (e >= 0) | ||
arb_pow_ui_binexp(y, b, e, prec); | ||
else if (e == -1) | ||
arb_inv(y, b, prec); | ||
else if (e == -2) | ||
{ | ||
arb_inv(y, b, prec); | ||
arb_sqr(y, y, prec); | ||
} | ||
else if (arb_is_exact(b)) | ||
{ | ||
arb_pow_ui_binexp(y, b, -e, prec + 2); | ||
arb_inv(y, y, prec); | ||
} | ||
else | ||
{ | ||
e = -e; | ||
arb_inv(y, b, prec + FLINT_BIT_COUNT(e) + 2); | ||
arb_pow_ui_binexp(y, y, e, prec); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright (C) 2021 Albin Ahlbäck | ||
|
||
This file is part of Arb. | ||
|
||
Arb is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU Lesser General Public License (LGPL) as published | ||
by the Free Software Foundation; either version 2.1 of the License, or | ||
(at your option) any later version. See <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "arb.h" | ||
|
||
void | ||
arb_sqr(arb_t res, const arb_t x, slong prec) | ||
{ | ||
mag_t resr, xm; | ||
int inexact; | ||
|
||
if (arb_is_exact(x)) | ||
{ | ||
inexact = arf_sqr_rnd_down(arb_midref(res), arb_midref(x), prec); | ||
|
||
if (inexact) | ||
arf_mag_set_ulp(arb_radref(res), arb_midref(res), prec); | ||
else | ||
mag_zero(arb_radref(res)); | ||
} | ||
else if (ARB_IS_LAGOM(x) && ARB_IS_LAGOM(res)) | ||
{ | ||
mag_fast_init_set_arf(xm, arb_midref(x)); | ||
|
||
mag_init(resr); | ||
mag_fast_mul(resr, xm, arb_radref(x)); | ||
if (resr->exp < COEFF_MAX && resr->exp >= COEFF_MIN) | ||
(resr->exp)++; | ||
else | ||
fmpz_add_ui(&(resr->exp), &(resr->exp), 1); | ||
mag_fast_addmul(resr, arb_radref(x), arb_radref(x)); | ||
|
||
inexact = arf_sqr_rnd_down(arb_midref(res), arb_midref(x), prec); | ||
|
||
if (inexact) | ||
arf_mag_fast_add_ulp(resr, resr, arb_midref(res), prec); | ||
|
||
*arb_radref(res) = *resr; | ||
} | ||
else | ||
{ | ||
mag_init_set_arf(xm, arb_midref(x)); | ||
|
||
mag_init(resr); | ||
mag_mul(resr, xm, arb_radref(x)); | ||
fmpz_add_ui(&(resr->exp), &(resr->exp), 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use MAG_EXPREF |
||
mag_addmul(resr, arb_radref(x), arb_radref(x)); | ||
|
||
inexact = arf_sqr_rnd_down(arb_midref(res), arb_midref(x), prec); | ||
|
||
if (inexact) | ||
arf_mag_add_ulp(arb_radref(res), resr, arb_midref(res), prec); | ||
else | ||
mag_swap(arb_radref(res), resr); | ||
|
||
mag_clear(xm); | ||
mag_clear(resr); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks are not needed; the exponent can be increment with risk of overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume you meant without risk of overflow ;) Och god jul, Fredrik!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
God jul :)