
(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 (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.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z))
(t_1 (* x (sin y)))
(t_2 (* z (fma t_1 (/ 1.0 z) 1.0))))
(if (<= z -1.06e+75)
t_0
(if (<= z -2.2e-259)
t_2
(if (<= z 3.95e-255) t_1 (if (<= z 4.2e-40) t_2 t_0))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = x * sin(y);
double t_2 = z * fma(t_1, (1.0 / z), 1.0);
double tmp;
if (z <= -1.06e+75) {
tmp = t_0;
} else if (z <= -2.2e-259) {
tmp = t_2;
} else if (z <= 3.95e-255) {
tmp = t_1;
} else if (z <= 4.2e-40) {
tmp = t_2;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = Float64(x * sin(y)) t_2 = Float64(z * fma(t_1, Float64(1.0 / z), 1.0)) tmp = 0.0 if (z <= -1.06e+75) tmp = t_0; elseif (z <= -2.2e-259) tmp = t_2; elseif (z <= 3.95e-255) tmp = t_1; elseif (z <= 4.2e-40) tmp = t_2; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(z * N[(t$95$1 * N[(1.0 / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.06e+75], t$95$0, If[LessEqual[z, -2.2e-259], t$95$2, If[LessEqual[z, 3.95e-255], t$95$1, If[LessEqual[z, 4.2e-40], t$95$2, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := x \cdot \sin y\\
t_2 := z \cdot \mathsf{fma}\left(t\_1, \frac{1}{z}, 1\right)\\
\mathbf{if}\;z \leq -1.06 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{-259}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;z \leq 3.95 \cdot 10^{-255}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-40}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.06e75 or 4.20000000000000036e-40 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6486.5
Applied rewrites86.5%
if -1.06e75 < z < -2.2000000000000001e-259 or 3.95000000000000005e-255 < z < 4.20000000000000036e-40Initial program 99.8%
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.f6488.3
Applied rewrites88.3%
Applied rewrites88.4%
Taylor expanded in y around 0
Applied rewrites84.1%
if -2.2000000000000001e-259 < z < 3.95000000000000005e-255Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6489.2
Applied rewrites89.2%
Final simplification85.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)) (t_1 (* z (fma x (/ (sin y) z) 1.0))))
(if (<= z -1.06e+75)
t_0
(if (<= z -2.2e-259)
t_1
(if (<= z 3.95e-255) (* x (sin y)) (if (<= z 4.2e-40) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = z * fma(x, (sin(y) / z), 1.0);
double tmp;
if (z <= -1.06e+75) {
tmp = t_0;
} else if (z <= -2.2e-259) {
tmp = t_1;
} else if (z <= 3.95e-255) {
tmp = x * sin(y);
} else if (z <= 4.2e-40) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = Float64(z * fma(x, Float64(sin(y) / z), 1.0)) tmp = 0.0 if (z <= -1.06e+75) tmp = t_0; elseif (z <= -2.2e-259) tmp = t_1; elseif (z <= 3.95e-255) tmp = Float64(x * sin(y)); elseif (z <= 4.2e-40) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.06e+75], t$95$0, If[LessEqual[z, -2.2e-259], t$95$1, If[LessEqual[z, 3.95e-255], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.2e-40], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := z \cdot \mathsf{fma}\left(x, \frac{\sin y}{z}, 1\right)\\
\mathbf{if}\;z \leq -1.06 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{-259}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.95 \cdot 10^{-255}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-40}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.06e75 or 4.20000000000000036e-40 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6486.5
Applied rewrites86.5%
if -1.06e75 < z < -2.2000000000000001e-259 or 3.95000000000000005e-255 < z < 4.20000000000000036e-40Initial program 99.8%
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.f6488.3
Applied rewrites88.3%
Taylor expanded in y around 0
Applied rewrites84.1%
if -2.2000000000000001e-259 < z < 3.95000000000000005e-255Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6489.2
Applied rewrites89.2%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cos y) z))) (if (<= z -1.15e-81) t_0 (if (<= z 1.75e-41) (* x (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (z <= -1.15e-81) {
tmp = t_0;
} else if (z <= 1.75e-41) {
tmp = x * sin(y);
} 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 = cos(y) * z
if (z <= (-1.15d-81)) then
tmp = t_0
else if (z <= 1.75d-41) then
tmp = x * sin(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double tmp;
if (z <= -1.15e-81) {
tmp = t_0;
} else if (z <= 1.75e-41) {
tmp = x * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z tmp = 0 if z <= -1.15e-81: tmp = t_0 elif z <= 1.75e-41: tmp = x * math.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.15e-81) tmp = t_0; elseif (z <= 1.75e-41) tmp = Float64(x * sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; tmp = 0.0; if (z <= -1.15e-81) tmp = t_0; elseif (z <= 1.75e-41) tmp = x * sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.15e-81], t$95$0, If[LessEqual[z, 1.75e-41], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;z \leq -1.15 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-41}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.14999999999999996e-81 or 1.75e-41 < z Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6484.8
Applied rewrites84.8%
if -1.14999999999999996e-81 < z < 1.75e-41Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6471.8
Applied rewrites71.8%
Final simplification79.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.0215)
t_0
(if (<= y 3.6e-22) (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.0215) {
tmp = t_0;
} else if (y <= 3.6e-22) {
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.0215) tmp = t_0; elseif (y <= 3.6e-22) 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.0215], t$95$0, If[LessEqual[y, 3.6e-22], 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.0215:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;\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.021499999999999998 or 3.5999999999999998e-22 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6453.2
Applied rewrites53.2%
if -0.021499999999999998 < y < 3.5999999999999998e-22Initial 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.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (<= x 1.06e+228) (* z 1.0) (* y x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.06e+228) {
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 <= 1.06d+228) 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 <= 1.06e+228) {
tmp = z * 1.0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.06e+228: tmp = z * 1.0 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.06e+228) 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 <= 1.06e+228) tmp = z * 1.0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.06e+228], N[(z * 1.0), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.06 \cdot 10^{+228}:\\
\;\;\;\;z \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < 1.06000000000000001e228Initial program 99.8%
Taylor expanded in x around 0
lower-*.f64N/A
lower-cos.f6466.8
Applied rewrites66.8%
Taylor expanded in y around 0
Applied rewrites44.4%
if 1.06000000000000001e228 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6437.8
Applied rewrites37.8%
Taylor expanded in y around inf
Applied rewrites37.8%
Final simplification44.0%
(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 (* 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.9
Applied rewrites52.9%
Taylor expanded in y around inf
Applied rewrites14.2%
Final simplification14.2%
herbie shell --seed 2024221
(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))))