User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Can you speed this code up?

Sat Apr 04, 2015 11:01 am

Hello there fellow Raspberry's I've been studying Prime numbers for a long time and this recent find is my best find. I'm not certain whether or not my primality test works for every Integer or if the test is a sort of probable prime test.
The challenge I leave to you is to speed the function up and to test the first 4000000000 numbers.
Feel free to cut paste and play with this code.

PrimeQu[a31_] :=
Module[{a34 = a31, ccf3 = Append[Table[1, {xd, a31 - 1}], 0]},
If[Mod[FromDigits[ccf3, 2], a34] == 0 &&
Mod[FromDigits[ccf3, 5], a34] == 0, True,
If[a34 == 2, True, False]]];

FuncTest[cg3_,cg4_] := Catch[Module[{at5 = cg4, atz = cg3, atd = 0, atc},
atc = RandomInteger[at5, atz + 1];
Label["spaz"];
atd = atd + 1;
If[PrimeQu[atc[[atd]]] == PrimeQ[atc[[atd]]], Goto["step2"];,
Goto["step3"];];
Label["step2"];
If[atd >= atz, Throw["All True"]; Goto["TEW"];, Goto["spaz"]];
Label["step3"];
Throw[{"False Result at", atc[[atd]]}];
Label["TEW"]
]];

bobthechemist
Posts: 11
Joined: Fri Mar 14, 2014 8:34 pm

Re: Can you speed this code up?

Sat Apr 04, 2015 3:21 pm

Is there a reason why you don't want to use the Mathematica function, PrimeQ?

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Sat Apr 04, 2015 3:42 pm

It's not Necessarily that I don't want to use PrimeQ. It's just that I want to be able to generate at least a quick list of potential large primes at a quick enough pace. I get great pleasure playing and studying the primes and a learn a lot from it.

User avatar
kusti8
Posts: 3441
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Can you speed this code up?

Sat Apr 04, 2015 6:46 pm

I don't really use mathematica that much, but this would probably be (if I left something out please correct me) the fastest:
Start at 4 and try 2 and 3. Since 4%2 = 0, then 4 is not prime. When trying 5, check only the previously calculated numbers up to the sqrt of the number+1, ie 2 and 3 are less than 5 but do not divide evenly. You can continue this pattern (check previous primes up until the sqrt of the number) and it should in theory be the fastest.

I myself am fascinated by prime numbers and have created a short program in python when solving for Project Euler that I believe is the fastest that way. I would love to hear any other improvements.
There are 10 types of people: those who understand binary and those who don't.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Sun Apr 05, 2015 2:29 am

kusti8 wrote:I don't really use mathematica that much, but this would probably be (if I left something out please correct me) the fastest:
Start at 4 and try 2 and 3. Since 4%2 = 0, then 4 is not prime. When trying 5, check only the previously calculated numbers up to the sqrt of the number+1, ie 2 and 3 are less than 5 but do not divide evenly. You can continue this pattern (check previous primes up until the sqrt of the number) and it should in theory be the fastest.

I myself am fascinated by prime numbers and have created a short program in python when solving for Project Euler that I believe is the fastest that way. I would love to hear any other improvements.
Ok I've managed to speed the function up and make it far more probable at the least Here's the MatheMatica Code.

PrimeQu[cex_] :=
Catch[
Module[
{zcv = PowerMod[2, cex, cex] - 2,
zcv2 =
JacobiSymbol[
FromDigits[Append[Table[1, {xvc, Floor[Log[2, cex]] + 1}], 0],
3] FromDigits[
Append[Table[1, {xvc, Floor[Log[3, cex]] + 1}], 0], 2],
cex],
zcv3 =
JacobiSymbol[
FromDigits[Append[Table[1, {xvc, Floor[Log[2, cex]] + 1}], 0],
5] FromDigits[
Append[Table[1, {xvc, Floor[Log[5, cex]] + 1}], 0], 2],
cex],
Var25, Var26, ced = cex
},
Var25 =
If[GCD[ced, 2] == 2 || GCD[ced, 3] == 3 || GCD[ced, 5] == 5,
If[ced == 2 || ced== 3 || ced == 5, 1, 2], 1];
Var26 = If[zcv == 0 && Abs[zcv2] == 1 && Abs[zcv3] == 1, 1, 2];
If[Var25 == 1 && Var26 == 1, Throw["True"], Throw["False"]];
]];
Last edited by qpwimblik on Sun Apr 05, 2015 7:34 am, edited 1 time in total.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Sun Apr 05, 2015 2:34 am

It's quite fast already all that's left now is to turn it into compile code and then try and make an asm file that does it a lot faster. I suspect I can get it running quicker than the current lot.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Tue Apr 07, 2015 12:58 pm

My searching function was faulty so I had to re-code the Prime Test Function.
This should work. If you can find any faults That I may have missed feel free to comment.

