
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.45e-16) (+ (* z (cos y)) (* x y)) (if (<= z 1.35e+69) (+ (* x (sin y)) z) (fma (cos y) z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e-16) {
tmp = (z * cos(y)) + (x * y);
} else if (z <= 1.35e+69) {
tmp = (x * sin(y)) + z;
} else {
tmp = fma(cos(y), z, (x * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.45e-16) tmp = Float64(Float64(z * cos(y)) + Float64(x * y)); elseif (z <= 1.35e+69) tmp = Float64(Float64(x * sin(y)) + z); else tmp = fma(cos(y), z, Float64(x * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.45e-16], N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.35e+69], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-16}:\\
\;\;\;\;z \cdot \cos y + x \cdot y\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+69}:\\
\;\;\;\;x \cdot \sin y + z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.4499999999999999e-16Initial program 99.7%
Taylor expanded in y around 0 81.2%
if -1.4499999999999999e-16 < z < 1.3499999999999999e69Initial program 99.7%
Taylor expanded in y around 0 89.0%
if 1.3499999999999999e69 < z Initial program 99.9%
add-cube-cbrt98.3%
pow398.4%
Applied egg-rr98.4%
Taylor expanded in y around 0 80.5%
+-commutative80.5%
unpow380.4%
add-cube-cbrt81.9%
*-commutative81.9%
fma-define81.9%
*-commutative81.9%
Applied egg-rr81.9%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-15) (not (<= z 6.5e+78))) (+ (* z (cos y)) (* x y)) (+ (* x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-15) || !(z <= 6.5e+78)) {
tmp = (z * cos(y)) + (x * y);
} else {
tmp = (x * sin(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.15d-15)) .or. (.not. (z <= 6.5d+78))) then
tmp = (z * cos(y)) + (x * y)
else
tmp = (x * sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-15) || !(z <= 6.5e+78)) {
tmp = (z * Math.cos(y)) + (x * y);
} else {
tmp = (x * Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-15) or not (z <= 6.5e+78): tmp = (z * math.cos(y)) + (x * y) else: tmp = (x * math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-15) || !(z <= 6.5e+78)) tmp = Float64(Float64(z * cos(y)) + Float64(x * y)); else tmp = Float64(Float64(x * sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-15) || ~((z <= 6.5e+78))) tmp = (z * cos(y)) + (x * y); else tmp = (x * sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-15], N[Not[LessEqual[z, 6.5e+78]], $MachinePrecision]], N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-15} \lor \neg \left(z \leq 6.5 \cdot 10^{+78}\right):\\
\;\;\;\;z \cdot \cos y + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if z < -1.14999999999999995e-15 or 6.50000000000000036e78 < z Initial program 99.8%
Taylor expanded in y around 0 81.5%
if -1.14999999999999995e-15 < z < 6.50000000000000036e78Initial program 99.7%
Taylor expanded in y around 0 89.0%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) z))
double code(double x, double y, double z) {
return (x * sin(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 * sin(y)) + z
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + z;
}
def code(x, y, z): return (x * math.sin(y)) + z
function code(x, y, z) return Float64(Float64(x * sin(y)) + z) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + z; end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 75.6%
Final simplification75.6%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2.05e+92)
(and (not (<= x 1.7e+43)) (or (<= x 7.4e+77) (not (<= x 1.05e+162)))))
(* x y)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e+92) || (!(x <= 1.7e+43) && ((x <= 7.4e+77) || !(x <= 1.05e+162)))) {
tmp = x * y;
} else {
tmp = 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 <= (-2.05d+92)) .or. (.not. (x <= 1.7d+43)) .and. (x <= 7.4d+77) .or. (.not. (x <= 1.05d+162))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e+92) || (!(x <= 1.7e+43) && ((x <= 7.4e+77) || !(x <= 1.05e+162)))) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.05e+92) or (not (x <= 1.7e+43) and ((x <= 7.4e+77) or not (x <= 1.05e+162))): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.05e+92) || (!(x <= 1.7e+43) && ((x <= 7.4e+77) || !(x <= 1.05e+162)))) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.05e+92) || (~((x <= 1.7e+43)) && ((x <= 7.4e+77) || ~((x <= 1.05e+162))))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.05e+92], And[N[Not[LessEqual[x, 1.7e+43]], $MachinePrecision], Or[LessEqual[x, 7.4e+77], N[Not[LessEqual[x, 1.05e+162]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+92} \lor \neg \left(x \leq 1.7 \cdot 10^{+43}\right) \land \left(x \leq 7.4 \cdot 10^{+77} \lor \neg \left(x \leq 1.05 \cdot 10^{+162}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.05000000000000012e92 or 1.70000000000000006e43 < x < 7.3999999999999999e77 or 1.05e162 < x Initial program 99.7%
Taylor expanded in y around 0 66.6%
Taylor expanded in y around 0 51.9%
+-commutative51.9%
Simplified51.9%
Taylor expanded in x around inf 42.3%
*-commutative42.3%
Simplified42.3%
if -2.05000000000000012e92 < x < 1.70000000000000006e43 or 7.3999999999999999e77 < x < 1.05e162Initial program 99.8%
Taylor expanded in y around 0 50.1%
Taylor expanded in y around 0 44.6%
Final simplification43.8%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 55.6%
Taylor expanded in y around 0 48.0%
+-commutative48.0%
Simplified48.0%
Final simplification48.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 55.6%
Taylor expanded in y around 0 33.3%
Final simplification33.3%
herbie shell --seed 2024048
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))