
(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 (- (* 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
(let* ((t_0 (* (- z) (sin y))) (t_1 (* (cos y) x)))
(if (<= y -4.05e+96)
t_0
(if (<= y -0.034)
t_1
(if (<= y 2.5e-12)
(fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
(if (<= y 6e+120) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = -z * sin(y);
double t_1 = cos(y) * x;
double tmp;
if (y <= -4.05e+96) {
tmp = t_0;
} else if (y <= -0.034) {
tmp = t_1;
} else if (y <= 2.5e-12) {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
} else if (y <= 6e+120) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-z) * sin(y)) t_1 = Float64(cos(y) * x) tmp = 0.0 if (y <= -4.05e+96) tmp = t_0; elseif (y <= -0.034) tmp = t_1; elseif (y <= 2.5e-12) tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); elseif (y <= 6e+120) tmp = t_1; else tmp = t_0; 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, -4.05e+96], t$95$0, If[LessEqual[y, -0.034], t$95$1, If[LessEqual[y, 2.5e-12], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[y, 6e+120], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot \sin y\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -4.05 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.034:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+120}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.0500000000000001e96 or 6e120 < y Initial 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.f6462.0
Applied rewrites62.0%
if -4.0500000000000001e96 < y < -0.034000000000000002 or 2.49999999999999985e-12 < y < 6e120Initial program 99.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6455.2
Applied rewrites55.2%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
associate-*l*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-cos.f6467.3
Applied rewrites67.3%
if -0.034000000000000002 < y < 2.49999999999999985e-12Initial 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-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e+56) (not (<= x 2.2e+165))) (* (cos y) x) (- (* x 1.0) (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+56) || !(x <= 2.2e+165)) {
tmp = cos(y) * x;
} else {
tmp = (x * 1.0) - (z * sin(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.9d+56)) .or. (.not. (x <= 2.2d+165))) then
tmp = cos(y) * x
else
tmp = (x * 1.0d0) - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+56) || !(x <= 2.2e+165)) {
tmp = Math.cos(y) * x;
} else {
tmp = (x * 1.0) - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e+56) or not (x <= 2.2e+165): tmp = math.cos(y) * x else: tmp = (x * 1.0) - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e+56) || !(x <= 2.2e+165)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.9e+56) || ~((x <= 2.2e+165))) tmp = cos(y) * x; else tmp = (x * 1.0) - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e+56], N[Not[LessEqual[x, 2.2e+165]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+56} \lor \neg \left(x \leq 2.2 \cdot 10^{+165}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\end{array}
\end{array}
if x < -3.89999999999999994e56 or 2.1999999999999999e165 < x Initial program 99.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6449.1
Applied rewrites49.1%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
associate-*l*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-cos.f6491.6
Applied rewrites91.6%
if -3.89999999999999994e56 < x < 2.1999999999999999e165Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites86.0%
Final simplification87.7%
(FPCore (x y z)
:precision binary64
(if (<= x -3.9e+56)
(* (cos y) x)
(if (<= x 1.55e+146)
(- (* x 1.0) (* z (sin y)))
(- (* x (cos y)) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.9e+56) {
tmp = cos(y) * x;
} else if (x <= 1.55e+146) {
tmp = (x * 1.0) - (z * sin(y));
} else {
tmp = (x * cos(y)) - (z * 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.9d+56)) then
tmp = cos(y) * x
else if (x <= 1.55d+146) then
tmp = (x * 1.0d0) - (z * sin(y))
else
tmp = (x * cos(y)) - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.9e+56) {
tmp = Math.cos(y) * x;
} else if (x <= 1.55e+146) {
tmp = (x * 1.0) - (z * Math.sin(y));
} else {
tmp = (x * Math.cos(y)) - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.9e+56: tmp = math.cos(y) * x elif x <= 1.55e+146: tmp = (x * 1.0) - (z * math.sin(y)) else: tmp = (x * math.cos(y)) - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.9e+56) tmp = Float64(cos(y) * x); elseif (x <= 1.55e+146) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); else tmp = Float64(Float64(x * cos(y)) - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.9e+56) tmp = cos(y) * x; elseif (x <= 1.55e+146) tmp = (x * 1.0) - (z * sin(y)); else tmp = (x * cos(y)) - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.9e+56], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.55e+146], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+56}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+146}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y - z \cdot y\\
\end{array}
\end{array}
if x < -3.89999999999999994e56Initial program 99.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6432.5
Applied rewrites32.5%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
associate-*l*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-cos.f6489.5
Applied rewrites89.5%
if -3.89999999999999994e56 < x < 1.5500000000000001e146Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites86.4%
if 1.5500000000000001e146 < x Initial program 99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6492.8
Applied rewrites92.8%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.034) (not (<= y 2.5e-12))) (* (cos y) x) (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.034) || !(y <= 2.5e-12)) {
tmp = cos(y) * x;
} else {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.034) || !(y <= 2.5e-12)) tmp = Float64(cos(y) * x); else tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.034], N[Not[LessEqual[y, 2.5e-12]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.034 \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\end{array}
\end{array}
if y < -0.034000000000000002 or 2.49999999999999985e-12 < y Initial program 99.7%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f6454.0
Applied rewrites54.0%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
associate-*l*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-cos.f6450.2
Applied rewrites50.2%
if -0.034000000000000002 < y < 2.49999999999999985e-12Initial 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-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e+118) (not (<= z 3.7e+111))) (* (- y) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e+118) || !(z <= 3.7e+111)) {
tmp = -y * z;
} else {
tmp = 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 <= (-2d+118)) .or. (.not. (z <= 3.7d+111))) then
tmp = -y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2e+118) || !(z <= 3.7e+111)) {
tmp = -y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e+118) or not (z <= 3.7e+111): tmp = -y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e+118) || !(z <= 3.7e+111)) tmp = Float64(Float64(-y) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2e+118) || ~((z <= 3.7e+111))) tmp = -y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e+118], N[Not[LessEqual[z, 3.7e+111]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+118} \lor \neg \left(z \leq 3.7 \cdot 10^{+111}\right):\\
\;\;\;\;\left(-y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.99999999999999993e118 or 3.7000000000000003e111 < z 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.f6450.8
Applied rewrites50.8%
Taylor expanded in x around 0
Applied rewrites35.8%
if -1.99999999999999993e118 < z < 3.7000000000000003e111Initial 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.f6455.3
Applied rewrites55.3%
Applied rewrites31.6%
Taylor expanded in x around -inf
Applied rewrites51.7%
Final simplification46.7%
(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.f6453.9
Applied rewrites53.9%
(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.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.f6453.9
Applied rewrites53.9%
Applied rewrites29.1%
Taylor expanded in x around -inf
Applied rewrites41.0%
herbie shell --seed 2024326
(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))))