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

You are not logged in.

- Topics: Active | Unanswered

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

Sure, 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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

Hi;

Okay, thanks. I will look at it, in the meantime I use mine because I can understand it.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

**Online**

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

Hi,

Yeah, me too.

I'll use this only when maxima can't obtain a g.f or recurrence, there are too many functions and options in this!

"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: 102,939

Hi gAr;

Sorry, but I need to rest. Wish I could talk with you more.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

**Online**

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

No problem, see you later..

"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: 102,939

Hi gAr;

I have some ideas on that square root problem.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

**Online**

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

Hi bobbym,

What are those ideas?

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

Use the built in square root function, then take the floor and the ceiling of that number. Add one and subtract one to each one. Now square each one and match it to the number you are testing.

That should take care of round off error either way.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

bobbym wrote:

Use the built in square root function, then take the floor and the ceiling of that number. Add one and subtract one to each one. Now square each one and match it to the number you are testing.

That should take care of round off error either way.

How is that different from the code code I have proposed?!

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: 102,939

How is that different from the code code I have proposed?!

For one thing, I am proposing testing 4 numbers rather than 2.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Of those 4 numbers, 2 will never be the square root of the given number, with rounding errors or without...

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: 102,939

Hi;

That may not be the case. For instance and this is just an example:

He gets an answer of 35136.000001. Is that round off from the correct 35135.9999998 or from 35136?

I proposed it as a way of being sure by testing 2 smaller and 2 larger.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Hi bobbym

We want our number to be a square of an integer, not a real number... Do you have an example in which my code will not get the correct answer and yours will?

*Last edited by anonimnystefy (2013-01-21 22:27:17)*

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: 102,939

Hi;

These are just suggestions for gAr to consider.

Do you have an example in which my code will not get the correct answer and yours will?

If you are demanding correctnes you do not even know if your idea would always work.

I would presume that an exhaustive test would have to be done on every square with whatever method he chooses.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Hi bobbym,

Good idea, but I liked your integer only suggestion better since the code dealing with integers would be faster than floating points. Also, that algorithm on wikipedia did not even have integer divisions, only shift operations!

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

Hi;

I was not suggesting rewriting a floating point routine. You would be using the built in square root routine as an estimate. It is probably implemented in the math coprocessor and would not use much time at all.

The integer square root does have the advantage of being verified for any other idea you would have to prove that it never missed. That means checking 4 billion square roots once.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Yes, I know you were talking about using the built-in sqrt, but I'm not sure whether that will be faster than our own integer sqrt.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

The speed question is secondary. I have no proof that mine will work in every case. It was just a suggestion.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Hi bobbym,

Okay, thanks for the idea..

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

So you will go with the isqrt routine? You wanted more speed than Sage could provide?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

Yes, I wanted more speed, since looping is a lot slower in sage.

But sage does provide with enough terms in reasonable time to get the g.f / recurrence.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

Perhaps Sage, has a single command that does what you want?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

You mean, to solve the diophantine equation?

I did not search for it yet.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 102,939

Hi;

No, I meant to determine whether a number is a square or not.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

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

That's already there, I was concerned about the requirement to loop through each integer.

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

Offline