
(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 (* (cos y) z)))
double code(double x, double y, double z) {
return fma(sin(y), x, (cos(y) * z));
}
function code(x, y, z) return fma(sin(y), x, Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.1e+58) (not (<= z 2.4e+76))) (* (cos y) z) (fma (sin y) x (* 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.1e+58) || !(z <= 2.4e+76)) {
tmp = cos(y) * z;
} else {
tmp = fma(sin(y), x, (1.0 * z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -4.1e+58) || !(z <= 2.4e+76)) tmp = Float64(cos(y) * z); else tmp = fma(sin(y), x, Float64(1.0 * z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.1e+58], N[Not[LessEqual[z, 2.4e+76]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+58} \lor \neg \left(z \leq 2.4 \cdot 10^{+76}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\end{array}
\end{array}
if z < -4.1e58 or 2.4e76 < z Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6490.2
Applied rewrites90.2%
if -4.1e58 < z < 2.4e76Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites89.4%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2600000000000.0) (not (<= x 1.56e-10))) (* (sin y) x) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2600000000000.0) || !(x <= 1.56e-10)) {
tmp = sin(y) * x;
} else {
tmp = cos(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 ((x <= (-2600000000000.0d0)) .or. (.not. (x <= 1.56d-10))) then
tmp = sin(y) * x
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2600000000000.0) || !(x <= 1.56e-10)) {
tmp = Math.sin(y) * x;
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2600000000000.0) or not (x <= 1.56e-10): tmp = math.sin(y) * x else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2600000000000.0) || !(x <= 1.56e-10)) tmp = Float64(sin(y) * x); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2600000000000.0) || ~((x <= 1.56e-10))) tmp = sin(y) * x; else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2600000000000.0], N[Not[LessEqual[x, 1.56e-10]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2600000000000 \lor \neg \left(x \leq 1.56 \cdot 10^{-10}\right):\\
\;\;\;\;\sin y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -2.6e12 or 1.56000000000000004e-10 < x Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6482.6
Applied rewrites82.6%
Taylor expanded in x around inf
Applied rewrites69.7%
if -2.6e12 < x < 1.56000000000000004e-10Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6485.9
Applied rewrites85.9%
Final simplification77.6%
(FPCore (x y z)
:precision binary64
(if (or (<= y -0.0265) (not (<= y 0.88)))
(* (cos y) z)
(+
(*
(fma
(fma (* (* y y) x) 0.008333333333333333 (* -0.16666666666666666 x))
(* y y)
x)
y)
(* z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0265) || !(y <= 0.88)) {
tmp = cos(y) * z;
} else {
tmp = (fma(fma(((y * y) * x), 0.008333333333333333, (-0.16666666666666666 * x)), (y * y), x) * y) + (z * 1.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.0265) || !(y <= 0.88)) tmp = Float64(cos(y) * z); else tmp = Float64(Float64(fma(fma(Float64(Float64(y * y) * x), 0.008333333333333333, Float64(-0.16666666666666666 * x)), Float64(y * y), x) * y) + Float64(z * 1.0)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0265], N[Not[LessEqual[y, 0.88]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(N[(N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision] * 0.008333333333333333 + N[(-0.16666666666666666 * x), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision] + N[(z * 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0265 \lor \neg \left(y \leq 0.88\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(y \cdot y\right) \cdot x, 0.008333333333333333, -0.16666666666666666 \cdot x\right), y \cdot y, x\right) \cdot y + z \cdot 1\\
\end{array}
\end{array}
if y < -0.0264999999999999993 or 0.880000000000000004 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6451.8
Applied rewrites51.8%
if -0.0264999999999999993 < y < 0.880000000000000004Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.5
Applied rewrites99.5%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e+168) (not (<= x 1.68e+103))) (* x y) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e+168) || !(x <= 1.68e+103)) {
tmp = x * y;
} else {
tmp = 1.0 * 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 ((x <= (-3.6d+168)) .or. (.not. (x <= 1.68d+103))) then
tmp = x * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e+168) || !(x <= 1.68e+103)) {
tmp = x * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e+168) or not (x <= 1.68e+103): tmp = x * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e+168) || !(x <= 1.68e+103)) tmp = Float64(x * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e+168) || ~((x <= 1.68e+103))) tmp = x * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e+168], N[Not[LessEqual[x, 1.68e+103]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+168} \lor \neg \left(x \leq 1.68 \cdot 10^{+103}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -3.5999999999999999e168 or 1.68000000000000001e103 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6455.1
Applied rewrites55.1%
Taylor expanded in x around inf
Applied rewrites40.0%
if -3.5999999999999999e168 < x < 1.68000000000000001e103Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6471.7
Applied rewrites71.7%
Taylor expanded in y around 0
Applied rewrites41.7%
Final simplification41.2%
(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.f6451.5
Applied rewrites51.5%
Final simplification51.5%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.5
Applied rewrites51.5%
Taylor expanded in x around inf
Applied rewrites20.0%
Final simplification20.0%
herbie shell --seed 2024321
(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))))