Skip to content
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

cubing analysis #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cubing/NUCUBE.pdf
Binary file not shown.
72 changes: 72 additions & 0 deletions cubing/antic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "form_common.h"
#include "qfb.h"

static void qfb_find_c(qfb_t form, const fmpz_t D)
{
fmpz_mul(form->c, form->b, form->b);
fmpz_sub(form->c, form->c, D);
fmpz_tdiv_q_2exp(form->c, form->c, 2);
fmpz_divexact(form->c, form->c, form->a);
}

static void print_form(qfb_t form)
{
mpz_t a, b, c;

mpz_inits(a, b, c, NULL);
fmpz_get_mpz(a, form->a);
fmpz_get_mpz(b, form->b);
fmpz_get_mpz(c, form->c);
/*gmp_printf("a = %#Zx\nb = %#Zx\nc = %#Zx\n", a, b, c);*/
gmp_printf("a = %#Zx\nb = %#Zx\n", a, b);

mpz_clears(a, b, c, NULL);
}

int main(int argc, char **argv)
{
int i, iters = atoi(argv[1]), runtime, d_size, n_reductions = 0;
fmpz_t D, L;
qfb_t form;
uint64_t start;

fmpz_init(D);
fmpz_set_str(D, MAIN_DISCR, 10);

qfb_init(form);
fmpz_set_ui(form->a, 2);
fmpz_set_ui(form->b, 1);
qfb_find_c(form, D);
d_size = __GMP_ABS(COEFF_TO_PTR(*D)->_mp_size);

fmpz_init(L);
fmpz_neg(L, D);
fmpz_root(L, L, 4);

start = get_time();
for (i = 0; i < iters; i++) {
qfb_nudupl(form, form, D, L);
/*qfb_nucomp(form, form, form, D, L);*/
if (COEFF_IS_MPZ(*form->a) &&
__GMP_ABS(COEFF_TO_PTR(*form->a)->_mp_size) > d_size) {
qfb_reduce(form, form, D);
n_reductions++;
}
/*printf("iter = %d\n", i);*/
/*print_form(form);*/
}
qfb_reduce(form, form, D);
print_form(form);
/*gmp_printf("D = %#Zx\nL = %#Zx\n", COEFF_TO_PTR(*D), COEFF_TO_PTR(*L));*/

runtime = (int)((get_time() - start) / 1000000);

runtime = runtime ? runtime : 1;
printf("Time: %d ms; speed: %dK ips\n", runtime, iters / runtime);
printf("n_reductions: %d\n", n_reductions);

fmpz_clear(D);
qfb_clear(form);
fmpz_clear(L);
return 0;
}
43 changes: 43 additions & 0 deletions cubing/bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
make -B libq;

for i in {0..1}
do

for j in {0..1}
do
if [ "$i" == 0 ]; then
if [ "$j" == 0 ]; then
printf "\n\ncubing never reducing\n\n"
else
printf "\n\ncubing always reducing\n\n"
fi
else
if [ "$j" == 0 ] ; then
printf "\n\nsquaring never reducing\n\n"
else
printf "\n\nsquaring always reducing\n\n"
fi
fi

for k in {1..5}
do
if [ "$i" == 1 ]; then
./libq 1000000 "$i" "$j";
else
./libq 630929 "$i" "$j";
fi
printf "\n"
done

for k in {1..3}
do
if [ "$i" == 1 ]; then
./libq 10000000 "$i" "$j";
else
./libq 6309297 "$i" "$j";
fi
printf "\n"
done
done
done
27 changes: 27 additions & 0 deletions cubing/form_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _FORM_COMMON_H
#define _FORM_COMMON_H

#include <inttypes.h>
#include <time.h>

static uint64_t get_time(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}

