
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(if (<= x -9.8e+89)
(* 0.5 (/ x t))
(if (or (<= x -3e-260) (and (not (<= x 2.35e-239)) (<= x 1.75e-137)))
(/ (* z -0.5) t)
(/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -9.8e+89) {
tmp = 0.5 * (x / t);
} else if ((x <= -3e-260) || (!(x <= 2.35e-239) && (x <= 1.75e-137))) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / 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 <= (-9.8d+89)) then
tmp = 0.5d0 * (x / t)
else if ((x <= (-3d-260)) .or. (.not. (x <= 2.35d-239)) .and. (x <= 1.75d-137)) then
tmp = (z * (-0.5d0)) / t
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -9.8e+89) {
tmp = 0.5 * (x / t);
} else if ((x <= -3e-260) || (!(x <= 2.35e-239) && (x <= 1.75e-137))) {
tmp = (z * -0.5) / t;
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -9.8e+89: tmp = 0.5 * (x / t) elif (x <= -3e-260) or (not (x <= 2.35e-239) and (x <= 1.75e-137)): tmp = (z * -0.5) / t else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -9.8e+89) tmp = Float64(0.5 * Float64(x / t)); elseif ((x <= -3e-260) || (!(x <= 2.35e-239) && (x <= 1.75e-137))) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -9.8e+89) tmp = 0.5 * (x / t); elseif ((x <= -3e-260) || (~((x <= 2.35e-239)) && (x <= 1.75e-137))) tmp = (z * -0.5) / t; else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -9.8e+89], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -3e-260], And[N[Not[LessEqual[x, 2.35e-239]], $MachinePrecision], LessEqual[x, 1.75e-137]]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{+89}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{elif}\;x \leq -3 \cdot 10^{-260} \lor \neg \left(x \leq 2.35 \cdot 10^{-239}\right) \land x \leq 1.75 \cdot 10^{-137}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -9.79999999999999992e89Initial program 100.0%
Taylor expanded in x around inf 70.0%
if -9.79999999999999992e89 < x < -3.0000000000000001e-260 or 2.3500000000000001e-239 < x < 1.7500000000000001e-137Initial program 100.0%
Taylor expanded in z around inf 55.3%
*-commutative55.3%
associate-*l/55.3%
Simplified55.3%
if -3.0000000000000001e-260 < x < 2.3500000000000001e-239 or 1.7500000000000001e-137 < x Initial program 100.0%
Taylor expanded in y around inf 42.0%
associate-*r/42.0%
Simplified42.0%
Final simplification50.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8.5e+84) (not (<= z 2.75e+100))) (/ (* z -0.5) t) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.5e+84) || !(z <= 2.75e+100)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / 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 <= (-8.5d+84)) .or. (.not. (z <= 2.75d+100))) then
tmp = (z * (-0.5d0)) / t
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.5e+84) || !(z <= 2.75e+100)) {
tmp = (z * -0.5) / t;
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8.5e+84) or not (z <= 2.75e+100): tmp = (z * -0.5) / t else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8.5e+84) || !(z <= 2.75e+100)) tmp = Float64(Float64(z * -0.5) / t); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8.5e+84) || ~((z <= 2.75e+100))) tmp = (z * -0.5) / t; else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8.5e+84], N[Not[LessEqual[z, 2.75e+100]], $MachinePrecision]], N[(N[(z * -0.5), $MachinePrecision] / t), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+84} \lor \neg \left(z \leq 2.75 \cdot 10^{+100}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if z < -8.5000000000000008e84 or 2.7500000000000001e100 < z Initial program 100.0%
Taylor expanded in z around inf 82.8%
*-commutative82.8%
associate-*l/82.8%
Simplified82.8%
if -8.5000000000000008e84 < z < 2.7500000000000001e100Initial program 100.0%
Taylor expanded in z around 0 89.7%
associate-*r/89.7%
associate-*l/89.4%
*-commutative89.4%
+-commutative89.4%
Simplified89.4%
Final simplification87.0%
(FPCore (x y z t) :precision binary64 (if (<= x -0.028) (* (- x z) (/ 0.5 t)) (/ (* 0.5 (- y z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.028) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (0.5 * (y - z)) / 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 <= (-0.028d0)) then
tmp = (x - z) * (0.5d0 / t)
else
tmp = (0.5d0 * (y - z)) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.028) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (0.5 * (y - z)) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -0.028: tmp = (x - z) * (0.5 / t) else: tmp = (0.5 * (y - z)) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -0.028) tmp = Float64(Float64(x - z) * Float64(0.5 / t)); else tmp = Float64(Float64(0.5 * Float64(y - z)) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -0.028) tmp = (x - z) * (0.5 / t); else tmp = (0.5 * (y - z)) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.028], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(y - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.028:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(y - z\right)}{t}\\
\end{array}
\end{array}
if x < -0.0280000000000000006Initial program 100.0%
Taylor expanded in y around 0 76.9%
*-commutative76.9%
associate-*l/76.9%
associate-/l*76.6%
Simplified76.6%
if -0.0280000000000000006 < x Initial program 100.0%
Taylor expanded in x around 0 77.5%
associate-*r/77.5%
Simplified77.5%
(FPCore (x y z t) :precision binary64 (if (<= y 7e+62) (* (- x z) (/ 0.5 t)) (* (+ x y) (/ 0.5 t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7e+62) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (x + y) * (0.5 / 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 (y <= 7d+62) then
tmp = (x - z) * (0.5d0 / t)
else
tmp = (x + y) * (0.5d0 / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7e+62) {
tmp = (x - z) * (0.5 / t);
} else {
tmp = (x + y) * (0.5 / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 7e+62: tmp = (x - z) * (0.5 / t) else: tmp = (x + y) * (0.5 / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 7e+62) tmp = Float64(Float64(x - z) * Float64(0.5 / t)); else tmp = Float64(Float64(x + y) * Float64(0.5 / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 7e+62) tmp = (x - z) * (0.5 / t); else tmp = (x + y) * (0.5 / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 7e+62], N[(N[(x - z), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{+62}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{0.5}{t}\\
\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\
\end{array}
\end{array}
if y < 6.99999999999999967e62Initial program 100.0%
Taylor expanded in y around 0 75.3%
*-commutative75.3%
associate-*l/75.3%
associate-/l*75.1%
Simplified75.1%
if 6.99999999999999967e62 < y Initial program 100.0%
Taylor expanded in z around 0 81.8%
associate-*r/81.8%
associate-*l/81.6%
*-commutative81.6%
+-commutative81.6%
Simplified81.6%
Final simplification76.6%
(FPCore (x y z t) :precision binary64 (if (<= x -0.0105) (* 0.5 (/ x t)) (/ (* y 0.5) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.0105) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / 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 <= (-0.0105d0)) then
tmp = 0.5d0 * (x / t)
else
tmp = (y * 0.5d0) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -0.0105) {
tmp = 0.5 * (x / t);
} else {
tmp = (y * 0.5) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -0.0105: tmp = 0.5 * (x / t) else: tmp = (y * 0.5) / t return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -0.0105) tmp = Float64(0.5 * Float64(x / t)); else tmp = Float64(Float64(y * 0.5) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -0.0105) tmp = 0.5 * (x / t); else tmp = (y * 0.5) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.0105], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0105:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot 0.5}{t}\\
\end{array}
\end{array}
if x < -0.0105000000000000007Initial program 100.0%
Taylor expanded in x around inf 53.5%
if -0.0105000000000000007 < x Initial program 100.0%
Taylor expanded in y around inf 42.4%
associate-*r/42.4%
Simplified42.4%
Final simplification45.3%
(FPCore (x y z t) :precision binary64 (* 0.5 (/ x t)))
double code(double x, double y, double z, double t) {
return 0.5 * (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 = 0.5d0 * (x / t)
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (x / t);
}
def code(x, y, z, t): return 0.5 * (x / t)
function code(x, y, z, t) return Float64(0.5 * Float64(x / t)) end
function tmp = code(x, y, z, t) tmp = 0.5 * (x / t); end
code[x_, y_, z_, t_] := N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{x}{t}
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 36.7%
herbie shell --seed 2024101
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, B"
:precision binary64
(/ (- (+ x y) z) (* t 2.0)))