
(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 (fma z (sin y) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, sin(y), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * N[Sin[y], $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Final simplification99.7%
(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.7%
Final simplification99.7%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.05e+51)
(and (not (<= x -5.4e-39))
(or (<= x -6.8e-123) (not (<= x 4.2e-113)))))
(* x (cos y))
(* z (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e+51) || (!(x <= -5.4e-39) && ((x <= -6.8e-123) || !(x <= 4.2e-113)))) {
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.05d+51)) .or. (.not. (x <= (-5.4d-39))) .and. (x <= (-6.8d-123)) .or. (.not. (x <= 4.2d-113))) 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.05e+51) || (!(x <= -5.4e-39) && ((x <= -6.8e-123) || !(x <= 4.2e-113)))) {
tmp = x * Math.cos(y);
} else {
tmp = z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e+51) or (not (x <= -5.4e-39) and ((x <= -6.8e-123) or not (x <= 4.2e-113))): tmp = x * math.cos(y) else: tmp = z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e+51) || (!(x <= -5.4e-39) && ((x <= -6.8e-123) || !(x <= 4.2e-113)))) 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.05e+51) || (~((x <= -5.4e-39)) && ((x <= -6.8e-123) || ~((x <= 4.2e-113))))) tmp = x * cos(y); else tmp = z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e+51], And[N[Not[LessEqual[x, -5.4e-39]], $MachinePrecision], Or[LessEqual[x, -6.8e-123], N[Not[LessEqual[x, 4.2e-113]], $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.05 \cdot 10^{+51} \lor \neg \left(x \leq -5.4 \cdot 10^{-39}\right) \land \left(x \leq -6.8 \cdot 10^{-123} \lor \neg \left(x \leq 4.2 \cdot 10^{-113}\right)\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if x < -1.0500000000000001e51 or -5.4000000000000001e-39 < x < -6.8000000000000001e-123 or 4.2e-113 < x Initial program 99.8%
Taylor expanded in x around inf 83.1%
if -1.0500000000000001e51 < x < -5.4000000000000001e-39 or -6.8000000000000001e-123 < x < 4.2e-113Initial program 99.6%
Taylor expanded in x around 0 82.1%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-27) (not (<= z 7800000000.0))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-27) || !(z <= 7800000000.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 <= (-3d-27)) .or. (.not. (z <= 7800000000.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 <= -3e-27) || !(z <= 7800000000.0)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-27) or not (z <= 7800000000.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 <= -3e-27) || !(z <= 7800000000.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 <= -3e-27) || ~((z <= 7800000000.0))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-27], N[Not[LessEqual[z, 7800000000.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 -3 \cdot 10^{-27} \lor \neg \left(z \leq 7800000000\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -3.0000000000000001e-27 or 7.8e9 < z Initial program 99.7%
Taylor expanded in y around 0 90.9%
if -3.0000000000000001e-27 < z < 7.8e9Initial program 99.8%
Taylor expanded in x around inf 91.3%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.9e-5) (not (<= y 2.5e-8))) (* x (cos y)) (+ x (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.9e-5) || !(y <= 2.5e-8)) {
tmp = x * cos(y);
} else {
tmp = x + (z * 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 <= (-4.9d-5)) .or. (.not. (y <= 2.5d-8))) then
tmp = x * cos(y)
else
tmp = x + (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.9e-5) || !(y <= 2.5e-8)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.9e-5) or not (y <= 2.5e-8): tmp = x * math.cos(y) else: tmp = x + (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.9e-5) || !(y <= 2.5e-8)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.9e-5) || ~((y <= 2.5e-8))) tmp = x * cos(y); else tmp = x + (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.9e-5], N[Not[LessEqual[y, 2.5e-8]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{-5} \lor \neg \left(y \leq 2.5 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot y\\
\end{array}
\end{array}
if y < -4.9e-5 or 2.4999999999999999e-8 < y Initial program 99.6%
Taylor expanded in x around inf 47.7%
if -4.9e-5 < y < 2.4999999999999999e-8Initial program 100.0%
Taylor expanded in y around 0 99.8%
+-commutative99.8%
Simplified99.8%
Final simplification69.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e+93) (* z y) (if (<= z 3.6e+244) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+93) {
tmp = z * y;
} else if (z <= 3.6e+244) {
tmp = x;
} else {
tmp = z * 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+93)) then
tmp = z * y
else if (z <= 3.6d+244) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+93) {
tmp = z * y;
} else if (z <= 3.6e+244) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e+93: tmp = z * y elif z <= 3.6e+244: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e+93) tmp = Float64(z * y); elseif (z <= 3.6e+244) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.05e+93) tmp = z * y; elseif (z <= 3.6e+244) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e+93], N[(z * y), $MachinePrecision], If[LessEqual[z, 3.6e+244], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+93}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+244}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.0499999999999999e93 or 3.6e244 < z Initial program 99.7%
Taylor expanded in y around 0 37.2%
+-commutative37.2%
Simplified37.2%
Taylor expanded in y around inf 34.0%
if -1.0499999999999999e93 < z < 3.6e244Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.3%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 44.5%
Final simplification42.0%
(FPCore (x y z) :precision binary64 (+ x (* z y)))
double code(double x, double y, double z) {
return x + (z * 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 + (z * y)
end function
public static double code(double x, double y, double z) {
return x + (z * y);
}
def code(x, y, z): return x + (z * y)
function code(x, y, z) return Float64(x + Float64(z * y)) end
function tmp = code(x, y, z) tmp = x + (z * y); end
code[x_, y_, z_] := N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot y
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 46.2%
+-commutative46.2%
Simplified46.2%
Final simplification46.2%
(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%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 35.4%
Final simplification35.4%
herbie shell --seed 2023285
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))