Linear.Quaternion:$c/ from linear-1.19.1.3, C

Percentage Accurate: 63.0% → 100.0%
Time: 4.2s
Alternatives: 3
Speedup: 5.0×

Specification

?
\[\begin{array}{l} t_0 := y \cdot y\\ \left(\left(x \cdot y + t_0\right) - y \cdot z\right) - t_0 \end{array} \]

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 3 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, 3.0× speedup?

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot y - y \cdot z} \]
    7. *-commutative98.4%

      \[\leadsto \color{blue}{y \cdot x} - y \cdot z \]
    8. distribute-lft-out--100.0%

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

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

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

Alternative 2: 78.2% accurate, 1.8× speedup?

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

    1. Initial program 66.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot y - y \cdot z} \]
      7. *-commutative97.6%

        \[\leadsto \color{blue}{y \cdot x} - y \cdot z \]
      8. distribute-lft-out--100.0%

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

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

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

    if -3.5e16 < x < 4.99999999999999954e-22

    1. Initial program 54.6%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot y - y \cdot z} \]
      7. *-commutative99.2%

        \[\leadsto \color{blue}{y \cdot x} - y \cdot z \]
      8. distribute-lft-out--100.0%

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

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

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

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

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

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

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

Alternative 3: 54.1% accurate, 5.0× speedup?

\[y \cdot x \]
Derivation
  1. Initial program 60.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot y - y \cdot z} \]
    7. *-commutative98.4%

      \[\leadsto \color{blue}{y \cdot x} - y \cdot z \]
    8. distribute-lft-out--100.0%

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

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

    \[\leadsto \color{blue}{y \cdot x} \]
  5. Final simplification52.7%

    \[\leadsto y \cdot x \]

Developer target: 100.0% accurate, 3.0× speedup?

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

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, C"
  :precision binary64

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

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