September 8, 2025
Takes two programs as strings and returns yes if it finds there equivalent no otherwise
def standardize_naming(source: ast) -> ast.AST:
"""
Standardizes all variable, function, and class names in the AST to numbered placeholders.
This helps ignore differences in naming conventions when comparing program structure.
"""
used_name = {} # Maps original names to standardized numbered names
name_id = 1 # Counter for generating new names
# Walk through all nodes in the AST
for node in ast.walk(source):
# Standardize variable names
if isinstance(node, ast.Name):
if node.id in used_name:
node.id = used_name[node.id]
else:
name_id += 1
used_name[node.id] = str(name_id)
node.id = str(name_id)
# Standardize function and class names
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
if node.name in used_name:
node.name = used_name[node.name]
else:
name_id += 1
used_name[node.name] = str(name_id)
node.name = str(name_id)
# Standardize function argument names
if isinstance(node, ast.arg):
if node.arg in used_name:
node.arg = used_name[node.arg]
else:
name_id += 1
used_name[node.arg] = str(name_id)
node.arg = str(name_id)
return source
detect_equivalence
works by running both programs on the same input and checking if they both produce the same output or fail in the same way.Proofgrammers