
(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 7 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 92.2%
lift--.f64N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.0
Applied egg-rr98.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) (- x) x))) (if (<= x -5e-57) t_1 (if (<= x 0.0033) (fma z (/ y t) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), -x, x);
double tmp;
if (x <= -5e-57) {
tmp = t_1;
} else if (x <= 0.0033) {
tmp = fma(z, (y / t), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), Float64(-x), x) tmp = 0.0 if (x <= -5e-57) tmp = t_1; elseif (x <= 0.0033) tmp = fma(z, Float64(y / t), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision]}, If[LessEqual[x, -5e-57], t$95$1, If[LessEqual[x, 0.0033], N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{if}\;x \leq -5 \cdot 10^{-57}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 0.0033:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -5.0000000000000002e-57 or 0.0033 < x Initial program 91.7%
lift--.f64N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6489.8
Simplified89.8%
if -5.0000000000000002e-57 < x < 0.0033Initial program 92.9%
Taylor expanded in z around inf
lower-/.f64N/A
lower-*.f6485.7
Simplified85.7%
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-fma.f6491.4
Applied egg-rr91.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma z (/ y t) x))) (if (<= t -2.52e-26) t_1 (if (<= t 7.6e-20) (/ (* y (- z x)) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma(z, (y / t), x);
double tmp;
if (t <= -2.52e-26) {
tmp = t_1;
} else if (t <= 7.6e-20) {
tmp = (y * (z - x)) / t;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(z, Float64(y / t), x) tmp = 0.0 if (t <= -2.52e-26) tmp = t_1; elseif (t <= 7.6e-20) tmp = Float64(Float64(y * Float64(z - x)) / t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t, -2.52e-26], t$95$1, If[LessEqual[t, 7.6e-20], N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, \frac{y}{t}, x\right)\\
\mathbf{if}\;t \leq -2.52 \cdot 10^{-26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 7.6 \cdot 10^{-20}:\\
\;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -2.52000000000000004e-26 or 7.5999999999999995e-20 < t Initial program 86.7%
Taylor expanded in z around inf
lower-/.f64N/A
lower-*.f6481.4
Simplified81.4%
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-fma.f6490.8
Applied egg-rr90.8%
if -2.52000000000000004e-26 < t < 7.5999999999999995e-20Initial program 98.9%
lift--.f64N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
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.8
Applied egg-rr95.8%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f6487.4
Simplified87.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ (- z x) t)))) (if (<= y -3.2e+67) t_1 (if (<= y 6.4e+153) (fma z (/ y t) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -3.2e+67) {
tmp = t_1;
} else if (y <= 6.4e+153) {
tmp = fma(z, (y / t), 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 <= -3.2e+67) tmp = t_1; elseif (y <= 6.4e+153) tmp = fma(z, Float64(y / t), 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, -3.2e+67], t$95$1, If[LessEqual[y, 6.4e+153], N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+67}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.19999999999999983e67 or 6.4000000000000003e153 < y Initial program 83.5%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6493.8
Simplified93.8%
if -3.19999999999999983e67 < y < 6.4000000000000003e153Initial program 96.5%
Taylor expanded in z around inf
lower-/.f64N/A
lower-*.f6482.4
Simplified82.4%
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-fma.f6484.6
Applied egg-rr84.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma z (/ y t) x))) (if (<= t -4.7e-241) t_1 (if (<= t 6.5e-193) (- (* (/ y t) x)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma(z, (y / t), x);
double tmp;
if (t <= -4.7e-241) {
tmp = t_1;
} else if (t <= 6.5e-193) {
tmp = -((y / t) * x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(z, Float64(y / t), x) tmp = 0.0 if (t <= -4.7e-241) tmp = t_1; elseif (t <= 6.5e-193) tmp = Float64(-Float64(Float64(y / t) * x)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t, -4.7e-241], t$95$1, If[LessEqual[t, 6.5e-193], (-N[(N[(y / t), $MachinePrecision] * x), $MachinePrecision]), t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, \frac{y}{t}, x\right)\\
\mathbf{if}\;t \leq -4.7 \cdot 10^{-241}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 6.5 \cdot 10^{-193}:\\
\;\;\;\;-\frac{y}{t} \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -4.6999999999999999e-241 or 6.5000000000000004e-193 < t Initial program 91.5%
Taylor expanded in z around inf
lower-/.f64N/A
lower-*.f6476.3
Simplified76.3%
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-fma.f6482.2
Applied egg-rr82.2%
if -4.6999999999999999e-241 < t < 6.5000000000000004e-193Initial program 96.9%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6471.6
Simplified71.6%
Taylor expanded in z around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6470.1
Simplified70.1%
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f6473.1
Applied egg-rr73.1%
Final simplification81.0%
(FPCore (x y z t) :precision binary64 (fma z (/ y t) x))
double code(double x, double y, double z, double t) {
return fma(z, (y / t), x);
}
function code(x, y, z, t) return fma(z, Float64(y / t), x) end
code[x_, y_, z_, t_] := N[(z * N[(y / t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \frac{y}{t}, x\right)
\end{array}
Initial program 92.2%
Taylor expanded in z around inf
lower-/.f64N/A
lower-*.f6471.0
Simplified71.0%
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-fma.f6477.2
Applied egg-rr77.2%
(FPCore (x y z t) :precision binary64 (* (/ y t) z))
double code(double x, double y, double z, double t) {
return (y / t) * z;
}
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 = (y / t) * z
end function
public static double code(double x, double y, double z, double t) {
return (y / t) * z;
}
def code(x, y, z, t): return (y / t) * z
function code(x, y, z, t) return Float64(Float64(y / t) * z) end
function tmp = code(x, y, z, t) tmp = (y / t) * z; end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{t} \cdot z
\end{array}
Initial program 92.2%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6433.0
Simplified33.0%
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
lower-*.f6438.0
Applied egg-rr38.0%
Final simplification38.0%
(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 2024207
(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)))