
(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 9 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 99.9%
+-commutative99.9%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(if (<= (+ z 1.0) -5e+138)
(* x z)
(if (or (<= (+ z 1.0) -200.0) (not (<= (+ z 1.0) 10000000000000.0)))
(* y z)
(+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5e+138) {
tmp = x * z;
} else if (((z + 1.0) <= -200.0) || !((z + 1.0) <= 10000000000000.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) <= (-5d+138)) then
tmp = x * z
else if (((z + 1.0d0) <= (-200.0d0)) .or. (.not. ((z + 1.0d0) <= 10000000000000.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) <= -5e+138) {
tmp = x * z;
} else if (((z + 1.0) <= -200.0) || !((z + 1.0) <= 10000000000000.0)) {
tmp = y * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -5e+138: tmp = x * z elif ((z + 1.0) <= -200.0) or not ((z + 1.0) <= 10000000000000.0): tmp = y * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -5e+138) tmp = Float64(x * z); elseif ((Float64(z + 1.0) <= -200.0) || !(Float64(z + 1.0) <= 10000000000000.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) <= -5e+138) tmp = x * z; elseif (((z + 1.0) <= -200.0) || ~(((z + 1.0) <= 10000000000000.0))) tmp = y * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -5e+138], N[(x * z), $MachinePrecision], If[Or[LessEqual[N[(z + 1.0), $MachinePrecision], -200.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 10000000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5 \cdot 10^{+138}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z + 1 \leq -200 \lor \neg \left(z + 1 \leq 10000000000000\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -5.00000000000000016e138Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 66.2%
*-commutative66.2%
Simplified66.2%
if -5.00000000000000016e138 < (+.f64 z #s(literal 1 binary64)) < -200 or 1e13 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf 97.9%
Taylor expanded in x around 0 43.9%
if -200 < (+.f64 z #s(literal 1 binary64)) < 1e13Initial program 99.9%
Taylor expanded in z around 0 95.0%
+-commutative95.0%
Simplified95.0%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+138) (* x z) (if (or (<= z -1.0) (not (<= z 5500000000000.0))) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+138) {
tmp = x * z;
} else if ((z <= -1.0) || !(z <= 5500000000000.0)) {
tmp = y * z;
} else {
tmp = x;
}
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 <= (-5.5d+138)) then
tmp = x * z
else if ((z <= (-1.0d0)) .or. (.not. (z <= 5500000000000.0d0))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+138) {
tmp = x * z;
} else if ((z <= -1.0) || !(z <= 5500000000000.0)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+138: tmp = x * z elif (z <= -1.0) or not (z <= 5500000000000.0): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+138) tmp = Float64(x * z); elseif ((z <= -1.0) || !(z <= 5500000000000.0)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+138) tmp = x * z; elseif ((z <= -1.0) || ~((z <= 5500000000000.0))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+138], N[(x * z), $MachinePrecision], If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 5500000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+138}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1 \lor \neg \left(z \leq 5500000000000\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4999999999999999e138Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 66.2%
*-commutative66.2%
Simplified66.2%
if -5.4999999999999999e138 < z < -1 or 5.5e12 < z Initial program 100.0%
Taylor expanded in z around inf 97.9%
Taylor expanded in x around 0 43.9%
if -1 < z < 5.5e12Initial program 99.9%
Taylor expanded in z around 0 95.0%
+-commutative95.0%
Simplified95.0%
Taylor expanded in y around 0 38.5%
Final simplification44.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 5500000000000.0))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 5500000000000.0)) {
tmp = y * z;
} else {
tmp = x;
}
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 <= 5500000000000.0d0))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 5500000000000.0)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 5500000000000.0): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 5500000000000.0)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 5500000000000.0))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 5500000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 5500000000000\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 5.5e12 < z Initial program 100.0%
Taylor expanded in z around inf 98.4%
Taylor expanded in x around 0 44.3%
if -1 < z < 5.5e12Initial program 99.9%
Taylor expanded in z around 0 95.0%
+-commutative95.0%
Simplified95.0%
Taylor expanded in y around 0 38.5%
Final simplification41.5%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -5e-211) (+ x (* x z)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-211) {
tmp = x + (x * z);
} 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) <= (-5d-211)) then
tmp = x + (x * z)
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) <= -5e-211) {
tmp = x + (x * z);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -5e-211: tmp = x + (x * z) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -5e-211) tmp = Float64(x + Float64(x * z)); 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) <= -5e-211) tmp = x + (x * z); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -5e-211], N[(x + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -5 \cdot 10^{-211}:\\
\;\;\;\;x + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -5.0000000000000002e-211Initial program 99.9%
Taylor expanded in x around inf 45.0%
distribute-lft-in45.0%
*-rgt-identity45.0%
Applied egg-rr45.0%
if -5.0000000000000002e-211 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 48.4%
Final simplification46.8%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -5e-211) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-211) {
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) <= (-5d-211)) 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) <= -5e-211) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -5e-211: 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) <= -5e-211) 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) <= -5e-211) 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], -5e-211], 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 -5 \cdot 10^{-211}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -5.0000000000000002e-211Initial program 99.9%
Taylor expanded in x around inf 45.0%
if -5.0000000000000002e-211 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 48.4%
(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 99.9%
(FPCore (x y z) :precision binary64 (if (<= y 4.8e-92) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.8e-92) {
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 <= 4.8d-92) 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 <= 4.8e-92) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.8e-92: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.8e-92) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.8e-92) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.8e-92], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.8 \cdot 10^{-92}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.8000000000000002e-92Initial program 99.9%
Taylor expanded in z around 0 48.9%
+-commutative48.9%
Simplified48.9%
Taylor expanded in y around 0 22.4%
if 4.8000000000000002e-92 < y Initial program 100.0%
Taylor expanded in z around 0 46.9%
+-commutative46.9%
Simplified46.9%
Taylor expanded in y around inf 31.3%
(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 99.9%
Taylor expanded in z around 0 48.1%
+-commutative48.1%
Simplified48.1%
Taylor expanded in y around 0 20.2%
herbie shell --seed 2024146
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))