
(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 8 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 (+ (* 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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.3e-25) (not (<= z 8.5e-60))) (* x (+ 1.0 (* z (/ (sin y) x)))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.3e-25) || !(z <= 8.5e-60)) {
tmp = x * (1.0 + (z * (sin(y) / x)));
} 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 <= (-3.3d-25)) .or. (.not. (z <= 8.5d-60))) then
tmp = x * (1.0d0 + (z * (sin(y) / x)))
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 <= -3.3e-25) || !(z <= 8.5e-60)) {
tmp = x * (1.0 + (z * (Math.sin(y) / x)));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.3e-25) or not (z <= 8.5e-60): tmp = x * (1.0 + (z * (math.sin(y) / x))) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.3e-25) || !(z <= 8.5e-60)) tmp = Float64(x * Float64(1.0 + Float64(z * Float64(sin(y) / x)))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.3e-25) || ~((z <= 8.5e-60))) tmp = x * (1.0 + (z * (sin(y) / x))); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.3e-25], N[Not[LessEqual[z, 8.5e-60]], $MachinePrecision]], N[(x * N[(1.0 + N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-25} \lor \neg \left(z \leq 8.5 \cdot 10^{-60}\right):\\
\;\;\;\;x \cdot \left(1 + z \cdot \frac{\sin y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -3.2999999999999998e-25 or 8.50000000000000044e-60 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 87.7%
associate-/l*87.6%
Simplified87.6%
Taylor expanded in y around 0 76.5%
if -3.2999999999999998e-25 < z < 8.50000000000000044e-60Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 92.9%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00185) (not (<= y 0.00039))) (* z (sin y)) (+ x (* y (+ z (* -0.5 (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00185) || !(y <= 0.00039)) {
tmp = z * sin(y);
} else {
tmp = x + (y * (z + (-0.5 * (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.00185d0)) .or. (.not. (y <= 0.00039d0))) then
tmp = z * sin(y)
else
tmp = x + (y * (z + ((-0.5d0) * (x * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00185) || !(y <= 0.00039)) {
tmp = z * Math.sin(y);
} else {
tmp = x + (y * (z + (-0.5 * (x * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00185) or not (y <= 0.00039): tmp = z * math.sin(y) else: tmp = x + (y * (z + (-0.5 * (x * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00185) || !(y <= 0.00039)) tmp = Float64(z * sin(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(-0.5 * Float64(x * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00185) || ~((y <= 0.00039))) tmp = z * sin(y); else tmp = x + (y * (z + (-0.5 * (x * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00185], N[Not[LessEqual[y, 0.00039]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(-0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00185 \lor \neg \left(y \leq 0.00039\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + -0.5 \cdot \left(x \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -0.0018500000000000001 or 3.89999999999999993e-4 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 55.0%
if -0.0018500000000000001 < y < 3.89999999999999993e-4Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -215000000.0) (not (<= y 1.4e+15))) (* x (cos y)) (+ x (* y (+ z (* y (+ (* x -0.5) (* -0.16666666666666666 (* y z)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -215000000.0) || !(y <= 1.4e+15)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (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 <= (-215000000.0d0)) .or. (.not. (y <= 1.4d+15))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * ((x * (-0.5d0)) + ((-0.16666666666666666d0) * (y * z))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -215000000.0) || !(y <= 1.4e+15)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -215000000.0) or not (y <= 1.4e+15): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -215000000.0) || !(y <= 1.4e+15)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(Float64(x * -0.5) + Float64(-0.16666666666666666 * Float64(y * z))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -215000000.0) || ~((y <= 1.4e+15))) tmp = x * cos(y); else tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -215000000.0], N[Not[LessEqual[y, 1.4e+15]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -215000000 \lor \neg \left(y \leq 1.4 \cdot 10^{+15}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5 + -0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)\\
\end{array}
\end{array}
if y < -2.15e8 or 1.4e15 < y Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 49.1%
if -2.15e8 < y < 1.4e15Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 96.7%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-268) (not (<= x 3.6e-177))) (* z (/ x z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-268) || !(x <= 3.6e-177)) {
tmp = z * (x / z);
} 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 ((x <= (-1.2d-268)) .or. (.not. (x <= 3.6d-177))) then
tmp = z * (x / z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-268) || !(x <= 3.6e-177)) {
tmp = z * (x / z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-268) or not (x <= 3.6e-177): tmp = z * (x / z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-268) || !(x <= 3.6e-177)) tmp = Float64(z * Float64(x / z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-268) || ~((x <= 3.6e-177))) tmp = z * (x / z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-268], N[Not[LessEqual[x, 3.6e-177]], $MachinePrecision]], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-268} \lor \neg \left(x \leq 3.6 \cdot 10^{-177}\right):\\
\;\;\;\;z \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.1999999999999999e-268 or 3.59999999999999983e-177 < x Initial program 99.8%
expm1-log1p-u99.8%
Applied egg-rr99.8%
expm1-undefine99.6%
flip--99.6%
log1p-undefine99.6%
rem-exp-log99.6%
+-commutative99.6%
log1p-undefine99.5%
rem-exp-log99.5%
+-commutative99.5%
metadata-eval99.5%
log1p-undefine99.5%
rem-exp-log99.6%
+-commutative99.6%
Applied egg-rr99.6%
difference-of-sqr-199.6%
associate--l+99.8%
metadata-eval99.8%
+-rgt-identity99.8%
associate-/l*99.8%
associate-+l+99.8%
metadata-eval99.8%
associate-+l+99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around inf 88.4%
+-commutative88.4%
distribute-lft-in88.4%
associate-*l/88.3%
associate-/r/88.4%
distribute-lft-out88.3%
associate-/r/88.3%
fma-define88.3%
Simplified88.3%
Taylor expanded in y around 0 39.5%
if -1.1999999999999999e-268 < x < 3.59999999999999983e-177Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 52.9%
Taylor expanded in x around 0 42.8%
Final simplification39.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.9e+223) (not (<= z 6e+129))) (* y z) (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.9e+223) || !(z <= 6e+129)) {
tmp = y * z;
} else {
tmp = y * (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 ((z <= (-3.9d+223)) .or. (.not. (z <= 6d+129))) then
tmp = y * z
else
tmp = y * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.9e+223) || !(z <= 6e+129)) {
tmp = y * z;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.9e+223) or not (z <= 6e+129): tmp = y * z else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.9e+223) || !(z <= 6e+129)) tmp = Float64(y * z); else tmp = Float64(y * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.9e+223) || ~((z <= 6e+129))) tmp = y * z; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.9e+223], N[Not[LessEqual[z, 6e+129]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.9 \cdot 10^{+223} \lor \neg \left(z \leq 6 \cdot 10^{+129}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.8999999999999999e223 or 6.0000000000000006e129 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 54.8%
Taylor expanded in x around 0 32.2%
if -3.8999999999999999e223 < z < 6.0000000000000006e129Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 52.6%
Taylor expanded in y around inf 44.4%
Taylor expanded in z around 0 38.0%
Final simplification36.5%
(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.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 53.2%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return 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 = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 53.2%
Taylor expanded in x around 0 15.7%
herbie shell --seed 2024160
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))