
(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 (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 (- (* 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 (or (<= z -1.7e+140)
(not
(or (<= z 4.1e-13) (and (not (<= z 40000000.0)) (<= z 5.6e+74)))))
(* (sin y) (- z))
(* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+140) || !((z <= 4.1e-13) || (!(z <= 40000000.0) && (z <= 5.6e+74)))) {
tmp = sin(y) * -z;
} 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 ((z <= (-1.7d+140)) .or. (.not. (z <= 4.1d-13) .or. (.not. (z <= 40000000.0d0)) .and. (z <= 5.6d+74))) then
tmp = sin(y) * -z
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+140) || !((z <= 4.1e-13) || (!(z <= 40000000.0) && (z <= 5.6e+74)))) {
tmp = Math.sin(y) * -z;
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e+140) or not ((z <= 4.1e-13) or (not (z <= 40000000.0) and (z <= 5.6e+74))): tmp = math.sin(y) * -z else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e+140) || !((z <= 4.1e-13) || (!(z <= 40000000.0) && (z <= 5.6e+74)))) tmp = Float64(sin(y) * Float64(-z)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e+140) || ~(((z <= 4.1e-13) || (~((z <= 40000000.0)) && (z <= 5.6e+74))))) tmp = sin(y) * -z; else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e+140], N[Not[Or[LessEqual[z, 4.1e-13], And[N[Not[LessEqual[z, 40000000.0]], $MachinePrecision], LessEqual[z, 5.6e+74]]]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+140} \lor \neg \left(z \leq 4.1 \cdot 10^{-13} \lor \neg \left(z \leq 40000000\right) \land z \leq 5.6 \cdot 10^{+74}\right):\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.7e140 or 4.1000000000000002e-13 < z < 4e7 or 5.60000000000000003e74 < z Initial program 99.7%
Taylor expanded in x around 0 87.1%
associate-*r*87.1%
neg-mul-187.1%
Simplified87.1%
if -1.7e140 < z < 4.1000000000000002e-13 or 4e7 < z < 5.60000000000000003e74Initial program 99.9%
add-sqr-sqrt45.8%
pow245.8%
Applied egg-rr45.8%
Taylor expanded in z around 0 83.8%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-110) (not (<= z 1.45e-19))) (- x (* (sin y) z)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-110) || !(z <= 1.45e-19)) {
tmp = x - (sin(y) * z);
} 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 ((z <= (-8.5d-110)) .or. (.not. (z <= 1.45d-19))) then
tmp = x - (sin(y) * z)
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-110) || !(z <= 1.45e-19)) {
tmp = x - (Math.sin(y) * z);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-110) or not (z <= 1.45e-19): tmp = x - (math.sin(y) * z) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-110) || !(z <= 1.45e-19)) tmp = Float64(x - Float64(sin(y) * z)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-110) || ~((z <= 1.45e-19))) tmp = x - (sin(y) * z); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-110], N[Not[LessEqual[z, 1.45e-19]], $MachinePrecision]], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-110} \lor \neg \left(z \leq 1.45 \cdot 10^{-19}\right):\\
\;\;\;\;x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -8.50000000000000029e-110 or 1.45e-19 < z Initial program 99.8%
Taylor expanded in y around 0 87.6%
if -8.50000000000000029e-110 < z < 1.45e-19Initial program 99.8%
add-sqr-sqrt40.8%
pow240.8%
Applied egg-rr40.8%
Taylor expanded in z around 0 93.8%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00028) (not (<= y 0.0165))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00028) || !(y <= 0.0165)) {
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.00028d0)) .or. (.not. (y <= 0.0165d0))) 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.00028) || !(y <= 0.0165)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00028) or not (y <= 0.0165): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00028) || !(y <= 0.0165)) 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.00028) || ~((y <= 0.0165))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00028], N[Not[LessEqual[y, 0.0165]], $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.00028 \lor \neg \left(y \leq 0.0165\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -2.7999999999999998e-4 or 0.016500000000000001 < y Initial program 99.6%
add-sqr-sqrt45.2%
pow245.2%
Applied egg-rr45.2%
Taylor expanded in z around 0 52.6%
if -2.7999999999999998e-4 < y < 0.016500000000000001Initial program 100.0%
Taylor expanded in y around 0 99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.02e+154) (not (<= z 3.9e+33))) (* z (- y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.02e+154) || !(z <= 3.9e+33)) {
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 ((z <= (-2.02d+154)) .or. (.not. (z <= 3.9d+33))) 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 ((z <= -2.02e+154) || !(z <= 3.9e+33)) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.02e+154) or not (z <= 3.9e+33): tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.02e+154) || !(z <= 3.9e+33)) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.02e+154) || ~((z <= 3.9e+33))) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.02e+154], N[Not[LessEqual[z, 3.9e+33]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.02 \cdot 10^{+154} \lor \neg \left(z \leq 3.9 \cdot 10^{+33}\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.0200000000000001e154 or 3.9000000000000002e33 < z Initial program 99.7%
add-sqr-sqrt42.9%
pow242.9%
Applied egg-rr42.9%
Taylor expanded in x around 0 0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt83.6%
neg-mul-183.6%
*-commutative83.6%
Simplified83.6%
Taylor expanded in y around 0 40.4%
mul-1-neg40.4%
distribute-rgt-neg-in40.4%
Simplified40.4%
if -2.0200000000000001e154 < z < 3.9000000000000002e33Initial program 99.9%
add-sqr-sqrt44.7%
pow244.7%
Applied egg-rr44.7%
Taylor expanded in y around 0 50.9%
Final simplification47.6%
(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%
add-sqr-sqrt44.1%
pow244.1%
Applied egg-rr44.1%
Taylor expanded in y around 0 38.5%
Final simplification38.5%
herbie shell --seed 2023257
(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))))