
(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.75e+186)
(* y z)
(if (<= z -1.0)
(* x z)
(if (<= z 490000.0)
(+ x y)
(if (or (<= z 1.2e+71) (not (<= z 3.9e+223))) (* x z) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e+186) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 490000.0) {
tmp = x + y;
} else if ((z <= 1.2e+71) || !(z <= 3.9e+223)) {
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.75d+186)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= 490000.0d0) then
tmp = x + y
else if ((z <= 1.2d+71) .or. (.not. (z <= 3.9d+223))) 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.75e+186) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 490000.0) {
tmp = x + y;
} else if ((z <= 1.2e+71) || !(z <= 3.9e+223)) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.75e+186: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= 490000.0: tmp = x + y elif (z <= 1.2e+71) or not (z <= 3.9e+223): tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.75e+186) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= 490000.0) tmp = Float64(x + y); elseif ((z <= 1.2e+71) || !(z <= 3.9e+223)) 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.75e+186) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= 490000.0) tmp = x + y; elseif ((z <= 1.2e+71) || ~((z <= 3.9e+223))) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.75e+186], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 490000.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.2e+71], N[Not[LessEqual[z, 3.9e+223]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+186}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 490000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+71} \lor \neg \left(z \leq 3.9 \cdot 10^{+223}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.74999999999999993e186 or 1.1999999999999999e71 < z < 3.8999999999999999e223Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 83.6%
Taylor expanded in y around inf 57.1%
*-commutative57.1%
Simplified57.1%
if -1.74999999999999993e186 < z < -1 or 4.9e5 < z < 1.1999999999999999e71 or 3.8999999999999999e223 < z Initial program 100.0%
Taylor expanded in z around inf 97.9%
+-commutative97.9%
Simplified97.9%
Taylor expanded in y around 0 42.0%
if -1 < z < 4.9e5Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification72.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z 1.0))))
(if (<= z -3.6e+186)
(* y z)
(if (<= z -1.15e-6)
t_0
(if (<= z 490000.0)
(+ x y)
(if (<= z 2.45e+73) t_0 (if (<= z 2.5e+225) (* y z) (* x z))))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -3.6e+186) {
tmp = y * z;
} else if (z <= -1.15e-6) {
tmp = t_0;
} else if (z <= 490000.0) {
tmp = x + y;
} else if (z <= 2.45e+73) {
tmp = t_0;
} else if (z <= 2.5e+225) {
tmp = y * z;
} else {
tmp = x * 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 <= (-3.6d+186)) then
tmp = y * z
else if (z <= (-1.15d-6)) then
tmp = t_0
else if (z <= 490000.0d0) then
tmp = x + y
else if (z <= 2.45d+73) then
tmp = t_0
else if (z <= 2.5d+225) then
tmp = y * z
else
tmp = x * 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 <= -3.6e+186) {
tmp = y * z;
} else if (z <= -1.15e-6) {
tmp = t_0;
} else if (z <= 490000.0) {
tmp = x + y;
} else if (z <= 2.45e+73) {
tmp = t_0;
} else if (z <= 2.5e+225) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -3.6e+186: tmp = y * z elif z <= -1.15e-6: tmp = t_0 elif z <= 490000.0: tmp = x + y elif z <= 2.45e+73: tmp = t_0 elif z <= 2.5e+225: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (z <= -3.6e+186) tmp = Float64(y * z); elseif (z <= -1.15e-6) tmp = t_0; elseif (z <= 490000.0) tmp = Float64(x + y); elseif (z <= 2.45e+73) tmp = t_0; elseif (z <= 2.5e+225) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if (z <= -3.6e+186) tmp = y * z; elseif (z <= -1.15e-6) tmp = t_0; elseif (z <= 490000.0) tmp = x + y; elseif (z <= 2.45e+73) tmp = t_0; elseif (z <= 2.5e+225) tmp = y * z; else tmp = x * 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, -3.6e+186], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.15e-6], t$95$0, If[LessEqual[z, 490000.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.45e+73], t$95$0, If[LessEqual[z, 2.5e+225], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -3.6 \cdot 10^{+186}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 490000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+225}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -3.6000000000000002e186 or 2.45e73 < z < 2.4999999999999999e225Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 83.6%
Taylor expanded in y around inf 57.1%
*-commutative57.1%
Simplified57.1%
if -3.6000000000000002e186 < z < -1.15e-6 or 4.9e5 < z < 2.45e73Initial program 99.9%
Taylor expanded in x around inf 45.5%
if -1.15e-6 < z < 4.9e5Initial program 100.0%
Taylor expanded in z around 0 99.3%
+-commutative99.3%
Simplified99.3%
if 2.4999999999999999e225 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 35.6%
Final simplification72.3%
(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.4%
+-commutative98.4%
Simplified98.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 99.5%
+-commutative99.5%
Simplified99.5%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= y 2.4e+31) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.4e+31) {
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 (y <= 2.4d+31) 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 (y <= 2.4e+31) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.4e+31: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.4e+31) 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 (y <= 2.4e+31) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.4e+31], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.4 \cdot 10^{+31}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 2.39999999999999982e31Initial program 100.0%
Taylor expanded in x around inf 55.4%
if 2.39999999999999982e31 < y Initial program 100.0%
Taylor expanded in x around 0 81.2%
Final simplification61.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.9e-102) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.9e-102) {
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 <= (-2.9d-102)) 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 <= -2.9e-102) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.9e-102: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.9e-102) 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 <= -2.9e-102) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.9e-102], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{-102}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.89999999999999986e-102Initial program 100.0%
Taylor expanded in z around inf 50.3%
+-commutative50.3%
Simplified50.3%
Taylor expanded in y around 0 37.4%
if -2.89999999999999986e-102 < x Initial program 100.0%
Taylor expanded in z around inf 55.4%
+-commutative55.4%
Simplified55.4%
Taylor expanded in y around inf 51.3%
Taylor expanded in y around inf 38.2%
*-commutative38.2%
Simplified38.2%
Final simplification38.0%
(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.9%
+-commutative53.9%
Simplified53.9%
Taylor expanded in y around 0 26.2%
Final simplification26.2%
herbie shell --seed 2024077
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))