Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1

Percentage Accurate: 97.7% → 97.7%
Time: 6.1s
Alternatives: 7
Speedup: 9.0×

Specification

?
\[\frac{x}{y} \cdot \left(z - t\right) + t \]

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.

Alternative 1: 97.7% accurate, 1.0× speedup?

\[t + \left(z - t\right) \cdot \frac{x}{y} \]
Derivation
  1. Initial program 98.3%

    \[\frac{x}{y} \cdot \left(z - t\right) + t \]
  2. Step-by-step derivation
    1. *-commutative98.3%

      \[\leadsto \color{blue}{\left(z - t\right) \cdot \frac{x}{y}} + t \]
    2. clear-num98.3%

      \[\leadsto \left(z - t\right) \cdot \color{blue}{\frac{1}{\frac{y}{x}}} + t \]
    3. un-div-inv98.3%

      \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
  3. Applied egg-rr98.3%

    \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
  4. Taylor expanded in z around 0 88.1%

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

      \[\leadsto \left(\color{blue}{z \cdot \frac{x}{y}} + -1 \cdot \frac{t \cdot x}{y}\right) + t \]
    2. associate-*r/91.3%

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

      \[\leadsto \left(z \cdot \frac{x}{y} + \color{blue}{\left(-1 \cdot t\right) \cdot \frac{x}{y}}\right) + t \]
    4. neg-mul-191.3%

      \[\leadsto \left(z \cdot \frac{x}{y} + \color{blue}{\left(-t\right)} \cdot \frac{x}{y}\right) + t \]
    5. cancel-sign-sub-inv91.3%

      \[\leadsto \color{blue}{\left(z \cdot \frac{x}{y} - t \cdot \frac{x}{y}\right)} + t \]
    6. distribute-rgt-out--98.3%

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

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

    \[\leadsto \color{blue}{\left(z - t\right) \cdot \frac{x}{y}} + t \]
  7. Final simplification98.3%

    \[\leadsto t + \left(z - t\right) \cdot \frac{x}{y} \]

Alternative 2: 95.4% accurate, 0.5× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -40000000 \lor \neg \left(\frac{x}{y} \leq 10^{-12}\right):\\ \;\;\;\;t + x \cdot \frac{z - t}{y}\\ \mathbf{else}:\\ \;\;\;\;t + z \cdot \frac{x}{y}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 x y) < -4e7 or 9.9999999999999998e-13 < (/.f64 x y)

    1. Initial program 97.6%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in x around 0 92.6%

      \[\leadsto \color{blue}{\frac{\left(z - t\right) \cdot x}{y}} + t \]
    3. Step-by-step derivation
      1. associate-*l/92.6%

        \[\leadsto \color{blue}{\frac{z - t}{y} \cdot x} + t \]
      2. *-commutative92.6%

        \[\leadsto \color{blue}{x \cdot \frac{z - t}{y}} + t \]
    4. Simplified92.6%

      \[\leadsto \color{blue}{x \cdot \frac{z - t}{y}} + t \]

    if -4e7 < (/.f64 x y) < 9.9999999999999998e-13

    1. Initial program 99.1%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in z around inf 93.5%

      \[\leadsto \color{blue}{\frac{z \cdot x}{y}} + t \]
    3. Step-by-step derivation
      1. associate-*r/98.5%

        \[\leadsto \color{blue}{z \cdot \frac{x}{y}} + t \]
    4. Simplified98.5%

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

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

