I want to simplify the following expression:
F = (A+B+C)(A+B'+C)(A'+B+C)
I have simplified it accordingly.
F = (A+B+C)(A+B'+C)(A'+B+C)
F = (A+C)(A'+B+C)
F = AA' + AB + AC + A'C + BC + C
F = AB + C(A + A' + B + 1) = AB + C
However, the correct answer is (A+C)(B+C).
Where in my "current" proof am I going wrong? I have seen the solution, but I want to know why my current approach is wrong.
Nothing wrong - it's just two different ways of expressing the same thing.
If the goal is minimization I would argue that your solution is "better" since it only references each term once.
Wolfram Alpha is your friend in cases like this.
My own equation is a bit longer, but the following example shows perfectly where I struggle at the moment.
So far I have been using the let() and letsimp() function
to substitute longer terms in an equation,
but in this example they have no effect:
(%i1) eq: ((2*u+a^2+d) * y+x)/2*a = x;
2
a ((2 u + d + a ) y + x)
(%o1) ------------------------ = x
2
(%i2) let(2*u+a^2+d, %beta);
2
(%o2) 2 u + d + a --> %beta
(%i3) letsimp(eq);
2
a ((2 u + d + a ) y + x)
(%o3) ------------------------ = x
2
What is the preferred way to replace 2*u+a^2+d with %beta in this sample equation?
And why has letsimp() no effect?
Thank you very much!
letsimp applies only to "*" expressions. You could try subst.
I'm writing a simple octave program that calculate similarity between two images.
The relevant part for this question can be found here:
http://pastebin.com/gBxN7VbP
The function struct_comp was supposed to return some number between zero and one. But the command
ec = (corr + C) / (dp1 * dp2 + C);
is setting ec as 0 even when it should not be zero.
The disp commands are showing the values of all variables involved in this division. The output is:
C:
6.5536
dp1
97.663
dp2
47.686
corr
-290
(corr + C)
-283
(dp1 * dp2 + C)
4663.7
(corr + C) / (dp1 * dp2 + C)
0
Struct comp:
0
As you can see, the partial values (numerator and denominator) are right, but the division is returning zero.
Somebody knows what is happening here?
Thank you.
EDIT:
The two images used to generate this output were these:
http://lasca.ic.unicamp.br/~hilder/tux.jpg
http://lasca.ic.unicamp.br/~hilder/monalisa.jpg
But you can use any grayscale image to test, just change the name in the code.
i replaced the line
ec = (corr + C) / (dp1 * dp2 + C);
by
ec = double(corr + C) / double(dp1 * dp2 + C);
and it worked.
My problem is just really simple,
I found somethng in the stackoverflow a same problem but it finds the largest number between 2 numbers
var c =(Math.sqrt( a*a + b*b - 2*a*b ) + a + b) / 2;
can somebody help me revised this equation so the lowest number should print out?
hi i have one solution
c = ((a + b) - sqrt((a - b) * (a - b))) / 2
Hope this will help you
Rewrite your code as below:
var c =((a + b) - Math.sqrt((a - b) * (a - b))) / 2;
As far as I know:
c = ((a + b) - sqrt((a - b) * (a - b))) / 2
equals
c = ((a + b) - (a - b)) / 2
equals
c = (a - a + b + b) /2 = b
or am I missing something?
Why don't you use the Math class for it? Like Math.min(a,b) ????
I have a game table like:
CREATE TABLE game_piece(
x Integer,
y Integer,
type Integer
);
Each (x,y) can only have 1 piece. Representing a grid (numbers being types):
1235
1134
9678
By connected I mean they have to be directly next to the origin in a vertical or horizontal fashion like:
C C=connected
COC O=origin
C
I'd like to check if there's 3 pieces connected anywhere on the grid without needing to get the whole grid of the database and doing it in python, if there's decent solution. Suggestions?
To clarify my comments on Xophmeister's answer, like this:
SELECT o.x, o.y
FROM game_piece o
JOIN game_piece p
ON p.type = o.type
AND (
(o.x = p.x AND p.y IN (o.y-1,o.y+1))
OR
(o.y = p.y AND p.x IN (o.x-1,o.x+1))
)
GROUP BY o.x, o.y
HAVING COUNT(*) > 1
And here it is working on your test data: http://sqlfiddle.com/#!3/0bd34/1
Edit: Since you only want to know if the condition exists, the best way to do it is to just shove LIMIT 1 on the end and see whether the query returns a result or not. For some reason sqlfiddle doesn't like me putting the LIMIT in there, but I tested it on my server and it works just fine.
By 'connected', I'm going to assume you mean adjacent: That is, (5,3,1234) and (4,3,1234) would be connected.
As such, what you can do is join the table to itself twice, where each join depends on the one that preceded, and the conditions include:
on nextPiece.type = lastPiece.type
and (nextPiece.x in (lastPiece.x - 1, lastPiece.x + 1)
or nextPiece.y in (lastPiece.x - 1, lastPiece.x + 1))
Note that this doesn't consider diagonals as being adjacent.
The problem with this technique is that it will return duplicates: If record A is connected to record B, then both A and B will show in the result set. As you're joining twice, you'll see three duplicates... You can do a select distinct if all you are interested in is whether you've found a match, but the query in general will not be particularly fast either way (depending on how big your grid is and how sparsely it is populated).
EDIT See Braiba's solution (and comments, below): I made a mistake :P
Depending on what do you mean by connected, you don't need to dump the whole db but only the 2 pieces on 4 directions.
select x, y,
from game_piece
where (
(x between origin_x - 2 AND origin_x + 2 AND y = origin_y)
OR (y between origin_y - 2 AND origin_y + 2 AND x = origin_x)
)
AND type = the_type;
origin_x, origin_y are the coordinates of the piece you want to check.
That will dump between 1 and 8 pieces you'll have to check.
If the game table is very large, you should add an index on the x and y column, otherwise that might not be useful.
Hope it helps.
M.
This will return the number of different connection types:
select count(distinct type) as connections
from game_piece
where ((y = $y and x between $x - 1 and $x + 1)
or (x = $x and y between $y - 1 and $y + 1))
and (x != $x or y != $y) -- exclude the origin itself
You can use this solution:
SELECT 1
FROM game_piece
WHERE
(x = $o_x AND y IN ($o_y + 1, $o_y - 1)) OR
(y = $o_y AND x IN ($o_x + 1, $o_x - 1))
GROUP BY type
HAVING COUNT(1) = 3
$o_x and $o_y being the originX and originY input parameters respectively.
If there are exactly 3 pieces of the same type connected to the origin (either vertically or horizontally), this will return 1, otherwise, it will return an empty result-set.
Edit:
What you can try in order to find out if there's any pieces on the grid having 2 or more of the same adjacent types:
SELECT COUNT(1) > 0 AS doesExist
FROM
(
SELECT 1
FROM game_piece p
INNER JOIN game_piece o ON
p.type = o.type AND (
(p.x = o.x AND p.y IN (o.y + 1, o.y - 1)) OR
(p.y = o.y AND p.x IN (o.x + 1, o.x - 1))
)
GROUP BY p.type, o.x, o.y
HAVING COUNT(1) > 1
) a
Which will return 1 if there are one or more pieces and 0 if not.