
(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 8 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 81.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
(FPCore (x y z t a) :precision binary64 (if (<= z -5.8e-24) (fma y (- 1.0 (/ t z)) x) (if (<= z 0.0065) (fma (/ (- t z) a) y x) (fma z (/ y (- z a)) x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -5.8e-24) {
tmp = fma(y, (1.0 - (t / z)), x);
} else if (z <= 0.0065) {
tmp = fma(((t - z) / a), y, x);
} else {
tmp = fma(z, (y / (z - a)), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -5.8e-24) tmp = fma(y, Float64(1.0 - Float64(t / z)), x); elseif (z <= 0.0065) tmp = fma(Float64(Float64(t - z) / a), y, x); else tmp = fma(z, Float64(y / Float64(z - a)), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -5.8e-24], N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 0.0065], N[(N[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] * y + x), $MachinePrecision], N[(z * N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(y, 1 - \frac{t}{z}, x\right)\\
\mathbf{elif}\;z \leq 0.0065:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - z}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{z - a}, x\right)\\
\end{array}
\end{array}
if z < -5.7999999999999997e-24Initial program 73.4%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
if -5.7999999999999997e-24 < z < 0.0064999999999999997Initial program 93.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.8
Applied rewrites96.8%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6482.5
Applied rewrites82.5%
if 0.0064999999999999997 < z Initial program 68.1%
Taylor expanded in t around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6485.8
Applied rewrites85.8%
(FPCore (x y z t a) :precision binary64 (if (<= z -4e-29) (fma y (- 1.0 (/ t z)) x) (if (<= z 8.4e-14) (fma t (/ y a) x) (fma z (/ y (- z a)) x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -4e-29) {
tmp = fma(y, (1.0 - (t / z)), x);
} else if (z <= 8.4e-14) {
tmp = fma(t, (y / a), x);
} else {
tmp = fma(z, (y / (z - a)), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -4e-29) tmp = fma(y, Float64(1.0 - Float64(t / z)), x); elseif (z <= 8.4e-14) tmp = fma(t, Float64(y / a), x); else tmp = fma(z, Float64(y / Float64(z - a)), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4e-29], N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 8.4e-14], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(z * N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(y, 1 - \frac{t}{z}, x\right)\\
\mathbf{elif}\;z \leq 8.4 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{z - a}, x\right)\\
\end{array}
\end{array}
if z < -3.99999999999999977e-29Initial program 73.7%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f6490.7
Applied rewrites90.7%
if -3.99999999999999977e-29 < z < 8.3999999999999995e-14Initial program 93.5%
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
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.1
Applied rewrites80.1%
if 8.3999999999999995e-14 < z Initial program 69.6%
Taylor expanded in t around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6484.9
Applied rewrites84.9%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (fma y (- 1.0 (/ t z)) x))) (if (<= z -4e-29) t_1 (if (<= z 0.012) (fma t (/ y a) x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma(y, (1.0 - (t / z)), x);
double tmp;
if (z <= -4e-29) {
tmp = t_1;
} else if (z <= 0.012) {
tmp = fma(t, (y / a), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(y, Float64(1.0 - Float64(t / z)), x) tmp = 0.0 if (z <= -4e-29) tmp = t_1; elseif (z <= 0.012) tmp = fma(t, Float64(y / a), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -4e-29], t$95$1, If[LessEqual[z, 0.012], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, 1 - \frac{t}{z}, x\right)\\
\mathbf{if}\;z \leq -4 \cdot 10^{-29}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 0.012:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.99999999999999977e-29 or 0.012 < z Initial program 71.1%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
if -3.99999999999999977e-29 < z < 0.012Initial program 93.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.8
Applied rewrites96.8%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6479.0
Applied rewrites79.0%
(FPCore (x y z t a) :precision binary64 (if (<= z -4.5e-29) (+ y x) (if (<= z 0.052) (fma t (/ y a) x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -4.5e-29) {
tmp = y + x;
} else if (z <= 0.052) {
tmp = fma(t, (y / a), x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -4.5e-29) tmp = Float64(y + x); elseif (z <= 0.052) tmp = fma(t, Float64(y / a), x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4.5e-29], N[(y + x), $MachinePrecision], If[LessEqual[z, 0.052], N[(t * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-29}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 0.052:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -4.4999999999999998e-29 or 0.0519999999999999976 < z Initial program 71.1%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6480.3
Applied rewrites80.3%
if -4.4999999999999998e-29 < z < 0.0519999999999999976Initial program 93.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.8
Applied rewrites96.8%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6479.0
Applied rewrites79.0%
(FPCore (x y z t a) :precision binary64 (if (<= z -1.55e-23) (+ y x) (if (<= z 0.08) (fma y (/ t a) x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.55e-23) {
tmp = y + x;
} else if (z <= 0.08) {
tmp = fma(y, (t / a), x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -1.55e-23) tmp = Float64(y + x); elseif (z <= 0.08) tmp = fma(y, Float64(t / a), x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -1.55e-23], N[(y + x), $MachinePrecision], If[LessEqual[z, 0.08], N[(y * N[(t / a), $MachinePrecision] + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{-23}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 0.08:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{t}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -1.5499999999999999e-23 or 0.0800000000000000017 < z Initial program 70.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6480.9
Applied rewrites80.9%
if -1.5499999999999999e-23 < z < 0.0800000000000000017Initial program 93.7%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.6
Applied rewrites76.6%
(FPCore (x y z t a) :precision binary64 (fma (/ y (- z a)) (- z t) x))
double code(double x, double y, double z, double t, double a) {
return fma((y / (z - a)), (z - t), x);
}
function code(x, y, z, t, a) return fma(Float64(y / Float64(z - a)), Float64(z - t), x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] * N[(z - t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z - a}, z - t, x\right)
\end{array}
Initial program 81.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.4
Applied rewrites95.4%
(FPCore (x y z t a) :precision binary64 (+ y x))
double code(double x, double y, double z, double t, double a) {
return y + x;
}
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 = y + x
end function
public static double code(double x, double y, double z, double t, double a) {
return y + x;
}
def code(x, y, z, t, a): return y + x
function code(x, y, z, t, a) return Float64(y + x) end
function tmp = code(x, y, z, t, a) tmp = y + x; end
code[x_, y_, z_, t_, a_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
y + x
\end{array}
Initial program 81.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6462.3
Applied rewrites62.3%
(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 2024220
(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))))