
(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%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -1.02e+37)
t_0
(if (<= z 0.00032) (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 <= -1.02e+37) {
tmp = t_0;
} else if (z <= 0.00032) {
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 <= -1.02e+37) tmp = t_0; elseif (z <= 0.00032) 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, -1.02e+37], t$95$0, If[LessEqual[z, 0.00032], 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 -1.02 \cdot 10^{+37}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.00032:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.01999999999999995e37 or 3.20000000000000026e-4 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6484.9
Applied rewrites84.9%
if -1.01999999999999995e37 < z < 3.20000000000000026e-4Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites90.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -4.1e-12) t_0 (if (<= z 2.3e-149) (* (sin y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -4.1e-12) {
tmp = t_0;
} else if (z <= 2.3e-149) {
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 <= (-4.1d-12)) then
tmp = t_0
else if (z <= 2.3d-149) 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 <= -4.1e-12) {
tmp = t_0;
} else if (z <= 2.3e-149) {
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 <= -4.1e-12: tmp = t_0 elif z <= 2.3e-149: 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 <= -4.1e-12) tmp = t_0; elseif (z <= 2.3e-149) 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 <= -4.1e-12) tmp = t_0; elseif (z <= 2.3e-149) 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, -4.1e-12], t$95$0, If[LessEqual[z, 2.3e-149], 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 -4.1 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-149}:\\
\;\;\;\;\sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.0999999999999999e-12 or 2.3e-149 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6480.5
Applied rewrites80.5%
if -4.0999999999999999e-12 < z < 2.3e-149Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6475.9
Applied rewrites75.9%
Final simplification78.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -230000000000.0)
t_0
(if (<= y 0.36)
(+
(* z 1.0)
(*
x
(fma
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
(* y (* y y))
y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -230000000000.0) {
tmp = t_0;
} else if (y <= 0.36) {
tmp = (z * 1.0) + (x * fma(fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), (y * (y * y)), y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -230000000000.0) tmp = t_0; elseif (y <= 0.36) tmp = Float64(Float64(z * 1.0) + Float64(x * fma(fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), Float64(y * Float64(y * y)), y))); 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, -230000000000.0], t$95$0, If[LessEqual[y, 0.36], N[(N[(z * 1.0), $MachinePrecision] + N[(x * N[(N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -230000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.36:\\
\;\;\;\;z \cdot 1 + x \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3e11 or 0.35999999999999999 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6447.3
Applied rewrites47.3%
if -2.3e11 < y < 0.35999999999999999Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Taylor expanded in y around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites98.5%
Taylor expanded in y around 0
Applied rewrites98.6%
Final simplification73.4%
(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.f6452.2
Applied rewrites52.2%
(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.f6452.2
Applied rewrites52.2%
Taylor expanded in y around inf
Applied rewrites18.7%
Final simplification18.7%
herbie shell --seed 2024226
(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))))