Why definite integral of undefined function returns unevaluated? - integral

Why can Maple yield the result of int(q(t)*diff(q(t),t),t) = (q(t)^2)/2 (indefinite integral) but with int(q(t)*diff(q(t),t),t=0..t) (definite integral) it returns unevaluated?
I expect the result of the definite integral to be (q(t)^2 - q(0)^2)/2.

int(q(t)*diff(q(t),t),t=0..t,continuous);
2 2
-1/2 q(0) + 1/2 q(t)

Related

Why the definition of Church's Numerals

I want to understand, why Church define the numerals like:
0 = λ f . λ x . x
1 = λ f . λ x . f x
2 = λ f . λ x . f f x
3 = λ f . λ x . f f f x
4 = λ f . λ x . f f f f x
What is the logic behind?
Why 0 is represent like:
0 = λ f . λ x . x
Church wasn't trying to be practical. He was trying to prove results about the expressive power of lambda calculus — that in principle any possible computation can be done in lambda calculus, hence lambda calculus can serve as a theoretical foundation for the study of computability. In order to do so, it was necessary to encode numbers as lambda expressions, in such a way that things like the successor function are easily definable. This was a key step in showing the equivalence of lambda calculus and Gödel's recursive function theory (which was about computable functions on the natural numbers). Church numerals are basically a convenient albeit not very readable encoding of numbers. In some sense, there isn't any very deep logic to it. The claim isn't that 1 in its essence is λ f . λ x . f x, but that the latter is a serviceable encoding of the former.
This doesn't mean that it is an arbitrary encoding. There is a definite logic to it. The most natural way to encode a number n is by something which involves n. Church numerals use n function applications. The natural number n is represented by the higher order function which applies a function n times to an input. 1 is encoded by a function applied once, 2 by a function applied twice and so on. It is a very natural encoding, especially in the context of lambda calculus. Furthermore, the fact that it is easy to define arithmetic on them streamlines the proof that lambda calculus is equivalent to recursive functions.
To see this in practice, you can run the following Python3 script:
#some Church numerals:
ZERO = lambda f: lambda x: x
ONE = lambda f: lambda x: f(x)
TWO = lambda f: lambda x: f(f(x))
THREE = lambda f: lambda x: f(f(f(x)))
#function to apply these numerals to:
def square(x): return x**2
#so ZERO(square), ONE(square), etc. are functions
#apply these to 2 and print the results:
print(ZERO(square)(2), ONE(square)(2), TWO(square)(2),THREE(square)(2))
Output:
2 4 16 256
Note that these numbers have been obtained by squaring the number two 0 times, 1 times, 2 times, and 3 times respectively.
According to the Peano axioms, a natural number is either 0 or S(n) for another natural number n:
0 = 0
1 = S(0)
2 = S(S(0))
...
You can see Church numerals as a generalization of Peano numbers, where you provide your own 0 and S:
0 = λs.λz. z
1 = λs.λz. s(z)
2 = λs.λz. s(s(z))
...
Since this is a programming forum, let's create some Church numerals in EcmaScript 6:
const ZERO = s => z => z;
const ONE = s => z => s(z);
const TWO = s => z => s(s(z));
...
You can convert these Church numerals to JavaScript numbers by providing the appropriate zero and successor:
function toInt(n) {
return n(i => i + 1)(0);
}
And then:
> toInt(TWO)
2
You could use Church numerals to do some practical things:
function shout(text) {
return text + "!";
}
> shout("hi")
"hi!"
> NINE(shout)("hi")
"hi!!!!!!!!!"
​
You can try it here: https://es6console.com/iyoim5y8/
The following paper by Robert (Corky) Cartwright broke it down for me very well.
Essential points to grasp, for the very beginning:
all Church numerals are functions with two parameters;
in the Church representation of any number, it is implied that:
f — is the 'successor' function (i.e. function which accepts a Church numeral and returns church numeral next to the passed one, it's basically and increment);
x — is a (Church numeral) value representing 'zero' (the count starting point).
Keeping that in mind:
λf . λx . x
will be equal to zero, if we will pass the appropriate f ('successor' —increment function) and x ('zero' — count starting point). In this particular case it doesn't matter what function will be passed as f, since it never applied:
λf . λx . ZERO
this:
λf . λx . fx
will be evaluated to 1:
λf . λx . INCREMENT ZERO
and the following:
λf . λx . f f x
will be qual to 2:
λf . λx . INCREMENT(INCREMENT ZERO)
and so on, for all the successive numbers.
Bonus (addition, multiplication and exponentiation of Church numerals):
Here is a Python code snippet to illustrate (and expand on) said above:
ZERO = lambda f: lambda x: x
ONE = lambda f: lambda x: f(x)
TWO = lambda f: lambda x: f(f(x))
THREE = lambda f: lambda x: f(f(f(x)))
SUCC = lambda x: x + 1
ADD = lambda f: lambda x: lambda n: lambda m: n(f)(m(f)(x))
MULT = lambda f: lambda x: lambda n: lambda m: n(m(f))(x)
EXPON = lambda m: lambda n: n(m)
ADD exploits the fact that any Church numeral accepts a 'zero' count starting point, as it's argument — it just counts to n starting with m. So, ADD(SUCC)(0)(THREE)(TWO) will just count to 3, but starting with 2, thus giving us 2 + 1 + 1 + 1 = 5.
MULT utilizes the fact that a 'successor' function is just an argument of a Church numeral, and thus could be replaced. Thus MULT(SUCC)(0)(TWO)(THREE) will return 3 twice, which is the same as 2 * 3 = 6.
EXPON is a bit tricky (it was for myself, at least), the key point here is to keep track of what is getting returned by what. What it, basically, does — is uses the intrinsic mechanism of Church numerals representation (recursion of f application, in particular). Here are some examples to illustrate:
30
EXPON(THREE)(ZERO)(SUCC)(0)
↓
lambda n: n(THREE)(ZERO)(SUCC)(0)
↓
ZERO(THREE)(SUCC)(0)
↓
lambda x: (SUCC)(0)
↓
SUCC(0)
↓
1
31
EXPON(THREE)(ONE)(SUCC)(0)
↓
lambda n: n(THREE)(ONE)(SUCC)(0)
↓
ONE(THREE)(SUCC)(0)
↓
lambda x: THREE(x)(SUCC)(0)
↓
THREE(SUCC)(0)
↓
3
13
EXPON(ONE)(THREE)(SUCC)(0)
↓
lambda n: n(ONE)(THREE)(SUCC)(0)
↓
THREE(ONE)(SUCC)(0)
↓
lambda x: ONE(ONE(ONE(x)))(SUCC)(0)
↓
ONE(ONE(ONE(SUCC)))(0)
↓
ONE(ONE(lambda x: SUCC(x)))(0)
↓
lambda x:(lambda x: (lambda x: SUCC(x)) (x))(x)(0)
↓
SUCC(0)
↓
1

Implications as functions in Coq?

I read that implications are functions. But I have a hard time trying to understand the example given in the above mentioned page:
The proof term for an implication P → Q is a function that takes
evidence for P as input and produces evidence for Q as its output.
Lemma silly_implication : (1 + 1) = 2 → 0 × 3 = 0. Proof. intros H.
reflexivity. Qed.
We can see that the proof term for the above lemma is indeed a
function:
Print silly_implication. (* ===> silly_implication = fun _ : 1 + 1 = 2
=> eq_refl
: 1 + 1 = 2 -> 0 * 3 = 0 *)
Indeed, it's a function. But its type does not look right to me. From my reading, the proof term for P -> Q should be a function with an evidence for Q as output. Then, the output of (1+1) = 2 -> 0*3 = 0 should be an evidence for 0*3 = 0, alone, right?
But the Coq print out above shows that the function image is eq_refl : 1 + 1 = 2 -> 0 * 3 = 0, instead of eq_refl: 0 * 3 = 0. I don't understand why the hypothesis 1 + 1 = 2 should appear in the output. Can anyone help explain what is going on here?
Thanks.
Your understanding is correct until:
But the Coq print out above shows that the function image is ...
I think you misunderstand the Print command. Print shows you the term associated with a definition, along with the type of the definition. It does not show the image/output of a function.
For example, the following prints the definition and type of the value x:
Definition x := 5.
Print x.
> x = 5
> : nat
Similarly, the following prints the definition and type of the function f:
Definition f := fun n => n + 2.
Print f.
> f = fun n : nat => n + 2
> : nat -> nat
If you want to see the function's codomain, you have to apply the function to a value, like so:
Definition fx := f x.
Print fx.
> fx = f x
> : nat
If you want to see the image/output of a function Print won't help you. What you need is Compute. Compute takes a term (e.g. a function application) and reduces it as far as possible:
Compute (f x).
> = 7
> : nat

Are the following functions in O(x³)?

I'm trying to decide whether the following functions are or can be O(x³) assuming k = 1. I have what I think are the right answers but I'm confused on a few so I figured someone on here could look over them. If one is wrong, could you please explain why? From what I understand if it is about x³ then it can be referred to as O(x³) and if its below it can't be? I think I may be viewing it wrong or have the concept of this backwards.
Thanks
a. 3x = TRUE
b. 10x + 42 = FALSE
c. 2 + 4x + 8x² = FALSE
d. (logx + 1)⋅(2x + 3) = true
e. 2x + x! = TRUE
What is meant by Big-O?
A function f is in O(g), if you can find a constant number c with f ≤ c·g (for all x > x0).
The results
3x is not in O(x3), due to limx → ∞ 3x/x3 = ∞
10x+42 is in O(x3). c = 52 holds for all x ≥ 1.
2 + 4x + 8x2 is in O(x3). c = 14 holds for all x ≥ 1.
(logx+1)(2x+3) is in O(x3). c = 7 holds for all x ≥ 1.
2x + x! is not in O(x3), due to limx→∞(2x+x!)/x3 = ∞
Think of O(f) as an upper bound. So when we write g = O(f) we mean g grows/runs at most as fast as f. It's like <= for running times. The correct answers are:
a. FALSE
b. TRUE
c. TRUE
d. TRUE
e. FALSE

Obtain x as result for Re[x] in mathematica

I'm trying to obtain the real part of the result of an operation which involves an undefined variable (let's say x).
How can I have Mathematica return x when I execute Re[x] if I know that x will never be a complex number? I think this involves telling Mathematica that x is a real, but I don't know how.
In my case the expression for which I want the real part is more complicated than a simple variable, but the concept will remain the same.
Some examples:
INPUT OUTPUT DESIRED RESULT
----- ------ --------------
Re[x] Re[x] x
Re[1] 1 1
Re[Sin[x]] Re[Sin[x]] Sin[x]
Re[1+x+I] 1 + Re[x] 1+x
Re[1 + x*I] 1-Im[x] 1
You can use for example the input Simplify[Re[x], x \[Element] Reals] which will give x as output.
Use ComplexExpand. It assumes that the variables are real unless you indicate otherwise. For example:
In[76]:= ComplexExpand[Re[x]]
Out[76]= x
In[77]:= ComplexExpand[Re[Sin[x]]]
Out[77]= Sin[x]
In[78]:= ComplexExpand[Re[1+x+I]]
Out[78]= 1+x
Two more possibilities:
Assuming[x \[Element] Reals, Refine[Re[x]]]
Refine[Re[x], x \[Element] Reals]
Both return x.
It can at times be useful to define UpValues for a symbol. This is far from robust, but it nevertheless can handle a number of cases.
Re[x] ^= x;
Im[x] ^= 0;
Re[x]
Re[1]
Re[1 + x + I]
Re[1 + x*I]
x
1
1 + x
1
Re[Sin[x]] does not evaluate as you desire, but one of the transformations used by FullSimplify does place it in a form that triggers Re[x]:
Re[Sin[x]] // FullSimplify
Sin[x]

