
(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 (if (or (<= x -5.8e+119) (not (<= x 3.8e+33))) (* (cos y) x) (fma (sin y) (- z) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+119) || !(x <= 3.8e+33)) {
tmp = cos(y) * x;
} else {
tmp = fma(sin(y), -z, (1.0 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e+119) || !(x <= 3.8e+33)) tmp = Float64(cos(y) * x); else tmp = fma(sin(y), Float64(-z), Float64(1.0 * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e+119], N[Not[LessEqual[x, 3.8e+33]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+119} \lor \neg \left(x \leq 3.8 \cdot 10^{+33}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\
\end{array}
\end{array}
if x < -5.80000000000000014e119 or 3.80000000000000002e33 < x Initial 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.f6452.7
Applied rewrites52.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.0
Applied rewrites91.0%
if -5.80000000000000014e119 < x < 3.80000000000000002e33Initial program 99.8%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites88.4%
lift--.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
Applied rewrites88.4%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e+119) (not (<= x 3.8e+33))) (* (cos y) x) (- (* x 1.0) (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e+119) || !(x <= 3.8e+33)) {
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 <= (-5.8d+119)) .or. (.not. (x <= 3.8d+33))) 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 <= -5.8e+119) || !(x <= 3.8e+33)) {
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 <= -5.8e+119) or not (x <= 3.8e+33): 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 <= -5.8e+119) || !(x <= 3.8e+33)) 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 <= -5.8e+119) || ~((x <= 3.8e+33))) 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, -5.8e+119], N[Not[LessEqual[x, 3.8e+33]], $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 -5.8 \cdot 10^{+119} \lor \neg \left(x \leq 3.8 \cdot 10^{+33}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\end{array}
\end{array}
if x < -5.80000000000000014e119 or 3.80000000000000002e33 < x Initial 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.f6452.7
Applied rewrites52.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.0
Applied rewrites91.0%
if -5.80000000000000014e119 < x < 3.80000000000000002e33Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites88.4%
Final simplification89.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -2.45e+234)
t_0
(if (<= y -1.15e-7)
(* (- z) (sin y))
(if (<= y 8.5e-17) (fma (- z) y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -2.45e+234) {
tmp = t_0;
} else if (y <= -1.15e-7) {
tmp = -z * sin(y);
} else if (y <= 8.5e-17) {
tmp = fma(-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 <= -2.45e+234) tmp = t_0; elseif (y <= -1.15e-7) tmp = Float64(Float64(-z) * sin(y)); elseif (y <= 8.5e-17) tmp = fma(Float64(-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, -2.45e+234], t$95$0, If[LessEqual[y, -1.15e-7], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.5e-17], N[((-z) * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -2.45 \cdot 10^{+234}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-7}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.44999999999999995e234 or 8.5e-17 < y Initial 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.f6452.5
Applied rewrites52.5%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6468.5
Applied rewrites68.5%
if -2.44999999999999995e234 < y < -1.14999999999999997e-7Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6464.7
Applied rewrites64.7%
if -1.14999999999999997e-7 < y < 8.5e-17Initial 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 simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -540.0) (not (<= y 8.5e-17))) (* (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 <= -540.0) || !(y <= 8.5e-17)) {
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 <= -540.0) || !(y <= 8.5e-17)) 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, -540.0], N[Not[LessEqual[y, 8.5e-17]], $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 -540 \lor \neg \left(y \leq 8.5 \cdot 10^{-17}\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 < -540 or 8.5e-17 < 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.f6451.2
Applied rewrites51.2%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6454.5
Applied rewrites54.5%
if -540 < y < 8.5e-17Initial 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-*.f6499.3
Applied rewrites99.3%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-167) (not (<= x 2.5e-24))) (* 1.0 x) (* (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-167) || !(x <= 2.5e-24)) {
tmp = 1.0 * 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 ((x <= (-9d-167)) .or. (.not. (x <= 2.5d-24))) then
tmp = 1.0d0 * x
else
tmp = -y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-167) || !(x <= 2.5e-24)) {
tmp = 1.0 * x;
} else {
tmp = -y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-167) or not (x <= 2.5e-24): tmp = 1.0 * x else: tmp = -y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-167) || !(x <= 2.5e-24)) tmp = Float64(1.0 * x); else tmp = Float64(Float64(-y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e-167) || ~((x <= 2.5e-24))) tmp = 1.0 * x; else tmp = -y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-167], N[Not[LessEqual[x, 2.5e-24]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[((-y) * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-167} \lor \neg \left(x \leq 2.5 \cdot 10^{-24}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\end{array}
\end{array}
if x < -9.0000000000000002e-167 or 2.4999999999999999e-24 < x 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.f6451.3
Applied rewrites51.3%
Taylor expanded in x around inf
Applied rewrites51.3%
Taylor expanded in x around inf
Applied rewrites44.7%
if -9.0000000000000002e-167 < x < 2.4999999999999999e-24Initial 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.6
Applied rewrites53.6%
Taylor expanded in x around 0
Applied rewrites38.3%
Final simplification42.4%
(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.f6452.1
Applied rewrites52.1%
Final simplification52.1%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot 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.f6452.1
Applied rewrites52.1%
Taylor expanded in x around inf
Applied rewrites49.4%
Taylor expanded in x around inf
Applied rewrites35.6%
Final simplification35.6%
herbie shell --seed 2024339
(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))))