
(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 8 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 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * 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 = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -1.42e+163)
t_0
(if (<= y -7.4e+30)
t_1
(if (<= y -0.023)
t_0
(if (<= y 0.022)
(+
z
(* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))
(if (or (<= y 240000000000.0) (not (<= y 7.7e+239))) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -1.42e+163) {
tmp = t_0;
} else if (y <= -7.4e+30) {
tmp = t_1;
} else if (y <= -0.023) {
tmp = t_0;
} else if (y <= 0.022) {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
} else if ((y <= 240000000000.0) || !(y <= 7.7e+239)) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = z * cos(y)
t_1 = x * sin(y)
if (y <= (-1.42d+163)) then
tmp = t_0
else if (y <= (-7.4d+30)) then
tmp = t_1
else if (y <= (-0.023d0)) then
tmp = t_0
else if (y <= 0.022d0) then
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
else if ((y <= 240000000000.0d0) .or. (.not. (y <= 7.7d+239))) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double t_1 = x * Math.sin(y);
double tmp;
if (y <= -1.42e+163) {
tmp = t_0;
} else if (y <= -7.4e+30) {
tmp = t_1;
} else if (y <= -0.023) {
tmp = t_0;
} else if (y <= 0.022) {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
} else if ((y <= 240000000000.0) || !(y <= 7.7e+239)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -1.42e+163: tmp = t_0 elif y <= -7.4e+30: tmp = t_1 elif y <= -0.023: tmp = t_0 elif y <= 0.022: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) elif (y <= 240000000000.0) or not (y <= 7.7e+239): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -1.42e+163) tmp = t_0; elseif (y <= -7.4e+30) tmp = t_1; elseif (y <= -0.023) tmp = t_0; elseif (y <= 0.022) tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); elseif ((y <= 240000000000.0) || !(y <= 7.7e+239)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = x * sin(y); tmp = 0.0; if (y <= -1.42e+163) tmp = t_0; elseif (y <= -7.4e+30) tmp = t_1; elseif (y <= -0.023) tmp = t_0; elseif (y <= 0.022) tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); elseif ((y <= 240000000000.0) || ~((y <= 7.7e+239))) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.42e+163], t$95$0, If[LessEqual[y, -7.4e+30], t$95$1, If[LessEqual[y, -0.023], t$95$0, If[LessEqual[y, 0.022], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 240000000000.0], N[Not[LessEqual[y, 7.7e+239]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.42 \cdot 10^{+163}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -7.4 \cdot 10^{+30}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -0.023:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.022:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\mathbf{elif}\;y \leq 240000000000 \lor \neg \left(y \leq 7.7 \cdot 10^{+239}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.4199999999999999e163 or -7.40000000000000032e30 < y < -0.023 or 0.021999999999999999 < y < 2.4e11 or 7.69999999999999994e239 < y Initial program 99.7%
Taylor expanded in x around 0 76.3%
if -1.4199999999999999e163 < y < -7.40000000000000032e30 or 2.4e11 < y < 7.69999999999999994e239Initial program 99.5%
Taylor expanded in x around inf 67.2%
if -0.023 < y < 0.021999999999999999Initial program 100.0%
Taylor expanded in y around 0 99.8%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e+154) (not (<= z 2.15e+145))) (* z (cos y)) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e+154) || !(z <= 2.15e+145)) {
tmp = z * cos(y);
} else {
tmp = z + (x * 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 ((z <= (-2.8d+154)) .or. (.not. (z <= 2.15d+145))) then
tmp = z * cos(y)
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e+154) || !(z <= 2.15e+145)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e+154) or not (z <= 2.15e+145): tmp = z * math.cos(y) else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e+154) || !(z <= 2.15e+145)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e+154) || ~((z <= 2.15e+145))) tmp = z * cos(y); else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e+154], N[Not[LessEqual[z, 2.15e+145]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+154} \lor \neg \left(z \leq 2.15 \cdot 10^{+145}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -2.7999999999999999e154 or 2.14999999999999999e145 < z Initial program 99.8%
Taylor expanded in x around 0 92.2%
if -2.7999999999999999e154 < z < 2.14999999999999999e145Initial program 99.8%
Taylor expanded in y around 0 85.7%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.33) (not (<= y 0.00078))) (* x (sin y)) (+ z (* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.33) || !(y <= 0.00078)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (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 ((y <= (-0.33d0)) .or. (.not. (y <= 0.00078d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.33) || !(y <= 0.00078)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.33) or not (y <= 0.00078): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.33) || !(y <= 0.00078)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.33) || ~((y <= 0.00078))) tmp = x * sin(y); else tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.33], N[Not[LessEqual[y, 0.00078]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.33 \lor \neg \left(y \leq 0.00078\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.330000000000000016 or 7.79999999999999986e-4 < y Initial program 99.6%
Taylor expanded in x around inf 52.1%
if -0.330000000000000016 < y < 7.79999999999999986e-4Initial program 100.0%
Taylor expanded in y around 0 99.5%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e+72) (not (<= x 6e+231))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e+72) || !(x <= 6e+231)) {
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 <= (-4.5d+72)) .or. (.not. (x <= 6d+231))) 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 <= -4.5e+72) || !(x <= 6e+231)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e+72) or not (x <= 6e+231): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e+72) || !(x <= 6e+231)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e+72) || ~((x <= 6e+231))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e+72], N[Not[LessEqual[x, 6e+231]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+72} \lor \neg \left(x \leq 6 \cdot 10^{+231}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.4999999999999998e72 or 6.0000000000000003e231 < x Initial program 99.8%
Taylor expanded in y around 0 45.0%
*-commutative45.0%
Simplified45.0%
Taylor expanded in z around 0 34.7%
*-commutative34.7%
Simplified34.7%
if -4.4999999999999998e72 < x < 6.0000000000000003e231Initial program 99.8%
Taylor expanded in x around 0 74.5%
Taylor expanded in y around 0 48.5%
Final simplification44.5%
(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.8%
Taylor expanded in y around 0 53.5%
*-commutative53.5%
Simplified53.5%
Final simplification53.5%
(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.8%
Taylor expanded in x around 0 59.2%
Taylor expanded in y around 0 38.5%
Final simplification38.5%
herbie shell --seed 2024115
(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))))