| Alternative 1 | |
|---|---|
| Accuracy | 58.9% |
| Cost | 1633 |
(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.5e+152)
(+ t (/ (- a y) (/ z (- t x))))
(if (<= z 6.5e+201)
(+ x (* (- x t) (/ (- z y) (- a z))))
(+ t (/ x (/ z (- y a)))))))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.5e+152) {
tmp = t + ((a - y) / (z / (t - x)));
} else if (z <= 6.5e+201) {
tmp = x + ((x - t) * ((z - y) / (a - z)));
} else {
tmp = t + (x / (z / (y - a)));
}
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.5d+152)) then
tmp = t + ((a - y) / (z / (t - x)))
else if (z <= 6.5d+201) then
tmp = x + ((x - t) * ((z - y) / (a - z)))
else
tmp = t + (x / (z / (y - a)))
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.5e+152) {
tmp = t + ((a - y) / (z / (t - x)));
} else if (z <= 6.5e+201) {
tmp = x + ((x - t) * ((z - y) / (a - z)));
} else {
tmp = t + (x / (z / (y - a)));
}
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.5e+152: tmp = t + ((a - y) / (z / (t - x))) elif z <= 6.5e+201: tmp = x + ((x - t) * ((z - y) / (a - z))) else: tmp = t + (x / (z / (y - a))) 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.5e+152) tmp = Float64(t + Float64(Float64(a - y) / Float64(z / Float64(t - x)))); elseif (z <= 6.5e+201) tmp = Float64(x + Float64(Float64(x - t) * Float64(Float64(z - y) / Float64(a - z)))); else tmp = Float64(t + Float64(x / Float64(z / Float64(y - a)))); 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.5e+152) tmp = t + ((a - y) / (z / (t - x))); elseif (z <= 6.5e+201) tmp = x + ((x - t) * ((z - y) / (a - z))); else tmp = t + (x / (z / (y - a))); 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.5e+152], N[(t + N[(N[(a - y), $MachinePrecision] / N[(z / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.5e+201], N[(x + N[(N[(x - t), $MachinePrecision] * N[(N[(z - y), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(x / N[(z / N[(y - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+152}:\\
\;\;\;\;t + \frac{a - y}{\frac{z}{t - x}}\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+201}:\\
\;\;\;\;x + \left(x - t\right) \cdot \frac{z - y}{a - z}\\
\mathbf{else}:\\
\;\;\;\;t + \frac{x}{\frac{z}{y - a}}\\
\end{array}
Results
| Original | 62.7% |
|---|---|
| Target | 81.8% |
| Herbie | 86.7% |
if z < -1.49999999999999995e152Initial program 26.6%
Simplified64.9%
[Start]26.6 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
+-commutative [=>]26.6 | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z} + x}
\] |
associate-*l/ [<=]64.9 | \[ \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)} + x
\] |
fma-def [=>]64.9 | \[ \color{blue}{\mathsf{fma}\left(\frac{y - z}{a - z}, t - x, x\right)}
\] |
Taylor expanded in z around inf 62.5%
Simplified84.8%
[Start]62.5 | \[ \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z} + t
\] |
|---|---|
+-commutative [=>]62.5 | \[ \color{blue}{t + \frac{\left(-1 \cdot y - -1 \cdot a\right) \cdot \left(t - x\right)}{z}}
\] |
associate-/l* [=>]84.8 | \[ t + \color{blue}{\frac{-1 \cdot y - -1 \cdot a}{\frac{z}{t - x}}}
\] |
distribute-lft-out-- [=>]84.8 | \[ t + \frac{\color{blue}{-1 \cdot \left(y - a\right)}}{\frac{z}{t - x}}
\] |
if -1.49999999999999995e152 < z < 6.5000000000000004e201Initial program 74.5%
Simplified87.2%
[Start]74.5 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-*l/ [<=]87.2 | \[ x + \color{blue}{\frac{y - z}{a - z} \cdot \left(t - x\right)}
\] |
if 6.5000000000000004e201 < z Initial program 22.7%
Simplified51.4%
[Start]22.7 | \[ x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\] |
|---|---|
associate-/l* [=>]51.4 | \[ x + \color{blue}{\frac{y - z}{\frac{a - z}{t - x}}}
\] |
Taylor expanded in z around inf 63.4%
Simplified63.4%
[Start]63.4 | \[ \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}
\] |
|---|---|
+-commutative [=>]63.4 | \[ \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right)} - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}
\] |
associate--l+ [=>]63.4 | \[ \color{blue}{t + \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)}
\] |
associate-*r/ [=>]63.4 | \[ t + \left(\color{blue}{\frac{-1 \cdot \left(y \cdot \left(t - x\right)\right)}{z}} - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
associate-*r/ [=>]63.4 | \[ t + \left(\frac{-1 \cdot \left(y \cdot \left(t - x\right)\right)}{z} - \color{blue}{\frac{-1 \cdot \left(a \cdot \left(t - x\right)\right)}{z}}\right)
\] |
div-sub [<=]63.4 | \[ t + \color{blue}{\frac{-1 \cdot \left(y \cdot \left(t - x\right)\right) - -1 \cdot \left(a \cdot \left(t - x\right)\right)}{z}}
\] |
distribute-lft-out-- [=>]63.4 | \[ t + \frac{\color{blue}{-1 \cdot \left(y \cdot \left(t - x\right) - a \cdot \left(t - x\right)\right)}}{z}
\] |
associate-*r/ [<=]63.4 | \[ t + \color{blue}{-1 \cdot \frac{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}{z}}
\] |
mul-1-neg [=>]63.4 | \[ t + \color{blue}{\left(-\frac{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}{z}\right)}
\] |
unsub-neg [=>]63.4 | \[ \color{blue}{t - \frac{y \cdot \left(t - x\right) - a \cdot \left(t - x\right)}{z}}
\] |
distribute-rgt-out-- [=>]63.4 | \[ t - \frac{\color{blue}{\left(t - x\right) \cdot \left(y - a\right)}}{z}
\] |
Taylor expanded in t around 0 71.4%
Simplified85.8%
[Start]71.4 | \[ t - -1 \cdot \frac{\left(y - a\right) \cdot x}{z}
\] |
|---|---|
associate-*r/ [=>]71.4 | \[ t - \color{blue}{\frac{-1 \cdot \left(\left(y - a\right) \cdot x\right)}{z}}
\] |
mul-1-neg [=>]71.4 | \[ t - \frac{\color{blue}{-\left(y - a\right) \cdot x}}{z}
\] |
*-commutative [=>]71.4 | \[ t - \frac{-\color{blue}{x \cdot \left(y - a\right)}}{z}
\] |
distribute-lft-neg-out [<=]71.4 | \[ t - \frac{\color{blue}{\left(-x\right) \cdot \left(y - a\right)}}{z}
\] |
associate-/l* [=>]85.8 | \[ t - \color{blue}{\frac{-x}{\frac{z}{y - a}}}
\] |
Final simplification86.7%
| Alternative 1 | |
|---|---|
| Accuracy | 58.9% |
| Cost | 1633 |
| Alternative 2 | |
|---|---|
| Accuracy | 58.4% |
| Cost | 1632 |
| Alternative 3 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 1632 |
| Alternative 4 | |
|---|---|
| Accuracy | 47.0% |
| Cost | 1504 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 1496 |
| Alternative 6 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 1496 |
| Alternative 7 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 1496 |
| Alternative 8 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 1440 |
| Alternative 9 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 1440 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 1368 |
| Alternative 11 | |
|---|---|
| Accuracy | 65.9% |
| Cost | 1236 |
| Alternative 12 | |
|---|---|
| Accuracy | 65.8% |
| Cost | 1236 |
| Alternative 13 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 1232 |
| Alternative 14 | |
|---|---|
| Accuracy | 49.1% |
| Cost | 1108 |
| Alternative 15 | |
|---|---|
| Accuracy | 69.0% |
| Cost | 1104 |
| Alternative 16 | |
|---|---|
| Accuracy | 45.0% |
| Cost | 976 |
| Alternative 17 | |
|---|---|
| Accuracy | 44.7% |
| Cost | 852 |
| Alternative 18 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 844 |
| Alternative 19 | |
|---|---|
| Accuracy | 59.2% |
| Cost | 844 |
| Alternative 20 | |
|---|---|
| Accuracy | 44.1% |
| Cost | 328 |
| Alternative 21 | |
|---|---|
| Accuracy | 29.2% |
| Cost | 64 |
herbie shell --seed 2023133
(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))))