
(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 7 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 (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.4e-10) (not (<= x 6.2e-52))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e-10) || !(x <= 6.2e-52)) {
tmp = x * (z + 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 <= (-6.4d-10)) .or. (.not. (x <= 6.2d-52))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e-10) || !(x <= 6.2e-52)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.4e-10) or not (x <= 6.2e-52): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.4e-10) || !(x <= 6.2e-52)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.4e-10) || ~((x <= 6.2e-52))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.4e-10], N[Not[LessEqual[x, 6.2e-52]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-10} \lor \neg \left(x \leq 6.2 \cdot 10^{-52}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.39999999999999961e-10 or 6.1999999999999998e-52 < x Initial program 95.3%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -6.39999999999999961e-10 < x < 6.1999999999999998e-52Initial program 100.0%
Taylor expanded in x around 0 70.5%
neg-mul-170.5%
Simplified70.5%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e-8) (not (<= x 1.62e-53))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-8) || !(x <= 1.62e-53)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-3.4d-8)) .or. (.not. (x <= 1.62d-53))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-8) || !(x <= 1.62e-53)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e-8) or not (x <= 1.62e-53): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e-8) || !(x <= 1.62e-53)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e-8) || ~((x <= 1.62e-53))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e-8], N[Not[LessEqual[x, 1.62e-53]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-8} \lor \neg \left(x \leq 1.62 \cdot 10^{-53}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -3.4e-8 or 1.62e-53 < x Initial program 95.3%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -3.4e-8 < x < 1.62e-53Initial program 100.0%
Taylor expanded in y around 0 71.1%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-9) (not (<= x 1.15e-51))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-9) || !(x <= 1.15e-51)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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.7d-9)) .or. (.not. (x <= 1.15d-51))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-9) || !(x <= 1.15e-51)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-9) or not (x <= 1.15e-51): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-9) || !(x <= 1.15e-51)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.7e-9) || ~((x <= 1.15e-51))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-9], N[Not[LessEqual[x, 1.15e-51]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-9} \lor \neg \left(x \leq 1.15 \cdot 10^{-51}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -2.7000000000000002e-9 or 1.15000000000000001e-51 < x Initial program 95.3%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -2.7000000000000002e-9 < x < 1.15000000000000001e-51Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 71.1%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e+47) (not (<= z 1.5e+99))) (- z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+47) || !(z <= 1.5e+99)) {
tmp = -z;
} else {
tmp = 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 ((z <= (-1.7d+47)) .or. (.not. (z <= 1.5d+99))) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+47) || !(z <= 1.5e+99)) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e+47) or not (z <= 1.5e+99): tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e+47) || !(z <= 1.5e+99)) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e+47) || ~((z <= 1.5e+99))) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e+47], N[Not[LessEqual[z, 1.5e+99]], $MachinePrecision]], (-z), N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+47} \lor \neg \left(z \leq 1.5 \cdot 10^{+99}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -1.6999999999999999e47 or 1.50000000000000007e99 < z Initial program 94.7%
Taylor expanded in x around 0 48.3%
neg-mul-148.3%
Simplified48.3%
if -1.6999999999999999e47 < z < 1.50000000000000007e99Initial program 98.8%
Taylor expanded in y around inf 65.6%
Final simplification59.2%
(FPCore (x y z) :precision binary64 (if (<= z -5.4e+46) (* x z) (if (<= z 1.46e+99) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.4e+46) {
tmp = x * z;
} else if (z <= 1.46e+99) {
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 <= (-5.4d+46)) then
tmp = x * z
else if (z <= 1.46d+99) 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 <= -5.4e+46) {
tmp = x * z;
} else if (z <= 1.46e+99) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.4e+46: tmp = x * z elif z <= 1.46e+99: tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.4e+46) tmp = Float64(x * z); elseif (z <= 1.46e+99) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.4e+46) tmp = x * z; elseif (z <= 1.46e+99) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.4e+46], N[(x * z), $MachinePrecision], If[LessEqual[z, 1.46e+99], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{+46}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 1.46 \cdot 10^{+99}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -5.4000000000000003e46Initial program 95.0%
Taylor expanded in y around 0 90.7%
Taylor expanded in x around inf 47.9%
*-commutative47.9%
Simplified47.9%
if -5.4000000000000003e46 < z < 1.4600000000000001e99Initial program 98.8%
Taylor expanded in y around inf 65.6%
if 1.4600000000000001e99 < z Initial program 94.1%
Taylor expanded in x around 0 54.5%
neg-mul-154.5%
Simplified54.5%
Final simplification60.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 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 97.3%
Taylor expanded in x around 0 31.9%
neg-mul-131.9%
Simplified31.9%
Final simplification31.9%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))