<blockquote>
  <ol>
  <li>Is my analysis correct? </li>
  </ol>
</blockquote>

<p>Given my remarks in the comments that your network is certainly not <em>deep</em>, let's accept that your analysis is indeed correct (after all, your model does seem to do a good job <em>inside its training scope</em>), in order to get to your 2nd question, which is the interesting one.</p>

<blockquote>
  <ol start="2">
  <li>If the answer to 1 is yes, then isn't the prediction scope of deep learning very limited?</li>
  </ol>
</blockquote>

<p>Well, this is the kind of questions not exactly suitable for SO, since the exact meaning of "very limited" is arguably unclear...</p>

<p>So, let's try to rephrase it: should we expect DL models to predict such numerical functions <em>outside</em> the numeric domain on which they have been trained?</p>

<p>An example from a different domain may be enlightening here: suppose we have built a model able to detect &amp; recognize animals in photos with very high accuracy (it is not hypothetical; such models do exist indeed); should we complain when the very same model cannot detect and recognize airplanes (or trees, refrigerators etc - you name it) in these same photos?</p>

<p>Put like that, the answer is a clear &amp; obvious <strong>no</strong> - we should not complain, and in fact we are certainly not even surprised by such a behavior in the first place.</p>

<p>It is tempting for us humans to think that such models should be able to <em>extrapolate</em>, especially in the numeric domain, since this is something we do very "easily" ourselves; but ML models, while exceptionally good at <em>interpolating</em>, they fail miserably in extrapolation tasks, such as the one you present here.</p>

<p>Trying to make it more intuitive, think that the whole "world" of such models is confined in the <em>domain</em> of their training sets: my example model above would be able to generalize and recognize animals in unseen photos as long as these animals are "between" (mind the quotes) the ones it has seen during training; in a similar manner, your model does a good job predicting the function value for arguments <em>between</em> the sample you have used for training. But in neither case these models are expected to go beyond their training domain (i.e. extrapolate). There is no "world" for my example model beyond animals, and similarly for your model beyond [-500, 500]...</p>

<p>For corroboration, consider the very recent paper <a href="https://arxiv.org/abs/1808.00508" rel="noreferrer">Neural Arithmetic Logic Units</a>, by DeepMind; quoting from the abstract:</p>

<blockquote>
  <p>Neural networks can learn to represent and manipulate numerical information, but they seldom generalize well outside of the range of numerical values encountered during training.</p>
</blockquote>

<p>See also a <a href="https://twitter.com/reza_zadeh/status/1030331049073565697?s=11" rel="noreferrer">relevant tweet</a> of a prominent practitioner:</p>

<p><a href="https://i.stack.imgur.com/aygJG.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/aygJG.jpg" alt="enter image description here"></a></p>

<p>On to your third question:</p>

<blockquote>
  <ol start="3">
  <li>Is there a better algorithm for predicting functions like <code>y = x**2</code> both inside and outside the scope of training data?</li>
  </ol>
</blockquote>

<p>As it should be clear by now, this is a (hot) area of current research; see the above paper for starters...</p>

<hr>

<p>So, are DL models limited? Definitely - forget the scary tales about AGI for the foreseeable future. Are they <em>very</em> limited, as you put it? Well, I don't know... But, given their limitation in extrapolating, are they <em>useful</em>?</p>

<p>This is arguably the real question of interest, and the answer is obviously - <em>hell, yeah</em>!</p>
Is deep learning bad at fitting simple non linear functions outside training scope (extrapolating)?
<p>I am trying to create a simple deep-learning based model to predict <code>y=x**2</code>
But looks like deep learning is not able to learn the general function <strong>outside the scope of its training set</strong>.</p>

<p>Intuitively I can think that neural network might not be able to fit y=x**2 as there is no multiplication involved between the inputs.</p>

<p>Please note I am not asking how to create a model to fit <code>x**2</code>. I have already achieved that. I want to know the answers to following questions:</p>

<ol>
<li>Is my analysis correct? </li>
<li>If the answer to 1 is yes, then isn't the prediction scope of deep learning very limited?</li>
<li>Is there a better algorithm for predicting functions like y = x**2 both inside and outside the scope of training data?</li>
</ol>

<p>Path to complete notebook:
<a href="https://github.com/krishansubudhi/MyPracticeProjects/blob/master/KerasBasic-nonlinear.ipynb" rel="nofollow noreferrer">https://github.com/krishansubudhi/MyPracticeProjects/blob/master/KerasBasic-nonlinear.ipynb</a></p>

<p><strong>training input</strong>:</p>

<pre class="lang-py prettyprint-override"><code>x = np.random.random((10000,1))*1000-500
y = x**2
x_train= x
</code></pre>

<p><a href="https://i.stack.imgur.com/Npyf5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Npyf5.png" alt="input data"></a></p>

<p><strong>training code</strong></p>

<pre><code>def getSequentialModel():
    model = Sequential()
    model.add(layers.Dense(8, kernel_regularizer=regularizers.l2(0.001), activation='relu', input_shape = (1,)))
    model.add(layers.Dense(1))
    print(model.summary())
    return model

def runmodel(model):
    model.compile(optimizer=optimizers.rmsprop(lr=0.01),loss='mse')
    from keras.callbacks import EarlyStopping
    early_stopping_monitor = EarlyStopping(patience=5)
    h = model.fit(x_train,y,validation_split=0.2,
             epochs= 300,
             batch_size=32,
             verbose=False,
             callbacks=[early_stopping_monitor])


_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_18 (Dense)             (None, 8)                 16        
_________________________________________________________________
dense_19 (Dense)             (None, 1)                 9         
=================================================================
Total params: 25
Trainable params: 25
Non-trainable params: 0
_________________________________________________________________
</code></pre>

<p><strong>Evaluation on random test set</strong></p>

<p><a href="https://i.stack.imgur.com/i3Rxq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i3Rxq.png" alt="enter image description here"></a></p>

<p>Deep learning in this example is not good at predicting a simple non linear function. But good at predicting values in the sample space of training data.</p>