
(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 92.5%
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.0
Applied rewrites97.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.22e-23) (not (<= y 9.5e+97))) (* (/ (- z x) t) y) (+ x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.22e-23) || !(y <= 9.5e+97)) {
tmp = ((z - x) / t) * y;
} else {
tmp = x + ((z * y) / t);
}
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.22d-23)) .or. (.not. (y <= 9.5d+97))) then
tmp = ((z - x) / t) * y
else
tmp = x + ((z * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.22e-23) || !(y <= 9.5e+97)) {
tmp = ((z - x) / t) * y;
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.22e-23) or not (y <= 9.5e+97): tmp = ((z - x) / t) * y else: tmp = x + ((z * y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.22e-23) || !(y <= 9.5e+97)) tmp = Float64(Float64(Float64(z - x) / t) * y); else tmp = Float64(x + Float64(Float64(z * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.22e-23) || ~((y <= 9.5e+97))) tmp = ((z - x) / t) * y; else tmp = x + ((z * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.22e-23], N[Not[LessEqual[y, 9.5e+97]], $MachinePrecision]], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.22 \cdot 10^{-23} \lor \neg \left(y \leq 9.5 \cdot 10^{+97}\right):\\
\;\;\;\;\frac{z - x}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if y < -1.22000000000000007e-23 or 9.49999999999999975e97 < y Initial program 88.1%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.6
Applied rewrites80.6%
Applied rewrites92.4%
if -1.22000000000000007e-23 < y < 9.49999999999999975e97Initial program 95.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6486.4
Applied rewrites86.4%
Final simplification88.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.22e-23) (not (<= y 3.7e+134))) (* (/ (- z x) t) y) (fma (/ z t) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.22e-23) || !(y <= 3.7e+134)) {
tmp = ((z - x) / t) * y;
} else {
tmp = fma((z / t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.22e-23) || !(y <= 3.7e+134)) tmp = Float64(Float64(Float64(z - x) / t) * y); else tmp = fma(Float64(z / t), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.22e-23], N[Not[LessEqual[y, 3.7e+134]], $MachinePrecision]], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.22 \cdot 10^{-23} \lor \neg \left(y \leq 3.7 \cdot 10^{+134}\right):\\
\;\;\;\;\frac{z - x}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\end{array}
\end{array}
if y < -1.22000000000000007e-23 or 3.70000000000000013e134 < y Initial program 88.1%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.0
Applied rewrites82.0%
Applied rewrites93.7%
if -1.22000000000000007e-23 < y < 3.70000000000000013e134Initial program 95.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
Taylor expanded in x around 0
lower-/.f6483.4
Applied rewrites83.4%
Final simplification87.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.5e-14) (not (<= z 2.4e+35))) (fma (/ z t) y x) (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.5e-14) || !(z <= 2.4e+35)) {
tmp = fma((z / t), y, x);
} else {
tmp = (1.0 - (y / t)) * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.5e-14) || !(z <= 2.4e+35)) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(1.0 - Float64(y / t)) * x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.5e-14], N[Not[LessEqual[z, 2.4e+35]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-14} \lor \neg \left(z \leq 2.4 \cdot 10^{+35}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\end{array}
\end{array}
if z < -9.4999999999999999e-14 or 2.40000000000000015e35 < z Initial program 90.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.2
Applied rewrites92.2%
Taylor expanded in x around 0
lower-/.f6485.6
Applied rewrites85.6%
if -9.4999999999999999e-14 < z < 2.40000000000000015e35Initial program 94.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
Final simplification87.3%
(FPCore (x y z t) :precision binary64 (if (<= y 3.6e+170) (fma (/ z t) y x) (* (- y) (/ x t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 3.6e+170) {
tmp = fma((z / t), y, x);
} else {
tmp = -y * (x / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 3.6e+170) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(-y) * Float64(x / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 3.6e+170], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[((-y) * N[(x / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{+170}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot \frac{x}{t}\\
\end{array}
\end{array}
if y < 3.6e170Initial program 93.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.3
Applied rewrites94.3%
Taylor expanded in x around 0
lower-/.f6476.8
Applied rewrites76.8%
if 3.6e170 < y Initial program 85.4%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.4
Applied rewrites85.4%
Taylor expanded in x around inf
Applied rewrites71.2%
(FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
double code(double x, double y, double z, double t) {
return fma((z / t), y, x);
}
function code(x, y, z, t) return fma(Float64(z / t), y, x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y, x\right)
\end{array}
Initial program 92.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.9
Applied rewrites94.9%
Taylor expanded in x around 0
lower-/.f6473.4
Applied rewrites73.4%
(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.5%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6437.5
Applied rewrites37.5%
Applied rewrites41.4%
(FPCore (x y z t) :precision binary64 (* y (/ z t)))
double code(double x, double y, double z, double t) {
return y * (z / 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 = y * (z / t)
end function
public static double code(double x, double y, double z, double t) {
return y * (z / t);
}
def code(x, y, z, t): return y * (z / t)
function code(x, y, z, t) return Float64(y * Float64(z / t)) end
function tmp = code(x, y, z, t) tmp = y * (z / t); end
code[x_, y_, z_, t_] := N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{z}{t}
\end{array}
Initial program 92.5%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6437.5
Applied rewrites37.5%
Applied rewrites38.5%
(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 2024324
(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)))