Answer the question
In order to leave comments, you need to log in
Where can I find tasks to simplify logical expressions?
Well, in general, the subject - you need to develop skills to simplify logical expressions and I'm trying to find a problem book where there would be examples of solutions, tasks and answers to tasks (following the example of M.I. Skanavi), but only in Boolean algebra.
Answer the question
In order to leave comments, you need to log in
Let the horse develop skills for simplifying logical expressions, it has a big head)))
But since you are so impatient - here is the simulator:
from random import choice
def scheme(n, m):
"""
:param n: число входных аргументов, не более 26 (a..z)
:param m: число логических операций, фигачь сколько влезет
:return: строка с логическим выражением для упрощения
"""
l, s = list('abcdefghijklmnopqrstuvwxyz'[:n]), ''
while s.count('(') < m:
op = choice(('not', 'and', 'or', '^'))
s = f'(not {choice(l)})' if op == 'not' else f'({choice(l)} {op} {choice(l)})'
l.append(s)
return s
print(scheme(5, 10))
import re
from itertools import product
def check(task, solution):
"""
:param task: строка задачи
:param solution: строка решения
:return: эквивалентны ли они (bool)
"""
args = sorted(set(re.findall(r'\b[a-z]\b', task)))
chk = compile(f'({task})==({solution})', '<string>', 'eval')
return all(eval(chk, {}, dict(zip(args, bulls)))
for bulls in product((False, True), repeat=len(args)))
print(check('a and (b or not b)', 'a'))
print(check('a and (b or not b)', 'a ^ b'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question