
(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 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}
\\
\left(x + \sin y\right) + 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -7.5e+73)
t_0
(if (<= z -2.1e-130)
(+ x z)
(if (<= z 4.4e-55) (+ x (sin y)) (if (<= z 1.85e+105) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -7.5e+73) {
tmp = t_0;
} else if (z <= -2.1e-130) {
tmp = x + z;
} else if (z <= 4.4e-55) {
tmp = x + sin(y);
} else if (z <= 1.85e+105) {
tmp = x + z;
} else {
tmp = t_0;
}
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) :: tmp
t_0 = z * cos(y)
if (z <= (-7.5d+73)) then
tmp = t_0
else if (z <= (-2.1d-130)) then
tmp = x + z
else if (z <= 4.4d-55) then
tmp = x + sin(y)
else if (z <= 1.85d+105) then
tmp = x + z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -7.5e+73) {
tmp = t_0;
} else if (z <= -2.1e-130) {
tmp = x + z;
} else if (z <= 4.4e-55) {
tmp = x + Math.sin(y);
} else if (z <= 1.85e+105) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -7.5e+73: tmp = t_0 elif z <= -2.1e-130: tmp = x + z elif z <= 4.4e-55: tmp = x + math.sin(y) elif z <= 1.85e+105: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -7.5e+73) tmp = t_0; elseif (z <= -2.1e-130) tmp = Float64(x + z); elseif (z <= 4.4e-55) tmp = Float64(x + sin(y)); elseif (z <= 1.85e+105) tmp = Float64(x + z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -7.5e+73) tmp = t_0; elseif (z <= -2.1e-130) tmp = x + z; elseif (z <= 4.4e-55) tmp = x + sin(y); elseif (z <= 1.85e+105) tmp = x + z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.5e+73], t$95$0, If[LessEqual[z, -2.1e-130], N[(x + z), $MachinePrecision], If[LessEqual[z, 4.4e-55], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.85e+105], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -7.5 \cdot 10^{+73}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-130}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-55}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{+105}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -7.5e73 or 1.84999999999999992e105 < z Initial program 99.7%
Taylor expanded in z around inf 87.4%
if -7.5e73 < z < -2.10000000000000002e-130 or 4.3999999999999999e-55 < z < 1.84999999999999992e105Initial program 99.9%
Taylor expanded in y around 0 81.0%
+-commutative81.0%
Simplified81.0%
if -2.10000000000000002e-130 < z < 4.3999999999999999e-55Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.1e-129) (not (<= z 7.5e-53))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.1e-129) || !(z <= 7.5e-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 <= (-5.1d-129)) .or. (.not. (z <= 7.5d-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 <= -5.1e-129) || !(z <= 7.5e-53)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.1e-129) or not (z <= 7.5e-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 <= -5.1e-129) || !(z <= 7.5e-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 <= -5.1e-129) || ~((z <= 7.5e-53))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.1e-129], N[Not[LessEqual[z, 7.5e-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 -5.1 \cdot 10^{-129} \lor \neg \left(z \leq 7.5 \cdot 10^{-53}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -5.0999999999999999e-129 or 7.5000000000000001e-53 < z Initial program 99.8%
Taylor expanded in x around inf 94.3%
if -5.0999999999999999e-129 < z < 7.5000000000000001e-53Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification95.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.06) (not (<= z 0.02))) (+ x (* z (cos y))) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.06) || !(z <= 0.02)) {
tmp = x + (z * cos(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.06d0)) .or. (.not. (z <= 0.02d0))) then
tmp = x + (z * cos(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.06) || !(z <= 0.02)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.06) or not (z <= 0.02): tmp = x + (z * math.cos(y)) else: tmp = (x + math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.06) || !(z <= 0.02)) tmp = Float64(x + Float64(z * cos(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.06) || ~((z <= 0.02))) tmp = x + (z * cos(y)); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.06], N[Not[LessEqual[z, 0.02]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.06 \lor \neg \left(z \leq 0.02\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -1.0600000000000001 or 0.0200000000000000004 < z Initial program 99.8%
Taylor expanded in x around inf 99.0%
if -1.0600000000000001 < z < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 99.0%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2e+74) (not (<= z 7.6e+105))) (* z (cos y)) (+ x z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+74) || !(z <= 7.6e+105)) {
tmp = z * cos(y);
} else {
tmp = x + 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 <= (-5.2d+74)) .or. (.not. (z <= 7.6d+105))) then
tmp = z * cos(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+74) || !(z <= 7.6e+105)) {
tmp = z * Math.cos(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2e+74) or not (z <= 7.6e+105): tmp = z * math.cos(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e+74) || !(z <= 7.6e+105)) tmp = Float64(z * cos(y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2e+74) || ~((z <= 7.6e+105))) tmp = z * cos(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e+74], N[Not[LessEqual[z, 7.6e+105]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+74} \lor \neg \left(z \leq 7.6 \cdot 10^{+105}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -5.2000000000000001e74 or 7.6e105 < z Initial program 99.7%
Taylor expanded in z around inf 87.4%
if -5.2000000000000001e74 < z < 7.6e105Initial program 100.0%
Taylor expanded in y around 0 73.3%
+-commutative73.3%
Simplified73.3%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= x -0.0023) x (if (<= x 110000000.0) (+ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0023) {
tmp = x;
} else if (x <= 110000000.0) {
tmp = y + 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 <= (-0.0023d0)) then
tmp = x
else if (x <= 110000000.0d0) then
tmp = y + z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.0023) {
tmp = x;
} else if (x <= 110000000.0) {
tmp = y + z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0023: tmp = x elif x <= 110000000.0: tmp = y + z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0023) tmp = x; elseif (x <= 110000000.0) tmp = Float64(y + z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.0023) tmp = x; elseif (x <= 110000000.0) tmp = y + z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0023], x, If[LessEqual[x, 110000000.0], N[(y + z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0023:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 110000000:\\
\;\;\;\;y + z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -0.0023 or 1.1e8 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
add-cube-cbrt99.8%
associate-*l*99.8%
fma-def99.8%
pow299.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 80.7%
if -0.0023 < x < 1.1e8Initial program 99.8%
Taylor expanded in x around 0 92.4%
Taylor expanded in y around 0 43.7%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 68.5%
+-commutative68.5%
Simplified68.5%
Final simplification68.5%
(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%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.6%
associate-*l*99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 44.1%
Final simplification44.1%
herbie shell --seed 2023321
(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))))