Construction of a special function

Let $f:\mathbb{R} \to \mathbb{R}$ is a function with these special properties. $f$ is continuous everywhere. $f$ is not smooth (not infinitely differentiable). $f$ is differentiable only finitely many times everywhere. $f$ belongs to $L^p$. For any $k$ belongs to $\mathbb{N}$ let $E$ be the set of all points where $f$ is differentiable exactly $k$ times then $E$ is not dense in any open subset of $\mathbb{R}$.Is such a function feasible? I need suggestions on ways to construct such a special function.

This is the final version. not going to change it further. I apologize for the inconvinience

-
This is not functional analysis. That refers to questions of continuous linear maps. Retagging. – kahen Nov 13 '10 at 9:47
@kahen: I didnt intend it to be...it was a mistake due to autocomplete....thanks for the retagging – Rajesh D Nov 13 '10 at 9:50
@chandru: thank you for the latex edit – Rajesh D Nov 13 '10 at 10:05
To some of us a "special function" is something completely different. – AD. Nov 13 '10 at 10:29
What I mean is completely in the opposite sense ! the other extreme ! – Rajesh D Nov 13 '10 at 10:39

I deleted this temporarily while I was working on an update. Also... whoever upvoted this, please remove your upvote as this answer is incorrect. The older answers are below this update. As for why it took me so long to edit this to reflect that it's wrong, that's because there has been water in the telephone cable or something. This area has been without phones and internet for about 48 hours.

Instead of trying to answer this question, I'll try and point out some examples of odd behaviour. The essential problem is that an exhibit of a function with similar properties as those you stated is probably going to be as a limit of differentiable functions. But uniform limits and differentiability don't play that nicely together - q.v. [Wikipedia].

Let's start simple. Consider $f_1 \in C^1([-1,1])$ and define $f_n$ as follows: $$f_n(x) = \begin{cases} g_n(x) & \text{ if } -\tfrac{1}{n} \lt x \lt \tfrac{1}{n} \\\\ f_{n-1}(x) & \text{ otherwise,} \end{cases}$$ where $g_n \in C^n([-\tfrac{1}{n},\tfrac{1}{n}])$ such that $g_n^{(k)}(\tfrac{\pm 1}{n}) = f_{n-1}^{(k)}(\tfrac{\pm 1}{n})$, $k = 0,\ldots n-1$ and $\sup_{x \in [-\tfrac{1}{n},\tfrac{1}{n}]} \lvert g_n (x)- f_{n-1}(x) \rvert < 2^{-n}$.

By construction this is a Cauchy sequence in $C[-1,1]$, so the limit, $f$ is continuous. Moreover for any $X \subset [-1,1]$ that doesn't contain a neighbourhood of $0$, the sequence $(f_n|_X)$ is eventually constant. So we know everything about $f$'s behaviour with respect to differentiability everywhere except at $0$.

Clearly it's possible for $f$ to be smooth at $0$ - for example if $(f_n)$ is eventually constant on some neighbourhood of $0$. But $g_n$ can have pretty much any behaviour on $[-\tfrac{1}{2n},\tfrac{1}{2n}]$, so $(g_n^{(k)}(0))$ can be any sequence of real numbers for each $k$.

This demonstrates that limits of real functions can be truly bizarre. The $f_n$ get nicer and nicer around $0$, but the limit can have any behaviour at all at $0$: Not differentiable, exactly $k$ times differentiable or smooth.

I'm not sure this next idea says anything at all about the problem (because the limit might not be differentiable at all), but I find it a bit of a waste to not write it down.

We shall say that a function $f$ is "$F^k$ on $U$" if $f$ is continuous and $k$ times differentiable on $U$ and nowhere $k+1$ times differentiable in $U$. Obviously the requirement that $f$ be continuous isn't needed for $k \neq 0$ ($f$ differentiable $\Rightarrow$ $f$ continuous), but stating it twice isn't a problem. We are mostly going to be concerned about intervals, so for endpoints of intervals we shall in addition require that the one-sided derivatives exist.

Now let $f_0$ be an $F^0$ function on $[0,1]$, asumme that we have defined the sequence up to $f_{n-1}$. We define $f_{n}$ in the following way: For each $k = 0, \ldots n-1$ and for each maximal open subinterval where $f_{n-1}$ is $F^k$, set $f_n$ to be an $F^{k+1}$ function on the two outer thirds of the interval such that the $k$ derivatives of $f_{n-1}$ and $f_n$ agree on the endpoints and such that $|f_n(x) - f_{n-1}(x)| < 2^{-n}$ for each $x$ in the interval (so the sequence is Cauchy). On the inner one third of the intervals we set $f_n = f_{n-1}$.

This simple ASCII diagram should help a bit with grokking the idea:

     0                             F^0                             1
