
(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.9
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= x -9.7e-11)
t_0
(if (<= x 3550000000.0)
(* (cos y) z)
(if (<= x 3.6e+158)
(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 (x <= -9.7e-11) {
tmp = t_0;
} else if (x <= 3550000000.0) {
tmp = cos(y) * z;
} else if (x <= 3.6e+158) {
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 (x <= -9.7e-11) tmp = t_0; elseif (x <= 3550000000.0) tmp = Float64(cos(y) * z); elseif (x <= 3.6e+158) 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[x, -9.7e-11], t$95$0, If[LessEqual[x, 3550000000.0], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[x, 3.6e+158], 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}\;x \leq -9.7 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3550000000:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+158}:\\
\;\;\;\;\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 x < -9.7000000000000001e-11 or 3.59999999999999988e158 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6474.3
Applied rewrites74.3%
if -9.7000000000000001e-11 < x < 3.55e9Initial program 99.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6484.8
Applied rewrites84.8%
if 3.55e9 < x < 3.59999999999999988e158Initial program 99.9%
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-*.f6479.2
Applied rewrites79.2%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 z (* x (sin y))))) (if (<= x -3.8e-45) t_0 (if (<= x 20000.0) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, z, (x * sin(y)));
double tmp;
if (x <= -3.8e-45) {
tmp = t_0;
} else if (x <= 20000.0) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, z, Float64(x * sin(y))) tmp = 0.0 if (x <= -3.8e-45) tmp = t_0; elseif (x <= 20000.0) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.8e-45], t$95$0, If[LessEqual[x, 20000.0], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{if}\;x \leq -3.8 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 20000:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.79999999999999997e-45 or 2e4 < x Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites91.6%
if -3.79999999999999997e-45 < x < 2e4Initial program 99.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6485.6
Applied rewrites85.6%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -260.0)
t_0
(if (<= y 0.078)
(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 <= -260.0) {
tmp = t_0;
} else if (y <= 0.078) {
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 <= -260.0) tmp = t_0; elseif (y <= 0.078) 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, -260.0], t$95$0, If[LessEqual[y, 0.078], 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 -260:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.078:\\
\;\;\;\;\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 < -260 or 0.0779999999999999999 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6455.0
Applied rewrites55.0%
if -260 < y < 0.0779999999999999999Initial 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%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+171) (* y x) (if (<= x 6.5e+161) (* z 1.0) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+171) {
tmp = y * x;
} else if (x <= 6.5e+161) {
tmp = z * 1.0;
} else {
tmp = y * x;
}
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 <= (-5.4d+171)) then
tmp = y * x
else if (x <= 6.5d+161) then
tmp = z * 1.0d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+171) {
tmp = y * x;
} else if (x <= 6.5e+161) {
tmp = z * 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.4e+171: tmp = y * x elif x <= 6.5e+161: tmp = z * 1.0 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+171) tmp = Float64(y * x); elseif (x <= 6.5e+161) tmp = Float64(z * 1.0); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.4e+171) tmp = y * x; elseif (x <= 6.5e+161) tmp = z * 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+171], N[(y * x), $MachinePrecision], If[LessEqual[x, 6.5e+161], N[(z * 1.0), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+171}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+161}:\\
\;\;\;\;z \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.3999999999999996e171 or 6.5e161 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6444.1
Applied rewrites44.1%
Taylor expanded in y around inf
Applied rewrites36.6%
if -5.3999999999999996e171 < x < 6.5e161Initial program 99.9%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6499.6
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.6
Applied rewrites99.6%
Taylor expanded in z around inf
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6498.4
Applied rewrites98.4%
Taylor expanded in y around 0
Applied rewrites51.9%
Final simplification48.8%
(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.f6454.7
Applied rewrites54.7%
(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.f6454.7
Applied rewrites54.7%
Taylor expanded in y around inf
Applied rewrites14.5%
Final simplification14.5%
herbie shell --seed 2024238
(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))))