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

(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
:precision binary64
(if (<= t -1.35e+54)
(- x (/ (- a z) (/ t y)))
(if (<= t 6.5e+49)
(+ x (+ y (/ (- t z) (/ (- a t) y))))
(+ (- x (/ y (/ t a))) (/ y (/ t z))))))double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.35e+54) {
tmp = x - ((a - z) / (t / y));
} else if (t <= 6.5e+49) {
tmp = x + (y + ((t - z) / ((a - t) / y)));
} else {
tmp = (x - (y / (t / a))) + (y / (t / 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) * y) / (a - t))
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 (t <= (-1.35d+54)) then
tmp = x - ((a - z) / (t / y))
else if (t <= 6.5d+49) then
tmp = x + (y + ((t - z) / ((a - t) / y)))
else
tmp = (x - (y / (t / a))) + (y / (t / 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) * y) / (a - t));
}
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.35e+54) {
tmp = x - ((a - z) / (t / y));
} else if (t <= 6.5e+49) {
tmp = x + (y + ((t - z) / ((a - t) / y)));
} else {
tmp = (x - (y / (t / a))) + (y / (t / z));
}
return tmp;
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
def code(x, y, z, t, a): tmp = 0 if t <= -1.35e+54: tmp = x - ((a - z) / (t / y)) elif t <= 6.5e+49: tmp = x + (y + ((t - z) / ((a - t) / y))) else: tmp = (x - (y / (t / a))) + (y / (t / z)) return tmp
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function code(x, y, z, t, a) tmp = 0.0 if (t <= -1.35e+54) tmp = Float64(x - Float64(Float64(a - z) / Float64(t / y))); elseif (t <= 6.5e+49) tmp = Float64(x + Float64(y + Float64(Float64(t - z) / Float64(Float64(a - t) / y)))); else tmp = Float64(Float64(x - Float64(y / Float64(t / a))) + Float64(y / Float64(t / z))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= -1.35e+54) tmp = x - ((a - z) / (t / y)); elseif (t <= 6.5e+49) tmp = x + (y + ((t - z) / ((a - t) / y))); else tmp = (x - (y / (t / a))) + (y / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -1.35e+54], N[(x - N[(N[(a - z), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 6.5e+49], N[(x + N[(y + N[(N[(t - z), $MachinePrecision] / N[(N[(a - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(y / N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -1.35 \cdot 10^{+54}:\\
\;\;\;\;x - \frac{a - z}{\frac{t}{y}}\\
\mathbf{elif}\;t \leq 6.5 \cdot 10^{+49}:\\
\;\;\;\;x + \left(y + \frac{t - z}{\frac{a - t}{y}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - \frac{y}{\frac{t}{a}}\right) + \frac{y}{\frac{t}{z}}\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 80.2% |
|---|---|
| Target | 88.8% |
| Herbie | 94.8% |
if t < -1.35000000000000005e54Initial program 53.4%
Simplified75.0%
[Start]53.4% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]56.8% | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
associate-/l* [=>]75.0% | \[ x + \left(y - \color{blue}{\frac{z - t}{\frac{a - t}{y}}}\right)
\] |
Applied egg-rr74.9%
[Start]75.0% | \[ x + \left(y - \frac{z - t}{\frac{a - t}{y}}\right)
\] |
|---|---|
div-inv [=>]75.0% | \[ x + \left(y - \color{blue}{\left(z - t\right) \cdot \frac{1}{\frac{a - t}{y}}}\right)
\] |
clear-num [<=]74.9% | \[ x + \left(y - \left(z - t\right) \cdot \color{blue}{\frac{y}{a - t}}\right)
\] |
Taylor expanded in t around inf 96.5%
Simplified99.8%
[Start]96.5% | \[ \left(-1 \cdot \frac{y \cdot a}{t} + x\right) - -1 \cdot \frac{y \cdot z}{t}
\] |
|---|---|
cancel-sign-sub-inv [=>]96.5% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot a}{t} + x\right) + \left(--1\right) \cdot \frac{y \cdot z}{t}}
\] |
+-commutative [=>]96.5% | \[ \color{blue}{\left(x + -1 \cdot \frac{y \cdot a}{t}\right)} + \left(--1\right) \cdot \frac{y \cdot z}{t}
\] |
metadata-eval [=>]96.5% | \[ \left(x + -1 \cdot \frac{y \cdot a}{t}\right) + \color{blue}{1} \cdot \frac{y \cdot z}{t}
\] |
*-lft-identity [=>]96.5% | \[ \left(x + -1 \cdot \frac{y \cdot a}{t}\right) + \color{blue}{\frac{y \cdot z}{t}}
\] |
associate-+l+ [=>]96.5% | \[ \color{blue}{x + \left(-1 \cdot \frac{y \cdot a}{t} + \frac{y \cdot z}{t}\right)}
\] |
*-lft-identity [<=]96.5% | \[ x + \left(-1 \cdot \frac{y \cdot a}{t} + \color{blue}{1 \cdot \frac{y \cdot z}{t}}\right)
\] |
metadata-eval [<=]96.5% | \[ x + \left(-1 \cdot \frac{y \cdot a}{t} + \color{blue}{\left(--1\right)} \cdot \frac{y \cdot z}{t}\right)
\] |
cancel-sign-sub-inv [<=]96.5% | \[ x + \color{blue}{\left(-1 \cdot \frac{y \cdot a}{t} - -1 \cdot \frac{y \cdot z}{t}\right)}
\] |
distribute-lft-out-- [=>]96.5% | \[ x + \color{blue}{-1 \cdot \left(\frac{y \cdot a}{t} - \frac{y \cdot z}{t}\right)}
\] |
div-sub [<=]96.5% | \[ x + -1 \cdot \color{blue}{\frac{y \cdot a - y \cdot z}{t}}
\] |
mul-1-neg [=>]96.5% | \[ x + \color{blue}{\left(-\frac{y \cdot a - y \cdot z}{t}\right)}
\] |
unsub-neg [=>]96.5% | \[ \color{blue}{x - \frac{y \cdot a - y \cdot z}{t}}
\] |
distribute-lft-out-- [=>]96.5% | \[ x - \frac{\color{blue}{y \cdot \left(a - z\right)}}{t}
\] |
*-commutative [=>]96.5% | \[ x - \frac{\color{blue}{\left(a - z\right) \cdot y}}{t}
\] |
sub-neg [=>]96.5% | \[ x - \frac{\color{blue}{\left(a + \left(-z\right)\right)} \cdot y}{t}
\] |
mul-1-neg [<=]96.5% | \[ x - \frac{\left(a + \color{blue}{-1 \cdot z}\right) \cdot y}{t}
\] |
+-commutative [<=]96.5% | \[ x - \frac{\color{blue}{\left(-1 \cdot z + a\right)} \cdot y}{t}
\] |
if -1.35000000000000005e54 < t < 6.5000000000000005e49Initial program 93.4%
Simplified96.0%
[Start]93.4% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]93.4% | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
associate-/l* [=>]96.0% | \[ x + \left(y - \color{blue}{\frac{z - t}{\frac{a - t}{y}}}\right)
\] |
if 6.5000000000000005e49 < t Initial program 52.0%
Simplified74.7%
[Start]52.0% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]56.5% | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
associate-/l* [=>]74.7% | \[ x + \left(y - \color{blue}{\frac{z - t}{\frac{a - t}{y}}}\right)
\] |
Taylor expanded in t around inf 89.6%
Simplified99.8%
[Start]89.6% | \[ \left(-1 \cdot \frac{y \cdot a}{t} + x\right) - -1 \cdot \frac{y \cdot z}{t}
\] |
|---|---|
sub-neg [=>]89.6% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot a}{t} + x\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)}
\] |
+-commutative [=>]89.6% | \[ \color{blue}{\left(x + -1 \cdot \frac{y \cdot a}{t}\right)} + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
mul-1-neg [=>]89.6% | \[ \left(x + \color{blue}{\left(-\frac{y \cdot a}{t}\right)}\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
unsub-neg [=>]89.6% | \[ \color{blue}{\left(x - \frac{y \cdot a}{t}\right)} + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
associate-/l* [=>]89.6% | \[ \left(x - \color{blue}{\frac{y}{\frac{t}{a}}}\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
mul-1-neg [=>]89.6% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \left(-\color{blue}{\left(-\frac{y \cdot z}{t}\right)}\right)
\] |
remove-double-neg [=>]89.6% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \color{blue}{\frac{y \cdot z}{t}}
\] |
associate-/l* [=>]99.8% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \color{blue}{\frac{y}{\frac{t}{z}}}
\] |
Final simplification97.0%
| Alternative 1 | |
|---|---|
| Accuracy | 94.8% |
| Cost | 1096 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 1096 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.3% |
| Cost | 1096 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 1088 |
| Alternative 5 | |
|---|---|
| Accuracy | 77.0% |
| Cost | 976 |
| Alternative 6 | |
|---|---|
| Accuracy | 93.3% |
| Cost | 968 |
| Alternative 7 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 841 |
| Alternative 9 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Accuracy | 77.5% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 57.7% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 62.9% |
| Cost | 456 |
| Alternative 13 | |
|---|---|
| Accuracy | 48.9% |
| Cost | 64 |
herbie shell --seed 2023277
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
:precision binary64
:herbie-target
(if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))
(- (+ x y) (/ (* (- z t) y) (- a t))))