
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e-123) (and (not (<= x -1.55e-180)) (<= x -1.6e-186))) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-123) || (!(x <= -1.55e-180) && (x <= -1.6e-186))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-2.4d-123)) .or. (.not. (x <= (-1.55d-180))) .and. (x <= (-1.6d-186))) then
tmp = x * (z + 1.0d0)
else
tmp = y * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-123) || (!(x <= -1.55e-180) && (x <= -1.6e-186))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e-123) or (not (x <= -1.55e-180) and (x <= -1.6e-186)): tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e-123) || (!(x <= -1.55e-180) && (x <= -1.6e-186))) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.4e-123) || (~((x <= -1.55e-180)) && (x <= -1.6e-186))) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e-123], And[N[Not[LessEqual[x, -1.55e-180]], $MachinePrecision], LessEqual[x, -1.6e-186]]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-123} \lor \neg \left(x \leq -1.55 \cdot 10^{-180}\right) \land x \leq -1.6 \cdot 10^{-186}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -2.4e-123 or -1.5499999999999999e-180 < x < -1.6e-186Initial program 100.0%
Taylor expanded in x around inf 62.1%
if -2.4e-123 < x < -1.5499999999999999e-180 or -1.6e-186 < x Initial program 100.0%
Taylor expanded in x around 0 60.6%
Final simplification61.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.3e+15) (not (<= z 2.35e-10))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.3e+15) || !(z <= 2.35e-10)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-7.3d+15)) .or. (.not. (z <= 2.35d-10))) then
tmp = z * (x + y)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.3e+15) || !(z <= 2.35e-10)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.3e+15) or not (z <= 2.35e-10): tmp = z * (x + y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.3e+15) || !(z <= 2.35e-10)) tmp = Float64(z * Float64(x + y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.3e+15) || ~((z <= 2.35e-10))) tmp = z * (x + y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.3e+15], N[Not[LessEqual[z, 2.35e-10]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.3 \cdot 10^{+15} \lor \neg \left(z \leq 2.35 \cdot 10^{-10}\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -7.3e15 or 2.3500000000000002e-10 < z Initial program 100.0%
Taylor expanded in z around inf 96.6%
+-commutative96.6%
Simplified96.6%
if -7.3e15 < z < 2.3500000000000002e-10Initial program 100.0%
Taylor expanded in z around 0 94.5%
+-commutative94.5%
Simplified94.5%
Final simplification95.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.3e+15) (not (<= z 1.45e-42))) (* x (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.3e+15) || !(z <= 1.45e-42)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-7.3d+15)) .or. (.not. (z <= 1.45d-42))) then
tmp = x * (z + 1.0d0)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.3e+15) || !(z <= 1.45e-42)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.3e+15) or not (z <= 1.45e-42): tmp = x * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.3e+15) || !(z <= 1.45e-42)) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.3e+15) || ~((z <= 1.45e-42))) tmp = x * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.3e+15], N[Not[LessEqual[z, 1.45e-42]], $MachinePrecision]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.3 \cdot 10^{+15} \lor \neg \left(z \leq 1.45 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -7.3e15 or 1.4500000000000001e-42 < z Initial program 100.0%
Taylor expanded in x around inf 48.6%
if -7.3e15 < z < 1.4500000000000001e-42Initial program 100.0%
Taylor expanded in z around 0 94.5%
+-commutative94.5%
Simplified94.5%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e-181) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-181) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 1.9d-181) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e-181) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e-181: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e-181) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e-181) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e-181], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-181}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.8999999999999999e-181Initial program 100.0%
Taylor expanded in x around inf 55.5%
Taylor expanded in z around 0 27.8%
if 1.8999999999999999e-181 < y Initial program 100.0%
Taylor expanded in x around 0 66.7%
Taylor expanded in z around 0 37.1%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return x + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + y
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 49.0%
+-commutative49.0%
Simplified49.0%
Final simplification49.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 48.4%
Taylor expanded in z around 0 23.7%
herbie shell --seed 2024107
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))