
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
return fma((y / t), (z - x), x);
}
function code(x, y, z, t) return fma(Float64(y / t), Float64(z - x), x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Initial program 93.6%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.6
Applied egg-rr97.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= z -8e+49) t_1 (if (<= z 1.06e-47) (fma (/ y t) (- x) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), z, x);
double tmp;
if (z <= -8e+49) {
tmp = t_1;
} else if (z <= 1.06e-47) {
tmp = fma((y / t), -x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), z, x) tmp = 0.0 if (z <= -8e+49) tmp = t_1; elseif (z <= 1.06e-47) tmp = fma(Float64(y / t), Float64(-x), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -8e+49], t$95$1, If[LessEqual[z, 1.06e-47], N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{if}\;z \leq -8 \cdot 10^{+49}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.06 \cdot 10^{-47}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -7.99999999999999957e49 or 1.06e-47 < z Initial program 93.8%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6499.0
Applied egg-rr99.0%
Taylor expanded in z around inf
Simplified93.6%
if -7.99999999999999957e49 < z < 1.06e-47Initial program 93.3%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6496.3
Applied egg-rr96.3%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6487.1
Simplified87.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= z -1.14e-94) t_1 (if (<= z 2.1e-51) (- x (/ (* y x) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), z, x);
double tmp;
if (z <= -1.14e-94) {
tmp = t_1;
} else if (z <= 2.1e-51) {
tmp = x - ((y * x) / t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), z, x) tmp = 0.0 if (z <= -1.14e-94) tmp = t_1; elseif (z <= 2.1e-51) tmp = Float64(x - Float64(Float64(y * x) / t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -1.14e-94], t$95$1, If[LessEqual[z, 2.1e-51], N[(x - N[(N[(y * x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{if}\;z \leq -1.14 \cdot 10^{-94}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-51}:\\
\;\;\;\;x - \frac{y \cdot x}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.14e-94 or 2.10000000000000002e-51 < z Initial program 92.2%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.6
Applied egg-rr98.6%
Taylor expanded in z around inf
Simplified89.2%
if -1.14e-94 < z < 2.10000000000000002e-51Initial program 95.5%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-/l*N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6488.8
Simplified88.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ (- z x) t)))) (if (<= y -1.26e+56) t_1 (if (<= y 1.4e+115) (+ x (/ (* y z) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -1.26e+56) {
tmp = t_1;
} else if (y <= 1.4e+115) {
tmp = x + ((y * z) / t);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * ((z - x) / t)
if (y <= (-1.26d+56)) then
tmp = t_1
else if (y <= 1.4d+115) then
tmp = x + ((y * z) / t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -1.26e+56) {
tmp = t_1;
} else if (y <= 1.4e+115) {
tmp = x + ((y * z) / t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * ((z - x) / t) tmp = 0 if y <= -1.26e+56: tmp = t_1 elif y <= 1.4e+115: tmp = x + ((y * z) / t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (y <= -1.26e+56) tmp = t_1; elseif (y <= 1.4e+115) tmp = Float64(x + Float64(Float64(y * z) / t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * ((z - x) / t); tmp = 0.0; if (y <= -1.26e+56) tmp = t_1; elseif (y <= 1.4e+115) tmp = x + ((y * z) / t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.26e+56], t$95$1, If[LessEqual[y, 1.4e+115], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -1.26 \cdot 10^{+56}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+115}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.2599999999999999e56 or 1.4e115 < y Initial program 87.5%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6486.9
Simplified86.9%
if -1.2599999999999999e56 < y < 1.4e115Initial program 96.8%
Taylor expanded in z around inf
/-lowering-/.f64N/A
*-lowering-*.f6486.3
Simplified86.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ (- z x) t)))) (if (<= y -8.5e+52) t_1 (if (<= y 9.5e+114) (fma (/ y t) z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -8.5e+52) {
tmp = t_1;
} else if (y <= 9.5e+114) {
tmp = fma((y / t), z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (y <= -8.5e+52) tmp = t_1; elseif (y <= 9.5e+114) tmp = fma(Float64(y / t), z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.5e+52], t$95$1, If[LessEqual[y, 9.5e+114], N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+52}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.49999999999999994e52 or 9.5000000000000001e114 < y Initial program 87.5%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6486.9
Simplified86.9%
if -8.49999999999999994e52 < y < 9.5000000000000001e114Initial program 96.8%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.7
Applied egg-rr98.7%
Taylor expanded in z around inf
Simplified86.1%
(FPCore (x y z t) :precision binary64 (if (<= t -2.6e+76) x (if (<= t 5.6e+42) (* (/ y t) z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.6e+76) {
tmp = x;
} else if (t <= 5.6e+42) {
tmp = (y / t) * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-2.6d+76)) then
tmp = x
else if (t <= 5.6d+42) then
tmp = (y / t) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.6e+76) {
tmp = x;
} else if (t <= 5.6e+42) {
tmp = (y / t) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.6e+76: tmp = x elif t <= 5.6e+42: tmp = (y / t) * z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.6e+76) tmp = x; elseif (t <= 5.6e+42) tmp = Float64(Float64(y / t) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.6e+76) tmp = x; elseif (t <= 5.6e+42) tmp = (y / t) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.6e+76], x, If[LessEqual[t, 5.6e+42], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.6 \cdot 10^{+76}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.6 \cdot 10^{+42}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -2.5999999999999999e76 or 5.5999999999999999e42 < t Initial program 88.5%
Taylor expanded in y around 0
Simplified67.0%
if -2.5999999999999999e76 < t < 5.5999999999999999e42Initial program 97.1%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6473.6
Simplified73.6%
Taylor expanded in z around inf
Simplified47.2%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6454.7
Applied egg-rr54.7%
(FPCore (x y z t) :precision binary64 (if (<= t -9.2e+76) x (if (<= t 2.5e+43) (* y (/ z t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -9.2e+76) {
tmp = x;
} else if (t <= 2.5e+43) {
tmp = y * (z / t);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-9.2d+76)) then
tmp = x
else if (t <= 2.5d+43) then
tmp = y * (z / t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -9.2e+76) {
tmp = x;
} else if (t <= 2.5e+43) {
tmp = y * (z / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -9.2e+76: tmp = x elif t <= 2.5e+43: tmp = y * (z / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -9.2e+76) tmp = x; elseif (t <= 2.5e+43) tmp = Float64(y * Float64(z / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -9.2e+76) tmp = x; elseif (t <= 2.5e+43) tmp = y * (z / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -9.2e+76], x, If[LessEqual[t, 2.5e+43], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -9.2 \cdot 10^{+76}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 2.5 \cdot 10^{+43}:\\
\;\;\;\;y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -9.20000000000000005e76 or 2.5000000000000002e43 < t Initial program 88.5%
Taylor expanded in y around 0
Simplified67.0%
if -9.20000000000000005e76 < t < 2.5000000000000002e43Initial program 97.1%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6473.6
Simplified73.6%
Taylor expanded in z around inf
Simplified47.2%
(FPCore (x y z t) :precision binary64 (fma (/ y t) z x))
double code(double x, double y, double z, double t) {
return fma((y / t), z, x);
}
function code(x, y, z, t) return fma(Float64(y / t), z, x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z, x\right)
\end{array}
Initial program 93.6%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.6
Applied egg-rr97.6%
Taylor expanded in z around inf
Simplified75.5%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 93.6%
Taylor expanded in y around 0
Simplified37.8%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2024201
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
(+ x (/ (* y (- z x)) t)))