
(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 94.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.7
Applied rewrites97.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- 1.0 (/ y t)) x)))
(if (<= x -8.5e-199)
t_1
(if (<= x 1.85e-277)
(* (- z x) (/ y t))
(if (<= x 3.2e-96) (* (/ (- z x) t) y) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (1.0 - (y / t)) * x;
double tmp;
if (x <= -8.5e-199) {
tmp = t_1;
} else if (x <= 1.85e-277) {
tmp = (z - x) * (y / t);
} else if (x <= 3.2e-96) {
tmp = ((z - x) / t) * y;
} 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 = (1.0d0 - (y / t)) * x
if (x <= (-8.5d-199)) then
tmp = t_1
else if (x <= 1.85d-277) then
tmp = (z - x) * (y / t)
else if (x <= 3.2d-96) then
tmp = ((z - x) / t) * y
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 = (1.0 - (y / t)) * x;
double tmp;
if (x <= -8.5e-199) {
tmp = t_1;
} else if (x <= 1.85e-277) {
tmp = (z - x) * (y / t);
} else if (x <= 3.2e-96) {
tmp = ((z - x) / t) * y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (1.0 - (y / t)) * x tmp = 0 if x <= -8.5e-199: tmp = t_1 elif x <= 1.85e-277: tmp = (z - x) * (y / t) elif x <= 3.2e-96: tmp = ((z - x) / t) * y else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(1.0 - Float64(y / t)) * x) tmp = 0.0 if (x <= -8.5e-199) tmp = t_1; elseif (x <= 1.85e-277) tmp = Float64(Float64(z - x) * Float64(y / t)); elseif (x <= 3.2e-96) tmp = Float64(Float64(Float64(z - x) / t) * y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (1.0 - (y / t)) * x; tmp = 0.0; if (x <= -8.5e-199) tmp = t_1; elseif (x <= 1.85e-277) tmp = (z - x) * (y / t); elseif (x <= 3.2e-96) tmp = ((z - x) / t) * y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -8.5e-199], t$95$1, If[LessEqual[x, 1.85e-277], N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.2e-96], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{-199}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.85 \cdot 10^{-277}:\\
\;\;\;\;\left(z - x\right) \cdot \frac{y}{t}\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-96}:\\
\;\;\;\;\frac{z - x}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -8.4999999999999994e-199 or 3.20000000000000012e-96 < x Initial program 92.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
if -8.4999999999999994e-199 < x < 1.84999999999999992e-277Initial program 94.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.8
Applied rewrites93.8%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6474.4
Applied rewrites74.4%
if 1.84999999999999992e-277 < x < 3.20000000000000012e-96Initial program 94.7%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6468.2
Applied rewrites68.2%
Final simplification74.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 2024230
(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)))