
(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 7 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 (- z))))
(if (<= z -21.0)
t_0
(if (<= z 1.0)
(+ x y)
(if (or (<= z 3.8e+189) (not (<= z 9.2e+252))) (* y (- z)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -21.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if ((z <= 3.8e+189) || !(z <= 9.2e+252)) {
tmp = y * -z;
} 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 = x * -z
if (z <= (-21.0d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = x + y
else if ((z <= 3.8d+189) .or. (.not. (z <= 9.2d+252))) then
tmp = y * -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -21.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if ((z <= 3.8e+189) || !(z <= 9.2e+252)) {
tmp = y * -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -21.0: tmp = t_0 elif z <= 1.0: tmp = x + y elif (z <= 3.8e+189) or not (z <= 9.2e+252): tmp = y * -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -21.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(x + y); elseif ((z <= 3.8e+189) || !(z <= 9.2e+252)) tmp = Float64(y * Float64(-z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -21.0) tmp = t_0; elseif (z <= 1.0) tmp = x + y; elseif ((z <= 3.8e+189) || ~((z <= 9.2e+252))) tmp = y * -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -21.0], t$95$0, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 3.8e+189], N[Not[LessEqual[z, 9.2e+252]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -21:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{+189} \lor \neg \left(z \leq 9.2 \cdot 10^{+252}\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -21 or 3.7999999999999998e189 < z < 9.1999999999999999e252Initial program 100.0%
Taylor expanded in z around inf 98.8%
mul-1-neg98.8%
distribute-lft-neg-out98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in y around 0 54.4%
associate-*r*54.4%
mul-1-neg54.4%
Simplified54.4%
if -21 < z < 1Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
if 1 < z < 3.7999999999999998e189 or 9.1999999999999999e252 < z Initial program 99.9%
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 x around inf 84.2%
*-commutative84.2%
fma-define84.2%
mul-1-neg84.2%
fma-neg84.2%
*-commutative84.2%
associate-/l*87.4%
distribute-lft-out--87.3%
Simplified87.3%
Taylor expanded in x around 0 57.6%
mul-1-neg57.6%
distribute-rgt-neg-out57.6%
Simplified57.6%
Final simplification74.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -18.5)
t_0
(if (<= z 0.14)
(+ x y)
(if (<= z 2.75e+193)
(* y (- 1.0 z))
(if (<= z 1.3e+253) t_0 (* y (- z))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -18.5) {
tmp = t_0;
} else if (z <= 0.14) {
tmp = x + y;
} else if (z <= 2.75e+193) {
tmp = y * (1.0 - z);
} else if (z <= 1.3e+253) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-18.5d0)) then
tmp = t_0
else if (z <= 0.14d0) then
tmp = x + y
else if (z <= 2.75d+193) then
tmp = y * (1.0d0 - z)
else if (z <= 1.3d+253) then
tmp = t_0
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -18.5) {
tmp = t_0;
} else if (z <= 0.14) {
tmp = x + y;
} else if (z <= 2.75e+193) {
tmp = y * (1.0 - z);
} else if (z <= 1.3e+253) {
tmp = t_0;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -18.5: tmp = t_0 elif z <= 0.14: tmp = x + y elif z <= 2.75e+193: tmp = y * (1.0 - z) elif z <= 1.3e+253: tmp = t_0 else: tmp = y * -z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -18.5) tmp = t_0; elseif (z <= 0.14) tmp = Float64(x + y); elseif (z <= 2.75e+193) tmp = Float64(y * Float64(1.0 - z)); elseif (z <= 1.3e+253) tmp = t_0; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -18.5) tmp = t_0; elseif (z <= 0.14) tmp = x + y; elseif (z <= 2.75e+193) tmp = y * (1.0 - z); elseif (z <= 1.3e+253) tmp = t_0; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -18.5], t$95$0, If[LessEqual[z, 0.14], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.75e+193], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.3e+253], t$95$0, N[(y * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -18.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.14:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.75 \cdot 10^{+193}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+253}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -18.5 or 2.7500000000000001e193 < z < 1.3e253Initial program 100.0%
Taylor expanded in z around inf 98.8%
mul-1-neg98.8%
distribute-lft-neg-out98.8%
*-commutative98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in y around 0 54.4%
associate-*r*54.4%
mul-1-neg54.4%
Simplified54.4%
if -18.5 < z < 0.14000000000000001Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
if 0.14000000000000001 < z < 2.7500000000000001e193Initial program 99.9%
Taylor expanded in x around 0 58.3%
if 1.3e253 < z Initial 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 x around inf 77.8%
*-commutative77.8%
fma-define77.8%
mul-1-neg77.8%
fma-neg77.8%
*-commutative77.8%
associate-/l*85.5%
distribute-lft-out--85.5%
Simplified85.5%
Taylor expanded in x around 0 55.3%
mul-1-neg55.3%
distribute-rgt-neg-out55.3%
Simplified55.3%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (or (<= y 1.75e-68) (and (not (<= y 5.2e-13)) (<= y 5e+19))) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= 1.75e-68) || (!(y <= 5.2e-13) && (y <= 5e+19))) {
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 <= 1.75d-68) .or. (.not. (y <= 5.2d-13)) .and. (y <= 5d+19)) 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 <= 1.75e-68) || (!(y <= 5.2e-13) && (y <= 5e+19))) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 1.75e-68) or (not (y <= 5.2e-13) and (y <= 5e+19)): tmp = x * (1.0 - z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 1.75e-68) || (!(y <= 5.2e-13) && (y <= 5e+19))) 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 <= 1.75e-68) || (~((y <= 5.2e-13)) && (y <= 5e+19))) tmp = x * (1.0 - z); else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 1.75e-68], And[N[Not[LessEqual[y, 5.2e-13]], $MachinePrecision], LessEqual[y, 5e+19]]], 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 1.75 \cdot 10^{-68} \lor \neg \left(y \leq 5.2 \cdot 10^{-13}\right) \land y \leq 5 \cdot 10^{+19}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 1.75000000000000006e-68 or 5.2000000000000001e-13 < y < 5e19Initial program 100.0%
Taylor expanded in x around inf 60.2%
*-commutative60.2%
Simplified60.2%
if 1.75000000000000006e-68 < y < 5.2000000000000001e-13 or 5e19 < y Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -4000000.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) <= -4000000.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) <= (-4000000.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) <= -4000000.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) <= -4000000.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) <= -4000000.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) <= -4000000.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], -4000000.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 -4000000 \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) < -4e6 or 2 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in z around inf 98.6%
mul-1-neg98.6%
distribute-lft-neg-out98.6%
*-commutative98.6%
+-commutative98.6%
Simplified98.6%
if -4e6 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -128000000000.0) (not (<= z 1.0))) (* y (- z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -128000000000.0) || !(z <= 1.0)) {
tmp = y * -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 <= (-128000000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = y * -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 <= -128000000000.0) || !(z <= 1.0)) {
tmp = y * -z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -128000000000.0) or not (z <= 1.0): tmp = y * -z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -128000000000.0) || !(z <= 1.0)) tmp = Float64(y * Float64(-z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -128000000000.0) || ~((z <= 1.0))) tmp = y * -z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -128000000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -128000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1.28e11 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 99.2%
mul-1-neg99.2%
distribute-lft-neg-out99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in x around inf 82.6%
*-commutative82.6%
fma-define82.6%
mul-1-neg82.6%
fma-neg82.6%
*-commutative82.6%
associate-/l*86.7%
distribute-lft-out--86.7%
Simplified86.7%
Taylor expanded in x around 0 52.1%
mul-1-neg52.1%
distribute-rgt-neg-out52.1%
Simplified52.1%
if -1.28e11 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.5%
+-commutative97.5%
Simplified97.5%
Final simplification72.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 44.9%
+-commutative44.9%
Simplified44.9%
Final simplification44.9%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))