
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) x (* z (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (fma z (/ (sin y) x) 1.0) x)))
(if (<= z -7.5e-78)
t_0
(if (<= z 2.5e-114)
(* x (cos y))
(if (<= z 5.4e+211) t_0 (* z (sin y)))))))
double code(double x, double y, double z) {
double t_0 = fma(z, (sin(y) / x), 1.0) * x;
double tmp;
if (z <= -7.5e-78) {
tmp = t_0;
} else if (z <= 2.5e-114) {
tmp = x * cos(y);
} else if (z <= 5.4e+211) {
tmp = t_0;
} else {
tmp = z * sin(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(fma(z, Float64(sin(y) / x), 1.0) * x) tmp = 0.0 if (z <= -7.5e-78) tmp = t_0; elseif (z <= 2.5e-114) tmp = Float64(x * cos(y)); elseif (z <= 5.4e+211) tmp = t_0; else tmp = Float64(z * sin(y)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[z, -7.5e-78], t$95$0, If[LessEqual[z, 2.5e-114], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5.4e+211], t$95$0, N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, \frac{\sin y}{x}, 1\right) \cdot x\\
\mathbf{if}\;z \leq -7.5 \cdot 10^{-78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-114}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{+211}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if z < -7.50000000000000041e-78 or 2.49999999999999995e-114 < z < 5.3999999999999998e211Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
associate-/r/N/A
flip3--N/A
clear-numN/A
Applied rewrites54.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6493.2
Applied rewrites93.2%
Taylor expanded in y around 0
Applied rewrites77.3%
if -7.50000000000000041e-78 < z < 2.49999999999999995e-114Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6495.3
Applied rewrites95.3%
if 5.3999999999999998e211 < z Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6494.1
Applied rewrites94.1%
Final simplification84.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -7e+122)
t_0
(if (<= y -0.7)
t_1
(if (<= y 2e-17)
(fma (fma (fma -0.16666666666666666 (* z y) (* -0.5 x)) y z) y x)
(if (<= y 6.5e+46) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -7e+122) {
tmp = t_0;
} else if (y <= -0.7) {
tmp = t_1;
} else if (y <= 2e-17) {
tmp = fma(fma(fma(-0.16666666666666666, (z * y), (-0.5 * x)), y, z), y, x);
} else if (y <= 6.5e+46) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -7e+122) tmp = t_0; elseif (y <= -0.7) tmp = t_1; elseif (y <= 2e-17) tmp = fma(fma(fma(-0.16666666666666666, Float64(z * y), Float64(-0.5 * x)), y, z), y, x); elseif (y <= 6.5e+46) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e+122], t$95$0, If[LessEqual[y, -0.7], t$95$1, If[LessEqual[y, 2e-17], N[(N[(N[(-0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y + z), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[y, 6.5e+46], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -7 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.7:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, z \cdot y, -0.5 \cdot x\right), y, z\right), y, x\right)\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -7.00000000000000028e122 or 2.00000000000000014e-17 < y < 6.50000000000000008e46Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6467.4
Applied rewrites67.4%
if -7.00000000000000028e122 < y < -0.69999999999999996 or 6.50000000000000008e46 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6464.1
Applied rewrites64.1%
if -0.69999999999999996 < y < 2.00000000000000014e-17Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.5
Applied rewrites99.5%
Final simplification82.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.7)
t_0
(if (<= y 5.4e+35)
(fma (fma (fma -0.16666666666666666 (* z y) (* -0.5 x)) y z) y x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.7) {
tmp = t_0;
} else if (y <= 5.4e+35) {
tmp = fma(fma(fma(-0.16666666666666666, (z * y), (-0.5 * x)), y, z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.7) tmp = t_0; elseif (y <= 5.4e+35) tmp = fma(fma(fma(-0.16666666666666666, Float64(z * y), Float64(-0.5 * x)), y, z), y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.7], t$95$0, If[LessEqual[y, 5.4e+35], N[(N[(N[(-0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y + z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.7:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, z \cdot y, -0.5 \cdot x\right), y, z\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.69999999999999996 or 5.40000000000000005e35 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6456.3
Applied rewrites56.3%
if -0.69999999999999996 < y < 5.40000000000000005e35Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (<= z 7.2e+200) (* 1.0 x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 7.2e+200) {
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 (z <= 7.2d+200) 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 (z <= 7.2e+200) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 7.2e+200: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 7.2e+200) 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 (z <= 7.2e+200) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 7.2e+200], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.2 \cdot 10^{+200}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < 7.1999999999999995e200Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6468.3
Applied rewrites68.3%
Taylor expanded in y around 0
Applied rewrites43.3%
if 7.1999999999999995e200 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6464.3
Applied rewrites64.3%
Taylor expanded in z around inf
Applied rewrites53.1%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6455.1
Applied rewrites55.1%
(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 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6455.1
Applied rewrites55.1%
Taylor expanded in z around inf
Applied rewrites19.2%
herbie shell --seed 2024256
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))