
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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 + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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 + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (- 1.0 z) (+ x y)))
double code(double x, double y, double z) {
return (1.0 - z) * (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 = (1.0d0 - z) * (x + y)
end function
public static double code(double x, double y, double z) {
return (1.0 - z) * (x + y);
}
def code(x, y, z): return (1.0 - z) * (x + y)
function code(x, y, z) return Float64(Float64(1.0 - z) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (1.0 - z) * (x + y); end
code[x_, y_, z_] := N[(N[(1.0 - z), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - z\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y 3.4e-146) (and (not (<= y 8.5e+116)) (<= y 2.7e+126))) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= 3.4e-146) || (!(y <= 8.5e+116) && (y <= 2.7e+126))) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - 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 <= 3.4d-146) .or. (.not. (y <= 8.5d+116)) .and. (y <= 2.7d+126)) then
tmp = x * (1.0d0 - z)
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= 3.4e-146) || (!(y <= 8.5e+116) && (y <= 2.7e+126))) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 3.4e-146) or (not (y <= 8.5e+116) and (y <= 2.7e+126)): tmp = x * (1.0 - z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 3.4e-146) || (!(y <= 8.5e+116) && (y <= 2.7e+126))) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= 3.4e-146) || (~((y <= 8.5e+116)) && (y <= 2.7e+126))) tmp = x * (1.0 - z); else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 3.4e-146], And[N[Not[LessEqual[y, 8.5e+116]], $MachinePrecision], LessEqual[y, 2.7e+126]]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.4 \cdot 10^{-146} \lor \neg \left(y \leq 8.5 \cdot 10^{+116}\right) \land y \leq 2.7 \cdot 10^{+126}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 3.4000000000000001e-146 or 8.5000000000000002e116 < y < 2.70000000000000002e126Initial program 100.0%
Taylor expanded in x around inf 63.5%
*-commutative63.5%
Simplified63.5%
if 3.4000000000000001e-146 < y < 8.5000000000000002e116 or 2.70000000000000002e126 < y Initial program 100.0%
Taylor expanded in x around 0 74.0%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -500.0) (not (<= (- 1.0 z) 2.0))) (* z (- (- y) x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -500.0) || !((1.0 - z) <= 2.0)) {
tmp = z * (-y - x);
} 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 (((1.0d0 - z) <= (-500.0d0)) .or. (.not. ((1.0d0 - z) <= 2.0d0))) then
tmp = z * (-y - x)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -500.0) || !((1.0 - z) <= 2.0)) {
tmp = z * (-y - x);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((1.0 - z) <= -500.0) or not ((1.0 - z) <= 2.0): tmp = z * (-y - x) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - z) <= -500.0) || !(Float64(1.0 - z) <= 2.0)) tmp = Float64(z * Float64(Float64(-y) - x)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((1.0 - z) <= -500.0) || ~(((1.0 - z) <= 2.0))) tmp = z * (-y - x); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -500.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0]], $MachinePrecision]], N[(z * N[((-y) - x), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -500 \lor \neg \left(1 - z \leq 2\right):\\
\;\;\;\;z \cdot \left(\left(-y\right) - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -500 or 2 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in z around inf 97.3%
mul-1-neg97.3%
distribute-lft-neg-out97.3%
*-commutative97.3%
+-commutative97.3%
Simplified97.3%
if -500 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 100.0%
Taylor expanded in z around 0 99.2%
+-commutative99.2%
Simplified99.2%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= z -9.6e+52) (* y (- z)) (if (or (<= z -2200.0) (not (<= z 1.0))) (* x (- z)) (+ x y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.6e+52) {
tmp = y * -z;
} else if ((z <= -2200.0) || !(z <= 1.0)) {
tmp = x * -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 <= (-9.6d+52)) then
tmp = y * -z
else if ((z <= (-2200.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = x * -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 <= -9.6e+52) {
tmp = y * -z;
} else if ((z <= -2200.0) || !(z <= 1.0)) {
tmp = x * -z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.6e+52: tmp = y * -z elif (z <= -2200.0) or not (z <= 1.0): tmp = x * -z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.6e+52) tmp = Float64(y * Float64(-z)); elseif ((z <= -2200.0) || !(z <= 1.0)) tmp = Float64(x * Float64(-z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.6e+52) tmp = y * -z; elseif ((z <= -2200.0) || ~((z <= 1.0))) tmp = x * -z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.6e+52], N[(y * (-z)), $MachinePrecision], If[Or[LessEqual[z, -2200.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{+52}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;z \leq -2200 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -9.5999999999999999e52Initial program 100.0%
Taylor expanded in x around 0 61.1%
Taylor expanded in z around inf 61.1%
neg-mul-161.1%
distribute-lft-neg-in61.1%
Simplified61.1%
if -9.5999999999999999e52 < z < -2200 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 97.2%
mul-1-neg97.2%
distribute-lft-neg-out97.2%
*-commutative97.2%
+-commutative97.2%
Simplified97.2%
Taylor expanded in y around inf 79.0%
mul-1-neg79.0%
unsub-neg79.0%
*-commutative79.0%
*-commutative79.0%
associate-/l*82.9%
distribute-lft-out--83.0%
Simplified83.0%
Taylor expanded in y around 0 52.2%
mul-1-neg52.2%
distribute-rgt-neg-in52.2%
Simplified52.2%
if -2200 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.8%
+-commutative97.8%
Simplified97.8%
Final simplification76.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2200.0) (not (<= z 1.0))) (* x (- z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2200.0) || !(z <= 1.0)) {
tmp = x * -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 <= (-2200.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = x * -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 <= -2200.0) || !(z <= 1.0)) {
tmp = x * -z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2200.0) or not (z <= 1.0): tmp = x * -z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2200.0) || !(z <= 1.0)) tmp = Float64(x * Float64(-z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2200.0) || ~((z <= 1.0))) tmp = x * -z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2200.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2200 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2200 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.4%
mul-1-neg98.4%
distribute-lft-neg-out98.4%
*-commutative98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in y around inf 82.5%
mul-1-neg82.5%
unsub-neg82.5%
*-commutative82.5%
*-commutative82.5%
associate-/l*86.3%
distribute-lft-out--86.3%
Simplified86.3%
Taylor expanded in y around 0 49.1%
mul-1-neg49.1%
distribute-rgt-neg-in49.1%
Simplified49.1%
if -2200 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.8%
+-commutative97.8%
Simplified97.8%
Final simplification73.5%
(FPCore (x y z) :precision binary64 (if (<= y 2.9e-148) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.9e-148) {
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 (y <= 2.9d-148) 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 (y <= 2.9e-148) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.9e-148: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.9e-148) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.9e-148) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.9e-148], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-148}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.8999999999999998e-148Initial program 100.0%
Taylor expanded in x around inf 63.1%
*-commutative63.1%
Simplified63.1%
Taylor expanded in z around 0 34.4%
if 2.8999999999999998e-148 < y Initial program 100.0%
Taylor expanded in z around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 63.9%
Taylor expanded in x around 0 35.1%
Final simplification34.6%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return 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 = x + y
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 50.8%
+-commutative50.8%
Simplified50.8%
Final simplification50.8%
(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 x around inf 52.6%
*-commutative52.6%
Simplified52.6%
Taylor expanded in z around 0 28.2%
Final simplification28.2%
herbie shell --seed 2024079
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))