I have stared at this assignment for far too long now and I simply don't understand what I am supposed to do exactly. We are given a 3x3 chess board and have to produce some propositonal clauses to this problem. This is what information we have been given:
Write a Python program that generates the input for a SAT
solver to solve the 3-Towers problem:
a) Write a function pair2int(r,c)
which maps (1,1), (1,2), ..., (3,3) to 1 to 9
using the formula 3*(r-1)+c.
b) Write nested for-loops that go through
all positions on the board from (1,1) to (3,3)
and produces clauses that represent attacks.
c) Write a for-loop that produces clauses that
specify that all 3 rows contain a tower
We are expected to write clauses in Conjunctive normal form as far as I understand. Could also be done directly in DIMACS
So I have done the a part, but I simply don't understand how I am supposed to express attacks or even what an attack constitutes, exactly.
This is the part of the program that I have done (a):
def pair2int(r):
return [3*(p[0]-1)+p[1] for p in r]
print(pair2int([(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]))
which simply returns a list of positions 1-9 on a 3x3 board:
[1,2,3,4,5,6,7,8,9]
I don't understand what I am supposed to do with this.
Can somebody push me in the right direction?
The three towers (rooks) have to be put on the chessboard without attacking eachother. Towers can either move horizontally (within a row) or vertically (within a column). Therefore, towers attack eachother if they are put on the same row or on the same column.
A problem solution consists of a set of coordinates (1..3;1..3) or cell numbers (1..9) of the three towers.
A possible binary encoding for tower coordinates consists of four binary variables per tower:
row (encoded with two bits)
column (encoded with two bits)
As alternative, you could encode the cell number 1..9 per tower. This also would require four bits per tower or 12 bits in total.
The constraints to be expressed as clauses:
All towers must have valid coordinates within the chessboard
No pair of towers shares the same row (i.e. one tower per row)
No pair of towers shares the same column (i.e. one tower per column)
3 towers is a simplification of the n queens problem.
Example solution for 8 rooks (Wikipedia):
Related
I have a plot in Excel (displayed below) which includes 5 different segments (A, B, C, D and E). These segments were drawn separately and move also separately. Now, I would like to do two things:
"link" them together in other that if, I move the intersection point between A and B then the length of A and B automatically adjust (however keeping the intersection point between B and C static).
I like to force Excel to consider segment A for example vertical. In other words, it means that if I move the intersection between segments A and B as stated under 1, then segment A parallelly moves and stays vertical.
Is there a way to do these 2 things in Excel (I guess maybe in the configuration of the draw)?
https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
I'm thinking they're a cute notation for arctan2, but I'm not sure. But then reading the notes below the equations just makes me more confused.
F.6.5.6 is using a triple bar and not an equal sign. The first part of the equation is Theta 1 and the second part is Theta 2, and then the arc that sweeps between them is the delta Theta (I suppose that just how you do it with a matrix, comma, parenthesis, angle sign, triple bar notation -- but I couldn't find other examples).
Theta1 (F.6.5.5) and Theta2 (F.6.5.6 left hand side) are calculated with atan2.
In the notation used in F.6.5.4
the half arrows (some people use full arrows here) over u and v indicate that these are vectors, ie directional quantities. These are usually expressed as a list of real numbers indicating a movement along each of the principle directions, for example in the 2-dimensional cartesian plane, we may have a vector (1,1) which indicates movement up by one and right by one (movement at a 45 degree angle).
On the left of the equation, the strange little symbol indicates an angle, so that left hand side reads the angle between the vectors u and v.
On the right hand side, the dot indicates a dot product (the sum of the products of corresponding entries in the vectors), and the double-bar notation indicates the length of the vector (the square root of the dot product of the vector with itself - in 2 dimensions, this should remind you of the Pythagorean Theorem).
This is a standard formula intimately familiar to anybody who has studied linear algebra. Here is a wikihow article demonstrating the formula where you will see the same notation in use.
F.6.5.5 and F.6.5.6
are applying this formula using the vectors created from the given variables at the beginning of the section. The first formula defines θ1 as the angle between the first chosen vector and the right x-axis (the vector representing a movement of one unit to the right and no vertical movement) and the stated vector. The second formula finds the angle Δθ in a similar manner.
The triple bar is a congruence relation (read x ≡ y mod 3 as x congruent to y mod 3). When two things are congruent mod something it indicates that the remainders of the two are the same when divided by the other number. Thus 13 ≡ 6 mod 7 because both 6 and 13 leave a remainder of 6 when divided by 7.
The formula for Δθ is saying that this angle is equal to the value computed on the right when both are interpreted as an angle between 0 and 360 degrees.
This is not the same as using the atan2 function. atan2 is useful for computing the angle a single vector forms with the x-axis, but not when we need the angle between two vectors (without transforming the coordinate system first).
Given a range of numbers, say from [80,240], it is easy to determine how much of that range lies within [100,105]: (105-100)/(240-80) = 5/160 = .03125. Easy.
So now, how much of a Meriam Webster dictionary lies between umbrella and velvet? Even if we assume uniform distribution of text across the corpus, is there a standard metric for text?
I don't think there is a standard for that. If you had all entries from Meriam Webster in an array, you could use first and last positions as the bounds, so you would have a set going from 1 to n. Then you could pick the positions of "umbrella" and "velvet", call them x and y, and calculate your range as (y - x + 1) / (n).
That works if you are seeing words as elements of an ordered set, so as to have them behave as real numbers. You are basically dividing the distance between two numbers in a set by the distance between the boundaries of the set. Some forms of algebra deal with them differently - when calculating the Levenshtein distance between any two given words, for example, each words is seen as a vector with as many dimensions as they have characters.
You could define the boundaries of your n-dimensional space by using the biggest word in Meriam Webster (hint: it's "pneumonoultramicroscopicsilicovolcanoconiosis", so your space would have 45 dimensions). However, when considering any A-B pair of words, a third word C of intermediary length may or may not be between those, depending on the operations involved in the transformation from A to B.
You'd have to check every word with a length between that of A and B to check whether they are part of the range between A and B... So it's not a matter of simple calculus, and I don't know if this could be even feasible with a regular computer nowadays. And that's just considering Meriam's close to half a million entries.
This paper contains confusion matrices for spelling errors in a noisy channel. It describes how to correct the errors based on conditional properties.
The conditional probability computation is on page 2, left column. In footnote 4, page 2, left column, the authors say: "The chars matrices can be easily replicated, and are therefore omitted from the appendix." I cannot figure out how can they be replicated!
How to replicate them? Do I need the original corpus? or, did the authors mean they could be recomputed from the material in the paper itself?
Looking at the paper, you just need to calculate them using a corpus, either the same one or one relevant to your application.
In replicating the matrices, note that they implicitly define two different chars matrices: a vector and an n-by-n matrix. For each character x, the vector chars contains a count of the number of times the character x occurred in the corpus. For each character sequence xy, the matrix chars contains a count of the number of times that sequence occurred in the corpus.
chars[x] represents a look-up of x in the vector; chars[x,y] represents a look-up of the sequence xy in the matrix. Note that chars[x] = the sum over chars[x,y] for each value of y.
Note that their counts are all based on the 1988 AP Newswire corpus (available from the LDC). If you can't use their exact corpus, I don't think it would be unreasonable to use another text from the same genre (i.e. another newswire corpus) and scale your counts such that they fit the original data. That is, the frequency of a given character shouldn't vary too much from one text to another if they're similar enough, so if you've got a corpus of 22 million words of newswire, you could count characters in that text and then double them to approximate their original counts.
Idealy I want to supply a sequence of points and have a line drawn at a right angle at every point (starting at the second point).
The direction of each line would alternate, so if I happened to draw a curve cosisting of 6 points, a line of a given lenth would be drawn for each point starting with the second point, i.e 5 additional lines on alternating sides of the curve, a bit like a caterpillar with alternating legs.
(I understand that the lines won't be entirely at right angles to the curve but rather at right angle to the line formed by any two points on the curve).
It's a question of vector mathematics. You can calculate the directing vector between two points A and B by subtracting A from B. In 2D and only in 2D the vector right angled to this vector can be obtained by reversing x and y component and taking one component negative. If you negate the new x component you'll make a left turn, by negating y you'll make a right turn. You can then reduce the directing vector to unit size (= of length 1) by dividing each component by the length of the vector (sqrt(xx + yy)). Finally you can stretch the unit vector again by your desired length and have one of the size you want. If you add this vector to either A or B you'll get a point to which you want to draw your line.
Here's a little math help:
These are points A and B expressed as vector.
The directing vector is calculated by a simple subtraction.
The normal vector is given by flipping the directing vector, that is to reverse the components and make one component negative. nl = normal, flipped to the left, nr = normal, flipped to the right
The unit vector of the normal vector is given by dividing each component by the length of the vector.
Calculates the length of a vector
If you want to draw a line from B to the left (when coming from A) you calculate the point P to draw the line to as
So you want to alternate that one time you draw to the left and one time to the right when iterating over the points.
If you have points lying outside your canvas, then you length is probably too large. You can of course calculate the point at which the vector to P would cross the boundary by calculating the intersection point of the vector BP and the border.