
(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 7 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 -1.6e+143) (not (<= x 5.6e+59))) (* x (cos y)) (fma z (- (sin y)) x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+143) || !(x <= 5.6e+59)) {
tmp = x * cos(y);
} else {
tmp = fma(z, -sin(y), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+143) || !(x <= 5.6e+59)) tmp = Float64(x * cos(y)); else tmp = fma(z, Float64(-sin(y)), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+143], N[Not[LessEqual[x, 5.6e+59]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision]) + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+143} \lor \neg \left(x \leq 5.6 \cdot 10^{+59}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, -\sin y, x\right)\\
\end{array}
\end{array}
if x < -1.60000000000000008e143 or 5.5999999999999996e59 < x 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%
Taylor expanded in z around 0 88.0%
if -1.60000000000000008e143 < x < 5.5999999999999996e59Initial 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%
Taylor expanded in y around 0 85.9%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.8e+142) (not (<= x 3e+60))) (* x (cos y)) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e+142) || !(x <= 3e+60)) {
tmp = x * cos(y);
} else {
tmp = x - (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 <= (-7.8d+142)) .or. (.not. (x <= 3d+60))) then
tmp = x * cos(y)
else
tmp = x - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e+142) || !(x <= 3e+60)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.8e+142) or not (x <= 3e+60): tmp = x * math.cos(y) else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.8e+142) || !(x <= 3e+60)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.8e+142) || ~((x <= 3e+60))) tmp = x * cos(y); else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.8e+142], N[Not[LessEqual[x, 3e+60]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{+142} \lor \neg \left(x \leq 3 \cdot 10^{+60}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -7.8000000000000001e142 or 2.9999999999999998e60 < x 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%
Taylor expanded in z around 0 88.0%
if -7.8000000000000001e142 < x < 2.9999999999999998e60Initial program 99.8%
Taylor expanded in y around 0 85.9%
Final simplification86.7%
(FPCore (x y z)
:precision binary64
(if (<= y -0.046)
(* x (cos y))
(if (<= y 1.0)
(+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* y z)))) z)))
(* (sin y) (- z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.046) {
tmp = x * cos(y);
} else if (y <= 1.0) {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
} else {
tmp = sin(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 (y <= (-0.046d0)) then
tmp = x * cos(y)
else if (y <= 1.0d0) then
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (y * z)))) - z))
else
tmp = sin(y) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.046) {
tmp = x * Math.cos(y);
} else if (y <= 1.0) {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.046: tmp = x * math.cos(y) elif y <= 1.0: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.046) tmp = Float64(x * cos(y)); elseif (y <= 1.0) tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(y * z)))) - z))); else tmp = Float64(sin(y) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.046) tmp = x * cos(y); elseif (y <= 1.0) tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.046], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.046:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(y \cdot z\right)\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -0.045999999999999999Initial program 99.5%
cancel-sign-sub-inv99.5%
+-commutative99.5%
distribute-lft-neg-out99.5%
distribute-rgt-neg-in99.5%
sin-neg99.5%
fma-define99.5%
sin-neg99.5%
Simplified99.5%
Taylor expanded in z around 0 56.9%
if -0.045999999999999999 < y < 1Initial program 100.0%
Taylor expanded in y around 0 99.4%
if 1 < y Initial program 99.7%
cancel-sign-sub-inv99.7%
+-commutative99.7%
distribute-lft-neg-out99.7%
distribute-rgt-neg-in99.7%
sin-neg99.7%
fma-define99.7%
sin-neg99.7%
Simplified99.7%
Taylor expanded in z around inf 53.1%
neg-mul-153.1%
distribute-rgt-neg-in53.1%
Simplified53.1%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.04) (not (<= y 0.08))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* y z)))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 0.08)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - 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.04d0)) .or. (.not. (y <= 0.08d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (y * z)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 0.08)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.04) or not (y <= 0.08): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.04) || !(y <= 0.08)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(y * z)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.04) || ~((y <= 0.08))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.04], N[Not[LessEqual[y, 0.08]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.04 \lor \neg \left(y \leq 0.08\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(y \cdot z\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -0.0400000000000000008 or 0.0800000000000000017 < y Initial program 99.6%
cancel-sign-sub-inv99.6%
+-commutative99.6%
distribute-lft-neg-out99.6%
distribute-rgt-neg-in99.6%
sin-neg99.6%
fma-define99.6%
sin-neg99.6%
Simplified99.6%
Taylor expanded in z around 0 51.9%
if -0.0400000000000000008 < y < 0.0800000000000000017Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification74.1%
(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.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%
Taylor expanded in y around 0 49.1%
mul-1-neg49.1%
unsub-neg49.1%
Simplified49.1%
(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%
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%
Taylor expanded in z around inf 89.9%
+-commutative89.9%
mul-1-neg89.9%
sub-neg89.9%
*-commutative89.9%
associate-/l*89.9%
Simplified89.9%
Taylor expanded in y around 0 36.8%
herbie shell --seed 2024111
(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))))