
(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 (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
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x (* z 1.0)))) (if (<= x -2.4e-40) t_0 (if (<= x 1.2e-91) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), x, (z * 1.0));
double tmp;
if (x <= -2.4e-40) {
tmp = t_0;
} else if (x <= 1.2e-91) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), x, Float64(z * 1.0)) tmp = 0.0 if (x <= -2.4e-40) tmp = t_0; elseif (x <= 1.2e-91) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x + N[(z * 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.4e-40], t$95$0, If[LessEqual[x, 1.2e-91], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, x, z \cdot 1\right)\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-91}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.39999999999999991e-40 or 1.20000000000000005e-91 < x Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites89.2%
if -2.39999999999999991e-40 < x < 1.20000000000000005e-91Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6486.9
Applied rewrites86.9%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= x -1.62e+15) t_0 (if (<= x 0.0023) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (x <= -1.62e+15) {
tmp = t_0;
} else if (x <= 0.0023) {
tmp = cos(y) * z;
} 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 * sin(y)
if (x <= (-1.62d+15)) then
tmp = t_0
else if (x <= 0.0023d0) then
tmp = cos(y) * z
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.sin(y);
double tmp;
if (x <= -1.62e+15) {
tmp = t_0;
} else if (x <= 0.0023) {
tmp = Math.cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if x <= -1.62e+15: tmp = t_0 elif x <= 0.0023: tmp = math.cos(y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (x <= -1.62e+15) tmp = t_0; elseif (x <= 0.0023) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (x <= -1.62e+15) tmp = t_0; elseif (x <= 0.0023) tmp = cos(y) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.62e+15], t$95$0, If[LessEqual[x, 0.0023], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;x \leq -1.62 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0023:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.62e15 or 0.0023 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6477.9
Applied rewrites77.9%
if -1.62e15 < x < 0.0023Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6481.5
Applied rewrites81.5%
Final simplification79.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.0245)
t_0
(if (<= y 0.066)
(fma y (fma y (fma z -0.5 (* (* y x) -0.16666666666666666)) x) z)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.0245) {
tmp = t_0;
} else if (y <= 0.066) {
tmp = fma(y, fma(y, fma(z, -0.5, ((y * x) * -0.16666666666666666)), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.0245) tmp = t_0; elseif (y <= 0.066) tmp = fma(y, fma(y, fma(z, -0.5, Float64(Float64(y * x) * -0.16666666666666666)), x), z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0245], t$95$0, If[LessEqual[y, 0.066], N[(y * N[(y * N[(z * -0.5 + N[(N[(y * x), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.0245:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.066:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, \left(y \cdot x\right) \cdot -0.16666666666666666\right), x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.024500000000000001 or 0.066000000000000003 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6456.3
Applied rewrites56.3%
if -0.024500000000000001 < y < 0.066000000000000003Initial program 100.0%
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
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= z -3.3e-36) (* z 1.0) (if (<= z 2.25e-147) (* y x) (* z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e-36) {
tmp = z * 1.0;
} else if (z <= 2.25e-147) {
tmp = y * x;
} else {
tmp = z * 1.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) :: tmp
if (z <= (-3.3d-36)) then
tmp = z * 1.0d0
else if (z <= 2.25d-147) then
tmp = y * x
else
tmp = z * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e-36) {
tmp = z * 1.0;
} else if (z <= 2.25e-147) {
tmp = y * x;
} else {
tmp = z * 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e-36: tmp = z * 1.0 elif z <= 2.25e-147: tmp = y * x else: tmp = z * 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e-36) tmp = Float64(z * 1.0); elseif (z <= 2.25e-147) tmp = Float64(y * x); else tmp = Float64(z * 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.3e-36) tmp = z * 1.0; elseif (z <= 2.25e-147) tmp = y * x; else tmp = z * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e-36], N[(z * 1.0), $MachinePrecision], If[LessEqual[z, 2.25e-147], N[(y * x), $MachinePrecision], N[(z * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-36}:\\
\;\;\;\;z \cdot 1\\
\mathbf{elif}\;z \leq 2.25 \cdot 10^{-147}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot 1\\
\end{array}
\end{array}
if z < -3.29999999999999991e-36 or 2.24999999999999986e-147 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6470.2
Applied rewrites70.2%
Taylor expanded in y around 0
Applied rewrites37.1%
if -3.29999999999999991e-36 < z < 2.24999999999999986e-147Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6440.2
Applied rewrites40.2%
Taylor expanded in y around inf
Applied rewrites32.0%
Final simplification35.3%
(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.f6441.8
Applied rewrites41.8%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6441.8
Applied rewrites41.8%
Taylor expanded in y around inf
Applied rewrites17.5%
Final simplification17.5%
herbie shell --seed 2024233
(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))))