Test1[vbe_] :=
Catch[Module[{ce1 = vbe, zcv2, zcv3, zcv4, zcv5, zcv6, zcv7, zcv8,
zcv9, zcv10, zcv11},
zcv2 =
JacobiSymbol[ce1,
FromDigits[
Append[Table[1, {xvc1 , Round[N[Log[2, ce1], 3]]}], 0],
3] FromDigits[
Append[Table[1, {xvc2, Round[N[Log[3, ce1], 3]]}], 0], 2]];
zcv3 =
JacobiSymbol[ce1,
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[2, ce1], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce1], 3]]}], 0], 2]];
zcv4 =
JacobiSymbol[ce1,
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[3, ce1], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce1], 3]]}], 0], 3]];
Throw[{zcv2, zcv3, zcv4}]
]];

Test2[vbt_] := Catch[Module[{ce2 = vbt, zcv5, zcv6, zcv7},
zcv5 =
JacobiSymbol[ce2 2,
FromDigits[
Append[Table[1, {xvc1, Round[N[Log[2, ce2], 3]]}], 0],
3] FromDigits[
Append[Table[1, {xvc2, Round[N[Log[3, ce2], 3]]}], 0], 2]];
zcv6 =
JacobiSymbol[ce2 2,
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[2, ce2], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce2], 3]]}], 0], 2]];
zcv7 =
JacobiSymbol[ce2 2,
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[3, ce2], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce2], 3]]}], 0], 3]];

Throw[{zcv5, zcv6, zcv7}]
]];

Test3[vbs_] := Catch[Module[{ce3 = vbs, zcv8, zcv9, zcv10},
zcv8 =
JacobiSymbol[ce3^2,
FromDigits[Append[Table[1, {xvc1, Floor[Log[2, ce3]] + 1}], 0],
3] FromDigits[Append[Table[1, {xvc2, Floor[Log[3, ce3]]}], 0],
2]];
zcv9 =
JacobiSymbol[ce3^2,
FromDigits[Append[Table[1, {xvc3, Floor[Log[2, ce3]] + 1}], 0],
5] FromDigits[Append[Table[1, {xvc4, Floor[Log[5, ce3]]}], 0],
2]];
zcv10 =
JacobiSymbol[ce3^2,
FromDigits[Append[Table[1, {xvc3, Floor[Log[3, ce3]] + 1}], 0],
5] FromDigits[Append[Table[1, {xvc4, Floor[Log[5, ce3]]}], 0],
3]];

Throw[{zcv8, zcv9, zcv10}]
]];
Test6[vbe_] :=
Catch[Module[{ce1 = vbe, zcv2, zcv3, zcv4, zcv5, zcv6, zcv7, zcv8,
zcv9, zcv10, zcv11},
zcv2 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc1 , Round[N[Log[2, ce1], 3]]}], 0],
3] FromDigits[
Append[Table[1, {xvc2, Round[N[Log[3, ce1], 3]]}], 0], 2],
ce1];
zcv3 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[2, ce1], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce1], 3]]}], 0], 2],
ce1];
zcv4 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[3, ce1], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce1], 3]]}], 0], 3],
ce1];
Throw[{zcv2, zcv3, zcv4}]
]];

Test7[vbt_] := Catch[Module[{ce2 = vbt, zcv5, zcv6, zcv7},
zcv5 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc1, Round[N[Log[2, ce2], 3]]}], 0],
3] FromDigits[
Append[Table[1, {xvc2, Round[N[Log[3, ce2], 3]]}], 0], 2],
ce2 5];
zcv6 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[2, ce2], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce2], 3]]}], 0], 2],
ce2 5];
zcv7 =
JacobiSymbol[
FromDigits[
Append[Table[1, {xvc3, Round[N[Log[3, ce2], 3]]}], 0],
5] FromDigits[
Append[Table[1, {xvc4, Round[N[Log[5, ce2], 3]]}], 0], 3],
ce2 5];

Throw[{zcv5, zcv6, zcv7}]
]];

Test8[vbs_] := Catch[Module[{ce3 = vbs, zcv8, zcv9, zcv10},
zcv8 =
JacobiSymbol[
FromDigits[Append[Table[1, {xvc1, Floor[Log[2, ce3]] + 1}], 0],
3] FromDigits[Append[Table[1, {xvc2, Floor[Log[3, ce3]]}], 0],
2], ce3^3];
zcv9 =
JacobiSymbol[
FromDigits[Append[Table[1, {xvc3, Floor[Log[2, ce3]] + 1}], 0],
5] FromDigits[Append[Table[1, {xvc4, Floor[Log[5, ce3]]}], 0],
2], ce3^3];
zcv10 =
JacobiSymbol[
FromDigits[Append[Table[1, {xvc3, Floor[Log[3, ce3]] + 1}], 0],
5] FromDigits[Append[Table[1, {xvc4, Floor[Log[5, ce3]]}], 0],
3], ce3^3];

Throw[{zcv8, zcv9, zcv10}]
]];

