
(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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma z (cos y) (+ x (sin y))))
double code(double x, double y, double z) {
return fma(z, cos(y), (x + sin(y)));
}
function code(x, y, z) return fma(z, cos(y), Float64(x + sin(y))) end
code[x_, y_, z_] := N[(z * N[Cos[y], $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \cos y, x + \sin y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
(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 + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e-8) (not (<= z 4.1e-53))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-8) || !(z <= 4.1e-53)) {
tmp = x + (z * cos(y));
} else {
tmp = 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.4d-8)) .or. (.not. (z <= 4.1d-53))) then
tmp = x + (z * cos(y))
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-8) || !(z <= 4.1e-53)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e-8) or not (z <= 4.1e-53): tmp = x + (z * math.cos(y)) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-8) || !(z <= 4.1e-53)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.4e-8) || ~((z <= 4.1e-53))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e-8], N[Not[LessEqual[z, 4.1e-53]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-8} \lor \neg \left(z \leq 4.1 \cdot 10^{-53}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -2.39999999999999998e-8 or 4.1000000000000001e-53 < z Initial program 99.9%
Taylor expanded in x around inf 99.0%
if -2.39999999999999998e-8 < z < 4.1000000000000001e-53Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around 0 94.2%
+-commutative94.2%
Simplified94.2%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -115000000.0) (not (<= z 3e+42))) (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -115000000.0) || !(z <= 3e+42)) {
tmp = z * cos(y);
} else {
tmp = 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 <= (-115000000.0d0)) .or. (.not. (z <= 3d+42))) then
tmp = z * cos(y)
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -115000000.0) || !(z <= 3e+42)) {
tmp = z * Math.cos(y);
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -115000000.0) or not (z <= 3e+42): tmp = z * math.cos(y) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -115000000.0) || !(z <= 3e+42)) tmp = Float64(z * cos(y)); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -115000000.0) || ~((z <= 3e+42))) tmp = z * cos(y); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -115000000.0], N[Not[LessEqual[z, 3e+42]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -115000000 \lor \neg \left(z \leq 3 \cdot 10^{+42}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -1.15e8 or 3.00000000000000029e42 < z Initial program 99.8%
+-commutative99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 73.8%
if -1.15e8 < z < 3.00000000000000029e42Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around 0 91.9%
+-commutative91.9%
Simplified91.9%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -580000000000.0) (not (<= x 2.3e-98))) (+ z x) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -580000000000.0) || !(x <= 2.3e-98)) {
tmp = z + x;
} else {
tmp = z * 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 ((x <= (-580000000000.0d0)) .or. (.not. (x <= 2.3d-98))) then
tmp = z + x
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -580000000000.0) || !(x <= 2.3e-98)) {
tmp = z + x;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -580000000000.0) or not (x <= 2.3e-98): tmp = z + x else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -580000000000.0) || !(x <= 2.3e-98)) tmp = Float64(z + x); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -580000000000.0) || ~((x <= 2.3e-98))) tmp = z + x; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -580000000000.0], N[Not[LessEqual[x, 2.3e-98]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -580000000000 \lor \neg \left(x \leq 2.3 \cdot 10^{-98}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -5.8e11 or 2.30000000000000001e-98 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 83.2%
if -5.8e11 < x < 2.30000000000000001e-98Initial program 99.8%
+-commutative99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 64.7%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e+21) (not (<= y 1.4e+28))) (+ z x) (+ (+ z x) (* y (+ 1.0 (* -0.5 (* z y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e+21) || !(y <= 1.4e+28)) {
tmp = z + x;
} else {
tmp = (z + x) + (y * (1.0 + (-0.5 * (z * 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 <= (-3.4d+21)) .or. (.not. (y <= 1.4d+28))) then
tmp = z + x
else
tmp = (z + x) + (y * (1.0d0 + ((-0.5d0) * (z * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e+21) || !(y <= 1.4e+28)) {
tmp = z + x;
} else {
tmp = (z + x) + (y * (1.0 + (-0.5 * (z * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e+21) or not (y <= 1.4e+28): tmp = z + x else: tmp = (z + x) + (y * (1.0 + (-0.5 * (z * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e+21) || !(y <= 1.4e+28)) tmp = Float64(z + x); else tmp = Float64(Float64(z + x) + Float64(y * Float64(1.0 + Float64(-0.5 * Float64(z * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e+21) || ~((y <= 1.4e+28))) tmp = z + x; else tmp = (z + x) + (y * (1.0 + (-0.5 * (z * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e+21], N[Not[LessEqual[y, 1.4e+28]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(z + x), $MachinePrecision] + N[(y * N[(1.0 + N[(-0.5 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+21} \lor \neg \left(y \leq 1.4 \cdot 10^{+28}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\left(z + x\right) + y \cdot \left(1 + -0.5 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -3.4e21 or 1.4000000000000001e28 < y Initial program 99.8%
+-commutative99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 45.0%
if -3.4e21 < y < 1.4000000000000001e28Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 95.9%
associate-+r+95.9%
Simplified95.9%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.4e+32) (not (<= y 3.8e+28))) (+ z x) (+ z (+ y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.4e+32) || !(y <= 3.8e+28)) {
tmp = z + x;
} else {
tmp = z + (y + x);
}
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 <= (-6.4d+32)) .or. (.not. (y <= 3.8d+28))) then
tmp = z + x
else
tmp = z + (y + x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.4e+32) || !(y <= 3.8e+28)) {
tmp = z + x;
} else {
tmp = z + (y + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.4e+32) or not (y <= 3.8e+28): tmp = z + x else: tmp = z + (y + x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.4e+32) || !(y <= 3.8e+28)) tmp = Float64(z + x); else tmp = Float64(z + Float64(y + x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.4e+32) || ~((y <= 3.8e+28))) tmp = z + x; else tmp = z + (y + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.4e+32], N[Not[LessEqual[y, 3.8e+28]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(z + N[(y + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{+32} \lor \neg \left(y \leq 3.8 \cdot 10^{+28}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;z + \left(y + x\right)\\
\end{array}
\end{array}
if y < -6.3999999999999998e32 or 3.7999999999999999e28 < y Initial program 99.8%
+-commutative99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 43.9%
if -6.3999999999999998e32 < y < 3.7999999999999999e28Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 94.4%
associate-+r+94.4%
+-commutative94.4%
Simplified94.4%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (<= x -520000000000.0) x (if (<= x 5e-5) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -520000000000.0) {
tmp = x;
} else if (x <= 5e-5) {
tmp = z;
} else {
tmp = x;
}
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 <= (-520000000000.0d0)) then
tmp = x
else if (x <= 5d-5) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -520000000000.0) {
tmp = x;
} else if (x <= 5e-5) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -520000000000.0: tmp = x elif x <= 5e-5: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -520000000000.0) tmp = x; elseif (x <= 5e-5) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -520000000000.0) tmp = x; elseif (x <= 5e-5) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -520000000000.0], x, If[LessEqual[x, 5e-5], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -520000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-5}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -5.2e11 or 5.00000000000000024e-5 < x Initial program 100.0%
expm1-log1p-u99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 75.0%
if -5.2e11 < x < 5.00000000000000024e-5Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 62.3%
Taylor expanded in y around 0 40.5%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + x;
}
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
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 68.0%
Final simplification68.0%
(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%
expm1-log1p-u99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 44.3%
herbie shell --seed 2024137
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))