Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B

Percentage Accurate: 100.0% → 100.0%
Time: 3.0s
Alternatives: 7
Speedup: TODO×

Specification

?
\[x + \left(y - x\right) \cdot z \]

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Alternative 1?

\[\mathsf{fma}\left(y - x, z, x\right) \]
Derivation
  1. Initial program 100.0%

    \[x + \left(y - x\right) \cdot z \]
  2. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z + x} \]
    2. fma-def100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, z, x\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, z, x\right)} \]
  4. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(y - x, z, x\right) \]

Alternative 2?

\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+62}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-77}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+274}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if z < -3.6999999999999997e151 or -4.49999999999999999e62 < z < -2.8e16 or 3.19999999999999983e274 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around inf 100.0%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z} \]
    3. Taylor expanded in y around 0 76.1%

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot x\right)} \]
    4. Step-by-step derivation
      1. mul-1-neg76.1%

        \[\leadsto \color{blue}{-z \cdot x} \]
      2. distribute-rgt-neg-out76.1%

        \[\leadsto \color{blue}{z \cdot \left(-x\right)} \]
    5. Simplified76.1%

      \[\leadsto \color{blue}{z \cdot \left(-x\right)} \]

    if -3.6999999999999997e151 < z < -4.49999999999999999e62 or -2.8e16 < z < -1.4499999999999999e-77 or 1.84999999999999991e-5 < z < 3.19999999999999983e274

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around inf 89.8%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z} \]
    3. Taylor expanded in y around inf 63.9%

      \[\leadsto \color{blue}{y \cdot z} \]
    4. Step-by-step derivation
      1. *-commutative63.9%

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Simplified63.9%

      \[\leadsto \color{blue}{z \cdot y} \]

    if -1.4499999999999999e-77 < z < 1.84999999999999991e-5

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around 0 82.6%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification74.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{+151}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+62}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{+16}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-77}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+274}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \end{array} \]

Alternative 3?

\[\begin{array}{l} \mathbf{if}\;z \leq -7.6 \cdot 10^{-77} \lor \neg \left(z \leq 0.00042\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < -7.5999999999999998e-77 or 4.2000000000000002e-4 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around inf 92.8%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z} \]

    if -7.5999999999999998e-77 < z < 4.2000000000000002e-4

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around 0 82.6%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.6 \cdot 10^{-77} \lor \neg \left(z \leq 0.00042\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4?

\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < -1 or 1 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around inf 98.7%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z} \]

    if -1 < z < 1

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in y around inf 98.6%

      \[\leadsto x + \color{blue}{y \cdot z} \]
    3. Step-by-step derivation
      1. *-commutative24.8%

        \[\leadsto \color{blue}{z \cdot y} \]
    4. Simplified98.6%

      \[\leadsto x + \color{blue}{z \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]

Alternative 5?

\[\begin{array}{l} \mathbf{if}\;z \leq -8.8 \cdot 10^{-77}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < -8.80000000000000028e-77 or 2.00000000000000016e-5 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around inf 92.8%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z} \]
    3. Taylor expanded in y around inf 54.2%

      \[\leadsto \color{blue}{y \cdot z} \]
    4. Step-by-step derivation
      1. *-commutative54.2%

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Simplified54.2%

      \[\leadsto \color{blue}{z \cdot y} \]

    if -8.80000000000000028e-77 < z < 2.00000000000000016e-5

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Taylor expanded in z around 0 82.6%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8.8 \cdot 10^{-77}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 6?

\[x + \left(y - x\right) \cdot z \]
Derivation
  1. Initial program 100.0%

    \[x + \left(y - x\right) \cdot z \]
  2. Final simplification100.0%

    \[\leadsto x + \left(y - x\right) \cdot z \]

Alternative 7?

\[x \]
Derivation
  1. Initial program 100.0%

    \[x + \left(y - x\right) \cdot z \]
  2. Taylor expanded in z around 0 42.1%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification42.1%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x y z)
  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
  :precision binary64
  (+ x (* (- y x) z)))