Test4[vbr_] := Catch[Module[{zcv, zcv11, fbe = vbr},
zcv = PowerMod[2, fbe, fbe] - 2;
zcv11 = PowerMod[3, fbe, fbe] - 3;
Throw[{zcv, zcv11}]
]];

Test5[vbr2_] :=
Catch[Module[{Vbry = vbr2,
asnd = Append[Table[1, {ghd, vbr2 - 1}], 0], tes1, tes2},
tes1 = Mod[FromDigits[asnd, 2], Vbry];
tes2 = Mod[FromDigits[asnd, 5], Vbry];
Throw[{tes1, tes2}]
]];


PrimeQPW[cex_] :=
Catch[Module[{Var27, Var28, Var29, Var30, Var26 = Test1[cex],
Var25 = Abs[Test2[cex]], Var24 = Test3[cex], Var23 = Test4[cex],
ced = cex},
If[ced == 2 || ced == 3 || ced == 5 || ced == 7 || ced == 11 ||
ced == 13, Throw[True]; Break[];];
If[IntegerQ[ced/2] == True || IntegerQ[ced/3] == True ||
IntegerQ[ced/5] == True || IntegerQ[ced/7] == True ||
IntegerQ[ced/11] == True || IntegerQ[ced/13] == True,
Throw[False]; Break[];];
If[Total[Abs[Var26]] < 2, Throw[False]; Break[], Var27 = 1];
If[Total[Var25] > 1, Throw[False]; Break[], Var28 = 1];
If[Var26[[2]] == -1 && Total[Var24] < 3 || Total[Var24] == 3,
Var29 = 1;, Throw[False]; Break[];];
Var30 = If[Var23 == {0, 0}, 1, 2];
If[Var27 == 1 && Var28 == 1 && Var29 == 1 && Var30 == 1,
Throw[True];, Throw[False];];
]];

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Tue Apr 07, 2015 12:59 pm

I'm currently working On a far more optimal version.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Tue Apr 07, 2015 8:17 pm

A false reading has been reported at 488881.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Thu Apr 09, 2015 10:58 pm

Just about to write up a test based on this finding watch the zero count on this relating to the other stats.

FiveItt[x98_, cc5_] :=
If[x98 == 1, 1, FromDigits[Append[Table[1, {ft, x98 - 1}], 0], cc5]];

BCC[x55_, g77_] :=
Drop[Flatten[
Reap[Module[{x45 = x55, z7 = 0, z8 = 0, z9, g7 = g77, bell},
z7 = If[x45/FiveItt[Length[IntegerDigits[x45, g7]], g7] <= 1,
If[x45 == 1, 1, Length[IntegerDigits[x45, g7]] - 1],
Length[IntegerDigits[x45, g7]]];
bell = FiveItt[z7 - 1, g7];
z9 = g7^(z7 - 1);
Label[SPo];
z8 =
If[IntegerQ[x45/g7] && x45 > g7,
Quotient[x45 - bell - (1/(2*g7)), z9],
If[x45 <= g7, x45, Quotient[x45 - bell, z9]]];
Sow[z8];
x45 = x45 - (z8*(z9));
z7 = z7 - 1;
z9 = z9/g7;
bell = bell - z9;
If[z7 < 1, Goto[EnD], Goto[SPo]];
Label[EnD];]]], 1];

T2xy[x_, y_] := ((x + y) (x + y - 1))/2 - y + 1;
Zequeba[fre_, fre2_] := Total[BCC[fre, fre2]];

Test10[zz7_,
zz8_] := {JacobiSymbol[Zequeba[zz7, zz8], T2xy[zz7, zz8]],
JacobiSymbol[T2xy[zz7, zz8], Zequeba[zz7, zz8]],
JacobiSymbol[Zequeba[zz7, zz8], T2xy[zz8, zz7]],
JacobiSymbol[T2xy[zz8, zz7], Zequeba[zz7, zz8]]};

Lightening[asif_] := Table[Test10[asif, Prime[hha]], {hha, 1, 6}];

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Speedy speedy speedy Tools

Mon Apr 13, 2015 1:28 pm

My Tools