How do I compute ∞/∞ correctly in Mathematica?

I had tried the code below in Mathematica 8:
f[z_] := (5 + 1/(z-a)) / ( 8 + 1/(z-a))
f[a]
and surprisingly I got following warnings:
Power::infy: Infinite expression 1/0 encountered. >>
Power::infy: Infinite expression 1/0 encountered. >>
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >
and the output is Indeterminate, which I think is not true because obviously it's 1.
What's weird is that when I changed the code to:
Simplify[(5 + 1/(z-a)) / ( 8 + 1/(z-a))] /. a -> z
I got the correct output 1. Why is that? And how should I deal with expressions involving ∞/∞ ?
Usually:
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a]
(*
-> 1
*)
Edit
You may also add a Direction option to take the limit coming from either side if necessary:
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a, Direction -> 1]
or
Limit[(5 + 1/(z - a))/(8 + 1/(z - a)), z -> a, Direction -> -1]
Edit 2
The weird behavior of Simplify[ ] (allowing some mathematically indefinite expressions to evaluate) is well documented in the help:
No, ∞/∞ is undefined. Consider that 2 ( ∞/∞ ) = (2∞/∞) = ∞/∞, which could be massaged to make 1 = 2 if ∞/∞ were defined as 1.
Infinity is not a number, so operations with it are pointless if you treat it as one:
infinity + 1 = infinity
(infinity + 1) - infinity = infinity - infinity
1 = 0
Other than that, limits are not always equal to the function's value, which is what Mathematica is hinting at when it gives you the error.
Infinity is not necessarily equal to infinity. Therefore, you cannot make the assertion that "infinity/infinity = 1".
Dividing infinity by infinity is indeed indeterminate. Taking the limit of f(x)/g(x) where f and g tend to infinity might produce an actual limit (or it might not). In your case the limit happens to be 1.

Resources