What's wrong with this function

  • Context: Undergrad 
  • Thread starter Thread starter MHD93
  • Start date Start date
  • Tags Tags
    Function
Click For Summary

Discussion Overview

The discussion revolves around the validity of a function designed to calculate the square root of 2, specifically examining the recursive definition provided by the original poster. Participants explore the implications of the function's definition and its behavior, particularly in the context of numerical analysis and continuity.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Some participants question the definition of f(x) when x is not 0, noting that it seems undefined.
  • Others argue that the function relies on floating point rounding, which may affect its correctness.
  • A participant points out a contradiction in assuming f(0) = 1 leads to an incorrect equation.
  • One participant proposes an alternative function g(x) and derives its properties, suggesting it leads to the correct value for the square root of 2.
  • Another participant discusses the implications of defining g(x) recursively and questions whether the method is valid without continuity assumptions.
  • Some express skepticism about the original function's ability to compute values correctly in a real-world context, emphasizing the need for limits in numerical analysis.
  • A later reply suggests that if the method reproduces the continued fraction expansion of sqrt(2), it may still be valid despite technical concerns.

Areas of Agreement / Disagreement

Participants generally do not reach a consensus on the validity of the original function or the proposed alternatives. Multiple competing views remain regarding the definitions and implications of the functions discussed.

Contextual Notes

Limitations include the potential dependence on numerical representation in computing, the need for continuity in certain methods, and unresolved questions about the function's definition for nonzero values.

MHD93
Messages
93
Reaction score
0
Hello

What follows is one way of calculating the square root of 2, as Wikipedia shows:
dc9b983d9e07314a6a8eae8dac8fea82.png


I built the following function as an attempt to express the calculation:

f(x) = 2 + 1 / f(x/2) if x is not 0
f(x) = 1 if x is 0

then square root of 2 = 1 + 1 / f(1)

I used the preceding approach to find the square root of 2, using C++, and it worked..
But the problem is that I have a way for showing that it's wrong!

What's wrong with that function, how can I convince myself logically!?
Thanks for help.. in advance.
 
Last edited:
Mathematics news on Phys.org
Something is missing. What is f(x)?
 
mathman said:
Something is missing. What is f(x)?

well, if f(0) = 1. The function relies on floating point rounding to calculate the other values of f(x).
 
willem2 said:
well, if f(0) = 1. The function relies on floating point rounding to calculate the other values of f(x).

Just curious ... I don't know anything about numerical analysis. To analyze a function like this, do we need to be told the value of N such that 1/N = 0?
 
f(x) = 2 + 1 / f(x/2) if x is not 0
f(x) = 1 if x is 0
This is uncorrect because :
you write (for x=0) f(0) = 1
and f(0) = 2 + 1/f(0)
since f(0)=1 your assuption is 1 = 2 + 1 = 3
 
He says "f(x) = 2 + 1 / f(x/2) if x is not 0".

But I still don't see a definition of f(x) when x is not 0.
 
He says "f(x) = 2 + 1 / f(x/2) if x is not 0".
Yes, you are right.
 
Last edited:
I built the following function as an attempt to express the calculation:
f(x) = 2 + 1 / f(x/2) if x is not 0
f(x) = 1 if x is 0
In fact, it isn't the right way.
Let define a function so that g(x)=1/(2+g(x)) any x
So that the infinite fraction is y = 1 + g(x)
What is the function g(x) ?
g(x)=1/(2+g(x))
g(x) (2+g(x)) = 1
(g(x))² + 2g(x) -1 = 0
Solving leads to
g(x) = -1 +(+or-)sqt(1+1)
The positive root is :
g(x) = -1+sqrt(2)
So, the function g(x) is constant.
y = 1 + g(x) = 1 +(-1+sqrt(2))
y = sqrt(2)
The value of the infinite fraction is sqrt(2)
 
Thanks for replies..

Many said "what is f(x)".. "it's not defined when x isn't 0"..

Actually, I see that it's defined.. here's a similar one:

{
g(x) = g(x/2) if x isn't zero
g(0) = 1
}

Let's try to find g(1)

Well.. by definition: g(1) = g(1/2) = g(1/4) = g(1/8) ...
In the end.. and after infinitely many steps.. doesn't the number between parentheses have to be 0, and then g(1) = g(0) = 1

??

That's the method I'm thinking about.. is it right?
 
  • #10
Mohammad_93 said:
Thanks for replies..

Many said "what is f(x)".. "it's not defined when x isn't 0"..

Actually, I see that it's defined.. here's a similar one:

{
g(x) = g(x/2) if x isn't zero
g(0) = 1
}

Let's try to find g(1)

Well.. by definition: g(1) = g(1/2) = g(1/4) = g(1/8) ...
In the end.. and after infinitely many steps.. doesn't the number between parentheses have to be 0, and then g(1) = g(0) = 1

??

That's the method I'm thinking about.. is it right?

I think that is pretty clever. You used your BRAIN to come up with a logical definition for f(0).:smile:
 
  • #11
Mohammad_93 said:
Thanks for replies..

Many said "what is f(x)".. "it's not defined when x isn't 0"..

Actually, I see that it's defined.. here's a similar one:

{
g(x) = g(x/2) if x isn't zero
g(0) = 1
}

Let's try to find g(1)

Well.. by definition: g(1) = g(1/2) = g(1/4) = g(1/8) ...
In the end.. and after infinitely many steps.. doesn't the number between parentheses have to be 0, and then g(1) = g(0) = 1

??

That's the method I'm thinking about.. is it right?

No, it's not right. Your function is not well-defined for any nonzero value. That's why the only way it makes sense is in the context of numerical analysis, when on some particular hardware, 1/N = 0 for sufficiently large N.

If your domain is the real numbers and you are using ordinary real number arithmetic, then how are you going to compute f(1)? You would have to do infinitely many operations and take a limit. That's not a valid definition of a function.

In a real world, physical computer, at some point 1/N is zero. That's numerical analysis ... when you take into account the physical representation of numbers in a computer.
 
  • #12
Mohammad_93 said:
Well.. by definition: g(1) = g(1/2) = g(1/4) = g(1/8) ...
In the end.. and after infinitely many steps.. doesn't the number between parentheses have to be 0, and then g(1) = g(0) = 1

??

That's the method I'm thinking about.. is it right?

That method requires that g is continuous. An extra assumption.
 
  • #13
If your method reproduces the continued fraction expansion of sqrt(2) then i don't see anything wrong with using it.

I used your iterative function to reproduce the continued fraction expansion of sqrt(2) by hand, on paper.

If you are going to focus on technicalities why it shouldn't work then you are in danger of disregarding the fact that it DOES work.

It's sort of like grounding a plane because one of the passenger seats is missing...:smile:
 
Last edited:

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
Replies
3
Views
2K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 28 ·
Replies
28
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
231K
  • · Replies 4 ·
Replies
4
Views
2K