
(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 (<= (- 1.0 z) -2e+107)
(* y (- z))
(if (<= (- 1.0 z) -2e+81)
(* z (- x))
(if (or (<= (- 1.0 z) -50000.0) (not (<= (- 1.0 z) 500000.0)))
(* y (- 1.0 z))
(+ x y)))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2e+107) {
tmp = y * -z;
} else if ((1.0 - z) <= -2e+81) {
tmp = z * -x;
} else if (((1.0 - z) <= -50000.0) || !((1.0 - z) <= 500000.0)) {
tmp = y * (1.0 - 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 ((1.0d0 - z) <= (-2d+107)) then
tmp = y * -z
else if ((1.0d0 - z) <= (-2d+81)) then
tmp = z * -x
else if (((1.0d0 - z) <= (-50000.0d0)) .or. (.not. ((1.0d0 - z) <= 500000.0d0))) then
tmp = y * (1.0d0 - z)
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) <= -2e+107) {
tmp = y * -z;
} else if ((1.0 - z) <= -2e+81) {
tmp = z * -x;
} else if (((1.0 - z) <= -50000.0) || !((1.0 - z) <= 500000.0)) {
tmp = y * (1.0 - z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (1.0 - z) <= -2e+107: tmp = y * -z elif (1.0 - z) <= -2e+81: tmp = z * -x elif ((1.0 - z) <= -50000.0) or not ((1.0 - z) <= 500000.0): tmp = y * (1.0 - z) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - z) <= -2e+107) tmp = Float64(y * Float64(-z)); elseif (Float64(1.0 - z) <= -2e+81) tmp = Float64(z * Float64(-x)); elseif ((Float64(1.0 - z) <= -50000.0) || !(Float64(1.0 - z) <= 500000.0)) tmp = Float64(y * Float64(1.0 - z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((1.0 - z) <= -2e+107) tmp = y * -z; elseif ((1.0 - z) <= -2e+81) tmp = z * -x; elseif (((1.0 - z) <= -50000.0) || ~(((1.0 - z) <= 500000.0))) tmp = y * (1.0 - z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - z), $MachinePrecision], -2e+107], N[(y * (-z)), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], -2e+81], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -50000.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 500000.0]], $MachinePrecision]], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -2 \cdot 10^{+107}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;1 - z \leq -2 \cdot 10^{+81}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;1 - z \leq -50000 \lor \neg \left(1 - z \leq 500000\right):\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -1.9999999999999999e107Initial program 100.0%
Taylor expanded in z around inf 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 78.6%
fma-define78.6%
mul-1-neg78.6%
fma-neg78.6%
*-commutative78.6%
*-commutative78.6%
associate-/l*88.3%
distribute-lft-out--88.3%
Simplified88.3%
Taylor expanded in y around inf 62.9%
associate-*r*62.9%
neg-mul-162.9%
Simplified62.9%
if -1.9999999999999999e107 < (-.f64 #s(literal 1 binary64) z) < -1.99999999999999984e81Initial program 100.0%
Taylor expanded in x around inf 58.4%
*-commutative58.4%
Simplified58.4%
Taylor expanded in z around inf 58.4%
associate-*r*58.4%
mul-1-neg58.4%
Simplified58.4%
if -1.99999999999999984e81 < (-.f64 #s(literal 1 binary64) z) < -5e4 or 5e5 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around 0 49.9%
if -5e4 < (-.f64 #s(literal 1 binary64) z) < 5e5Initial program 100.0%
Taylor expanded in z around 0 96.7%
+-commutative96.7%
Simplified96.7%
Final simplification76.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= z -1.06e+122)
t_0
(if (<= z -6.8e+21)
(* z (- x))
(if (or (<= z -420000.0) (not (<= z 1.0))) t_0 (+ x y))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -1.06e+122) {
tmp = t_0;
} else if (z <= -6.8e+21) {
tmp = z * -x;
} else if ((z <= -420000.0) || !(z <= 1.0)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * -z
if (z <= (-1.06d+122)) then
tmp = t_0
else if (z <= (-6.8d+21)) then
tmp = z * -x
else if ((z <= (-420000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = t_0
else
tmp = x + y
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 <= -1.06e+122) {
tmp = t_0;
} else if (z <= -6.8e+21) {
tmp = z * -x;
} else if ((z <= -420000.0) || !(z <= 1.0)) {
tmp = t_0;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if z <= -1.06e+122: tmp = t_0 elif z <= -6.8e+21: tmp = z * -x elif (z <= -420000.0) or not (z <= 1.0): tmp = t_0 else: tmp = x + y return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -1.06e+122) tmp = t_0; elseif (z <= -6.8e+21) tmp = Float64(z * Float64(-x)); elseif ((z <= -420000.0) || !(z <= 1.0)) tmp = t_0; else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (z <= -1.06e+122) tmp = t_0; elseif (z <= -6.8e+21) tmp = z * -x; elseif ((z <= -420000.0) || ~((z <= 1.0))) tmp = t_0; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.06e+122], t$95$0, If[LessEqual[z, -6.8e+21], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[z, -420000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], t$95$0, N[(x + y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.06 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -6.8 \cdot 10^{+21}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq -420000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1.06000000000000002e122 or -6.8e21 < z < -4.2e5 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 83.2%
fma-define83.2%
mul-1-neg83.2%
fma-neg83.2%
*-commutative83.2%
*-commutative83.2%
associate-/l*86.8%
distribute-lft-out--86.8%
Simplified86.8%
Taylor expanded in y around inf 53.3%
associate-*r*53.3%
neg-mul-153.3%
Simplified53.3%
if -1.06000000000000002e122 < z < -6.8e21Initial program 99.9%
Taylor expanded in x around inf 41.3%
*-commutative41.3%
Simplified41.3%
Taylor expanded in z around inf 41.3%
associate-*r*41.3%
mul-1-neg41.3%
Simplified41.3%
if -4.2e5 < z < 1Initial program 100.0%
Taylor expanded in z around 0 96.7%
+-commutative96.7%
Simplified96.7%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (<= x -7e-77) (* x (- 1.0 z)) (if (or (<= x -2.2e-137) (not (<= x -2.15e-162))) (* y (- 1.0 z)) (+ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e-77) {
tmp = x * (1.0 - z);
} else if ((x <= -2.2e-137) || !(x <= -2.15e-162)) {
tmp = y * (1.0 - 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 (x <= (-7d-77)) then
tmp = x * (1.0d0 - z)
else if ((x <= (-2.2d-137)) .or. (.not. (x <= (-2.15d-162)))) then
tmp = y * (1.0d0 - z)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7e-77) {
tmp = x * (1.0 - z);
} else if ((x <= -2.2e-137) || !(x <= -2.15e-162)) {
tmp = y * (1.0 - z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7e-77: tmp = x * (1.0 - z) elif (x <= -2.2e-137) or not (x <= -2.15e-162): tmp = y * (1.0 - z) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7e-77) tmp = Float64(x * Float64(1.0 - z)); elseif ((x <= -2.2e-137) || !(x <= -2.15e-162)) tmp = Float64(y * Float64(1.0 - z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7e-77) tmp = x * (1.0 - z); elseif ((x <= -2.2e-137) || ~((x <= -2.15e-162))) tmp = y * (1.0 - z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7e-77], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -2.2e-137], N[Not[LessEqual[x, -2.15e-162]], $MachinePrecision]], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-77}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{-137} \lor \neg \left(x \leq -2.15 \cdot 10^{-162}\right):\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if x < -7.00000000000000026e-77Initial program 100.0%
Taylor expanded in x around inf 69.3%
*-commutative69.3%
Simplified69.3%
if -7.00000000000000026e-77 < x < -2.2000000000000001e-137 or -2.14999999999999998e-162 < x Initial program 100.0%
Taylor expanded in x around 0 65.6%
if -2.2000000000000001e-137 < x < -2.14999999999999998e-162Initial program 100.0%
Taylor expanded in z around 0 75.9%
+-commutative75.9%
Simplified75.9%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -50000.0) (not (<= (- 1.0 z) 2.0))) (* z (- (- x) y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -50000.0) || !((1.0 - z) <= 2.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 (((1.0d0 - z) <= (-50000.0d0)) .or. (.not. ((1.0d0 - z) <= 2.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 (((1.0 - z) <= -50000.0) || !((1.0 - z) <= 2.0)) {
tmp = z * (-x - y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((1.0 - z) <= -50000.0) or not ((1.0 - z) <= 2.0): tmp = z * (-x - y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - z) <= -50000.0) || !(Float64(1.0 - z) <= 2.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 (((1.0 - z) <= -50000.0) || ~(((1.0 - z) <= 2.0))) tmp = z * (-x - y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -50000.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0]], $MachinePrecision]], N[(z * N[((-x) - y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -50000 \lor \neg \left(1 - z \leq 2\right):\\
\;\;\;\;z \cdot \left(\left(-x\right) - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -5e4 or 2 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in z around inf 97.1%
mul-1-neg97.1%
distribute-lft-neg-out97.1%
*-commutative97.1%
+-commutative97.1%
Simplified97.1%
if -5e4 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8) (not (<= z 1.0))) (* z (- x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8) || !(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 <= (-4.8d0)) .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 <= -4.8) || !(z <= 1.0)) {
tmp = z * -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8) or not (z <= 1.0): tmp = z * -x else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8) || !(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 <= -4.8) || ~((z <= 1.0))) tmp = z * -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8], 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 -4.8 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -4.79999999999999982 or 1 < z Initial program 100.0%
Taylor expanded in x around inf 49.5%
*-commutative49.5%
Simplified49.5%
Taylor expanded in z around inf 49.5%
associate-*r*49.5%
mul-1-neg49.5%
Simplified49.5%
if -4.79999999999999982 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification74.1%
(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.1%
+-commutative51.1%
Simplified51.1%
Final simplification51.1%
(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 47.6%
*-commutative47.6%
Simplified47.6%
Taylor expanded in z around 0 24.2%
herbie shell --seed 2024108
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))