//#define MAIN_DISCR "-141140317794792668862943332656856519378482291428727287413318722089216448567155737094768903643716404517549715385664163360316296284155310058980984373770517398492951860161717960368874227473669336541818575166839209228684755811071416376384551902149780184532086881683576071479646499601330824259260645952517205526679"
//#define MAIN_DISCR "-27793237001305170698656509497755844092586386872496295629779837507971117559354691523581890478176914693359675630301087242227995550958743592046124379271342523117944672201940224307563498623282396336043787901362415643315794359898423628976229444385132461815183120709043651974544581523175645485793883889543615011559151806508862786144831212673747194337362835767292592316842392285011597319847853278165631070684231627247677822273593999074723433871243030768063363559931194419142809976257675348498631355931756891791994467558601521208397038790339158400191945339609224183625935566879000287625158572127711542235803324639115306136663"
//#define MAIN_DISCR "-127164462567847778219294467290798377711838589019145190353449816167344564110074781472688725188393418671695166379136185123981715928520244618453846477324756550462271161980528136156888957489523978997469231408034701544783191950766365099765349852625276283636470182602947454694471830519159273251751637689469616413503"
//#define MAIN_DISCR "-22860268135667589903208331872058959644142720896076490823036956523426871243057005623505476986654689939375998245856993161024948296872170534869221722135644973959012888002949501494113381338789280303679733080730438033019666639966900351382828082678005982175916602634000534350896624481506431434777044646876008529391876870048240213603396995410840224417690158196925755814193658109752326536604932474550333192155457005596353353830007682583292452152740351360124232916300019971396822173991978324891202726049248875578742068807587094918402232524218740688217013728548119820088136470614150744917910151631117447073386272668820859492199"

//#define MAIN_DISCR "-23691568091548358017259637993407812230314418165147795386600373329848215683771213857667362169693733008362778716574316997235267858700764119559861600956511256676232855938030698277199034345585030857367890503704506447852347056438495676751737058302712794260556978257255965420246256846535943700876456389936134171956545720945246308667940474052840791070914617357917504498950677428796391022066582256269060483532160164032601359274999843795007300555505628490825410097167679058715770442045778766944473863675430083574437852351295513093909413328168246461511861248888011238680533933347710420259769808235209837173054653629903258229223"
//#define MAIN_DISCR "-131788722068868995676597214155436530472810282104737608756485556614199943757271803669298052494822291665034138798731021924874395047959731936765171871991647982416831489547155946335728383690668539299047258214816845534257572287426350486052693277642931121286508704257275935248327283501566536594501890379884486903911"
#define MAIN_DISCR "-969542699839054213372756559081910261441572422049388279625057157914202573360476290538815084697016462533388018735857321275506472384116240431785651216842959700128207943153983702474771102417387067347954346010356753016781727718574844132457619818698134815371641287044279847846275781176210603265454227056201158552573373773308561536662653342433902035123958154319968493251665600024115268400788938644094045994623652444864289771665567412616405769135935620452382181651024012003257231298780350936606371667877988153352960951634013487235084185036501677385853912933220162974237910499109717515866315851982998050811889588467143598487581205367725385532250549352416245306164187176208711916465352732276759679438902318164735287291748441312225690698711484313234604936835826106150105179375497617419062393768508562366809053711125023442870179292917714278404500388652695814692602797907499014513338598109925496781256172390922050380407995004880095758153500180375851683462554992615514679303768539269778635645135306306559794161311351719718250980914786323272355574377305077401138916026674240156995369222389109902008973646843670232766516601516952329889013977779221308266668007503272646122932622881201681461709975882786411252681993719982707487477366128585267709405879"
//#define MAIN_DISCR "-10803348631530927498051139133692244575660405578875230976223327234876122403281659421806531129062326072200502709281708716321227674097332898098036720510889559"
//#define MAIN_DISCR "-9000330564166397509327590423889038062715879572962212921450570485956142854985901051805676903273940331395686458091858430390002283902379278168223089959414511"

//#define MAIN_DISCR "-102522683075961319165911365929379221882824975317180317196283357569799441166543"
//#define MAIN_DISCR "-309361850110207312103360594127882960623"
#endif /* _FORM_COMMON_H */
17 changes: 17 additions & 0 deletions cubing/gcdinv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "flint/fmpz.h"

int main()
{
fmpz_t a, b, d, inv;
unsigned int gcd;

fmpz_init_set_ui(a, 67309);
fmpz_init_set_ui(b, 65536);
fmpz_init(d);
fmpz_init(inv);

fmpz_gcdinv(d, inv, a, b);
gcd = fmpz_get_ui(d);
printf("gcd = %d\n", gcd);
return 0;
}
Binary file added cubing/libq
Binary file not shown.
103 changes: 103 additions & 0 deletions cubing/libq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "form_common.h"
#include "libqform/mpz_qform.h"
#include <time.h>

