
(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 8 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 (- (* 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}
Initial program 99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -7.4e+135)
(* (sin y) (- z))
(if (<= y -76000.0)
t_0
(if (<= y 0.225)
(-
x
(*
y
(fma
(* y y)
(fma
(* y y)
(* z (fma (* y y) -0.0001984126984126984 0.008333333333333333))
(* z -0.16666666666666666))
z)))
t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -7.4e+135) {
tmp = sin(y) * -z;
} else if (y <= -76000.0) {
tmp = t_0;
} else if (y <= 0.225) {
tmp = x - (y * fma((y * y), fma((y * y), (z * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), (z * -0.16666666666666666)), z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -7.4e+135) tmp = Float64(sin(y) * Float64(-z)); elseif (y <= -76000.0) tmp = t_0; elseif (y <= 0.225) tmp = Float64(x - Float64(y * fma(Float64(y * y), fma(Float64(y * y), Float64(z * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), Float64(z * -0.16666666666666666)), z))); 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, -7.4e+135], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], If[LessEqual[y, -76000.0], t$95$0, If[LessEqual[y, 0.225], N[(x - N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(z * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(z * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -7.4 \cdot 10^{+135}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq -76000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.225:\\
\;\;\;\;x - y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), z \cdot -0.16666666666666666\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.39999999999999994e135Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6471.9
Simplified71.9%
if -7.39999999999999994e135 < y < -76000 or 0.225000000000000006 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6465.0
Simplified65.0%
if -76000 < y < 0.225000000000000006Initial program 100.0%
Taylor expanded in y around 0
Simplified100.0%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified99.1%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -7.2e+86) t_0 (if (<= x 1.8e+85) (- x (* z (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -7.2e+86) {
tmp = t_0;
} else if (x <= 1.8e+85) {
tmp = x - (z * 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 = x * cos(y)
if (x <= (-7.2d+86)) then
tmp = t_0
else if (x <= 1.8d+85) then
tmp = x - (z * 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 = x * Math.cos(y);
double tmp;
if (x <= -7.2e+86) {
tmp = t_0;
} else if (x <= 1.8e+85) {
tmp = x - (z * Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -7.2e+86: tmp = t_0 elif x <= 1.8e+85: tmp = x - (z * math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -7.2e+86) tmp = t_0; elseif (x <= 1.8e+85) tmp = Float64(x - Float64(z * sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -7.2e+86) tmp = t_0; elseif (x <= 1.8e+85) tmp = x - (z * sin(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.2e+86], t$95$0, If[LessEqual[x, 1.8e+85], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -7.2 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+85}:\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.20000000000000011e86 or 1.7999999999999999e85 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6491.3
Simplified91.3%
if -7.20000000000000011e86 < x < 1.7999999999999999e85Initial program 99.8%
Taylor expanded in y around 0
Simplified90.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -76000.0)
t_0
(if (<= y 1.25)
(-
x
(*
y
(fma
(* y y)
(fma
(* y y)
(* z (fma (* y y) -0.0001984126984126984 0.008333333333333333))
(* z -0.16666666666666666))
z)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -76000.0) {
tmp = t_0;
} else if (y <= 1.25) {
tmp = x - (y * fma((y * y), fma((y * y), (z * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), (z * -0.16666666666666666)), z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -76000.0) tmp = t_0; elseif (y <= 1.25) tmp = Float64(x - Float64(y * fma(Float64(y * y), fma(Float64(y * y), Float64(z * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), Float64(z * -0.16666666666666666)), z))); 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, -76000.0], t$95$0, If[LessEqual[y, 1.25], N[(x - N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(z * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(z * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -76000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.25:\\
\;\;\;\;x - y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), z \cdot -0.16666666666666666\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -76000 or 1.25 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6456.2
Simplified56.2%
if -76000 < y < 1.25Initial program 100.0%
Taylor expanded in y around 0
Simplified100.0%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified99.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y z)))) (if (<= z -4.3e+156) t_0 (if (<= z 1.45e+197) x t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -4.3e+156) {
tmp = t_0;
} else if (z <= 1.45e+197) {
tmp = x;
} 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 = -(y * z)
if (z <= (-4.3d+156)) then
tmp = t_0
else if (z <= 1.45d+197) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -4.3e+156) {
tmp = t_0;
} else if (z <= 1.45e+197) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -4.3e+156: tmp = t_0 elif z <= 1.45e+197: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -4.3e+156) tmp = t_0; elseif (z <= 1.45e+197) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -4.3e+156) tmp = t_0; elseif (z <= 1.45e+197) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -4.3e+156], t$95$0, If[LessEqual[z, 1.45e+197], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -4.3 \cdot 10^{+156}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+197}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.29999999999999985e156 or 1.45000000000000001e197 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6453.7
Simplified53.7%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6454.6
Simplified54.6%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6441.0
Simplified41.0%
if -4.29999999999999985e156 < z < 1.45000000000000001e197Initial program 99.8%
Taylor expanded in y around 0
Simplified45.5%
Final simplification44.2%
(FPCore (x y z) :precision binary64 (fma y (- z) x))
double code(double x, double y, double z) {
return fma(y, -z, x);
}
function code(x, y, z) return fma(y, Float64(-z), x) end
code[x_, y_, z_] := N[(y * (-z) + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, -z, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6453.2
Simplified53.2%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6454.4
Simplified54.4%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (y * z);
}
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 * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6454.4
Simplified54.4%
Final simplification54.4%
(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.8%
Taylor expanded in y around 0
Simplified37.7%
herbie shell --seed 2024199
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))