
(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}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 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}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(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}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -2e+154)
t_0
(if (<= y -1.7)
t_1
(if (<= y -0.0075)
t_0
(if (<= y 0.086)
(+ (* -0.5 (* z (* y y))) (+ z (* x y)))
(if (<= y 5.8e+20) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -2e+154) {
tmp = t_0;
} else if (y <= -1.7) {
tmp = t_1;
} else if (y <= -0.0075) {
tmp = t_0;
} else if (y <= 0.086) {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
} else if (y <= 5.8e+20) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = z * cos(y)
t_1 = x * sin(y)
if (y <= (-2d+154)) then
tmp = t_0
else if (y <= (-1.7d0)) then
tmp = t_1
else if (y <= (-0.0075d0)) then
tmp = t_0
else if (y <= 0.086d0) then
tmp = ((-0.5d0) * (z * (y * y))) + (z + (x * y))
else if (y <= 5.8d+20) then
tmp = t_1
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 t_1 = x * Math.sin(y);
double tmp;
if (y <= -2e+154) {
tmp = t_0;
} else if (y <= -1.7) {
tmp = t_1;
} else if (y <= -0.0075) {
tmp = t_0;
} else if (y <= 0.086) {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
} else if (y <= 5.8e+20) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -2e+154: tmp = t_0 elif y <= -1.7: tmp = t_1 elif y <= -0.0075: tmp = t_0 elif y <= 0.086: tmp = (-0.5 * (z * (y * y))) + (z + (x * y)) elif y <= 5.8e+20: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2e+154) tmp = t_0; elseif (y <= -1.7) tmp = t_1; elseif (y <= -0.0075) tmp = t_0; elseif (y <= 0.086) tmp = Float64(Float64(-0.5 * Float64(z * Float64(y * y))) + Float64(z + Float64(x * y))); elseif (y <= 5.8e+20) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = x * sin(y); tmp = 0.0; if (y <= -2e+154) tmp = t_0; elseif (y <= -1.7) tmp = t_1; elseif (y <= -0.0075) tmp = t_0; elseif (y <= 0.086) tmp = (-0.5 * (z * (y * y))) + (z + (x * y)); elseif (y <= 5.8e+20) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e+154], t$95$0, If[LessEqual[y, -1.7], t$95$1, If[LessEqual[y, -0.0075], t$95$0, If[LessEqual[y, 0.086], N[(N[(-0.5 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.8e+20], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2 \cdot 10^{+154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.7:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -0.0075:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.086:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot y\right)\right) + \left(z + x \cdot y\right)\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+20}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.00000000000000007e154 or -1.69999999999999996 < y < -0.0074999999999999997 or 5.8e20 < y Initial program 99.5%
Taylor expanded in x around 0 99.5%
fma-def99.5%
Simplified99.5%
Taylor expanded in z around inf 64.4%
if -2.00000000000000007e154 < y < -1.69999999999999996 or 0.085999999999999993 < y < 5.8e20Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around 0 68.2%
if -0.0074999999999999997 < y < 0.085999999999999993Initial program 100.0%
Taylor expanded in y around 0 100.0%
expm1-log1p-u95.7%
expm1-udef95.7%
unpow295.7%
associate-*l*95.7%
Applied egg-rr95.7%
expm1-def95.7%
expm1-log1p100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+126) (not (<= z 2.1e+36))) (* z (cos y)) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+126) || !(z <= 2.1e+36)) {
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 <= (-1d+126)) .or. (.not. (z <= 2.1d+36))) 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 <= -1e+126) || !(z <= 2.1e+36)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+126) or not (z <= 2.1e+36): tmp = z * math.cos(y) else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+126) || !(z <= 2.1e+36)) 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 <= -1e+126) || ~((z <= 2.1e+36))) tmp = z * cos(y); else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+126], N[Not[LessEqual[z, 2.1e+36]], $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 -1 \cdot 10^{+126} \lor \neg \left(z \leq 2.1 \cdot 10^{+36}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -9.99999999999999925e125 or 2.10000000000000004e36 < z Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 91.1%
if -9.99999999999999925e125 < z < 2.10000000000000004e36Initial program 99.8%
Taylor expanded in y around 0 90.4%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0071) (not (<= y 4.1e+17))) (* z (cos y)) (+ (* -0.5 (* z (* y y))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0071) || !(y <= 4.1e+17)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (z + (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 ((y <= (-0.0071d0)) .or. (.not. (y <= 4.1d+17))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (z * (y * y))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0071) || !(y <= 4.1e+17)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0071) or not (y <= 4.1e+17): tmp = z * math.cos(y) else: tmp = (-0.5 * (z * (y * y))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0071) || !(y <= 4.1e+17)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(z * Float64(y * y))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0071) || ~((y <= 4.1e+17))) tmp = z * cos(y); else tmp = (-0.5 * (z * (y * y))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0071], N[Not[LessEqual[y, 4.1e+17]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0071 \lor \neg \left(y \leq 4.1 \cdot 10^{+17}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot y\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -0.0071000000000000004 or 4.1e17 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in z around inf 59.3%
if -0.0071000000000000004 < y < 4.1e17Initial program 100.0%
Taylor expanded in y around 0 96.7%
expm1-log1p-u92.6%
expm1-udef92.6%
unpow292.6%
associate-*l*92.6%
Applied egg-rr92.6%
expm1-def92.6%
expm1-log1p96.7%
*-commutative96.7%
*-commutative96.7%
associate-*r*96.7%
Simplified96.7%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (<= z -4.8e-53) z (if (<= z 1.04e-100) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e-53) {
tmp = z;
} else if (z <= 1.04e-100) {
tmp = x * y;
} else {
tmp = 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 (z <= (-4.8d-53)) then
tmp = z
else if (z <= 1.04d-100) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e-53) {
tmp = z;
} else if (z <= 1.04e-100) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e-53: tmp = z elif z <= 1.04e-100: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e-53) tmp = z; elseif (z <= 1.04e-100) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.8e-53) tmp = z; elseif (z <= 1.04e-100) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e-53], z, If[LessEqual[z, 1.04e-100], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-53}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.04 \cdot 10^{-100}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -4.80000000000000015e-53 or 1.04e-100 < z Initial program 99.7%
Taylor expanded in x around 0 99.7%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 47.3%
if -4.80000000000000015e-53 < z < 1.04e-100Initial program 99.9%
Taylor expanded in x around 0 99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around 0 72.5%
Taylor expanded in y around 0 42.6%
Final simplification45.6%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return 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 = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 57.0%
Final simplification57.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 39.1%
Final simplification39.1%
herbie shell --seed 2023224
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))