
(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.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -9.2e+38) (* x z) (if (or (<= x -1e-26) (not (<= x 4.2e-32))) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e+38) {
tmp = x * z;
} else if ((x <= -1e-26) || !(x <= 4.2e-32)) {
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 <= (-9.2d+38)) then
tmp = x * z
else if ((x <= (-1d-26)) .or. (.not. (x <= 4.2d-32))) 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 <= -9.2e+38) {
tmp = x * z;
} else if ((x <= -1e-26) || !(x <= 4.2e-32)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.2e+38: tmp = x * z elif (x <= -1e-26) or not (x <= 4.2e-32): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.2e+38) tmp = Float64(x * z); elseif ((x <= -1e-26) || !(x <= 4.2e-32)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.2e+38) tmp = x * z; elseif ((x <= -1e-26) || ~((x <= 4.2e-32))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.2e+38], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -1e-26], N[Not[LessEqual[x, 4.2e-32]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{+38}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-26} \lor \neg \left(x \leq 4.2 \cdot 10^{-32}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -9.2000000000000005e38Initial program 96.2%
*-commutative96.2%
sub-neg96.2%
distribute-rgt-in96.2%
metadata-eval96.2%
neg-mul-196.2%
associate-+r+96.2%
unsub-neg96.2%
+-commutative96.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 76.1%
Taylor expanded in x around inf 76.1%
*-commutative76.1%
Simplified76.1%
if -9.2000000000000005e38 < x < -1e-26 or 4.1999999999999998e-32 < x Initial program 95.0%
*-commutative95.0%
sub-neg95.0%
distribute-rgt-in95.0%
metadata-eval95.0%
neg-mul-195.0%
associate-+r+95.0%
unsub-neg95.0%
+-commutative95.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 60.0%
if -1e-26 < x < 4.1999999999999998e-32Initial 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 x around 0 78.0%
neg-mul-178.0%
Simplified78.0%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1060000000000.0) (not (<= x 6.4e-24))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1060000000000.0) || !(x <= 6.4e-24)) {
tmp = x * (z + y);
} 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 ((x <= (-1060000000000.0d0)) .or. (.not. (x <= 6.4d-24))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1060000000000.0) || !(x <= 6.4e-24)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1060000000000.0) or not (x <= 6.4e-24): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1060000000000.0) || !(x <= 6.4e-24)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1060000000000.0) || ~((x <= 6.4e-24))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1060000000000.0], N[Not[LessEqual[x, 6.4e-24]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1060000000000 \lor \neg \left(x \leq 6.4 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1.06e12 or 6.40000000000000025e-24 < x Initial program 95.1%
*-commutative95.1%
sub-neg95.1%
distribute-rgt-in95.1%
metadata-eval95.1%
neg-mul-195.1%
associate-+r+95.1%
unsub-neg95.1%
+-commutative95.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 98.9%
+-commutative98.9%
Simplified98.9%
if -1.06e12 < x < 6.40000000000000025e-24Initial 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 z around 0 99.8%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-28) (not (<= x 1.9e-33))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-28) || !(x <= 1.9e-33)) {
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 <= (-8.5d-28)) .or. (.not. (x <= 1.9d-33))) 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 <= -8.5e-28) || !(x <= 1.9e-33)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-28) or not (x <= 1.9e-33): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-28) || !(x <= 1.9e-33)) 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 <= -8.5e-28) || ~((x <= 1.9e-33))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-28], N[Not[LessEqual[x, 1.9e-33]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-28} \lor \neg \left(x \leq 1.9 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.49999999999999925e-28 or 1.89999999999999997e-33 < x Initial program 95.5%
*-commutative95.5%
sub-neg95.5%
distribute-rgt-in95.5%
metadata-eval95.5%
neg-mul-195.5%
associate-+r+95.5%
unsub-neg95.5%
+-commutative95.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 96.9%
+-commutative96.9%
Simplified96.9%
if -8.49999999999999925e-28 < x < 1.89999999999999997e-33Initial 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 x around 0 78.0%
neg-mul-178.0%
Simplified78.0%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e-28) (not (<= x 6e-34))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-28) || !(x <= 6e-34)) {
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 <= (-1.1d-28)) .or. (.not. (x <= 6d-34))) 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 <= -1.1e-28) || !(x <= 6e-34)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-28) or not (x <= 6e-34): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-28) || !(x <= 6e-34)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e-28) || ~((x <= 6e-34))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-28], N[Not[LessEqual[x, 6e-34]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-28} \lor \neg \left(x \leq 6 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.09999999999999998e-28 or 6e-34 < x Initial program 95.5%
*-commutative95.5%
sub-neg95.5%
distribute-rgt-in95.5%
metadata-eval95.5%
neg-mul-195.5%
associate-+r+95.5%
unsub-neg95.5%
+-commutative95.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 49.6%
if -1.09999999999999998e-28 < x < 6e-34Initial 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 x around 0 78.0%
neg-mul-178.0%
Simplified78.0%
Final simplification63.1%
(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.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 39.9%
neg-mul-139.9%
Simplified39.9%
(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 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 39.9%
neg-mul-139.9%
Simplified39.9%
neg-sub039.9%
sub-neg39.9%
add-sqr-sqrt20.3%
sqrt-unprod16.4%
sqr-neg16.4%
sqrt-unprod1.1%
add-sqr-sqrt2.4%
Applied egg-rr2.4%
Taylor expanded in z around 0 2.4%
herbie shell --seed 2024132
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))