
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) x (* z (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* (cos y) x)))
(if (<= y -1.02e+27)
t_1
(if (<= y 0.075)
(fma (fma -0.5 (* y y) 1.0) x t_0)
(if (<= y 1.9e+205) t_0 t_1)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = cos(y) * x;
double tmp;
if (y <= -1.02e+27) {
tmp = t_1;
} else if (y <= 0.075) {
tmp = fma(fma(-0.5, (y * y), 1.0), x, t_0);
} else if (y <= 1.9e+205) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(cos(y) * x) tmp = 0.0 if (y <= -1.02e+27) tmp = t_1; elseif (y <= 0.075) tmp = fma(fma(-0.5, Float64(y * y), 1.0), x, t_0); elseif (y <= 1.9e+205) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -1.02e+27], t$95$1, If[LessEqual[y, 0.075], N[(N[(-0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x + t$95$0), $MachinePrecision], If[LessEqual[y, 1.9e+205], t$95$0, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -1.02 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.075:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5, y \cdot y, 1\right), x, t\_0\right)\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+205}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.0199999999999999e27 or 1.9e205 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6459.9
Applied rewrites59.9%
if -1.0199999999999999e27 < y < 0.0749999999999999972Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.3
Applied rewrites99.3%
if 0.0749999999999999972 < y < 1.9e205Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6459.1
Applied rewrites59.1%
Final simplification80.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -260.0)
t_0
(if (<= y 0.019)
(fma y (fma y (* x -0.5) z) x)
(if (<= y 1.9e+205) (* z (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -260.0) {
tmp = t_0;
} else if (y <= 0.019) {
tmp = fma(y, fma(y, (x * -0.5), z), x);
} else if (y <= 1.9e+205) {
tmp = z * sin(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -260.0) tmp = t_0; elseif (y <= 0.019) tmp = fma(y, fma(y, Float64(x * -0.5), z), x); elseif (y <= 1.9e+205) tmp = Float64(z * sin(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -260.0], t$95$0, If[LessEqual[y, 0.019], N[(y * N[(y * N[(x * -0.5), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 1.9e+205], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -260:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.019:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, x \cdot -0.5, z\right), x\right)\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+205}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -260 or 1.9e205 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6459.7
Applied rewrites59.7%
if -260 < y < 0.0189999999999999995Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
if 0.0189999999999999995 < y < 1.9e205Initial program 99.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sin.f6459.1
Applied rewrites59.1%
Final simplification80.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.55)
t_0
(if (<= y 0.75)
(fma
(fma -0.5 (* y y) 1.0)
x
(*
y
(fma
(* y y)
(fma
(* y y)
(* z (fma -0.0001984126984126984 (* y y) 0.008333333333333333))
(* z -0.16666666666666666))
z)))
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -0.55) {
tmp = t_0;
} else if (y <= 0.75) {
tmp = fma(fma(-0.5, (y * y), 1.0), x, (y * fma((y * y), fma((y * y), (z * fma(-0.0001984126984126984, (y * y), 0.008333333333333333)), (z * -0.16666666666666666)), z)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -0.55) tmp = t_0; elseif (y <= 0.75) tmp = fma(fma(-0.5, Float64(y * y), 1.0), x, Float64(y * fma(Float64(y * y), fma(Float64(y * y), Float64(z * fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333)), Float64(z * -0.16666666666666666)), z))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.55], t$95$0, If[LessEqual[y, 0.75], N[(N[(-0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(z * N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(z * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.55:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.75:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5, y \cdot y, 1\right), x, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), z \cdot -0.16666666666666666\right), z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.55000000000000004 or 0.75 < y Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6454.9
Applied rewrites54.9%
if -0.55000000000000004 < y < 0.75Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= z -9.6e+151) (* y z) (if (<= z 1.95e+174) (* x 1.0) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.6e+151) {
tmp = y * z;
} else if (z <= 1.95e+174) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
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 (z <= (-9.6d+151)) then
tmp = y * z
else if (z <= 1.95d+174) then
tmp = x * 1.0d0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.6e+151) {
tmp = y * z;
} else if (z <= 1.95e+174) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.6e+151: tmp = y * z elif z <= 1.95e+174: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.6e+151) tmp = Float64(y * z); elseif (z <= 1.95e+174) tmp = Float64(x * 1.0); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.6e+151) tmp = y * z; elseif (z <= 1.95e+174) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.6e+151], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.95e+174], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{+151}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+174}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -9.6000000000000004e151 or 1.9499999999999999e174 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6470.1
Applied rewrites70.1%
Taylor expanded in z around inf
Applied rewrites49.0%
if -9.6000000000000004e151 < z < 1.9499999999999999e174Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6474.5
Applied rewrites74.5%
Taylor expanded in y around 0
Applied rewrites45.9%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6454.2
Applied rewrites54.2%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6454.2
Applied rewrites54.2%
Taylor expanded in z around inf
Applied rewrites18.1%
herbie shell --seed 2024238
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))