FiveItt[x98_, cc5_] :=
If[x98 == 1, 1, FromDigits[Append[Table[1, {ft, x98 - 1}], 0], cc5]];
RS[x_, y_] := \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{
FractionBox[
RowBox[{"Pochhammer", "[",
RowBox[{
RowBox[{"y", "+", "1"}], ",",
RowBox[{"x", "-", "1"}]}], "]"}],
RowBox[{
RowBox[{"(",
RowBox[{"x", "-", "1"}], ")"}], "!"}]],
RowBox[{
RowBox[{"Abs", "[", "x", "]"}], "<=", " ",
RowBox[{"Abs", "[", "y", "]"}]}]},
{
FractionBox[
RowBox[{"Pochhammer", "[",
RowBox[{"x", ",", "y"}], "]"}],
RowBox[{"y", "!"}]],
RowBox[{
RowBox[{"Abs", "[", "x", "]"}], ">",
RowBox[{"Abs", "[", "y", "]"}]}]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{
"Columns" -> {{Left}}, "ColumnsIndexed" -> {},
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
GridBoxItemSize->{
"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
"Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
Selectable->True]}
},
GridBoxAlignment->{
"Columns" -> {{Left}}, "ColumnsIndexed" -> {},
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
GridBoxItemSize->{
"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {},
"Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False]\);
Test4[vbr_] := Catch[Module[{zcv, zcv11, fbe = vbr},
zcv = PowerMod[2, fbe, fbe] - 2;
zcv11 = PowerMod[3, fbe, fbe] - 3;
Throw[{zcv, zcv11}]
]];
BCCLog[x22_, y22_] :=
Catch[Module[{s21 = x22, t22 = Length[IntegerDigits[x22, y22]]},
If[FiveItt[t22, y22] > s21, t22 = t22 - 1];
Throw[t22];
]];
T2xy[x_, y_] := ((x + y) (x + y - 1))/2 - y + 1;

Fifty[tas_, ras_] :=
Catch[Module[{tar = tas, rar = ras, leng1, fvar1, fvar2, fvar3},
fvar1 = Prime[rar];
fvar2 = Length[IntegerDigits[tar, fvar1]];
fvar3 = FiveItt[fvar2, fvar1];
If[fvar3 > tar, fvar2 = fvar2 - 1];
fvar3 = IntegerQ[Mod[(FiveItt[fvar2, fvar1] + tar), tar]/fvar2];
Throw[fvar3];
]];

Test10[aa7_, aa8_] :=

Catch[Module[{zz7 = aa7, zz8 = aa8, zz9 = T2xy[aa8, aa7],
zz10 = T2xy[aa7, aa8]},
Throw[{JacobiSymbol[zz7, zz10], JacobiSymbol[zz7, zz9],
JacobiSymbol[zz10, zz7], JacobiSymbol[zz9, zz7]}]]];

Test11[r56_, r58_] :=
Catch[Module[{x57 = r56, x58 = r58, x51, x52, d43, d44},
d44 = Prime[x58];
x51 = Length[IntegerDigits[x57, d44]];
x52 = FiveItt[x51, d44];
If[x52 > x57, x51 = x51 - 1];
d43 =
Flatten[Table[Test10[x57, r57*x51], {r57, x57, x57 + d44}]];

Throw[d43];
]];

MiniTest[y44_] :=
Catch[Module[{y45 = y44, y67 = T2xy[y44 + 5, y44],
y68 = T2xy[y44, y44 + 5]},
Throw[{JacobiSymbol[y67, y45], JacobiSymbol[y68, y45],
JacobiSymbol[y45, y67], JacobiSymbol[y45, y68]}]]];

Test14[t13_, t16_] := Catch[Module[{t14 = t13, Data12, t15 = t16},
Data12 = Test11[t14, t15];
Total[{Count[Data12, 1], Count[Data12, -1]}]

]];

TestQPW[RNGx_] :=
Catch[
Module[{RNGy = RNGx, SETy, SETya, WRONGy = {1}, SET2y},

Label["DEFINEy"];

If[Length[RNGy] == 2, SETy = RNGy[[1]]; SET2y = 2;, SETy = 1;
SET2y = 1;];
If[Length[RNGy] == 2,
If[RNGy[[1]] > RNGy[[2]], Break[];];
];

Label["STARTy"];
SETya = PrimeQPW[SETy];

If[SETya === Null || SETya == "True" || SETya == "False",
WRONGy = Append[WRONGy, SETy]; Goto["START2y"];];
If[PrimeQ[SETy] != PrimeQPW[SETy], WRONGy = Append[WRONGy, SETy];];

Label["START2y"];

If[SET2y == 1,
If[SETy == RNGy, Goto["ENDy"];];,
If[SETy == RNGy[[2]], Goto["ENDy"];];
];
SETy++;
Goto["STARTy"];

Label["ENDy"];

If[Length[WRONGy] == 1, Throw["No False results found"]; Break[];];
Throw[Drop[WRONGy, 1]];

]];
"Tools"

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Speedy speedy review

Mon Apr 13, 2015 1:29 pm

Details[ww5_, ww6_] :=
Column[{{Mod[ww5, 3], Mod[ww5, 5], Mod[ww5, 7], Mod[ww5, 11]},
{Floor[
Total[{Test14[ww5 2, ww6], Test14[ww5 3, ww6],
Test14[ww5 5, ww6], Test14[ww5 7, ww6],
Test14[ww5 11, ww6]}]/5],
IntegerQ[
Total[{Test14[ww5 2, ww6], Test14[ww5 3, ww6],
Test14[ww5 5, ww6], Test14[ww5 7, ww6],
Test14[ww5 11, ww6]}]/5], {Test14[ww5^2, ww6],
Test14[ww5 2, ww6], Test14[ww5 3, ww6], Test14[ww5 5, ww6],
Test14[ww5 7, ww6], Test14[ww5 11, ww6]}},
MiniTest[ww5], {Fifty[ww5, 1], Fifty[ww5, 2], Fifty[ww5, 3],
Fifty[ww5, 4], Fifty[ww5, 5]}, PrimeQPW[ww5], ww5}];

"Details"

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Sloppy speedy test program part 1

Mon Apr 13, 2015 1:31 pm

PrimeQPW[hh3_] := Catch[Module[
{aa3, aa4 = hh3, aa5, aa6, aa7, aa8, aa9, a10, a11, a12, a13, a14,
a15, a16, aam},
aa5 = 1;

Label["Whittle"];
If[aa4 == Prime[aa5] || aa4 == Prime[aa5 + 1] ||
aa4 == Prime[aa5 + 2], Throw[True]; Break[];];
If[aa5 >= 25, aa5 = 1; Goto["Whittle2"] ;, aa5 = aa5 + 3;
Goto["Whittle"];];

Label["Whittle2"];
If[IntegerQ[aa4/Prime[aa5]] == True ||
IntegerQ[aa4/Prime[aa5 + 1]] == True ||
IntegerQ[aa4/Prime[aa5 + 2]] == True, Throw[False]; Break[];];
If[aa5 >= 25, aa5 = 1; Goto["NextStep"] ;, aa5 = aa5 + 3;
Goto["Whittle2"];];

Label["NextStep"];
If[aa4 < Prime[25]^2, Throw[True]; Break[];];
aa8 = Test14[aa4^2, 5];
If[aa8 == 48, aa6 = 1; aa3 = {1};];
If[aa8 == 46, aa3 = {1}; aa6 = 2;];
If[aa6 == 1 || aa6 == 2, Goto["NextStep2"];];
Goto["FalseEnd"];

Label["NextStep2"];
aa3 = Append[aa3, Test14[aa4*Prime[aa5], 5]];
aa5++;
If[aa5 > 5, aa5 = 1;
If[aa6 == 1, Goto["CheckRecords"];, Goto["CheckRecords2"];];,
Goto["NextStep2"];];

Label["CheckRecords"];
aa3 = Drop[aa3, 1];
If[aa3 == {0, 32, 40, 36, 40} , aa6 = 0; Goto["CheckPoint"];];
If[aa3 == {24, 48, 38, 40, 40}, aa6 = 1; Goto["CheckPoint"]; ];
If[aa3 == {24, 32, 40, 36, 40}, aa6 = 2; Goto["CheckPoint"];];
If[aa3 == {24, 48, 40, 36, 40}, aa6 = 3; Goto["CheckPoint"];];
If[aa3 == {24, 48, 40, 40, 40}, aa6 = 4; Goto["CheckPoint"];];
If[aa3 == {24, 46, 38, 38, 38}, aa6 = 5; Goto["CheckPoint"];];
If[aa3 == {22, 46, 38, 36, 40}, aa6 = 6; Goto["CheckPoint"];];
If[aa3 == {22, 46, 38, 34, 38}, aa6 = 7; Goto["CheckPoint"];];
If[aa3 == {24, 48, 38, 34, 38}, aa6 = 8; Goto["CheckPoint"];];
If[aa3 == {0, 30, 38, 34, 38}, aa6 = 9; Goto["CheckPoint"];];
If[aa3 == {0, 32, 40, 40, 40}, aa6 = 10; Goto["CheckPoint"];];
If[aa3 == {0, 32, 48, 40, 40}, aa6 = 11; Goto["CheckPoint"];];
If[aa3 == {24, 32, 48, 40, 40}, aa6 = 12; Goto["CheckPoint"];];
If[aa3 == {24, 32, 40, 40, 40}, aa6 = 13; Goto["CheckPoint"];];
If[aa3 == {24, 48, 38, 36, 48}, aa6 = 20; Goto["CheckPoint"];];
If[aa3 == {0, 48, 38, 36, 40}, aa6 = 21; Goto["CheckPoint"];];
If[aa3 == {24, 32, 38, 40, 40}, aa6 = 22; Goto["CheckPoint"];];
If[aa3 == {0, 32, 38, 40, 40}, aa6 = 23; Goto["CheckPoint"];];
If[aa3 == {24, 32, 38, 36, 40}, aa6 = 24; Goto["CheckPoint"];];
If[aa3 == {24, 48, 48, 36, 40}, aa6 = 25; Goto["CheckPoint"];];
If[aa3 == {24, 32, 48, 48, 40}, aa6 = 26; Goto["CheckPoint"];];
If[aa3 == {24, 32, 40, 48, 40}, aa6 = 27; Goto["CheckPoint"];];
If[aa3 == {0, 32, 40, 48, 40}, aa6 = 28; Goto["CheckPoint"];];
If[aa3 == {0, 48, 38, 40, 40}, aa6 = 29; Goto["CheckPoint"];];
If[aa3 == {24, 32, 38, 48, 40}, aa6 = 30; Goto["CheckPoint"];];

Goto["FalseEnd"];

Label["CheckRecords2"];
aa3 = Drop[aa3, 1];
If[aa3 == {24, 48, 40, 40, 38}, aa6 = 14; Goto["CheckPoint"];];
If[aa3 == {24, 48, 40, 36, 40}, aa6 = 15; Goto["CheckPoint"];];
If[aa3 == {24, 48, 40, 40, 40}, aa6 = 16; Goto["CheckPoint"];];
If[aa3 == {24, 30, 38, 34, 38}, aa6 = 17; Goto["CheckPoint"];];
If[aa3 == {0, 32, 40, 36, 40}, aa6 = 18; Goto["CheckPoint"];];
If[aa3 == {0, 32, 40, 40, 40}, aa6 = 19; Goto["CheckPoint"];];
Goto["FalseEnd"];

Label["CheckPoint"];
aa5 = {{Mod[aa4, 3], Mod[aa4, 5]}, {Mod[aa4, 7], Mod[aa4, 11]}};
aa7 = MiniTest[aa4];
aa9 = {Fifty[aa4, 1], Fifty[aa4, 2], Fifty[aa4, 3], Fifty[aa4, 4],
Fifty[aa4, 5]};
a10 = Floor[Total[aa3]/5];
a11 = GatherBy[Flatten[aa5], OddQ];
If[Length[a11] == 1,
If[AnyTrue[a11[[1]], OddQ] == True, a12 = {4, 0};,
a12 = {0, 4};],
If[AnyTrue[a11[[1]], OddQ] == True,
a12 = {Length[a11[[1]]], Length[a11[[2]]]};,
a12 = {Length[a11[[2]]], Length[a11[[1]]]};];];
a11 = {GatherBy[aa5[[1]], OddQ], GatherBy[aa5[[2]], OddQ]};
If[Length[a11[[1]]] == 1,
If[EvenQ[Flatten[a11[[1]]][[1]]] == True, a13 = {0, 2};,
a13 = {2, 0};];, a13 = {1, 1};];
If[Length[a11[[2]]] == 1,
If[EvenQ[Flatten[a11[[2]]][[1]]] == True, a14 = {0, 2};,
a14 = {2, 0};];, a14 = {1, 1};];
a11 = {a13, a14};
a12 = Append[{a12}, {a13, a14}];
a11 = GatherBy[Flatten[aa5], PrimeQ];
If[Length[a11] == 1,
If[AnyTrue[a11[[1]], PrimeQ] == True, a13 = 4, a13 = 0];,
If[AnyTrue[a11[[1]], PrimeQ] == True, a13 = Length[a11[[1]]];,
a13 = Length[a11[[2]]]];];
a14 = Count[Flatten[aa5], 1];
a15 = Count[Flatten[aa5], 2];
a12 = Append[a12, {a13, a14, a15}];
aam = {0};
If[aa7 == {1, 1, 1, 1}, Goto["Check1111"];];
Goto["CheckPoint2a"];

Label["CheckPoint2a"];
Throw["2"]; Break[];

Label["Check1111"];
If[IntegerQ[Sqrt[aa4]] == True, Throw[False]; Break[];];
If[aa9 == {True, False, False, False, False},
Goto["1111abbbb"];];
If[aa9 == {False, False, False, True, True}, Goto["1111bbbaa"];];
If[aa9 == {False, False, True, False, True}, Goto["1111bbaba"];];
If[aa9 == {False, True, True, False, True}, Goto["1111baaba"];];
If[aa9 == {False, False, True, False, False},
Goto["1111bbabb"];];
If[aa9 == {False, True, False, False, True}, Goto["1111babba"];];
If[aa9 == {False, True, False, True, True}, Goto["1111babaa"];];
If[aa9 == {False, False, False, True, False},
Goto["1111bbbab"];];
If[aa9 == {True, False, False, True, False}, Goto["1111abbab"];];
If[aa9 == {False, False, False, False, False}, Goto["1111bbbbb"];];
If[aa9 == {False, True, False, False, False},
Goto["1111babbb"];];
If[aa9 == {True, False, False, False, True}, Goto["1111abbba"];];
Goto["CheckPoint2a"];

Label["1111abbbb"];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {4, 0, 1}},
aam = Append[aam, 2]];
If[a12 == {{1, 3}, {{1, 1}, {0, 2}}, {1, 1, 1}},
aam = Append[aam, 1]];
Label["1111abbbbS2"];
Throw[{a12, aam}]; Break[];

Label["1111bbbaa"];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {2, 1, 0}},
aam = Append[aam, 2]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {4, 0, 2}},
aam = Append[aam, 2]];
If[a12 == {{1, 3}, {{1, 1}, {0, 2}}, {1, 1, 1}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 1, 1}},
aam = Append[aam, 2]];
If[a12 == {{0, 4}, {{0, 2}, {0, 2}}, {1, 0, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {3, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {4, 0, 1}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {3, 1, 3}},
aam = Append[aam, 1]];
If[a12 == {{4, 0}, {{2, 0}, {2, 0}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 1]];
Label["1111bbbaaS2"];
Throw[{a12, aam}]; Break[];

Label["1111bbaba"];
If[a12 == {{2, 2}, {{0, 2}, {2, 0}}, {4, 0, 2}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {2, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{0, 2}, {2, 0}}, {2, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {2, 1, 0}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {2, 0, 1}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {2, 1, 1}},
aam = Append[aam, 2]];
Label["1111bbabaS2"];
Throw[{a12, aam}]; Break[];

Label["1111baaba"];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {2, 0, 2}},
aam = Append[aam, 1]];
Label["1111baabaS2"];
Throw[{a12, aam}]; Break[];

Label["1111bbabb"];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {1, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {3, 1, 2}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {1, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {3, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{0, 2}, {2, 0}}, {3, 0, 1}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {3, 0, 2}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{1, 1}, {0, 2}}, {1, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {1, 1, 0}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {4, 0, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {2, 1, 1}},
aam = Append[aam, 1]];
Label["1111bbabbS2"];
Throw[{a12, aam}]; Break[];

Label["1111babba"];
If[a12 == {{4, 0}, {{2, 0}, {2, 0}}, {1, 3, 0}},
aam = Append[aam, 2]];
If[a12 == {{2, 2}, {{2, 0}, {0, 2}}, {0, 2, 0}},
aam = Append[aam, 2]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {3, 0, 1}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {3, 1, 1}},
aam = Append[aam, 2]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {2, 0, 1}},
aam = Append[aam, 2]];
If[a12 == {{0, 4}, {{0, 2}, {0, 2}}, {2, 0, 2}},
aam = Append[aam, 2]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {4, 0, 3}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 2]];
If[a12 == {{4, 0}, {{2, 0}, {2, 0}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {2, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{4, 0}, {{2, 0}, {2, 0}}, {2, 1, 0}},
aam = Append[aam, 1]];
Label["1111babbaS2"];
Throw[{a12, aam}]; Break[];

Label["1111babaa"];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {1, 1, 0}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {3, 0, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{0, 2}, {2, 0}}, {4, 0, 2}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {1, 1, 1}},
aam = Append[aam, 1]];
Label["1111babaaS2"];
Throw[{a12, aam}]; Break[];

