
(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 5 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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -72000000.0) (not (<= y 0.035))) (* x (cos y)) (+ x (* y (+ z (* y (* x -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -72000000.0) || !(y <= 0.035)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
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 <= (-72000000.0d0)) .or. (.not. (y <= 0.035d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -72000000.0) || !(y <= 0.035)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -72000000.0) or not (y <= 0.035): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -72000000.0) || !(y <= 0.035)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -72000000.0) || ~((y <= 0.035))) tmp = x * cos(y); else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -72000000.0], N[Not[LessEqual[y, 0.035]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -72000000 \lor \neg \left(y \leq 0.035\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -7.2e7 or 0.035000000000000003 < y Initial program 99.7%
Taylor expanded in x around inf 53.5%
if -7.2e7 < y < 0.035000000000000003Initial program 100.0%
Taylor expanded in y around 0 97.5%
+-commutative97.5%
*-commutative97.5%
associate-*r*97.5%
unpow297.5%
associate-*r*97.5%
distribute-rgt-out97.5%
*-commutative97.5%
*-commutative97.5%
Simplified97.5%
Final simplification73.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+61) (not (<= z 3.35e+22))) (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+61) || !(z <= 3.35e+22)) {
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 <= (-2.2d+61)) .or. (.not. (z <= 3.35d+22))) 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 <= -2.2e+61) || !(z <= 3.35e+22)) {
tmp = z * Math.sin(y);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+61) or not (z <= 3.35e+22): tmp = z * math.sin(y) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+61) || !(z <= 3.35e+22)) 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 <= -2.2e+61) || ~((z <= 3.35e+22))) tmp = z * sin(y); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+61], N[Not[LessEqual[z, 3.35e+22]], $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 -2.2 \cdot 10^{+61} \lor \neg \left(z \leq 3.35 \cdot 10^{+22}\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -2.2e61 or 3.3500000000000001e22 < z Initial program 99.8%
Taylor expanded in x around 0 71.4%
if -2.2e61 < z < 3.3500000000000001e22Initial program 99.9%
Taylor expanded in x around inf 85.1%
Final simplification79.2%
(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.9%
Taylor expanded in y around 0 48.5%
+-commutative48.5%
Simplified48.5%
Final simplification48.5%
(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.9%
Taylor expanded in y around 0 48.5%
+-commutative48.5%
Simplified48.5%
Taylor expanded in y around inf 15.9%
Final simplification15.9%
herbie shell --seed 2024048
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))