System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2

Percentage Accurate: 99.9% → 99.6%
Time: 9.0s
Alternatives: 7
Speedup: TODO×

Specification

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

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.

Target

Original99.9%
Target99.8%
Herbie99.6%
\[\left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right) \]

Alternative 1?

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

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Step-by-step derivation
    1. distribute-lft-in99.9%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
  3. Applied egg-rr99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
  4. Final simplification99.9%

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

Alternative 2?

\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+63} \lor \neg \left(y \leq 4.6 \cdot 10^{+25}\right):\\ \;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if y < -5.7999999999999999e63 or 4.5999999999999996e25 < y

    1. Initial program 99.8%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. sub-neg99.8%

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+99.8%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-lft-in99.7%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot 1 + y \cdot \left(\left(-z\right) + \log z\right)\right)} \]
      4. *-rgt-identity99.7%

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + y \cdot \left(\left(-z\right) + \log z\right)\right) \]
      5. associate-+r+99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 + y\right) + y \cdot \left(\left(-z\right) + \log z\right)} \]
      6. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} + y \cdot \left(\left(-z\right) + \log z\right) \]
      7. +-commutative99.7%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) + y \cdot \color{blue}{\left(\log z + \left(-z\right)\right)} \]
      8. unsub-neg99.7%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) + y \cdot \color{blue}{\left(\log z - z\right)} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right) + y \cdot \left(\log z - z\right)} \]
    4. Taylor expanded in x around 0 89.8%

      \[\leadsto \color{blue}{y + y \cdot \left(\log z - z\right)} \]
    5. Step-by-step derivation
      1. *-commutative89.8%

        \[\leadsto y + \color{blue}{\left(\log z - z\right) \cdot y} \]
      2. distribute-rgt1-in89.9%

        \[\leadsto \color{blue}{\left(\left(\log z - z\right) + 1\right) \cdot y} \]
      3. associate-+l-89.9%

        \[\leadsto \color{blue}{\left(\log z - \left(z - 1\right)\right)} \cdot y \]
    6. Applied egg-rr89.9%

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

    if -5.7999999999999999e63 < y < 4.5999999999999996e25

    1. Initial program 99.9%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
    3. Applied egg-rr100.0%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
    4. Taylor expanded in z around inf 90.3%

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    5. Step-by-step derivation
      1. associate-*r*90.3%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-190.3%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right)} \cdot z \]
    6. Simplified90.3%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out90.3%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y \cdot z\right)} \]
      2. unsub-neg90.3%

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
    8. Applied egg-rr90.3%

      \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+63} \lor \neg \left(y \leq 4.6 \cdot 10^{+25}\right):\\ \;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5 - y \cdot z\\ \end{array} \]

Alternative 3?

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

    1. Initial program 99.8%

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

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(1 + \log z\right) \cdot y} \]
    3. Step-by-step derivation
      1. *-commutative97.6%

        \[\leadsto x \cdot 0.5 + \color{blue}{y \cdot \left(1 + \log z\right)} \]
      2. distribute-lft-in97.6%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot 1 + y \cdot \log z\right)} \]
      3. *-rgt-identity97.6%

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + y \cdot \log z\right) \]
    4. Simplified97.6%

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

    if 0.28000000000000003 < z

    1. Initial program 99.9%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Step-by-step derivation
      1. distribute-lft-in99.9%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
    3. Applied egg-rr99.9%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
    4. Taylor expanded in z around inf 98.0%

      \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    5. Step-by-step derivation
      1. associate-*r*98.0%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. neg-mul-198.0%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right)} \cdot z \]
    6. Simplified98.0%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out98.0%

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

        \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
    8. Applied egg-rr98.0%

      \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.8%

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

Alternative 4?

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

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Final simplification99.9%

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

Alternative 5?

\[x \cdot 0.5 - y \cdot z \]
Derivation
  1. Initial program 99.9%

    \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
  2. Step-by-step derivation
    1. distribute-lft-in99.9%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
  3. Applied egg-rr99.9%

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot \left(1 - z\right) + y \cdot \log z\right)} \]
  4. Taylor expanded in z around inf 77.3%

    \[\leadsto x \cdot 0.5 + \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
  5. Step-by-step derivation
    1. associate-*r*77.3%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
    2. neg-mul-177.3%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right)} \cdot z \]
  6. Simplified77.3%

    \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y\right) \cdot z} \]
  7. Step-by-step derivation
    1. distribute-lft-neg-out77.3%

      \[\leadsto x \cdot 0.5 + \color{blue}{\left(-y \cdot z\right)} \]
    2. unsub-neg77.3%

      \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
  8. Applied egg-rr77.3%

    \[\leadsto \color{blue}{x \cdot 0.5 - y \cdot z} \]
  9. Final simplification77.3%

    \[\leadsto x \cdot 0.5 - y \cdot z \]

