
(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.8%
fma-define99.9%
Simplified99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-71) (not (<= x 1.46e-75))) (fma x (sin y) z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-71) || !(x <= 1.46e-75)) {
tmp = fma(x, sin(y), z);
} else {
tmp = z * cos(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -7e-71) || !(x <= 1.46e-75)) tmp = fma(x, sin(y), z); else tmp = Float64(z * cos(y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-71], N[Not[LessEqual[x, 1.46e-75]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-71} \lor \neg \left(x \leq 1.46 \cdot 10^{-75}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -6.9999999999999998e-71 or 1.45999999999999991e-75 < x Initial program 99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 91.4%
if -6.9999999999999998e-71 < x < 1.45999999999999991e-75Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around 0 90.0%
Final simplification90.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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
(if (<= y -5.5e+111)
t_0
(if (<= y -5.4e+23)
t_1
(if (<= y -0.022)
t_0
(if (<= y 0.32)
(+
z
(* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))
(if (<= y 1.95e+149) 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 <= -5.5e+111) {
tmp = t_0;
} else if (y <= -5.4e+23) {
tmp = t_1;
} else if (y <= -0.022) {
tmp = t_0;
} else if (y <= 0.32) {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
} else if (y <= 1.95e+149) {
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 <= (-5.5d+111)) then
tmp = t_0
else if (y <= (-5.4d+23)) then
tmp = t_1
else if (y <= (-0.022d0)) then
tmp = t_0
else if (y <= 0.32d0) then
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
else if (y <= 1.95d+149) 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 <= -5.5e+111) {
tmp = t_0;
} else if (y <= -5.4e+23) {
tmp = t_1;
} else if (y <= -0.022) {
tmp = t_0;
} else if (y <= 0.32) {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
} else if (y <= 1.95e+149) {
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 <= -5.5e+111: tmp = t_0 elif y <= -5.4e+23: tmp = t_1 elif y <= -0.022: tmp = t_0 elif y <= 0.32: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) elif y <= 1.95e+149: 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 <= -5.5e+111) tmp = t_0; elseif (y <= -5.4e+23) tmp = t_1; elseif (y <= -0.022) tmp = t_0; elseif (y <= 0.32) tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); elseif (y <= 1.95e+149) 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 <= -5.5e+111) tmp = t_0; elseif (y <= -5.4e+23) tmp = t_1; elseif (y <= -0.022) tmp = t_0; elseif (y <= 0.32) tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); elseif (y <= 1.95e+149) 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, -5.5e+111], t$95$0, If[LessEqual[y, -5.4e+23], t$95$1, If[LessEqual[y, -0.022], t$95$0, If[LessEqual[y, 0.32], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e+149], 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 -5.5 \cdot 10^{+111}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.4 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -0.022:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.32:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+149}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.4999999999999998e111 or -5.3999999999999997e23 < y < -0.021999999999999999 or 1.95e149 < y Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 70.8%
if -5.4999999999999998e111 < y < -5.3999999999999997e23 or 0.320000000000000007 < y < 1.95e149Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around 0 67.4%
if -0.021999999999999999 < y < 0.320000000000000007Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 99.5%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e-69) (not (<= x 1.15e-75))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-69) || !(x <= 1.15e-75)) {
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.65d-69)) .or. (.not. (x <= 1.15d-75))) 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.65e-69) || !(x <= 1.15e-75)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e-69) or not (x <= 1.15e-75): 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.65e-69) || !(x <= 1.15e-75)) 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.65e-69) || ~((x <= 1.15e-75))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e-69], N[Not[LessEqual[x, 1.15e-75]], $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.65 \cdot 10^{-69} \lor \neg \left(x \leq 1.15 \cdot 10^{-75}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.65e-69 or 1.15e-75 < x Initial program 99.8%
Taylor expanded in y around 0 91.4%
if -1.65e-69 < x < 1.15e-75Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around 0 90.0%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.045) (not (<= y 2.1e-6))) (* x (sin y)) (+ z (* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.045) || !(y <= 2.1e-6)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (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.045d0)) .or. (.not. (y <= 2.1d-6))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.045) || !(y <= 2.1e-6)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.045) or not (y <= 2.1e-6): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.045) || !(y <= 2.1e-6)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.045) || ~((y <= 2.1e-6))) tmp = x * sin(y); else tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.045], N[Not[LessEqual[y, 2.1e-6]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.045 \lor \neg \left(y \leq 2.1 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.044999999999999998 or 2.0999999999999998e-6 < y Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 56.7%
if -0.044999999999999998 < y < 2.0999999999999998e-6Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 99.9%
Final simplification77.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e+86) (not (<= x 2.8e+206))) (* x y) (* x (/ z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+86) || !(x <= 2.8e+206)) {
tmp = x * y;
} else {
tmp = x * (z / 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 ((x <= (-1.5d+86)) .or. (.not. (x <= 2.8d+206))) then
tmp = x * y
else
tmp = x * (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+86) || !(x <= 2.8e+206)) {
tmp = x * y;
} else {
tmp = x * (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e+86) or not (x <= 2.8e+206): tmp = x * y else: tmp = x * (z / x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e+86) || !(x <= 2.8e+206)) tmp = Float64(x * y); else tmp = Float64(x * Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e+86) || ~((x <= 2.8e+206))) tmp = x * y; else tmp = x * (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e+86], N[Not[LessEqual[x, 2.8e+206]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * N[(z / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+86} \lor \neg \left(x \leq 2.8 \cdot 10^{+206}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{z}{x}\\
\end{array}
\end{array}
if x < -1.49999999999999988e86 or 2.7999999999999998e206 < x Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 54.5%
+-commutative54.5%
Simplified54.5%
Taylor expanded in x around inf 42.6%
*-commutative42.6%
Simplified42.6%
if -1.49999999999999988e86 < x < 2.7999999999999998e206Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 50.1%
+-commutative50.1%
Simplified50.1%
Taylor expanded in x around inf 44.5%
Taylor expanded in y around 0 38.7%
Final simplification40.0%
(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%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 51.6%
+-commutative51.6%
Simplified51.6%
Final simplification51.6%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 51.6%
+-commutative51.6%
Simplified51.6%
Taylor expanded in x around inf 20.2%
*-commutative20.2%
Simplified20.2%
Final simplification20.2%
herbie shell --seed 2024144
(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))))