Apply DAG-aware AND tree balancing to the network.
(balance aignet aignet2 config) → new-aignet2
Note: This implementation is heavily based on the one in ABC, developed and maintained at Berkeley by Alan Mishchenko.
Settings for the transform can be tweaked using the
Function:
(defun balance (aignet aignet2 config) (declare (xargs :stobjs (aignet aignet2))) (declare (xargs :guard (balance-config-p config))) (let ((__function__ 'balance)) (declare (ignorable __function__)) (b* (((local-stobjs aignet-tmp) (mv aignet2 aignet-tmp)) (- (cw "Balance input: ") (print-aignet-levels aignet)) (aignet-tmp (balance-core aignet aignet-tmp config)) (aignet2 (aignet-prune-comb aignet-tmp aignet2 (balance-config->gatesimp config))) (- (cw "Balance output: ") (print-aignet-levels aignet))) (mv aignet2 aignet-tmp))))
Theorem:
(defthm num-ins-of-balance (b* ((?new-aignet2 (balance aignet aignet2 config))) (equal (stype-count :pi new-aignet2) (stype-count :pi aignet))))
Theorem:
(defthm num-regs-of-balance (b* ((?new-aignet2 (balance aignet aignet2 config))) (equal (stype-count :reg new-aignet2) (stype-count :reg aignet))))
Theorem:
(defthm num-outs-of-balance (b* ((?new-aignet2 (balance aignet aignet2 config))) (equal (stype-count :po new-aignet2) (stype-count :po aignet))))
Theorem:
(defthm balance-comb-equivalent (b* ((?new-aignet2 (balance aignet aignet2 config))) (comb-equiv new-aignet2 aignet)))
Theorem:
(defthm normalize-input-of-balance (implies (syntaxp (not (equal aignet2 ''nil))) (equal (balance aignet aignet2 config) (balance aignet nil config))))
Theorem:
(defthm balance-of-balance-config-fix-config (equal (balance aignet aignet2 (balance-config-fix config)) (balance aignet aignet2 config)))
Theorem:
(defthm balance-balance-config-equiv-congruence-on-config (implies (balance-config-equiv config config-equiv) (equal (balance aignet aignet2 config) (balance aignet aignet2 config-equiv))) :rule-classes :congruence)