| Alternative 1 | |
|---|---|
| Error | 27.0 |
| Cost | 2160 |
(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 -4.5e+189)
(+ t (- (* (/ y z) (- x t)) (/ (- x t) (/ z a))))
(if (<= z 4.2e+157)
(- x (* (- t x) (/ (- z y) (- a z))))
(- t (/ (- x t) (/ z (- a y)))))))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 <= -4.5e+189) {
tmp = t + (((y / z) * (x - t)) - ((x - t) / (z / a)));
} else if (z <= 4.2e+157) {
tmp = x - ((t - x) * ((z - y) / (a - z)));
} else {
tmp = t - ((x - t) / (z / (a - y)));
}
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 <= (-4.5d+189)) then
tmp = t + (((y / z) * (x - t)) - ((x - t) / (z / a)))
else if (z <= 4.2d+157) then
tmp = x - ((t - x) * ((z - y) / (a - z)))
else
tmp = t - ((x - t) / (z / (a - y)))
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 <= -4.5e+189) {
tmp = t + (((y / z) * (x - t)) - ((x - t) / (z / a)));
} else if (z <= 4.2e+157) {
tmp = x - ((t - x) * ((z - y) / (a - z)));
} else {
tmp = t - ((x - t) / (z / (a - y)));
}
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 <= -4.5e+189: tmp = t + (((y / z) * (x - t)) - ((x - t) / (z / a))) elif z <= 4.2e+157: tmp = x - ((t - x) * ((z - y) / (a - z))) else: tmp = t - ((x - t) / (z / (a - y))) 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 <= -4.5e+189) tmp = Float64(t + Float64(Float64(Float64(y / z) * Float64(x - t)) - Float64(Float64(x - t) / Float64(z / a)))); elseif (z <= 4.2e+157) tmp = Float64(x - Float64(Float64(t - x) * Float64(Float64(z - y) / Float64(a - z)))); else tmp = Float64(t - Float64(Float64(x - t) / Float64(z / Float64(a - y)))); 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 <= -4.5e+189) tmp = t + (((y / z) * (x - t)) - ((x - t) / (z / a))); elseif (z <= 4.2e+157) tmp = x - ((t - x) * ((z - y) / (a - z))); else tmp = t - ((x - t) / (z / (a - y))); 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, -4.5e+189], N[(t + N[(N[(N[(y / z), $MachinePrecision] * N[(x - t), $MachinePrecision]), $MachinePrecision] - N[(N[(x - t), $MachinePrecision] / N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.2e+157], N[(x - N[(N[(t - x), $MachinePrecision] * N[(N[(z - y), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t - N[(N[(x - t), $MachinePrecision] / N[(z / N[(a - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+189}:\\
\;\;\;\;t + \left(\frac{y}{z} \cdot \left(x - t\right) - \frac{x - t}{\frac{z}{a}}\right)\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+157}:\\
\;\;\;\;x - \left(t - x\right) \cdot \frac{z - y}{a - z}\\
\mathbf{else}:\\
\;\;\;\;t - \frac{x - t}{\frac{z}{a - y}}\\
\end{array}
Results
| Original | 24.6 |
|---|---|
| Target | 11.6 |
| Herbie | 7.8 |
if z < -4.49999999999999973e189Initial program 50.2
Simplified30.0
[Start]50.2 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
+-commutative [=>]50.2 | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} + x}
\] |
associate-*r/ [<=]30.1 | \[ \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z}} + x
\] |
*-commutative [<=]30.1 | \[ \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)} + x
\] |
fma-def [=>]30.0 | \[ \color{blue}{\mathsf{fma}\left(\frac{t - x}{a - z}, y - z, x\right)}
\] |
Taylor expanded in z around inf 22.7
Simplified7.6
[Start]22.7 | \[ -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
|---|---|
+-commutative [=>]22.7 | \[ \color{blue}{\left(t + \frac{a \cdot \left(t - x\right)}{z}\right) + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}}
\] |
mul-1-neg [=>]22.7 | \[ \left(t + \frac{a \cdot \left(t - x\right)}{z}\right) + \color{blue}{\left(-\frac{y \cdot \left(t - x\right)}{z}\right)}
\] |
unsub-neg [=>]22.7 | \[ \color{blue}{\left(t + \frac{a \cdot \left(t - x\right)}{z}\right) - \frac{y \cdot \left(t - x\right)}{z}}
\] |
associate--l+ [=>]22.7 | \[ \color{blue}{t + \left(\frac{a \cdot \left(t - x\right)}{z} - \frac{y \cdot \left(t - x\right)}{z}\right)}
\] |
*-commutative [=>]22.7 | \[ t + \left(\frac{\color{blue}{\left(t - x\right) \cdot a}}{z} - \frac{y \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]18.4 | \[ t + \left(\color{blue}{\frac{t - x}{\frac{z}{a}}} - \frac{y \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]8.5 | \[ t + \left(\frac{t - x}{\frac{z}{a}} - \color{blue}{\frac{y}{\frac{z}{t - x}}}\right)
\] |
associate-/r/ [=>]7.6 | \[ t + \left(\frac{t - x}{\frac{z}{a}} - \color{blue}{\frac{y}{z} \cdot \left(t - x\right)}\right)
\] |
if -4.49999999999999973e189 < z < 4.2e157Initial program 16.3
Simplified7.7
[Start]16.3 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]7.7 | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
if 4.2e157 < z Initial program 48.5
Simplified28.0
[Start]48.5 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
+-commutative [=>]48.5 | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} + x}
\] |
associate-*r/ [<=]28.1 | \[ \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z}} + x
\] |
*-commutative [<=]28.1 | \[ \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)} + x
\] |
fma-def [=>]28.0 | \[ \color{blue}{\mathsf{fma}\left(\frac{t - x}{a - z}, y - z, x\right)}
\] |
Taylor expanded in z around inf 23.2
Simplified8.0
[Start]23.2 | \[ -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
|---|---|
+-commutative [=>]23.2 | \[ \color{blue}{\left(t + \frac{a \cdot \left(t - x\right)}{z}\right) + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}}
\] |
mul-1-neg [=>]23.2 | \[ \left(t + \frac{a \cdot \left(t - x\right)}{z}\right) + \color{blue}{\left(-\frac{y \cdot \left(t - x\right)}{z}\right)}
\] |
unsub-neg [=>]23.2 | \[ \color{blue}{\left(t + \frac{a \cdot \left(t - x\right)}{z}\right) - \frac{y \cdot \left(t - x\right)}{z}}
\] |
associate--l+ [=>]23.2 | \[ \color{blue}{t + \left(\frac{a \cdot \left(t - x\right)}{z} - \frac{y \cdot \left(t - x\right)}{z}\right)}
\] |
*-commutative [=>]23.2 | \[ t + \left(\frac{\color{blue}{\left(t - x\right) \cdot a}}{z} - \frac{y \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]18.3 | \[ t + \left(\color{blue}{\frac{t - x}{\frac{z}{a}}} - \frac{y \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]9.1 | \[ t + \left(\frac{t - x}{\frac{z}{a}} - \color{blue}{\frac{y}{\frac{z}{t - x}}}\right)
\] |
associate-/r/ [=>]8.0 | \[ t + \left(\frac{t - x}{\frac{z}{a}} - \color{blue}{\frac{y}{z} \cdot \left(t - x\right)}\right)
\] |
Taylor expanded in z around 0 23.2
Simplified8.0
[Start]23.2 | \[ t + \frac{a \cdot \left(t - x\right) - y \cdot \left(t - x\right)}{z}
\] |
|---|---|
distribute-rgt-out-- [=>]23.2 | \[ t + \frac{\color{blue}{\left(t - x\right) \cdot \left(a - y\right)}}{z}
\] |
associate-/l* [=>]8.0 | \[ t + \color{blue}{\frac{t - x}{\frac{z}{a - y}}}
\] |
Final simplification7.8
| Alternative 1 | |
|---|---|
| Error | 27.0 |
| Cost | 2160 |
| Alternative 2 | |
|---|---|
| Error | 24.2 |
| Cost | 1632 |
| Alternative 3 | |
|---|---|
| Error | 24.0 |
| Cost | 1632 |
| Alternative 4 | |
|---|---|
| Error | 26.8 |
| Cost | 1500 |
| Alternative 5 | |
|---|---|
| Error | 17.4 |
| Cost | 1496 |
| Alternative 6 | |
|---|---|
| Error | 17.4 |
| Cost | 1496 |
| Alternative 7 | |
|---|---|
| Error | 29.9 |
| Cost | 1436 |
| Alternative 8 | |
|---|---|
| Error | 41.6 |
| Cost | 1376 |
| Alternative 9 | |
|---|---|
| Error | 41.6 |
| Cost | 1244 |
| Alternative 10 | |
|---|---|
| Error | 41.6 |
| Cost | 1244 |
| Alternative 11 | |
|---|---|
| Error | 18.2 |
| Cost | 1233 |
| Alternative 12 | |
|---|---|
| Error | 22.0 |
| Cost | 1104 |
| Alternative 13 | |
|---|---|
| Error | 22.0 |
| Cost | 1104 |
| Alternative 14 | |
|---|---|
| Error | 7.8 |
| Cost | 1097 |
| Alternative 15 | |
|---|---|
| Error | 30.1 |
| Cost | 844 |
| Alternative 16 | |
|---|---|
| Error | 29.1 |
| Cost | 712 |
| Alternative 17 | |
|---|---|
| Error | 35.4 |
| Cost | 328 |
| Alternative 18 | |
|---|---|
| Error | 45.7 |
| Cost | 64 |
herbie shell --seed 2023039
(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))))