void mpz_qform_c(void *group, mpz_t c, mpz_t a, mpz_t b);

int main(int argc, char **argv)
{
int i, iters = atoi(argv[1]), runtime, d_size, n_reductions = 0;
int square = atoi(argv[2]);
int reduce = atoi(argv[3]);
mpz_t D;
mpz_qform_group_t group;
mpz_qform_t form;
uint64_t start;

mpz_init_set_str(D, MAIN_DISCR, 10);

mpz_qform_group_init(&group);
mpz_qform_group_set_discriminant(&group, D);
mpz_qform_init(&group, &form);
/*mpz_qform_set_id(&group, &form);*/
mpz_set_ui(form.a, 2);
mpz_set_ui(form.b, 1);
mpz_qform_c(&group, form.c, form.a, form.b);
d_size = __GMP_ABS(D->_mp_size);
//d_size = 8;

clock_t clock_start, clock_end;
double cube_avg, reduce_avg;

if (square == 1 && reduce == 1) {
start = get_time();
for (i = 0; i < iters; i++) {
/*clock_start = clock();
mpz_qform_square(&group, &form, &form);
clock_end = clock();
cube_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));

clock_start = clock();
mpz_qform_reduce(&group, &form);
clock_end = clock();
reduce_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));
n_reductions++;*/

mpz_qform_square(&group, &form, &form);
mpz_qform_reduce(&group, &form);
n_reductions++;
}
} else if (square == 1 && reduce == 0) {
start = get_time();
for (i = 0; i < iters; i++) {
/*clock_start = clock();
mpz_qform_square(&group, &form, &form);
clock_end = clock();
cube_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));*/

mpz_qform_square(&group, &form, &form);
}
} else if (square == 0 && reduce == 1) {
start = get_time();
for (i = 0; i < iters; i++) {
/*clock_start = clock();
mpz_qform_cube(&group, &form, &form);
clock_end = clock();
cube_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));

clock_start = clock();
mpz_qform_reduce(&group, &form);
clock_end = clock();
reduce_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));
n_reductions++;*/

mpz_qform_cube(&group, &form, &form);
mpz_qform_reduce(&group, &form);
n_reductions++;
}
} else if (square == 0 && reduce == 0) {
start = get_time();
for (i = 0; i < iters; i++) {
/*clock_start = clock();
mpz_qform_cube(&group, &form, &form);
clock_end = clock();
cube_avg += ((double) (clock_end - clock_start)) / ((double)(CLOCKS_PER_SEC));*/

mpz_qform_cube(&group, &form, &form);

}
}
mpz_qform_reduce(&group, &form);
runtime = (int)((get_time() - start) / 1000000);
/*gmp_printf("a = %#Zx\nb = %#Zx\nc = %#Zx\n", form.a, form.b, form.c);*/
gmp_printf("a = %#Zx\nb = %#Zx\n", form.a, form.b);
gmp_printf("D = %#Zx\nL = %#Zx\n", D, group.L);

runtime = runtime ? runtime : 1;
printf("Time: %d ms; speed: %dK ips\n", runtime, iters / runtime);
printf("n_reductions: %d\n", n_reductions);
//printf("cube avg: %f\n", cube_avg);
//printf("reduce avg: %f\n", reduce_avg);
mpz_clear(D);
return 0;
}
31 changes: 31 additions & 0 deletions cubing/long_bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
make -B libq;

for i in {0..1}
do

for j in {0..1}
do
if [ "$i" == 0 ]; then
if [ "$j" == 0 ]; then
printf "\n\ncubing never reducing\n\n"
else
printf "\n\ncubing always reducing\n\n"
fi
else
if [ "$j" == 0 ] ; then
printf "\n\nsquaring never reducing\n\n"
else
printf "\n\nsquaring always reducing\n\n"
fi
fi

if [ "$i" == 1 ]; then
./libq 30000000 "$i" "$j";
else
./libq 18927892 "$i" "$j";
fi
printf "\n"

done
done