
(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 -8e+184)
t_0
(if (<= z -4.6e+58)
(* y z)
(if (<= z -1.5e-8)
t_0
(if (<= z 32000.0) (+ x y) (if (<= z 8.5e+91) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -8e+184) {
tmp = t_0;
} else if (z <= -4.6e+58) {
tmp = y * z;
} else if (z <= -1.5e-8) {
tmp = t_0;
} else if (z <= 32000.0) {
tmp = x + y;
} else if (z <= 8.5e+91) {
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 <= (-8d+184)) then
tmp = t_0
else if (z <= (-4.6d+58)) then
tmp = y * z
else if (z <= (-1.5d-8)) then
tmp = t_0
else if (z <= 32000.0d0) then
tmp = x + y
else if (z <= 8.5d+91) 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 <= -8e+184) {
tmp = t_0;
} else if (z <= -4.6e+58) {
tmp = y * z;
} else if (z <= -1.5e-8) {
tmp = t_0;
} else if (z <= 32000.0) {
tmp = x + y;
} else if (z <= 8.5e+91) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -8e+184: tmp = t_0 elif z <= -4.6e+58: tmp = y * z elif z <= -1.5e-8: tmp = t_0 elif z <= 32000.0: tmp = x + y elif z <= 8.5e+91: 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 <= -8e+184) tmp = t_0; elseif (z <= -4.6e+58) tmp = Float64(y * z); elseif (z <= -1.5e-8) tmp = t_0; elseif (z <= 32000.0) tmp = Float64(x + y); elseif (z <= 8.5e+91) 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 <= -8e+184) tmp = t_0; elseif (z <= -4.6e+58) tmp = y * z; elseif (z <= -1.5e-8) tmp = t_0; elseif (z <= 32000.0) tmp = x + y; elseif (z <= 8.5e+91) 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, -8e+184], t$95$0, If[LessEqual[z, -4.6e+58], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.5e-8], t$95$0, If[LessEqual[z, 32000.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 8.5e+91], 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 -8 \cdot 10^{+184}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{+58}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.5 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 32000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -8.00000000000000014e184 or -4.60000000000000005e58 < z < -1.49999999999999987e-8 or 32000 < z < 8.4999999999999995e91Initial program 100.0%
Taylor expanded in x around inf 50.7%
if -8.00000000000000014e184 < z < -4.60000000000000005e58 or 8.4999999999999995e91 < z Initial program 100.0%
Taylor expanded in x around 0 57.7%
+-commutative57.7%
distribute-lft-in57.7%
*-rgt-identity57.7%
Applied egg-rr57.7%
Taylor expanded in z around inf 57.7%
if -1.49999999999999987e-8 < z < 32000Initial program 100.0%
Taylor expanded in z around 0 98.2%
+-commutative98.2%
Simplified98.2%
Final simplification75.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 98.5%
+-commutative98.5%
Simplified98.5%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.8%
+-commutative98.8%
Simplified98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2600000000.0) (not (<= z 1.0))) (* y z) y))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2600000000.0) || !(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 <= (-2600000000.0d0)) .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 <= -2600000000.0) || !(z <= 1.0)) {
tmp = y * z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2600000000.0) or not (z <= 1.0): tmp = y * z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2600000000.0) || !(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 <= -2600000000.0) || ~((z <= 1.0))) tmp = y * z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2600000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2600000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -2.6e9 or 1 < z Initial program 100.0%
Taylor expanded in x around 0 55.0%
+-commutative55.0%
distribute-lft-in55.0%
*-rgt-identity55.0%
Applied egg-rr55.0%
Taylor expanded in z around inf 54.6%
if -2.6e9 < z < 1Initial program 100.0%
Taylor expanded in x around 0 51.9%
Taylor expanded in z around 0 50.8%
Final simplification52.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 13.5))) (* y z) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 13.5)) {
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)) .or. (.not. (z <= 13.5d0))) 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) || !(z <= 13.5)) {
tmp = y * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 13.5): tmp = y * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 13.5)) 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) || ~((z <= 13.5))) tmp = y * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 13.5]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 13.5\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 13.5 < z Initial program 100.0%
Taylor expanded in x around 0 55.3%
+-commutative55.3%
distribute-lft-in55.3%
*-rgt-identity55.3%
Applied egg-rr55.3%
Taylor expanded in z around inf 54.7%
if -1 < z < 13.5Initial program 100.0%
Taylor expanded in z around 0 98.8%
+-commutative98.8%
Simplified98.8%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (<= x -3.6e-112) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e-112) {
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 <= (-3.6d-112)) 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 <= -3.6e-112) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.6e-112: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.6e-112) 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 <= -3.6e-112) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.6e-112], 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 -3.6 \cdot 10^{-112}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -3.6000000000000001e-112Initial program 100.0%
Taylor expanded in x around inf 72.6%
if -3.6000000000000001e-112 < x Initial program 100.0%
Taylor expanded in x around 0 65.2%
Final simplification67.8%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 53.5%
Taylor expanded in z around 0 26.2%
Final simplification26.2%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))