
(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 x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(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 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -1.85e+153)
t_0
(if (<= y -1.05e+97)
t_1
(if (<= y -0.04)
t_0
(if (<= y 2e-41)
(+ (* -0.5 (* z (* y y))) (+ z (* x y)))
(if (<= y 4.6e+275) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -1.85e+153) {
tmp = t_0;
} else if (y <= -1.05e+97) {
tmp = t_1;
} else if (y <= -0.04) {
tmp = t_0;
} else if (y <= 2e-41) {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
} else if (y <= 4.6e+275) {
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 * cos(y)
t_1 = x * sin(y)
if (y <= (-1.85d+153)) then
tmp = t_0
else if (y <= (-1.05d+97)) then
tmp = t_1
else if (y <= (-0.04d0)) then
tmp = t_0
else if (y <= 2d-41) then
tmp = ((-0.5d0) * (z * (y * y))) + (z + (x * y))
else if (y <= 4.6d+275) 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.cos(y);
double t_1 = x * Math.sin(y);
double tmp;
if (y <= -1.85e+153) {
tmp = t_0;
} else if (y <= -1.05e+97) {
tmp = t_1;
} else if (y <= -0.04) {
tmp = t_0;
} else if (y <= 2e-41) {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
} else if (y <= 4.6e+275) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -1.85e+153: tmp = t_0 elif y <= -1.05e+97: tmp = t_1 elif y <= -0.04: tmp = t_0 elif y <= 2e-41: tmp = (-0.5 * (z * (y * y))) + (z + (x * y)) elif y <= 4.6e+275: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -1.85e+153) tmp = t_0; elseif (y <= -1.05e+97) tmp = t_1; elseif (y <= -0.04) tmp = t_0; elseif (y <= 2e-41) tmp = Float64(Float64(-0.5 * Float64(z * Float64(y * y))) + Float64(z + Float64(x * y))); elseif (y <= 4.6e+275) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = x * sin(y); tmp = 0.0; if (y <= -1.85e+153) tmp = t_0; elseif (y <= -1.05e+97) tmp = t_1; elseif (y <= -0.04) tmp = t_0; elseif (y <= 2e-41) tmp = (-0.5 * (z * (y * y))) + (z + (x * y)); elseif (y <= 4.6e+275) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.85e+153], t$95$0, If[LessEqual[y, -1.05e+97], t$95$1, If[LessEqual[y, -0.04], t$95$0, If[LessEqual[y, 2e-41], N[(N[(-0.5 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.6e+275], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.85 \cdot 10^{+153}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -0.04:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-41}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot y\right)\right) + \left(z + x \cdot y\right)\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+275}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.8500000000000001e153 or -1.05000000000000006e97 < y < -0.0400000000000000008 or 4.60000000000000021e275 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in z around inf 65.0%
if -1.8500000000000001e153 < y < -1.05000000000000006e97 or 2.00000000000000001e-41 < y < 4.60000000000000021e275Initial program 99.7%
Taylor expanded in x around 0 99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around 0 70.7%
if -0.0400000000000000008 < y < 2.00000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 99.4%
expm1-log1p-u94.4%
expm1-udef94.4%
unpow294.4%
associate-*l*94.4%
Applied egg-rr94.4%
expm1-def94.4%
expm1-log1p99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-9) (not (<= x 1.6e-79))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-9) || !(x <= 1.6e-79)) {
tmp = z + (x * sin(y));
} else {
tmp = z * cos(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 <= (-3.6d-9)) .or. (.not. (x <= 1.6d-79))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-9) || !(x <= 1.6e-79)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-9) or not (x <= 1.6e-79): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-9) || !(x <= 1.6e-79)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e-9) || ~((x <= 1.6e-79))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-9], N[Not[LessEqual[x, 1.6e-79]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-9} \lor \neg \left(x \leq 1.6 \cdot 10^{-79}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -3.6e-9 or 1.59999999999999994e-79 < x Initial program 99.8%
Taylor expanded in y around 0 88.0%
if -3.6e-9 < x < 1.59999999999999994e-79Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 86.7%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.034) (not (<= y 0.25))) (* z (cos y)) (+ (* -0.5 (* z (* y y))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.034) || !(y <= 0.25)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (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 <= (-0.034d0)) .or. (.not. (y <= 0.25d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (z * (y * y))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.034) || !(y <= 0.25)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.034) or not (y <= 0.25): tmp = z * math.cos(y) else: tmp = (-0.5 * (z * (y * y))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.034) || !(y <= 0.25)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(z * Float64(y * y))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.034) || ~((y <= 0.25))) tmp = z * cos(y); else tmp = (-0.5 * (z * (y * y))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.034], N[Not[LessEqual[y, 0.25]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.034 \lor \neg \left(y \leq 0.25\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot y\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -0.034000000000000002 or 0.25 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in z around inf 51.7%
if -0.034000000000000002 < y < 0.25Initial program 100.0%
Taylor expanded in y around 0 99.2%
expm1-log1p-u94.6%
expm1-udef94.6%
unpow294.6%
associate-*l*94.6%
Applied egg-rr94.6%
expm1-def94.6%
expm1-log1p99.2%
associate-*r*99.2%
*-commutative99.2%
Simplified99.2%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (<= z -3.7e-233) z (if (<= z 8.1e-106) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e-233) {
tmp = z;
} else if (z <= 8.1e-106) {
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 <= (-3.7d-233)) then
tmp = z
else if (z <= 8.1d-106) 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 <= -3.7e-233) {
tmp = z;
} else if (z <= 8.1e-106) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.7e-233: tmp = z elif z <= 8.1e-106: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.7e-233) tmp = z; elseif (z <= 8.1e-106) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.7e-233) tmp = z; elseif (z <= 8.1e-106) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.7e-233], z, If[LessEqual[z, 8.1e-106], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{-233}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 8.1 \cdot 10^{-106}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.6999999999999998e-233 or 8.1000000000000002e-106 < z Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 43.1%
if -3.6999999999999998e-233 < z < 8.1000000000000002e-106Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around 0 85.2%
Taylor expanded in y around 0 44.9%
Final simplification43.5%
(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 52.6%
Final simplification52.6%
(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 x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 36.2%
Final simplification36.2%
herbie shell --seed 2023240
(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))))