
(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 8 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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.9%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(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 = (x * cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (- (* (sin y) z))))
(if (<= y -1.85e+233)
t_0
(if (<= y -0.038)
t_1
(if (<= y 900000.0)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
(if (<= y 3.1e+179) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = -(sin(y) * z);
double tmp;
if (y <= -1.85e+233) {
tmp = t_0;
} else if (y <= -0.038) {
tmp = t_1;
} else if (y <= 900000.0) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else if (y <= 3.1e+179) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(-Float64(sin(y) * z)) tmp = 0.0 if (y <= -1.85e+233) tmp = t_0; elseif (y <= -0.038) tmp = t_1; elseif (y <= 900000.0) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); elseif (y <= 3.1e+179) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])}, If[LessEqual[y, -1.85e+233], t$95$0, If[LessEqual[y, -0.038], t$95$1, If[LessEqual[y, 900000.0], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 3.1e+179], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := -\sin y \cdot z\\
\mathbf{if}\;y \leq -1.85 \cdot 10^{+233}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.038:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 900000:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+179}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8499999999999999e233 or 3.1e179 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6463.2
Applied rewrites63.2%
if -1.8499999999999999e233 < y < -0.0379999999999999991 or 9e5 < y < 3.1e179Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6470.5
Applied rewrites70.5%
if -0.0379999999999999991 < y < 9e5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.3
Applied rewrites99.3%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (* (sin y) z)))) (if (<= z -1.6e+35) t_0 (if (<= z 3.1e-43) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (sin(y) * z);
double tmp;
if (z <= -1.6e+35) {
tmp = t_0;
} else if (z <= 3.1e-43) {
tmp = x * cos(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 = x - (sin(y) * z)
if (z <= (-1.6d+35)) then
tmp = t_0
else if (z <= 3.1d-43) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (Math.sin(y) * z);
double tmp;
if (z <= -1.6e+35) {
tmp = t_0;
} else if (z <= 3.1e-43) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (math.sin(y) * z) tmp = 0 if z <= -1.6e+35: tmp = t_0 elif z <= 3.1e-43: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(sin(y) * z)) tmp = 0.0 if (z <= -1.6e+35) tmp = t_0; elseif (z <= 3.1e-43) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (sin(y) * z); tmp = 0.0; if (z <= -1.6e+35) tmp = t_0; elseif (z <= 3.1e-43) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.6e+35], t$95$0, If[LessEqual[z, 3.1e-43], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \sin y \cdot z\\
\mathbf{if}\;z \leq -1.6 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{-43}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.59999999999999991e35 or 3.0999999999999999e-43 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites89.9%
if -1.59999999999999991e35 < z < 3.0999999999999999e-43Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6487.2
Applied rewrites87.2%
Final simplification88.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.24)
t_0
(if (<= y 0.07)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.24) {
tmp = t_0;
} else if (y <= 0.07) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.24) tmp = t_0; elseif (y <= 0.07) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.24], t$95$0, If[LessEqual[y, 0.07], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.24:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.07:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.23999999999999999 or 0.070000000000000007 < y Initial program 99.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6444.2
Applied rewrites44.2%
if -0.23999999999999999 < y < 0.070000000000000007Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= z 6.8e+97) x (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 6.8e+97) {
tmp = x;
} 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 <= 6.8d+97) then
tmp = x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6.8e+97) {
tmp = x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6.8e+97: tmp = x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6.8e+97) tmp = x; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6.8e+97) tmp = x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6.8e+97], x, N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.8 \cdot 10^{+97}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 6.8000000000000002e97Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6464.0
Applied rewrites64.0%
Taylor expanded in y around 0
Applied rewrites42.5%
*-rgt-identity42.5
Applied rewrites42.5%
if 6.8000000000000002e97 < z Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6458.1
Applied rewrites58.1%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f6439.7
Applied rewrites39.7%
Final simplification41.9%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 = x - (y * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.0
Applied rewrites52.0%
Final simplification52.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6456.6
Applied rewrites56.6%
Taylor expanded in y around 0
Applied rewrites37.9%
*-rgt-identity37.9
Applied rewrites37.9%
herbie shell --seed 2024214
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))