
(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
(let* ((t_0 (- x (* x z))))
(if (<= z -4.8e-6)
t_0
(if (<= z 0.02)
(+ x y)
(if (or (<= z 2.3e+193) (not (<= z 4e+218))) t_0 (* z (- y)))))))
double code(double x, double y, double z) {
double t_0 = x - (x * z);
double tmp;
if (z <= -4.8e-6) {
tmp = t_0;
} else if (z <= 0.02) {
tmp = x + y;
} else if ((z <= 2.3e+193) || !(z <= 4e+218)) {
tmp = t_0;
} else {
tmp = z * -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) :: t_0
real(8) :: tmp
t_0 = x - (x * z)
if (z <= (-4.8d-6)) then
tmp = t_0
else if (z <= 0.02d0) then
tmp = x + y
else if ((z <= 2.3d+193) .or. (.not. (z <= 4d+218))) then
tmp = t_0
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (x * z);
double tmp;
if (z <= -4.8e-6) {
tmp = t_0;
} else if (z <= 0.02) {
tmp = x + y;
} else if ((z <= 2.3e+193) || !(z <= 4e+218)) {
tmp = t_0;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x * z) tmp = 0 if z <= -4.8e-6: tmp = t_0 elif z <= 0.02: tmp = x + y elif (z <= 2.3e+193) or not (z <= 4e+218): tmp = t_0 else: tmp = z * -y return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x * z)) tmp = 0.0 if (z <= -4.8e-6) tmp = t_0; elseif (z <= 0.02) tmp = Float64(x + y); elseif ((z <= 2.3e+193) || !(z <= 4e+218)) tmp = t_0; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x * z); tmp = 0.0; if (z <= -4.8e-6) tmp = t_0; elseif (z <= 0.02) tmp = x + y; elseif ((z <= 2.3e+193) || ~((z <= 4e+218))) tmp = t_0; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.8e-6], t$95$0, If[LessEqual[z, 0.02], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 2.3e+193], N[Not[LessEqual[z, 4e+218]], $MachinePrecision]], t$95$0, N[(z * (-y)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - x \cdot z\\
\mathbf{if}\;z \leq -4.8 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 0.02:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+193} \lor \neg \left(z \leq 4 \cdot 10^{+218}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < -4.7999999999999998e-6 or 0.0200000000000000004 < z < 2.30000000000000013e193 or 4.00000000000000033e218 < z Initial program 100.0%
Taylor expanded in x around inf 50.8%
sub-neg50.8%
+-commutative50.8%
distribute-rgt1-in50.8%
distribute-lft-neg-out50.8%
unsub-neg50.8%
Simplified50.8%
if -4.7999999999999998e-6 < z < 0.0200000000000000004Initial program 100.0%
Taylor expanded in z around 0 99.4%
if 2.30000000000000013e193 < z < 4.00000000000000033e218Initial program 100.0%
*-commutative100.0%
distribute-lft-in83.3%
fma-def83.3%
Applied egg-rr83.3%
Taylor expanded in z around inf 83.3%
mul-1-neg83.3%
distribute-rgt-neg-in83.3%
Simplified83.3%
Taylor expanded in x around 0 50.2%
associate-*r*50.2%
neg-mul-150.2%
*-commutative50.2%
Simplified50.2%
Final simplification74.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -20.5)
t_0
(if (<= z 1.0)
(+ x y)
(if (or (<= z 5.8e+192) (not (<= z 3.8e+216))) t_0 (* z (- y)))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -20.5) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if ((z <= 5.8e+192) || !(z <= 3.8e+216)) {
tmp = t_0;
} else {
tmp = z * -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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (z <= (-20.5d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = x + y
else if ((z <= 5.8d+192) .or. (.not. (z <= 3.8d+216))) then
tmp = t_0
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -20.5) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if ((z <= 5.8e+192) || !(z <= 3.8e+216)) {
tmp = t_0;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -20.5: tmp = t_0 elif z <= 1.0: tmp = x + y elif (z <= 5.8e+192) or not (z <= 3.8e+216): tmp = t_0 else: tmp = z * -y return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -20.5) tmp = t_0; elseif (z <= 1.0) tmp = Float64(x + y); elseif ((z <= 5.8e+192) || !(z <= 3.8e+216)) tmp = t_0; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -20.5) tmp = t_0; elseif (z <= 1.0) tmp = x + y; elseif ((z <= 5.8e+192) || ~((z <= 3.8e+216))) tmp = t_0; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -20.5], t$95$0, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 5.8e+192], N[Not[LessEqual[z, 3.8e+216]], $MachinePrecision]], t$95$0, N[(z * (-y)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -20.5:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+192} \lor \neg \left(z \leq 3.8 \cdot 10^{+216}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < -20.5 or 1 < z < 5.8000000000000003e192 or 3.80000000000000014e216 < z Initial program 100.0%
Taylor expanded in x around inf 52.0%
sub-neg52.0%
+-commutative52.0%
distribute-rgt1-in52.0%
distribute-lft-neg-out52.0%
unsub-neg52.0%
Simplified52.0%
Taylor expanded in z around inf 50.7%
associate-*r*50.7%
mul-1-neg50.7%
Simplified50.7%
if -20.5 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.9%
if 5.8000000000000003e192 < z < 3.80000000000000014e216Initial program 100.0%
*-commutative100.0%
distribute-lft-in83.3%
fma-def83.3%
Applied egg-rr83.3%
Taylor expanded in z around inf 83.3%
mul-1-neg83.3%
distribute-rgt-neg-in83.3%
Simplified83.3%
Taylor expanded in x around 0 50.2%
associate-*r*50.2%
neg-mul-150.2%
*-commutative50.2%
Simplified50.2%
Final simplification74.7%
(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(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(\left(-x\right) - 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%
mul-1-neg97.4%
+-commutative97.4%
distribute-rgt-neg-out97.4%
+-commutative97.4%
Simplified97.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.9%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -240.0) (not (<= z 1.0))) (* z (- y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -240.0) || !(z <= 1.0)) {
tmp = z * -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 <= (-240.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * -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 <= -240.0) || !(z <= 1.0)) {
tmp = z * -y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -240.0) or not (z <= 1.0): tmp = z * -y else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -240.0) || !(z <= 1.0)) tmp = Float64(z * Float64(-y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -240.0) || ~((z <= 1.0))) tmp = z * -y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -240.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -240 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -240 or 1 < z Initial program 100.0%
*-commutative100.0%
distribute-lft-in97.6%
fma-def98.4%
Applied egg-rr98.4%
Taylor expanded in z around inf 97.5%
mul-1-neg97.5%
distribute-rgt-neg-in97.5%
Simplified97.5%
Taylor expanded in x around 0 52.0%
associate-*r*52.0%
neg-mul-152.0%
*-commutative52.0%
Simplified52.0%
if -240 < z < 1Initial program 100.0%
Taylor expanded in z around 0 96.6%
Final simplification75.0%
(FPCore (x y z) :precision binary64 (if (<= y 1.6e-94) (- x (* x z)) (- y (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.6e-94) {
tmp = x - (x * z);
} else {
tmp = y - (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 <= 1.6d-94) then
tmp = x - (x * z)
else
tmp = y - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.6e-94) {
tmp = x - (x * z);
} else {
tmp = y - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.6e-94: tmp = x - (x * z) else: tmp = y - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.6e-94) tmp = Float64(x - Float64(x * z)); else tmp = Float64(y - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.6e-94) tmp = x - (x * z); else tmp = y - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.6e-94], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-94}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot z\\
\end{array}
\end{array}
if y < 1.59999999999999998e-94Initial program 100.0%
Taylor expanded in x around inf 56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt1-in56.7%
distribute-lft-neg-out56.7%
unsub-neg56.7%
Simplified56.7%
if 1.59999999999999998e-94 < y Initial program 100.0%
Taylor expanded in x around 0 76.5%
sub-neg76.5%
distribute-lft-in76.5%
distribute-rgt-neg-out76.5%
unsub-neg76.5%
*-rgt-identity76.5%
Simplified76.5%
Final simplification62.9%
(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 51.4%
Final simplification51.4%
(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 48.0%
sub-neg48.0%
+-commutative48.0%
distribute-rgt1-in48.0%
distribute-lft-neg-out48.0%
unsub-neg48.0%
Simplified48.0%
Taylor expanded in z around 0 23.8%
Final simplification23.8%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))