
(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 (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 89.6%
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.2
Applied rewrites98.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ x (/ (* y (- z x)) t))) (t_2 (* y (/ (- z x) t)))) (if (<= t_1 -5e+279) t_2 (if (<= t_1 1e+291) (+ x (/ (* y z) t)) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = x + ((y * (z - x)) / t);
double t_2 = y * ((z - x) / t);
double tmp;
if (t_1 <= -5e+279) {
tmp = t_2;
} else if (t_1 <= 1e+291) {
tmp = x + ((y * z) / t);
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: tmp
t_1 = x + ((y * (z - x)) / t)
t_2 = y * ((z - x) / t)
if (t_1 <= (-5d+279)) then
tmp = t_2
else if (t_1 <= 1d+291) then
tmp = x + ((y * z) / t)
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((y * (z - x)) / t);
double t_2 = y * ((z - x) / t);
double tmp;
if (t_1 <= -5e+279) {
tmp = t_2;
} else if (t_1 <= 1e+291) {
tmp = x + ((y * z) / t);
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = x + ((y * (z - x)) / t) t_2 = y * ((z - x) / t) tmp = 0 if t_1 <= -5e+279: tmp = t_2 elif t_1 <= 1e+291: tmp = x + ((y * z) / t) else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t)) t_2 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (t_1 <= -5e+279) tmp = t_2; elseif (t_1 <= 1e+291) tmp = Float64(x + Float64(Float64(y * z) / t)); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + ((y * (z - x)) / t); t_2 = y * ((z - x) / t); tmp = 0.0; if (t_1 <= -5e+279) tmp = t_2; elseif (t_1 <= 1e+291) tmp = x + ((y * z) / t); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+279], t$95$2, If[LessEqual[t$95$1, 1e+291], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
t_2 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+279}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+291}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -5.0000000000000002e279 or 9.9999999999999996e290 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) Initial program 81.7%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6487.7
Applied rewrites87.7%
if -5.0000000000000002e279 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 9.9999999999999996e290Initial program 98.6%
Taylor expanded in z around inf
lower-*.f6483.4
Applied rewrites83.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 2024228
(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)))