
(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 10 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) (* (+ x y) z)))
double code(double x, double y, double z) {
return (x + y) + ((x + y) * z);
}
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) + ((x + y) * z)
end function
public static double code(double x, double y, double z) {
return (x + y) + ((x + y) * z);
}
def code(x, y, z): return (x + y) + ((x + y) * z)
function code(x, y, z) return Float64(Float64(x + y) + Float64(Float64(x + y) * z)) end
function tmp = code(x, y, z) tmp = (x + y) + ((x + y) * z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) + \left(x + y\right) \cdot z
\end{array}
Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(if (<= (+ z 1.0) -2e+46)
(* x z)
(if (<= (+ z 1.0) -0.5)
(* y z)
(if (<= (+ z 1.0) 4e+21) (+ x y) (* x (+ z 1.0))))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -2e+46) {
tmp = x * z;
} else if ((z + 1.0) <= -0.5) {
tmp = y * z;
} else if ((z + 1.0) <= 4e+21) {
tmp = x + y;
} else {
tmp = x * (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 ((z + 1.0d0) <= (-2d+46)) then
tmp = x * z
else if ((z + 1.0d0) <= (-0.5d0)) then
tmp = y * z
else if ((z + 1.0d0) <= 4d+21) then
tmp = x + y
else
tmp = x * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -2e+46) {
tmp = x * z;
} else if ((z + 1.0) <= -0.5) {
tmp = y * z;
} else if ((z + 1.0) <= 4e+21) {
tmp = x + y;
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -2e+46: tmp = x * z elif (z + 1.0) <= -0.5: tmp = y * z elif (z + 1.0) <= 4e+21: tmp = x + y else: tmp = x * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -2e+46) tmp = Float64(x * z); elseif (Float64(z + 1.0) <= -0.5) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= 4e+21) tmp = Float64(x + y); else tmp = Float64(x * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= -2e+46) tmp = x * z; elseif ((z + 1.0) <= -0.5) tmp = y * z; elseif ((z + 1.0) <= 4e+21) tmp = x + y; else tmp = x * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -2e+46], N[(x * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], -0.5], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 4e+21], N[(x + y), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -2 \cdot 10^{+46}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z + 1 \leq -0.5:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq 4 \cdot 10^{+21}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -2e46Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 52.1%
*-commutative52.1%
Simplified52.1%
if -2e46 < (+.f64 z #s(literal 1 binary64)) < -0.5Initial program 100.0%
Taylor expanded in z around inf 89.8%
Taylor expanded in x around 0 52.7%
if -0.5 < (+.f64 z #s(literal 1 binary64)) < 4e21Initial program 100.0%
Taylor expanded in z around 0 94.9%
+-commutative94.9%
Simplified94.9%
if 4e21 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf 53.7%
Final simplification72.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.8e+45) (* x z) (if (<= z -1.0) (* y z) (if (<= z 2.4e+21) (+ x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e+45) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 2.4e+21) {
tmp = x + y;
} else {
tmp = x * 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 <= (-2.8d+45)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 2.4d+21) then
tmp = x + y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e+45) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 2.4e+21) {
tmp = x + y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.8e+45: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 2.4e+21: tmp = x + y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.8e+45) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 2.4e+21) tmp = Float64(x + y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.8e+45) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 2.4e+21) tmp = x + y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.8e+45], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.4e+21], N[(x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+45}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+21}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -2.7999999999999999e45 or 2.4e21 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 52.9%
*-commutative52.9%
Simplified52.9%
if -2.7999999999999999e45 < z < -1Initial program 100.0%
Taylor expanded in z around inf 89.8%
Taylor expanded in x around 0 52.7%
if -1 < z < 2.4e21Initial program 100.0%
Taylor expanded in z around 0 94.9%
+-commutative94.9%
Simplified94.9%
Final simplification72.9%
(FPCore (x y z) :precision binary64 (if (<= z -7.5e+45) (* x z) (if (<= z -4.8e-5) (* y z) (if (<= z 2.4e+21) y (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e+45) {
tmp = x * z;
} else if (z <= -4.8e-5) {
tmp = y * z;
} else if (z <= 2.4e+21) {
tmp = y;
} else {
tmp = x * 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 <= (-7.5d+45)) then
tmp = x * z
else if (z <= (-4.8d-5)) then
tmp = y * z
else if (z <= 2.4d+21) then
tmp = y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e+45) {
tmp = x * z;
} else if (z <= -4.8e-5) {
tmp = y * z;
} else if (z <= 2.4e+21) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.5e+45: tmp = x * z elif z <= -4.8e-5: tmp = y * z elif z <= 2.4e+21: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.5e+45) tmp = Float64(x * z); elseif (z <= -4.8e-5) tmp = Float64(y * z); elseif (z <= 2.4e+21) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.5e+45) tmp = x * z; elseif (z <= -4.8e-5) tmp = y * z; elseif (z <= 2.4e+21) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.5e+45], N[(x * z), $MachinePrecision], If[LessEqual[z, -4.8e-5], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.4e+21], y, N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+45}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-5}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+21}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -7.50000000000000058e45 or 2.4e21 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 52.9%
*-commutative52.9%
Simplified52.9%
if -7.50000000000000058e45 < z < -4.8000000000000001e-5Initial program 100.0%
Taylor expanded in z around inf 81.7%
Taylor expanded in x around 0 48.0%
if -4.8000000000000001e-5 < z < 2.4e21Initial program 100.0%
Taylor expanded in z around 0 95.4%
+-commutative95.4%
Simplified95.4%
Taylor expanded in y around inf 52.4%
Final simplification52.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-5) (not (<= z 1.0))) (* y z) y))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-5) || !(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 <= (-4.8d-5)) .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 <= -4.8e-5) || !(z <= 1.0)) {
tmp = y * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-5) or not (z <= 1.0): tmp = y * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-5) || !(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 <= -4.8e-5) || ~((z <= 1.0))) tmp = y * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-5], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-5} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -4.8000000000000001e-5 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.2%
Taylor expanded in x around 0 52.5%
if -4.8000000000000001e-5 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in y around inf 54.2%
Final simplification53.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-299) (* x (+ z 1.0)) (+ y (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-299) {
tmp = x * (z + 1.0);
} else {
tmp = y + (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 ((x + y) <= (-1d-299)) then
tmp = x * (z + 1.0d0)
else
tmp = y + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-299) {
tmp = x * (z + 1.0);
} else {
tmp = y + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -1e-299: tmp = x * (z + 1.0) else: tmp = y + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-299) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -1e-299) tmp = x * (z + 1.0); else tmp = y + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-299], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-299}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot z\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999992e-300Initial program 100.0%
Taylor expanded in x around inf 50.5%
if -9.99999999999999992e-300 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 53.8%
distribute-lft-in53.8%
*-rgt-identity53.8%
Applied egg-rr53.8%
Final simplification52.1%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-299) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-299) {
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 + y) <= (-1d-299)) 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 + y) <= -1e-299) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -1e-299: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-299) 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 + y) <= -1e-299) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-299], 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 + y \leq -1 \cdot 10^{-299}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999992e-300Initial program 100.0%
Taylor expanded in x around inf 50.5%
if -9.99999999999999992e-300 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 53.8%
(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 (<= y 2.1e-110) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.1e-110) {
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 <= 2.1d-110) 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 <= 2.1e-110) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.1e-110: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.1e-110) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.1e-110) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.1e-110], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{-110}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.10000000000000002e-110Initial program 100.0%
Taylor expanded in z around 0 44.7%
+-commutative44.7%
Simplified44.7%
Taylor expanded in y around 0 26.9%
if 2.10000000000000002e-110 < y Initial program 100.0%
Taylor expanded in z around 0 50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in y around inf 36.7%
(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 z around 0 46.8%
+-commutative46.8%
Simplified46.8%
Taylor expanded in y around 0 22.9%
herbie shell --seed 2024181
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))