Label["1111bbbab"];
If[a12 == {{0, 4}, {{0, 2}, {0, 2}}, {2, 0, 2}},
aam = Append[aam, 2]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 2]];
Label["1111bbbabS2"];
Throw[{a12, aam}]; Break[];

Label["1111abbab"];
If[a12 == {{4, 0}, {{2, 0}, {2, 0}}, {1, 2, 0}},
aam = Append[aam, 2]];
Label["1111abbabS2"];
Throw[{a12, aam}]; Break[];

Label["1111bbbbb"];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {2, 0, 1}},
aam = Append[aam, 2]];
If[a12 == {{2, 2}, {{0, 2}, {2, 0}}, {4, 0, 2}},
aam = Append[aam, 1]];
If[a12 == {{1, 3}, {{0, 2}, {1, 1}}, {1, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{2, 2}, {{1, 1}, {1, 1}}, {2, 1, 1}},
aam = Append[aam, 1]];
If[a12 == {{0, 4}, {{0, 2}, {0, 2}}, {2, 0, 2}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {2, 2, 1}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {3, 1, 1}},
aam = Append[aam, 1]];
Label["1111bbbbbS2"];
Throw[{a12, aam}]; Break[];

Label["1111babbb"];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {2, 1, 0}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {1, 2, 0}},
aam = Append[aam, 1]];
If[a12 == {{3, 1}, {{1, 1}, {2, 0}}, {3, 1, 1}},
aam = Append[aam, 1]];
Label["1111babbbS2"];
Throw[{a12, aam}]; Break[];

