
(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-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
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 (* x (sin y))) (t_1 (* (cos y) z)))
(if (<= y -1.35e+233)
t_0
(if (<= y -0.01)
t_1
(if (<= y 900000.0)
(fma y (fma z (* y -0.5) x) z)
(if (<= y 1.32e+185) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = cos(y) * z;
double tmp;
if (y <= -1.35e+233) {
tmp = t_0;
} else if (y <= -0.01) {
tmp = t_1;
} else if (y <= 900000.0) {
tmp = fma(y, fma(z, (y * -0.5), x), z);
} else if (y <= 1.32e+185) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(cos(y) * z) tmp = 0.0 if (y <= -1.35e+233) tmp = t_0; elseif (y <= -0.01) tmp = t_1; elseif (y <= 900000.0) tmp = fma(y, fma(z, Float64(y * -0.5), x), z); elseif (y <= 1.32e+185) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -1.35e+233], t$95$0, If[LessEqual[y, -0.01], t$95$1, If[LessEqual[y, 900000.0], N[(y * N[(z * N[(y * -0.5), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[y, 1.32e+185], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := \cos y \cdot z\\
\mathbf{if}\;y \leq -1.35 \cdot 10^{+233}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.01:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 900000:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{+185}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.35000000000000004e233 or 1.3199999999999999e185 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6463.9
Applied rewrites63.9%
if -1.35000000000000004e233 < y < -0.0100000000000000002 or 9e5 < y < 1.3199999999999999e185Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6469.9
Applied rewrites69.9%
if -0.0100000000000000002 < y < 9e5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification83.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= z -1.9e+35)
t_0
(if (<= z 7.8e+100) (fma 1.0 z (* x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (z <= -1.9e+35) {
tmp = t_0;
} else if (z <= 7.8e+100) {
tmp = fma(1.0, z, (x * sin(y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (z <= -1.9e+35) tmp = t_0; elseif (z <= 7.8e+100) tmp = fma(1.0, z, Float64(x * sin(y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.9e+35], t$95$0, If[LessEqual[z, 7.8e+100], N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;z \leq -1.9 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+100}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.9e35 or 7.8e100 < z Initial program 99.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6488.4
Applied rewrites88.4%
if -1.9e35 < z < 7.8e100Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites87.6%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= y -0.09) t_0 (if (<= y 0.018) (fma y (fma z (* y -0.5) x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.09) {
tmp = t_0;
} else if (y <= 0.018) {
tmp = fma(y, fma(z, (y * -0.5), 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.09) tmp = t_0; elseif (y <= 0.018) tmp = fma(y, fma(z, Float64(y * -0.5), 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.09], t$95$0, If[LessEqual[y, 0.018], N[(y * N[(z * N[(y * -0.5), $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.09:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.018:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.089999999999999997 or 0.0179999999999999986 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6444.0
Applied rewrites44.0%
if -0.089999999999999997 < y < 0.0179999999999999986Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+184) (* y x) (if (<= x 3.2e+143) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+184) {
tmp = y * x;
} else if (x <= 3.2e+143) {
tmp = z;
} 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+184)) then
tmp = y * x
else if (x <= 3.2d+143) then
tmp = z
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+184) {
tmp = y * x;
} else if (x <= 3.2e+143) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.4e+184: tmp = y * x elif x <= 3.2e+143: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+184) tmp = Float64(y * x); elseif (x <= 3.2e+143) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.4e+184) tmp = y * x; elseif (x <= 3.2e+143) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+184], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.2e+143], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+184}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+143}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.3999999999999998e184 or 3.20000000000000016e143 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6474.2
Applied rewrites74.2%
Taylor expanded in y around 0
lower-*.f6440.8
Applied rewrites40.8%
if -5.3999999999999998e184 < x < 3.20000000000000016e143Initial program 99.7%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
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.f6496.7
Applied rewrites96.7%
Taylor expanded in y around 0
Applied rewrites46.2%
*-rgt-identity46.2
Applied rewrites46.2%
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.f6452.9
Applied rewrites52.9%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
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.f6492.7
Applied rewrites92.7%
Taylor expanded in y around 0
Applied rewrites38.9%
*-rgt-identity38.9
Applied rewrites38.9%
herbie shell --seed 2024214
(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))))