
(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 10 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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e+158) (not (<= x 4.5e-62))) (* x (cos y)) (fma (sin y) (- z) x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e+158) || !(x <= 4.5e-62)) {
tmp = x * cos(y);
} else {
tmp = fma(sin(y), -z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e+158) || !(x <= 4.5e-62)) tmp = Float64(x * cos(y)); else tmp = fma(sin(y), Float64(-z), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e+158], N[Not[LessEqual[x, 4.5e-62]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+158} \lor \neg \left(x \leq 4.5 \cdot 10^{-62}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, x\right)\\
\end{array}
\end{array}
if x < -3.59999999999999988e158 or 4.50000000000000018e-62 < x Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 87.8%
if -3.59999999999999988e158 < x < 4.50000000000000018e-62Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 90.0%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(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 * cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (<= y -3e+173)
(* x (cos y))
(if (or (<= y -0.0003) (not (<= y 0.0012)))
(* z (- (sin y)))
(- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+173) {
tmp = x * cos(y);
} else if ((y <= -0.0003) || !(y <= 0.0012)) {
tmp = z * -sin(y);
} else {
tmp = x - (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 <= (-3d+173)) then
tmp = x * cos(y)
else if ((y <= (-0.0003d0)) .or. (.not. (y <= 0.0012d0))) then
tmp = z * -sin(y)
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3e+173) {
tmp = x * Math.cos(y);
} else if ((y <= -0.0003) || !(y <= 0.0012)) {
tmp = z * -Math.sin(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+173: tmp = x * math.cos(y) elif (y <= -0.0003) or not (y <= 0.0012): tmp = z * -math.sin(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+173) tmp = Float64(x * cos(y)); elseif ((y <= -0.0003) || !(y <= 0.0012)) tmp = Float64(z * Float64(-sin(y))); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e+173) tmp = x * cos(y); elseif ((y <= -0.0003) || ~((y <= 0.0012))) tmp = z * -sin(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+173], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.0003], N[Not[LessEqual[y, 0.0012]], $MachinePrecision]], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+173}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq -0.0003 \lor \neg \left(y \leq 0.0012\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -2.9999999999999998e173Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in z around 0 62.6%
if -2.9999999999999998e173 < y < -2.99999999999999974e-4 or 0.00119999999999999989 < y Initial program 99.6%
Taylor expanded in x around 0 60.1%
associate-*r*60.1%
neg-mul-160.1%
Simplified60.1%
if -2.99999999999999974e-4 < y < 0.00119999999999999989Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification80.4%
(FPCore (x y z)
:precision binary64
(if (<= y -1.95e+171)
(* x (cos y))
(if (or (<= y -0.0015) (not (<= y 0.00035)))
(* z (- (sin y)))
(fma y (- z) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+171) {
tmp = x * cos(y);
} else if ((y <= -0.0015) || !(y <= 0.00035)) {
tmp = z * -sin(y);
} else {
tmp = fma(y, -z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+171) tmp = Float64(x * cos(y)); elseif ((y <= -0.0015) || !(y <= 0.00035)) tmp = Float64(z * Float64(-sin(y))); else tmp = fma(y, Float64(-z), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+171], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.0015], N[Not[LessEqual[y, 0.00035]], $MachinePrecision]], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], N[(y * (-z) + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+171}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq -0.0015 \lor \neg \left(y \leq 0.00035\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x\right)\\
\end{array}
\end{array}
if y < -1.95e171Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in z around 0 62.6%
if -1.95e171 < y < -0.0015 or 3.49999999999999996e-4 < y Initial program 99.6%
Taylor expanded in x around 0 60.1%
associate-*r*60.1%
neg-mul-160.1%
Simplified60.1%
if -0.0015 < y < 3.49999999999999996e-4Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 100.0%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e+160) (not (<= x 6.5e-61))) (* x (cos y)) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+160) || !(x <= 6.5e-61)) {
tmp = x * cos(y);
} else {
tmp = x - (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 ((x <= (-2d+160)) .or. (.not. (x <= 6.5d-61))) then
tmp = x * cos(y)
else
tmp = x - (sin(y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+160) || !(x <= 6.5e-61)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+160) or not (x <= 6.5e-61): tmp = x * math.cos(y) else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+160) || !(x <= 6.5e-61)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e+160) || ~((x <= 6.5e-61))) tmp = x * cos(y); else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+160], N[Not[LessEqual[x, 6.5e-61]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+160} \lor \neg \left(x \leq 6.5 \cdot 10^{-61}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -2.00000000000000001e160 or 6.4999999999999994e-61 < x Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 87.8%
if -2.00000000000000001e160 < x < 6.4999999999999994e-61Initial program 99.8%
Taylor expanded in y around 0 90.0%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0014) (not (<= y 0.49))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0014) || !(y <= 0.49)) {
tmp = x * cos(y);
} else {
tmp = x - (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.0014d0)) .or. (.not. (y <= 0.49d0))) then
tmp = x * cos(y)
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0014) || !(y <= 0.49)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0014) or not (y <= 0.49): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0014) || !(y <= 0.49)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0014) || ~((y <= 0.49))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0014], N[Not[LessEqual[y, 0.49]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0014 \lor \neg \left(y \leq 0.49\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -0.00139999999999999999 or 0.48999999999999999 < y Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 46.6%
if -0.00139999999999999999 < y < 0.48999999999999999Initial program 100.0%
Taylor expanded in y around 0 99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (<= z 1.45e+168) x (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.45e+168) {
tmp = 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 (z <= 1.45d+168) then
tmp = x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.45e+168) {
tmp = x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.45e+168: tmp = x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.45e+168) tmp = x; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.45e+168) tmp = x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.45e+168], x, N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+168}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.45e168Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 43.7%
if 1.45e168 < z Initial program 99.8%
Taylor expanded in y around 0 49.6%
+-commutative49.6%
mul-1-neg49.6%
unsub-neg49.6%
Simplified49.6%
Taylor expanded in x around 0 38.3%
associate-*r*38.3%
neg-mul-138.3%
Simplified38.3%
Final simplification42.9%
(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%
Taylor expanded in y around 0 53.2%
+-commutative53.2%
mul-1-neg53.2%
unsub-neg53.2%
Simplified53.2%
Final simplification53.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%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 39.6%
Final simplification39.6%
herbie shell --seed 2023199
(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))))