Alternative 6?

\[\begin{array}{l} \mathbf{if}\;z \leq 5.2 \cdot 10^{+16}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < 5.2e16

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{0.5 \cdot x} \]

    if 5.2e16 < z

    1. Initial program 100.0%

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

        \[\leadsto x \cdot 0.5 + y \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} + \log z\right) \]
      2. associate-+l+100.0%

        \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(1 + \left(\left(-z\right) + \log z\right)\right)} \]
      3. distribute-lft-in100.0%

        \[\leadsto x \cdot 0.5 + \color{blue}{\left(y \cdot 1 + y \cdot \left(\left(-z\right) + \log z\right)\right)} \]
      4. *-rgt-identity100.0%

        \[\leadsto x \cdot 0.5 + \left(\color{blue}{y} + y \cdot \left(\left(-z\right) + \log z\right)\right) \]
      5. associate-+r+100.0%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right)} + y \cdot \left(\left(-z\right) + \log z\right) \]
      7. +-commutative100.0%

        \[\leadsto \mathsf{fma}\left(x, 0.5, y\right) + y \cdot \color{blue}{\left(\log z + \left(-z\right)\right)} \]
      8. unsub-neg100.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, y\right) + y \cdot \left(\log z - z\right)} \]
    4. Taylor expanded in y around -inf 75.1%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(-1 \cdot \left(\log z - z\right) - 1\right)\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg75.1%

        \[\leadsto \color{blue}{-y \cdot \left(-1 \cdot \left(\log z - z\right) - 1\right)} \]
      2. distribute-rgt-neg-in75.1%

        \[\leadsto \color{blue}{y \cdot \left(-\left(-1 \cdot \left(\log z - z\right) - 1\right)\right)} \]
      3. sub-neg75.1%

        \[\leadsto y \cdot \left(-\color{blue}{\left(-1 \cdot \left(\log z - z\right) + \left(-1\right)\right)}\right) \]
      4. mul-1-neg75.1%

        \[\leadsto y \cdot \left(-\left(\color{blue}{\left(-\left(\log z - z\right)\right)} + \left(-1\right)\right)\right) \]
      5. sub-neg75.1%

        \[\leadsto y \cdot \left(-\left(\left(-\color{blue}{\left(\log z + \left(-z\right)\right)}\right) + \left(-1\right)\right)\right) \]
      6. +-commutative75.1%

        \[\leadsto y \cdot \left(-\left(\left(-\color{blue}{\left(\left(-z\right) + \log z\right)}\right) + \left(-1\right)\right)\right) \]
      7. distribute-neg-in75.1%

        \[\leadsto y \cdot \left(-\left(\color{blue}{\left(\left(-\left(-z\right)\right) + \left(-\log z\right)\right)} + \left(-1\right)\right)\right) \]
      8. remove-double-neg75.1%

        \[\leadsto y \cdot \left(-\left(\left(\color{blue}{z} + \left(-\log z\right)\right) + \left(-1\right)\right)\right) \]
      9. sub-neg75.1%

        \[\leadsto y \cdot \left(-\left(\color{blue}{\left(z - \log z\right)} + \left(-1\right)\right)\right) \]
      10. metadata-eval75.1%

        \[\leadsto y \cdot \left(-\left(\left(z - \log z\right) + \color{blue}{-1}\right)\right) \]
      11. +-commutative75.1%

        \[\leadsto y \cdot \left(-\color{blue}{\left(-1 + \left(z - \log z\right)\right)}\right) \]
    6. Simplified75.1%

      \[\leadsto \color{blue}{y \cdot \left(-\left(-1 + \left(z - \log z\right)\right)\right)} \]
    7. Taylor expanded in z around inf 75.1%

      \[\leadsto y \cdot \left(-\color{blue}{z}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 5.2 \cdot 10^{+16}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]

Alternative 7?

\[x \cdot 0.5 \]
Derivation
  1. Initial program 99.9%

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

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  3. Final simplification41.2%

    \[\leadsto x \cdot 0.5 \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x y z)
  :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
  :precision binary64

  :herbie-target
  (- (+ y (* 0.5 x)) (* y (- z (log z))))

  (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))