Complete guide for using Jupyter notebooks with the Nice Connectives project.
# Navigate to project root
cd nice_connectives
# Option 1: Install with optional dependencies (recommended)
pip install -e ".[jupyter]"
# Option 2: Install from requirements file
cd notebooks/
pip install -r requirements.txt
# Verify installation
python -c "import jupyter, matplotlib, pandas; print('✓ Jupyter dependencies installed')"jupyter>=1.0.0- Jupyter notebook serveripykernel>=6.0.0- IPython kernelmatplotlib>=3.5.0- Plotting and visualizationpandas>=2.0.0- DataFrames for tabular data
# Navigate to notebooks directory
cd notebooks/
# Launch Jupyter notebook
jupyter notebook
# Your browser will open to http://localhost:8888-
Start with 00_setup_and_basics.ipynb
- Verifies your installation
- Introduces basic concepts
- Shows first examples
-
Follow the learning path
- See notebooks/README.md for learning paths
- Beginner path: notebooks 00-02 (~50 min)
- Complete path: notebooks 00-06 (~3 hours)
-
Run cells in order
- Use Shift+Enter to run cells
- Earlier cells set up variables for later cells
All notebooks include automatic path setup - no manual configuration needed!
Each notebook starts with a path setup cell that automatically adds the project root to Python's path:
# Setup Python path to find the src module
import sys
from pathlib import Path
# Add project root to Python path
project_root = Path.cwd().parent
if str(project_root) not in sys.path:
sys.path.insert(0, str(project_root))
print(f"✓ Project root added to path: {project_root}")Simply run this cell first, then imports from src will work correctly.
Basic Navigation:
Shift + Enter- Run current cell and move to nextCtrl + Enter- Run current cell and stayAlt + Enter- Run current cell and insert new cell below
Kernel Operations:
Kernel → Restart- Restart Python kernel (clears all variables)Kernel → Restart & Run All- Fresh start, run all cellsKernel → Interrupt- Stop a long-running cell
Notebooks use matplotlib for visualizations:
import matplotlib.pyplot as plt
%matplotlib inline # Display plots inline
# Create visualization
from notebooks.utils import visualize_truth_table
from src.constants import AND
fig = visualize_truth_table(AND)
plt.show()Feel free to modify and experiment!
# Original example
from src.constants import AND, OR, XOR
from notebooks.utils import compare_connectives
fig = compare_connectives([AND, OR, XOR])
plt.show()
# Your modification - try different connectives!
from src.constants import NAND, NOR, EQUIV
fig = compare_connectives([NAND, NOR, EQUIV])
plt.show()Topics: Installation check, first connective, visualization Time: 10 minutes Prerequisites: None
Topics: Arity, truth tables, binary connectives Time: 20 minutes Prerequisites: Notebook 00
Topics: BitVec encoding, row indexing, ternary connectives Time: 20 minutes Prerequisites: Notebook 01
Topics: Post's theorem, completeness checking Time: 30 minutes Prerequisites: Notebooks 00-02
Topics: Pattern enumeration, nice sets Time: 30 minutes Prerequisites: Notebooks 00-03
Topics: Enumeration search, max=3 result Time: 30 minutes Prerequisites: Notebooks 00-04
Topics: Z3 search, size-17+, current research Time: 30 minutes Prerequisites: Notebooks 00-05
from src.constants import AND, XOR, TRUE
from src.post_classes import is_complete
from src.independence import is_independent
my_set = [AND, XOR, TRUE]
# Check completeness
complete = is_complete(my_set)
print(f\"Complete: {complete}\")
# Check independence
independent = is_independent(my_set, max_depth=3)
print(f\"Independent: {independent}\")
# Nice set?
if complete and independent:
print(\"✓ This is a nice set!\")from src.connectives import Connective
from notebooks.utils import visualize_truth_table
import matplotlib.pyplot as plt
# Create custom connective
# Truth table value 150 = ternary majority
my_conn = Connective(3, 150)
# Visualize
fig = visualize_truth_table(my_conn, title=\"My Custom Connective\")
plt.show()# Binary-only search (fast)
from src.constants import ALL_BINARY
from src.search import search_nice_sets_enumeration
nice_sets = search_nice_sets_enumeration(
ALL_BINARY,
target_size=3,
max_depth=3
)
print(f\"Found {len(nice_sets)} nice sets of size 3\")
# Show first result
if nice_sets:
from notebooks.utils import print_nice_set_summary
print_nice_set_summary(nice_sets[0], \"Example Nice Set\")ModuleNotFoundError: No module named 'pandas'
Solution: Install Jupyter dependencies
pip install -e \".[jupyter]\"Problem 2: Cannot import from src
ModuleNotFoundError: No module named 'src'
Solution: Run the path setup cell (first code cell in each notebook)
- All notebooks include automatic path setup
- Simply run the first cell that starts with
# Setup Python path - This adds the project root to Python's path
Symptoms: Cells won't run, "Kernel busy" forever
Solution: Restart kernel
- Click
Kernel → Restartin menu - Re-run cells from the top
Symptoms: Plots don't appear
Solution: Check matplotlib inline mode
%matplotlib inline
import matplotlib.pyplot as pltSymptoms: Searches take very long
Solutions:
- Use smaller target sizes for learning (size 17 instead of 30)
- Use CLI for large searches (
python -m src.cli prove z3) - Increase max_candidates only if needed
Symptoms: Previous cell outputs disappeared
Cause: Notebooks are stored without output (nbstripout)
Solution: Normal! Just run cells again
| Search Type | Size | Time | Notebook |
|---|---|---|---|
| Binary enumeration | 3 | <1 second | 05 |
| Binary enumeration | 4 | ~10 seconds | 05 |
| Z3 ternary | 17 | ~1-2 seconds | 06 |
| Z3 ternary | 30 | ~4 minutes | 06 |
| Z3 ternary | 35 | ~46 minutes | CLI only |
For large searches (size 30+), use the CLI instead:
# Exit Jupyter and use CLI
cd ..
python -m src.cli prove z3 --target-size 30 --max-depth 3
# See results
cat examples/z3_nice_set_30.mdfrom src.connectives import Connective
# Create custom pool (only specific ternary connectives)
my_ternary = [Connective(3, i) for i in [19, 23, 150, 232, 247]]
# Add binary connectives
from src.constants import AND, OR, XOR
my_pool = [AND, OR, XOR] + my_ternary
# Search in custom pool
from src.independence import is_independent
from src.post_classes import is_complete
if is_complete(my_pool) and is_independent(my_pool, max_depth=3):
print(\"Nice set!\")# Save truth table to CSV
import pandas as pd
from notebooks.utils import display_truth_table
from src.constants import AND
df = display_truth_table(AND)
df.to_csv(\"and_truth_table.csv\", index=False)
# Save visualization
from notebooks.utils import visualize_truth_table
import matplotlib.pyplot as plt
fig = visualize_truth_table(AND)
fig.savefig(\"and_visualization.png\", dpi=300, bbox_inches='tight')
plt.close()- Notebooks README - Notebook overview and learning paths
- Usage Guide - CLI commands
- Installation Guide - Setup instructions
- Claude Code Guide - AI assistance
- Project README - Project overview
- Launch Jupyter:
cd notebooks/ && jupyter notebook - Start with notebook 00: Setup and basics
- Follow a learning path: See notebooks/README.md
- Experiment: Modify examples and explore
- Share findings: Contribute back to the project!
Happy exploring!