Feedback on Assignment 1: BDDs
Set your git name and email correctly
berkayc, denizarberk, francesca.albio, juliaoli, anasistac, cosimo-radler, TomUng, Petra.Kocsis, zsofia.sandor, MariaGeorgescu ssouppeyy, Māra, mara, Ytse, juliedeboer, mayairemozbayoglu, MafaldaCandal, han, memet Barbara_Plebanowicz
Use one single git name and email
5 Ana Sistac Plaza 2 Ana Sistac 1 anasistac 6 Leon Wloch 1 Leonard Wloch
melledoucet@sp-byods-145-109-3-187.wireless.uva.nl melledoucet@sp-byods-145-109-7-102.wireless.uva.nl melledoucet@Melles-MacBook-Pro-2.local elifkozan@sp-byods-145-109-15-177.wireless.uva.nl elifkozan@sp-byods-145-109-16-90.wireless.uva.nl leticiadupleich@sp-byods-145-109-28-214.wireless.uva.nl leticiadupleich@MacBook-Pro-de-admin.local jonathancowley@Jonathans-MacBook-Air.local jonathancowley@sp-byods-145-109-37-160.wireless.uva.nl jonathancowley@sp-byods-145-109-33-249.wireless.uva.nl
Make your scripts executable
chmod +x simplify_truth_table.py
- Don't copy, import. "
read_truth_tablefunction is copied to this file fromsimplify_truth_table.py" I'm not a fan of end-of-line comments. Better put them on the line before. Otherwise things can get very cluttered. In any case it's often better to write your code so that it speaks for itself and doesn't need the comment.
if len(line) > 5: # Makes sure we don't get parse the None line pass # Makes sure we don't get parse the None line if len(line) > 5: pass
Comprehension
def combine_terms(term1, term2): combined = [] for a, b in zip(term1, term2): if a == b: combined.append(a) else: combined.append(None) return combined def combine_terms(term1, term2): return [a if a == b else None for a, b in zip(term1, term2)]
Refactor where possible
def read_and_print_truth_table(): """Reads a truth table from a file and prints it.""" with open("truth_table.txt", "r") as f: lines = f.readlines() for line in lines: print(line, end="") def read_and_print_truth_table(): """Reads a truth table from a file and prints it.""" with open("truth_table.txt", "r") as f: for line in f.readlines(): print(line, end="")
Only import what you need
import numpy as np
- Limit lines to < 80 chars. Also comments.
When you read a line and then write it, Python keeps the newline at the end of the line it read and also adds a newline after printing it. That might not be what you want.
with open("file.txt") as inf: for line in inf.readlines(): print(line) with open("file.txt") as inf: for line in inf.readlines(): print(line[:-1]) with open("file.txt") as inf: for line in inf.readlines(): print(line, end="")
- Python functions should use snake case, not PascalCase, i.el
get_val, notGetVal - Let the names of variables say a little more about what they carry. Not
just
term1,term2,new_term. With better names your code can become "self-documenting" Do not print excessive output. It makes it more difficult to pipe
$ python ./decision_table.py | python ./optimize_truth_table_bdd.py Not(Or(And(a, ~b), And(a, c))) This is the best variable ordering resulting in the smallest bdd ['a', 'b', 'c']
- Commit message: "Jill on Jack's laptop" Commit your own work under your own name. (Group grades and individual grades.)
- Learn how to make long commit messages with Emacs, vim, or whatever code editor you use.
- Recommendations for Git Commit Messages
Use docstrings, not this
######################################################## ## Function to order the BDD based on the given order ## ######################################################## def order_bdd(expression, order):
- Be careful of superfluous whitespace in your code files. It can mess up your git diffs.
Write information-carrying commit messages.
a412 * Update optimize_truth_table.py 246b * Update optimize_truth_table.py c9c2 * Update optimizing_truth_table.py 593f * Update simplify_truth_table.py e71b * Update optimizing_truth_table.py e177 * Update not_working_pyeda_version.py 9a96 * Update optimizing_truth_table.py 7092 * Update optimizing_without_pyeda.py 6621 * Update optimizing_without_pyeda.py 4883 * Update optimizing_without_pyeda.py 1c97 * Update optimizing_without_pyeda.py