473,763 Members | 7,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

primes with Child's Binomial Theorem

theorem states that:
Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) in Z[x].

so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)

#include <stdlib.h>
#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;
int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47};

int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}
void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
{
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}
}

int power (int base, int n)
{

p = 1;
for (i = 1; i <= n; ++i)
p *= base;
return p;
}
Mar 24 '07 #1
5 2450
Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) in Z[x].

In theorem, x must be integer , but do not say all integer satisfy
this condition. Theorem means , for all prime numbers there is an
integer (x) that satisfy this therom.
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
In here i must be constant ( not c language as in maths ) then find x
like this

for ( i = 0 ; i < 16 ; ++i )
for ( j = 1 ; j < 1000 ; ++j )
{
if( (power((j+1), expect[i]) % expect[i]) == ((power(j,
expect[i]) +1) % expect[i]))
{
// I found it
printf ( "%d", j );
break;
}
}

Erdinç Taşkın
erdinctaskin.bl ogspot.com
-----------------
On 24 Mart, 13:22, Carramba <u...@example.n etwrote:
theorem states that:
Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) in Z[x].

so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)

#include <stdlib.h>
#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;
int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47};

int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}

void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
{
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}

}

int power (int base, int n)
{

p = 1;
for (i = 1; i <= n; ++i)
p *= base;
return p;

}

Mar 24 '07 #2
Erdinç wrote:
>Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) inZ[x].
In theorem, x must be integer , but do not say all integer satisfy
this condition. Theorem means , for all prime numbers there is an
integer (x) that satisfy this therom.
thanx!
oh ok, but is there any known integers that I can use?
> if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
In here i must be constant ( not c language as in maths ) then find x
like this

for ( i = 0 ; i < 16 ; ++i )
for ( j = 1 ; j < 1000 ; ++j )
{
if( (power((j+1), expect[i]) % expect[i]) == ((power(j,
expect[i]) +1) % expect[i]))
{
// I found it
printf ( "%d", j );
I have only used expect to by able compare output, in this case program
doesn't generate primes
break;
}
}

Erdinç Taşkın
erdinctaskin.bl ogspot.com
-----------------
On 24 Mart, 13:22, Carramba <u...@example.n etwrote:
>theorem states that:
Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) inZ[x].

so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)

#include <stdlib.h>
#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;
int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,43,
47};

int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}

void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
{
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}

}

int power (int base, int n)
{

p = 1;
for (i = 1; i <= n; ++i)
p *= base;
return p;

}
Mar 24 '07 #3
On Sat, 24 Mar 2007 12:22:22 +0100, Carramba <us**@example.n etwrote:
>theorem states that:
Integer n is prime if and only if (x +1)^n ? x^n +1 (mod n) in Z[x].
What does the '?' mean above? Is it congruent? What is Z[x] and how
does it differ from "normal" arithmetic?

Must it be true for all x or just for some x that you have to find? Is
there any upper limit on x (it doesn't take very long for powers to
exceed the range of an int)?
>
so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)

#include <stdlib.h>
You don't appear to use this header.
>#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;
These two are used only in power and should be defined there.
>int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47};
These two are used only in id_prime and could (should) be defined
there as static.
>
int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}
void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
Is this the way you do arithmetic in Z[x]?
{
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}
}

int power (int base, int n)
{

p = 1;
Why are you using a global for this?
for (i = 1; i <= n; ++i)
Why another global?
> p *= base;
return p;
}

Remove del for email
Mar 24 '07 #4
Barry Schwarz wrote:
On Sat, 24 Mar 2007 12:22:22 +0100, Carramba <us**@example.n etwrote:
>theorem states that:
Integer n is prime if and only if (x +1)^n ? x^n +1 (mod n) in Z[x].

What does the '?' mean above? Is it congruent? What is Z[x] and how
does it differ from "normal" arithmetic?
? just encoding error it should by equivalent

Z[x] means x in Z, were Z is set of integers
Must it be true for all x or just for some x that you have to find? Is
there any upper limit on x (it doesn't take very long for powers to
exceed the range of an int)?
>so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)

#include <stdlib.h>

You don't appear to use this header.
>#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;

These two are used only in power and should be defined there.
>int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47};

These two are used only in id_prime and could (should) be defined
there as static.
>int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}
void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))

Is this the way you do arithmetic in Z[x]?
> {
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}
}

int power (int base, int n)
{

p = 1;

Why are you using a global for this?
> for (i = 1; i <= n; ++i)

Why another global?
> p *= base;
return p;
}


