Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Discrete Mathematics

Lab 1. March 14, 2013

Understanding logical operations

Lets say we have the following code (Matlab): W = 1024; x = -W/2:1:W/2; xmat = meshgrid(x); ymat = xmat; R = sqrt(xmat.^2+ymat.^2); %filter it out! filter = (xmat > 0 & R > 100); imshow(filter) This will produce the following image: Using this code as a base, modify it to

Figure 1: The image produced by default render the images in the gure 2. In case you are using a dierent programming language, I would recommend using a .ppm format for the output.

Figure 2: The images that you need to obtain

XOR

Create a program that would ask for two boolean values (true or false, 0 or 1) and would output the result fo the XOR operation performed on them. Use only And, Or and Not operations.

Truth Tables

Write a program that would compute the truth table for a simple boolean expression (no parantheses, only + and *). It should take a string as an input and output a set of strings containing the truth table. For example: Input: a + b * c Note that the input will always be correct - no variables will be repeated and the operations will always be isolated with spaces. Output: | a | b | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | | | | | | | | | c 0 1 0 1 0 1 0 1 | | | | | | | | | a + b * c | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |

Hint: One of the ways to solve this is use a tree structure. You might look into the concept of an Abstract Syntax tree for that. When youre done, congratulations, youve just built your rst parser!

You might also like