
(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 6 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 (/ (- z x) (/ t y))))
double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
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 + ((z - x) / (t / y))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
def code(x, y, z, t): return x + ((z - x) / (t / y))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) / Float64(t / y))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) / (t / y)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z - x}{\frac{t}{y}}
\end{array}
Initial program 92.4%
associate-*l/97.8%
Simplified97.8%
*-commutative97.8%
clear-num97.6%
un-div-inv97.8%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.85e+187) (not (<= x 2.9e+282))) (* x (/ (- y) t)) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.85e+187) || !(x <= 2.9e+282)) {
tmp = x * (-y / t);
} 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 ((x <= (-1.85d+187)) .or. (.not. (x <= 2.9d+282))) then
tmp = x * (-y / t)
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 ((x <= -1.85e+187) || !(x <= 2.9e+282)) {
tmp = x * (-y / t);
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.85e+187) or not (x <= 2.9e+282): tmp = x * (-y / t) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.85e+187) || !(x <= 2.9e+282)) tmp = Float64(x * Float64(Float64(-y) / t)); else tmp = Float64(x + Float64(z * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.85e+187) || ~((x <= 2.9e+282))) tmp = x * (-y / t); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.85e+187], N[Not[LessEqual[x, 2.9e+282]], $MachinePrecision]], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+187} \lor \neg \left(x \leq 2.9 \cdot 10^{+282}\right):\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.85000000000000009e187 or 2.90000000000000016e282 < x Initial program 87.8%
associate-*l/100.0%
Simplified100.0%
*-commutative100.0%
clear-num99.8%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in z around 0 87.8%
mul-1-neg87.8%
associate-*r/90.6%
Simplified90.6%
Taylor expanded in y around inf 64.9%
associate-*r/64.9%
neg-mul-164.9%
*-commutative64.9%
distribute-rgt-neg-in64.9%
associate-*r/69.3%
Simplified69.3%
if -1.85000000000000009e187 < x < 2.90000000000000016e282Initial program 93.3%
associate-*l/97.4%
Simplified97.4%
Taylor expanded in z around inf 74.8%
associate-*l/76.7%
*-commutative76.7%
Simplified76.7%
Final simplification75.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.1e-29) (not (<= z 4.3e-22))) (+ x (* z (/ y t))) (- x (* x (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e-29) || !(z <= 4.3e-22)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (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 <= (-3.1d-29)) .or. (.not. (z <= 4.3d-22))) then
tmp = x + (z * (y / t))
else
tmp = x - (x * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e-29) || !(z <= 4.3e-22)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (x * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.1e-29) or not (z <= 4.3e-22): tmp = x + (z * (y / t)) else: tmp = x - (x * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.1e-29) || !(z <= 4.3e-22)) tmp = Float64(x + Float64(z * Float64(y / t))); else tmp = Float64(x - Float64(x * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.1e-29) || ~((z <= 4.3e-22))) tmp = x + (z * (y / t)); else tmp = x - (x * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.1e-29], N[Not[LessEqual[z, 4.3e-22]], $MachinePrecision]], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-29} \lor \neg \left(z \leq 4.3 \cdot 10^{-22}\right):\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -3.10000000000000026e-29 or 4.30000000000000037e-22 < z Initial program 91.6%
associate-*l/99.4%
Simplified99.4%
Taylor expanded in z around inf 83.9%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
if -3.10000000000000026e-29 < z < 4.30000000000000037e-22Initial program 93.4%
associate-*l/95.9%
Simplified95.9%
Taylor expanded in x around inf 90.3%
*-commutative90.3%
distribute-lft-in90.3%
*-rgt-identity90.3%
mul-1-neg90.3%
distribute-rgt-neg-in90.3%
unsub-neg90.3%
Simplified90.3%
Final simplification89.1%
(FPCore (x y z t) :precision binary64 (if (<= t -3e+56) x (if (<= t 1.8e+23) (* x (/ (- y) t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3e+56) {
tmp = x;
} else if (t <= 1.8e+23) {
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 (t <= (-3d+56)) then
tmp = x
else if (t <= 1.8d+23) 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 (t <= -3e+56) {
tmp = x;
} else if (t <= 1.8e+23) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3e+56: tmp = x elif t <= 1.8e+23: tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3e+56) tmp = x; elseif (t <= 1.8e+23) 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 (t <= -3e+56) tmp = x; elseif (t <= 1.8e+23) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3e+56], x, If[LessEqual[t, 1.8e+23], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3 \cdot 10^{+56}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 1.8 \cdot 10^{+23}:\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -3.00000000000000006e56 or 1.7999999999999999e23 < t Initial program 81.4%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in y around 0 64.0%
if -3.00000000000000006e56 < t < 1.7999999999999999e23Initial program 99.8%
associate-*l/96.8%
Simplified96.8%
*-commutative96.8%
clear-num96.7%
un-div-inv97.0%
Applied egg-rr97.0%
Taylor expanded in z around 0 61.9%
mul-1-neg61.9%
associate-*r/54.5%
Simplified54.5%
Taylor expanded in y around inf 49.6%
associate-*r/49.6%
neg-mul-149.6%
*-commutative49.6%
distribute-rgt-neg-in49.6%
associate-*r/50.1%
Simplified50.1%
Final simplification55.7%
(FPCore (x y z t) :precision binary64 (+ x (* (- z x) (/ y t))))
double code(double x, double y, double z, double t) {
return x + ((z - x) * (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 + ((z - x) * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) * (y / t));
}
def code(x, y, z, t): return x + ((z - x) * (y / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z - x\right) \cdot \frac{y}{t}
\end{array}
Initial program 92.4%
associate-*l/97.8%
Simplified97.8%
Final simplification97.8%
(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.4%
associate-*l/97.8%
Simplified97.8%
Taylor expanded in y around 0 33.8%
Final simplification33.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 2023240
(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)))