
(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 (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial 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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -9.5e+123)
t_0
(if (<= y -0.68)
t_1
(if (<= y 0.0076)
(fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
(if (<= y 1.9e+48) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -9.5e+123) {
tmp = t_0;
} else if (y <= -0.68) {
tmp = t_1;
} else if (y <= 0.0076) {
tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
} else if (y <= 1.9e+48) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -9.5e+123) tmp = t_0; elseif (y <= -0.68) tmp = t_1; elseif (y <= 0.0076) tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, z); elseif (y <= 1.9e+48) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.5e+123], t$95$0, If[LessEqual[y, -0.68], t$95$1, If[LessEqual[y, 0.0076], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], If[LessEqual[y, 1.9e+48], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.68:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0076:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+48}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -9.4999999999999996e123 or 0.00759999999999999998 < y < 1.9e48Initial program 99.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6464.3
Applied rewrites64.3%
if -9.4999999999999996e123 < y < -0.680000000000000049 or 1.9e48 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6464.0
Applied rewrites64.0%
if -0.680000000000000049 < y < 0.00759999999999999998Initial 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.5
Applied rewrites99.5%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x (* 1.0 z)))) (if (<= x -8.2e-49) t_0 (if (<= x 5.2e-66) (* z (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), x, (1.0 * z));
double tmp;
if (x <= -8.2e-49) {
tmp = t_0;
} else if (x <= 5.2e-66) {
tmp = z * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), x, Float64(1.0 * z)) tmp = 0.0 if (x <= -8.2e-49) tmp = t_0; elseif (x <= 5.2e-66) tmp = Float64(z * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.2e-49], t$95$0, If[LessEqual[x, 5.2e-66], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{if}\;x \leq -8.2 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-66}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.2000000000000003e-49 or 5.1999999999999998e-66 < x Initial 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.6%
if -8.2000000000000003e-49 < x < 5.1999999999999998e-66Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.6
Applied rewrites91.6%
Final simplification90.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.019)
t_0
(if (<= y 0.0076) (fma (fma (* -0.5 y) z x) y z) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.019) {
tmp = t_0;
} else if (y <= 0.0076) {
tmp = fma(fma((-0.5 * y), z, 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.019) tmp = t_0; elseif (y <= 0.0076) tmp = fma(fma(Float64(-0.5 * y), z, 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.019], t$95$0, If[LessEqual[y, 0.0076], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + 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.019:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0076:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0189999999999999995 or 0.00759999999999999998 < y Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6448.2
Applied rewrites48.2%
if -0.0189999999999999995 < y < 0.00759999999999999998Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (<= x 3.4e+174) (* 1.0 z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.4e+174) {
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 <= 3.4d+174) 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 <= 3.4e+174) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.4e+174: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.4e+174) 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 <= 3.4e+174) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.4e+174], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.4 \cdot 10^{+174}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 3.4000000000000001e174Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6466.5
Applied rewrites66.5%
Taylor expanded in y around 0
Applied rewrites44.2%
if 3.4000000000000001e174 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6462.3
Applied rewrites62.3%
Taylor expanded in z around 0
Applied rewrites43.6%
Final simplification44.1%
(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.f6455.2
Applied rewrites55.2%
(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.f6455.2
Applied rewrites55.2%
Taylor expanded in z around 0
Applied rewrites18.0%
Final simplification18.0%
herbie shell --seed 2024256
(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))))