feat: progress
This commit is contained in:
@@ -40,16 +40,6 @@ func isViable(e *Expression) (*Abstraction, Expression, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// betaReduce performs a single beta reduction step.
|
||||
// Given (\. body) arg, it substitutes arg for index 0 in body,
|
||||
// then shifts the result down to account for the removed abstraction.
|
||||
func betaReduce(fn *Abstraction, arg Expression) Expression {
|
||||
// Substitute arg for variable 0 in the body.
|
||||
substituted := Substitute(fn.body, 0, Shift(arg, 1, 0))
|
||||
// Shift down to account for the removed abstraction.
|
||||
return Shift(substituted, -1, 0)
|
||||
}
|
||||
|
||||
// Reduce performs normal order reduction on a De Bruijn expression.
|
||||
func (r *NormalOrderReducer) Reduce() {
|
||||
r.Emit(reducer.StartEvent)
|
||||
@@ -59,7 +49,11 @@ func (r *NormalOrderReducer) Reduce() {
|
||||
if fn, arg, ok := isViable(it.Current()); !ok {
|
||||
it.Next()
|
||||
} else {
|
||||
it.Swap(betaReduce(fn, arg))
|
||||
// Substitute arg for variable 0 in the body.
|
||||
substituted := Substitute(fn.body, 0, Shift(arg, 1, 0))
|
||||
// Shift down to account for the removed abstraction.
|
||||
it.Swap(Shift(substituted, -1, 0))
|
||||
|
||||
r.Emit(reducer.StepEvent)
|
||||
|
||||
if _, _, ok := isViable(it.Parent()); ok {
|
||||
|
||||
Reference in New Issue
Block a user