Stuck with table : alignement - layout

I'm not satisfied with the layout and I thought about maybe some sort of table without borders or idk can u help me with it plz?
This is my code:
\begin{equation}
\forall x \in \mathbb{R}, \cos(x+2\pi)=\cos(x) \quad\text{and}\quad \forall x \in \mathbb{R}, \sin(x+2\pi)=\sin(x)
\end{equation}
\begin{equation}
\forall x\in \mathbb{R}, \cos(x+\pi)=-\cos(x)\quad\text{and}\quad \forall x \in \mathbb{R}, sin(x+\pi)=-\sin(x)
\end{equation}

Here is a possible solution with the align environment from amsmath.
\documentclass[]{article}
\usepackage{amsmath,amsfonts}
\begin{document}
\noindent Initial version with two equation environment
\begin{equation}
\forall x \in \mathbb{R}, \cos(x+2\pi)=\cos(x) \quad\text{and}\quad \forall x \in \mathbb{R}, \sin(x+2\pi)=\sin(x)
\end{equation}
\begin{equation}
\forall x\in \mathbb{R}, \cos(x+\pi)=-\cos(x)\quad\text{and}\quad \forall x \in \mathbb{R}, sin(x+\pi)=-\sin(x)
\end{equation}
\medskip
\noindent With the align environment. = signs and 'and' are aligned
\begin{align}
\forall x \in \mathbb{R},\, \cos(x+2\pi)&=\quad\cos(x) \quad\text{and}& \forall x \in \mathbb{R},\, \sin(x+2\pi)=&\quad\sin(x)\\
\forall x\in \mathbb{R},\, \cos(x+\pi)&=-\cos(x)\quad\text{and}& \forall x \in \mathbb{R},\, \sin(x+\pi)=&-\sin(x)
\end{align}
\end{document}
The equal signs and the `and' are aligned. I also added extra space after the = signs of the first line to align the sin/cos operators. This is unusual (and maybe forbidden by math standards), but it makes the symmetry of the expressions more obvious .
Disclaimer note : I am definitely not sure that it is compliant with the best mathematical typography recommendations. Experiment with other alignments.

Related

How is the full adder's carry out term derived?

I'm reading the section of the full adder in Digital Design by Morris Mano and I can't seem to figure out how it got from equation A to equation B.
From a full adder's truth table and k-map using inputs x, y, and z, the carry out term, C, is defined as:
C = xy + xz + yz (equation A)
I could understand the above, but in order to leverage the xor already used by the summation term of x, y, and z, the book redefines C as:
C = z(xy' + x'y) + xy = xy'z + x'yz + xy (equation B)
How are these two equivalent? I've tried to derive one from the other on paper but I'm not able to come up with the steps in between.
Sorry my comment (which I removed) was hastily stated.
Consider the following logic table (I'm using ^ to represent XOR for brevity):
The results of xy + xz + yz are the same as xy + (x ^ y)z because, for the first 6 cases, the value of x + y and x ^ y are the same. For the last two cases where they are different, the xy term being OR'ed in is 1 which makes their difference irrelevant to the final value.

Translation to Predicate Logic with Lexicon

How would one translate the following statement into predicate logic:
"Even though the examiner hopes all students will satisfy the requirements for grade E or better, somebody will receive a lower grade and be disappointed."
The first step is to define an alphabet. Take the following first-order alphabet with the desired interpretation:
Unary predicates:
S(x): "x is a student"
E(x): "x is an examiner"
G(x): "x is a grade"
D(x): "x is disappointed"
Binary predicates:
R(x, y): "x is a requirement for y"
B(x, y): "x is y or better"
O(x, y): "x receives y"
Ternary predicates:
H(x, y, z): "x hopes that y fulfills z"
e: Constant ("the grade E")
x, y, z, w: Variables
Let's break the original statement in two parts:
S1: "The examiner hopes all students will satisfy the requirements for grade E or better"
S2: "Somebody will receive a lower grade and be disappointed"
And use the defined alphabet to write it in first-order:
S1: ∃x(E(x) ∧ ∀y(S(y) ⇒ ∃z∃w(R(z, e) ∧ B(w, z) ∧ H(x, y, w))))
S2: ∃x∃y(S(x) ∧ G(y) ∧ O(x, y) ∧ ¬B(y, e) ∧ D(x))
Finally we compute the original statement, that is:
S1 ∧ S2
Keep in mind that this is just one of the interpretations that will lead to a correct (satisfying) answer.
I hope it helps

How to convert (0,0) to [0,0] in prolog?

I'm making a predicate distance/3 that calculates the distance between 2 points on a 2d plane. For example :
?- distance((0,0), (3,4), X).
X = 5
Yes
My predicate only works if (0,0) is the list [0,0]. Is there a way to make this conversion?
You can do this with a simple rule that unifies its left and right sides:
convert((A,B), [A,B]).
Demo.
Although the others have answered, keep in mind that (a,b) in Prolog is actually not what you might think it is:
?- write_canonical((a,b)).
','(a,b)
true.
So this is the term ','/2. If you are working with pairs, you can do two things that are probably "prettier":
Keep them as a "pair", a-b:
?- write_canonical(a-b).
-(a,b)
true.
The advantage here is that pairs like this can be manipulated with a bunch of de-facto standard predicates, for example keysort, as well as library(pairs).
Or, if they are actually a data structure that is part of your program, you might as well make that explicit, as in coor(a, b) for example. A distance in two-dimensional space will then take two coor/2 terms:
distance(coor(X1, Y1), coor(X2, Y2), D) :-
D is sqrt((X1-X2)^2 + (Y1-Y2)^2).
If you don't know how many dimensions you have, you can then indeed keep the coordinates of each point in a list. The message here is that lists are meant for things that can have 0 or more elements in them, while pairs, or other terms with arity 2, or any term with a known arity, are more explicit about the number of elements they have.
If you just have a simple pair, you can use the univ operator and simply say something like:
X = (a,b) ,
X =.. [_|Y] .
which produces
X = (a,b) .
Y = [a,b] .
This doesn't work if X is something like (a,b,c), producing as it does
X = (a,b,c) .
Y = [a,(b,c)] .
[probably not what you want].
The more general case is pretty simple:
csv2list( X , [X] ) :- % We have a list of length 1
var(X) . % - if X is UNbound
csv2list( X , [X] ) :- % We have a list of length 1
nonvar(X) , % - if X is bound, and
X \= (_,_) . % - X is not a (_,_) term.
cs22list( Xs , [A|Ys] ) :- % otherwise (the general case) ,
nonvar(Xs) , % - if X is bound, and
Xs = (A,Bs) , % - X is a (_,) term,
csv2list(Bs,Ys % - recurse down added the first item to result list.
. % Easy!

Find combinations of words in two vectors

I have a long list of words contained in two vectors
The first vector looks like this:
x <- c("considerably", "much", "far")
The second vector looks like this:
y <- c("higher", "lower")
I need a vector returned, which lists possible combinations of words from each vector. Using x and y, I would need this vector returned
[1] "considerably higher" "considerably lower" "much higher" "much lower"
[5] "far higher" "far lower"
Therefore words in vector x must come before words in vector y. Is there a quick way of doing this?
You could use outer with paste, I think that will be quite quick!
as.vector( t( outer( x , y , "paste" ) ) )
# [1] "considerably higher" "considerably lower" "much higher"
# [4] "much lower" "far higher" "far lower"
You could use expand.grid.
sort(apply(X = expand.grid(x, y), MARGIN = 1, FUN = function(x) paste(x[1], x[2], sep = " ")))

Check if coordinate in selected area

I have 4 coordinates of area: x1,y1 ... etc. And have one more position x0,y0.
How to check if my coordinate in selected area?
I will explain you how to check that (x0,y0) lies "below" the line through (x1,y1) and (x2,y2). Essentially, you want that the vector (x0-x1,y0-y1) points "to the right" of (x2-x1, y2-y1). This is equivalent to saying that the matrix
x0-x1 y0-y1
x2-x1 y2-y1
has a negative determinant. So your condition becomes
(x0-x1)(y2-y1) < (y0-y1)(x2-x1).
You get such a condition for any line bounding the area.
Let
A = {x1, y1}
B = {x2, y2}
C = {x3, x3}
D = {x4, x4}
First, make sure that points form a polynomial and are not in straight line. This can be done by comparing the direction(AB) != direction(AC) != direction(AD) where AB, AC, AD are directional vectors.
To make sure that certain point P = {x0, y0} lies within the polygon ABCD, it is sufficient to check that sign(AC X AP) == sign(CD X CP) == sign(DB X DP) == sign(BA X BP).
AC: Directional vector A -> C
AP: Directional vector A -> P
.
. so on!
.
X: Cross product
sign: sign of cross product (+ or -)
It is only required to compare the sign of direction not the magnitude.

Resources