
(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 7 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 (+ (* 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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
(if (<= y -1.3e+191)
t_0
(if (<= y -0.00125)
t_1
(if (<= y 5.2e-6) (+ z (* x y)) (if (<= y 2.2e+245) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = z * cos(y);
double tmp;
if (y <= -1.3e+191) {
tmp = t_0;
} else if (y <= -0.00125) {
tmp = t_1;
} else if (y <= 5.2e-6) {
tmp = z + (x * y);
} else if (y <= 2.2e+245) {
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 * sin(y)
t_1 = z * cos(y)
if (y <= (-1.3d+191)) then
tmp = t_0
else if (y <= (-0.00125d0)) then
tmp = t_1
else if (y <= 5.2d-6) then
tmp = z + (x * y)
else if (y <= 2.2d+245) 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.sin(y);
double t_1 = z * Math.cos(y);
double tmp;
if (y <= -1.3e+191) {
tmp = t_0;
} else if (y <= -0.00125) {
tmp = t_1;
} else if (y <= 5.2e-6) {
tmp = z + (x * y);
} else if (y <= 2.2e+245) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = z * math.cos(y) tmp = 0 if y <= -1.3e+191: tmp = t_0 elif y <= -0.00125: tmp = t_1 elif y <= 5.2e-6: tmp = z + (x * y) elif y <= 2.2e+245: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(z * cos(y)) tmp = 0.0 if (y <= -1.3e+191) tmp = t_0; elseif (y <= -0.00125) tmp = t_1; elseif (y <= 5.2e-6) tmp = Float64(z + Float64(x * y)); elseif (y <= 2.2e+245) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); t_1 = z * cos(y); tmp = 0.0; if (y <= -1.3e+191) tmp = t_0; elseif (y <= -0.00125) tmp = t_1; elseif (y <= 5.2e-6) tmp = z + (x * y); elseif (y <= 2.2e+245) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.3e+191], t$95$0, If[LessEqual[y, -0.00125], t$95$1, If[LessEqual[y, 5.2e-6], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.2e+245], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -1.3 \cdot 10^{+191}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.00125:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-6}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+245}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.3e191 or 2.2000000000000001e245 < y Initial program 99.8%
Taylor expanded in x around inf 67.9%
if -1.3e191 < y < -0.00125000000000000003 or 5.20000000000000019e-6 < y < 2.2000000000000001e245Initial program 99.6%
Taylor expanded in x around 0 69.2%
if -0.00125000000000000003 < y < 5.20000000000000019e-6Initial program 100.0%
Taylor expanded in y around 0 99.3%
+-commutative99.3%
Simplified99.3%
Final simplification84.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
(if (<= y -4.4e+189)
t_0
(if (<= y -0.0013)
t_1
(if (<= y 7.6e-6) (fma x y z) (if (<= y 1.85e+242) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = z * cos(y);
double tmp;
if (y <= -4.4e+189) {
tmp = t_0;
} else if (y <= -0.0013) {
tmp = t_1;
} else if (y <= 7.6e-6) {
tmp = fma(x, y, z);
} else if (y <= 1.85e+242) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(z * cos(y)) tmp = 0.0 if (y <= -4.4e+189) tmp = t_0; elseif (y <= -0.0013) tmp = t_1; elseif (y <= 7.6e-6) tmp = fma(x, y, z); elseif (y <= 1.85e+242) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.4e+189], t$95$0, If[LessEqual[y, -0.0013], t$95$1, If[LessEqual[y, 7.6e-6], N[(x * y + z), $MachinePrecision], If[LessEqual[y, 1.85e+242], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -4.4 \cdot 10^{+189}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.0013:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+242}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.4000000000000001e189 or 1.85e242 < y Initial program 99.8%
Taylor expanded in x around inf 67.9%
if -4.4000000000000001e189 < y < -0.0012999999999999999 or 7.6000000000000001e-6 < y < 1.85e242Initial program 99.6%
Taylor expanded in x around 0 69.2%
if -0.0012999999999999999 < y < 7.6000000000000001e-6Initial program 100.0%
Taylor expanded in y around 0 99.3%
+-commutative99.3%
fma-def99.3%
Simplified99.3%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -11500.0) (not (<= y 0.032))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -11500.0) || !(y <= 0.032)) {
tmp = x * sin(y);
} else {
tmp = z + (x * 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 <= (-11500.0d0)) .or. (.not. (y <= 0.032d0))) then
tmp = x * sin(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -11500.0) || !(y <= 0.032)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -11500.0) or not (y <= 0.032): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -11500.0) || !(y <= 0.032)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -11500.0) || ~((y <= 0.032))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -11500.0], N[Not[LessEqual[y, 0.032]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -11500 \lor \neg \left(y \leq 0.032\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -11500 or 0.032000000000000001 < y Initial program 99.7%
Taylor expanded in x around inf 42.8%
if -11500 < y < 0.032000000000000001Initial program 100.0%
Taylor expanded in y around 0 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification71.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.55e-52) z (if (<= z 1.02e-108) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e-52) {
tmp = z;
} else if (z <= 1.02e-108) {
tmp = x * y;
} 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 (z <= (-1.55d-52)) then
tmp = z
else if (z <= 1.02d-108) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e-52) {
tmp = z;
} else if (z <= 1.02e-108) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.55e-52: tmp = z elif z <= 1.02e-108: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.55e-52) tmp = z; elseif (z <= 1.02e-108) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.55e-52) tmp = z; elseif (z <= 1.02e-108) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.55e-52], z, If[LessEqual[z, 1.02e-108], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{-52}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{-108}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.5499999999999999e-52 or 1.02000000000000008e-108 < z Initial program 99.8%
Taylor expanded in y around 0 53.9%
+-commutative53.9%
Simplified53.9%
Taylor expanded in x around 0 48.8%
if -1.5499999999999999e-52 < z < 1.02000000000000008e-108Initial program 99.8%
Taylor expanded in x around inf 75.3%
Taylor expanded in y around 0 37.6%
Final simplification45.1%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * 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 + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 53.2%
+-commutative53.2%
Simplified53.2%
Final simplification53.2%
(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.8%
Taylor expanded in y around 0 53.2%
+-commutative53.2%
Simplified53.2%
Taylor expanded in x around 0 38.7%
Final simplification38.7%
herbie shell --seed 2023320
(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))))