
(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 8 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 (if (<= x -4e-153) (fma (/ y t) (- z x) x) (+ x (/ y (/ t (- z x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -4e-153) {
tmp = fma((y / t), (z - x), x);
} else {
tmp = x + (y / (t / (z - x)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -4e-153) tmp = fma(Float64(y / t), Float64(z - x), x); else tmp = Float64(x + Float64(y / Float64(t / Float64(z - x)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -4e-153], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(y / N[(t / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-153}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\
\end{array}
\end{array}
if x < -4.00000000000000016e-153Initial program 90.4%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6499.9
Applied egg-rr99.9%
if -4.00000000000000016e-153 < x Initial program 91.5%
associate-/l*N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.5
Applied egg-rr98.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* x (- 1.0 (/ y t))))) (if (<= x -8.5e+26) t_1 (if (<= x 3.5e-11) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x * (1.0 - (y / t));
double tmp;
if (x <= -8.5e+26) {
tmp = t_1;
} else if (x <= 3.5e-11) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x * Float64(1.0 - Float64(y / t))) tmp = 0.0 if (x <= -8.5e+26) tmp = t_1; elseif (x <= 3.5e-11) tmp = fma(Float64(z / t), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e+26], t$95$1, If[LessEqual[x, 3.5e-11], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -8.5e26 or 3.50000000000000019e-11 < x Initial program 90.8%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around 0
*-rgt-identityN/A
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f6491.6
Simplified91.6%
if -8.5e26 < x < 3.50000000000000019e-11Initial program 91.4%
Taylor expanded in z around inf
Simplified81.0%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f6486.7
Applied egg-rr86.7%
(FPCore (x y z t) :precision binary64 (if (<= y -1.55e+15) (* y (/ z t)) (if (<= y 1.6e-75) x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.55e+15) {
tmp = y * (z / t);
} else if (y <= 1.6e-75) {
tmp = x;
} else {
tmp = (y / t) * z;
}
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 (y <= (-1.55d+15)) then
tmp = y * (z / t)
else if (y <= 1.6d-75) then
tmp = x
else
tmp = (y / t) * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.55e+15) {
tmp = y * (z / t);
} else if (y <= 1.6e-75) {
tmp = x;
} else {
tmp = (y / t) * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.55e+15: tmp = y * (z / t) elif y <= 1.6e-75: tmp = x else: tmp = (y / t) * z return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.55e+15) tmp = Float64(y * Float64(z / t)); elseif (y <= 1.6e-75) tmp = x; else tmp = Float64(Float64(y / t) * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.55e+15) tmp = y * (z / t); elseif (y <= 1.6e-75) tmp = x; else tmp = (y / t) * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.55e+15], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.6e-75], x, N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+15}:\\
\;\;\;\;y \cdot \frac{z}{t}\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\end{array}
\end{array}
if y < -1.55e15Initial program 86.1%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.0
Applied egg-rr97.0%
Taylor expanded in z around inf
/-lowering-/.f64N/A
remove-double-negN/A
distribute-lft-neg-outN/A
mul-1-negN/A
neg-sub0N/A
sub-negN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
+-commutativeN/A
accelerator-lowering-fma.f6450.4
Simplified50.4%
+-rgt-identityN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6458.7
Applied egg-rr58.7%
if -1.55e15 < y < 1.59999999999999988e-75Initial program 96.7%
Taylor expanded in y around 0
Simplified65.1%
if 1.59999999999999988e-75 < y Initial program 86.1%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6495.6
Applied egg-rr95.6%
Taylor expanded in z around inf
/-lowering-/.f64N/A
remove-double-negN/A
distribute-lft-neg-outN/A
mul-1-negN/A
neg-sub0N/A
sub-negN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
+-commutativeN/A
accelerator-lowering-fma.f6440.9
Simplified40.9%
+-rgt-identityN/A
associate-*l/N/A
*-lowering-*.f64N/A
/-lowering-/.f6449.0
Applied egg-rr49.0%
(FPCore (x y z t) :precision binary64 (if (<= x -5.8e-21) x (if (<= x 1.1e-99) (* y (/ z t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -5.8e-21) {
tmp = x;
} else if (x <= 1.1e-99) {
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 <= (-5.8d-21)) then
tmp = x
else if (x <= 1.1d-99) 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 <= -5.8e-21) {
tmp = x;
} else if (x <= 1.1e-99) {
tmp = y * (z / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -5.8e-21: tmp = x elif x <= 1.1e-99: tmp = y * (z / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -5.8e-21) tmp = x; elseif (x <= 1.1e-99) 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 <= -5.8e-21) tmp = x; elseif (x <= 1.1e-99) tmp = y * (z / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -5.8e-21], x, If[LessEqual[x, 1.1e-99], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-99}:\\
\;\;\;\;y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -5.8e-21 or 1.10000000000000002e-99 < x Initial program 91.3%
Taylor expanded in y around 0
Simplified52.1%
if -5.8e-21 < x < 1.10000000000000002e-99Initial program 90.8%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6492.7
Applied egg-rr92.7%
Taylor expanded in z around inf
/-lowering-/.f64N/A
remove-double-negN/A
distribute-lft-neg-outN/A
mul-1-negN/A
neg-sub0N/A
sub-negN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
+-commutativeN/A
accelerator-lowering-fma.f6463.4
Simplified63.4%
+-rgt-identityN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6468.8
Applied egg-rr68.8%
(FPCore (x y z t) :precision binary64 (if (<= x -1.52e-135) (fma (/ y t) (- z x) x) (fma (/ (- z x) t) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.52e-135) {
tmp = fma((y / t), (z - x), x);
} else {
tmp = fma(((z - x) / t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -1.52e-135) tmp = fma(Float64(y / t), Float64(z - x), x); else tmp = fma(Float64(Float64(z - x) / t), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.52e-135], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{-135}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\
\end{array}
\end{array}
if x < -1.5200000000000001e-135Initial program 89.8%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6499.9
Applied egg-rr99.9%
if -1.5200000000000001e-135 < x Initial program 91.8%
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6498.1
Applied egg-rr98.1%
(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.1%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.0
Applied egg-rr97.0%
(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.1%
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
--lowering--.f6497.0
Applied egg-rr97.0%
Taylor expanded in z around inf
Simplified77.4%
(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.1%
Taylor expanded in y around 0
Simplified39.4%
(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 2024196
(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)))