Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3

Percentage Accurate: 97.8% → 100.0%
Time: 3.4s
Alternatives: 6
Speedup: 9.0×

Specification

?
\[x \cdot y + z \cdot \left(1 - y\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 6 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: 100.0% accurate, 1.3× speedup?

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

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

      \[\leadsto \color{blue}{z \cdot \left(1 - y\right) + x \cdot y} \]
    2. sub-neg98.4%

      \[\leadsto z \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \cdot y \]
    3. distribute-rgt-in98.4%

      \[\leadsto \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)} + x \cdot y \]
    4. *-lft-identity98.4%

      \[\leadsto \left(\color{blue}{z} + \left(-y\right) \cdot z\right) + x \cdot y \]
    5. associate-+l+98.4%

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

      \[\leadsto \color{blue}{\left(\left(-y\right) \cdot z + x \cdot y\right) + z} \]
    7. *-commutative98.4%

      \[\leadsto \left(\color{blue}{z \cdot \left(-y\right)} + x \cdot y\right) + z \]
    8. neg-mul-198.4%

      \[\leadsto \left(z \cdot \color{blue}{\left(-1 \cdot y\right)} + x \cdot y\right) + z \]
    9. associate-*r*98.4%

      \[\leadsto \left(\color{blue}{\left(z \cdot -1\right) \cdot y} + x \cdot y\right) + z \]
    10. distribute-rgt-out100.0%

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

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

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

      \[\leadsto \mathsf{fma}\left(y, x + \color{blue}{-1 \cdot z}, z\right) \]
    14. neg-mul-1100.0%

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

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

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

    \[\leadsto \color{blue}{y \cdot \left(x - z\right) + z} \]
  5. Final simplification100.0%

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

Alternative 2: 60.9% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-79}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+133} \lor \neg \left(y \leq 2.4 \cdot 10^{+223}\right) \land y \leq 2.85 \cdot 10^{+277}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if y < -1 or 8.0000000000000002e133 < y < 2.40000000000000011e223 or 2.84999999999999984e277 < y

    1. Initial program 95.4%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot z + x\right)} \]
    3. Step-by-step derivation
      1. neg-mul-198.9%

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

        \[\leadsto y \cdot \color{blue}{\left(x + \left(-z\right)\right)} \]
      3. sub-neg98.9%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified98.9%

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

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

        \[\leadsto \color{blue}{-y \cdot z} \]
      2. distribute-rgt-neg-out62.7%

        \[\leadsto \color{blue}{y \cdot \left(-z\right)} \]
    7. Simplified62.7%

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

    if -1 < y < 3.90000000000000006e-79

    1. Initial program 100.0%

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

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

    if 3.90000000000000006e-79 < y < 8.0000000000000002e133 or 2.40000000000000011e223 < y < 2.84999999999999984e277

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-79}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+133} \lor \neg \left(y \leq 2.4 \cdot 10^{+223}\right) \land y \leq 2.85 \cdot 10^{+277}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]

Alternative 3: 84.6% accurate, 1.0× speedup?

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

    1. Initial program 97.2%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot z + x\right)} \]
    3. Step-by-step derivation
      1. neg-mul-194.0%

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

        \[\leadsto y \cdot \color{blue}{\left(x + \left(-z\right)\right)} \]
      3. sub-neg94.0%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified94.0%

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

    if -1.19999999999999997e-15 < y < 1.6e-77

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.6%

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

Alternative 4: 99.0% accurate, 1.0× speedup?

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

    1. Initial program 96.9%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot z + x\right)} \]
    3. Step-by-step derivation
      1. neg-mul-198.8%

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

        \[\leadsto y \cdot \color{blue}{\left(x + \left(-z\right)\right)} \]
      3. sub-neg98.8%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified98.8%

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

    if -1 < y < 1

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-y\right) \cdot z + x \cdot y\right) + z} \]
      7. *-commutative100.0%

        \[\leadsto \left(\color{blue}{z \cdot \left(-y\right)} + x \cdot y\right) + z \]
      8. neg-mul-1100.0%

        \[\leadsto \left(z \cdot \color{blue}{\left(-1 \cdot y\right)} + x \cdot y\right) + z \]
      9. associate-*r*100.0%

        \[\leadsto \left(\color{blue}{\left(z \cdot -1\right) \cdot y} + x \cdot y\right) + z \]
      10. distribute-rgt-out100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(y, x + \color{blue}{-1 \cdot z}, z\right) \]
      14. neg-mul-1100.0%

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

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

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

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

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

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

Alternative 5: 61.3% accurate, 1.3× speedup?

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

    1. Initial program 97.2%

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

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

    if -1.95000000000000002e-13 < y < 1.8e-77

    1. Initial program 100.0%

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

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

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

Alternative 6: 36.2% accurate, 9.0× speedup?

\[z \]
Derivation
  1. Initial program 98.4%

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

    \[\leadsto \color{blue}{z} \]
  3. Final simplification36.3%

    \[\leadsto z \]

Developer target: 100.0% accurate, 1.3× speedup?

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

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (- z (* (- z x) y))

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