
(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 9 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-def99.8%
sin-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+140) (not (<= x 6.8e-12))) (* x (cos y)) (fma z (- (sin y)) x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+140) || !(x <= 6.8e-12)) {
tmp = x * cos(y);
} else {
tmp = fma(z, -sin(y), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+140) || !(x <= 6.8e-12)) 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.95e+140], N[Not[LessEqual[x, 6.8e-12]], $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.95 \cdot 10^{+140} \lor \neg \left(x \leq 6.8 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, -\sin y, x\right)\\
\end{array}
\end{array}
if x < -1.94999999999999987e140 or 6.8000000000000001e-12 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in x around inf 92.4%
if -1.94999999999999987e140 < x < 6.8000000000000001e-12Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.9%
sin-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 90.7%
Final simplification91.4%
(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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- (sin y)))) (t_1 (* x (cos y))))
(if (<= y -3.5e+200)
t_0
(if (<= y -0.18)
t_1
(if (<= y 30500.0)
(- (+ x (* -0.5 (* x (* y y)))) (* z y))
(if (or (<= y 3.1e+209) (not (<= y 3.6e+235))) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -3.5e+200) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (x + (-0.5 * (x * (y * y)))) - (z * y);
} else if ((y <= 3.1e+209) || !(y <= 3.6e+235)) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = z * -sin(y)
t_1 = x * cos(y)
if (y <= (-3.5d+200)) then
tmp = t_0
else if (y <= (-0.18d0)) then
tmp = t_1
else if (y <= 30500.0d0) then
tmp = (x + ((-0.5d0) * (x * (y * y)))) - (z * y)
else if ((y <= 3.1d+209) .or. (.not. (y <= 3.6d+235))) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -Math.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -3.5e+200) {
tmp = t_0;
} else if (y <= -0.18) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (x + (-0.5 * (x * (y * y)))) - (z * y);
} else if ((y <= 3.1e+209) || !(y <= 3.6e+235)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -3.5e+200: tmp = t_0 elif y <= -0.18: tmp = t_1 elif y <= 30500.0: tmp = (x + (-0.5 * (x * (y * y)))) - (z * y) elif (y <= 3.1e+209) or not (y <= 3.6e+235): tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-sin(y))) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -3.5e+200) tmp = t_0; elseif (y <= -0.18) tmp = t_1; elseif (y <= 30500.0) tmp = Float64(Float64(x + Float64(-0.5 * Float64(x * Float64(y * y)))) - Float64(z * y)); elseif ((y <= 3.1e+209) || !(y <= 3.6e+235)) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -3.5e+200) tmp = t_0; elseif (y <= -0.18) tmp = t_1; elseif (y <= 30500.0) tmp = (x + (-0.5 * (x * (y * y)))) - (z * y); elseif ((y <= 3.1e+209) || ~((y <= 3.6e+235))) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.5e+200], t$95$0, If[LessEqual[y, -0.18], t$95$1, If[LessEqual[y, 30500.0], N[(N[(x + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.1e+209], N[Not[LessEqual[y, 3.6e+235]], $MachinePrecision]], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-\sin y\right)\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+200}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.18:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 30500:\\
\;\;\;\;\left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right) - z \cdot y\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+209} \lor \neg \left(y \leq 3.6 \cdot 10^{+235}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.50000000000000006e200 or 3.1000000000000001e209 < y < 3.59999999999999985e235Initial program 99.7%
Taylor expanded in x around 0 67.9%
neg-mul-167.9%
*-commutative67.9%
distribute-rgt-neg-in67.9%
Simplified67.9%
if -3.50000000000000006e200 < y < -0.17999999999999999 or 30500 < y < 3.1000000000000001e209 or 3.59999999999999985e235 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
neg-mul-199.6%
+-commutative99.6%
fma-def99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
Taylor expanded in x around inf 66.1%
if -0.17999999999999999 < y < 30500Initial program 100.0%
Taylor expanded in y around 0 97.7%
+-commutative97.7%
mul-1-neg97.7%
unsub-neg97.7%
fma-def97.7%
*-commutative97.7%
unpow297.7%
associate-*r*97.7%
Simplified97.7%
fma-udef97.7%
associate-*l*97.7%
Applied egg-rr97.7%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.36e+139) (not (<= x 6.8e-12))) (* x (cos y)) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.36e+139) || !(x <= 6.8e-12)) {
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 <= (-1.36d+139)) .or. (.not. (x <= 6.8d-12))) 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 <= -1.36e+139) || !(x <= 6.8e-12)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.36e+139) or not (x <= 6.8e-12): tmp = x * math.cos(y) else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.36e+139) || !(x <= 6.8e-12)) 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 <= -1.36e+139) || ~((x <= 6.8e-12))) tmp = x * cos(y); else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.36e+139], N[Not[LessEqual[x, 6.8e-12]], $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 -1.36 \cdot 10^{+139} \lor \neg \left(x \leq 6.8 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.36000000000000004e139 or 6.8000000000000001e-12 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in x around inf 92.4%
if -1.36000000000000004e139 < x < 6.8000000000000001e-12Initial program 99.8%
Taylor expanded in y around 0 90.7%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.18) (not (<= y 30500.0))) (* x (cos y)) (- (+ x (* -0.5 (* x (* y y)))) (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.18) || !(y <= 30500.0)) {
tmp = x * cos(y);
} else {
tmp = (x + (-0.5 * (x * (y * y)))) - (z * 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 <= (-0.18d0)) .or. (.not. (y <= 30500.0d0))) then
tmp = x * cos(y)
else
tmp = (x + ((-0.5d0) * (x * (y * y)))) - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.18) || !(y <= 30500.0)) {
tmp = x * Math.cos(y);
} else {
tmp = (x + (-0.5 * (x * (y * y)))) - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.18) or not (y <= 30500.0): tmp = x * math.cos(y) else: tmp = (x + (-0.5 * (x * (y * y)))) - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.18) || !(y <= 30500.0)) tmp = Float64(x * cos(y)); else tmp = Float64(Float64(x + Float64(-0.5 * Float64(x * Float64(y * y)))) - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.18) || ~((y <= 30500.0))) tmp = x * cos(y); else tmp = (x + (-0.5 * (x * (y * y)))) - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.18], N[Not[LessEqual[y, 30500.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.18 \lor \neg \left(y \leq 30500\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\right) - z \cdot y\\
\end{array}
\end{array}
if y < -0.17999999999999999 or 30500 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
neg-mul-199.6%
+-commutative99.6%
fma-def99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
Taylor expanded in x around inf 54.7%
if -0.17999999999999999 < y < 30500Initial program 100.0%
Taylor expanded in y around 0 97.7%
+-commutative97.7%
mul-1-neg97.7%
unsub-neg97.7%
fma-def97.7%
*-commutative97.7%
unpow297.7%
associate-*r*97.7%
Simplified97.7%
fma-udef97.7%
associate-*l*97.7%
Applied egg-rr97.7%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (<= x -2e-133) x (if (<= x 8.5e-220) (* z (- y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2e-133) {
tmp = x;
} else if (x <= 8.5e-220) {
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 <= (-2d-133)) then
tmp = x
else if (x <= 8.5d-220) 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 <= -2e-133) {
tmp = x;
} else if (x <= 8.5e-220) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2e-133: tmp = x elif x <= 8.5e-220: tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2e-133) tmp = x; elseif (x <= 8.5e-220) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2e-133) tmp = x; elseif (x <= 8.5e-220) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2e-133], x, If[LessEqual[x, 8.5e-220], N[(z * (-y)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-133}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-220}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.0000000000000001e-133 or 8.4999999999999996e-220 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in y around 0 48.9%
if -2.0000000000000001e-133 < x < 8.4999999999999996e-220Initial program 99.8%
Taylor expanded in y around 0 59.2%
+-commutative59.2%
mul-1-neg59.2%
unsub-neg59.2%
fma-def59.2%
*-commutative59.2%
unpow259.2%
associate-*r*59.5%
Simplified59.5%
Taylor expanded in x around 0 44.8%
mul-1-neg44.8%
distribute-rgt-neg-out44.8%
Simplified44.8%
Final simplification47.9%
(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 58.1%
+-commutative58.1%
mul-1-neg58.1%
unsub-neg58.1%
Simplified58.1%
Final simplification58.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%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in y around 0 41.9%
Final simplification41.9%
herbie shell --seed 2023268
(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))))