
(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 8 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 (* (+ z 1.0) (+ x y)))
double code(double x, double y, double z) {
return (z + 1.0) * (x + y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z + 1.0d0) * (x + y)
end function
public static double code(double x, double y, double z) {
return (z + 1.0) * (x + y);
}
def code(x, y, z): return (z + 1.0) * (x + y)
function code(x, y, z) return Float64(Float64(z + 1.0) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (z + 1.0) * (x + y); end
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(z + 1\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z 1.0))))
(if (<= (+ z 1.0) 0.99999988)
t_0
(if (<= (+ z 1.0) 1.2) (+ x y) (if (<= (+ z 1.0) 5e+232) t_0 (* y z))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if ((z + 1.0) <= 0.99999988) {
tmp = t_0;
} else if ((z + 1.0) <= 1.2) {
tmp = x + y;
} else if ((z + 1.0) <= 5e+232) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x * (z + 1.0d0)
if ((z + 1.0d0) <= 0.99999988d0) then
tmp = t_0
else if ((z + 1.0d0) <= 1.2d0) then
tmp = x + y
else if ((z + 1.0d0) <= 5d+232) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if ((z + 1.0) <= 0.99999988) {
tmp = t_0;
} else if ((z + 1.0) <= 1.2) {
tmp = x + y;
} else if ((z + 1.0) <= 5e+232) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if (z + 1.0) <= 0.99999988: tmp = t_0 elif (z + 1.0) <= 1.2: tmp = x + y elif (z + 1.0) <= 5e+232: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (Float64(z + 1.0) <= 0.99999988) tmp = t_0; elseif (Float64(z + 1.0) <= 1.2) tmp = Float64(x + y); elseif (Float64(z + 1.0) <= 5e+232) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if ((z + 1.0) <= 0.99999988) tmp = t_0; elseif ((z + 1.0) <= 1.2) tmp = x + y; elseif ((z + 1.0) <= 5e+232) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z + 1.0), $MachinePrecision], 0.99999988], t$95$0, If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.2], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 5e+232], t$95$0, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z + 1 \leq 0.99999988:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z + 1 \leq 1.2:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+232}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < 0.999999879999999952 or 1.19999999999999996 < (+.f64 z #s(literal 1 binary64)) < 4.99999999999999987e232Initial program 100.0%
Taylor expanded in x around inf 49.8%
if 0.999999879999999952 < (+.f64 z #s(literal 1 binary64)) < 1.19999999999999996Initial program 100.0%
Taylor expanded in z around 0 98.6%
+-commutative98.6%
Simplified98.6%
if 4.99999999999999987e232 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around 0 43.0%
Final simplification74.6%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z -3e-289)
x
(if (<= z 0.26) y (if (<= z 3.5e+234) (* x z) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -3e-289) {
tmp = x;
} else if (z <= 0.26) {
tmp = y;
} else if (z <= 3.5e+234) {
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)) then
tmp = x * z
else if (z <= (-3d-289)) then
tmp = x
else if (z <= 0.26d0) then
tmp = y
else if (z <= 3.5d+234) 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) {
tmp = x * z;
} else if (z <= -3e-289) {
tmp = x;
} else if (z <= 0.26) {
tmp = y;
} else if (z <= 3.5e+234) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= -3e-289: tmp = x elif z <= 0.26: tmp = y elif z <= 3.5e+234: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= -3e-289) tmp = x; elseif (z <= 0.26) tmp = y; elseif (z <= 3.5e+234) 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) tmp = x * z; elseif (z <= -3e-289) tmp = x; elseif (z <= 0.26) tmp = y; elseif (z <= 3.5e+234) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, -3e-289], x, If[LessEqual[z, 0.26], y, If[LessEqual[z, 3.5e+234], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -3 \cdot 10^{-289}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.26:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+234}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 0.26000000000000001 < z < 3.50000000000000033e234Initial program 100.0%
Taylor expanded in z around inf 97.1%
Taylor expanded in x around inf 49.2%
*-commutative49.2%
Simplified49.2%
if -1 < z < -2.9999999999999998e-289Initial program 100.0%
Taylor expanded in z around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in y around 0 46.2%
if -2.9999999999999998e-289 < z < 0.26000000000000001Initial program 100.0%
Taylor expanded in z around 0 99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in y around inf 56.6%
if 3.50000000000000033e234 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around 0 43.0%
Final simplification49.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 108.0) (+ x y) (if (<= z 1.66e+236) (* x z) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 108.0) {
tmp = x + y;
} else if (z <= 1.66e+236) {
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)) then
tmp = x * z
else if (z <= 108.0d0) then
tmp = x + y
else if (z <= 1.66d+236) 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) {
tmp = x * z;
} else if (z <= 108.0) {
tmp = x + y;
} else if (z <= 1.66e+236) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 108.0: tmp = x + y elif z <= 1.66e+236: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 108.0) tmp = Float64(x + y); elseif (z <= 1.66e+236) 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) tmp = x * z; elseif (z <= 108.0) tmp = x + y; elseif (z <= 1.66e+236) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 108.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.66e+236], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 108:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.66 \cdot 10^{+236}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 108 < z < 1.66000000000000005e236Initial program 100.0%
Taylor expanded in z around inf 98.6%
Taylor expanded in x around inf 50.1%
*-commutative50.1%
Simplified50.1%
if -1 < z < 108Initial program 100.0%
Taylor expanded in z around 0 96.2%
+-commutative96.2%
Simplified96.2%
if 1.66000000000000005e236 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around 0 43.0%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z -1.05e-286) x (if (<= z 0.31) y (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= -1.05e-286) {
tmp = x;
} else if (z <= 0.31) {
tmp = 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 <= (-1.0d0)) then
tmp = y * z
else if (z <= (-1.05d-286)) then
tmp = x
else if (z <= 0.31d0) then
tmp = 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 <= -1.0) {
tmp = y * z;
} else if (z <= -1.05e-286) {
tmp = x;
} else if (z <= 0.31) {
tmp = y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= -1.05e-286: tmp = x elif z <= 0.31: tmp = y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= -1.05e-286) tmp = x; elseif (z <= 0.31) tmp = y; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = y * z; elseif (z <= -1.05e-286) tmp = x; elseif (z <= 0.31) tmp = y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.05e-286], x, If[LessEqual[z, 0.31], y, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-286}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.31:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 0.309999999999999998 < z Initial program 100.0%
Taylor expanded in z around inf 97.6%
Taylor expanded in x around 0 50.6%
if -1 < z < -1.04999999999999994e-286Initial program 100.0%
Taylor expanded in z around 0 95.9%
+-commutative95.9%
Simplified95.9%
Taylor expanded in y around 0 46.2%
if -1.04999999999999994e-286 < z < 0.309999999999999998Initial program 100.0%
Taylor expanded in z around 0 99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in y around inf 56.6%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -5e-249) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-249) {
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-249)) 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-249) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -5e-249: 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-249) 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-249) 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-249], 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^{-249}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -4.9999999999999999e-249Initial program 100.0%
Taylor expanded in x around inf 49.7%
if -4.9999999999999999e-249 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 53.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-21) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e-21) {
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 <= (-1.05d-21)) 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 <= -1.05e-21) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e-21: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e-21) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e-21) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-21], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.05000000000000006e-21Initial program 100.0%
Taylor expanded in z around 0 49.9%
+-commutative49.9%
Simplified49.9%
Taylor expanded in y around 0 37.1%
if -1.05000000000000006e-21 < x Initial program 100.0%
Taylor expanded in z around 0 54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in y around inf 35.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 100.0%
Taylor expanded in z around 0 53.3%
+-commutative53.3%
Simplified53.3%
Taylor expanded in y around 0 25.5%
herbie shell --seed 2024172
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))