| Alternative 1 | |
|---|---|
| Error | 14.1 |
| Cost | 1104 |
(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 -2.9e+185)
(+ x (/ y (/ t (- z a))))
(if (<= t 1.25e+183)
(+ x (- y (/ y (/ (- a t) (- z t)))))
(+ x (* y (/ (- z a) t))))))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 <= -2.9e+185) {
tmp = x + (y / (t / (z - a)));
} else if (t <= 1.25e+183) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x + (y * ((z - a) / t));
}
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 <= (-2.9d+185)) then
tmp = x + (y / (t / (z - a)))
else if (t <= 1.25d+183) then
tmp = x + (y - (y / ((a - t) / (z - t))))
else
tmp = x + (y * ((z - a) / t))
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 <= -2.9e+185) {
tmp = x + (y / (t / (z - a)));
} else if (t <= 1.25e+183) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x + (y * ((z - a) / t));
}
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 <= -2.9e+185: tmp = x + (y / (t / (z - a))) elif t <= 1.25e+183: tmp = x + (y - (y / ((a - t) / (z - t)))) else: tmp = x + (y * ((z - a) / t)) 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 <= -2.9e+185) tmp = Float64(x + Float64(y / Float64(t / Float64(z - a)))); elseif (t <= 1.25e+183) tmp = Float64(x + Float64(y - Float64(y / Float64(Float64(a - t) / Float64(z - t))))); else tmp = Float64(x + Float64(y * Float64(Float64(z - a) / t))); 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 <= -2.9e+185) tmp = x + (y / (t / (z - a))); elseif (t <= 1.25e+183) tmp = x + (y - (y / ((a - t) / (z - t)))); else tmp = x + (y * ((z - a) / t)); 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, -2.9e+185], N[(x + N[(y / N[(t / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.25e+183], N[(x + N[(y - N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(z - a), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -2.9 \cdot 10^{+185}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z - a}}\\
\mathbf{elif}\;t \leq 1.25 \cdot 10^{+183}:\\
\;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z - a}{t}\\
\end{array}
Results
| Original | 16.7 |
|---|---|
| Target | 8.4 |
| Herbie | 5.7 |
if t < -2.89999999999999988e185Initial program 34.4
Simplified13.4
[Start]34.4 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]34.4 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]34.4 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]29.8 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]29.8 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]29.8 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]13.4 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
Taylor expanded in t around inf 14.3
Simplified14.3
[Start]14.3 | \[ x + \frac{-1 \cdot \left(a \cdot y\right) - -1 \cdot \left(y \cdot z\right)}{t}
\] |
|---|---|
*-commutative [<=]14.3 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot a\right)} - -1 \cdot \left(y \cdot z\right)}{t}
\] |
distribute-lft-out-- [=>]14.3 | \[ x + \frac{\color{blue}{-1 \cdot \left(y \cdot a - y \cdot z\right)}}{t}
\] |
distribute-lft-out-- [=>]14.3 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot \left(a - z\right)\right)}}{t}
\] |
associate-*r* [=>]14.3 | \[ x + \frac{\color{blue}{\left(-1 \cdot y\right) \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]14.3 | \[ x + \frac{\color{blue}{\left(-y\right)} \cdot \left(a - z\right)}{t}
\] |
Taylor expanded in y around 0 14.3
Simplified4.7
[Start]14.3 | \[ x + -1 \cdot \frac{y \cdot \left(a - z\right)}{t}
\] |
|---|---|
associate-*r/ [=>]14.3 | \[ x + \color{blue}{\frac{-1 \cdot \left(y \cdot \left(a - z\right)\right)}{t}}
\] |
associate-*l/ [<=]14.4 | \[ x + \color{blue}{\frac{-1}{t} \cdot \left(y \cdot \left(a - z\right)\right)}
\] |
*-commutative [=>]14.4 | \[ x + \color{blue}{\left(y \cdot \left(a - z\right)\right) \cdot \frac{-1}{t}}
\] |
associate-*l* [=>]4.7 | \[ x + \color{blue}{y \cdot \left(\left(a - z\right) \cdot \frac{-1}{t}\right)}
\] |
associate-*r/ [=>]4.7 | \[ x + y \cdot \color{blue}{\frac{\left(a - z\right) \cdot -1}{t}}
\] |
*-commutative [=>]4.7 | \[ x + y \cdot \frac{\color{blue}{-1 \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]4.7 | \[ x + y \cdot \frac{\color{blue}{-\left(a - z\right)}}{t}
\] |
neg-sub0 [=>]4.7 | \[ x + y \cdot \frac{\color{blue}{0 - \left(a - z\right)}}{t}
\] |
sub-neg [=>]4.7 | \[ x + y \cdot \frac{0 - \color{blue}{\left(a + \left(-z\right)\right)}}{t}
\] |
+-commutative [<=]4.7 | \[ x + y \cdot \frac{0 - \color{blue}{\left(\left(-z\right) + a\right)}}{t}
\] |
associate--r+ [=>]4.7 | \[ x + y \cdot \frac{\color{blue}{\left(0 - \left(-z\right)\right) - a}}{t}
\] |
neg-sub0 [<=]4.7 | \[ x + y \cdot \frac{\color{blue}{\left(-\left(-z\right)\right)} - a}{t}
\] |
remove-double-neg [=>]4.7 | \[ x + y \cdot \frac{\color{blue}{z} - a}{t}
\] |
Applied egg-rr4.8
if -2.89999999999999988e185 < t < 1.25000000000000002e183Initial program 11.7
Simplified5.9
[Start]11.7 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]11.7 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]11.7 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]10.3 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]10.3 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]10.3 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]5.9 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
if 1.25000000000000002e183 < t Initial program 34.7
Simplified13.8
[Start]34.7 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]34.7 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]34.7 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]30.0 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]30.0 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]30.0 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]13.8 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
Taylor expanded in t around inf 14.5
Simplified14.5
[Start]14.5 | \[ x + \frac{-1 \cdot \left(a \cdot y\right) - -1 \cdot \left(y \cdot z\right)}{t}
\] |
|---|---|
*-commutative [<=]14.5 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot a\right)} - -1 \cdot \left(y \cdot z\right)}{t}
\] |
distribute-lft-out-- [=>]14.5 | \[ x + \frac{\color{blue}{-1 \cdot \left(y \cdot a - y \cdot z\right)}}{t}
\] |
distribute-lft-out-- [=>]14.5 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot \left(a - z\right)\right)}}{t}
\] |
associate-*r* [=>]14.5 | \[ x + \frac{\color{blue}{\left(-1 \cdot y\right) \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]14.5 | \[ x + \frac{\color{blue}{\left(-y\right)} \cdot \left(a - z\right)}{t}
\] |
Taylor expanded in y around 0 14.5
Simplified5.3
[Start]14.5 | \[ x + -1 \cdot \frac{y \cdot \left(a - z\right)}{t}
\] |
|---|---|
associate-*r/ [=>]14.5 | \[ x + \color{blue}{\frac{-1 \cdot \left(y \cdot \left(a - z\right)\right)}{t}}
\] |
associate-*l/ [<=]14.5 | \[ x + \color{blue}{\frac{-1}{t} \cdot \left(y \cdot \left(a - z\right)\right)}
\] |
*-commutative [=>]14.5 | \[ x + \color{blue}{\left(y \cdot \left(a - z\right)\right) \cdot \frac{-1}{t}}
\] |
associate-*l* [=>]5.3 | \[ x + \color{blue}{y \cdot \left(\left(a - z\right) \cdot \frac{-1}{t}\right)}
\] |
associate-*r/ [=>]5.3 | \[ x + y \cdot \color{blue}{\frac{\left(a - z\right) \cdot -1}{t}}
\] |
*-commutative [=>]5.3 | \[ x + y \cdot \frac{\color{blue}{-1 \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]5.3 | \[ x + y \cdot \frac{\color{blue}{-\left(a - z\right)}}{t}
\] |
neg-sub0 [=>]5.3 | \[ x + y \cdot \frac{\color{blue}{0 - \left(a - z\right)}}{t}
\] |
sub-neg [=>]5.3 | \[ x + y \cdot \frac{0 - \color{blue}{\left(a + \left(-z\right)\right)}}{t}
\] |
+-commutative [<=]5.3 | \[ x + y \cdot \frac{0 - \color{blue}{\left(\left(-z\right) + a\right)}}{t}
\] |
associate--r+ [=>]5.3 | \[ x + y \cdot \frac{\color{blue}{\left(0 - \left(-z\right)\right) - a}}{t}
\] |
neg-sub0 [<=]5.3 | \[ x + y \cdot \frac{\color{blue}{\left(-\left(-z\right)\right)} - a}{t}
\] |
remove-double-neg [=>]5.3 | \[ x + y \cdot \frac{\color{blue}{z} - a}{t}
\] |
Final simplification5.7
| Alternative 1 | |
|---|---|
| Error | 14.1 |
| Cost | 1104 |
| Alternative 2 | |
|---|---|
| Error | 11.5 |
| Cost | 1104 |
| Alternative 3 | |
|---|---|
| Error | 9.2 |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Error | 10.5 |
| Cost | 840 |
| Alternative 5 | |
|---|---|
| Error | 14.8 |
| Cost | 712 |
| Alternative 6 | |
|---|---|
| Error | 20.4 |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Error | 29.0 |
| Cost | 64 |
herbie shell --seed 2023066
(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))))