Label["1111abbba"];
If[a12 == {{3, 1}, {{2, 0}, {1, 1}}, {2, 1, 0}},
aam = Append[aam, 1]];
Label["1111abbbaS2"];
Throw[{a12, aam}]; Break[];

Label["CheckIfTrue"];

Label["FalseEnd"];
Throw["1"];
]];

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Some Investigations into Factorisation and Twin Primes

Wed Apr 15, 2015 7:09 am

T2Root[xxy_] := (Sqrt[8 xxy + 1] - 1)/2;
T2xy[x_, y_] := ((x + y) (x + y - 1))/2 - y + 1;
FiveItt[x98_, cc5_] :=
If[x98 == 1, 1, FromDigits[Append[Table[1, {ft, x98 - 1}], 0], cc5]];

BCC[x55_, g77_] :=
Drop[Flatten[
Reap[Module[{x45 = x55, z7 = 0, z8 = 0, z9, g7 = g77, bell},
z7 = If[x45/FiveItt[Length[IntegerDigits[x45, g7]], g7] <= 1,
If[x45 == 1, 1, Length[IntegerDigits[x45, g7]] - 1],
Length[IntegerDigits[x45, g7]]];
bell = FiveItt[z7 - 1, g7];
z9 = g7^(z7 - 1);
Label[SPo];
z8 =
If[IntegerQ[x45/g7] && x45 > g7,
Quotient[x45 - bell - (1/(2*g7)), z9],
If[x45 <= g7, x45, Quotient[x45 - bell, z9]]];
Sow[z8];
x45 = x45 - (z8*(z9));
z7 = z7 - 1;
z9 = z9/g7;
bell = bell - z9;
If[z7 < 1, Goto[EnD], Goto[SPo]];
Label[EnD];]]], 1];
Zequeba[fre_, fre2_] := Total[BCC[fre, fre2]];
T2manip[rt_, tw_] := RS[Zequeba[rt, 5], 5];

