
(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 7 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 -4e-35) (not (<= z 1.22e-57))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e-35) || !(z <= 1.22e-57)) {
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 <= (-4d-35)) .or. (.not. (z <= 1.22d-57))) 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 <= -4e-35) || !(z <= 1.22e-57)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e-35) or not (z <= 1.22e-57): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e-35) || !(z <= 1.22e-57)) 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 <= -4e-35) || ~((z <= 1.22e-57))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e-35], N[Not[LessEqual[z, 1.22e-57]], $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 -4 \cdot 10^{-35} \lor \neg \left(z \leq 1.22 \cdot 10^{-57}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -4.00000000000000003e-35 or 1.2200000000000001e-57 < z Initial program 99.8%
Taylor expanded in y around 0 89.7%
if -4.00000000000000003e-35 < z < 1.2200000000000001e-57Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 86.9%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.45e+64) (not (<= z 23000.0))) (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.45e+64) || !(z <= 23000.0)) {
tmp = 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 <= (-4.45d+64)) .or. (.not. (z <= 23000.0d0))) then
tmp = 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 <= -4.45e+64) || !(z <= 23000.0)) {
tmp = z * Math.sin(y);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.45e+64) or not (z <= 23000.0): tmp = z * math.sin(y) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.45e+64) || !(z <= 23000.0)) tmp = 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 <= -4.45e+64) || ~((z <= 23000.0))) tmp = z * sin(y); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.45e+64], N[Not[LessEqual[z, 23000.0]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.45 \cdot 10^{+64} \lor \neg \left(z \leq 23000\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -4.44999999999999988e64 or 23000 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 77.9%
if -4.44999999999999988e64 < z < 23000Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 81.4%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0042) (not (<= y 0.58))) (* 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 <= -0.0042) || !(y <= 0.58)) {
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 <= (-0.0042d0)) .or. (.not. (y <= 0.58d0))) 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 <= -0.0042) || !(y <= 0.58)) {
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 <= -0.0042) or not (y <= 0.58): 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 <= -0.0042) || !(y <= 0.58)) 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 <= -0.0042) || ~((y <= 0.58))) 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, -0.0042], N[Not[LessEqual[y, 0.58]], $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 -0.0042 \lor \neg \left(y \leq 0.58\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 < -0.00419999999999999974 or 0.57999999999999996 < y Initial program 99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around inf 49.3%
if -0.00419999999999999974 < y < 0.57999999999999996Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 99.3%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.7e+64) (not (<= z 4e+75))) (* y z) (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.7e+64) || !(z <= 4e+75)) {
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 <= (-4.7d+64)) .or. (.not. (z <= 4d+75))) 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 <= -4.7e+64) || !(z <= 4e+75)) {
tmp = y * z;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.7e+64) or not (z <= 4e+75): tmp = y * z else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.7e+64) || !(z <= 4e+75)) 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 <= -4.7e+64) || ~((z <= 4e+75))) tmp = y * z; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.7e+64], N[Not[LessEqual[z, 4e+75]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.7 \cdot 10^{+64} \lor \neg \left(z \leq 4 \cdot 10^{+75}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -4.70000000000000029e64 or 3.99999999999999971e75 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 45.1%
Taylor expanded in x around 0 32.6%
if -4.70000000000000029e64 < z < 3.99999999999999971e75Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 49.4%
Taylor expanded in y around inf 37.8%
Taylor expanded in z around 0 32.6%
Final simplification32.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.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 47.8%
(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 47.8%
Taylor expanded in x around 0 17.7%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))