Truth table to prove an argument true/false - truthtable

Can someone help me out with truth tables? I would like to create a truth table to prove whether or not this is true.

A B C B∧C A∨(B∧C) A ∨ B A ∧ C (A ∨ B) ∨ (A ∧ C)
0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 1 0 1
0 1 1 1 1 1 0 1
1 0 0 0 1 1 0 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 0 1
1 1 1 1 1 1 1 1
When A=0, B=1 and C=0
A ∨ (B ∧ C) = 0
(A ∨ B) ∨ (A ∧ C) = 1 ∨ 0 = 1
So A ∨ (B ∧ C) = A ∨ B) ∨ (A ∧ C) is false.

A = 0, B = 0, C = 0
A ∨ (B ∧ C) = 0 ∨ (0 ∧ 0) = 0 ∨ 0 = 0
(A ∨ B) ∨ (A ∧ C) = 0
Do the similar for the 7 more combination of A, B and C.
A = 0, B = 0, C = 1
A = 0, B = 1, C = 0
//// etc.
If you find both end same for all the eight then that is proved. Otherwise the are not same.
Also visit the Wikipedia entry for truth table for the details. Application section contains an example proof of another equation.
Note: Sounds like a homework. So not providing the full solution.

You only have three boolean variables, which means a 2^3=8 entry truth table will suffice. I suggest breaking down columns in your table to produce one boolean result at a time. If the two columns of the two sides of your boolean equation match, them you proved they are the same, otherwise you will have one or more counter-examples.
If the two expressions match, then you can try to prove they are equal using the rules of Boolean algebra. Karnaugh maps could even be used to point the way.

Related

Rasterization of image

