
(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 7 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 (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -375.0)
t_0
(if (<= y 1.15e-6)
(fma y (fma z (* y -0.5) x) z)
(if (<= y 4.3e+198) (* (sin y) x) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -375.0) {
tmp = t_0;
} else if (y <= 1.15e-6) {
tmp = fma(y, fma(z, (y * -0.5), x), z);
} else if (y <= 4.3e+198) {
tmp = sin(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -375.0) tmp = t_0; elseif (y <= 1.15e-6) tmp = fma(y, fma(z, Float64(y * -0.5), x), z); elseif (y <= 4.3e+198) tmp = Float64(sin(y) * x); 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, -375.0], t$95$0, If[LessEqual[y, 1.15e-6], N[(y * N[(z * N[(y * -0.5), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[y, 4.3e+198], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -375:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+198}:\\
\;\;\;\;\sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -375 or 4.29999999999999982e198 < y Initial program 99.7%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6458.1
Simplified58.1%
if -375 < y < 1.15e-6Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.3
Simplified99.3%
if 1.15e-6 < y < 4.29999999999999982e198Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6468.2
Simplified68.2%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -2.9e+87) t_0 (if (<= z 3.6e+179) (fma (sin y) x z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.9e+87) {
tmp = t_0;
} else if (z <= 3.6e+179) {
tmp = fma(sin(y), x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.9e+87) tmp = t_0; elseif (z <= 3.6e+179) tmp = fma(sin(y), x, z); 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, -2.9e+87], t$95$0, If[LessEqual[z, 3.6e+179], N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{+87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.8999999999999998e87 or 3.5999999999999998e179 < z Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6495.2
Simplified95.2%
if -2.8999999999999998e87 < z < 3.5999999999999998e179Initial program 99.8%
Taylor expanded in y around 0
Simplified86.4%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6486.4
Applied egg-rr86.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -0.098)
t_0
(if (<= y 3.5e-6)
(fma y (fma y (fma z -0.5 (* -0.16666666666666666 (* y x))) x) z)
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -0.098) {
tmp = t_0;
} else if (y <= 3.5e-6) {
tmp = fma(y, fma(y, fma(z, -0.5, (-0.16666666666666666 * (y * x))), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -0.098) tmp = t_0; elseif (y <= 3.5e-6) tmp = fma(y, fma(y, fma(z, -0.5, Float64(-0.16666666666666666 * Float64(y * x))), x), z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.098], t$95$0, If[LessEqual[y, 3.5e-6], N[(y * N[(y * N[(z * -0.5 + N[(-0.16666666666666666 * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -0.098:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, -0.16666666666666666 \cdot \left(y \cdot x\right)\right), x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.098000000000000004 or 3.49999999999999995e-6 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6454.4
Simplified54.4%
if -0.098000000000000004 < y < 3.49999999999999995e-6Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Simplified100.0%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (<= x 2.9e+99) z (* y x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 2.9e+99) {
tmp = z;
} else {
tmp = y * 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 (x <= 2.9d+99) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2.9e+99) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2.9e+99: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2.9e+99) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2.9e+99) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2.9e+99], z, N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.9 \cdot 10^{+99}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < 2.9000000000000002e99Initial program 99.8%
Taylor expanded in y around 0
Simplified44.5%
if 2.9000000000000002e99 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6444.0
Simplified44.0%
Taylor expanded in y around inf
*-lowering-*.f6439.5
Simplified39.5%
Final simplification43.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
accelerator-lowering-fma.f6452.1
Simplified52.1%
(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 y around 0
Simplified38.6%
herbie shell --seed 2024204
(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))))