
(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 z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.8%
sin-neg99.8%
Simplified99.8%
(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 (<= y -4.5e+29)
(* z (- (sin y)))
(if (<= y 5.2e+34)
(- (* x (+ (+ (cos y) 1.0) -1.0)) (* z y))
(* x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+29) {
tmp = z * -sin(y);
} else if (y <= 5.2e+34) {
tmp = (x * ((cos(y) + 1.0) + -1.0)) - (z * y);
} else {
tmp = x * cos(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 (y <= (-4.5d+29)) then
tmp = z * -sin(y)
else if (y <= 5.2d+34) then
tmp = (x * ((cos(y) + 1.0d0) + (-1.0d0))) - (z * y)
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+29) {
tmp = z * -Math.sin(y);
} else if (y <= 5.2e+34) {
tmp = (x * ((Math.cos(y) + 1.0) + -1.0)) - (z * y);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+29: tmp = z * -math.sin(y) elif y <= 5.2e+34: tmp = (x * ((math.cos(y) + 1.0) + -1.0)) - (z * y) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+29) tmp = Float64(z * Float64(-sin(y))); elseif (y <= 5.2e+34) tmp = Float64(Float64(x * Float64(Float64(cos(y) + 1.0) + -1.0)) - Float64(z * y)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.5e+29) tmp = z * -sin(y); elseif (y <= 5.2e+34) tmp = (x * ((cos(y) + 1.0) + -1.0)) - (z * y); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+29], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], If[LessEqual[y, 5.2e+34], N[(N[(x * N[(N[(N[Cos[y], $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+29}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+34}:\\
\;\;\;\;x \cdot \left(\left(\cos y + 1\right) + -1\right) - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if y < -4.5000000000000002e29Initial program 99.7%
Taylor expanded in x around 0 57.6%
neg-mul-157.6%
*-commutative57.6%
distribute-rgt-neg-in57.6%
Simplified57.6%
if -4.5000000000000002e29 < y < 5.19999999999999995e34Initial program 99.9%
expm1-log1p-u99.9%
expm1-undefine99.9%
Applied egg-rr99.9%
expm1-define99.9%
Simplified99.9%
expm1-undefine99.9%
log1p-undefine99.9%
rem-exp-log99.9%
+-commutative99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 94.4%
*-commutative94.4%
Simplified94.4%
if 5.19999999999999995e34 < y Initial program 99.6%
Taylor expanded in x around inf 58.1%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e-55) (not (<= x 6.1e-158))) (* x (cos y)) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-55) || !(x <= 6.1e-158)) {
tmp = x * cos(y);
} else {
tmp = 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 <= (-1.6d-55)) .or. (.not. (x <= 6.1d-158))) then
tmp = x * cos(y)
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-55) || !(x <= 6.1e-158)) {
tmp = x * Math.cos(y);
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e-55) or not (x <= 6.1e-158): tmp = x * math.cos(y) else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e-55) || !(x <= 6.1e-158)) tmp = Float64(x * cos(y)); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e-55) || ~((x <= 6.1e-158))) tmp = x * cos(y); else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e-55], N[Not[LessEqual[x, 6.1e-158]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-55} \lor \neg \left(x \leq 6.1 \cdot 10^{-158}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -1.6000000000000001e-55 or 6.0999999999999998e-158 < x Initial program 99.8%
Taylor expanded in x around inf 80.5%
if -1.6000000000000001e-55 < x < 6.0999999999999998e-158Initial program 99.8%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
*-commutative75.9%
distribute-rgt-neg-in75.9%
Simplified75.9%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0112) (not (<= y 1350.0))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* (* z y) 0.16666666666666666))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0112) || !(y <= 1350.0)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - 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 ((y <= (-0.0112d0)) .or. (.not. (y <= 1350.0d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + ((z * y) * 0.16666666666666666d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0112) || !(y <= 1350.0)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0112) or not (y <= 1350.0): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0112) || !(y <= 1350.0)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(Float64(z * y) * 0.16666666666666666))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0112) || ~((y <= 1350.0))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0112], N[Not[LessEqual[y, 1350.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(N[(z * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0112 \lor \neg \left(y \leq 1350\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + \left(z \cdot y\right) \cdot 0.16666666666666666\right) - z\right)\\
\end{array}
\end{array}
if y < -0.0111999999999999999 or 1350 < y Initial program 99.7%
Taylor expanded in x around inf 55.9%
if -0.0111999999999999999 < y < 1350Initial program 100.0%
Taylor expanded in y around 0 98.7%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= x -4.8e-58) x (if (<= x 7.5e-201) (* z (- y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-58) {
tmp = x;
} else if (x <= 7.5e-201) {
tmp = z * -y;
} 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 (x <= (-4.8d-58)) then
tmp = x
else if (x <= 7.5d-201) then
tmp = z * -y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-58) {
tmp = x;
} else if (x <= 7.5e-201) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e-58: tmp = x elif x <= 7.5e-201: tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e-58) tmp = x; elseif (x <= 7.5e-201) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e-58) tmp = x; elseif (x <= 7.5e-201) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e-58], x, If[LessEqual[x, 7.5e-201], N[(z * (-y)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-58}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-201}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -4.8000000000000001e-58 or 7.49999999999999987e-201 < x Initial program 99.8%
Taylor expanded in y around 0 48.8%
if -4.8000000000000001e-58 < x < 7.49999999999999987e-201Initial program 99.8%
Taylor expanded in y around 0 53.6%
mul-1-neg53.6%
unsub-neg53.6%
*-commutative53.6%
Simplified53.6%
Taylor expanded in x around 0 41.7%
associate-*r*41.7%
neg-mul-141.7%
*-commutative41.7%
Simplified41.7%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (z * 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 - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 54.2%
mul-1-neg54.2%
unsub-neg54.2%
*-commutative54.2%
Simplified54.2%
(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 38.5%
herbie shell --seed 2024170
(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))))