
(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 91.9%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.4
Applied egg-rr97.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= z -4e-51) t_1 (if (<= z 1.55e-20) (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 <= -4e-51) {
tmp = t_1;
} else if (z <= 1.55e-20) {
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 <= -4e-51) tmp = t_1; elseif (z <= 1.55e-20) 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, -4e-51], t$95$1, If[LessEqual[z, 1.55e-20], 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 -4 \cdot 10^{-51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.55 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -4e-51 or 1.55e-20 < z Initial program 87.5%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.4
Applied egg-rr97.4%
Taylor expanded in z around inf
Simplified89.7%
if -4e-51 < z < 1.55e-20Initial program 97.5%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.4
Applied egg-rr97.4%
Taylor expanded in z around 0
mul-1-negN/A
neg-lowering-neg.f6491.8
Simplified91.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) z x))) (if (<= z -1.7e-54) t_1 (if (<= z 5.1e-43) (- 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.7e-54) {
tmp = t_1;
} else if (z <= 5.1e-43) {
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.7e-54) tmp = t_1; elseif (z <= 5.1e-43) 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.7e-54], t$95$1, If[LessEqual[z, 5.1e-43], 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.7 \cdot 10^{-54}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.1 \cdot 10^{-43}:\\
\;\;\;\;x - \frac{y \cdot x}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.69999999999999994e-54 or 5.0999999999999997e-43 < z Initial program 88.0%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.5
Applied egg-rr97.5%
Taylor expanded in z around inf
Simplified88.9%
if -1.69999999999999994e-54 < z < 5.0999999999999997e-43Initial program 97.3%
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-*.f6489.2
Simplified89.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -7.5e-69) t_1 (if (<= t 1.6e-46) (* y (/ (- z x) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (t <= -7.5e-69) {
tmp = t_1;
} else if (t <= 1.6e-46) {
tmp = y * ((z - x) / t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(z / t), y, x) tmp = 0.0 if (t <= -7.5e-69) tmp = t_1; elseif (t <= 1.6e-46) tmp = Float64(y * Float64(Float64(z - x) / t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[t, -7.5e-69], t$95$1, If[LessEqual[t, 1.6e-46], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;t \leq -7.5 \cdot 10^{-69}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 1.6 \cdot 10^{-46}:\\
\;\;\;\;y \cdot \frac{z - x}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -7.5e-69 or 1.6e-46 < t Initial program 87.0%
+-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
Simplified87.6%
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6489.9
Applied egg-rr89.9%
if -7.5e-69 < t < 1.6e-46Initial program 98.9%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6479.9
Simplified79.9%
(FPCore (x y z t) :precision binary64 (if (<= t -3.6e-63) x (if (<= t 5.5e-54) (* (/ y t) z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3.6e-63) {
tmp = x;
} else if (t <= 5.5e-54) {
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 <= (-3.6d-63)) then
tmp = x
else if (t <= 5.5d-54) 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 <= -3.6e-63) {
tmp = x;
} else if (t <= 5.5e-54) {
tmp = (y / t) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3.6e-63: tmp = x elif t <= 5.5e-54: tmp = (y / t) * z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3.6e-63) tmp = x; elseif (t <= 5.5e-54) 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 <= -3.6e-63) tmp = x; elseif (t <= 5.5e-54) tmp = (y / t) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3.6e-63], x, If[LessEqual[t, 5.5e-54], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.6 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.5 \cdot 10^{-54}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -3.60000000000000008e-63 or 5.50000000000000046e-54 < t Initial program 87.2%
Taylor expanded in y around 0
Simplified62.2%
if -3.60000000000000008e-63 < t < 5.50000000000000046e-54Initial program 98.9%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6479.5
Simplified79.5%
Taylor expanded in z around inf
Simplified45.1%
associate-*r/N/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6453.5
Applied egg-rr53.5%
(FPCore (x y z t) :precision binary64 (if (<= x -7e-28) x (if (<= x 3.7e+15) (* y (/ z t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -7e-28) {
tmp = x;
} else if (x <= 3.7e+15) {
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 (x <= (-7d-28)) then
tmp = x
else if (x <= 3.7d+15) 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 (x <= -7e-28) {
tmp = x;
} else if (x <= 3.7e+15) {
tmp = y * (z / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -7e-28: tmp = x elif x <= 3.7e+15: tmp = y * (z / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -7e-28) tmp = x; elseif (x <= 3.7e+15) 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 (x <= -7e-28) tmp = x; elseif (x <= 3.7e+15) tmp = y * (z / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -7e-28], x, If[LessEqual[x, 3.7e+15], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-28}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{+15}:\\
\;\;\;\;y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -6.9999999999999999e-28 or 3.7e15 < x Initial program 91.5%
Taylor expanded in y around 0
Simplified56.2%
if -6.9999999999999999e-28 < x < 3.7e15Initial program 92.2%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6466.2
Simplified66.2%
Taylor expanded in z around inf
Simplified55.1%
(FPCore (x y z t) :precision binary64 (if (<= y -6.3e+240) (* x (/ y (- t))) (fma (/ y t) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6.3e+240) {
tmp = x * (y / -t);
} else {
tmp = fma((y / t), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -6.3e+240) tmp = Float64(x * Float64(y / Float64(-t))); else tmp = fma(Float64(y / t), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -6.3e+240], N[(x * N[(y / (-t)), $MachinePrecision]), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.3 \cdot 10^{+240}:\\
\;\;\;\;x \cdot \frac{y}{-t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z, x\right)\\
\end{array}
\end{array}
if y < -6.2999999999999997e240Initial program 79.8%
Taylor expanded in y around inf
div-subN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.7
Simplified97.7%
Taylor expanded in z around 0
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
neg-lowering-neg.f6484.4
Simplified84.4%
if -6.2999999999999997e240 < y Initial program 92.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
Simplified78.6%
(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 91.9%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.4
Applied egg-rr97.4%
Taylor expanded in z around inf
Simplified76.3%
(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 91.9%
Taylor expanded in y around 0
Simplified41.3%
(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 2024199
(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)))