I have a function ℚ -> ℚ -> Bool taking a Cartesian coordinate, where true stands for black and false for white. Is there any existing library that I can use to "rasterize" it into a bitmap image?
The PBM file format is a pretty simple text-based image file format. See https://en.wikipedia.org/wiki/Netpbm for a description. It's easy to write code to produce PBM files.
For the function λ x y → x ≤ᵇ y, the below code outputs the following PBM file contents:
P1
20 10
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
The lines mean the following:
P1 is a magic number that identifies the file format.
20 10 are the width and height of the image.
Each of the remaining lines represents one line of the image. 1 represents a black pixel and 0 a white pixel.
Put the above contents in a .pbm file (say, test.pbm) and you have something that you can open in image processing tools that support PBM files.
The makePBM function takes the width and height of the image to be produced, the x and y starting points in ℚ, the step to make in ℚ for each pixel in the x and y direction, and the ℚ → ℚ → Bool function to be evaluated.
--guardedness is only required, because I use IO for demonstration purposes.
{-# OPTIONS --guardedness #-}
module Raster where
open import Data.Bool using (Bool ; if_then_else_)
open import Data.Nat using (ℕ ; zero ; suc)
open import Data.Nat.Show using (show)
open import Data.Rational using (ℚ ; 0ℚ ; 1ℚ ; _+_ ; _≤ᵇ_)
open import Data.String using (String ; _++_)
open import IO using (Main ; run ; putStrLn)
-- width height offset-x offset-y step-x step-y function
makePBM : (w h : ℕ) → (ox oy sx sy : ℚ) → (ℚ → ℚ → Bool) → String
makePBM w h ox oy sx sy f = header ++ bitmap h oy
where
header : String
header = "P1\n" ++ show w ++ " " ++ show h ++ "\n"
row : (n : ℕ) → (x y : ℚ) → String
row zero x y = "\n"
row (suc n) x y = pixel ++ " " ++ row n (x + sx) y
where pixel = if f x y then "1" else "0"
bitmap : (n : ℕ) → (y : ℚ) → String
bitmap zero y = ""
bitmap (suc n) y = row w ox y ++ bitmap n (y + sy)
testPBM : String
testPBM = makePBM 20 10 0ℚ 0ℚ 1ℚ 1ℚ (λ x y → x ≤ᵇ y)
main : Main
main = run (putStrLn testPBM)
I'd be very surprised if there were. I'm not aware of any work on image manipulations in Agda.
Having said that, it should be relatively easy to do.
Create a m x n matrix of type Vector (Vector ℕ m) n from Data.Vec.Functional containing (i,j) at the ith row and jth column.
Map each (i,j) to the desired range of coordinates in the image.
Map the function f : ℚ -> ℚ -> Bool over each the entire matrix.

Taylor series expansion in maxima

How to expand taylor series/polynomials about Q=0 , and then extract coefficients as a list
example :
taylor ( (sin(q)), q, 0, 9); //taylor expansion for first 9 terms gives the next line
(%o1)/T/ q\-q^3/6+q^5/120\-q^7/5040+q^9/362880+...
then using coeff ((%o1), q ^n); gives me the coefficient at n only, what i want is a list for all the coefficients of that expression
Try coeff plus makelist, e.g. something like: makelist(coeff(%o1, q, n), n, 0, 9);
Edit:
I see now that I misread your question and there is already an answer. Nevertheless I will keep it because it is related to your question.
Use powerseries instead of taylor:
(%i1) expr:powerseries(sin(x),x,0);
inf
==== i2 2 i2 + 1
\ (- 1) x
(%o1) > -----------------
/ (2 i2 + 1)!
====
i2 = 0
You can access the coefficient by the args or part function
(%i2) op(expr);
(%o2) sum
(%i3) args(expr);
i2 2 i2 + 1
(- 1) x
(%o3) [-----------------, i2, 0, inf]
(2 i2 + 1)!
(%i4) part(expr,1);
i2 2 i2 + 1
(- 1) x
(%o4) -----------------
(2 i2 + 1)!
(%i5) args(expr)[1];
i2 2 i2 + 1
(- 1) x
(%o5) -----------------
(2 i2 + 1)!
If you want to change the index variable:
(%i6) niceindices(expr),niceindicespref=[n];
inf
==== n 2 n + 1
\ (- 1) x
(%o6) > ---------------
/ (2 n + 1)!
====
n = 0

How to represent binary logical in Three Address Code

In three address code a branch can only have a binary relational operator,
e.g.
if x relop y goto L1, where relop is (!=,==,>,>=,<,<=)
How would the following be represented as three address code format:
j = 0
while(j < 10 || j < 20)
{
System.out.println(i);
j++;
}
Here is my solution which is obviously incorrect:
main:
j = 1
sum = 0
L2:
if j < 10 || j < 20 goto L3
goto L4
L3:
mt2 = sum + 1
sum = mt2
mt3 = j + 1
j = mt3
goto L2
L4:
sum = 2
You break it down into two tests:
L2:
if j < 10 goto L3
if j < 20 goto L3
goto L4
L3:
(Did you mean j < 10 || j > 20? As written, the first test is redundant.)
In general, || and && are control flow operators and translate into individual branch instructions. Note that boolean not is often implemented by flipping labels.
Boolean operators are usually "short-circuiting" -- that is, the right-hand operation is not evaluated unless necessary -- precisely because of this translation style. Had the second computation been more complicated, it would have been done after the first if, which would lead to short-circuit behaviour.

Construct DFA for L = {(na(w)-nb(w)) mod 3>0}

As per the title:
L = {(na(w)-nb(w)) mod 3>0}
Alphabet = {a,b}
I found two answers to this problem:
In this solution, our language is accepted.
However,
w = b
is accepted as well.
In the next solution:
Our problem of
w = b
is solved here but
w = aaab
is not accepted.
How do I approach this problem? I couldn't find a suitable answer for it on the internet.
Assume we have the following definition of mod:
x mod y = { x, if 0 <= x < y
(x - y) mod y, if 0 < y <= x
x, if -y < x < 0
(x + y) mod y, if x <= -y < 0
-(-x mod -y) if y < 0
}
So our modulus works like this:
3 mod 5 = 3
6 mod 5 = 6-5 mod 5 = 1 mod 5 = 1
-3 mod 5 = -3
-6 mod 5 = -6+5 mod 5 = -1 mod 5 = -1
-6 mod -5 = -(6 mod 5) = -1
6 mod -5 = -(-6 mod 5) = -(-1) = 1
Our language is L = {(n_a(w) - n_b(w)) mod 3 > 0}
Let's define A := n_a(w) and B := n_b(w). So we need to solve (A - B) mod 3 > 0 using our definition of mod. We have five cases:
if 0 <= A - B < 3, meaning B <= A < B + 3, then (A - B) mod 3 = A - B. By hypothesis it is at least zero, and can only be zero then if A = B. We can confirm that when A = B we are always in case #1 and we always have (A - B) mod 3 > 0 false, so we can throw that possibility out.
if 0 < 3 <= A - B, meaning B < 3 + B <= A or simply A >= 3 + B, then (A - B) mod 3 = (A - B - 3) mod 3. By the hypothesis, A - B - 3 >= 3 + B - B - 3 >= 0, so we are still in either case 1 or 2. If we remain in case 2, we can repeat this until we eventually reach case 1, and we will see that we cannot have A - B - 3k = 0; that is, it cannot be that A = B + 3k for any positive k.
if -3 < A - B < 0, or B - 3 < A < B, then (A - B) mod 3 = A - B. By the hypothesis it is less than zero, and so we must throw out all of these possibilities.
if A - B <= -3 < 0, meaning A <= B - 3 < B or simply A <= B - 3 then (A - B) mod 3 = (A - B + 3) mod 3. By the hypothesis, A - B + 3 <= B - 3 - B + 3 = 0, so we are still in either case 3 or 4. If we remain in case 4, we can repeat this until we eventually reach case 3, and we will see nothing remains.
We cannot be in this case since 3 > 0.
We had to throw out the following strings from our language:
A = B
A = B + 3k
A < B.
So we keep only strings with more a's than b's where A - B is not divisible by 3. Suppose this language were regular. Consider the string (b^p)(a^(p+1)) in the language. By the pumping lemma, we should be able to pump the number of bs; but then we could get more bs than as. So the language cannot be regular.
If we take what is maybe a more usual definition for x mod y (not more correct, necessarily):
x mod y = { x , if 0 <= x < y
(x - y) , if 0 < y <= x
(x + y) mod y , if -y < x < 0
-(-x mod -y) , if y < 0
}
By this definition:
in case 1, we throw out A = B
in case 2, we throw out A = B + 3k
in case 3, we throw out A = B - 3k
since 3 > 0, case 4 doesn't apply
Now we have only thrown out the cases where A mod B = 0 (mod 3). This language is regular and has DFA:
+------------a-------------+
| |
| +---b----+ +---b----+ |
| | | | | |
V V | V | |
(q0)---a--->(q1)---a--->(q2)
--->(q0)
(q0)---b--->(q3)---b--->(q4)
^ ^ | ^ | |
| | | | | |
| +---a----+ +---a----+ |
| |
+------------b-------------+

How to get a single value from a cell-range by matching multiple columns and rows

I'm struggling with this one.
Here is data from 'sheet1':
|| A B C D E
=========================================
1 || C1 C2 X1 X2 X3
.........................................
2 || a b 1 2 3
3 || a d 10 11 12
4 || c d 4 5 6
5 || c f 13 14 15
6 || e f 7 8 9
7 || e b 16 17 18
Here's data in "sheet2":
|| A B C D
=================================
1 || C1 C2 C3 | val
.................................
2 || a d X2 | ?
3 || c f X1 | ?
4 || e b X3 | ?
Note that column C in sheet2 actually has values equal to user column names in sheet1.
I simply want to match A, B and C in sheet2 with A, B and 1 in sheet1 to find values in the last column:
|| A B C D
=================================
1 || C1 C2 C3 | val
.................................
2 || a d X2 | 11
3 || c f X1 | 13
4 || e b X3 | 18
I've been playing with OFFSET() and MATCH() but can't seem to lock down on one cell using multiple search criteria. Can someone help please?
I would use this function in sheet2 D2 field:
=index(filter(sheet1!C:E,sheet1!A:A=A2,sheet1!B:B=B2),1,match(C2,sheet1!$C$1:$E$1,0))
Explanation:
There is a FILTER function which will result the X1,X2,X3 values (C,D,E columns of sheet1) of the row which matches to the these two conditions:
C1 is "a"
C2 is "d"
So it will give back an array: [10,11,12] - which is the values of the X1, X2, X3 (C,D,E ) columns of sheet1 in the appropriate row.
Then, the INDEX function will grab this array. Now we only need to determine which value to pick. The MATCH function will do this computation as it tries to find the third condition C3 (which is in this case "X2) in the header row of sheet1. And in this example it will give back "2" as X2 is in the 2nd position of sheet1!c1:e1
So the INDEX function will give back the 2nd element of this array:[10,11,12], which is 11, the desired value.
Hope this helps.

Resources