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

You are not logged in.

## #2051 2013-01-16 08:48:23

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2052 2013-01-16 09:16:43

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,018

### Re: What do you think?

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

## #2053 2013-01-16 09:32:01

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2054 2013-01-16 11:02:50

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,018

### Re: What do you think?

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

## #2055 2013-01-16 11:07:34

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2056 2013-01-16 11:09:34

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,018

### Re: What do you think?

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

## #2057 2013-01-16 11:13:14

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

First by checking the mod 10 of the argument.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2058 2013-01-17 01:59:48

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,018

### Re: What do you think?

Ok.

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

## #2059 2013-01-17 04:35:23

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

### Re: What do you think?

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

## #2060 2013-01-17 14:26:14

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

Hi gAr;

Let me know how they work.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2061 2013-01-18 01:48:45

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

### Re: What do you think?

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

## #2062 2013-01-18 04:39:02

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2063 2013-01-18 16:15:43

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

### Re: What do you think?

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

## #2064 2013-01-18 16:20:16

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2065 2013-01-18 16:29:17

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

### Re: What do you think?

Hi,

Where do I substitute the terms?

"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

## #2066 2013-01-18 17:37:21

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

### Re: What do you think?

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.

"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

## #2067 2013-01-18 17:38:31

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2068 2013-01-18 17:50:17

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

### Re: What do you think?

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

"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

## #2069 2013-01-18 17:53:42

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2070 2013-01-18 18:02:43

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

### Re: What do you think?

Okay, see you tomorrow..
I am trying out the function "devine" also.

"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

## #2071 2013-01-18 22:32:20

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

Hi gAr;

Mathematica's FindGeneratingFunction command gets it.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2072 2013-01-18 22:41:10

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

### Re: What do you think?

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.

"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

## #2073 2013-01-18 22:43:13

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #2074 2013-01-18 22:51:35

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

### Re: What do you think?

Hi,

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

"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

## #2075 2013-01-18 22:53:39

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 107,133

### Re: What do you think?

Hi;

Can I have the link?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## Board footer

Powered by FluxBB