This repository explores how symbolic regression can be used to discover and recover program patterns. Using array transformations as a case study, we demonstrate how programs can be represented as hypergraphs and analyzed to find reusable computational patterns.
This project demonstrates an exploratory approach to program synthesis using symbolic regression and hypergraph analysis. Key concepts include:
- Representing programs as hypergraphs
- Discovering common computational patterns
- Using symbolic regression for pattern recovery
- Composing discovered patterns into new programs
This research serves as an exploratory learning experience to understand:
- How programs can be represented as hypergraphs
- How symbolic regression might discover program patterns
- The feasibility of recovering program structure from compositions
- The role of abstraction in program synthesis
A test bed of simple array transformations that:
- Preserve input/output array size
- Perform local operations (shifts, comparisons)
- Can be composed in various ways
Available transformations:
shift_right/left: Circular array shiftslocal_max/min: Neighborhood operationsscale_up/down: Element-wise scalingthreshold: Mean-based thresholding
Tools for analyzing program structure:
- Convert AST to hypergraph representation
- Identify common computational patterns
- Find similar program structures
- Analyze function composition patterns
The analysis involves:
-
Program Representation
- Converting programs to hypergraphs
- Representing function compositions
- Identifying computational patterns
-
Pattern Discovery
- Finding common substructures
- Analyzing pattern frequency
- Understanding composition rules
-
Pattern Recovery
- Using symbolic regression to learn patterns
- Reconstructing program components
- Validating recovered patterns
python src/array_transforms.py \
--size 100 \
--length 8 \
--max-depth 6 \
--output dataset.jsonpython src/composition_analysis.py \
dataset.json \
--output analysis.json \
--viz patterns.png- Python 3.x
- Required packages:
- numpy: Array operations
- hypernetx: Hypergraph representation
- matplotlib: Visualization
- networkx: Graph analysis
- sympy: Symbolic mathematics
- PySR: Symbolic regression
# Create and activate conda environment
conda create -n symstrate python=3.9
conda activate symstrate
# Install required packages
pip install -r requirements.txtAreas for exploration:
- Additional array transformations
- More sophisticated pattern analysis
- Pattern visualization improvements
- Synthesis applications
This is an experimental exploration into program synthesis techniques. The methods demonstrated are meant to provoke thought and discussion about alternative approaches to program recovery and synthesis, rather than provide production-ready solutions.
[Add your chosen license here]