
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
metadata-eval98.0%
mul-1-neg98.0%
unsub-neg98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -8e+159)
(* x z)
(if (<= z -1.8e+130)
(- z)
(if (<= z -1.25e+105)
(* x z)
(if (or (<= z 1e-76) (and (not (<= z 1.7e+20)) (<= z 7.6e+82)))
(* x y)
(- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e+159) {
tmp = x * z;
} else if (z <= -1.8e+130) {
tmp = -z;
} else if (z <= -1.25e+105) {
tmp = x * z;
} else if ((z <= 1e-76) || (!(z <= 1.7e+20) && (z <= 7.6e+82))) {
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 (z <= (-8d+159)) then
tmp = x * z
else if (z <= (-1.8d+130)) then
tmp = -z
else if (z <= (-1.25d+105)) then
tmp = x * z
else if ((z <= 1d-76) .or. (.not. (z <= 1.7d+20)) .and. (z <= 7.6d+82)) 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 (z <= -8e+159) {
tmp = x * z;
} else if (z <= -1.8e+130) {
tmp = -z;
} else if (z <= -1.25e+105) {
tmp = x * z;
} else if ((z <= 1e-76) || (!(z <= 1.7e+20) && (z <= 7.6e+82))) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e+159: tmp = x * z elif z <= -1.8e+130: tmp = -z elif z <= -1.25e+105: tmp = x * z elif (z <= 1e-76) or (not (z <= 1.7e+20) and (z <= 7.6e+82)): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e+159) tmp = Float64(x * z); elseif (z <= -1.8e+130) tmp = Float64(-z); elseif (z <= -1.25e+105) tmp = Float64(x * z); elseif ((z <= 1e-76) || (!(z <= 1.7e+20) && (z <= 7.6e+82))) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e+159) tmp = x * z; elseif (z <= -1.8e+130) tmp = -z; elseif (z <= -1.25e+105) tmp = x * z; elseif ((z <= 1e-76) || (~((z <= 1.7e+20)) && (z <= 7.6e+82))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e+159], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.8e+130], (-z), If[LessEqual[z, -1.25e+105], N[(x * z), $MachinePrecision], If[Or[LessEqual[z, 1e-76], And[N[Not[LessEqual[z, 1.7e+20]], $MachinePrecision], LessEqual[z, 7.6e+82]]], N[(x * y), $MachinePrecision], (-z)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+159}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1.8 \cdot 10^{+130}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -1.25 \cdot 10^{+105}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 10^{-76} \lor \neg \left(z \leq 1.7 \cdot 10^{+20}\right) \land z \leq 7.6 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -7.9999999999999994e159 or -1.8000000000000001e130 < z < -1.25000000000000011e105Initial program 93.9%
Taylor expanded in x around inf 73.5%
+-commutative73.5%
Simplified73.5%
Taylor expanded in z around inf 67.8%
if -7.9999999999999994e159 < z < -1.8000000000000001e130 or 9.99999999999999927e-77 < z < 1.7e20 or 7.60000000000000067e82 < z Initial program 98.7%
Taylor expanded in x around 0 62.1%
neg-mul-162.1%
Simplified62.1%
if -1.25000000000000011e105 < z < 9.99999999999999927e-77 or 1.7e20 < z < 7.60000000000000067e82Initial program 98.6%
Taylor expanded in y around inf 72.7%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(if (<= z -5e+129)
(- z)
(if (or (<= z 2e-76) (and (not (<= z 10500000000.0)) (<= z 8.2e+82)))
(* x y)
(- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e+129) {
tmp = -z;
} else if ((z <= 2e-76) || (!(z <= 10500000000.0) && (z <= 8.2e+82))) {
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 (z <= (-5d+129)) then
tmp = -z
else if ((z <= 2d-76) .or. (.not. (z <= 10500000000.0d0)) .and. (z <= 8.2d+82)) 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 (z <= -5e+129) {
tmp = -z;
} else if ((z <= 2e-76) || (!(z <= 10500000000.0) && (z <= 8.2e+82))) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e+129: tmp = -z elif (z <= 2e-76) or (not (z <= 10500000000.0) and (z <= 8.2e+82)): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e+129) tmp = Float64(-z); elseif ((z <= 2e-76) || (!(z <= 10500000000.0) && (z <= 8.2e+82))) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5e+129) tmp = -z; elseif ((z <= 2e-76) || (~((z <= 10500000000.0)) && (z <= 8.2e+82))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e+129], (-z), If[Or[LessEqual[z, 2e-76], And[N[Not[LessEqual[z, 10500000000.0]], $MachinePrecision], LessEqual[z, 8.2e+82]]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+129}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-76} \lor \neg \left(z \leq 10500000000\right) \land z \leq 8.2 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -5.0000000000000003e129 or 1.99999999999999985e-76 < z < 1.05e10 or 8.1999999999999999e82 < z Initial program 97.0%
Taylor expanded in x around 0 54.2%
neg-mul-154.2%
Simplified54.2%
if -5.0000000000000003e129 < z < 1.99999999999999985e-76 or 1.05e10 < z < 8.1999999999999999e82Initial program 98.7%
Taylor expanded in y around inf 71.4%
Final simplification64.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.45e-8) (not (<= x 7e-118))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.45e-8) || !(x <= 7e-118)) {
tmp = x * (y + z);
} 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.45d-8)) .or. (.not. (x <= 7d-118))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.45e-8) || !(x <= 7e-118)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.45e-8) or not (x <= 7e-118): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.45e-8) || !(x <= 7e-118)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.45e-8) || ~((x <= 7e-118))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.45e-8], N[Not[LessEqual[x, 7e-118]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{-8} \lor \neg \left(x \leq 7 \cdot 10^{-118}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -2.4500000000000001e-8 or 7e-118 < x Initial program 97.0%
Taylor expanded in x around inf 89.3%
+-commutative89.3%
Simplified89.3%
if -2.4500000000000001e-8 < x < 7e-118Initial program 100.0%
Taylor expanded in x around 0 75.0%
neg-mul-175.0%
Simplified75.0%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.2e+129) (not (<= z 1.8e-76))) (* z (+ x -1.0)) (* x (+ y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+129) || !(z <= 1.8e-76)) {
tmp = z * (x + -1.0);
} else {
tmp = x * (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 <= (-4.2d+129)) .or. (.not. (z <= 1.8d-76))) then
tmp = z * (x + (-1.0d0))
else
tmp = x * (y + z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+129) || !(z <= 1.8e-76)) {
tmp = z * (x + -1.0);
} else {
tmp = x * (y + z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e+129) or not (z <= 1.8e-76): tmp = z * (x + -1.0) else: tmp = x * (y + z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e+129) || !(z <= 1.8e-76)) tmp = Float64(z * Float64(x + -1.0)); else tmp = Float64(x * Float64(y + z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.2e+129) || ~((z <= 1.8e-76))) tmp = z * (x + -1.0); else tmp = x * (y + z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e+129], N[Not[LessEqual[z, 1.8e-76]], $MachinePrecision]], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+129} \lor \neg \left(z \leq 1.8 \cdot 10^{-76}\right):\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + z\right)\\
\end{array}
\end{array}
if z < -4.19999999999999993e129 or 1.8e-76 < z Initial program 96.5%
Taylor expanded in y around 0 90.7%
if -4.19999999999999993e129 < z < 1.8e-76Initial program 99.3%
Taylor expanded in x around inf 82.5%
+-commutative82.5%
Simplified82.5%
Final simplification86.2%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 33.2%
neg-mul-133.2%
Simplified33.2%
Final simplification33.2%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))