
(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 (<= x -6.5e-77) (* x (+ z 1.0)) (if (or (<= x -1.9e-137) (not (<= x -2.35e-163))) (* y (+ z 1.0)) (+ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e-77) {
tmp = x * (z + 1.0);
} else if ((x <= -1.9e-137) || !(x <= -2.35e-163)) {
tmp = y * (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 (x <= (-6.5d-77)) then
tmp = x * (z + 1.0d0)
else if ((x <= (-1.9d-137)) .or. (.not. (x <= (-2.35d-163)))) then
tmp = y * (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 (x <= -6.5e-77) {
tmp = x * (z + 1.0);
} else if ((x <= -1.9e-137) || !(x <= -2.35e-163)) {
tmp = y * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.5e-77: tmp = x * (z + 1.0) elif (x <= -1.9e-137) or not (x <= -2.35e-163): tmp = y * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.5e-77) tmp = Float64(x * Float64(z + 1.0)); elseif ((x <= -1.9e-137) || !(x <= -2.35e-163)) tmp = Float64(y * Float64(z + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.5e-77) tmp = x * (z + 1.0); elseif ((x <= -1.9e-137) || ~((x <= -2.35e-163))) tmp = y * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.5e-77], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -1.9e-137], N[Not[LessEqual[x, -2.35e-163]], $MachinePrecision]], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-77}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-137} \lor \neg \left(x \leq -2.35 \cdot 10^{-163}\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if x < -6.4999999999999999e-77Initial program 100.0%
Taylor expanded in x around inf 69.3%
if -6.4999999999999999e-77 < x < -1.89999999999999999e-137 or -2.35e-163 < x Initial program 100.0%
Taylor expanded in x around 0 65.6%
if -1.89999999999999999e-137 < x < -2.35e-163Initial program 100.0%
Taylor expanded in z around 0 76.6%
+-commutative76.6%
Simplified76.6%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (<= z -4.5e+122) (* y z) (if (<= z -1.9e-5) (* x (+ z 1.0)) (if (<= z 56.0) (+ x y) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+122) {
tmp = y * z;
} else if (z <= -1.9e-5) {
tmp = x * (z + 1.0);
} else if (z <= 56.0) {
tmp = x + y;
} else {
tmp = y * z;
}
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 <= (-4.5d+122)) then
tmp = y * z
else if (z <= (-1.9d-5)) then
tmp = x * (z + 1.0d0)
else if (z <= 56.0d0) then
tmp = x + y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+122) {
tmp = y * z;
} else if (z <= -1.9e-5) {
tmp = x * (z + 1.0);
} else if (z <= 56.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e+122: tmp = y * z elif z <= -1.9e-5: tmp = x * (z + 1.0) elif z <= 56.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e+122) tmp = Float64(y * z); elseif (z <= -1.9e-5) tmp = Float64(x * Float64(z + 1.0)); elseif (z <= 56.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e+122) tmp = y * z; elseif (z <= -1.9e-5) tmp = x * (z + 1.0); elseif (z <= 56.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e+122], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.9e-5], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 56.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+122}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.9 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{elif}\;z \leq 56:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.49999999999999997e122 or 56 < z Initial program 100.0%
Taylor expanded in x around 0 54.2%
+-commutative54.2%
distribute-lft-in54.2%
*-rgt-identity54.2%
Applied egg-rr54.2%
Taylor expanded in z around inf 53.1%
if -4.49999999999999997e122 < z < -1.9000000000000001e-5Initial program 99.9%
Taylor expanded in x around inf 33.5%
if -1.9000000000000001e-5 < z < 56Initial program 100.0%
Taylor expanded in z around 0 99.3%
+-commutative99.3%
Simplified99.3%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) 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 <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * (x + y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= -1.0) || ~((z <= 1.0))) tmp = z * (x + y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 97.1%
+-commutative97.1%
Simplified97.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 65.0))) (* y z) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 65.0)) {
tmp = y * z;
} 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 <= (-1.0d0)) .or. (.not. (z <= 65.0d0))) then
tmp = y * z
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 65.0)) {
tmp = y * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 65.0): tmp = y * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 65.0)) tmp = Float64(y * z); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 65.0))) tmp = y * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 65.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 65\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 65 < z Initial program 100.0%
Taylor expanded in x around 0 56.5%
+-commutative56.5%
distribute-lft-in56.4%
*-rgt-identity56.4%
Applied egg-rr56.4%
Taylor expanded in z around inf 53.6%
if -1 < z < 65Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.21) (not (<= z 1.0))) (* y z) y))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.21) || !(z <= 1.0)) {
tmp = y * z;
} 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 ((z <= (-0.21d0)) .or. (.not. (z <= 1.0d0))) then
tmp = y * z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -0.21) || !(z <= 1.0)) {
tmp = y * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.21) or not (z <= 1.0): tmp = y * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.21) || !(z <= 1.0)) tmp = Float64(y * z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.21) || ~((z <= 1.0))) tmp = y * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.21], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.21 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -0.209999999999999992 or 1 < z Initial program 100.0%
Taylor expanded in x around 0 56.8%
+-commutative56.8%
distribute-lft-in56.8%
*-rgt-identity56.8%
Applied egg-rr56.8%
Taylor expanded in z around inf 53.2%
if -0.209999999999999992 < z < 1Initial program 100.0%
Taylor expanded in x around 0 55.6%
Taylor expanded in z around 0 55.2%
Final simplification54.2%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 56.2%
Taylor expanded in z around 0 29.0%
herbie shell --seed 2024108
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))