
(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 (sin y) z (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)))
(if (<= z -1.6e-60)
(+ (fma (* y y) (* x (fma y (* y 0.041666666666666664) -0.5)) x) t_0)
(if (<= z 7e+37) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (z <= -1.6e-60) {
tmp = fma((y * y), (x * fma(y, (y * 0.041666666666666664), -0.5)), x) + t_0;
} else if (z <= 7e+37) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (z <= -1.6e-60) tmp = Float64(fma(Float64(y * y), Float64(x * fma(y, Float64(y * 0.041666666666666664), -0.5)), x) + t_0); elseif (z <= 7e+37) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.6e-60], N[(N[(N[(y * y), $MachinePrecision] * N[(x * N[(y * N[(y * 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[z, 7e+37], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;z \leq -1.6 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(y, y \cdot 0.041666666666666664, -0.5\right), x\right) + t\_0\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.6000000000000001e-60Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6470.1
Applied rewrites70.1%
if -1.6000000000000001e-60 < z < 7e37Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6488.8
Applied rewrites88.8%
if 7e37 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6470.3
Applied rewrites70.3%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (sin y) z))) (if (<= z -3.8e+66) t_0 (if (<= z 7e+37) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (z <= -3.8e+66) {
tmp = t_0;
} else if (z <= 7e+37) {
tmp = x * cos(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 = sin(y) * z
if (z <= (-3.8d+66)) then
tmp = t_0
else if (z <= 7d+37) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * z;
double tmp;
if (z <= -3.8e+66) {
tmp = t_0;
} else if (z <= 7e+37) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * z tmp = 0 if z <= -3.8e+66: tmp = t_0 elif z <= 7e+37: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (z <= -3.8e+66) tmp = t_0; elseif (z <= 7e+37) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * z; tmp = 0.0; if (z <= -3.8e+66) tmp = t_0; elseif (z <= 7e+37) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -3.8e+66], t$95$0, If[LessEqual[z, 7e+37], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.8000000000000002e66 or 7e37 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6469.7
Applied rewrites69.7%
if -3.8000000000000002e66 < z < 7e37Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6486.8
Applied rewrites86.8%
Final simplification79.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.061)
t_0
(if (<= y 3.6e-22)
(fma y (fma y (* -0.16666666666666666 (* y z)) z) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.061) {
tmp = t_0;
} else if (y <= 3.6e-22) {
tmp = fma(y, fma(y, (-0.16666666666666666 * (y * z)), z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.061) tmp = t_0; elseif (y <= 3.6e-22) tmp = fma(y, fma(y, Float64(-0.16666666666666666 * Float64(y * z)), z), 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.061], t$95$0, If[LessEqual[y, 3.6e-22], N[(y * N[(y * N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.061:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, -0.16666666666666666 \cdot \left(y \cdot z\right), z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.060999999999999999 or 3.5999999999999998e-22 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6453.1
Applied rewrites53.1%
if -0.060999999999999999 < y < 3.5999999999999998e-22Initial program 100.0%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.7
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6499.7
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (<= z -2.6e+170) (* y z) (if (<= z 3.5e+202) (* x 1.0) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+170) {
tmp = y * z;
} else if (z <= 3.5e+202) {
tmp = x * 1.0;
} else {
tmp = y * 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 <= (-2.6d+170)) then
tmp = y * z
else if (z <= 3.5d+202) then
tmp = x * 1.0d0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+170) {
tmp = y * z;
} else if (z <= 3.5e+202) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.6e+170: tmp = y * z elif z <= 3.5e+202: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.6e+170) tmp = Float64(y * z); elseif (z <= 3.5e+202) tmp = Float64(x * 1.0); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.6e+170) tmp = y * z; elseif (z <= 3.5e+202) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.6e+170], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.5e+202], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+170}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+202}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.5999999999999998e170 or 3.49999999999999987e202 < z Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.9
Applied rewrites53.9%
Taylor expanded in z around inf
Applied rewrites40.3%
if -2.5999999999999998e170 < z < 3.49999999999999987e202Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6473.2
Applied rewrites73.2%
Taylor expanded in y around 0
Applied rewrites45.8%
(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.f6452.9
Applied rewrites52.9%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return 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 = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6452.9
Applied rewrites52.9%
Taylor expanded in z around inf
Applied rewrites16.8%
herbie shell --seed 2024221
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))