
(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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-96) (not (<= z 5.9e-220))) (+ x (* z (sin y))) (+ (* x (cos y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-96) || !(z <= 5.9e-220)) {
tmp = x + (z * sin(y));
} else {
tmp = (x * cos(y)) + (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 <= (-6.5d-96)) .or. (.not. (z <= 5.9d-220))) then
tmp = x + (z * sin(y))
else
tmp = (x * cos(y)) + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-96) || !(z <= 5.9e-220)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = (x * Math.cos(y)) + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-96) or not (z <= 5.9e-220): tmp = x + (z * math.sin(y)) else: tmp = (x * math.cos(y)) + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-96) || !(z <= 5.9e-220)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(Float64(x * cos(y)) + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e-96) || ~((z <= 5.9e-220))) tmp = x + (z * sin(y)); else tmp = (x * cos(y)) + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-96], N[Not[LessEqual[z, 5.9e-220]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-96} \lor \neg \left(z \leq 5.9 \cdot 10^{-220}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y + y \cdot z\\
\end{array}
\end{array}
if z < -6.50000000000000001e-96 or 5.8999999999999996e-220 < z Initial program 99.9%
Taylor expanded in y around 0 90.6%
if -6.50000000000000001e-96 < z < 5.8999999999999996e-220Initial program 99.8%
Taylor expanded in y around 0 79.7%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-95) (not (<= z 2.5e-107))) (+ x (* z (sin y))) (/ 1.0 (/ 1.0 (* x (cos y))))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-95) || !(z <= 2.5e-107)) {
tmp = x + (z * sin(y));
} else {
tmp = 1.0 / (1.0 / (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-95)) .or. (.not. (z <= 2.5d-107))) then
tmp = x + (z * sin(y))
else
tmp = 1.0d0 / (1.0d0 / (x * cos(y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-95) || !(z <= 2.5e-107)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = 1.0 / (1.0 / (x * Math.cos(y)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-95) or not (z <= 2.5e-107): tmp = x + (z * math.sin(y)) else: tmp = 1.0 / (1.0 / (x * math.cos(y))) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-95) || !(z <= 2.5e-107)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(1.0 / Float64(1.0 / Float64(x * cos(y)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-95) || ~((z <= 2.5e-107))) tmp = x + (z * sin(y)); else tmp = 1.0 / (1.0 / (x * cos(y))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-95], N[Not[LessEqual[z, 2.5e-107]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 / N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-95} \lor \neg \left(z \leq 2.5 \cdot 10^{-107}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{x \cdot \cos y}}\\
\end{array}
\end{array}
if z < -3e-95 or 2.49999999999999985e-107 < z Initial program 99.9%
Taylor expanded in y around 0 92.1%
if -3e-95 < z < 2.49999999999999985e-107Initial program 99.8%
Taylor expanded in y around 0 79.3%
flip-+47.8%
clear-num47.6%
*-commutative47.6%
pow247.6%
*-commutative47.6%
pow247.6%
Applied egg-rr47.6%
Taylor expanded in x around inf 94.4%
Final simplification92.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0074) (not (<= y 0.044))) (* z (sin y)) (+ (* y z) (* x (+ 1.0 (* -0.5 (* y y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0074) || !(y <= 0.044)) {
tmp = z * sin(y);
} else {
tmp = (y * z) + (x * (1.0 + (-0.5 * (y * 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.0074d0)) .or. (.not. (y <= 0.044d0))) then
tmp = z * sin(y)
else
tmp = (y * z) + (x * (1.0d0 + ((-0.5d0) * (y * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0074) || !(y <= 0.044)) {
tmp = z * Math.sin(y);
} else {
tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0074) or not (y <= 0.044): tmp = z * math.sin(y) else: tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0074) || !(y <= 0.044)) tmp = Float64(z * sin(y)); else tmp = Float64(Float64(y * z) + Float64(x * Float64(1.0 + Float64(-0.5 * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0074) || ~((y <= 0.044))) tmp = z * sin(y); else tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0074], N[Not[LessEqual[y, 0.044]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] + N[(x * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0074 \lor \neg \left(y \leq 0.044\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z + x \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -0.0074000000000000003 or 0.043999999999999997 < y Initial program 99.7%
Taylor expanded in x around 0 57.4%
if -0.0074000000000000003 < y < 0.043999999999999997Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in y around 0 99.8%
unpow299.8%
Simplified99.8%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (+ x (* z (sin y))))
double code(double x, double y, double z) {
return x + (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 + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return x + (z * Math.sin(y));
}
def code(x, y, z): return x + (z * math.sin(y))
function code(x, y, z) return Float64(x + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = x + (z * sin(y)); end
code[x_, y_, z_] := N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \sin y
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 82.6%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e+153) (* y z) (if (<= z 5.5e+191) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+153) {
tmp = y * z;
} else if (z <= 5.5e+191) {
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.05d+153)) then
tmp = y * z
else if (z <= 5.5d+191) 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.05e+153) {
tmp = y * z;
} else if (z <= 5.5e+191) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e+153: tmp = y * z elif z <= 5.5e+191: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e+153) tmp = Float64(y * z); elseif (z <= 5.5e+191) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.05e+153) tmp = y * z; elseif (z <= 5.5e+191) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e+153], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.5e+191], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+153}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+191}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.05000000000000008e153 or 5.5000000000000002e191 < z Initial program 99.8%
Taylor expanded in y around 0 57.4%
Taylor expanded in y around inf 47.0%
if -1.05000000000000008e153 < z < 5.5000000000000002e191Initial program 99.9%
Taylor expanded in y around 0 70.1%
flip-+43.3%
clear-num43.2%
*-commutative43.2%
pow243.2%
*-commutative43.2%
pow243.2%
Applied egg-rr43.2%
Taylor expanded in y around 0 54.0%
clear-num54.1%
div-inv54.1%
metadata-eval54.1%
Applied egg-rr54.1%
Final simplification52.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.9%
Taylor expanded in y around 0 59.3%
Final simplification59.3%
(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.9%
Taylor expanded in y around 0 67.2%
flip-+42.2%
clear-num42.0%
*-commutative42.0%
pow242.0%
*-commutative42.0%
pow242.0%
Applied egg-rr42.0%
Taylor expanded in y around 0 44.3%
clear-num44.4%
div-inv44.4%
metadata-eval44.4%
Applied egg-rr44.4%
Final simplification44.4%
herbie shell --seed 2023171
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))