Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3

Percentage Accurate: 99.8% → 99.8%
Time: 7.6s
Alternatives: 8
Speedup: 207.0×

Specification

?
\[x \cdot \cos y + z \cdot \sin y \]

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 8 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: 99.8% accurate, 0.7× speedup?

\[\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right) \]
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y + z \cdot \sin y \]
  2. Step-by-step derivation
    1. fma-def99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)} \]
  4. Final simplification99.8%

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

Alternative 2: 99.8% accurate, 1.0× speedup?

\[z \cdot \sin y + x \cdot \cos y \]
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y + z \cdot \sin y \]
  2. Final simplification99.8%

    \[\leadsto z \cdot \sin y + x \cdot \cos y \]

Alternative 3: 85.3% accurate, 1.9× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{+17} \lor \neg \left(x \leq 8.5 \cdot 10^{-21}\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \sin y\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < -2.3e17 or 8.4999999999999993e-21 < x

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
      2. add-cube-cbrt99.3%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \sqrt[3]{\cos y}\right)} \cdot x + z \cdot \sin y \]
      3. associate-*l*99.2%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \left(\sqrt[3]{\cos y} \cdot x\right)} + z \cdot \sin y \]
      4. fma-def99.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
      5. pow299.2%

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\cos y}\right)}^{2}}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right) \]
    3. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\cos y}\right)}^{2}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
    4. Taylor expanded in x around inf 86.2%

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot \left(\cos y \cdot x\right)} \]
    5. Step-by-step derivation
      1. pow-base-186.2%

        \[\leadsto \color{blue}{1} \cdot \left(\cos y \cdot x\right) \]
      2. *-lft-identity86.2%

        \[\leadsto \color{blue}{\cos y \cdot x} \]
    6. Simplified86.2%

      \[\leadsto \color{blue}{\cos y \cdot x} \]

    if -2.3e17 < x < 8.4999999999999993e-21

    1. Initial program 99.7%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Taylor expanded in y around 0 92.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{+17} \lor \neg \left(x \leq 8.5 \cdot 10^{-21}\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \sin y\\ \end{array} \]

Alternative 4: 73.5% accurate, 1.9× speedup?

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

    1. Initial program 99.5%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Taylor expanded in x around 0 53.7%

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

    if -0.0071999999999999998 < y < 9.80000000000000047e-31

    1. Initial program 100.0%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Taylor expanded in y around 0 99.6%

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

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

Alternative 5: 73.6% accurate, 1.9× speedup?

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

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
      2. add-cube-cbrt99.3%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \sqrt[3]{\cos y}\right)} \cdot x + z \cdot \sin y \]
      3. associate-*l*99.2%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \left(\sqrt[3]{\cos y} \cdot x\right)} + z \cdot \sin y \]
      4. fma-def99.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
      5. pow299.2%

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\cos y}\right)}^{2}}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right) \]
    3. Applied egg-rr99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\cos y}\right)}^{2}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
    4. Taylor expanded in x around inf 85.2%

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot \left(\cos y \cdot x\right)} \]
    5. Step-by-step derivation
      1. pow-base-185.2%

        \[\leadsto \color{blue}{1} \cdot \left(\cos y \cdot x\right) \]
      2. *-lft-identity85.2%

        \[\leadsto \color{blue}{\cos y \cdot x} \]
    6. Simplified85.2%

      \[\leadsto \color{blue}{\cos y \cdot x} \]

    if -0.00115 < x < 1.8e-25

    1. Initial program 99.7%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Taylor expanded in x around 0 68.6%

      \[\leadsto \color{blue}{z \cdot \sin y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.00115 \lor \neg \left(x \leq 1.8 \cdot 10^{-25}\right):\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sin y\\ \end{array} \]

Alternative 6: 41.7% accurate, 29.1× speedup?

\[\begin{array}{l} \mathbf{if}\;z \leq -2.55 \cdot 10^{+122}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+139}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < -2.55e122 or 2.60000000000000022e139 < z

    1. Initial program 99.7%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Taylor expanded in y around 0 52.1%

      \[\leadsto \color{blue}{y \cdot z + x} \]
    3. Taylor expanded in y around inf 38.7%

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

    if -2.55e122 < z < 2.60000000000000022e139

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
      2. add-cube-cbrt99.4%

        \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \sqrt[3]{\cos y}\right)} \cdot x + z \cdot \sin y \]
      3. associate-*l*99.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \left(\sqrt[3]{\cos y} \cdot x\right)} + z \cdot \sin y \]
      4. fma-def99.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
      5. pow299.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\cos y}\right)}^{2}}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right) \]
    3. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\cos y}\right)}^{2}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
    4. Taylor expanded in y around 0 46.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.55 \cdot 10^{+122}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+139}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 7: 52.1% accurate, 41.4× speedup?

\[x + y \cdot z \]
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y + z \cdot \sin y \]
  2. Taylor expanded in y around 0 51.8%

    \[\leadsto \color{blue}{y \cdot z + x} \]
  3. Final simplification51.8%

    \[\leadsto x + y \cdot z \]

Alternative 8: 38.8% accurate, 207.0× speedup?

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

    \[x \cdot \cos y + z \cdot \sin y \]
  2. Step-by-step derivation
    1. *-commutative99.8%

      \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
    2. add-cube-cbrt99.4%

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \sqrt[3]{\cos y}\right)} \cdot x + z \cdot \sin y \]
    3. associate-*l*99.4%

      \[\leadsto \color{blue}{\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}\right) \cdot \left(\sqrt[3]{\cos y} \cdot x\right)} + z \cdot \sin y \]
    4. fma-def99.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\cos y} \cdot \sqrt[3]{\cos y}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
    5. pow299.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\cos y}\right)}^{2}}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right) \]
  3. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{\cos y}\right)}^{2}, \sqrt[3]{\cos y} \cdot x, z \cdot \sin y\right)} \]
  4. Taylor expanded in y around 0 38.6%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification38.6%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x y z)
  :name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
  :precision binary64
  (+ (* x (cos y)) (* z (sin y))))