
(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
(let* ((t_0 (* x (+ z 1.0))))
(if (<= z -2.3e+235)
(* y z)
(if (<= z -2.6e+67)
(* x z)
(if (<= z -4.4e+22)
(* y z)
(if (<= z -0.0028)
t_0
(if (<= z 9.2e-5) (+ x y) (if (<= z 1.65e+81) t_0 (* y z)))))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -2.3e+235) {
tmp = y * z;
} else if (z <= -2.6e+67) {
tmp = x * z;
} else if (z <= -4.4e+22) {
tmp = y * z;
} else if (z <= -0.0028) {
tmp = t_0;
} else if (z <= 9.2e-5) {
tmp = x + y;
} else if (z <= 1.65e+81) {
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 <= (-2.3d+235)) then
tmp = y * z
else if (z <= (-2.6d+67)) then
tmp = x * z
else if (z <= (-4.4d+22)) then
tmp = y * z
else if (z <= (-0.0028d0)) then
tmp = t_0
else if (z <= 9.2d-5) then
tmp = x + y
else if (z <= 1.65d+81) 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 <= -2.3e+235) {
tmp = y * z;
} else if (z <= -2.6e+67) {
tmp = x * z;
} else if (z <= -4.4e+22) {
tmp = y * z;
} else if (z <= -0.0028) {
tmp = t_0;
} else if (z <= 9.2e-5) {
tmp = x + y;
} else if (z <= 1.65e+81) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -2.3e+235: tmp = y * z elif z <= -2.6e+67: tmp = x * z elif z <= -4.4e+22: tmp = y * z elif z <= -0.0028: tmp = t_0 elif z <= 9.2e-5: tmp = x + y elif z <= 1.65e+81: 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 (z <= -2.3e+235) tmp = Float64(y * z); elseif (z <= -2.6e+67) tmp = Float64(x * z); elseif (z <= -4.4e+22) tmp = Float64(y * z); elseif (z <= -0.0028) tmp = t_0; elseif (z <= 9.2e-5) tmp = Float64(x + y); elseif (z <= 1.65e+81) 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 <= -2.3e+235) tmp = y * z; elseif (z <= -2.6e+67) tmp = x * z; elseif (z <= -4.4e+22) tmp = y * z; elseif (z <= -0.0028) tmp = t_0; elseif (z <= 9.2e-5) tmp = x + y; elseif (z <= 1.65e+81) 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[z, -2.3e+235], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.6e+67], N[(x * z), $MachinePrecision], If[LessEqual[z, -4.4e+22], N[(y * z), $MachinePrecision], If[LessEqual[z, -0.0028], t$95$0, If[LessEqual[z, 9.2e-5], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.65e+81], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -2.3 \cdot 10^{+235}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.6 \cdot 10^{+67}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{+22}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -0.0028:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{-5}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.3e235 or -2.6e67 < z < -4.4e22 or 1.65e81 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in90.8%
flip-+28.7%
Applied egg-rr28.7%
difference-of-squares29.0%
+-commutative29.0%
distribute-lft-in29.0%
associate-/l*48.6%
*-inverses100.0%
*-commutative100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 49.6%
if -2.3e235 < z < -2.6e67Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 43.7%
if -4.4e22 < z < -0.00279999999999999997 or 9.20000000000000001e-5 < z < 1.65e81Initial program 99.8%
Taylor expanded in x around inf 70.0%
if -0.00279999999999999997 < z < 9.20000000000000001e-5Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification72.8%
(FPCore (x y z)
:precision binary64
(if (<= z -2.3e+235)
(* y z)
(if (<= z -5.1e+67)
(* x z)
(if (or (<= z -21.0) (not (<= z 1.1e+23))) (* y z) (+ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e+235) {
tmp = y * z;
} else if (z <= -5.1e+67) {
tmp = x * z;
} else if ((z <= -21.0) || !(z <= 1.1e+23)) {
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 <= (-2.3d+235)) then
tmp = y * z
else if (z <= (-5.1d+67)) then
tmp = x * z
else if ((z <= (-21.0d0)) .or. (.not. (z <= 1.1d+23))) 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 <= -2.3e+235) {
tmp = y * z;
} else if (z <= -5.1e+67) {
tmp = x * z;
} else if ((z <= -21.0) || !(z <= 1.1e+23)) {
tmp = y * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.3e+235: tmp = y * z elif z <= -5.1e+67: tmp = x * z elif (z <= -21.0) or not (z <= 1.1e+23): tmp = y * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.3e+235) tmp = Float64(y * z); elseif (z <= -5.1e+67) tmp = Float64(x * z); elseif ((z <= -21.0) || !(z <= 1.1e+23)) 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 <= -2.3e+235) tmp = y * z; elseif (z <= -5.1e+67) tmp = x * z; elseif ((z <= -21.0) || ~((z <= 1.1e+23))) tmp = y * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.3e+235], N[(y * z), $MachinePrecision], If[LessEqual[z, -5.1e+67], N[(x * z), $MachinePrecision], If[Or[LessEqual[z, -21.0], N[Not[LessEqual[z, 1.1e+23]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+235}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -5.1 \cdot 10^{+67}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -21 \lor \neg \left(z \leq 1.1 \cdot 10^{+23}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.3e235 or -5.1000000000000002e67 < z < -21 or 1.10000000000000004e23 < z Initial program 100.0%
Taylor expanded in z around inf 98.6%
+-commutative98.6%
Simplified98.6%
distribute-lft-in90.4%
flip-+29.7%
Applied egg-rr29.7%
difference-of-squares30.0%
+-commutative30.0%
distribute-lft-in30.0%
associate-/l*52.7%
*-inverses98.6%
*-commutative98.6%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in x around 0 46.5%
if -2.3e235 < z < -5.1000000000000002e67Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 43.7%
if -21 < z < 1.10000000000000004e23Initial program 100.0%
Taylor expanded in z around 0 94.8%
+-commutative94.8%
Simplified94.8%
Final simplification69.8%
(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 99.9%
Taylor expanded in z around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.7%
+-commutative97.7%
Simplified97.7%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.25e-101) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e-101) {
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.25d-101)) 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.25e-101) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e-101: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e-101) 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.25e-101) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e-101], 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.25 \cdot 10^{-101}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -1.25e-101Initial program 100.0%
Taylor expanded in x around inf 64.9%
if -1.25e-101 < x Initial program 100.0%
Taylor expanded in x around 0 58.2%
Final simplification60.7%
(FPCore (x y z) :precision binary64 (if (<= y 6.8e-121) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 6.8e-121) {
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 <= 6.8d-121) 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 <= 6.8e-121) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 6.8e-121: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 6.8e-121) 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 <= 6.8e-121) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 6.8e-121], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.8 \cdot 10^{-121}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < 6.80000000000000003e-121Initial program 100.0%
Taylor expanded in z around inf 53.1%
+-commutative53.1%
Simplified53.1%
Taylor expanded in y around 0 36.2%
if 6.80000000000000003e-121 < y Initial program 100.0%
Taylor expanded in z around inf 52.8%
+-commutative52.8%
Simplified52.8%
distribute-lft-in46.4%
flip-+13.9%
Applied egg-rr13.9%
difference-of-squares14.3%
+-commutative14.3%
distribute-lft-in14.3%
associate-/l*28.2%
*-inverses52.8%
*-commutative52.8%
associate-/l*52.7%
Simplified52.7%
Taylor expanded in x around 0 38.6%
Final simplification37.1%
(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 53.0%
+-commutative53.0%
Simplified53.0%
Taylor expanded in y around 0 29.2%
Final simplification29.2%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))