?

Average Error: 3.2% → 3.2%
Time: 8.7s
Precision: binary64
Cost: 6848

?

\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\mathsf{fma}\left(\frac{x}{y}, z - t, t\right) \]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t) :precision binary64 (fma (/ x y) (- z t) t))
double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
	return fma((x / y), (z - t), t);
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x / y) * Float64(z - t)) + t)
end
function code(x, y, z, t)
	return fma(Float64(x / y), Float64(z - t), t)
end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision] + t), $MachinePrecision]
\frac{x}{y} \cdot \left(z - t\right) + t
\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)

Error?

Target

Original3.2%
Target3.62%
Herbie3.2%
\[\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} \]

Derivation?

  1. Initial program 3.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)} \]
    Proof

    [Start]3.2

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

    fma-def [=>]3.2

    \[ \color{blue}{\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)} \]
  3. Final simplification3.2

    \[\leadsto \mathsf{fma}\left(\frac{x}{y}, z - t, t\right) \]

Alternatives

Alternative 1
Error35.12%
Cost1944
\[\begin{array}{l} t_1 := x \cdot \frac{t}{-y}\\ \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -1 \cdot 10^{-37}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-184}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-155}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+176}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error35.49%
Cost1944
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{+63}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-t\right)\\ \mathbf{elif}\;\frac{x}{y} \leq -1 \cdot 10^{-37}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-184}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-155}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+176}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{t}{-y}\\ \end{array} \]
Alternative 3
Error30.1%
Cost1637
\[\begin{array}{l} t_1 := t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{if}\;t \leq -1.5 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -6 \cdot 10^{-120}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;t \leq -2.4 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.2 \cdot 10^{-177}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;t \leq -2.95 \cdot 10^{-210}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -8.5 \cdot 10^{-258}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;t \leq 7.8 \cdot 10^{-271} \lor \neg \left(t \leq 3.2 \cdot 10^{-220}\right) \land t \leq 3.8 \cdot 10^{-144}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error23.97%
Cost1489
\[\begin{array}{l} t_1 := x \cdot \frac{z - t}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-184}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-155} \lor \neg \left(\frac{x}{y} \leq 2000000000\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \end{array} \]
Alternative 5
Error6.74%
Cost1488
\[\begin{array}{l} t_1 := t + \frac{z}{\frac{y}{x}}\\ t_2 := x \cdot \frac{z - t}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-309}:\\ \;\;\;\;t + \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.002:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error6.38%
Cost1488
\[\begin{array}{l} t_1 := t + \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -2000:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-309}:\\ \;\;\;\;t + \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.002:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{z - t}{y}\\ \end{array} \]
Alternative 7
Error3.89%
Cost1488
\[\begin{array}{l} t_1 := t + \frac{z}{\frac{y}{x}}\\ t_2 := \frac{z - t}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -2000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-309}:\\ \;\;\;\;t + \frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.002:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error35.87%
Cost1362
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -5.3 \cdot 10^{-39} \lor \neg \left(\frac{x}{y} \leq 6.5 \cdot 10^{-181}\right) \land \left(\frac{x}{y} \leq 1.3 \cdot 10^{-155} \lor \neg \left(\frac{x}{y} \leq 1.3 \cdot 10^{-10}\right)\right):\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 9
Error36.05%
Cost1360
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot z\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-184}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-155}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error35.99%
Cost1360
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-37}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-184}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-155}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 11
Error7.41%
Cost969
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{+24} \lor \neg \left(\frac{x}{y} \leq 0.002\right):\\ \;\;\;\;x \cdot \frac{z - t}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 12
Error3.2%
Cost576
\[t + \frac{x}{y} \cdot \left(z - t\right) \]
Alternative 13
Error49.94%
Cost64
\[t \]

Error

Reproduce?

herbie shell --seed 2023088 
(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))