Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

So then the numbers themeselves are unsigned ints 64 bits wide?

Why not write your own integer square root algorithm ( they're are many on the web, I can post them for you ) otherwise you run the risk of comparing a float to an int?

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,917

Do you think thisbwould work?

int p=floor(sqrt(n));

if (p*p==n||p*(p+2)+1==n) return 1;else return 0;

?

*Last edited by anonimnystefy (2013-01-16 11:02:35)*

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

I am not saying that it would not, I am only saying that rounding errors may destroy the result. They are rare but unpredictable. What if the sqrt(36) was given as 5.99999999999999?

This is just an example and programmers would all start laughing, "Ho, hoo ahhh," they would exclaim, "my favorite language does not suffer from those type problems!"

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,917

How about the edited code?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

That might, have you seen any of the posts phrontister and I had about floating point arithmetic?

The problem can remedied in several ways but perhaps the best idea is a more mathematical approach and using Sage. This might be a case of the wrong tool for the right job.

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,917

What kind of mathematical approach?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

First by checking the mod 10 of the argument.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,917

Ok.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi bobbym,

Yes, integer only algorithms will do a good job, I was thinking only about using sqrt function..

Found a few algorithms, thanks.

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi gAr;

Let me know how they work.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi,

I found an algorithm after some searching, wiki, attempting to understand it..

However, after finding first few terms, I used WA, which fetched me a g.f.

Is it possible to get a g.f without finding recurrence first?

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Is it possible to get a g.f without finding recurrence first?

I think so?!

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

You know of any method?

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

If you have a sequence you can fit a rational function to it. For instance

by using the first three terms of the sequence, and then testing if the fitted function does the rest.

You can try as many as you like of different forms.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi,

Where do I substitute the terms?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi bobbym,

Thanks for the info.

I just found that there's also a function "ggf" in maxima, nice one! It guessed the g.f as well.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

Oh yes, the packages do these easily, much better than a human can.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Yes!

Anyway, it could not guess catalan numbers' g.f.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

No kidding! That is very strange. I will try Mathematica's tomorrow, right now I need to sleep. See you later.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Okay, see you tomorrow..

I am trying out the function "devine" also.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi gAr;

Mathematica's FindGeneratingFunction command gets it.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi bobbym,

I see.

Meanwhile, I found that axiom's guess implementations are the most powerful among the free CAS out there. I used friCAS 1.1.8 to test, did the job quite well.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

Guess is the implementation that both Maple and Mathematica use too.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi,

Yes, read about that. I was going through the implementer's paper in arxiv.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 93,591

Hi;

Can I have the link?

**In mathematics, you don't understand things. You just get used to them.**

Offline