For my class I have to study some Boolean algebra. Now I'm having some difficulties with simplifying expression.
For example I get:
A.B.C + NOT(A) + NOT(B) + NOT(C)
I tried checking wolfram alpha but there's not simplification showing up there.
Can you tell me how to simplify this expression?
Thanks in advance
Truth table:
A B C X
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1
So the simplification is just:
X = 1
Boolean Algebraic Solution (using a more traditional notation):
Given Boolean expression:
abc + a' + b' + c'
Apply double negation:
(abc + a' + b' + c')''
Apply De Morgan's Law for a disjunction:
((abc)'a''b''c'')'
Reduce double negations:
((abc)'abc)'
AND of x and x' is 0:
(0)'
Negation of 0 is 1:
1
Boolean Algebraic Solution (using the given notation):
Given Boolean expression:
a.b.c + NOT(a) + NOT(b) + NOT(c)
Apply double negation:
NOT(NOT(a.b.c + NOT(a) + NOT(b) + NOT(c)))
Apply De Morgan's Law for a disjunction:
NOT(NOT(a.b.c).NOT(NOT(a)).NOT(NOT(b)).NOT(NOT(c))))
Reduce double negations:
NOT(NOT(a.b.c).a.b.c)
AND of x and x' is 0:
NOT(0)
Negation of 0 is 1:
1
Wolfram Alpha wasn't giving a simplification because it didn't understand your notation. Using (A and B and C) or NOT(A) or NOT(B) or NOT(C) shows that it simplifies to true.
Or you can just look at it: if any are false, the NOT will makke everything true, and if they're all true, then so is the first clause.
Use http://en.wikipedia.org/wiki/De_Morgan%27s_laws
A AND B = NOT(NOT(A) OR NOT(B))
A OR B = NOT(NOT(A) AND NOT(B))
and the normal methods for distribution, commutation, etc. See
http://en.wikipedia.org/wiki/Boolean_algebra#Laws
Note that in the linked texts above the symbols are written differently.
AND is ∧
OR is ∨
NOT is ¬
Related
I have this program that, when run, has prints in this pattern:
a(0) = 0
a(1) = 1
a(2) = 2 + a(1) = 3
a(3) = 3 + a(2) + a(1) = 3 + 3 + 1 = 7
a(4) = 4 + 3 + 3 + 1 = 15
At this point I observe that there is a pattern of it becoming O(2^n - 1). However, I am not sure if this is a valid proof by induction. An idea I had was:
a(n)= n + a(n-1) + a(n-2) + ... + 1 = 2^n - 1
But from here the pattern for the terms are not very clear to me. I know the first term is n (in our code, this is due to a for loop that prints a statement n times), and due to recursion I know I will be summing the previous values but I don't know what a(n-1), a(n-2), etc. are in terms of n.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
My apologies, this question is now redirected to
this web page in math forum.
Empirically, I can know that (a+b+c) mod 2 = (a-b-c) mod 2.
e.g.,)
1+2+3 = 6, 6 mod 2 = 0
1-2-3 = -4, -4 mod 2 = 0
1+2+4 = 7, 7 mod 2 = 1
1-2-4 = -5, -5 mod 2 = 1
It seems that it is only possible when we use binary modulo (mod 2).
Is there any formal proof for this?
Not sure, why this ended up on SO. As James said in the comments, these questions should be asked on math.stackexchange But since it is here:
I a + b + c = a - b - c + 2(b + c)
II 2(b + c) ≡ 0 (mod 2), ergo
III a + b + c ≡ a - b - c (mod 2)
Edit, since it was requested: The generalisation of II would require n to be a divisor of 2 to fulfill
2(b + c) ≡ 0 (mod n)
for all b and c, which means that n is either 1 or 2.
The reason this works mod 2 is exactly because there are only two residues: 0 and 1. And thus it is true that for any x
x ≡ -x mod 2
Thus a + b ≡ a - b mod 2
Obviously this is not true for any other modulo operation. So for any other n > 2 you can create a simple counter-example for (a+b+c) ≡ (a-b-c) mod n:
a = n
b = 0
c = 1
(a + b + c) mod n = 1
(a - b - c) mod n = n - 1
Obviously n - 1 is not equal to 1 if n > 2. Actually most of the triplets (a, b, c) would be counter-examples for any n > 2.
I am trying to write a program to draw a bezier curve segment implementing the knowledge from my textbook. I wanted to try making a drawing program to draw something using implicit functions. I want my program to work as follow.
user input an implicit function, let's say y=2x^3.
calculate control points (don't know how to do)
draw bezier curve (done)
next function
Theoretically, I can draw the curves by direct substitution, but I might do some modifications to the curve and I want to implement what I have learnt, so, I wanted to do it wisely(direct substitution seems dumb).Thz^^
Edit 1 : Let's assume the boundaries were provided by the user
The first step is generating a parameterized expression for the curve. The given example can be transformed very easily:
c(t) = (t, 2 * t^3)^T
Now express this curve in Monomial basis:
c(t) = / 0 1 0 0 \ * (1, t, t^2, t^3)^T
\ 0 0 0 2 /
= C * M(t)
In this expression, the first matrix C is the coefficient matrix. All we need to do is transform this matrix to Bernstein basis. The matrix that transforms Monomial basis to Bernstein basis is:
/ 1 - 3t + 3t^2 - t^3 \ / 1 -3 3 -1 \ / 1 \
B(t) = | 3t - 6t^2 + 3t^3 | = | 0 3 -6 3 | * | t |
| 3t^2 - 3t^3 | | 0 0 3 -3 | | t^2 |
\ t^3 / \ 0 0 0 1 / \ t^3 /
This equation can be inverted to get:
/ 1 1 1 1 \
M(t) = | 0 1/3 2/3 1 | * B(t)
| 0 0 1/3 1 |
\ 0 0 0 1 /
Substituting this into the curve equation, we get:
c(t) = C * M(t)
/ 1 1 1 1 \
= C * | 0 1/3 2/3 1 | * B(t)
| 0 0 1/3 1 |
\ 0 0 0 1 /
The first matrix product can be calculated:
c(t) = / 0 1/3 2/3 1 \ * B(t)
\ 0 0 0 2 /
And this gives you the control points for the Bezier curve:
p0 = (0, 0)^T
p1 = (1/3, 0)^T
p2 = (2/3, 0)^T
p3 = (1, 2)^T
This very procedure can be applied to any polynomial curve.
The general solution for an equation in the form
y = a + b * x + c * x^2 + d * x^3
is:
p0 = (0, a)^T
p1 = (1/3, a + b/3)^T
p2 = (2/3, a + 2b/3 + c/3)^T
p3 = (1, a + b + c + d)^T
I want to write in Maple Taylor series for cosinus function. Here's my code:
better_cos := proc (x) options operator, arrow; sum((-1)^n*x^(2*n)/factorial(2*n), n = 0 .. 20) end proc;
better_cos(0) returns 0 instead of 1 (cos(0) == 1). It's probably because x^(2*n) return always 0 instead of 1. For example:
fun_sum := proc (x) options operator, arrow; sum(x^(2*n), n = 0 .. 0) end proc
return 0 for x == 1.
It's weird because 0^0 returns 1. Do you have any idea how can I correctly implement taylor series for cosinus?
You should be able to get what you want by using add instead of sum in your better_cos operator.
Using add is often more appropriate for adding up a finite number of terms of a numeric sequence, and also note that add has Maple's so-called special evaluation rules.
If you intend to take the sum of a fixed number of terms (ie. n from 0 to 20) then you should not write a procedure that computes the factorials for each input argument (ie. for each value of x). Instead, produce the truncated series just once, and then use unapply to produce an operator. This approach also happens to deal with your original problem, since the x^0 term becomes 1 because the symbol x is used.
You could also rearrange the polynomial (truncated series) so that it is in Horner form, to try and minimize arithmetic steps when evaluating subsequently at various numeric values of x.
For example, using 5 terms for brevity instead of 20 as you had it,
convert(add((-1)^n*x^(2*n)/factorial(2*n), n = 0 .. 5),horner);
/ 1 /1 / 1 / 1 1 2\ 2\ 2\ 2\ 2
1 + |- - + |-- + |- --- + |----- - ------- x | x | x | x | x
\ 2 \24 \ 720 \40320 3628800 / / / /
bc := unapply(%,x):
You can now apply the procedure bc as you wish, either with symbolic or numeric arguments.
expand(bc(x));
1 2 1 4 1 6 1 8 1 10
1 - - x + -- x - --- x + ----- x - ------- x
2 24 720 40320 3628800
bc(0);
1
bc(1.2);
0.3623577360
If you prefer to have your procedure better_cos take a pair of arguments, so that the number of terms is variable, then you could still consider using add to deal with your original problem. eg,
bc := (x,N)->add((-1)^n*x^(2*n)/(2*n)!, n = 0 .. N):
I suppose that this is a homework assignment, and that you realize that you could also use the existing system commands taylor or series to get the same results, ie.
convert(series(cos(x),x=0,10),polynom);
1 2 1 4 1 6 1 8
1 - - x + -- x - --- x + ----- x
2 24 720 40320
convert(taylor(cos(x),x=0,10),polynom);
1 2 1 4 1 6 1 8
1 - - x + -- x - --- x + ----- x
2 24 720 40320
Here's the Taylor series definition:
Don't start the loop with zero; initialize with one and start at two.
Factorial is inefficient, too.
What is the Equation that on increasing the integer x returns an alternate of 0 and 1
example
x = 22
result 1
x = 23
result 0
x = 24
result 1
Based on the example data, it would be modulo 2. Assuming x is an int (and C/C++/C#):
(x + 1) % 2;
In C or C++ this would be
int y = (x+1)%2;
mathematically,
y = (x+1) modulo 2
It's called modulo. You can use mod by 2 after adding one in the value.
x = 22
result = (x+1) modulo 2
In programming languages, it's often called %:
x = 22
result = (x+1) % 2 //<< result 1
x = 23
result = (x+1) % 2 //<< result 0
and so on..