
(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 6 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 (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/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 (* z (cos y)))) (if (<= z -1.3e-32) t_0 (if (<= z 4.8e+51) (fma 1.0 z (* x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1.3e-32) {
tmp = t_0;
} else if (z <= 4.8e+51) {
tmp = fma(1.0, z, (x * sin(y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -1.3e-32) tmp = t_0; elseif (z <= 4.8e+51) tmp = fma(1.0, z, Float64(x * sin(y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.3e-32], t$95$0, If[LessEqual[z, 4.8e+51], N[(1.0 * 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.3 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.2999999999999999e-32 or 4.7999999999999997e51 < z Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6487.8
Applied rewrites87.8%
if -1.2999999999999999e-32 < z < 4.7999999999999997e51Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites88.5%
Final simplification88.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -65.0)
t_0
(if (<= y 0.48)
(+
(* (fma (fma 0.041666666666666664 (* y y) -0.5) (* y y) 1.0) z)
(*
(fma
(* (fma 0.008333333333333333 (* y y) -0.16666666666666666) x)
(* y y)
x)
y))
t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -65.0) {
tmp = t_0;
} else if (y <= 0.48) {
tmp = (fma(fma(0.041666666666666664, (y * y), -0.5), (y * y), 1.0) * z) + (fma((fma(0.008333333333333333, (y * y), -0.16666666666666666) * x), (y * y), x) * y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -65.0) tmp = t_0; elseif (y <= 0.48) tmp = Float64(Float64(fma(fma(0.041666666666666664, Float64(y * y), -0.5), Float64(y * y), 1.0) * z) + Float64(fma(Float64(fma(0.008333333333333333, Float64(y * y), -0.16666666666666666) * x), Float64(y * y), x) * y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -65.0], t$95$0, If[LessEqual[y, 0.48], N[(N[(N[(N[(0.041666666666666664 * N[(y * y), $MachinePrecision] + -0.5), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * z), $MachinePrecision] + N[(N[(N[(N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * x), $MachinePrecision] * N[(y * y), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -65:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.48:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, y \cdot y, -0.5\right), y \cdot y, 1\right) \cdot z + \mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right) \cdot x, y \cdot y, x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -65 or 0.47999999999999998 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6460.8
Applied rewrites60.8%
if -65 < y < 0.47999999999999998Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*l*N/A
*-rgt-identityN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-fma.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.4
Applied rewrites99.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (<= z -7e-129) (* 1.0 z) (if (<= z 8e-90) (* x y) (* 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e-129) {
tmp = 1.0 * z;
} else if (z <= 8e-90) {
tmp = x * y;
} else {
tmp = 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 (z <= (-7d-129)) then
tmp = 1.0d0 * z
else if (z <= 8d-90) then
tmp = x * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7e-129) {
tmp = 1.0 * z;
} else if (z <= 8e-90) {
tmp = x * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e-129: tmp = 1.0 * z elif z <= 8e-90: tmp = x * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e-129) tmp = Float64(1.0 * z); elseif (z <= 8e-90) tmp = Float64(x * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e-129) tmp = 1.0 * z; elseif (z <= 8e-90) tmp = x * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e-129], N[(1.0 * z), $MachinePrecision], If[LessEqual[z, 8e-90], N[(x * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-129}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-90}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if z < -6.9999999999999995e-129 or 7.99999999999999996e-90 < z Initial program 99.8%
lift-+.f64N/A
flip-+N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites51.7%
Taylor expanded in z around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6497.7
Applied rewrites97.7%
Taylor expanded in y around 0
Applied rewrites48.7%
if -6.9999999999999995e-129 < z < 7.99999999999999996e-90Initial program 99.9%
lift-+.f64N/A
flip-+N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites52.1%
Taylor expanded in y around 0
sub-negN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
Applied rewrites32.3%
Applied rewrites62.9%
Taylor expanded in x around inf
Applied rewrites46.6%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\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 (* 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 \cdot y
\end{array}
Initial program 99.8%
lift-+.f64N/A
flip-+N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites51.8%
Taylor expanded in y around 0
sub-negN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
Applied rewrites38.8%
Applied rewrites41.6%
Taylor expanded in x around inf
Applied rewrites18.3%
herbie shell --seed 2024297
(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))))