Alternative 3: 65.4% accurate, 0.6× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1 \lor \neg \left(\frac{x}{y} \leq 150000\right):\\ \;\;\;\;\frac{x}{y} \cdot \left(-t\right)\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 x y) < -1 or 1.5e5 < (/.f64 x y)

    1. Initial program 97.5%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in z around 0 61.8%

      \[\leadsto \color{blue}{t + -1 \cdot \frac{t \cdot x}{y}} \]
    3. Step-by-step derivation
      1. mul-1-neg61.8%

        \[\leadsto t + \color{blue}{\left(-\frac{t \cdot x}{y}\right)} \]
      2. unsub-neg61.8%

        \[\leadsto \color{blue}{t - \frac{t \cdot x}{y}} \]
      3. associate-/l*63.6%

        \[\leadsto t - \color{blue}{\frac{t}{\frac{y}{x}}} \]
      4. associate-/r/58.2%

        \[\leadsto t - \color{blue}{\frac{t}{y} \cdot x} \]
    4. Simplified58.2%

      \[\leadsto \color{blue}{t - \frac{t}{y} \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative58.2%

        \[\leadsto t - \color{blue}{x \cdot \frac{t}{y}} \]
      2. associate-*r/61.8%

        \[\leadsto t - \color{blue}{\frac{x \cdot t}{y}} \]
    6. Applied egg-rr61.8%

      \[\leadsto t - \color{blue}{\frac{x \cdot t}{y}} \]
    7. Taylor expanded in x around inf 61.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot x}{y}} \]
    8. Step-by-step derivation
      1. mul-1-neg61.3%

        \[\leadsto \color{blue}{-\frac{t \cdot x}{y}} \]
      2. associate-*r/64.8%

        \[\leadsto -\color{blue}{t \cdot \frac{x}{y}} \]
      3. *-commutative64.8%

        \[\leadsto -\color{blue}{\frac{x}{y} \cdot t} \]
      4. distribute-rgt-neg-in64.8%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \left(-t\right)} \]
    9. Simplified64.8%

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

    if -1 < (/.f64 x y) < 1.5e5

    1. Initial program 99.1%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in x around 0 72.7%

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

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

Alternative 4: 83.9% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;t \leq -1.8 \cdot 10^{-70} \lor \neg \left(t \leq 6.2 \cdot 10^{+59}\right):\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t + x \cdot \frac{z}{y}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if t < -1.8000000000000001e-70 or 6.20000000000000029e59 < t

    1. Initial program 99.9%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in z around 0 83.9%

      \[\leadsto \color{blue}{t + -1 \cdot \frac{t \cdot x}{y}} \]
    3. Step-by-step derivation
      1. mul-1-neg83.9%

        \[\leadsto t + \color{blue}{\left(-\frac{t \cdot x}{y}\right)} \]
      2. unsub-neg83.9%

        \[\leadsto \color{blue}{t - \frac{t \cdot x}{y}} \]
      3. associate-/l*88.5%

        \[\leadsto t - \color{blue}{\frac{t}{\frac{y}{x}}} \]
      4. associate-/r/79.8%

        \[\leadsto t - \color{blue}{\frac{t}{y} \cdot x} \]
    4. Simplified79.8%

      \[\leadsto \color{blue}{t - \frac{t}{y} \cdot x} \]
    5. Taylor expanded in t around 0 88.5%

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

    if -1.8000000000000001e-70 < t < 6.20000000000000029e59

    1. Initial program 96.7%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Step-by-step derivation
      1. *-commutative96.7%

        \[\leadsto \color{blue}{\left(z - t\right) \cdot \frac{x}{y}} + t \]
      2. clear-num96.6%

        \[\leadsto \left(z - t\right) \cdot \color{blue}{\frac{1}{\frac{y}{x}}} + t \]
      3. un-div-inv96.6%

        \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
    3. Applied egg-rr96.6%

      \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
    4. Taylor expanded in z around inf 83.7%

      \[\leadsto \color{blue}{\frac{z \cdot x}{y}} + t \]
    5. Step-by-step derivation
      1. *-commutative83.7%

        \[\leadsto \frac{\color{blue}{x \cdot z}}{y} + t \]
      2. associate-*r/83.7%

        \[\leadsto \color{blue}{x \cdot \frac{z}{y}} + t \]
    6. Simplified83.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -1.8 \cdot 10^{-70} \lor \neg \left(t \leq 6.2 \cdot 10^{+59}\right):\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t + x \cdot \frac{z}{y}\\ \end{array} \]

