
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * 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 = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * 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 = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.7%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= z -3.8e-127) (fma (sin y) z x) (if (<= z 520000.0) (* x (cos y)) (+ x (* z (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-127) {
tmp = fma(sin(y), z, x);
} else if (z <= 520000.0) {
tmp = x * cos(y);
} else {
tmp = x + (z * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.8e-127) tmp = fma(sin(y), z, x); elseif (z <= 520000.0) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(z * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.8e-127], N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[z, 520000.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-127}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
\mathbf{elif}\;z \leq 520000:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if z < -3.80000000000000003e-127Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 85.4%
if -3.80000000000000003e-127 < z < 5.2e5Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 89.8%
if 5.2e5 < z Initial program 99.8%
Taylor expanded in y around 0 89.6%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.05e-124) (not (<= z 1150000.0))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-124) || !(z <= 1150000.0)) {
tmp = x + (z * sin(y));
} else {
tmp = x * 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 ((z <= (-1.05d-124)) .or. (.not. (z <= 1150000.0d0))) then
tmp = x + (z * sin(y))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-124) || !(z <= 1150000.0)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.05e-124) or not (z <= 1150000.0): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.05e-124) || !(z <= 1150000.0)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.05e-124) || ~((z <= 1150000.0))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.05e-124], N[Not[LessEqual[z, 1150000.0]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-124} \lor \neg \left(z \leq 1150000\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.05e-124 or 1.15e6 < z Initial program 99.7%
Taylor expanded in y around 0 87.1%
if -1.05e-124 < z < 1.15e6Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 89.8%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.106) (not (<= y 0.000102))) (* z (sin y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.106) || !(y <= 0.000102)) {
tmp = z * sin(y);
} else {
tmp = x + (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 ((y <= (-0.106d0)) .or. (.not. (y <= 0.000102d0))) then
tmp = z * sin(y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.106) || !(y <= 0.000102)) {
tmp = z * Math.sin(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.106) or not (y <= 0.000102): tmp = z * math.sin(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.106) || !(y <= 0.000102)) tmp = Float64(z * sin(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.106) || ~((y <= 0.000102))) tmp = z * sin(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.106], N[Not[LessEqual[y, 0.000102]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.106 \lor \neg \left(y \leq 0.000102\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -0.105999999999999997 or 1.01999999999999999e-4 < y Initial program 99.5%
Taylor expanded in x around 0 47.4%
if -0.105999999999999997 < y < 1.01999999999999999e-4Initial program 100.0%
Taylor expanded in y around 0 99.7%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e-10) (not (<= x 1.2e-132))) (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-10) || !(x <= 1.2e-132)) {
tmp = x * cos(y);
} else {
tmp = z * sin(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.55d-10)) .or. (.not. (x <= 1.2d-132))) then
tmp = x * cos(y)
else
tmp = z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-10) || !(x <= 1.2e-132)) {
tmp = x * Math.cos(y);
} else {
tmp = z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e-10) or not (x <= 1.2e-132): tmp = x * math.cos(y) else: tmp = z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e-10) || !(x <= 1.2e-132)) tmp = Float64(x * cos(y)); else tmp = Float64(z * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e-10) || ~((x <= 1.2e-132))) tmp = x * cos(y); else tmp = z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e-10], N[Not[LessEqual[x, 1.2e-132]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-10} \lor \neg \left(x \leq 1.2 \cdot 10^{-132}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.55000000000000008e-10 or 1.20000000000000008e-132 < x Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in z around 0 83.9%
if -1.55000000000000008e-10 < x < 1.20000000000000008e-132Initial program 99.8%
Taylor expanded in x around 0 70.5%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z 1.4e+233) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.4e+233) {
tmp = x;
} else {
tmp = 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 (z <= 1.4d+233) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.4e+233) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.4e+233: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.4e+233) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.4e+233) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.4e+233], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.4 \cdot 10^{+233}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 1.40000000000000005e233Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 41.8%
if 1.40000000000000005e233 < z Initial program 99.9%
Taylor expanded in y around 0 64.6%
Taylor expanded in y around inf 57.0%
Final simplification42.6%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (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 + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 50.6%
Final simplification50.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 40.0%
Final simplification40.0%
herbie shell --seed 2023258
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))