
(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 x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e+57) (not (<= x 1.2e+31))) (* x (cos y)) (fma (sin y) z x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e+57) || !(x <= 1.2e+31)) {
tmp = x * cos(y);
} else {
tmp = fma(sin(y), z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e+57) || !(x <= 1.2e+31)) tmp = Float64(x * cos(y)); else tmp = fma(sin(y), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e+57], N[Not[LessEqual[x, 1.2e+31]], $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 -9.5 \cdot 10^{+57} \lor \neg \left(x \leq 1.2 \cdot 10^{+31}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
\end{array}
\end{array}
if x < -9.4999999999999997e57 or 1.19999999999999991e31 < x Initial program 99.9%
Taylor expanded in x around inf 84.7%
if -9.4999999999999997e57 < x < 1.19999999999999991e31Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 89.7%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (* z (sin y))))
(if (<= x -2.02e-84)
t_0
(if (<= x 2.85e-105)
t_1
(if (<= x 6.2e-55) (+ x (* y z)) (if (<= x 3.2e-14) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = z * sin(y);
double tmp;
if (x <= -2.02e-84) {
tmp = t_0;
} else if (x <= 2.85e-105) {
tmp = t_1;
} else if (x <= 6.2e-55) {
tmp = x + (y * z);
} else if (x <= 3.2e-14) {
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 = x * cos(y)
t_1 = z * sin(y)
if (x <= (-2.02d-84)) then
tmp = t_0
else if (x <= 2.85d-105) then
tmp = t_1
else if (x <= 6.2d-55) then
tmp = x + (y * z)
else if (x <= 3.2d-14) 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 = x * Math.cos(y);
double t_1 = z * Math.sin(y);
double tmp;
if (x <= -2.02e-84) {
tmp = t_0;
} else if (x <= 2.85e-105) {
tmp = t_1;
} else if (x <= 6.2e-55) {
tmp = x + (y * z);
} else if (x <= 3.2e-14) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) t_1 = z * math.sin(y) tmp = 0 if x <= -2.02e-84: tmp = t_0 elif x <= 2.85e-105: tmp = t_1 elif x <= 6.2e-55: tmp = x + (y * z) elif x <= 3.2e-14: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(z * sin(y)) tmp = 0.0 if (x <= -2.02e-84) tmp = t_0; elseif (x <= 2.85e-105) tmp = t_1; elseif (x <= 6.2e-55) tmp = Float64(x + Float64(y * z)); elseif (x <= 3.2e-14) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); t_1 = z * sin(y); tmp = 0.0; if (x <= -2.02e-84) tmp = t_0; elseif (x <= 2.85e-105) tmp = t_1; elseif (x <= 6.2e-55) tmp = x + (y * z); elseif (x <= 3.2e-14) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.02e-84], t$95$0, If[LessEqual[x, 2.85e-105], t$95$1, If[LessEqual[x, 6.2e-55], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.2e-14], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := z \cdot \sin y\\
\mathbf{if}\;x \leq -2.02 \cdot 10^{-84}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.85 \cdot 10^{-105}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-55}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-14}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.02e-84 or 3.2000000000000002e-14 < x Initial program 99.8%
Taylor expanded in x around inf 80.0%
if -2.02e-84 < x < 2.84999999999999981e-105 or 6.19999999999999993e-55 < x < 3.2000000000000002e-14Initial program 99.6%
Taylor expanded in x around 0 83.0%
if 2.84999999999999981e-105 < x < 6.19999999999999993e-55Initial program 99.8%
Taylor expanded in y around 0 79.0%
+-commutative79.0%
Simplified79.0%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e+57) (not (<= x 3e+33))) (* x (cos y)) (+ x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e+57) || !(x <= 3e+33)) {
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 <= (-8.5d+57)) .or. (.not. (x <= 3d+33))) 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 <= -8.5e+57) || !(x <= 3e+33)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e+57) or not (x <= 3e+33): tmp = x * math.cos(y) else: tmp = x + (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e+57) || !(x <= 3e+33)) 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 <= -8.5e+57) || ~((x <= 3e+33))) tmp = x * cos(y); else tmp = x + (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e+57], N[Not[LessEqual[x, 3e+33]], $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 -8.5 \cdot 10^{+57} \lor \neg \left(x \leq 3 \cdot 10^{+33}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if x < -8.5000000000000001e57 or 2.99999999999999984e33 < x Initial program 99.9%
Taylor expanded in x around inf 84.7%
if -8.5000000000000001e57 < x < 2.99999999999999984e33Initial program 99.7%
Taylor expanded in y around 0 89.7%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+17) (not (<= y 0.00088))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+17) || !(y <= 0.00088)) {
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 <= (-2.5d+17)) .or. (.not. (y <= 0.00088d0))) 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 <= -2.5e+17) || !(y <= 0.00088)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+17) or not (y <= 0.00088): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+17) || !(y <= 0.00088)) 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 <= -2.5e+17) || ~((y <= 0.00088))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+17], N[Not[LessEqual[y, 0.00088]], $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 -2.5 \cdot 10^{+17} \lor \neg \left(y \leq 0.00088\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -2.5e17 or 8.80000000000000031e-4 < y Initial program 99.6%
Taylor expanded in x around inf 45.8%
if -2.5e17 < y < 8.80000000000000031e-4Initial program 100.0%
Taylor expanded in y around 0 96.4%
+-commutative96.4%
Simplified96.4%
Final simplification69.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%
Taylor expanded in y around 0 47.6%
+-commutative47.6%
Simplified47.6%
Final simplification47.6%
(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%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 37.1%
Final simplification37.1%
herbie shell --seed 2024029
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))