TorchLean API

FloatLib.Numerics.Reduction.Tree

Parenthesized reductions #

ReductionTree records a nonempty reduction without choosing an arithmetic implementation. Unlike mathlib's BinaryTree, values occur at leaves, not internal nodes. An empty reduction needs a separately chosen identity and is deliberately not represented here.

inductive FloatLib.Numerics.ReductionTree (α : Type u_1) :
Type u_1

A nonempty collection of inputs together with a binary evaluation schedule.

Instances For
    Instances For
      @[instance_reducible]
      instance FloatLib.Numerics.instReprReductionTree {α✝ : Type u_1} [Repr α✝] :
      @[instance_reducible]
      def FloatLib.Numerics.instDecidableEqReductionTree.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : ReductionTree α✝) :
      Decidable (x✝ = x✝¹)
      Instances For

        Input occurrences in left-to-right order, including repetitions.

        Instances For
          def FloatLib.Numerics.ReductionTree.eval {α : Type u_1} {β : Type u_2} (combine : βββ) (value : αβ) :
          ReductionTree αβ

          Evaluate the chosen schedule; the combining operation need not be associative.

          Instances For
            def FloatLib.Numerics.ReductionTree.map {α : Type u_1} {β : Type u_2} (f : αβ) :

            Change leaf values without changing the evaluation schedule.

            Instances For
              @[simp]
              theorem FloatLib.Numerics.ReductionTree.eval_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} (t : ReductionTree α) (f : αβ) (combine : γγγ) (value : βγ) :
              eval combine value (map f t) = eval combine (value f) t

              Mapping leaves commutes with evaluation.

              @[simp]
              theorem FloatLib.Numerics.ReductionTree.leaves_map {α : Type u_1} {β : Type u_2} (t : ReductionTree α) (f : αβ) :

              Mapping preserves the order and multiplicity of leaf occurrences.

              Number of combining operations in the schedule.

              Instances For

                A full binary reduction performs one fewer addition than it has inputs.

                A permutation of inputs cannot change the number of combining operations.

                def FloatLib.Numerics.ReductionTree.AllNodes {α : Type u_1} {β : Type u_2} (combine : βββ) (value : αβ) (p : ββProp) :

                A predicate on the two evaluated operands holds at every internal node of this tree.

                Instances For
                  theorem FloatLib.Numerics.ReductionTree.map_eval {α : Type u_1} {β : Type u_2} {γ : Type u_3} (t : ReductionTree α) (combine : βββ) (value : αβ) (interpret : βγ) (combine' : γγγ) (h : AllNodes combine value (fun (x y : β) => interpret (combine x y) = combine' (interpret x) (interpret y)) t) :
                  interpret (eval combine value t) = eval combine' (interpret value) t

                  Interpretation commutes with evaluation when it preserves the actual operations used.

                  theorem FloatLib.Numerics.ReductionTree.eval_add_eq_sum {α : Type u_1} {β : Type u_2} [AddMonoid β] (t : ReductionTree α) (value : αβ) :
                  eval (fun (x1 x2 : β) => x1 + x2) value t = (List.map value t.leaves).sum

                  Exact additive evaluation agrees with the ordinary list sum.

                  theorem FloatLib.Numerics.ReductionTree.eval_add_eq_of_perm {α : Type u_1} {β : Type u_2} [AddCommMonoid β] {a b : ReductionTree α} (h : a.leaves.Perm b.leaves) (value : αβ) :
                  eval (fun (x1 x2 : β) => x1 + x2) value a = eval (fun (x1 x2 : β) => x1 + x2) value b

                  Reordering leaves or changing parentheses preserves an exact commutative sum.