Remove del for email
Mar 25 '07 #5
Carramba wrote:
theorem states that:
Integer n is prime if and only if (x +1)^n ≡ x^n +1 (mod n) in Z[x].

so I testing it, but values doesn't match ... and I don't se why.. I
guess :) it's some thing wrong in my implementation. ..
hope you can help out :)
If you were to run the following,
#include <stdio.h>

const unsigned testmax = 300;
int main(void)
{
unsigned n, x, lhp, rhp, rhs, ok, j;

for (n = 1; n <= testmax; n++) {
for (x = ok = 0; x <= n; x++) {
for (lhp = rhp = j = 1, rhs = 2; j <= n; j++) {
lhp *= x + 1;
rhp *= x;
lhp %= n;
rhp %= n;
rhs = rhp == n - 1 ? 0 : rhp + 1;
}
if (lhp != rhs) {
ok = 1;
break;
}
}
if (!ok)
printf("%u ok\n", n);
else
printf
("%u fails: (%u+1)^%u = %u (%u), %u^%u +1 == %u"
" (%u).\n",
n, x, n, lhp, n, x, n, rhs, n);

}
return 0;

}
it strongly suggests that the test need only be done for x = 1.
If you can demonstrate that
Integer n is prime if and only if 2^n (mod n) ≡ 2 (mod n),
then this shorter program will suffice (some implementations of printf
are broken; if your lines are too long, yours is one of those):
#include <stdio.h>

const unsigned testmax = 1000;
int main(void)
{
unsigned n, lhp, rhs, ok, j, linepos = 0;
const unsigned linelimit = 60;
for (n = 1; n <= testmax; n++) {
ok = 1;
rhs = 2 % n;
for (lhp = j = 1; j <= n; j++) {
lhp *= 2;
lhp %= n;
}
if (lhp == rhs) {
linepos += printf("%u", n);
if (linepos < linelimit)
putchar(' ');
else {
putchar('\n');
linepos = 0;
}

}
}
if (linepos)
putchar('\n');
return 0;

}


>
#include <stdlib.h>
#include <stdio.h>

void id_prime(int i);
int power (int base, int n) ;

int i, p ;
int index = 0;
int expect[16] = {1, 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47};

int main(void)
{
int i;
for(i=1;i<50;i+ +)
{
id_prime(i);
}

return 0;

}
void id_prime(int i)
{
if( (power((4+1), i) % i) == ((power(4, i) +1) % i))
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
This is not the way to do this
{
printf("PRIME :%d", i);
printf(" EXPECTED : %d\n", expect[index]);
index++;
}
}

int power (int base, int n)
{

p = 1;
for (i = 1; i <= n; ++i)
p *= base;
return p;
}
Mar 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
8400
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N, but a prime number tester would also be nice. I'm dealing with numbers in the 10^6-10^8 range so it would have to fairly efficient Dag
0
2076
by: Ryan M. Keith | last post by:
I am having a problem with the ostream operator in templated classes that I wrote (I'm using the Borland compiler), and I'm certain that the templates are the problem because when I remove the templating completely everything works perfectly. Here is the error message: Error: Unresolved external 'operator <<(std::basic_ostream<char, std::char_traits<char> >&, const BinomialTree<int>&)' referenced from C:\DOCUMENTS AND...
2
5967
by: keit6736 | last post by:
Hi, I'm using the Borland compiler and I've created two templated classes in which I've overloaded the ostream << operator. However, when I try and use the operator on objects of either class I get the following error: Error: Unresolved external 'operator <<(std::basic_ostream<char, std::char_traits<char> >&, const BinomialTree<int>&)' referenced from C:\DOCUMENTS AND SETTINGS\RYAN\DESKTOP\COMPUTER SCIENCE\CS
9
2108
by: uttre | last post by:
hai to all, i did some programming in Lisp (6 months) & next i want to learn C++. i searched all the archives of "comp.lang.c++" & ACCU too & decided "C++ Primer" 3/e as my text book. (unfortunatley i tried but Accelerated C++ is not available in India, not even "C++ Primer 4/e). anyway, my question: I want to start doing math only for learning the following skills:
7
758
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
13
2500
by: sigmundccs | last post by:
Write a program to load in two integers from the user. Display all the prime numbers between the two integers. i'm a beginner. i'm problem doing this. can anyone teach me ? thanks a lot.
4
4277
by: Busgosu | last post by:
i dont know how to upload in a way that you can see it clearly.. so im just going to copy and paste what i have so far... sorry. :S #include <iostream> using namespace std; #include <cmath> void calculateNumber (double); double mypow (double, int);
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.