
(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-define99.8%
sin-neg99.8%
Simplified99.8%
Final simplification99.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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0003)
t_0
(if (<= y 9.8e-6)
(- x (* z y))
(if (or (<= y 4.2e+32) (not (<= y 2.8e+137))) t_0 (* z (- (sin y))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0003) {
tmp = t_0;
} else if (y <= 9.8e-6) {
tmp = x - (z * y);
} else if ((y <= 4.2e+32) || !(y <= 2.8e+137)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-0.0003d0)) then
tmp = t_0
else if (y <= 9.8d-6) then
tmp = x - (z * y)
else if ((y <= 4.2d+32) .or. (.not. (y <= 2.8d+137))) then
tmp = t_0
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (y <= -0.0003) {
tmp = t_0;
} else if (y <= 9.8e-6) {
tmp = x - (z * y);
} else if ((y <= 4.2e+32) || !(y <= 2.8e+137)) {
tmp = t_0;
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.0003: tmp = t_0 elif y <= 9.8e-6: tmp = x - (z * y) elif (y <= 4.2e+32) or not (y <= 2.8e+137): tmp = t_0 else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.0003) tmp = t_0; elseif (y <= 9.8e-6) tmp = Float64(x - Float64(z * y)); elseif ((y <= 4.2e+32) || !(y <= 2.8e+137)) tmp = t_0; else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -0.0003) tmp = t_0; elseif (y <= 9.8e-6) tmp = x - (z * y); elseif ((y <= 4.2e+32) || ~((y <= 2.8e+137))) tmp = t_0; else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0003], t$95$0, If[LessEqual[y, 9.8e-6], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 4.2e+32], N[Not[LessEqual[y, 2.8e+137]], $MachinePrecision]], t$95$0, N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0003:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-6}:\\
\;\;\;\;x - z \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+32} \lor \neg \left(y \leq 2.8 \cdot 10^{+137}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if y < -2.99999999999999974e-4 or 9.79999999999999934e-6 < y < 4.2000000000000001e32 or 2.80000000000000001e137 < y Initial program 99.7%
Taylor expanded in x around inf 60.7%
if -2.99999999999999974e-4 < y < 9.79999999999999934e-6Initial program 100.0%
Taylor expanded in y around 0 99.7%
mul-1-neg99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
sub-neg99.7%
Simplified99.7%
if 4.2000000000000001e32 < y < 2.80000000000000001e137Initial program 99.5%
Taylor expanded in x around 0 68.7%
neg-mul-168.7%
*-commutative68.7%
distribute-rgt-neg-in68.7%
Simplified68.7%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.00033)
t_0
(if (<= y 0.00023)
(fma (- y) z x)
(if (or (<= y 2.1e+32) (not (<= y 8.6e+137))) t_0 (* z (- (sin y))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.00033) {
tmp = t_0;
} else if (y <= 0.00023) {
tmp = fma(-y, z, x);
} else if ((y <= 2.1e+32) || !(y <= 8.6e+137)) {
tmp = t_0;
} else {
tmp = z * -sin(y);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.00033) tmp = t_0; elseif (y <= 0.00023) tmp = fma(Float64(-y), z, x); elseif ((y <= 2.1e+32) || !(y <= 8.6e+137)) tmp = t_0; else tmp = Float64(z * Float64(-sin(y))); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.00033], t$95$0, If[LessEqual[y, 0.00023], N[((-y) * z + x), $MachinePrecision], If[Or[LessEqual[y, 2.1e+32], N[Not[LessEqual[y, 8.6e+137]], $MachinePrecision]], t$95$0, N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.00033:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00023:\\
\;\;\;\;\mathsf{fma}\left(-y, z, x\right)\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+32} \lor \neg \left(y \leq 8.6 \cdot 10^{+137}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if y < -3.3e-4 or 2.3000000000000001e-4 < y < 2.1000000000000001e32 or 8.59999999999999929e137 < y Initial program 99.7%
Taylor expanded in x around inf 60.7%
if -3.3e-4 < y < 2.3000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 99.7%
+-commutative99.7%
associate-*r*99.7%
fma-define99.7%
mul-1-neg99.7%
Simplified99.7%
if 2.1000000000000001e32 < y < 8.59999999999999929e137Initial program 99.5%
Taylor expanded in x around 0 68.7%
neg-mul-168.7%
*-commutative68.7%
distribute-rgt-neg-in68.7%
Simplified68.7%
Final simplification80.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0105)
t_0
(if (<= y 0.00022)
(- x (+ (* -0.16666666666666666 (* z (pow y 3.0))) (* z y)))
(if (or (<= y 2.1e+32) (not (<= y 7.2e+137))) t_0 (* z (- (sin y))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0105) {
tmp = t_0;
} else if (y <= 0.00022) {
tmp = x - ((-0.16666666666666666 * (z * pow(y, 3.0))) + (z * y));
} else if ((y <= 2.1e+32) || !(y <= 7.2e+137)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-0.0105d0)) then
tmp = t_0
else if (y <= 0.00022d0) then
tmp = x - (((-0.16666666666666666d0) * (z * (y ** 3.0d0))) + (z * y))
else if ((y <= 2.1d+32) .or. (.not. (y <= 7.2d+137))) then
tmp = t_0
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (y <= -0.0105) {
tmp = t_0;
} else if (y <= 0.00022) {
tmp = x - ((-0.16666666666666666 * (z * Math.pow(y, 3.0))) + (z * y));
} else if ((y <= 2.1e+32) || !(y <= 7.2e+137)) {
tmp = t_0;
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.0105: tmp = t_0 elif y <= 0.00022: tmp = x - ((-0.16666666666666666 * (z * math.pow(y, 3.0))) + (z * y)) elif (y <= 2.1e+32) or not (y <= 7.2e+137): tmp = t_0 else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.0105) tmp = t_0; elseif (y <= 0.00022) tmp = Float64(x - Float64(Float64(-0.16666666666666666 * Float64(z * (y ^ 3.0))) + Float64(z * y))); elseif ((y <= 2.1e+32) || !(y <= 7.2e+137)) tmp = t_0; else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -0.0105) tmp = t_0; elseif (y <= 0.00022) tmp = x - ((-0.16666666666666666 * (z * (y ^ 3.0))) + (z * y)); elseif ((y <= 2.1e+32) || ~((y <= 7.2e+137))) tmp = t_0; else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0105], t$95$0, If[LessEqual[y, 0.00022], N[(x - N[(N[(-0.16666666666666666 * N[(z * N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.1e+32], N[Not[LessEqual[y, 7.2e+137]], $MachinePrecision]], t$95$0, N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0105:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00022:\\
\;\;\;\;x - \left(-0.16666666666666666 \cdot \left(z \cdot {y}^{3}\right) + z \cdot y\right)\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+32} \lor \neg \left(y \leq 7.2 \cdot 10^{+137}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if y < -0.0105000000000000007 or 2.20000000000000008e-4 < y < 2.1000000000000001e32 or 7.1999999999999999e137 < y Initial program 99.7%
Taylor expanded in x around inf 60.7%
if -0.0105000000000000007 < y < 2.20000000000000008e-4Initial program 100.0%
log1p-expm1-u100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 100.0%
if 2.1000000000000001e32 < y < 7.1999999999999999e137Initial program 99.5%
Taylor expanded in x around 0 68.7%
neg-mul-168.7%
*-commutative68.7%
distribute-rgt-neg-in68.7%
Simplified68.7%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00115) (not (<= y 0.0001))) (* x (cos y)) (- x (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00115) || !(y <= 0.0001)) {
tmp = x * cos(y);
} else {
tmp = x - (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.00115d0)) .or. (.not. (y <= 0.0001d0))) then
tmp = x * cos(y)
else
tmp = x - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00115) || !(y <= 0.0001)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00115) or not (y <= 0.0001): tmp = x * math.cos(y) else: tmp = x - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00115) || !(y <= 0.0001)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00115) || ~((y <= 0.0001))) tmp = x * cos(y); else tmp = x - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00115], N[Not[LessEqual[y, 0.0001]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00115 \lor \neg \left(y \leq 0.0001\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot y\\
\end{array}
\end{array}
if y < -0.00115 or 1.00000000000000005e-4 < y Initial program 99.6%
Taylor expanded in x around inf 55.0%
if -0.00115 < y < 1.00000000000000005e-4Initial program 100.0%
Taylor expanded in y around 0 99.7%
mul-1-neg99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
sub-neg99.7%
Simplified99.7%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.2e-90) x (if (<= x 3.5e-181) (* z (- y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e-90) {
tmp = x;
} else if (x <= 3.5e-181) {
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 <= (-1.2d-90)) then
tmp = x
else if (x <= 3.5d-181) 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 <= -1.2e-90) {
tmp = x;
} else if (x <= 3.5e-181) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e-90: tmp = x elif x <= 3.5e-181: tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e-90) tmp = x; elseif (x <= 3.5e-181) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.2e-90) tmp = x; elseif (x <= 3.5e-181) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e-90], x, If[LessEqual[x, 3.5e-181], N[(z * (-y)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-90}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-181}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.2000000000000001e-90 or 3.49999999999999996e-181 < x Initial program 99.8%
Taylor expanded in y around 0 53.9%
mul-1-neg53.9%
Simplified53.9%
Taylor expanded in x around inf 47.6%
if -1.2000000000000001e-90 < x < 3.49999999999999996e-181Initial program 99.7%
Taylor expanded in y around 0 44.1%
mul-1-neg44.1%
Simplified44.1%
Taylor expanded in x around 0 31.9%
associate-*r*31.9%
neg-mul-131.9%
Simplified31.9%
Final simplification43.2%
(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 51.1%
mul-1-neg51.1%
Simplified51.1%
Taylor expanded in x around 0 51.1%
mul-1-neg51.1%
sub-neg51.1%
Simplified51.1%
Final simplification51.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 y around 0 51.1%
mul-1-neg51.1%
Simplified51.1%
Taylor expanded in x around inf 38.9%
Final simplification38.9%
herbie shell --seed 2024045
(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))))