
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma z (cos y) (+ x (sin y))))
double code(double x, double y, double z) {
return fma(z, cos(y), (x + sin(y)));
}
function code(x, y, z) return fma(z, cos(y), Float64(x + sin(y))) end
code[x_, y_, z_] := N[(z * N[Cos[y], $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \cos y, x + \sin y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -6e+51)
t_0
(if (<= z -3.2e-16)
(+ y (+ z x))
(if (<= z 1.02e+37) (+ x (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -6e+51) {
tmp = t_0;
} else if (z <= -3.2e-16) {
tmp = y + (z + x);
} else if (z <= 1.02e+37) {
tmp = x + sin(y);
} 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 = z * cos(y)
if (z <= (-6d+51)) then
tmp = t_0
else if (z <= (-3.2d-16)) then
tmp = y + (z + x)
else if (z <= 1.02d+37) then
tmp = x + sin(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -6e+51) {
tmp = t_0;
} else if (z <= -3.2e-16) {
tmp = y + (z + x);
} else if (z <= 1.02e+37) {
tmp = x + Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -6e+51: tmp = t_0 elif z <= -3.2e-16: tmp = y + (z + x) elif z <= 1.02e+37: tmp = x + math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -6e+51) tmp = t_0; elseif (z <= -3.2e-16) tmp = Float64(y + Float64(z + x)); elseif (z <= 1.02e+37) tmp = Float64(x + sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -6e+51) tmp = t_0; elseif (z <= -3.2e-16) tmp = y + (z + x); elseif (z <= 1.02e+37) tmp = x + sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6e+51], t$95$0, If[LessEqual[z, -3.2e-16], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.02e+37], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6 \cdot 10^{+51}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-16}:\\
\;\;\;\;y + \left(z + x\right)\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{+37}:\\
\;\;\;\;x + \sin y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6e51 or 1.01999999999999995e37 < z Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.1%
associate-*l*99.0%
fma-def99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in z around inf 85.3%
pow-base-185.3%
*-commutative85.3%
*-lft-identity85.3%
Simplified85.3%
if -6e51 < z < -3.20000000000000023e-16Initial program 100.0%
Taylor expanded in y around 0 86.8%
if -3.20000000000000023e-16 < z < 1.01999999999999995e37Initial program 100.0%
Taylor expanded in z around 0 87.7%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.8e+51) (not (<= z 1.55e+42))) (* z (cos y)) (+ z (+ x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.8e+51) || !(z <= 1.55e+42)) {
tmp = z * cos(y);
} else {
tmp = z + (x + sin(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 <= (-8.8d+51)) .or. (.not. (z <= 1.55d+42))) then
tmp = z * cos(y)
else
tmp = z + (x + sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.8e+51) || !(z <= 1.55e+42)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x + Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.8e+51) or not (z <= 1.55e+42): tmp = z * math.cos(y) else: tmp = z + (x + math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.8e+51) || !(z <= 1.55e+42)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x + sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.8e+51) || ~((z <= 1.55e+42))) tmp = z * cos(y); else tmp = z + (x + sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.8e+51], N[Not[LessEqual[z, 1.55e+42]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.8 \cdot 10^{+51} \lor \neg \left(z \leq 1.55 \cdot 10^{+42}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + \sin y\right)\\
\end{array}
\end{array}
if z < -8.79999999999999967e51 or 1.5500000000000001e42 < z Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.1%
associate-*l*99.0%
fma-def99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in z around inf 85.3%
pow-base-185.3%
*-commutative85.3%
*-lft-identity85.3%
Simplified85.3%
if -8.79999999999999967e51 < z < 1.5500000000000001e42Initial program 100.0%
Taylor expanded in y around 0 95.2%
Final simplification91.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -1e+57)
(+ (+ y x) t_0)
(if (<= z 4.5e+43) (+ z (+ x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1e+57) {
tmp = (y + x) + t_0;
} else if (z <= 4.5e+43) {
tmp = z + (x + sin(y));
} 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 = z * cos(y)
if (z <= (-1d+57)) then
tmp = (y + x) + t_0
else if (z <= 4.5d+43) then
tmp = z + (x + sin(y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -1e+57) {
tmp = (y + x) + t_0;
} else if (z <= 4.5e+43) {
tmp = z + (x + Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -1e+57: tmp = (y + x) + t_0 elif z <= 4.5e+43: tmp = z + (x + math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -1e+57) tmp = Float64(Float64(y + x) + t_0); elseif (z <= 4.5e+43) tmp = Float64(z + Float64(x + sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -1e+57) tmp = (y + x) + t_0; elseif (z <= 4.5e+43) tmp = z + (x + sin(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e+57], N[(N[(y + x), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[z, 4.5e+43], N[(z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -1 \cdot 10^{+57}:\\
\;\;\;\;\left(y + x\right) + t_0\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+43}:\\
\;\;\;\;z + \left(x + \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1.00000000000000005e57Initial program 99.9%
Taylor expanded in y around 0 88.2%
if -1.00000000000000005e57 < z < 4.5e43Initial program 100.0%
Taylor expanded in y around 0 94.8%
if 4.5e43 < z Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.1%
associate-*l*99.0%
fma-def99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in z around inf 85.8%
pow-base-185.8%
*-commutative85.8%
*-lft-identity85.8%
Simplified85.8%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+52) (not (<= z 4.5e+43))) (* z (cos y)) (+ z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+52) || !(z <= 4.5e+43)) {
tmp = z * cos(y);
} else {
tmp = z + x;
}
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 <= (-1d+52)) .or. (.not. (z <= 4.5d+43))) then
tmp = z * cos(y)
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+52) || !(z <= 4.5e+43)) {
tmp = z * Math.cos(y);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+52) or not (z <= 4.5e+43): tmp = z * math.cos(y) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+52) || !(z <= 4.5e+43)) tmp = Float64(z * cos(y)); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1e+52) || ~((z <= 4.5e+43))) tmp = z * cos(y); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+52], N[Not[LessEqual[z, 4.5e+43]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+52} \lor \neg \left(z \leq 4.5 \cdot 10^{+43}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if z < -9.9999999999999999e51 or 4.5e43 < z Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.1%
associate-*l*99.0%
fma-def99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in z around inf 85.3%
pow-base-185.3%
*-commutative85.3%
*-lft-identity85.3%
Simplified85.3%
if -9.9999999999999999e51 < z < 4.5e43Initial program 100.0%
Taylor expanded in y around 0 68.2%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= y -6.2e+48) (+ z x) (if (<= y 8.2e+17) (+ y (+ z x)) (+ z x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+48) {
tmp = z + x;
} else if (y <= 8.2e+17) {
tmp = y + (z + x);
} else {
tmp = z + x;
}
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 <= (-6.2d+48)) then
tmp = z + x
else if (y <= 8.2d+17) then
tmp = y + (z + x)
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+48) {
tmp = z + x;
} else if (y <= 8.2e+17) {
tmp = y + (z + x);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.2e+48: tmp = z + x elif y <= 8.2e+17: tmp = y + (z + x) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.2e+48) tmp = Float64(z + x); elseif (y <= 8.2e+17) tmp = Float64(y + Float64(z + x)); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.2e+48) tmp = z + x; elseif (y <= 8.2e+17) tmp = y + (z + x); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.2e+48], N[(z + x), $MachinePrecision], If[LessEqual[y, 8.2e+17], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+48}:\\
\;\;\;\;z + x\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+17}:\\
\;\;\;\;y + \left(z + x\right)\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if y < -6.20000000000000011e48 or 8.2e17 < y Initial program 99.8%
Taylor expanded in y around 0 39.0%
if -6.20000000000000011e48 < y < 8.2e17Initial program 100.0%
Taylor expanded in y around 0 93.5%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.8e+50) x (if (<= y 3e+35) (+ y x) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e+50) {
tmp = x;
} else if (y <= 3e+35) {
tmp = y + x;
} else {
tmp = x;
}
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 <= (-2.8d+50)) then
tmp = x
else if (y <= 3d+35) then
tmp = y + x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e+50) {
tmp = x;
} else if (y <= 3e+35) {
tmp = y + x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.8e+50: tmp = x elif y <= 3e+35: tmp = y + x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.8e+50) tmp = x; elseif (y <= 3e+35) tmp = Float64(y + x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.8e+50) tmp = x; elseif (y <= 3e+35) tmp = y + x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.8e+50], x, If[LessEqual[y, 3e+35], N[(y + x), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+35}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.7999999999999998e50 or 2.99999999999999991e35 < y Initial program 99.8%
Taylor expanded in x around inf 35.0%
if -2.7999999999999998e50 < y < 2.99999999999999991e35Initial program 100.0%
Taylor expanded in z around 0 53.3%
Taylor expanded in y around 0 50.7%
Final simplification43.7%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 64.7%
Final simplification64.7%
(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 99.9%
Taylor expanded in x around inf 39.5%
Final simplification39.5%
herbie shell --seed 2023176
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))