(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* y (/ (- z t) (- a t))))
(t_2 (+ x (/ (* (- y x) (- z t)) (- a t))))
(t_3 (/ (- a t) (- z t))))
(if (<= t_2 -2e-223)
(+ t_1 (* x (- 1.0 (pow t_3 -1.0))))
(if (<= t_2 0.0)
(+ t_1 (* x (/ (- z a) t)))
(+ (/ y t_3) (* x (+ (/ (- t z) (- a t)) 1.0)))))))double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
double t_1 = y * ((z - t) / (a - t));
double t_2 = x + (((y - x) * (z - t)) / (a - t));
double t_3 = (a - t) / (z - t);
double tmp;
if (t_2 <= -2e-223) {
tmp = t_1 + (x * (1.0 - pow(t_3, -1.0)));
} else if (t_2 <= 0.0) {
tmp = t_1 + (x * ((z - a) / t));
} else {
tmp = (y / t_3) + (x * (((t - z) / (a - t)) + 1.0));
}
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 - x) * (z - t)) / (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) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = y * ((z - t) / (a - t))
t_2 = x + (((y - x) * (z - t)) / (a - t))
t_3 = (a - t) / (z - t)
if (t_2 <= (-2d-223)) then
tmp = t_1 + (x * (1.0d0 - (t_3 ** (-1.0d0))))
else if (t_2 <= 0.0d0) then
tmp = t_1 + (x * ((z - a) / t))
else
tmp = (y / t_3) + (x * (((t - z) / (a - t)) + 1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = y * ((z - t) / (a - t));
double t_2 = x + (((y - x) * (z - t)) / (a - t));
double t_3 = (a - t) / (z - t);
double tmp;
if (t_2 <= -2e-223) {
tmp = t_1 + (x * (1.0 - Math.pow(t_3, -1.0)));
} else if (t_2 <= 0.0) {
tmp = t_1 + (x * ((z - a) / t));
} else {
tmp = (y / t_3) + (x * (((t - z) / (a - t)) + 1.0));
}
return tmp;
}
def code(x, y, z, t, a): return x + (((y - x) * (z - t)) / (a - t))
def code(x, y, z, t, a): t_1 = y * ((z - t) / (a - t)) t_2 = x + (((y - x) * (z - t)) / (a - t)) t_3 = (a - t) / (z - t) tmp = 0 if t_2 <= -2e-223: tmp = t_1 + (x * (1.0 - math.pow(t_3, -1.0))) elif t_2 <= 0.0: tmp = t_1 + (x * ((z - a) / t)) else: tmp = (y / t_3) + (x * (((t - z) / (a - t)) + 1.0)) return tmp
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) end
function code(x, y, z, t, a) t_1 = Float64(y * Float64(Float64(z - t) / Float64(a - t))) t_2 = Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) t_3 = Float64(Float64(a - t) / Float64(z - t)) tmp = 0.0 if (t_2 <= -2e-223) tmp = Float64(t_1 + Float64(x * Float64(1.0 - (t_3 ^ -1.0)))); elseif (t_2 <= 0.0) tmp = Float64(t_1 + Float64(x * Float64(Float64(z - a) / t))); else tmp = Float64(Float64(y / t_3) + Float64(x * Float64(Float64(Float64(t - z) / Float64(a - t)) + 1.0))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = x + (((y - x) * (z - t)) / (a - t)); end
function tmp_2 = code(x, y, z, t, a) t_1 = y * ((z - t) / (a - t)); t_2 = x + (((y - x) * (z - t)) / (a - t)); t_3 = (a - t) / (z - t); tmp = 0.0; if (t_2 <= -2e-223) tmp = t_1 + (x * (1.0 - (t_3 ^ -1.0))); elseif (t_2 <= 0.0) tmp = t_1 + (x * ((z - a) / t)); else tmp = (y / t_3) + (x * (((t - z) / (a - t)) + 1.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e-223], N[(t$95$1 + N[(x * N[(1.0 - N[Power[t$95$3, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], N[(t$95$1 + N[(x * N[(N[(z - a), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / t$95$3), $MachinePrecision] + N[(x * N[(N[(N[(t - z), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\begin{array}{l}
t_1 := y \cdot \frac{z - t}{a - t}\\
t_2 := x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}\\
t_3 := \frac{a - t}{z - t}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{-223}:\\
\;\;\;\;t_1 + x \cdot \left(1 - {t_3}^{-1}\right)\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;t_1 + x \cdot \frac{z - a}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t_3} + x \cdot \left(\frac{t - z}{a - t} + 1\right)\\
\end{array}
Results
| Original | 24.3 |
|---|---|
| Target | 9.3 |
| Herbie | 5.2 |
if (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -1.9999999999999999e-223Initial program 21.3
Simplified9.8
Taylor expanded in x around -inf 14.6
Simplified4.7
Applied egg-rr4.7
if -1.9999999999999999e-223 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 0.0Initial program 53.4
Simplified54.1
Taylor expanded in x around -inf 15.7
Simplified29.7
Taylor expanded in t around inf 6.8
Simplified7.0
if 0.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) Initial program 21.1
Simplified10.7
Taylor expanded in x around -inf 14.9
Simplified5.2
Applied egg-rr5.2
Final simplification5.2
herbie shell --seed 2022210
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:linMap from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< a -1.6153062845442575e-142) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t)))) (if (< a 3.774403170083174e-182) (- y (* (/ z t) (- y x))) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t))))))
(+ x (/ (* (- y x) (- z t)) (- a t))))