
(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 -1.25e+125)
(* y z)
(if (<= z -9.5e+49)
(* x z)
(if (<= z -2.1e+30)
(* y z)
(if (<= z -1.0) (* x z) (if (<= z 24.0) (+ x y) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+125) {
tmp = y * z;
} else if (z <= -9.5e+49) {
tmp = x * z;
} else if (z <= -2.1e+30) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 24.0) {
tmp = x + 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.25d+125)) then
tmp = y * z
else if (z <= (-9.5d+49)) then
tmp = x * z
else if (z <= (-2.1d+30)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= 24.0d0) then
tmp = x + 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.25e+125) {
tmp = y * z;
} else if (z <= -9.5e+49) {
tmp = x * z;
} else if (z <= -2.1e+30) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 24.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+125: tmp = y * z elif z <= -9.5e+49: tmp = x * z elif z <= -2.1e+30: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= 24.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+125) tmp = Float64(y * z); elseif (z <= -9.5e+49) tmp = Float64(x * z); elseif (z <= -2.1e+30) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= 24.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.25e+125) tmp = y * z; elseif (z <= -9.5e+49) tmp = x * z; elseif (z <= -2.1e+30) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= 24.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+125], N[(y * z), $MachinePrecision], If[LessEqual[z, -9.5e+49], N[(x * z), $MachinePrecision], If[LessEqual[z, -2.1e+30], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 24.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+125}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{+49}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{+30}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 24:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.24999999999999991e125 or -9.49999999999999969e49 < z < -2.1e30 or 24 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in y around inf 57.9%
if -1.24999999999999991e125 < z < -9.49999999999999969e49 or -2.1e30 < z < -1Initial program 100.0%
Taylor expanded in z around inf 93.9%
+-commutative93.9%
Simplified93.9%
Taylor expanded in y around 0 39.3%
if -1 < z < 24Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification79.6%
(FPCore (x y z)
:precision binary64
(if (<= z -1.8e+128)
(* y z)
(if (<= z -1.16e+50)
(* x z)
(if (<= z -1.95e+30)
(* y z)
(if (<= z -0.105) (* x (+ z 1.0)) (if (<= z 80.0) (+ x y) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+128) {
tmp = y * z;
} else if (z <= -1.16e+50) {
tmp = x * z;
} else if (z <= -1.95e+30) {
tmp = y * z;
} else if (z <= -0.105) {
tmp = x * (z + 1.0);
} else if (z <= 80.0) {
tmp = x + 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.8d+128)) then
tmp = y * z
else if (z <= (-1.16d+50)) then
tmp = x * z
else if (z <= (-1.95d+30)) then
tmp = y * z
else if (z <= (-0.105d0)) then
tmp = x * (z + 1.0d0)
else if (z <= 80.0d0) then
tmp = x + 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.8e+128) {
tmp = y * z;
} else if (z <= -1.16e+50) {
tmp = x * z;
} else if (z <= -1.95e+30) {
tmp = y * z;
} else if (z <= -0.105) {
tmp = x * (z + 1.0);
} else if (z <= 80.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.8e+128: tmp = y * z elif z <= -1.16e+50: tmp = x * z elif z <= -1.95e+30: tmp = y * z elif z <= -0.105: tmp = x * (z + 1.0) elif z <= 80.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.8e+128) tmp = Float64(y * z); elseif (z <= -1.16e+50) tmp = Float64(x * z); elseif (z <= -1.95e+30) tmp = Float64(y * z); elseif (z <= -0.105) tmp = Float64(x * Float64(z + 1.0)); elseif (z <= 80.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.8e+128) tmp = y * z; elseif (z <= -1.16e+50) tmp = x * z; elseif (z <= -1.95e+30) tmp = y * z; elseif (z <= -0.105) tmp = x * (z + 1.0); elseif (z <= 80.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+128], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.16e+50], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.95e+30], N[(y * z), $MachinePrecision], If[LessEqual[z, -0.105], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 80.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+128}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.16 \cdot 10^{+50}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1.95 \cdot 10^{+30}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -0.105:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{elif}\;z \leq 80:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.80000000000000014e128 or -1.16e50 < z < -1.95000000000000005e30 or 80 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in y around inf 57.9%
if -1.80000000000000014e128 < z < -1.16e50Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 33.5%
if -1.95000000000000005e30 < z < -0.104999999999999996Initial program 100.0%
Taylor expanded in x around inf 67.7%
if -0.104999999999999996 < z < 80Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification79.9%
(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 97.4%
+-commutative97.4%
Simplified97.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e-127) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-127) {
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 <= (-1.9d-127)) 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 <= -1.9e-127) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e-127: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e-127) 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 <= -1.9e-127) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e-127], 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 \leq -1.9 \cdot 10^{-127}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -1.90000000000000001e-127Initial program 100.0%
Taylor expanded in x around inf 69.1%
if -1.90000000000000001e-127 < x Initial program 100.0%
Taylor expanded in x around 0 63.8%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.5e-122) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.5e-122) {
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 (x <= (-3.5d-122)) 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 (x <= -3.5e-122) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.5e-122: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.5e-122) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.5e-122) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.5e-122], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-122}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.5000000000000001e-122Initial program 100.0%
Taylor expanded in z around inf 42.6%
+-commutative42.6%
Simplified42.6%
Taylor expanded in y around 0 32.2%
if -3.5000000000000001e-122 < x Initial program 100.0%
Taylor expanded in z around inf 44.5%
+-commutative44.5%
Simplified44.5%
Taylor expanded in y around inf 33.0%
Final simplification32.7%
(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 43.8%
+-commutative43.8%
Simplified43.8%
Taylor expanded in y around 0 22.9%
Final simplification22.9%
herbie shell --seed 2024053
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))