
(FPCore (x y z t a) :precision binary64 (- x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x - ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x - ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x - Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x - ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x - N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot \left(z - t\right)}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (- x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x - ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x - ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x - Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x - ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x - N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y \cdot \left(z - t\right)}{a}
\end{array}
(FPCore (x y z t a) :precision binary64 (+ x (* (/ y a) (- t z))))
double code(double x, double y, double z, double t, double a) {
return x + ((y / a) * (t - z));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + ((y / a) * (t - z))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y / a) * (t - z));
}
def code(x, y, z, t, a): return x + ((y / a) * (t - z))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y / a) * Float64(t - z))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y / a) * (t - z)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y / a), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{a} \cdot \left(t - z\right)
\end{array}
Initial program 95.5%
associate-*l/97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -6.2e+72) (not (<= z 2.5e-33))) (- x (* (/ y a) z)) (+ x (* (/ y a) t))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -6.2e+72) || !(z <= 2.5e-33)) {
tmp = x - ((y / a) * z);
} else {
tmp = x + ((y / a) * t);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((z <= (-6.2d+72)) .or. (.not. (z <= 2.5d-33))) then
tmp = x - ((y / a) * z)
else
tmp = x + ((y / a) * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -6.2e+72) || !(z <= 2.5e-33)) {
tmp = x - ((y / a) * z);
} else {
tmp = x + ((y / a) * t);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (z <= -6.2e+72) or not (z <= 2.5e-33): tmp = x - ((y / a) * z) else: tmp = x + ((y / a) * t) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -6.2e+72) || !(z <= 2.5e-33)) tmp = Float64(x - Float64(Float64(y / a) * z)); else tmp = Float64(x + Float64(Float64(y / a) * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((z <= -6.2e+72) || ~((z <= 2.5e-33))) tmp = x - ((y / a) * z); else tmp = x + ((y / a) * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -6.2e+72], N[Not[LessEqual[z, 2.5e-33]], $MachinePrecision]], N[(x - N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / a), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+72} \lor \neg \left(z \leq 2.5 \cdot 10^{-33}\right):\\
\;\;\;\;x - \frac{y}{a} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{a} \cdot t\\
\end{array}
\end{array}
if z < -6.19999999999999977e72 or 2.50000000000000014e-33 < z Initial program 96.0%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in z around inf 84.1%
associate-*l/88.8%
*-commutative88.8%
Simplified88.8%
if -6.19999999999999977e72 < z < 2.50000000000000014e-33Initial program 95.0%
associate-*l/96.5%
Simplified96.5%
Taylor expanded in z around 0 86.7%
*-commutative86.7%
associate-*l/89.5%
neg-mul-189.5%
distribute-rgt-neg-out89.5%
Simplified89.5%
Final simplification89.2%
(FPCore (x y z t a) :precision binary64 (if (<= t -1.45e+25) (- x (/ y (/ (- a) t))) (if (<= t 9.8e+82) (- x (* (/ y a) z)) (+ x (* (/ y a) t)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.45e+25) {
tmp = x - (y / (-a / t));
} else if (t <= 9.8e+82) {
tmp = x - ((y / a) * z);
} else {
tmp = x + ((y / a) * t);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (t <= (-1.45d+25)) then
tmp = x - (y / (-a / t))
else if (t <= 9.8d+82) then
tmp = x - ((y / a) * z)
else
tmp = x + ((y / a) * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.45e+25) {
tmp = x - (y / (-a / t));
} else if (t <= 9.8e+82) {
tmp = x - ((y / a) * z);
} else {
tmp = x + ((y / a) * t);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= -1.45e+25: tmp = x - (y / (-a / t)) elif t <= 9.8e+82: tmp = x - ((y / a) * z) else: tmp = x + ((y / a) * t) return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= -1.45e+25) tmp = Float64(x - Float64(y / Float64(Float64(-a) / t))); elseif (t <= 9.8e+82) tmp = Float64(x - Float64(Float64(y / a) * z)); else tmp = Float64(x + Float64(Float64(y / a) * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= -1.45e+25) tmp = x - (y / (-a / t)); elseif (t <= 9.8e+82) tmp = x - ((y / a) * z); else tmp = x + ((y / a) * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -1.45e+25], N[(x - N[(y / N[((-a) / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 9.8e+82], N[(x - N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / a), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.45 \cdot 10^{+25}:\\
\;\;\;\;x - \frac{y}{\frac{-a}{t}}\\
\mathbf{elif}\;t \leq 9.8 \cdot 10^{+82}:\\
\;\;\;\;x - \frac{y}{a} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{a} \cdot t\\
\end{array}
\end{array}
if t < -1.44999999999999995e25Initial program 94.3%
associate-/l*95.6%
Simplified95.6%
Taylor expanded in z around 0 85.2%
associate-*r/85.2%
neg-mul-185.2%
Simplified85.2%
if -1.44999999999999995e25 < t < 9.8000000000000001e82Initial program 96.0%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in z around inf 85.5%
associate-*l/89.4%
*-commutative89.4%
Simplified89.4%
if 9.8000000000000001e82 < t Initial program 95.7%
associate-*l/99.5%
Simplified99.5%
Taylor expanded in z around 0 95.7%
*-commutative95.7%
associate-*l/99.5%
neg-mul-199.5%
distribute-rgt-neg-out99.5%
Simplified99.5%
Final simplification90.0%
(FPCore (x y z t a) :precision binary64 (- x (* (/ y a) z)))
double code(double x, double y, double z, double t, double a) {
return x - ((y / a) * z);
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x - ((y / a) * z)
end function
public static double code(double x, double y, double z, double t, double a) {
return x - ((y / a) * z);
}
def code(x, y, z, t, a): return x - ((y / a) * z)
function code(x, y, z, t, a) return Float64(x - Float64(Float64(y / a) * z)) end
function tmp = code(x, y, z, t, a) tmp = x - ((y / a) * z); end
code[x_, y_, z_, t_, a_] := N[(x - N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{y}{a} \cdot z
\end{array}
Initial program 95.5%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in z around inf 69.0%
associate-*l/72.8%
*-commutative72.8%
Simplified72.8%
Final simplification72.8%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ a (- z t))))
(if (< y -1.0761266216389975e-10)
(- x (/ 1.0 (/ t_1 y)))
(if (< y 2.894426862792089e-49)
(- x (/ (* y (- z t)) a))
(- x (/ y t_1))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x - (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x - ((y * (z - t)) / a);
} else {
tmp = x - (y / t_1);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = a / (z - t)
if (y < (-1.0761266216389975d-10)) then
tmp = x - (1.0d0 / (t_1 / y))
else if (y < 2.894426862792089d-49) then
tmp = x - ((y * (z - t)) / a)
else
tmp = x - (y / t_1)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x - (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x - ((y * (z - t)) / a);
} else {
tmp = x - (y / t_1);
}
return tmp;
}
def code(x, y, z, t, a): t_1 = a / (z - t) tmp = 0 if y < -1.0761266216389975e-10: tmp = x - (1.0 / (t_1 / y)) elif y < 2.894426862792089e-49: tmp = x - ((y * (z - t)) / a) else: tmp = x - (y / t_1) return tmp
function code(x, y, z, t, a) t_1 = Float64(a / Float64(z - t)) tmp = 0.0 if (y < -1.0761266216389975e-10) tmp = Float64(x - Float64(1.0 / Float64(t_1 / y))); elseif (y < 2.894426862792089e-49) tmp = Float64(x - Float64(Float64(y * Float64(z - t)) / a)); else tmp = Float64(x - Float64(y / t_1)); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = a / (z - t); tmp = 0.0; if (y < -1.0761266216389975e-10) tmp = x - (1.0 / (t_1 / y)); elseif (y < 2.894426862792089e-49) tmp = x - ((y * (z - t)) / a); else tmp = x - (y / t_1); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(a / N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[Less[y, -1.0761266216389975e-10], N[(x - N[(1.0 / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Less[y, 2.894426862792089e-49], N[(x - N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{a}{z - t}\\
\mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\
\;\;\;\;x - \frac{1}{\frac{t_1}{y}}\\
\mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\
\;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{t_1}\\
\end{array}
\end{array}
herbie shell --seed 2024024
(FPCore (x y z t a)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"
:precision binary64
:herbie-target
(if (< y -1.0761266216389975e-10) (- x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (- x (/ (* y (- z t)) a)) (- x (/ y (/ a (- z t))))))
(- x (/ (* y (- z t)) a)))