| Alternative 1 | |
|---|---|
| Accuracy | 93.8% |
| Cost | 1352 |

(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y z) (- t x)) (- a z))))
(FPCore (x y z t a)
:precision binary64
(if (<= z -1.45e+16)
(+ t (* (/ y z) (- x t)))
(if (<= z 1e-15)
(+ x (* (- t x) (/ (- y z) (- a z))))
(+ (- t (/ y (/ z (- t x)))) (/ (* (- t x) a) z)))))double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.45e+16) {
tmp = t + ((y / z) * (x - t));
} else if (z <= 1e-15) {
tmp = x + ((t - x) * ((y - z) / (a - z)));
} else {
tmp = (t - (y / (z / (t - x)))) + (((t - x) * a) / z);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (((y - z) * (t - x)) / (a - z))
end function
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (z <= (-1.45d+16)) then
tmp = t + ((y / z) * (x - t))
else if (z <= 1d-15) then
tmp = x + ((t - x) * ((y - z) / (a - z)))
else
tmp = (t - (y / (z / (t - x)))) + (((t - x) * a) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.45e+16) {
tmp = t + ((y / z) * (x - t));
} else if (z <= 1e-15) {
tmp = x + ((t - x) * ((y - z) / (a - z)));
} else {
tmp = (t - (y / (z / (t - x)))) + (((t - x) * a) / z);
}
return tmp;
}
def code(x, y, z, t, a): return x + (((y - z) * (t - x)) / (a - z))
def code(x, y, z, t, a): tmp = 0 if z <= -1.45e+16: tmp = t + ((y / z) * (x - t)) elif z <= 1e-15: tmp = x + ((t - x) * ((y - z) / (a - z))) else: tmp = (t - (y / (z / (t - x)))) + (((t - x) * a) / z) return tmp
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - z) * Float64(t - x)) / Float64(a - z))) end
function code(x, y, z, t, a) tmp = 0.0 if (z <= -1.45e+16) tmp = Float64(t + Float64(Float64(y / z) * Float64(x - t))); elseif (z <= 1e-15) tmp = Float64(x + Float64(Float64(t - x) * Float64(Float64(y - z) / Float64(a - z)))); else tmp = Float64(Float64(t - Float64(y / Float64(z / Float64(t - x)))) + Float64(Float64(Float64(t - x) * a) / z)); end return tmp end
function tmp = code(x, y, z, t, a) tmp = x + (((y - z) * (t - x)) / (a - z)); end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -1.45e+16) tmp = t + ((y / z) * (x - t)); elseif (z <= 1e-15) tmp = x + ((t - x) * ((y - z) / (a - z))); else tmp = (t - (y / (z / (t - x)))) + (((t - x) * a) / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -1.45e+16], N[(t + N[(N[(y / z), $MachinePrecision] * N[(x - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e-15], N[(x + N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t - N[(y / N[(z / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t - x), $MachinePrecision] * a), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+16}:\\
\;\;\;\;t + \frac{y}{z} \cdot \left(x - t\right)\\
\mathbf{elif}\;z \leq 10^{-15}:\\
\;\;\;\;x + \left(t - x\right) \cdot \frac{y - z}{a - z}\\
\mathbf{else}:\\
\;\;\;\;\left(t - \frac{y}{\frac{z}{t - x}}\right) + \frac{\left(t - x\right) \cdot a}{z}\\
\end{array}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 73.8% |
|---|---|
| Target | 89.7% |
| Herbie | 93.8% |
if z < -1.45e16Initial program 48.6%
Simplified63.3%
[Start]48.6% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]63.3% | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
Taylor expanded in z around inf 91.6%
Simplified95.8%
[Start]91.6% | \[ \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}
\] |
|---|---|
sub-neg [=>]91.6% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)}
\] |
+-commutative [=>]91.6% | \[ \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]91.6% | \[ \left(t + \color{blue}{\left(-\frac{y \cdot \left(t - x\right)}{z}\right)}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
unsub-neg [=>]91.6% | \[ \color{blue}{\left(t - \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]95.8% | \[ \left(t - \color{blue}{\frac{y}{\frac{z}{t - x}}}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]95.8% | \[ \left(t - \frac{y}{\frac{z}{t - x}}\right) + \left(-\color{blue}{\left(-\frac{a \cdot \left(t - x\right)}{z}\right)}\right)
\] |
remove-double-neg [=>]95.8% | \[ \left(t - \frac{y}{\frac{z}{t - x}}\right) + \color{blue}{\frac{a \cdot \left(t - x\right)}{z}}
\] |
Taylor expanded in a around 0 88.7%
Simplified97.1%
[Start]88.7% | \[ t - \frac{y \cdot \left(t - x\right)}{z}
\] |
|---|---|
associate-*l/ [<=]97.1% | \[ t - \color{blue}{\frac{y}{z} \cdot \left(t - x\right)}
\] |
*-commutative [=>]97.1% | \[ t - \color{blue}{\left(t - x\right) \cdot \frac{y}{z}}
\] |
if -1.45e16 < z < 1.0000000000000001e-15Initial program 90.0%
Simplified92.0%
[Start]90.0% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]92.0% | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
if 1.0000000000000001e-15 < z Initial program 40.8%
Simplified53.5%
[Start]40.8% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]53.5% | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
Taylor expanded in z around inf 88.8%
Simplified95.1%
[Start]88.8% | \[ \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}
\] |
|---|---|
sub-neg [=>]88.8% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)}
\] |
+-commutative [=>]88.8% | \[ \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]88.8% | \[ \left(t + \color{blue}{\left(-\frac{y \cdot \left(t - x\right)}{z}\right)}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
unsub-neg [=>]88.8% | \[ \color{blue}{\left(t - \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]95.1% | \[ \left(t - \color{blue}{\frac{y}{\frac{z}{t - x}}}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]95.1% | \[ \left(t - \frac{y}{\frac{z}{t - x}}\right) + \left(-\color{blue}{\left(-\frac{a \cdot \left(t - x\right)}{z}\right)}\right)
\] |
remove-double-neg [=>]95.1% | \[ \left(t - \frac{y}{\frac{z}{t - x}}\right) + \color{blue}{\frac{a \cdot \left(t - x\right)}{z}}
\] |
Final simplification93.6%
| Alternative 1 | |
|---|---|
| Accuracy | 93.8% |
| Cost | 1352 |
| Alternative 2 | |
|---|---|
| Accuracy | 53.5% |
| Cost | 1572 |
| Alternative 3 | |
|---|---|
| Accuracy | 54.0% |
| Cost | 1436 |
| Alternative 4 | |
|---|---|
| Accuracy | 53.8% |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Accuracy | 93.3% |
| Cost | 1097 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.0% |
| Cost | 972 |
| Alternative 7 | |
|---|---|
| Accuracy | 88.1% |
| Cost | 969 |
| Alternative 8 | |
|---|---|
| Accuracy | 59.8% |
| Cost | 908 |
| Alternative 9 | |
|---|---|
| Accuracy | 71.5% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 79.4% |
| Cost | 841 |
| Alternative 11 | |
|---|---|
| Accuracy | 65.9% |
| Cost | 840 |
| Alternative 12 | |
|---|---|
| Accuracy | 40.9% |
| Cost | 712 |
| Alternative 13 | |
|---|---|
| Accuracy | 54.1% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 40.3% |
| Cost | 584 |
| Alternative 15 | |
|---|---|
| Accuracy | 40.4% |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Accuracy | 42.0% |
| Cost | 328 |
| Alternative 17 | |
|---|---|
| Accuracy | 24.4% |
| Cost | 64 |
herbie shell --seed 2023277
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:invLinMap from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< z -1.2536131056095036e+188) (- t (* (/ y z) (- t x))) (if (< z 4.446702369113811e+64) (+ x (/ (- y z) (/ (- a z) (- t x)))) (- t (* (/ y z) (- t x)))))
(+ x (/ (* (- y z) (- t x)) (- a z))))