
(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.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -1e+260)
(* x (sin y))
(if (<= y -0.001)
t_0
(if (<= y 0.0029)
(fma (fma (* (* x y) -0.16666666666666666) y x) y z)
t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -1e+260) {
tmp = x * sin(y);
} else if (y <= -0.001) {
tmp = t_0;
} else if (y <= 0.0029) {
tmp = fma(fma(((x * y) * -0.16666666666666666), y, x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -1e+260) tmp = Float64(x * sin(y)); elseif (y <= -0.001) tmp = t_0; elseif (y <= 0.0029) tmp = fma(fma(Float64(Float64(x * y) * -0.16666666666666666), y, x), y, z); 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[y, -1e+260], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -0.001], t$95$0, If[LessEqual[y, 0.0029], N[(N[(N[(N[(x * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -1 \cdot 10^{+260}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;y \leq -0.001:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0029:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot y\right) \cdot -0.16666666666666666, y, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.00000000000000007e260Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites82.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
unpow1N/A
sqr-powN/A
lower-fma.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6453.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f6453.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
Taylor expanded in x around -inf
*-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-sin.f6482.2
Applied rewrites82.2%
if -1.00000000000000007e260 < y < -1e-3 or 0.0029 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6460.6
Applied rewrites60.6%
if -1e-3 < y < 0.0029Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites99.9%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -2.3e+18) t_0 (if (<= z 6.2e+31) (fma 1.0 z (* x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.3e+18) {
tmp = t_0;
} else if (z <= 6.2e+31) {
tmp = fma(1.0, z, (x * sin(y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.3e+18) tmp = t_0; elseif (z <= 6.2e+31) 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[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.3e+18], t$95$0, If[LessEqual[z, 6.2e+31], N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.3 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+31}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.3e18 or 6.2000000000000004e31 < z Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6493.0
Applied rewrites93.0%
if -2.3e18 < z < 6.2000000000000004e31Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites92.7%
Final simplification92.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.001)
t_0
(if (<= y 0.0029)
(fma (fma (* (* x y) -0.16666666666666666) y x) y z)
t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.001) {
tmp = t_0;
} else if (y <= 0.0029) {
tmp = fma(fma(((x * y) * -0.16666666666666666), y, x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.001) tmp = t_0; elseif (y <= 0.0029) tmp = fma(fma(Float64(Float64(x * y) * -0.16666666666666666), y, x), y, z); 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[y, -0.001], t$95$0, If[LessEqual[y, 0.0029], N[(N[(N[(N[(x * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.001:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0029:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot y\right) \cdot -0.16666666666666666, y, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1e-3 or 0.0029 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6457.8
Applied rewrites57.8%
if -1e-3 < y < 0.0029Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites99.9%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.48e+228) (* x y) (if (<= x 8.6e+203) (* 1.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.48e+228) {
tmp = x * y;
} else if (x <= 8.6e+203) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
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.48d+228)) then
tmp = x * y
else if (x <= 8.6d+203) then
tmp = 1.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.48e+228) {
tmp = x * y;
} else if (x <= 8.6e+203) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.48e+228: tmp = x * y elif x <= 8.6e+203: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.48e+228) tmp = Float64(x * y); elseif (x <= 8.6e+203) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.48e+228) tmp = x * y; elseif (x <= 8.6e+203) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.48e+228], N[(x * y), $MachinePrecision], If[LessEqual[x, 8.6e+203], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.48 \cdot 10^{+228}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{+203}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.48e228 or 8.6e203 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6461.5
Applied rewrites61.5%
Taylor expanded in x around inf
Applied rewrites50.9%
if -1.48e228 < x < 8.6e203Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
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.f6495.5
Applied rewrites95.5%
Taylor expanded in y around 0
Applied rewrites50.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.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6458.9
Applied rewrites58.9%
(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.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6458.9
Applied rewrites58.9%
Taylor expanded in x around inf
Applied rewrites16.8%
herbie shell --seed 2024308
(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))))