
(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 (/ (- 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.3%
associate-*l/96.6%
Simplified96.6%
*-commutative96.6%
clear-num96.6%
un-div-inv97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.2e-65) (not (<= z 4.5e-99))) (+ x (* z (/ y t))) (* x (- 1.0 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.2e-65) || !(z <= 4.5e-99)) {
tmp = x + (z * (y / 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 <= (-4.2d-65)) .or. (.not. (z <= 4.5d-99))) then
tmp = x + (z * (y / 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 <= -4.2e-65) || !(z <= 4.5e-99)) {
tmp = x + (z * (y / t));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.2e-65) or not (z <= 4.5e-99): tmp = x + (z * (y / t)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.2e-65) || !(z <= 4.5e-99)) tmp = Float64(x + Float64(z * Float64(y / 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 <= -4.2e-65) || ~((z <= 4.5e-99))) tmp = x + (z * (y / t)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.2e-65], N[Not[LessEqual[z, 4.5e-99]], $MachinePrecision]], N[(x + N[(z * N[(y / 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 -4.2 \cdot 10^{-65} \lor \neg \left(z \leq 4.5 \cdot 10^{-99}\right):\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if z < -4.20000000000000006e-65 or 4.5000000000000003e-99 < z Initial program 92.2%
associate-*l/98.2%
Simplified98.2%
Taylor expanded in z around inf 84.0%
associate-*l/88.4%
*-commutative88.4%
Simplified88.4%
if -4.20000000000000006e-65 < z < 4.5000000000000003e-99Initial program 92.5%
associate-/l*93.0%
Simplified93.0%
Taylor expanded in z around 0 81.3%
associate-*r/81.3%
neg-mul-181.3%
Simplified81.3%
Taylor expanded in x around 0 84.2%
mul-1-neg84.2%
sub-neg84.2%
*-commutative84.2%
Simplified84.2%
Final simplification86.8%
(FPCore (x y z t) :precision binary64 (if (<= t -4.5e-51) x (if (<= t 1.5) (* x (/ (- y) t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -4.5e-51) {
tmp = x;
} else if (t <= 1.5) {
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 <= (-4.5d-51)) then
tmp = x
else if (t <= 1.5d0) 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 <= -4.5e-51) {
tmp = x;
} else if (t <= 1.5) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -4.5e-51: tmp = x elif t <= 1.5: tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -4.5e-51) tmp = x; elseif (t <= 1.5) 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 <= -4.5e-51) tmp = x; elseif (t <= 1.5) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -4.5e-51], x, If[LessEqual[t, 1.5], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.5 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 1.5:\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -4.49999999999999974e-51 or 1.5 < t Initial program 87.4%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in z around 0 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
Taylor expanded in y around 0 56.7%
if -4.49999999999999974e-51 < t < 1.5Initial program 98.2%
associate-/l*91.1%
Simplified91.1%
Taylor expanded in z around 0 48.7%
associate-*r/48.7%
neg-mul-148.7%
Simplified48.7%
Taylor expanded in x around 0 52.0%
mul-1-neg52.0%
sub-neg52.0%
*-commutative52.0%
Simplified52.0%
Taylor expanded in y around inf 46.3%
mul-1-neg46.3%
associate-*l/45.5%
distribute-rgt-neg-in45.5%
Simplified45.5%
Final simplification51.6%
(FPCore (x y z t) :precision binary64 (if (<= t -7.8e-51) x (if (<= t 2.6) (/ (- x) (/ t y)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -7.8e-51) {
tmp = x;
} else if (t <= 2.6) {
tmp = -x / (t / y);
} 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 <= (-7.8d-51)) then
tmp = x
else if (t <= 2.6d0) then
tmp = -x / (t / y)
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 <= -7.8e-51) {
tmp = x;
} else if (t <= 2.6) {
tmp = -x / (t / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -7.8e-51: tmp = x elif t <= 2.6: tmp = -x / (t / y) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -7.8e-51) tmp = x; elseif (t <= 2.6) tmp = Float64(Float64(-x) / Float64(t / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -7.8e-51) tmp = x; elseif (t <= 2.6) tmp = -x / (t / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -7.8e-51], x, If[LessEqual[t, 2.6], N[((-x) / N[(t / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -7.8 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 2.6:\\
\;\;\;\;\frac{-x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -7.7999999999999995e-51 or 2.60000000000000009 < t Initial program 87.4%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in z around 0 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
Taylor expanded in y around 0 56.7%
if -7.7999999999999995e-51 < t < 2.60000000000000009Initial program 98.2%
associate-/l*91.1%
Simplified91.1%
Taylor expanded in z around 0 48.7%
associate-*r/48.7%
neg-mul-148.7%
Simplified48.7%
Taylor expanded in x around 0 52.0%
mul-1-neg52.0%
sub-neg52.0%
*-commutative52.0%
Simplified52.0%
Taylor expanded in y around inf 46.3%
mul-1-neg46.3%
*-commutative46.3%
associate-/l*47.0%
distribute-neg-frac47.0%
Simplified47.0%
Final simplification52.3%
(FPCore (x y z t) :precision binary64 (if (<= t -6.6e-233) x (if (<= t 9.5e-81) (/ x (/ t y)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -6.6e-233) {
tmp = x;
} else if (t <= 9.5e-81) {
tmp = x / (t / y);
} 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 <= (-6.6d-233)) then
tmp = x
else if (t <= 9.5d-81) then
tmp = x / (t / y)
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 <= -6.6e-233) {
tmp = x;
} else if (t <= 9.5e-81) {
tmp = x / (t / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -6.6e-233: tmp = x elif t <= 9.5e-81: tmp = x / (t / y) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -6.6e-233) tmp = x; elseif (t <= 9.5e-81) tmp = Float64(x / Float64(t / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -6.6e-233) tmp = x; elseif (t <= 9.5e-81) tmp = x / (t / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -6.6e-233], x, If[LessEqual[t, 9.5e-81], N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -6.6 \cdot 10^{-233}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 9.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -6.6000000000000001e-233 or 9.49999999999999917e-81 < t Initial program 90.0%
associate-/l*96.8%
Simplified96.8%
Taylor expanded in z around 0 63.7%
associate-*r/63.7%
neg-mul-163.7%
Simplified63.7%
Taylor expanded in y around 0 44.6%
if -6.6000000000000001e-233 < t < 9.49999999999999917e-81Initial program 99.8%
associate-/l*89.8%
Simplified89.8%
Taylor expanded in z around 0 42.5%
associate-*r/42.5%
neg-mul-142.5%
Simplified42.5%
Taylor expanded in x around 0 44.1%
mul-1-neg44.1%
sub-neg44.1%
*-commutative44.1%
Simplified44.1%
Taylor expanded in y around inf 44.3%
mul-1-neg44.3%
associate-*l/42.8%
distribute-rgt-neg-in42.8%
Simplified42.8%
clear-num42.8%
associate-*l/44.5%
*-un-lft-identity44.5%
add-sqr-sqrt19.6%
sqrt-unprod30.2%
sqr-neg30.2%
sqrt-unprod17.3%
add-sqr-sqrt24.6%
Applied egg-rr24.6%
Final simplification39.9%
(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.3%
associate-*l/96.6%
Simplified96.6%
Final simplification96.6%
(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.3%
associate-/l*95.2%
Simplified95.2%
Taylor expanded in z around 0 58.7%
associate-*r/58.7%
neg-mul-158.7%
Simplified58.7%
Taylor expanded in x around 0 61.0%
mul-1-neg61.0%
sub-neg61.0%
*-commutative61.0%
Simplified61.0%
Final simplification61.0%
(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.3%
associate-/l*95.2%
Simplified95.2%
Taylor expanded in z around 0 58.7%
associate-*r/58.7%
neg-mul-158.7%
Simplified58.7%
Taylor expanded in y around 0 34.9%
Final simplification34.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 2023274
(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)))