f_0: |-------------------------------------------------------------|
F^1                  F^0                  F^1
f_1: |-------------------)(-------------------)(-------------------|
F^2    F^1    F^2    F^1    F^0    F^1    F^2    F^1    F^2
f_2: |-----)(-----)(-----)(-----)(-----)(-----)(-----)(-----)(-----]


If this makes you think of the Cantor set and the Towers of Hanoi, it's not a coincidence - that's exactly how I got the idea. Anyway as I said, the limit of the $f_n$ might not be differentiable anywhere, but it seems to me that it's at least a starting point for constructing a sequence which has a limit that's $F^k$ on a nowhere dense set in $[0,1]$ for all $k > 0$.

Proposition. There exists no $f \in C(\mathbb{R})$ such that:

1. $f \notin C^\infty(\mathbb{R})$,
2. If $k \in \mathbb{N}_{0}$, then $E_k := \lbrace x \in \mathbb{R} \mid f \text{ is exactly } k \text{ times differentiable at } x\rbrace$ is nowhere dense.

Proof. Consider $\cup_{k=0}^\infty E_k$. This has to be all of $\mathbb{R}$ since $f$ is continuous. But then we'd have written $\mathbb{R}$ as a countable union of nowhere dense sets contradicting that $\mathbb{R}$ is a Baire space.

This is my second answer which is also wrong

Proposition. There exists no function, $f$ such that:

1. $f \in C(\mathbb{R})$,
2. for all $k \in \mathbb{N}$ the set of points where $f$ is exactly $k$ times differentiable is nowhere dense,
3. $f$ is nowhere smooth.

Proof. Recall that if $f$ is differentiable at a point $x_1$, there exists an entire open interval (UPDATE: no there doesn't. The Cantor function is a counterexample), $I_1$ around $x_1$ where $f$ is differentiable. Find a closed interval, $J_1$ containing $x_1$ inside $I_1$. Since the set of points where $f$ is exactly $k$ times differentiable is nowhere dense, there must be a point $x_2 \in J_1$ where $f$ is twice differentiable. Like before we get a closed interval $J_2$ contained in $J_1$ where $f$ is twice differentiable. Proceed by induction and we get a nested sequence of closed intervals, $J_1 \supset J_2 \supset \dotsb$. By the nested interval theorem, $\cap_{\mathbb{N}} J_n$ is nonempty and it's easy to see that $f$ has to be smooth on all the points in the intersection, contradicting our assumption that $f$ was nowhere smooth.

-
please see the edit – Rajesh D Nov 13 '10 at 10:36
Seems to me you forgot to count E_0, so your argument is bogus. – Marek Nov 13 '10 at 10:54
Alright then. $\mathbb{R} = \cup_{n=0}^\infty E_n$... I had just assumed that he wanted the function to be at least differentiable everywhere. Maybe the problem is just stated imprecisely? Rewriting to make my answer more precise. – kahen Nov 13 '10 at 11:25
@kahen: Your answer is not for my question. I did'nt count $k=0$.I have clearly mentioned that $f$ is continuous everywhere. Just to clarify i am in the opinion that a function $f$ is $k=0$ times differentiable means it is continuous.Please correct me if i am wrong. – Rajesh D Nov 14 '10 at 5:07
@kahen: I apologize if you were not able to get the question in the current form as there was some mix up while i was editing and i was away for a while – Rajesh D Nov 14 '10 at 5:13

Here is a construction:

Consider the operator $T:X\to Y$ where $X=L^1\cap L^\infty$ defined by $$T(f)(x)=f*g(x)$$ where $g(x)=e^{-x^2}$.

Some properties of $Y$:

Young's inequality on convolutions we see that $T(f)\in L^r$ where $1/r=1/p+1/q-1$ provided $f\in L^p$ and $g\in L^q$ - in our case this is true for all $r$.

Also, $T(f)$ is smooth (we talked about that in a previous thread of yours).

If we by some reason wish to destroy the smoothness, we can if wish use $g(x)=e^{-x^2}h(x)$ where $h\in C^n\cap L^\infty$ instead of the previous $g$.

-
@AD.: I do not fully understand how the last statement. That is where i think the whole problem is lying. – Rajesh D Nov 14 '10 at 5:08
@Rajesh D: 1) Since $h\in C^n$ we have $g\in C^n$. 2) Since $h$ is bounded and $exp(-x^2)\in L^p$ spaces ($p>0$), we must have $g\in L^p$ for all $p$'s. -- Now we can apply the above to reach $T(f)\in C^n$ without being smooth. – AD. Nov 14 '10 at 5:37
The question here is not just about reaching $C^n$.Please read the last condition in the question.It is not equivalent to your statement of reaching $C^n$. – Rajesh D Nov 14 '10 at 5:45
Rajesh, if I remember correctly you changed that part in the question. – AD. Nov 14 '10 at 6:03
@AD.: I sincerely apologize...i missed those restrictions in my first typing...sorry for the inconvenience..thank you – Rajesh D Nov 14 '10 at 6:45