
(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 8 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%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -5.9e+66) t_0 (if (<= z 7.2e+95) (fma (sin y) x (* z 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.9e+66) {
tmp = t_0;
} else if (z <= 7.2e+95) {
tmp = fma(sin(y), x, (z * 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -5.9e+66) tmp = t_0; elseif (z <= 7.2e+95) tmp = fma(sin(y), x, Float64(z * 1.0)); 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, -5.9e+66], t$95$0, If[LessEqual[z, 7.2e+95], N[(N[Sin[y], $MachinePrecision] * x + N[(z * 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.9 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{+95}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.89999999999999988e66 or 7.19999999999999955e95 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6494.1
Applied rewrites94.1%
if -5.89999999999999988e66 < z < 7.19999999999999955e95Initial 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 rewrites85.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -5.4e-161) t_0 (if (<= z 7.5e-133) (* (sin y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.4e-161) {
tmp = t_0;
} else if (z <= 7.5e-133) {
tmp = sin(y) * 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 = z * cos(y)
if (z <= (-5.4d-161)) then
tmp = t_0
else if (z <= 7.5d-133) then
tmp = sin(y) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -5.4e-161) {
tmp = t_0;
} else if (z <= 7.5e-133) {
tmp = Math.sin(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -5.4e-161: tmp = t_0 elif z <= 7.5e-133: tmp = math.sin(y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -5.4e-161) tmp = t_0; elseif (z <= 7.5e-133) tmp = Float64(sin(y) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -5.4e-161) tmp = t_0; elseif (z <= 7.5e-133) tmp = sin(y) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.4e-161], t$95$0, If[LessEqual[z, 7.5e-133], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.4 \cdot 10^{-161}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-133}:\\
\;\;\;\;\sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.3999999999999999e-161 or 7.4999999999999999e-133 < z Initial program 99.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6478.5
Applied rewrites78.5%
if -5.3999999999999999e-161 < z < 7.4999999999999999e-133Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6478.2
Applied rewrites78.2%
Final simplification78.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -0.27)
t_0
(if (<= y 0.16)
(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 = sin(y) * x;
double tmp;
if (y <= -0.27) {
tmp = t_0;
} else if (y <= 0.16) {
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(sin(y) * x) tmp = 0.0 if (y <= -0.27) tmp = t_0; elseif (y <= 0.16) 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[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.27], t$95$0, If[LessEqual[y, 0.16], 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 := \sin y \cdot x\\
\mathbf{if}\;y \leq -0.27:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.16:\\
\;\;\;\;\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.27000000000000002 or 0.160000000000000003 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6449.2
Applied rewrites49.2%
if -0.27000000000000002 < y < 0.160000000000000003Initial 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-*.f6499.0
Applied rewrites99.0%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (fma y (fma y (fma z -0.5 (* (* y x) -0.16666666666666666)) x) z))
double code(double x, double y, double z) {
return fma(y, fma(y, fma(z, -0.5, ((y * x) * -0.16666666666666666)), x), z);
}
function code(x, y, z) return fma(y, fma(y, fma(z, -0.5, Float64(Float64(y * x) * -0.16666666666666666)), x), z) end
code[x_, y_, z_] := N[(y * N[(y * N[(z * -0.5 + N[(N[(y * x), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\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)
\end{array}
Initial program 99.8%
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-*.f6453.2
Applied rewrites53.2%
(FPCore (x y z) :precision binary64 (if (<= x -4.5e+232) (* y x) (* z 1.0)))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+232) {
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 (x <= (-4.5d+232)) 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 (x <= -4.5e+232) {
tmp = y * x;
} else {
tmp = z * 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e+232: tmp = y * x else: tmp = z * 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e+232) 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 (x <= -4.5e+232) tmp = y * x; else tmp = z * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e+232], N[(y * x), $MachinePrecision], N[(z * 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+232}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot 1\\
\end{array}
\end{array}
if x < -4.4999999999999998e232Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.2
Applied rewrites66.2%
Taylor expanded in y around inf
Applied rewrites46.2%
if -4.4999999999999998e232 < x Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6468.3
Applied rewrites68.3%
Taylor expanded in y around 0
Applied rewrites44.8%
Final simplification44.9%
(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.f6453.1
Applied rewrites53.1%
(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.f6453.1
Applied rewrites53.1%
Taylor expanded in y around inf
Applied rewrites14.3%
Final simplification14.3%
herbie shell --seed 2024223
(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))))