Alternative 5: 84.8% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{-54}:\\ \;\;\;\;t + x \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+61}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t + z \cdot \frac{x}{y}\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if z < -1.01999999999999999e-54

    1. Initial program 98.3%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Step-by-step derivation
      1. *-commutative98.3%

        \[\leadsto \color{blue}{\left(z - t\right) \cdot \frac{x}{y}} + t \]
      2. clear-num98.3%

        \[\leadsto \left(z - t\right) \cdot \color{blue}{\frac{1}{\frac{y}{x}}} + t \]
      3. un-div-inv98.5%

        \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
    3. Applied egg-rr98.5%

      \[\leadsto \color{blue}{\frac{z - t}{\frac{y}{x}}} + t \]
    4. Taylor expanded in z around inf 75.7%

      \[\leadsto \color{blue}{\frac{z \cdot x}{y}} + t \]
    5. Step-by-step derivation
      1. *-commutative75.7%

        \[\leadsto \frac{\color{blue}{x \cdot z}}{y} + t \]
      2. associate-*r/86.0%

        \[\leadsto \color{blue}{x \cdot \frac{z}{y}} + t \]
    6. Simplified86.0%

      \[\leadsto \color{blue}{x \cdot \frac{z}{y}} + t \]

    if -1.01999999999999999e-54 < z < 8.19999999999999944e61

    1. Initial program 97.9%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in z around 0 83.2%

      \[\leadsto \color{blue}{t + -1 \cdot \frac{t \cdot x}{y}} \]
    3. Step-by-step derivation
      1. mul-1-neg83.2%

        \[\leadsto t + \color{blue}{\left(-\frac{t \cdot x}{y}\right)} \]
      2. unsub-neg83.2%

        \[\leadsto \color{blue}{t - \frac{t \cdot x}{y}} \]
      3. associate-/l*84.6%

        \[\leadsto t - \color{blue}{\frac{t}{\frac{y}{x}}} \]
      4. associate-/r/78.9%

        \[\leadsto t - \color{blue}{\frac{t}{y} \cdot x} \]
    4. Simplified78.9%

      \[\leadsto \color{blue}{t - \frac{t}{y} \cdot x} \]
    5. Taylor expanded in t around 0 84.6%

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

    if 8.19999999999999944e61 < z

    1. Initial program 99.6%

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Taylor expanded in z around inf 87.0%

      \[\leadsto \color{blue}{\frac{z \cdot x}{y}} + t \]
    3. Step-by-step derivation
      1. associate-*r/94.2%

        \[\leadsto \color{blue}{z \cdot \frac{x}{y}} + t \]
    4. Simplified94.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{-54}:\\ \;\;\;\;t + x \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+61}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t + z \cdot \frac{x}{y}\\ \end{array} \]

Alternative 6: 66.6% accurate, 1.3× speedup?

\[t \cdot \left(1 - \frac{x}{y}\right) \]
Derivation
  1. Initial program 98.3%

    \[\frac{x}{y} \cdot \left(z - t\right) + t \]
  2. Taylor expanded in z around 0 67.1%

    \[\leadsto \color{blue}{t + -1 \cdot \frac{t \cdot x}{y}} \]
  3. Step-by-step derivation
    1. mul-1-neg67.1%

      \[\leadsto t + \color{blue}{\left(-\frac{t \cdot x}{y}\right)} \]
    2. unsub-neg67.1%

      \[\leadsto \color{blue}{t - \frac{t \cdot x}{y}} \]
    3. associate-/l*69.1%

      \[\leadsto t - \color{blue}{\frac{t}{\frac{y}{x}}} \]
    4. associate-/r/64.2%

      \[\leadsto t - \color{blue}{\frac{t}{y} \cdot x} \]
  4. Simplified64.2%

    \[\leadsto \color{blue}{t - \frac{t}{y} \cdot x} \]
  5. Taylor expanded in t around 0 69.9%

    \[\leadsto \color{blue}{t \cdot \left(1 - \frac{x}{y}\right)} \]
  6. Final simplification69.9%

    \[\leadsto t \cdot \left(1 - \frac{x}{y}\right) \]

Alternative 7: 38.9% accurate, 9.0× speedup?

\[t \]
Derivation
  1. Initial program 98.3%

    \[\frac{x}{y} \cdot \left(z - t\right) + t \]
  2. Taylor expanded in x around 0 39.9%

    \[\leadsto \color{blue}{t} \]
  3. Final simplification39.9%

    \[\leadsto t \]

Developer target: 97.6% accurate, 0.7× speedup?

\[\begin{array}{l} \mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\ \;\;\;\;x \cdot \frac{z - t}{y} + t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \end{array} \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x y z t)
  :name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
  :precision binary64

  :herbie-target
  (if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))

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