
(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 (* (+ 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}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ x y) (- 1.0 z))))
(if (<= t_0 (- INFINITY))
(* (- z) x)
(if (<= t_0 -1e-213)
(* 1.0 x)
(if (<= t_0 INFINITY) (* 1.0 y) (* (- z) y))))))
double code(double x, double y, double z) {
double t_0 = (x + y) * (1.0 - z);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = -z * x;
} else if (t_0 <= -1e-213) {
tmp = 1.0 * x;
} else if (t_0 <= ((double) INFINITY)) {
tmp = 1.0 * y;
} else {
tmp = -z * y;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x + y) * (1.0 - z);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = -z * x;
} else if (t_0 <= -1e-213) {
tmp = 1.0 * x;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = 1.0 * y;
} else {
tmp = -z * y;
}
return tmp;
}
def code(x, y, z): t_0 = (x + y) * (1.0 - z) tmp = 0 if t_0 <= -math.inf: tmp = -z * x elif t_0 <= -1e-213: tmp = 1.0 * x elif t_0 <= math.inf: tmp = 1.0 * y else: tmp = -z * y return tmp
function code(x, y, z) t_0 = Float64(Float64(x + y) * Float64(1.0 - z)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(-z) * x); elseif (t_0 <= -1e-213) tmp = Float64(1.0 * x); elseif (t_0 <= Inf) tmp = Float64(1.0 * y); else tmp = Float64(Float64(-z) * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x + y) * (1.0 - z); tmp = 0.0; if (t_0 <= -Inf) tmp = -z * x; elseif (t_0 <= -1e-213) tmp = 1.0 * x; elseif (t_0 <= Inf) tmp = 1.0 * y; else tmp = -z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[((-z) * x), $MachinePrecision], If[LessEqual[t$95$0, -1e-213], N[(1.0 * x), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(1.0 * y), $MachinePrecision], N[((-z) * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) \cdot \left(1 - z\right)\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-213}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -inf.0Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6444.0
Applied rewrites44.0%
Taylor expanded in z around inf
Applied rewrites44.0%
if -inf.0 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -9.9999999999999995e-214Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
Taylor expanded in z around 0
Applied rewrites35.4%
if -9.9999999999999995e-214 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < +inf.0Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.8
Applied rewrites49.8%
Taylor expanded in z around 0
Applied rewrites29.4%
if +inf.0 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.9
Applied rewrites49.9%
Taylor expanded in z around inf
Applied rewrites25.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ x y) (- 1.0 z))) (t_1 (* (- z) x)))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -1e-213) (* 1.0 x) (if (<= t_0 INFINITY) (* 1.0 y) t_1)))))
double code(double x, double y, double z) {
double t_0 = (x + y) * (1.0 - z);
double t_1 = -z * x;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -1e-213) {
tmp = 1.0 * x;
} else if (t_0 <= ((double) INFINITY)) {
tmp = 1.0 * y;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x + y) * (1.0 - z);
double t_1 = -z * x;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -1e-213) {
tmp = 1.0 * x;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = 1.0 * y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (x + y) * (1.0 - z) t_1 = -z * x tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= -1e-213: tmp = 1.0 * x elif t_0 <= math.inf: tmp = 1.0 * y else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(x + y) * Float64(1.0 - z)) t_1 = Float64(Float64(-z) * x) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -1e-213) tmp = Float64(1.0 * x); elseif (t_0 <= Inf) tmp = Float64(1.0 * y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x + y) * (1.0 - z); t_1 = -z * x; tmp = 0.0; if (t_0 <= -Inf) tmp = t_1; elseif (t_0 <= -1e-213) tmp = 1.0 * x; elseif (t_0 <= Inf) tmp = 1.0 * y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -1e-213], N[(1.0 * x), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(1.0 * y), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) \cdot \left(1 - z\right)\\
t_1 := \left(-z\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-213}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -inf.0 or +inf.0 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6444.0
Applied rewrites44.0%
Taylor expanded in z around inf
Applied rewrites44.0%
if -inf.0 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -9.9999999999999995e-214Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
Taylor expanded in z around 0
Applied rewrites35.4%
if -9.9999999999999995e-214 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < +inf.0Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.8
Applied rewrites49.8%
Taylor expanded in z around 0
Applied rewrites29.4%
(FPCore (x y z)
:precision binary64
(if (<= (+ x y) 5e-296)
(* (- 1.0 z) x)
(if (or (<= (+ x y) 5e-32) (not (<= (+ x y) 5e+67)))
(* (- z) y)
(* 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= 5e-296) {
tmp = (1.0 - z) * x;
} else if (((x + y) <= 5e-32) || !((x + y) <= 5e+67)) {
tmp = -z * y;
} else {
tmp = 1.0 * 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 ((x + y) <= 5d-296) then
tmp = (1.0d0 - z) * x
else if (((x + y) <= 5d-32) .or. (.not. ((x + y) <= 5d+67))) then
tmp = -z * y
else
tmp = 1.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= 5e-296) {
tmp = (1.0 - z) * x;
} else if (((x + y) <= 5e-32) || !((x + y) <= 5e+67)) {
tmp = -z * y;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= 5e-296: tmp = (1.0 - z) * x elif ((x + y) <= 5e-32) or not ((x + y) <= 5e+67): tmp = -z * y else: tmp = 1.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= 5e-296) tmp = Float64(Float64(1.0 - z) * x); elseif ((Float64(x + y) <= 5e-32) || !(Float64(x + y) <= 5e+67)) tmp = Float64(Float64(-z) * y); else tmp = Float64(1.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= 5e-296) tmp = (1.0 - z) * x; elseif (((x + y) <= 5e-32) || ~(((x + y) <= 5e+67))) tmp = -z * y; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], 5e-296], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], If[Or[LessEqual[N[(x + y), $MachinePrecision], 5e-32], N[Not[LessEqual[N[(x + y), $MachinePrecision], 5e+67]], $MachinePrecision]], N[((-z) * y), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq 5 \cdot 10^{-296}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{elif}\;x + y \leq 5 \cdot 10^{-32} \lor \neg \left(x + y \leq 5 \cdot 10^{+67}\right):\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < 5.0000000000000003e-296Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6454.7
Applied rewrites54.7%
if 5.0000000000000003e-296 < (+.f64 x y) < 5e-32 or 4.99999999999999976e67 < (+.f64 x y) Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6455.7
Applied rewrites55.7%
Taylor expanded in z around inf
Applied rewrites30.8%
if 5e-32 < (+.f64 x y) < 4.99999999999999976e67Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6439.1
Applied rewrites39.1%
Taylor expanded in z around 0
Applied rewrites32.0%
Final simplification42.6%
(FPCore (x y z) :precision binary64 (if (<= (* (+ x y) (- 1.0 z)) -1e-213) (* 1.0 x) (* 1.0 y)))
double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -1e-213) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * 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 (((x + y) * (1.0d0 - z)) <= (-1d-213)) then
tmp = 1.0d0 * x
else
tmp = 1.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -1e-213) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x + y) * (1.0 - z)) <= -1e-213: tmp = 1.0 * x else: tmp = 1.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x + y) * Float64(1.0 - z)) <= -1e-213) tmp = Float64(1.0 * x); else tmp = Float64(1.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x + y) * (1.0 - z)) <= -1e-213) tmp = 1.0 * x; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], -1e-213], N[(1.0 * x), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) \cdot \left(1 - z\right) \leq -1 \cdot 10^{-213}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -9.9999999999999995e-214Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6451.5
Applied rewrites51.5%
Taylor expanded in z around 0
Applied rewrites28.4%
if -9.9999999999999995e-214 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.8
Applied rewrites49.8%
Taylor expanded in z around 0
Applied rewrites29.4%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-220) (* (- 1.0 z) x) (* (- 1.0 z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-220) {
tmp = (1.0 - z) * x;
} else {
tmp = (1.0 - 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) :: tmp
if ((x + y) <= (-2d-220)) then
tmp = (1.0d0 - z) * x
else
tmp = (1.0d0 - z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-220) {
tmp = (1.0 - z) * x;
} else {
tmp = (1.0 - z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-220: tmp = (1.0 - z) * x else: tmp = (1.0 - z) * y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-220) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(Float64(1.0 - z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-220) tmp = (1.0 - z) * x; else tmp = (1.0 - z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-220], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999998e-220Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6454.9
Applied rewrites54.9%
if -1.99999999999999998e-220 < (+.f64 x y) Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6451.7
Applied rewrites51.7%
(FPCore (x y z) :precision binary64 (if (<= y 5.2e+40) (* 1.0 x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 5.2e+40) {
tmp = 1.0 * x;
} 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) :: tmp
if (y <= 5.2d+40) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 5.2e+40) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 5.2e+40: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 5.2e+40) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 5.2e+40) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 5.2e+40], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.2 \cdot 10^{+40}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < 5.2000000000000001e40Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6459.9
Applied rewrites59.9%
Taylor expanded in z around 0
Applied rewrites31.2%
if 5.2000000000000001e40 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6474.5
Applied rewrites74.5%
Taylor expanded in z around inf
Applied rewrites37.7%
Applied rewrites9.9%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.9
Applied rewrites49.9%
Taylor expanded in z around inf
Applied rewrites25.6%
Applied rewrites4.3%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))