Tulip[eee_, Tbe_] := Mod[T2manip[eee, Tbe], eee];

TulipFactorize[Maybe_] :=
Catch[Module[{who = Maybe, SetBit, SetBit2 = 0, SetBit3},
Label["Go"];
SetBit2++;
If[SetBit2 == 1, SetBit = Tulip[who, SetBit2 + 2];
SetBit3 = SetBit;, SetBit3 = SetBit;
SetBit = Tulip[SetBit, SetBit2 + 2];];
If[SetBit == 0,
Throw[{SetBit3 - 1, SetBit2,
Floor[(T2Root[who] -
T2Root[SetBit2] T2xy[SetBit2, SetBit2])/((SetBit3 -
1)/(SetBit2 - 2))*SetBit2/2]}]; Break[];,
Goto["Go"];];
];];


Although this Function does Itterate It seems to have low Itteration Depth.

TwinPrimeQ[zza_] :=
Catch[Module[{zzd = zza, rem1, rem2, rem3, rem4, Counter1 = 0,
Counter2 = 0},

If[zzd == 2 || zzd == 1, Throw[False]; Break[]];
If[zzd == 3 || zzd == 5 || zzd == 7, Throw[True]; Break[]];
rem1 = Mod[RS[FiveItt[2, zzd], 5]/zzd, (zzd + 2)];
rem2 = Mod[RS[FiveItt[2, zzd - 2], 5]/(zzd - 2), zzd];
rem3 = Mod[RS[FiveItt[2, zzd + 2], 5]/(zzd + 2), zzd + 4];
If[rem1 == 0, Counter1 = 1;];
If[rem2 == 0, Counter2 = 1;];
If[Counter1 == 1 && Counter2 == 1, Goto["Check11"]];
If[Counter1 == 1 || Counter2 == 1, Goto["Check4a3"]];
Throw["False"]; Break[];

Label["Check4a3"];
If[Counter1 == 1 && Counter2 == 0,
If[Mod[zzd, 3] == 0 || Mod[zzd + 2, 3] == 0, Throw[False];
Break[];];];
If[Counter1 == 0 && Counter2 == 1,
If[Mod[zzd - 2, 3] == 0 || Mod[zzd, 3] == 0, Throw[False];
Break[];];];
If[Counter1 == 1 && Counter2 == 0,
If[Mod[rem1, 7] == 0, Throw[True]; Break[];];];
If[Counter1 == 0 && Counter2 == 1,
If[Mod[rem3, 7] == 0, Throw[True]; Break[];];];
Throw[False]; Break[];

Label["Check11"];
If[Mod[rem3, 11] == 0 || Mod[rem3, 3] == 0, Throw[True];
Break[]];
Throw[False];
]];

That's where I'm with It all at the moment.

User avatar
qpwimblik
Posts: 15
Joined: Sat Apr 04, 2015 10:50 am

Re: Can you speed this code up?

Fri Apr 17, 2015 6:55 am

What I want and what I have.

FiveItt[x98_, cc5_] :=
If[x98 == 1, 1,
FromDigits[Append[Table[1, {ft, x98 - 1}], 0], cc5]];
BCCLog[x22_, y22_] :=
Catch[Module[{s21 = x22, t22 = Length[IntegerDigits[x22, y22]]},
If[FiveItt[t22, y22] > s21, t22 = t22 - 1];
Throw[t22];
]];

"Now what I Want (My Wish)"

Must Solve for...
PrimeEst[pt_] := BCCLog[pt, GoldenE] pt];

"Why";

TheReasonIs[ptt_] :=
Floor[(((BCCLog[ptt, 2] + BCCLog[ptt, 3])/2.1) ptt)];

Return to “Mathematica”