
(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 9 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 (<= (- 1.0 z) -2e+114)
(* y (- z))
(if (<= (- 1.0 z) -1000000000000.0)
(* z (- x))
(if (<= (- 1.0 z) 1.01) (+ x y) (* y (- 1.0 z))))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2e+114) {
tmp = y * -z;
} else if ((1.0 - z) <= -1000000000000.0) {
tmp = z * -x;
} else if ((1.0 - z) <= 1.01) {
tmp = x + y;
} 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 ((1.0d0 - z) <= (-2d+114)) then
tmp = y * -z
else if ((1.0d0 - z) <= (-1000000000000.0d0)) then
tmp = z * -x
else if ((1.0d0 - z) <= 1.01d0) then
tmp = x + y
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 ((1.0 - z) <= -2e+114) {
tmp = y * -z;
} else if ((1.0 - z) <= -1000000000000.0) {
tmp = z * -x;
} else if ((1.0 - z) <= 1.01) {
tmp = x + y;
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (1.0 - z) <= -2e+114: tmp = y * -z elif (1.0 - z) <= -1000000000000.0: tmp = z * -x elif (1.0 - z) <= 1.01: tmp = x + y else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - z) <= -2e+114) tmp = Float64(y * Float64(-z)); elseif (Float64(1.0 - z) <= -1000000000000.0) tmp = Float64(z * Float64(-x)); elseif (Float64(1.0 - z) <= 1.01) tmp = Float64(x + y); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((1.0 - z) <= -2e+114) tmp = y * -z; elseif ((1.0 - z) <= -1000000000000.0) tmp = z * -x; elseif ((1.0 - z) <= 1.01) tmp = x + y; else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - z), $MachinePrecision], -2e+114], N[(y * (-z)), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], -1000000000000.0], N[(z * (-x)), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 1.01], N[(x + y), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -2 \cdot 10^{+114}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;1 - z \leq -1000000000000:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;1 - z \leq 1.01:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (-.f64 1 z) < -2e114Initial program 100.0%
Taylor expanded in z around inf 100.0%
mul-1-neg100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 41.6%
associate-*r*41.6%
mul-1-neg41.6%
Simplified41.6%
if -2e114 < (-.f64 1 z) < -1e12Initial program 99.9%
Taylor expanded in x around inf 49.3%
*-commutative49.3%
Simplified49.3%
Taylor expanded in z around inf 49.3%
associate-*r*100.0%
mul-1-neg100.0%
Simplified49.3%
if -1e12 < (-.f64 1 z) < 1.01000000000000001Initial program 100.0%
Taylor expanded in z around 0 98.5%
+-commutative98.5%
Simplified98.5%
if 1.01000000000000001 < (-.f64 1 z) Initial program 100.0%
Taylor expanded in x around 0 58.0%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -1000000000000.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) <= -1000000000000.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) <= (-1000000000000.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) <= -1000000000000.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) <= -1000000000000.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) <= -1000000000000.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) <= -1000000000000.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], -1000000000000.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 -1000000000000 \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 1 z) < -1e12 or 2 < (-.f64 1 z) Initial program 100.0%
Taylor expanded in z around inf 99.1%
mul-1-neg99.1%
*-commutative99.1%
distribute-rgt-neg-out99.1%
+-commutative99.1%
Simplified99.1%
if -1e12 < (-.f64 1 z) < 2Initial program 100.0%
Taylor expanded in z around 0 98.0%
+-commutative98.0%
Simplified98.0%
Final simplification98.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 z))))
(if (<= y 3.4e-77)
t_0
(if (<= y 6e+26) (+ x y) (if (<= y 3.2e+43) t_0 (* y (- 1.0 z)))))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - z);
double tmp;
if (y <= 3.4e-77) {
tmp = t_0;
} else if (y <= 6e+26) {
tmp = x + y;
} else if (y <= 3.2e+43) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - z)
if (y <= 3.4d-77) then
tmp = t_0
else if (y <= 6d+26) then
tmp = x + y
else if (y <= 3.2d+43) then
tmp = t_0
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - z);
double tmp;
if (y <= 3.4e-77) {
tmp = t_0;
} else if (y <= 6e+26) {
tmp = x + y;
} else if (y <= 3.2e+43) {
tmp = t_0;
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - z) tmp = 0 if y <= 3.4e-77: tmp = t_0 elif y <= 6e+26: tmp = x + y elif y <= 3.2e+43: tmp = t_0 else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - z)) tmp = 0.0 if (y <= 3.4e-77) tmp = t_0; elseif (y <= 6e+26) tmp = Float64(x + y); elseif (y <= 3.2e+43) tmp = t_0; else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - z); tmp = 0.0; if (y <= 3.4e-77) tmp = t_0; elseif (y <= 6e+26) tmp = x + y; elseif (y <= 3.2e+43) tmp = t_0; else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 3.4e-77], t$95$0, If[LessEqual[y, 6e+26], N[(x + y), $MachinePrecision], If[LessEqual[y, 3.2e+43], t$95$0, N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - z\right)\\
\mathbf{if}\;y \leq 3.4 \cdot 10^{-77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+26}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+43}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 3.39999999999999983e-77 or 5.99999999999999994e26 < y < 3.20000000000000014e43Initial program 100.0%
Taylor expanded in x around inf 59.8%
*-commutative59.8%
Simplified59.8%
if 3.39999999999999983e-77 < y < 5.99999999999999994e26Initial program 100.0%
Taylor expanded in z around 0 72.0%
+-commutative72.0%
Simplified72.0%
if 3.20000000000000014e43 < y Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification64.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= z -26.5)
t_0
(if (<= z 1.0) (+ x y) (if (<= z 1.65e+113) (* z (- x)) t_0)))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -26.5) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 1.65e+113) {
tmp = z * -x;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = y * -z
if (z <= (-26.5d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = x + y
else if (z <= 1.65d+113) then
tmp = z * -x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -26.5) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 1.65e+113) {
tmp = z * -x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if z <= -26.5: tmp = t_0 elif z <= 1.0: tmp = x + y elif z <= 1.65e+113: tmp = z * -x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -26.5) tmp = t_0; elseif (z <= 1.0) tmp = Float64(x + y); elseif (z <= 1.65e+113) tmp = Float64(z * Float64(-x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (z <= -26.5) tmp = t_0; elseif (z <= 1.0) tmp = x + y; elseif (z <= 1.65e+113) tmp = z * -x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -26.5], t$95$0, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.65e+113], N[(z * (-x)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -26.5:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+113}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -26.5 or 1.6500000000000002e113 < z Initial program 100.0%
Taylor expanded in z around inf 99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-rgt-neg-out99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in y around inf 50.8%
associate-*r*50.8%
mul-1-neg50.8%
Simplified50.8%
if -26.5 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.0%
+-commutative98.0%
Simplified98.0%
if 1 < z < 1.6500000000000002e113Initial program 99.9%
Taylor expanded in x around inf 49.3%
*-commutative49.3%
Simplified49.3%
Taylor expanded in z around inf 49.3%
associate-*r*100.0%
mul-1-neg100.0%
Simplified49.3%
Final simplification75.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -105.0) (not (<= z 1.0))) (* z (- x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -105.0) || !(z <= 1.0)) {
tmp = z * -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 ((z <= (-105.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * -x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -105.0) || !(z <= 1.0)) {
tmp = z * -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -105.0) or not (z <= 1.0): tmp = z * -x else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -105.0) || !(z <= 1.0)) tmp = Float64(z * Float64(-x)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -105.0) || ~((z <= 1.0))) tmp = z * -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -105.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -105 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -105 or 1 < z Initial program 100.0%
Taylor expanded in x around inf 54.9%
*-commutative54.9%
Simplified54.9%
Taylor expanded in z around inf 54.9%
associate-*r*99.2%
mul-1-neg99.2%
Simplified54.9%
if -105 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.4%
+-commutative97.4%
Simplified97.4%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= y 4.6e-53) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.6e-53) {
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 <= 4.6d-53) 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 <= 4.6e-53) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.6e-53: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.6e-53) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.6e-53) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.6e-53], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.6 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.6000000000000003e-53Initial program 100.0%
Taylor expanded in x around inf 59.2%
*-commutative59.2%
Simplified59.2%
Taylor expanded in z around 0 29.8%
if 4.6000000000000003e-53 < y Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in97.3%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 83.9%
associate-*r*83.9%
mul-1-neg83.9%
Simplified83.9%
Taylor expanded in z around 0 36.9%
Final simplification31.8%
(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 53.0%
+-commutative53.0%
Simplified53.0%
Final simplification53.0%
(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 51.7%
*-commutative51.7%
Simplified51.7%
Taylor expanded in z around 0 26.6%
Final simplification26.6%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))