
(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 6 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 (- (* 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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.8e-143) (not (<= z 1.52e-99))) (- (* x 1.0) (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-143) || !(z <= 1.52e-99)) {
tmp = (x * 1.0) - (z * sin(y));
} else {
tmp = cos(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 ((z <= (-7.8d-143)) .or. (.not. (z <= 1.52d-99))) then
tmp = (x * 1.0d0) - (z * sin(y))
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-143) || !(z <= 1.52e-99)) {
tmp = (x * 1.0) - (z * Math.sin(y));
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.8e-143) or not (z <= 1.52e-99): tmp = (x * 1.0) - (z * math.sin(y)) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.8e-143) || !(z <= 1.52e-99)) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.8e-143) || ~((z <= 1.52e-99))) tmp = (x * 1.0) - (z * sin(y)); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.8e-143], N[Not[LessEqual[z, 1.52e-99]], $MachinePrecision]], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-143} \lor \neg \left(z \leq 1.52 \cdot 10^{-99}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -7.80000000000000007e-143 or 1.51999999999999999e-99 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites85.6%
if -7.80000000000000007e-143 < z < 1.51999999999999999e-99Initial program 99.8%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites94.8%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -1.65e+171)
t_0
(if (<= y -0.84)
(* (- z) (sin y))
(if (<= y 8e-20) (fma (- (* (* y x) -0.5) z) y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -1.65e+171) {
tmp = t_0;
} else if (y <= -0.84) {
tmp = -z * sin(y);
} else if (y <= 8e-20) {
tmp = fma((((y * x) * -0.5) - z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -1.65e+171) tmp = t_0; elseif (y <= -0.84) tmp = Float64(Float64(-z) * sin(y)); elseif (y <= 8e-20) tmp = fma(Float64(Float64(Float64(y * x) * -0.5) - z), y, x); 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, -1.65e+171], t$95$0, If[LessEqual[y, -0.84], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e-20], N[(N[(N[(N[(y * x), $MachinePrecision] * -0.5), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.84:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot x\right) \cdot -0.5 - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.64999999999999996e171 or 7.99999999999999956e-20 < y Initial program 99.7%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites92.0%
Taylor expanded in x around inf
Applied rewrites64.5%
if -1.64999999999999996e171 < y < -0.839999999999999969Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6460.6
Applied rewrites60.6%
if -0.839999999999999969 < y < 7.99999999999999956e-20Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6498.9
Applied rewrites98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.75e-5) (not (<= y 8e-20))) (* (cos y) x) (fma (- z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.75e-5) || !(y <= 8e-20)) {
tmp = cos(y) * x;
} else {
tmp = fma(-z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.75e-5) || !(y <= 8e-20)) tmp = Float64(cos(y) * x); else tmp = fma(Float64(-z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.75e-5], N[Not[LessEqual[y, 8e-20]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.75 \cdot 10^{-5} \lor \neg \left(y \leq 8 \cdot 10^{-20}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\
\end{array}
\end{array}
if y < -2.7500000000000001e-5 or 7.99999999999999956e-20 < y Initial program 99.7%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites89.4%
Taylor expanded in x around inf
Applied rewrites57.3%
if -2.7500000000000001e-5 < y < 7.99999999999999956e-20Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification78.5%
(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(Float64(-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
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6454.0
Applied rewrites54.0%
(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(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}
\\
\left(-y\right) \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6454.0
Applied rewrites54.0%
Taylor expanded in x around 0
Applied rewrites17.4%
herbie shell --seed 2024332
(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))))