
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (cos(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 * sin(y)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -0.000175)
t_0
(if (<= y 0.0032)
(+ z (* y x))
(if (or (<= y 3.4e+209) (not (<= y 1.02e+288))) (* (cos y) z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.000175) {
tmp = t_0;
} else if (y <= 0.0032) {
tmp = z + (y * x);
} else if ((y <= 3.4e+209) || !(y <= 1.02e+288)) {
tmp = cos(y) * z;
} 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) :: tmp
t_0 = x * sin(y)
if (y <= (-0.000175d0)) then
tmp = t_0
else if (y <= 0.0032d0) then
tmp = z + (y * x)
else if ((y <= 3.4d+209) .or. (.not. (y <= 1.02d+288))) then
tmp = cos(y) * z
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.sin(y);
double tmp;
if (y <= -0.000175) {
tmp = t_0;
} else if (y <= 0.0032) {
tmp = z + (y * x);
} else if ((y <= 3.4e+209) || !(y <= 1.02e+288)) {
tmp = Math.cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if y <= -0.000175: tmp = t_0 elif y <= 0.0032: tmp = z + (y * x) elif (y <= 3.4e+209) or not (y <= 1.02e+288): tmp = math.cos(y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.000175) tmp = t_0; elseif (y <= 0.0032) tmp = Float64(z + Float64(y * x)); elseif ((y <= 3.4e+209) || !(y <= 1.02e+288)) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (y <= -0.000175) tmp = t_0; elseif (y <= 0.0032) tmp = z + (y * x); elseif ((y <= 3.4e+209) || ~((y <= 1.02e+288))) tmp = cos(y) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.000175], t$95$0, If[LessEqual[y, 0.0032], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.4e+209], N[Not[LessEqual[y, 1.02e+288]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.000175:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.0032:\\
\;\;\;\;z + y \cdot x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+209} \lor \neg \left(y \leq 1.02 \cdot 10^{+288}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.74999999999999998e-4 or 3.3999999999999997e209 < y < 1.02000000000000003e288Initial program 99.6%
Taylor expanded in x around inf 66.7%
if -1.74999999999999998e-4 < y < 0.00320000000000000015Initial program 100.0%
Taylor expanded in y around 0 99.7%
+-commutative99.7%
Simplified99.7%
if 0.00320000000000000015 < y < 3.3999999999999997e209 or 1.02000000000000003e288 < y Initial program 99.8%
Taylor expanded in x around 0 59.8%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-58) (not (<= x 2.85e-105))) (+ z (* x (sin y))) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-58) || !(x <= 2.85e-105)) {
tmp = z + (x * sin(y));
} else {
tmp = cos(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-58)) .or. (.not. (x <= 2.85d-105))) then
tmp = z + (x * sin(y))
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-58) || !(x <= 2.85e-105)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-58) or not (x <= 2.85e-105): tmp = z + (x * math.sin(y)) else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-58) || !(x <= 2.85e-105)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e-58) || ~((x <= 2.85e-105))) tmp = z + (x * sin(y)); else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-58], N[Not[LessEqual[x, 2.85e-105]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-58} \lor \neg \left(x \leq 2.85 \cdot 10^{-105}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -2.0000000000000001e-58 or 2.84999999999999981e-105 < x Initial program 99.8%
Taylor expanded in y around 0 91.4%
if -2.0000000000000001e-58 < x < 2.84999999999999981e-105Initial program 99.9%
Taylor expanded in x around 0 92.7%
Final simplification91.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.2e-5) (not (<= y 8.7e-23))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-5) || !(y <= 8.7e-23)) {
tmp = x * sin(y);
} else {
tmp = z + (y * 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 ((y <= (-3.2d-5)) .or. (.not. (y <= 8.7d-23))) then
tmp = x * sin(y)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-5) || !(y <= 8.7e-23)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.2e-5) or not (y <= 8.7e-23): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.2e-5) || !(y <= 8.7e-23)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.2e-5) || ~((y <= 8.7e-23))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e-5], N[Not[LessEqual[y, 8.7e-23]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-5} \lor \neg \left(y \leq 8.7 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -3.19999999999999986e-5 or 8.7000000000000005e-23 < y Initial program 99.7%
Taylor expanded in x around inf 57.3%
if -3.19999999999999986e-5 < y < 8.7000000000000005e-23Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e+174) (not (<= x 5.2e+39))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e+174) || !(x <= 5.2e+39)) {
tmp = y * x;
} else {
tmp = 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 <= (-8.2d+174)) .or. (.not. (x <= 5.2d+39))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e+174) || !(x <= 5.2e+39)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e+174) or not (x <= 5.2e+39): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e+174) || !(x <= 5.2e+39)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e+174) || ~((x <= 5.2e+39))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e+174], N[Not[LessEqual[x, 5.2e+39]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+174} \lor \neg \left(x \leq 5.2 \cdot 10^{+39}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.20000000000000061e174 or 5.2e39 < x Initial program 99.8%
Taylor expanded in x around inf 76.6%
Taylor expanded in y around 0 43.7%
if -8.20000000000000061e174 < x < 5.2e39Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 52.8%
Final simplification49.9%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 59.1%
+-commutative59.1%
Simplified59.1%
Final simplification59.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 42.8%
Final simplification42.8%
herbie shell --seed 2024019
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))