| Alternative 1 | |
|---|---|
| Accuracy | 87.8% |
| Cost | 1096 |

(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 -7.2e+168)
(+ t (/ (- a y) (/ (- z) x)))
(if (<= z 9e+88)
(- x (/ (- x t) (/ (- a z) (- y z))))
(+ t (/ (- a y) (/ z (- t x)))))))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 <= -7.2e+168) {
tmp = t + ((a - y) / (-z / x));
} else if (z <= 9e+88) {
tmp = x - ((x - t) / ((a - z) / (y - z)));
} else {
tmp = t + ((a - y) / (z / (t - x)));
}
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 <= (-7.2d+168)) then
tmp = t + ((a - y) / (-z / x))
else if (z <= 9d+88) then
tmp = x - ((x - t) / ((a - z) / (y - z)))
else
tmp = t + ((a - y) / (z / (t - x)))
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 <= -7.2e+168) {
tmp = t + ((a - y) / (-z / x));
} else if (z <= 9e+88) {
tmp = x - ((x - t) / ((a - z) / (y - z)));
} else {
tmp = t + ((a - y) / (z / (t - x)));
}
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 <= -7.2e+168: tmp = t + ((a - y) / (-z / x)) elif z <= 9e+88: tmp = x - ((x - t) / ((a - z) / (y - z))) else: tmp = t + ((a - y) / (z / (t - x))) 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 <= -7.2e+168) tmp = Float64(t + Float64(Float64(a - y) / Float64(Float64(-z) / x))); elseif (z <= 9e+88) tmp = Float64(x - Float64(Float64(x - t) / Float64(Float64(a - z) / Float64(y - z)))); else tmp = Float64(t + Float64(Float64(a - y) / Float64(z / Float64(t - x)))); 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 <= -7.2e+168) tmp = t + ((a - y) / (-z / x)); elseif (z <= 9e+88) tmp = x - ((x - t) / ((a - z) / (y - z))); else tmp = t + ((a - y) / (z / (t - x))); 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, -7.2e+168], N[(t + N[(N[(a - y), $MachinePrecision] / N[((-z) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9e+88], N[(x - N[(N[(x - t), $MachinePrecision] / N[(N[(a - z), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(N[(a - y), $MachinePrecision] / N[(z / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{+168}:\\
\;\;\;\;t + \frac{a - y}{\frac{-z}{x}}\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+88}:\\
\;\;\;\;x - \frac{x - t}{\frac{a - z}{y - z}}\\
\mathbf{else}:\\
\;\;\;\;t + \frac{a - y}{\frac{z}{t - x}}\\
\end{array}
Herbie found 26 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 68.6% |
|---|---|
| Target | 83.8% |
| Herbie | 87.8% |
if z < -7.1999999999999999e168Initial program 17.5%
Simplified51.7%
[Start]17.5% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
+-commutative [=>]17.5% | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} + x}
\] |
associate-*l/ [<=]51.7% | \[ \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)} + x
\] |
fma-def [=>]51.7% | \[ \color{blue}{\mathsf{fma}\left(\frac{y - z}{a - z}, t - x, x\right)}
\] |
Taylor expanded in z around inf 66.7%
Simplified93.4%
[Start]66.7% | \[ \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z} + t
\] |
|---|---|
+-commutative [=>]66.7% | \[ \color{blue}{t + \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z}}
\] |
associate-/l* [=>]93.4% | \[ t + \color{blue}{\frac{-1 \cdot y - -1 \cdot a}{\frac{z}{t - x}}}
\] |
distribute-lft-out-- [=>]93.4% | \[ t + \frac{\color{blue}{-1 \cdot \left(y - a\right)}}{\frac{z}{t - x}}
\] |
mul-1-neg [=>]93.4% | \[ t + \frac{\color{blue}{-\left(y - a\right)}}{\frac{z}{t - x}}
\] |
distribute-neg-frac [<=]93.4% | \[ t + \color{blue}{\left(-\frac{y - a}{\frac{z}{t - x}}\right)}
\] |
associate-/l* [<=]66.7% | \[ t + \left(-\color{blue}{\frac{\left(y - a\right) \cdot \left(t - x\right)}{z}}\right)
\] |
*-commutative [=>]66.7% | \[ t + \left(-\frac{\color{blue}{\left(t - x\right) \cdot \left(y - a\right)}}{z}\right)
\] |
distribute-rgt-out-- [<=]66.7% | \[ t + \left(-\frac{\color{blue}{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}}{z}\right)
\] |
unsub-neg [=>]66.7% | \[ \color{blue}{t - \frac{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}{z}}
\] |
distribute-rgt-out-- [=>]66.7% | \[ t - \frac{\color{blue}{\left(t - x\right) \cdot \left(y - a\right)}}{z}
\] |
*-commutative [<=]66.7% | \[ t - \frac{\color{blue}{\left(y - a\right) \cdot \left(t - x\right)}}{z}
\] |
associate-/l* [=>]93.4% | \[ t - \color{blue}{\frac{y - a}{\frac{z}{t - x}}}
\] |
Taylor expanded in t around 0 93.4%
Simplified93.4%
[Start]93.4% | \[ t - \frac{y - a}{-1 \cdot \frac{z}{x}}
\] |
|---|---|
associate-*r/ [=>]93.4% | \[ t - \frac{y - a}{\color{blue}{\frac{-1 \cdot z}{x}}}
\] |
neg-mul-1 [<=]93.4% | \[ t - \frac{y - a}{\frac{\color{blue}{-z}}{x}}
\] |
if -7.1999999999999999e168 < z < 9e88Initial program 84.8%
Simplified93.2%
[Start]84.8% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]93.2% | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
Applied egg-rr93.6%
[Start]93.2% | \[ x + \frac{y - z}{a - z} \cdot \left(t - x\right)
\] |
|---|---|
*-commutative [=>]93.2% | \[ x + \color{blue}{\left(t - x\right) \cdot \frac{y - z}{a - z}}
\] |
clear-num [=>]93.1% | \[ x + \left(t - x\right) \cdot \color{blue}{\frac{1}{\frac{a - z}{y - z}}}
\] |
un-div-inv [=>]93.6% | \[ x + \color{blue}{\frac{t - x}{\frac{a - z}{y - z}}}
\] |
if 9e88 < z Initial program 39.1%
Simplified65.7%
[Start]39.1% | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
+-commutative [=>]39.1% | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} + x}
\] |
associate-*l/ [<=]65.6% | \[ \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)} + x
\] |
fma-def [=>]65.7% | \[ \color{blue}{\mathsf{fma}\left(\frac{y - z}{a - z}, t - x, x\right)}
\] |
Taylor expanded in z around inf 72.0%
Simplified86.9%
[Start]72.0% | \[ \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z} + t
\] |
|---|---|
+-commutative [=>]72.0% | \[ \color{blue}{t + \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z}}
\] |
associate-/l* [=>]86.9% | \[ t + \color{blue}{\frac{-1 \cdot y - -1 \cdot a}{\frac{z}{t - x}}}
\] |
distribute-lft-out-- [=>]86.9% | \[ t + \frac{\color{blue}{-1 \cdot \left(y - a\right)}}{\frac{z}{t - x}}
\] |
mul-1-neg [=>]86.9% | \[ t + \frac{\color{blue}{-\left(y - a\right)}}{\frac{z}{t - x}}
\] |
distribute-neg-frac [<=]86.9% | \[ t + \color{blue}{\left(-\frac{y - a}{\frac{z}{t - x}}\right)}
\] |
associate-/l* [<=]72.0% | \[ t + \left(-\color{blue}{\frac{\left(y - a\right) \cdot \left(t - x\right)}{z}}\right)
\] |
*-commutative [=>]72.0% | \[ t + \left(-\frac{\color{blue}{\left(t - x\right) \cdot \left(y - a\right)}}{z}\right)
\] |
distribute-rgt-out-- [<=]71.9% | \[ t + \left(-\frac{\color{blue}{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}}{z}\right)
\] |
unsub-neg [=>]71.9% | \[ \color{blue}{t - \frac{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}{z}}
\] |
distribute-rgt-out-- [=>]72.0% | \[ t - \frac{\color{blue}{\left(t - x\right) \cdot \left(y - a\right)}}{z}
\] |
*-commutative [<=]72.0% | \[ t - \frac{\color{blue}{\left(y - a\right) \cdot \left(t - x\right)}}{z}
\] |
associate-/l* [=>]86.9% | \[ t - \color{blue}{\frac{y - a}{\frac{z}{t - x}}}
\] |
Final simplification92.3%
| Alternative 1 | |
|---|---|
| Accuracy | 87.8% |
| Cost | 1096 |
| Alternative 2 | |
|---|---|
| Accuracy | 46.5% |
| Cost | 1833 |
| Alternative 3 | |
|---|---|
| Accuracy | 46.4% |
| Cost | 1701 |
| Alternative 4 | |
|---|---|
| Accuracy | 57.5% |
| Cost | 1368 |
| Alternative 5 | |
|---|---|
| Accuracy | 55.8% |
| Cost | 1368 |
| Alternative 6 | |
|---|---|
| Accuracy | 48.0% |
| Cost | 1306 |
| Alternative 7 | |
|---|---|
| Accuracy | 37.3% |
| Cost | 1240 |
| Alternative 8 | |
|---|---|
| Accuracy | 45.5% |
| Cost | 1240 |
| Alternative 9 | |
|---|---|
| Accuracy | 45.7% |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Accuracy | 74.5% |
| Cost | 1232 |
| Alternative 11 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 1104 |
| Alternative 12 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 1104 |
| Alternative 13 | |
|---|---|
| Accuracy | 71.2% |
| Cost | 1100 |
| Alternative 14 | |
|---|---|
| Accuracy | 72.9% |
| Cost | 1100 |
| Alternative 15 | |
|---|---|
| Accuracy | 87.7% |
| Cost | 1096 |
| Alternative 16 | |
|---|---|
| Accuracy | 37.3% |
| Cost | 1044 |
| Alternative 17 | |
|---|---|
| Accuracy | 68.9% |
| Cost | 1036 |
| Alternative 18 | |
|---|---|
| Accuracy | 38.3% |
| Cost | 980 |
| Alternative 19 | |
|---|---|
| Accuracy | 38.3% |
| Cost | 980 |
| Alternative 20 | |
|---|---|
| Accuracy | 46.4% |
| Cost | 976 |
| Alternative 21 | |
|---|---|
| Accuracy | 71.2% |
| Cost | 972 |
| Alternative 22 | |
|---|---|
| Accuracy | 62.6% |
| Cost | 841 |
| Alternative 23 | |
|---|---|
| Accuracy | 38.5% |
| Cost | 716 |
| Alternative 24 | |
|---|---|
| Accuracy | 38.7% |
| Cost | 716 |
| Alternative 25 | |
|---|---|
| Accuracy | 39.2% |
| Cost | 328 |
| Alternative 26 | |
|---|---|
| Accuracy | 25.2% |
| Cost | 64 |
herbie shell --seed 2023263
(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))))