I want to know the meaning of these two logical statement. These two statement is the same but share difference quantifiers. I try to google some examples on quantifiers but still not able to solve the question.
Statement 1:∀x∃y: If operation x is exposed by y, then y is a spy.
Statement 2:∀x∀y: If operation x is exposed by y, then y is a spy.
Can someone please give me some advices on these kind of question?
Thanks for your kindly attention.
So it is a little strange to apply the first statement to a conditional statement, but they mean:
Statement 1:∀x∃y: If operation x is exposed by y, then y is a spy.
For all x there exists a y for which it is true that if x is exposed by y, then y is a spy. The logic seems to be that there is at least one spying exposer out there (though note well with the quantifiers set up in this order it is entirely possible x is exposed by some non-spies as well). But why I am saying this is strange, is that logically, I could have a y that does not expose x, and that would satisfy the existence claim, because a false "if" implies any conclusion (i.e., if true, then false is true, and so is if false then true.).
Statement 2:∀x∀y: If operation x is exposed by y, then y is a spy. This says for all x, for all y (so basically for any x, y, pair) If x is exposed by y, then y is a spy.
Related
I'm in a Discrete Structures class (Computer Science Professor is teaching) and I recently got this problem on a quiz. I was under the assumption that this function was not injective, as there are x values between -1 and 0 that map to the same Y value. What am I doing wrong here?
Problem statement (verbatim):
Prove that: F(x) = y = X^2 + x for x in R ,and x > -1; and y in R
Injective
Let x1=-4/5 and x2=-1/5
(-4/5)2+(-4/5)=(-1/5)2+(-1/5)
-4/25= -4/25
Therefore, this function is not injective. It is not injective because two points on the function have equivalent outputs.
My professor responded with:
When using direct proof, do not use a particular case. Direct proof is for all x or all y.
You are confused about injection. If two distinct x arrive top the same y, then yes, it's not injective. This function is injective. -10
I want to plot a function in scilab in order to find the maximum over a range of numbers:
function y=pr(a,b)
m=1/(1/270000+1/a);
n=1/(1/150000+1/a);
y=5*(b/(n+b)-b/(m+b))
endfunction
x=linspace(10,80000,50)
y=linspace(10,200000,50)
z=feval(x,y,pr)
surf(x,y,z);
disp( max(z))
For these values this is the plot:
It's obvious that increasing the X axis will not increase the maximum but Y axis will.
However from my tests it seems the two axis are mixed up. Increasing the X axis will actually double the max Z value.
For example, this is what happens when I increase the Y axis by a factor of ten (which intuitively should increase the function value):
It seems to increase the other axis (in the sense that z vector is calculated for y,x pair of numbers instead of x,y)!
What am I doing wrong here?
With Scilab's surf you have to use transposed z if comming from feval. It is easy so realize if you use a different number of points in X and Y directions, as surf will complain about the size of the third argument. So in your case, use:
surf(x,y,z')
For more information see the help page of surf.
Stephane's answer is correct, but I thought I'd try to explain better why / what is happening.
From the help surf page (emphasis mine):
X,Y:
two vectors of real numbers, of lengths nx and ny ; or two real matrices of sizes ny x nx: They define the data grid (horizontal coordinates of the grid nodes). All grid cells are quadrangular but not necessarily rectangular. By default, X = 1:size(Z,2) and Y = 1:size(Z,1) are used.
Z:
a real matrix explicitly defining the heights of nodes, of sizes ny x nx.
In other words, think of surf as surf( Col, Row, Z )
From the help feval page (changed notation for convenience):
z=feval(u,v,f):
returns the matrix z such as z(i,j)=f(u(i),v(j))
In other words, in your z output, the i become rows (and therefore u should represent your rows), and j becomes your columns (and therefore v should represent your columns).
Therefore, you can see that you've called feval with the x, y arguments the other way round. In a sense, you should have designed pr so that it should have expected to be called as pr(y,x) instead, so that when passed to feval as feval(y,x,pr), you would end up with an output whose rows increase with y, and columns increase with x.
Then you could have called surf(x, y, z) normally, knowing that x corresponds to columns, and y corresponds to rows.
However, if you don't want to change your whole function just for this, which presumably you don't want to, then you simply have to transpose z in the call to surf, to ensure that you match x to the columns or z' (i.e, the rows of z), and y to the rows of z' (i.e. the columns of z).
Having said all that, it would probably be much better to make your function vectorized, and just use the surf(x, y, pr) syntax directly.
I'm currently solving some problems in prolog and I can't seem to get it work with one question regarding recursion, I have been presented with this table: Gryffindor Table.
Given that information, I made my own KB with this content:
/*
This order represents how they are sit from left to right
parvati_patil is left to lavender_brown,
lavender_brown is left to neville_longbottom
and so on, until we reach parvati again at the end.
*/
seatedTogether(parvati_patil, lavender_brown).
seatedTogether(lavender_brown, neville_longbottom).
seatedTogether(neville_longbottom, alicia_spinnet).
seatedTogether(alicia_spinnet, fred_weasley).
seatedTogether(fred_weasley, george_weasley).
seatedTogether(george_weasley, lee_jordan).
seatedTogether(lee_jordan, dennis_creevey).
seatedTogether(dennis_creevey, dean_thomas).
seatedTogether(dean_thomas, ginny_weasley).
seatedTogether(ginny_weasley, angelina_johnson).
seatedTogether(angelina_johnson, seamus_finnigan).
seatedTogether(seamus_finnigan, colin_creevey).
seatedTogether(colin_creevey, harry_potter).
seatedTogether(harry_potter, hermione_granger).
seatedTogether(hermione_granger, ron_weasley).
seatedTogether(ron_weasley, natalie_mcdonald).
seatedTogether(natalie_mcdonald, katie_bell).
seatedTogether(katie_bell, parvati_patil).
% X is left to Y if they are seatedTogether(X,Y)
isAtLeft(X,Y):-seatedTogether(X,Y).
% X is right to Y if they are seatedTogether(Y,X)
isAtRight(X,Y):-seatedTogether(Y,X).
/*
This rule just tells us who X is two places away from Y,
X is two places away from Y if
X is seatedTogether(X,Z)
and that Z is seatedTogether(Z,Y).
*/
twoPlacesAway(X,Y):-seatedTogether(X, Z), seatedTogether(Z,Y).
/*
This rule just tells us whos sitting # the table
by just unifying X with the values of seatedTogether(X,Y)
without regarding Y.
*/
atTable(X):-seatedTogether(X,_).
/*
Between two:
Its supposed to tell us whos Z is between X and Y
The perfect case (for me) would be that X and Y are sitting
together, so they have no one in the middle.
The other way around would be that
X is not equal to Y
X1 is sitting left to X,
and then we call it again with
X1, Y and Z1 as args,
after each call, we equal
Z to X1 value.
*/
betweenTwo(X,Y,Z):-isAtLeft(X,Y),isAtRight(Y,X).
betweenTwo(X,Y,Z):-
X \= Y,
isAtLeft(X, X1),
betweenTwo(X1, Y, Z1),
Z = X1.
The problem comes with the last rule definition, if I call it like this:
betweenTwo(ron_weasley, alicia_spinnet, Z).
The value of Z should be:
natalie_mcdonald,
katie_bell,
parvati_patil,
lavender_brown,
neville_longbottom.
But Z only unifies with the value of
natalie_mcdonald.
I believe I'm super close to it, but I'm really lost on what's going wrong with that rule. I defined it so X step by step equals the value of Y, but with the value before Y it should fall in the perfect case and stop moving, and unify the rest of elements before it. Any ideas?
First: your base case (what you call "perfect case") says "if X is at left of Y, and Y is at right of X, then every Z is between them", instead of "no one is between them" (the conditions are redundant as well). The base case should say when the predicate holds (that is, when some Z is between X and Y), not when it doesn't. See also this answer: https://stackoverflow.com/a/3001941/9204
Second: in the non-base case, you have
isAtLeft(X, X1),
betweenTwo(X1, Y, Z1),
Z = X1.
When Prolog searches for X1 in isAtLeft(ron_weasley, X1), the only answer is natalie_mcdonald, and later Z = X1 forces Z to be natalie_mcdonald too.
So this part of your code is equivalent to
isAtLeft(X, Z),
betweenTwo(Z, Y, Z1).
or in words "Z is between X and Y if: X is not equal to Y, X is directly to the left of Z, and some Z1 is between Z and Y", which doesn't make sense.
You should note the warning about singleton variable Z1, too.
I'm trying to multiply two numbers in Prolog recursively i.e. 3*4 = 3+3+3+3 = 12.
My code is :
mult(0,Y,Y).
mult(X,Y,Z) :-
NewX is X-1,
Z is Y + mult(NewX,Y,Z).
but I keep either in an infinite loop or being told mult is not a function.
What you here constructed is a predicate. A predicate is not the same as a function in computer science, you can not write A is B + some_pred(C), or at least not as far as I know in ISO Prolog, and definitely not without adding some extra logic.
In order to pass values, one uses variables. We can thus call the mult/3 predicate recursively, and use a variable that will be unified with the result. We can then perform arithmetic with it, like:
mult(0, _, 0).
mult(X, Y, Z) :-
X1 is X - 1,
mult(X1, Y, Z1),
Z is Y + Z1.
Note that you can not reassign a (different) value to a variable. So if, like you did in the question, use Z twice, then given Y is not 0, this will fail.
The above is however still not sufficient, since it will produce a result, but then get stuck in an infinite loop since if it calls (eventually) mult(0, 4, Z) (4 is here just a value), there are two ways to resolve this: with the base case, and with the recursive case.
We thus need a "guard" for the second case, like:
mult(0, _, 0).
mult(X, Y, Z) :-
X > 0,
X1 is X - 1,
mult(X1, Y, Z1),
Z is Y + Z1.
We then obtain for example:
?- mult(14, 25, Z).
Z = 350 ;
false.
One can improve the speed of this mult/3 predicate by implementing a version with an accumulator. I leave this as an exercise.
I have two approximated functions and I want to find the maximum value (error) between their graphs, to see how much they approach. I used :
FindMaximum[Abs[f[x] - p[x]], x], but Mathematica 8 gave me that output:
{2.75612*10^104, {x -> 2.75612*10^104}}
what does this mean? It is too big!
can you suggest me a better way?
Thanks
It's hard to tell not knowing your functions, but I'd guess that the position of the maximum it found is well outside your intended domain. You may have more success using a different form or FindMaximum, namely
FindMaximum[Abs[f[x] - p[x]],{x,x0,xmin,xmax}]
where x0 would be your initial guess for it (can be any point inside the region of interest), and xmin,xmax are the endpoints of your region of interest.
The reason is probably what Leonid said. To look at what FindMaximum is doing in real time, you can do
f[x_] := Sin[x];
p[x_] := x^2;
lst = {};
Monitor[
FindMaximum[Abs[f[x] - p[x]], x,
EvaluationMonitor :> (AppendTo[lst, x]; Pause[.01])
], ListPlot[lst, PlotRange -> Full]
]
the vertical axis on the resulting plot is the x-coordinate FindMaximum is currently looking at. Once FindMaximum is done, the plot disappears; the list is stored in lst so you can eg ListPlot it.
You can also try this with {Abs[f[x] - p[x]], -1 <= x <= 1} as the argument, as suggested by Spencer Nelson, to see how the search proceeds then.
This is probably caused by some sort of overflow in one of the two functions when the input value of x is a very large number. You should restrict your domain to [-1, 1]:
FindMaximum[{Abs[f[x] - p[x]], -1 <= x <= 1}, x]
If you want to search for a global maximum within the interval {a, b}, I suggest NMaximize:
NMaximize[{Abs[f[x] - p[x]], a <= x <= b}, x].
Note that FindMaximum searches for any local maximum, which is only good if you know that, for your particular function, a local maximum would also be a global maximum.
Instead of the objective function Abs[f[x] - p[x]], you may wish to use the objective function (f[x] - p[x])^2. This would make the objective function smooth (if f[x] and p[x] are smooth), which can help improve the efficiency of some numerical optimization methods.