
(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 (if (<= t 3e-18) (+ x (* (/ y t) (- z x))) (fma y (/ (- z x) t) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 3e-18) {
tmp = x + ((y / t) * (z - x));
} else {
tmp = fma(y, ((z - x) / t), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (t <= 3e-18) tmp = Float64(x + Float64(Float64(y / t) * Float64(z - x))); else tmp = fma(y, Float64(Float64(z - x) / t), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[t, 3e-18], N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 3 \cdot 10^{-18}:\\
\;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\
\end{array}
\end{array}
if t < 2.99999999999999983e-18Initial program 92.4%
associate-*l/98.6%
Simplified98.6%
if 2.99999999999999983e-18 < t Initial program 83.8%
+-commutative83.8%
associate-*r/99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.1e+123) (not (<= x 1.06e-44))) (- x (* x (/ y t))) (+ x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.1e+123) || !(x <= 1.06e-44)) {
tmp = x - (x * (y / t));
} else {
tmp = x + ((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 ((x <= (-1.1d+123)) .or. (.not. (x <= 1.06d-44))) then
tmp = x - (x * (y / t))
else
tmp = x + ((y / t) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.1e+123) || !(x <= 1.06e-44)) {
tmp = x - (x * (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.1e+123) or not (x <= 1.06e-44): tmp = x - (x * (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.1e+123) || !(x <= 1.06e-44)) tmp = Float64(x - Float64(x * Float64(y / t))); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.1e+123) || ~((x <= 1.06e-44))) tmp = x - (x * (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.1e+123], N[Not[LessEqual[x, 1.06e-44]], $MachinePrecision]], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+123} \lor \neg \left(x \leq 1.06 \cdot 10^{-44}\right):\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if x < -1.09999999999999996e123 or 1.0599999999999999e-44 < x Initial program 86.1%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 93.8%
*-commutative93.8%
distribute-lft-in93.8%
*-rgt-identity93.8%
mul-1-neg93.8%
distribute-rgt-neg-in93.8%
unsub-neg93.8%
Simplified93.8%
if -1.09999999999999996e123 < x < 1.0599999999999999e-44Initial program 93.0%
associate-*l/95.0%
Simplified95.0%
Taylor expanded in z around inf 85.5%
associate-*l/89.5%
*-commutative89.5%
Simplified89.5%
Final simplification91.4%
(FPCore (x y z t) :precision binary64 (if (<= t 2e+106) (+ x (* (/ y t) (- z x))) (+ x (/ y (/ t (- z x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 2e+106) {
tmp = x + ((y / t) * (z - x));
} else {
tmp = x + (y / (t / (z - 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 (t <= 2d+106) then
tmp = x + ((y / t) * (z - x))
else
tmp = x + (y / (t / (z - x)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 2e+106) {
tmp = x + ((y / t) * (z - x));
} else {
tmp = x + (y / (t / (z - x)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 2e+106: tmp = x + ((y / t) * (z - x)) else: tmp = x + (y / (t / (z - x))) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 2e+106) tmp = Float64(x + Float64(Float64(y / t) * Float64(z - x))); else tmp = Float64(x + Float64(y / Float64(t / Float64(z - x)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 2e+106) tmp = x + ((y / t) * (z - x)); else tmp = x + (y / (t / (z - x))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 2e+106], N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / N[(t / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 2 \cdot 10^{+106}:\\
\;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\
\end{array}
\end{array}
if t < 2.00000000000000018e106Initial program 93.3%
associate-*l/98.8%
Simplified98.8%
if 2.00000000000000018e106 < t Initial program 76.4%
associate-/l*99.8%
Simplified99.8%
Final simplification99.0%
(FPCore (x y z t) :precision binary64 (if (<= t 1e+107) (+ x (* (/ y t) z)) (+ x (/ y (/ t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1e+107) {
tmp = x + ((y / t) * z);
} else {
tmp = x + (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 (t <= 1d+107) then
tmp = x + ((y / t) * z)
else
tmp = x + (y / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1e+107) {
tmp = x + ((y / t) * z);
} else {
tmp = x + (y / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 1e+107: tmp = x + ((y / t) * z) else: tmp = x + (y / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 1e+107) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(x + Float64(y / Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 1e+107) tmp = x + ((y / t) * z); else tmp = x + (y / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 1e+107], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 10^{+107}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z}}\\
\end{array}
\end{array}
if t < 9.9999999999999997e106Initial program 93.3%
associate-*l/98.8%
Simplified98.8%
Taylor expanded in z around inf 69.9%
associate-*l/74.8%
*-commutative74.8%
Simplified74.8%
if 9.9999999999999997e106 < t Initial program 76.4%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around inf 93.1%
Final simplification78.5%
(FPCore (x y z t) :precision binary64 (+ x (* (/ y t) (- z x))))
double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - 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 + ((y / t) * (z - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
def code(x, y, z, t): return x + ((y / t) * (z - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * Float64(z - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * (z - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot \left(z - x\right)
\end{array}
Initial program 89.9%
associate-*l/97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x y z t) :precision binary64 (+ x (* (/ y t) z)))
double code(double x, double y, double z, double t) {
return x + ((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 = x + ((y / t) * z)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * z);
}
def code(x, y, z, t): return x + ((y / t) * z)
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * z)) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * z); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot z
\end{array}
Initial program 89.9%
associate-*l/97.2%
Simplified97.2%
Taylor expanded in z around inf 72.3%
associate-*l/76.7%
*-commutative76.7%
Simplified76.7%
Final simplification76.7%
(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 89.9%
associate-*l/97.2%
Simplified97.2%
Taylor expanded in y around 0 38.2%
Final simplification38.2%
(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 2023196
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:herbie-target
(- x (+ (* x (/ y t)) (* (- z) (/ y t))))
(+ x (/ (* y (- z x)) t)))