Finding derivative by first principle
$$
f'(x) = \lim_{x \to 0}\frac{f(x + h) - f(h)}{h}
$$

I wrote a program that calculate any derivative for any function as long as it's with respect to x, although in the first principle, the h is dismissed as a result, however, the executable string can only contains one variable, it's x, so I have to get rid of h, the most convenient method that works is to let it to be one ,by using $f'(x) = f(x + 1) - f(x)$, I did the following:
$$ \text{for: } f(x) = 2x^3 + x^{-1} $$
- replace the
xto(x + 1)in that string to get $f(x + 1)$,2 * (x + 1) ** 3 + (x + 1) ** -1 - subtract with $f(x)$,
(2 * (x + 1) ** 3 + (x + 1) ** -1) - (2 * x ** 3 + x ** -1)
It's pretty simple, and works fine. However, I find it impractical for integration. which with knowing the expression, it's hard to work out the integral (I am trying to get an equation, not an area value)
refer to this post.
@Simply Beautiful Art, suggested that
By letting $x = t^2$ and applying PFD over complex numbers, you'll get integrals of the form $\int{\frac{sin(t^2)}{t-a}}dt$, from there, replace sine with its complex exponential definition and use incomplete gamma functions.
I cannot relate this context to computation.
here is the question, if we know an expression, which has one variable x, such as:
# these are executable strings which I can pass in a numeric value as x and get y as output
'2 * x ** 3 + x ** -1'
'3.1415926 * sin(x) * ln(x) * 2'
Is there a way I can compute an integral for the function?
Hope I have stated it clear, sorry if I confused you.
If I understood right, you want an expression for integral which a computer can evaluate by algorithms. Before I get into explaining the answer for this, I'll first comment some things about the expression for derivative mentioned in your post.
It is not true (as pointed out by David C. Ullrich and A-level Student) that:
$$ f'(x) = \frac{f(x+h) - f(x)}{h}$$
It is only the limit that $h \to 0 $ is the above equation true. To make this more explicit, consider this function:
$$ g(x,h) = f'(x) - \frac{f(x+h) - f(x)}{h}$$
Take any point $x$, say $x=1$ and plot the above expression as a function of $h$, you will notice that it becomes zero only as $h$ approaches zero and is undefined at exactly $h=0$ (that's why the limit).
For the $\sin(x)$ function, we can write at $x=1$ $g$ as:
$$ g(1,h) = \cos(1) - \frac{ \sin( 1+h) - \sin(1)}{h}$$
The right side is the expression for the first principle derivative of $\sin(x)$ without the limit. I plotted the equation as a graph on desmos:
As we can see the ratio only equals the derivative ( causing g to be close to zero) $h$ is really close to zero. Hence, to get a more accurate expression for the derivative consider keeping keeping $h$ as lowest as you can take, for example: $\frac{f(x+.1) - f(x)}{.1}$ is a much better approximation to a derivative than $ \frac{f(x+1)-f(x)}{1}$ at the point $x$.
First principle for integration..?
From what I've learned, there are actually many ways to formulate the integral. However, the one taught early on with the rectangle addition is known as riennman sum. The expression for it can thought the following way:
Take a set $(a,b)$ , partition it into $n$ subsets of width $h$ (*), with the following relation between $n$ and $h$ holding:
$$ b=a+nh$$
Then the integral of a function can be given(**) as:
$$ \int_a^b f(x) dx \approx \left[ f(x)h + f(x+h) h... + f(x+nh)h \right] \tag{1}$$
There is a geometric interpretation of the above equation, which you can find on the internet ( I feel this topic is done to death by many places).
*: Think of the partion in the following way: $(a,b) = (a,a+h) \cup (a+h,a+2h) \cup... \cup (a+(n-1) h , a+nh) $
**: Both sides agree only when $ n \to \infty $ and $ h \to 0$
Example of (1):
$$ \int_0^1 e^x dx \approx \left[ e^0 h + e^{0+h} h .. + e^{nh} \right]$$
Setting $n=10$ and $h=.5$,
$$ \left[ e^0 h + e^{0+h} h .. + e^{nh} h\right] = \left[ e^0 (.5) + e^{.5} (.5) .. + e^{10 (.5) } .5 \right]$$