
(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 (+ 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 92.0%
associate-*l/98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.9e-58) (not (<= z 0.0006))) (+ x (* y (/ z t))) (* x (- 1.0 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.9e-58) || !(z <= 0.0006)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (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 ((z <= (-1.9d-58)) .or. (.not. (z <= 0.0006d0))) then
tmp = x + (y * (z / t))
else
tmp = x * (1.0d0 - (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.9e-58) || !(z <= 0.0006)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.9e-58) or not (z <= 0.0006): tmp = x + (y * (z / t)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.9e-58) || !(z <= 0.0006)) tmp = Float64(x + Float64(y * Float64(z / t))); else tmp = Float64(x * Float64(1.0 - Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.9e-58) || ~((z <= 0.0006))) tmp = x + (y * (z / t)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.9e-58], N[Not[LessEqual[z, 0.0006]], $MachinePrecision]], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-58} \lor \neg \left(z \leq 0.0006\right):\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if z < -1.8999999999999999e-58 or 5.99999999999999947e-4 < z Initial program 92.0%
associate-*l/99.2%
Simplified99.2%
*-commutative99.2%
clear-num99.1%
un-div-inv99.2%
Applied egg-rr99.2%
Taylor expanded in z around inf 86.2%
*-commutative86.2%
associate-*l/83.3%
*-commutative83.3%
Simplified83.3%
if -1.8999999999999999e-58 < z < 5.99999999999999947e-4Initial program 92.0%
associate-*l/96.6%
Simplified96.6%
Taylor expanded in x around inf 89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
Final simplification85.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.32e-58) (not (<= z 0.00055))) (+ x (* (/ y t) z)) (* x (- 1.0 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.32e-58) || !(z <= 0.00055)) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (1.0 - (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 ((z <= (-1.32d-58)) .or. (.not. (z <= 0.00055d0))) then
tmp = x + ((y / t) * z)
else
tmp = x * (1.0d0 - (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.32e-58) || !(z <= 0.00055)) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.32e-58) or not (z <= 0.00055): tmp = x + ((y / t) * z) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.32e-58) || !(z <= 0.00055)) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(x * Float64(1.0 - Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.32e-58) || ~((z <= 0.00055))) tmp = x + ((y / t) * z); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.32e-58], N[Not[LessEqual[z, 0.00055]], $MachinePrecision]], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.32 \cdot 10^{-58} \lor \neg \left(z \leq 0.00055\right):\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if z < -1.31999999999999993e-58 or 5.50000000000000033e-4 < z Initial program 92.0%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in z around inf 86.2%
associate-*l/92.1%
*-commutative92.1%
Simplified92.1%
if -1.31999999999999993e-58 < z < 5.50000000000000033e-4Initial program 92.0%
associate-*l/96.6%
Simplified96.6%
Taylor expanded in x around inf 89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (<= z -2.15e-58) (+ x (/ z (/ t y))) (if (<= z 0.00075) (* x (- 1.0 (/ y t))) (+ x (* (/ y t) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.15e-58) {
tmp = x + (z / (t / y));
} else if (z <= 0.00075) {
tmp = x * (1.0 - (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 (z <= (-2.15d-58)) then
tmp = x + (z / (t / y))
else if (z <= 0.00075d0) then
tmp = x * (1.0d0 - (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 (z <= -2.15e-58) {
tmp = x + (z / (t / y));
} else if (z <= 0.00075) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.15e-58: tmp = x + (z / (t / y)) elif z <= 0.00075: tmp = x * (1.0 - (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.15e-58) tmp = Float64(x + Float64(z / Float64(t / y))); elseif (z <= 0.00075) tmp = Float64(x * Float64(1.0 - 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 (z <= -2.15e-58) tmp = x + (z / (t / y)); elseif (z <= 0.00075) tmp = x * (1.0 - (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.15e-58], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.00075], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{-58}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\mathbf{elif}\;z \leq 0.00075:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if z < -2.15e-58Initial program 94.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around inf 86.2%
associate-*l/91.2%
*-commutative91.2%
Simplified91.2%
clear-num91.1%
div-inv91.3%
Applied egg-rr91.3%
if -2.15e-58 < z < 7.5000000000000002e-4Initial program 92.0%
associate-*l/96.6%
Simplified96.6%
Taylor expanded in x around inf 89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
if 7.5000000000000002e-4 < z Initial program 88.8%
associate-*l/98.4%
Simplified98.4%
Taylor expanded in z around inf 86.3%
associate-*l/93.1%
*-commutative93.1%
Simplified93.1%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (<= z -1.3e-59) (+ x (/ z (/ t y))) (if (<= z 0.00068) (- x (* x (/ y t))) (+ x (* (/ y t) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.3e-59) {
tmp = x + (z / (t / y));
} else if (z <= 0.00068) {
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 (z <= (-1.3d-59)) then
tmp = x + (z / (t / y))
else if (z <= 0.00068d0) 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 (z <= -1.3e-59) {
tmp = x + (z / (t / y));
} else if (z <= 0.00068) {
tmp = x - (x * (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.3e-59: tmp = x + (z / (t / y)) elif z <= 0.00068: tmp = x - (x * (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.3e-59) tmp = Float64(x + Float64(z / Float64(t / y))); elseif (z <= 0.00068) 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 (z <= -1.3e-59) tmp = x + (z / (t / y)); elseif (z <= 0.00068) tmp = x - (x * (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.3e-59], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.00068], 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}\;z \leq -1.3 \cdot 10^{-59}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\mathbf{elif}\;z \leq 0.00068:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if z < -1.29999999999999999e-59Initial program 94.9%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around inf 86.2%
associate-*l/91.2%
*-commutative91.2%
Simplified91.2%
clear-num91.1%
div-inv91.3%
Applied egg-rr91.3%
if -1.29999999999999999e-59 < z < 6.8e-4Initial program 92.0%
associate-*l/96.6%
Simplified96.6%
Taylor expanded in z around 0 81.6%
associate-*r/81.6%
mul-1-neg81.6%
distribute-lft-neg-out81.6%
*-commutative81.6%
associate-/l*85.0%
Simplified85.0%
frac-2neg85.0%
div-inv85.0%
distribute-neg-frac85.0%
add-sqr-sqrt45.3%
sqrt-unprod49.7%
sqr-neg49.7%
sqrt-unprod17.2%
add-sqr-sqrt43.9%
frac-2neg43.9%
clear-num43.9%
cancel-sign-sub-inv43.9%
clear-num43.9%
div-inv43.9%
associate-/r/45.6%
*-commutative45.6%
add-sqr-sqrt18.1%
sqrt-unprod50.4%
sqr-neg50.4%
sqrt-unprod46.1%
add-sqr-sqrt89.1%
Applied egg-rr89.1%
if 6.8e-4 < z Initial program 88.8%
associate-*l/98.4%
Simplified98.4%
Taylor expanded in z around inf 86.3%
associate-*l/93.1%
*-commutative93.1%
Simplified93.1%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.8e+57) (not (<= y 2100.0))) (* x (/ (- y) t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.8e+57) || !(y <= 2100.0)) {
tmp = x * (-y / t);
} else {
tmp = 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 ((y <= (-3.8d+57)) .or. (.not. (y <= 2100.0d0))) then
tmp = x * (-y / t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.8e+57) || !(y <= 2100.0)) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.8e+57) or not (y <= 2100.0): tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.8e+57) || !(y <= 2100.0)) tmp = Float64(x * Float64(Float64(-y) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.8e+57) || ~((y <= 2100.0))) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.8e+57], N[Not[LessEqual[y, 2100.0]], $MachinePrecision]], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+57} \lor \neg \left(y \leq 2100\right):\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.7999999999999999e57 or 2100 < y Initial program 84.3%
associate-*l/98.3%
Simplified98.3%
Taylor expanded in x around inf 61.7%
mul-1-neg61.7%
unsub-neg61.7%
Simplified61.7%
Taylor expanded in y around inf 39.6%
mul-1-neg39.6%
associate-*r/46.6%
distribute-rgt-neg-out46.6%
distribute-frac-neg46.6%
Simplified46.6%
if -3.7999999999999999e57 < y < 2100Initial program 98.8%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in y around 0 54.8%
Final simplification50.9%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ y t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (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 * (1.0d0 - (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (y / t));
}
def code(x, y, z, t): return x * (1.0 - (y / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (y / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{y}{t}\right)
\end{array}
Initial program 92.0%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in x around inf 64.7%
mul-1-neg64.7%
unsub-neg64.7%
Simplified64.7%
Final simplification64.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 92.0%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in y around 0 36.9%
Final simplification36.9%
(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 2024031
(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)))