
(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 9 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.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * 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 = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -2e+148)
t_0
(if (<= y -0.000185)
t_1
(if (<= y 6.5e-18)
(+ z (* x y))
(if (or (<= y 2.3e+91) (not (<= y 1.05e+200))) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -2e+148) {
tmp = t_0;
} else if (y <= -0.000185) {
tmp = t_1;
} else if (y <= 6.5e-18) {
tmp = z + (x * y);
} else if ((y <= 2.3e+91) || !(y <= 1.05e+200)) {
tmp = t_0;
} else {
tmp = t_1;
}
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 <= (-2d+148)) then
tmp = t_0
else if (y <= (-0.000185d0)) then
tmp = t_1
else if (y <= 6.5d-18) then
tmp = z + (x * y)
else if ((y <= 2.3d+91) .or. (.not. (y <= 1.05d+200))) then
tmp = t_0
else
tmp = t_1
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 <= -2e+148) {
tmp = t_0;
} else if (y <= -0.000185) {
tmp = t_1;
} else if (y <= 6.5e-18) {
tmp = z + (x * y);
} else if ((y <= 2.3e+91) || !(y <= 1.05e+200)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -2e+148: tmp = t_0 elif y <= -0.000185: tmp = t_1 elif y <= 6.5e-18: tmp = z + (x * y) elif (y <= 2.3e+91) or not (y <= 1.05e+200): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2e+148) tmp = t_0; elseif (y <= -0.000185) tmp = t_1; elseif (y <= 6.5e-18) tmp = Float64(z + Float64(x * y)); elseif ((y <= 2.3e+91) || !(y <= 1.05e+200)) tmp = t_0; else tmp = t_1; 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 <= -2e+148) tmp = t_0; elseif (y <= -0.000185) tmp = t_1; elseif (y <= 6.5e-18) tmp = z + (x * y); elseif ((y <= 2.3e+91) || ~((y <= 1.05e+200))) tmp = t_0; else tmp = t_1; 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, -2e+148], t$95$0, If[LessEqual[y, -0.000185], t$95$1, If[LessEqual[y, 6.5e-18], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.3e+91], N[Not[LessEqual[y, 1.05e+200]], $MachinePrecision]], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2 \cdot 10^{+148}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.000185:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-18}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+91} \lor \neg \left(y \leq 1.05 \cdot 10^{+200}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.0000000000000001e148 or 6.50000000000000008e-18 < y < 2.29999999999999991e91 or 1.04999999999999999e200 < y Initial program 99.8%
Taylor expanded in x around 0 69.5%
if -2.0000000000000001e148 < y < -1.85e-4 or 2.29999999999999991e91 < y < 1.04999999999999999e200Initial program 99.7%
Taylor expanded in x around inf 68.0%
if -1.85e-4 < y < 6.50000000000000008e-18Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification85.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -1.05e+147)
t_0
(if (<= y -8e-5)
t_1
(if (<= y 6.5e-18)
(fma x y z)
(if (or (<= y 1.15e+91) (not (<= y 2.3e+196))) t_0 t_1))))))
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.05e+147) {
tmp = t_0;
} else if (y <= -8e-5) {
tmp = t_1;
} else if (y <= 6.5e-18) {
tmp = fma(x, y, z);
} else if ((y <= 1.15e+91) || !(y <= 2.3e+196)) {
tmp = t_0;
} else {
tmp = t_1;
}
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.05e+147) tmp = t_0; elseif (y <= -8e-5) tmp = t_1; elseif (y <= 6.5e-18) tmp = fma(x, y, z); elseif ((y <= 1.15e+91) || !(y <= 2.3e+196)) tmp = t_0; else tmp = t_1; end return 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.05e+147], t$95$0, If[LessEqual[y, -8e-5], t$95$1, If[LessEqual[y, 6.5e-18], N[(x * y + z), $MachinePrecision], If[Or[LessEqual[y, 1.15e+91], N[Not[LessEqual[y, 2.3e+196]], $MachinePrecision]], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -8 \cdot 10^{-5}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+91} \lor \neg \left(y \leq 2.3 \cdot 10^{+196}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.05000000000000003e147 or 6.50000000000000008e-18 < y < 1.14999999999999996e91 or 2.2999999999999998e196 < y Initial program 99.8%
Taylor expanded in x around 0 69.5%
if -1.05000000000000003e147 < y < -8.00000000000000065e-5 or 1.14999999999999996e91 < y < 2.2999999999999998e196Initial program 99.7%
Taylor expanded in x around inf 68.0%
if -8.00000000000000065e-5 < y < 6.50000000000000008e-18Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e-14) (not (<= x 5.6e-56))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-14) || !(x <= 5.6e-56)) {
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 <= (-1.75d-14)) .or. (.not. (x <= 5.6d-56))) 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 <= -1.75e-14) || !(x <= 5.6e-56)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e-14) or not (x <= 5.6e-56): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e-14) || !(x <= 5.6e-56)) 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 <= -1.75e-14) || ~((x <= 5.6e-56))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e-14], N[Not[LessEqual[x, 5.6e-56]], $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 -1.75 \cdot 10^{-14} \lor \neg \left(x \leq 5.6 \cdot 10^{-56}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.7500000000000001e-14 or 5.59999999999999986e-56 < x Initial program 99.8%
Taylor expanded in y around 0 91.4%
if -1.7500000000000001e-14 < x < 5.59999999999999986e-56Initial program 99.9%
Taylor expanded in x around 0 93.6%
Final simplification92.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00046) (not (<= y 1050000000.0))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00046) || !(y <= 1050000000.0)) {
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 <= (-0.00046d0)) .or. (.not. (y <= 1050000000.0d0))) 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 <= -0.00046) || !(y <= 1050000000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00046) or not (y <= 1050000000.0): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00046) || !(y <= 1050000000.0)) 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 <= -0.00046) || ~((y <= 1050000000.0))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00046], N[Not[LessEqual[y, 1050000000.0]], $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 -0.00046 \lor \neg \left(y \leq 1050000000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -4.6000000000000001e-4 or 1.05e9 < y Initial program 99.7%
Taylor expanded in x around inf 50.2%
if -4.6000000000000001e-4 < y < 1.05e9Initial program 100.0%
Taylor expanded in y around 0 98.5%
+-commutative98.5%
Simplified98.5%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.2e+181) (not (<= x 1.3e+54))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.2e+181) || !(x <= 1.3e+54)) {
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 ((x <= (-8.2d+181)) .or. (.not. (x <= 1.3d+54))) 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 ((x <= -8.2e+181) || !(x <= 1.3e+54)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.2e+181) or not (x <= 1.3e+54): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.2e+181) || !(x <= 1.3e+54)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.2e+181) || ~((x <= 1.3e+54))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.2e+181], N[Not[LessEqual[x, 1.3e+54]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+181} \lor \neg \left(x \leq 1.3 \cdot 10^{+54}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.20000000000000035e181 or 1.30000000000000003e54 < x Initial program 99.8%
Taylor expanded in x around inf 68.2%
Taylor expanded in y around 0 37.7%
if -8.20000000000000035e181 < x < 1.30000000000000003e54Initial program 99.9%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 52.7%
Final simplification47.4%
(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.9%
Taylor expanded in y around 0 58.2%
+-commutative58.2%
Simplified58.2%
Final simplification58.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.9%
add-cube-cbrt99.2%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 42.2%
Final simplification42.2%
herbie shell --seed 2024027
(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))))