| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 1220 |
\[\begin{array}{l}
t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\
\mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\
\end{array}
\]

(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ t (* (/ x y) (- z t))))) (if (<= t_1 5e+306) t_1 (/ (* x (- z t)) y))))
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) {
double t_1 = t + ((x / y) * (z - t));
double tmp;
if (t_1 <= 5e+306) {
tmp = t_1;
} else {
tmp = (x * (z - t)) / y;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x / y) * (z - t)) + t
end function
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = t + ((x / y) * (z - t))
if (t_1 <= 5d+306) then
tmp = t_1
else
tmp = (x * (z - t)) / y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + t;
}
public static double code(double x, double y, double z, double t) {
double t_1 = t + ((x / y) * (z - t));
double tmp;
if (t_1 <= 5e+306) {
tmp = t_1;
} else {
tmp = (x * (z - t)) / y;
}
return tmp;
}
def code(x, y, z, t): return ((x / y) * (z - t)) + t
def code(x, y, z, t): t_1 = t + ((x / y) * (z - t)) tmp = 0 if t_1 <= 5e+306: tmp = t_1 else: tmp = (x * (z - t)) / y return tmp
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(z - t)) + t) end
function code(x, y, z, t) t_1 = Float64(t + Float64(Float64(x / y) * Float64(z - t))) tmp = 0.0 if (t_1 <= 5e+306) tmp = t_1; else tmp = Float64(Float64(x * Float64(z - t)) / y); end return tmp end
function tmp = code(x, y, z, t) tmp = ((x / y) * (z - t)) + t; end
function tmp_2 = code(x, y, z, t) t_1 = t + ((x / y) * (z - t)); tmp = 0.0; if (t_1 <= 5e+306) tmp = t_1; else tmp = (x * (z - t)) / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e+306], t$95$1, N[(N[(x * N[(z - t), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\
\mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 97.7% |
|---|---|
| Target | 97.3% |
| Herbie | 98.4% |
if (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t) < 4.99999999999999993e306Initial program 98.2%
if 4.99999999999999993e306 < (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t) Initial program 87.5%
Simplified99.9%
[Start]87.5% | \[ \frac{x}{y} \cdot \left(z - t\right) + t
\] |
|---|---|
associate-*l/ [=>]100.0% | \[ \color{blue}{\frac{x \cdot \left(z - t\right)}{y}} + t
\] |
*-commutative [=>]100.0% | \[ \frac{\color{blue}{\left(z - t\right) \cdot x}}{y} + t
\] |
associate-*l/ [<=]99.9% | \[ \color{blue}{\frac{z - t}{y} \cdot x} + t
\] |
*-commutative [=>]99.9% | \[ \color{blue}{x \cdot \frac{z - t}{y}} + t
\] |
fma-def [=>]99.9% | \[ \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)}
\] |
Applied egg-rr99.9%
[Start]99.9% | \[ \mathsf{fma}\left(x, \frac{z - t}{y}, t\right)
\] |
|---|---|
clear-num [=>]99.9% | \[ \mathsf{fma}\left(x, \color{blue}{\frac{1}{\frac{y}{z - t}}}, t\right)
\] |
associate-/r/ [=>]99.9% | \[ \mathsf{fma}\left(x, \color{blue}{\frac{1}{y} \cdot \left(z - t\right)}, t\right)
\] |
Taylor expanded in x around -inf 100.0%
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 1220 |
| Alternative 2 | |
|---|---|
| Accuracy | 63.6% |
| Cost | 2205 |
| Alternative 3 | |
|---|---|
| Accuracy | 63.4% |
| Cost | 2205 |
| Alternative 4 | |
|---|---|
| Accuracy | 62.8% |
| Cost | 1425 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 1096 |
| Alternative 6 | |
|---|---|
| Accuracy | 94.3% |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 64.3% |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Accuracy | 63.1% |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Accuracy | 85.3% |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Accuracy | 76.3% |
| Cost | 448 |
| Alternative 12 | |
|---|---|
| Accuracy | 37.8% |
| Cost | 64 |
herbie shell --seed 2023263
(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))