
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.5e+277)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 1.85e-6)
(+ x y)
(if (<= z 2.7e+142) (* x (+ z 1.0)) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+277) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1.85e-6) {
tmp = x + y;
} else if (z <= 2.7e+142) {
tmp = x * (z + 1.0);
} 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 <= (-2.5d+277)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 1.85d-6) then
tmp = x + y
else if (z <= 2.7d+142) then
tmp = x * (z + 1.0d0)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+277) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1.85e-6) {
tmp = x + y;
} else if (z <= 2.7e+142) {
tmp = x * (z + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e+277: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 1.85e-6: tmp = x + y elif z <= 2.7e+142: tmp = x * (z + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e+277) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 1.85e-6) tmp = Float64(x + y); elseif (z <= 2.7e+142) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e+277) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 1.85e-6) tmp = x + y; elseif (z <= 2.7e+142) tmp = x * (z + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e+277], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.85e-6], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.7e+142], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+277}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{-6}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+142}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.49999999999999991e277Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in87.5%
Applied egg-rr87.5%
Taylor expanded in y around 0 51.8%
*-commutative51.8%
Simplified51.8%
if -2.49999999999999991e277 < z < -1 or 2.69999999999999983e142 < z Initial program 100.0%
Taylor expanded in z around inf 98.9%
+-commutative98.9%
Simplified98.9%
distribute-lft-in95.7%
Applied egg-rr95.7%
Taylor expanded in y around inf 53.7%
*-commutative53.7%
Simplified53.7%
if -1 < z < 1.8500000000000001e-6Initial program 100.0%
Taylor expanded in z around 0 99.3%
+-commutative99.3%
Simplified99.3%
if 1.8500000000000001e-6 < z < 2.69999999999999983e142Initial program 100.0%
Taylor expanded in x around inf 50.8%
Final simplification73.5%
(FPCore (x y z)
:precision binary64
(if (<= z -3.3e+275)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 44.0) (+ x y) (if (<= z 3.3e+142) (* x z) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e+275) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 44.0) {
tmp = x + y;
} else if (z <= 3.3e+142) {
tmp = x * z;
} 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 <= (-3.3d+275)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 44.0d0) then
tmp = x + y
else if (z <= 3.3d+142) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e+275) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 44.0) {
tmp = x + y;
} else if (z <= 3.3e+142) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e+275: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 44.0: tmp = x + y elif z <= 3.3e+142: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e+275) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 44.0) tmp = Float64(x + y); elseif (z <= 3.3e+142) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.3e+275) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 44.0) tmp = x + y; elseif (z <= 3.3e+142) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e+275], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 44.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 3.3e+142], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+275}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 44:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 3.3 \cdot 10^{+142}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.30000000000000022e275 or 44 < z < 3.3000000000000002e142Initial program 100.0%
Taylor expanded in z around inf 98.1%
+-commutative98.1%
Simplified98.1%
distribute-lft-in96.0%
Applied egg-rr96.0%
Taylor expanded in y around 0 52.0%
*-commutative52.0%
Simplified52.0%
if -3.30000000000000022e275 < z < -1 or 3.3000000000000002e142 < z Initial program 100.0%
Taylor expanded in z around inf 98.9%
+-commutative98.9%
Simplified98.9%
distribute-lft-in95.7%
Applied egg-rr95.7%
Taylor expanded in y around inf 53.7%
*-commutative53.7%
Simplified53.7%
if -1 < z < 44Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification73.6%
(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 98.7%
+-commutative98.7%
Simplified98.7%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y 1.55e-49) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.55e-49) {
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 (y <= 1.55d-49) 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 (y <= 1.55e-49) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.55e-49: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.55e-49) 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 (y <= 1.55e-49) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.55e-49], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.55 \cdot 10^{-49}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 1.55e-49Initial program 100.0%
Taylor expanded in x around inf 62.4%
if 1.55e-49 < y Initial program 100.0%
Taylor expanded in x around 0 77.0%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (<= y 4.4e-40) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.4e-40) {
tmp = x * z;
} 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 (y <= 4.4d-40) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 4.4e-40) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.4e-40: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.4e-40) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.4e-40) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.4e-40], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.4 \cdot 10^{-40}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < 4.40000000000000018e-40Initial program 100.0%
Taylor expanded in z around inf 56.3%
+-commutative56.3%
Simplified56.3%
distribute-lft-in55.7%
Applied egg-rr55.7%
Taylor expanded in y around 0 37.4%
*-commutative37.4%
Simplified37.4%
if 4.40000000000000018e-40 < y Initial program 100.0%
Taylor expanded in z around inf 55.0%
+-commutative55.0%
Simplified55.0%
distribute-lft-in51.3%
Applied egg-rr51.3%
Taylor expanded in y around inf 44.9%
*-commutative44.9%
Simplified44.9%
Final simplification39.8%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return x * 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 * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 55.9%
+-commutative55.9%
Simplified55.9%
distribute-lft-in54.3%
Applied egg-rr54.3%
Taylor expanded in y around 0 31.1%
*-commutative31.1%
Simplified31.1%
Final simplification31.1%
herbie shell --seed 2024075
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))