
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
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)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
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)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- z a)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (z - a)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(z - a)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{z - a}, y, x\right)
\end{array}
Initial program 87.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* y (/ (- z t) (- z a)))) (t_2 (/ (* y (- z t)) (- z a))))
(if (<= t_2 -1e+105)
t_1
(if (<= t_2 1e+112) (+ (/ (* y z) (- z a)) x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = y * ((z - t) / (z - a));
double t_2 = (y * (z - t)) / (z - a);
double tmp;
if (t_2 <= -1e+105) {
tmp = t_1;
} else if (t_2 <= 1e+112) {
tmp = ((y * z) / (z - a)) + x;
} else {
tmp = t_1;
}
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
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = y * ((z - t) / (z - a))
t_2 = (y * (z - t)) / (z - a)
if (t_2 <= (-1d+105)) then
tmp = t_1
else if (t_2 <= 1d+112) then
tmp = ((y * z) / (z - a)) + x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = y * ((z - t) / (z - a));
double t_2 = (y * (z - t)) / (z - a);
double tmp;
if (t_2 <= -1e+105) {
tmp = t_1;
} else if (t_2 <= 1e+112) {
tmp = ((y * z) / (z - a)) + x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = y * ((z - t) / (z - a)) t_2 = (y * (z - t)) / (z - a) tmp = 0 if t_2 <= -1e+105: tmp = t_1 elif t_2 <= 1e+112: tmp = ((y * z) / (z - a)) + x else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(y * Float64(Float64(z - t) / Float64(z - a))) t_2 = Float64(Float64(y * Float64(z - t)) / Float64(z - a)) tmp = 0.0 if (t_2 <= -1e+105) tmp = t_1; elseif (t_2 <= 1e+112) tmp = Float64(Float64(Float64(y * z) / Float64(z - a)) + x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = y * ((z - t) / (z - a)); t_2 = (y * (z - t)) / (z - a); tmp = 0.0; if (t_2 <= -1e+105) tmp = t_1; elseif (t_2 <= 1e+112) tmp = ((y * z) / (z - a)) + x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+105], t$95$1, If[LessEqual[t$95$2, 1e+112], N[(N[(N[(y * z), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - t}{z - a}\\
t_2 := \frac{y \cdot \left(z - t\right)}{z - a}\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{+105}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 10^{+112}:\\
\;\;\;\;\frac{y \cdot z}{z - a} + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < -9.9999999999999994e104 or 9.9999999999999993e111 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) Initial program 60.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.7
Applied rewrites96.7%
Taylor expanded in z around 0
lower-/.f6443.0
Applied rewrites43.0%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6483.2
Applied rewrites83.2%
if -9.9999999999999994e104 < (/.f64 (*.f64 y (-.f64 z t)) (-.f64 z a)) < 9.9999999999999993e111Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6485.3
Applied rewrites85.3%
Final simplification84.6%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- z a) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
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 - a) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((z - a) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(z - a) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((z - a) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{z - a}{z - t}}
\end{array}
herbie shell --seed 2024230
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- z a) (- z t)))))
(+ x (/ (* y (- z t)) (- z a))))