
(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) -100.0) (* y z) (if (<= (+ z 1.0) 50.0) (+ x y) (if (<= (+ z 1.0) 5e+97) (* x z) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -100.0) {
tmp = y * z;
} else if ((z + 1.0) <= 50.0) {
tmp = x + y;
} else if ((z + 1.0) <= 5e+97) {
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 + 1.0d0) <= (-100.0d0)) then
tmp = y * z
else if ((z + 1.0d0) <= 50.0d0) then
tmp = x + y
else if ((z + 1.0d0) <= 5d+97) 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 + 1.0) <= -100.0) {
tmp = y * z;
} else if ((z + 1.0) <= 50.0) {
tmp = x + y;
} else if ((z + 1.0) <= 5e+97) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -100.0: tmp = y * z elif (z + 1.0) <= 50.0: tmp = x + y elif (z + 1.0) <= 5e+97: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -100.0) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= 50.0) tmp = Float64(x + y); elseif (Float64(z + 1.0) <= 5e+97) 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 + 1.0) <= -100.0) tmp = y * z; elseif ((z + 1.0) <= 50.0) tmp = x + y; elseif ((z + 1.0) <= 5e+97) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -100.0], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 50.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 5e+97], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -100:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq 50:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+97}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -100 or 4.99999999999999999e97 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf 98.1%
Taylor expanded in x around 0 59.8%
if -100 < (+.f64 z #s(literal 1 binary64)) < 50Initial program 100.0%
Taylor expanded in z around 0 96.8%
+-commutative96.8%
Simplified96.8%
if 50 < (+.f64 z #s(literal 1 binary64)) < 4.99999999999999999e97Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 54.7%
*-commutative54.7%
Simplified54.7%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= z -0.21) (* y z) (if (<= z 3500000.0) y (if (<= z 2.7e+98) (* x z) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.21) {
tmp = y * z;
} else if (z <= 3500000.0) {
tmp = y;
} else if (z <= 2.7e+98) {
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 <= (-0.21d0)) then
tmp = y * z
else if (z <= 3500000.0d0) then
tmp = y
else if (z <= 2.7d+98) 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 <= -0.21) {
tmp = y * z;
} else if (z <= 3500000.0) {
tmp = y;
} else if (z <= 2.7e+98) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.21: tmp = y * z elif z <= 3500000.0: tmp = y elif z <= 2.7e+98: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.21) tmp = Float64(y * z); elseif (z <= 3500000.0) tmp = y; elseif (z <= 2.7e+98) 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 <= -0.21) tmp = y * z; elseif (z <= 3500000.0) tmp = y; elseif (z <= 2.7e+98) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.21], N[(y * z), $MachinePrecision], If[LessEqual[z, 3500000.0], y, If[LessEqual[z, 2.7e+98], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.21:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3500000:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+98}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -0.209999999999999992 or 2.7e98 < z Initial program 100.0%
Taylor expanded in z around inf 97.2%
Taylor expanded in x around 0 59.3%
if -0.209999999999999992 < z < 3.5e6Initial program 100.0%
Taylor expanded in z around 0 97.3%
+-commutative97.3%
Simplified97.3%
Taylor expanded in y around inf 49.0%
if 3.5e6 < z < 2.7e98Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 54.7%
*-commutative54.7%
Simplified54.7%
Final simplification53.9%
(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 z around inf 97.0%
Taylor expanded in x around 0 57.8%
if -0.209999999999999992 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in y around inf 49.3%
Final simplification53.5%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-226) (+ x (* x z)) (+ y (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-226) {
tmp = x + (x * z);
} 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) <= (-2d-226)) then
tmp = x + (x * z)
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) <= -2e-226) {
tmp = x + (x * z);
} else {
tmp = y + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-226: tmp = x + (x * z) else: tmp = y + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-226) tmp = Float64(x + Float64(x * z)); else tmp = Float64(y + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-226) tmp = x + (x * z); else tmp = y + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-226], N[(x + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-226}:\\
\;\;\;\;x + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot z\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999984e-226Initial program 100.0%
Taylor expanded in x around inf 52.2%
distribute-lft-in52.2%
*-rgt-identity52.2%
Applied egg-rr52.2%
if -1.99999999999999984e-226 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 58.2%
distribute-lft-in58.2%
*-rgt-identity58.2%
Applied egg-rr58.2%
Final simplification55.6%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-226) (+ x (* x z)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-226) {
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) <= (-2d-226)) 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) <= -2e-226) {
tmp = x + (x * z);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-226: tmp = x + (x * z) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-226) 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) <= -2e-226) 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], -2e-226], 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 -2 \cdot 10^{-226}:\\
\;\;\;\;x + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999984e-226Initial program 100.0%
Taylor expanded in x around inf 52.2%
distribute-lft-in52.2%
*-rgt-identity52.2%
Applied egg-rr52.2%
if -1.99999999999999984e-226 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 58.2%
Final simplification55.6%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-226) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-226) {
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) <= (-2d-226)) 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) <= -2e-226) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-226: 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) <= -2e-226) 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) <= -2e-226) 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], -2e-226], 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 -2 \cdot 10^{-226}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999984e-226Initial program 100.0%
Taylor expanded in x around inf 52.2%
if -1.99999999999999984e-226 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 58.2%
(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 -8.6e-133) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.6e-133) {
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 (x <= (-8.6d-133)) 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 (x <= -8.6e-133) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.6e-133: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.6e-133) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.6e-133) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.6e-133], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-133}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -8.60000000000000032e-133Initial program 100.0%
Taylor expanded in z around 0 46.9%
+-commutative46.9%
Simplified46.9%
Taylor expanded in y around 0 32.9%
if -8.60000000000000032e-133 < x Initial program 100.0%
Taylor expanded in z around 0 52.5%
+-commutative52.5%
Simplified52.5%
Taylor expanded in y around inf 31.4%
(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 50.8%
+-commutative50.8%
Simplified50.8%
Taylor expanded in y around 0 26.1%
herbie shell --seed 2024116
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))